33#include <sys/socket.h>
35#include <netinet/in.h>
40#define MSG_INNARDS(prefix, ...) \
42 printf(prefix __VA_ARGS__); \
46#define MSG(...) MSG_INNARDS("", __VA_ARGS__)
47#define MSG_WARN(...) MSG_INNARDS("** WARNING **: ", __VA_ARGS__)
48#define MSG_ERR(...) MSG_INNARDS("** ERROR **: ", __VA_ARGS__)
69 const int buf_sz = 8*1024;
70 char buf[buf_sz], *msg = NULL;
74 st = read(fd, buf, buf_sz);
85 }
while (st == buf_sz);
87 msg = (dstr->
len > 0) ? dstr->
str : NULL;
99 while (st < 0 && errno == EINTR);
106 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) {
119 char *fname, *rcline = NULL, *tail;
123 if ((In = fopen(fname,
"r")) == NULL) {
125 }
else if ((rcline =
dGetline(In)) == NULL) {
126 MSG_ERR(
"[Dpi_read_comm_keys] empty file: %s\n", fname);
128 *port = strtol(rcline, &tail, 10);
129 for (i = 0; *tail && isxdigit(tail[i+1]); ++i)
144 struct sockaddr_in sin;
145 const socklen_t sin_sz =
sizeof(sin);
146 int sock_fd, dpid_port, ret = -1;
149 memset(&sin, 0,
sizeof(sin));
150 sin.sin_family = AF_INET;
151 sin.sin_addr.s_addr = inet_addr(
"127.0.0.1");
154 sin.sin_port = htons(dpid_port);
156 MSG(
"Dpi_check_dpid_ids: sock_fd=%d %s\n", sock_fd,
dStrerror(errno));
157 }
else if (connect(sock_fd, (
struct sockaddr *)&sin, sin_sz) == -1) {
171 while (sent < msg_len) {
172 st = write(fd, msg + sent, msg_len - sent);
174 if (errno == EINTR) {
184 return (sent == msg_len) ? 1 : -1;
194 int st_pipe[2], ret = 1;
206 if (execl(path1,
"dpid", (
char*)NULL) == -1) {
208 if (execlp(
"dpid",
"dpid", (
char*)NULL) == -1) {
211 MSG(
"Dpi_start_dpid (child): can't write to pipe.\n");
214 _exit (EXIT_FAILURE);
217 }
else if (pid < 0) {
228 MSG(
"Dpi_start_dpid: can't start dpid\n");
245 static int starting = 0;
246 int check_st = 1, ret = 2;
249 _MSG(
"Dpi_check_dpid: check_st=%d\n", check_st);
262 }
else if (++starting < num_tries) {
271 _MSG(
"Dpi_check_dpid:: %s\n",
272 (ret == 0) ?
"OK" : (ret == 1 ?
"EAGAIN" :
"ERROR"));
284 MSG(
"Dpi_blocking_start_dpid: try %d\n", ++
try);
301 int sock_fd = -1, dpi_port = -1;
302 int dpid_port, ok = 0;
303 struct sockaddr_in sin;
304 char *cmd, *request, *rply = NULL, *port_str;
308 _MSG(
"Dpi_get_server_port:: server_name = [%s]\n", server_name);
317 sin_sz =
sizeof(sin);
318 memset(&sin, 0,
sizeof(sin));
319 sin.sin_family = AF_INET;
320 sin.sin_addr.s_addr = inet_addr(
"127.0.0.1");
321 sin.sin_port = htons(dpid_port);
323 connect(sock_fd, (
struct sockaddr *)&sin, sin_sz) == -1) {
333 _MSG(
"[%s]\n", request);
346 MSG(
"Dpi_get_server_port: can't read server port from dpid.\n");
355 if (strcmp(cmd,
"send_data") == 0) {
357 _MSG(
"Dpi_get_server_port: rply=%s\n", rply);
358 _MSG(
"Dpi_get_server_port: port_str=%s\n", port_str);
359 dpi_port = strtol(port_str, NULL, 10);
368 return ok ? dpi_port : -1;
374 struct sockaddr_in sin;
375 int sock_fd, dpi_port, ret = -1;
380 _MSG(
"Dpi_connect_socket:: can't get port number for %s\n", server_name);
383 _MSG(
"Dpi_connect_socket: server=%s port=%d\n", server_name, dpi_port);
386 memset(&sin, 0,
sizeof(sin));
387 sin.sin_family = AF_INET;
388 sin.sin_addr.s_addr = inet_addr(
"127.0.0.1");
389 sin.sin_port = htons(dpi_port);
392 perror(
"[dpi::socket]");
393 }
else if (connect(sock_fd, (
void*)&sin,
sizeof(sin)) == -1) {
394 MSG(
"[dpi::connect] errno:%d %s\n", errno,
dStrerror(errno));
398 MSG_ERR(
"[Dpi_connect_socket] Can't make auth message.\n");
400 MSG_ERR(
"[Dpi_connect_socket] Can't send auth message.\n");
405 if (sock_fd != -1 && ret == -1)
423 MSG_ERR(
"[a_Dpi_send_blocking_cmd] Can't connect to server.\n");
425 MSG_ERR(
"[a_Dpi_send_blocking_cmd] Can't send message.\n");
427 MSG_ERR(
"[a_Dpi_send_blocking_cmd] Can't read message.\n");
439 char *cmd, *dpip_tag;
443 "set_cookie", cookie,
447 "set_cookie", cookie,
451 _MSG(
"a_Cookies_set: dpip_tag = {%s}\n", dpip_tag);
460 char *cmd, *dpip_tag, *query;
463 "get_cookie", scheme,
467 _MSG(
"cookies.c: a_Dpi_send_blocking_cmd cmd = {%s}\n", cmd);
469 _MSG(
"cookies.c: after a_Dpi_send_blocking_cmd resp={%s}\n", dpip_tag);
472 if (dpip_tag != NULL) {
482static void expect(
int lineno,
const char *exp_reply,
483 const char *scheme,
const char *host,
const char *
path)
487 if (strcmp(reply, exp_reply)) {
488 MSG(
"line %d: EXPECTED: %s GOT: %s\n", lineno, exp_reply, reply);
519 expect(__LINE__,
"Cookie: 7=1; 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; "
520 "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; "
521 "20=1; 21=1\r\n",
"http",
"toomany.com",
"/path/");
524 expect(__LINE__,
"Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; "
525 "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; "
526 "20=1; 21=1\r\n",
"http",
"toomany.com",
"/");
529 expect(__LINE__,
"Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; "
530 "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; "
531 "20=1; 21=1; 22=1\r\n",
"http",
"toomany.com",
"/path/");
536 time_t t = time(NULL)+1000;
537 char *server_date =
dStrdup(ctime(&t));
539 a_Cookies_set(
"name=val; max-age=0",
"maxage0.com",
"/", NULL);
540 expect(__LINE__,
"",
"http",
"maxage0.com",
"/");
542 a_Cookies_set(
"name=val; max-age=-0",
"maxage-0.com",
"/", NULL);
543 expect(__LINE__,
"",
"http",
"maxage-0.com",
"/");
545 a_Cookies_set(
"name=val; max-age=100",
"maxage100.com",
"/", NULL);
546 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage100.com",
"/");
548 a_Cookies_set(
"name=val; max-age=-100",
"maxage-100.com",
"/", NULL);
549 expect(__LINE__,
"",
"http",
"maxage-100.com",
"/");
551 a_Cookies_set(
"name=val; max-age=2000000000",
"maxage2bil.com",
"/", NULL);
552 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage2bil.com",
"/");
554 a_Cookies_set(
"name=val; max-age=3000000000",
"maxage3bil.com",
"/", NULL);
555 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage3bil.com",
"/");
557 a_Cookies_set(
"name=val; max-age=7000000000",
"maxage7bil.com",
"/", NULL);
558 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage7bil.com",
"/");
560 a_Cookies_set(
"name=val; max-age=-2000000000",
"maxage-2bil.com",
"/",NULL);
561 expect(__LINE__,
"",
"http",
"maxage-2bil.com",
"/");
563 a_Cookies_set(
"name=val; max-age=-3000000000",
"maxage-3bil.com",
"/",NULL);
564 expect(__LINE__,
"",
"http",
"maxage-3bil.com",
"/");
566 a_Cookies_set(
"name=val; max-age=-7000000000",
"maxage-7bil.com",
"/",NULL);
567 expect(__LINE__,
"",
"http",
"maxage-7bil.com",
"/");
571 a_Cookies_set(
"name=val; max-age=0",
"maxage0s.com",
"/", server_date);
572 expect(__LINE__,
"",
"http",
"maxage0s.com",
"/");
574 a_Cookies_set(
"name=val; max-age=100",
"maxage100s.com",
"/", server_date);
575 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage100s.com",
"/");
577 a_Cookies_set(
"name=val; max-age=-100",
"maxage-100s.com",
"/",server_date);
578 expect(__LINE__,
"",
"http",
"maxage-100s.com",
"/");
581 a_Cookies_set(
"name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010",
582 "maxagelater.com",
"/", NULL);
583 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxagelater.com",
"/");
585 a_Cookies_set(
"name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010",
586 "maxagelaters.com",
"/", server_date);
587 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxagelaters.com",
"/");
595 time_t t = time(NULL)+1000;
596 char *server_date =
dStrdup(ctime(&t));
597 time_t expt = t + 1000;
598 char *exp_date =
dStrdup(ctime(&expt));
600 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
602 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e2000s1000.com",
"/");
605 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e2000s1000s.com",
"/");
609 exp_date =
dStrdup(ctime(&expt));
611 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
613 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e500s1000.com",
"/");
616 expect(__LINE__,
"",
"http",
"e500s1000s.com",
"/");
620 exp_date =
dStrdup(ctime(&expt));
622 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
624 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e1000s1000.com",
"/");
627 expect(__LINE__,
"",
"http",
"e1000s1000s.com",
"/");
631 exp_date =
dStrdup(ctime(&expt));
633 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
635 expect(__LINE__,
"",
"http",
"e0s1000.com",
"/");
638 expect(__LINE__,
"",
"http",
"e0s1000s.com",
"/");
647 time_t t = time(NULL)-1000;
648 char *server_date =
dStrdup(ctime(&t));
650 time_t expt = t + 1000;
651 char *exp_date =
dStrdup(ctime(&expt));
653 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
655 expect(__LINE__,
"",
"http",
"e0s-1000.com",
"/");
658 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e0s-1000s.com",
"/");
662 exp_date =
dStrdup(ctime(&expt));
664 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
666 expect(__LINE__,
"",
"http",
"e-500s-1000.com",
"/");
669 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e-500s-1000s.com",
"/");
673 exp_date =
dStrdup(ctime(&expt));
675 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
677 expect(__LINE__,
"",
"http",
"e-1000s-1000.com",
"/");
679 a_Cookies_set(
string,
"e-1000s-1000s.com",
"/", server_date);
680 expect(__LINE__,
"",
"http",
"e-1000s-1000s.com",
"/");
691 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1801",
"expmin.com",
693 expect(__LINE__,
"",
"http",
"expmin.com",
"/");
695 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1901",
"expmin2.com",
697 expect(__LINE__,
"",
"http",
"expmin2.com",
"/");
699 a_Cookies_set(
"name=val; expires=Wed Dec 31 23:59:59 1969",
"expneg.com",
701 expect(__LINE__,
"",
"http",
"expneg.com",
"/");
703 a_Cookies_set(
"name=val; expires=Thu, 01-January-70 00:00:00 GMT",
704 "expepoch.com",
"/", NULL);
705 expect(__LINE__,
"",
"http",
"expepoch.com",
"/");
708 a_Cookies_set(
"name=val; expires=Tue Jan 19 03:14:07 2038",
"expmax.com",
710 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"expmax.com",
"/");
712 a_Cookies_set(
"name=val; expires=Sun January 1 00:00:00 2040",
713 "pastmax.com",
"/", NULL);
714 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"pastmax.com",
"/");
717 server_date =
dStrdup(ctime(&t));
719 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1901",
"expmina.com",
721 expect(__LINE__,
"",
"http",
"expmina.com",
"/");
723 a_Cookies_set(
"name=val; expires=Wed Dec 31 23:59:59 1969",
"expnega.com",
725 expect(__LINE__,
"",
"http",
"expnega.com",
"/");
727 a_Cookies_set(
"name=val; expires=Thu Jan 1 00:00:00 1970",
"expepocha.com",
729 expect(__LINE__,
"",
"http",
"expepocha.com",
"/");
731 a_Cookies_set(
"name=val; expires=Tue Jan 19 03:14:07 2038",
"expmaxa.com",
733 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"expmaxa.com",
"/");
735 a_Cookies_set(
"name=val; expires=Thu, 01-Jan-40 00:00:00 GMT",
736 "pastmaxa.com",
"/", server_date);
737 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"pastmaxa.com",
"/");
741 server_date =
dStrdup(ctime(&t));
743 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1901",
"expminb.com",
745 expect(__LINE__,
"",
"http",
"expminb.com",
"/");
747 a_Cookies_set(
"name=val; expires=Wed Dec 31 23:59:59 1969",
"expnegb.com",
749 expect(__LINE__,
"",
"http",
"expnegb.com",
"/");
751 a_Cookies_set(
"name=val; expires=Thu Jan 1 00:00:00 1970",
"expepochb.com",
753 expect(__LINE__,
"",
"http",
"expepochb.com",
"/");
755 a_Cookies_set(
"name=val; expires=Tue Jan 19 03:14:07 2038",
"expmaxb.com",
757 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"expmaxb.com",
"/");
759 a_Cookies_set(
"name=val; expires=Sun Jan 1 00:00:00 2040",
"pastmaxb.com",
761 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"pastmaxb.com",
"/");
774 a_Cookies_set(
"name=val; expires=Mon, 10-Dec-2037 17:02:24 GMT",
775 "format1.com",
"/", NULL);
776 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format1.com",
"/");
779 a_Cookies_set(
"name=val; expires=Wed, 09 Dec 2037 16:27:23 GMT",
780 "format2.com",
"/", NULL);
781 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format2.com",
"/");
787 a_Cookies_set(
"name=val; expires=Thursday, 01-Jan-2036 00:00:00 GMT",
788 "format3.com",
"/", NULL);
789 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format3.com",
"/");
792 a_Cookies_set(
"name=val; expires=Mon Dec 10 16:32:30 2037 GMT",
793 "format4.com",
"/", NULL);
794 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format4.com",
"/");
799 a_Cookies_set(
"name=val; expires=Wednesday, 01-Jan-37 00:00:00 GMT",
800 "format5.com",
"/", NULL);
801 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format5.com",
"/");
804 a_Cookies_set(
"name=val; expires=Mon, 10-Dec-37 20:35:03 GMT",
805 "format6.com",
"/", NULL);
806 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format6.com",
"/");
812 a_Cookies_set(
"name=val; expires=Wed, 1 Jan 2035 00:00:00 GMT",
813 "format7.com",
"/", NULL);
814 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format7.com",
"/");
817 a_Cookies_set(
"name=val; expires=Saturday, 8-Dec-2035 21:24:09 GMT",
818 "format8.com",
"/", NULL);
819 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format8.com",
"/");
825 a_Cookies_set(
"name=val; expires=Thu, 31 Dec 23:55:55 2037 GMT",
826 "format9.com",
"/", NULL);
827 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format9.com",
"/");
832 a_Cookies_set(
"name=val; expires=Sun, 9 Dec 2036 13:42:05 GMT",
833 "formata.com",
"/", NULL);
834 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formata.com",
"/");
840 a_Cookies_set(
"name=val; expires=Wed Dec 12 2037 08:44:07 GMT-0500 (EST)",
841 "formatb.com",
"/", NULL);
842 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formatb.com",
"/");
844 a_Cookies_set(
"name=val; expires=Sun, 1-Jan-2035 00:00:00 GMT",
845 "formatc.com",
"/", NULL);
846 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formatc.com",
"/");
853 a_Cookies_set(
"name=val; expires=Sat, 07 Jul 2035 21:41:24 -0000",
854 "formatd.com",
"/", NULL);
855 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formatd.com",
"/");
862 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p1.com",
"/");
864 a_Cookies_set(
"name=val; path=/dir1",
"p2.com",
"/dir2", NULL);
865 expect(__LINE__,
"",
"http",
"p2.com",
"/");
866 expect(__LINE__,
"",
"http",
"p2.com",
"/d");
867 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p2.com",
"/dir1");
868 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p2.com",
"/dir1/");
869 expect(__LINE__,
"",
"http",
"p2.com",
"/dir2");
870 expect(__LINE__,
"",
"http",
"p2.com",
"/dir11");
872 a_Cookies_set(
"name=val; path=dir1",
"p3.com",
"/dir2", NULL);
873 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p3.com",
"/");
874 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p3.com",
"/dir1");
875 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p3.com",
"/dir2");
877 a_Cookies_set(
"name=val; path=/dir1/",
"p4.com",
"/dir2", NULL);
878 expect(__LINE__,
"",
"http",
"p4.com",
"/");
881 expect(__LINE__,
"",
"http",
"p4.com",
"/dir1");
882 expect(__LINE__,
"",
"http",
"p4.com",
"/dir11");
883 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p4.com",
"/dir1/");
884 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p4.com",
"/dir1/sub");
887 expect(__LINE__,
"",
"http",
"p5.com",
"/");
888 expect(__LINE__,
"",
"http",
"p5.com",
"/bir");
889 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p5.com",
"/dir");
890 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p5.com",
"/dir/");
893 expect(__LINE__,
"",
"http",
"p6.com",
"/dir/");
894 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p6.com",
"/dir/subdir");
895 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p6.com",
"/dir/subdir/s");
900 const int line_maxlen = 4096;
903 char line[line_maxlen];
908 stream = fopen(filename,
"r");
912 MSG_ERR(
"Cannot run test; cannot open cookiesrc.\n");
917 while (!feof(stream)) {
921 rc = fgets(line, line_maxlen, stream);
922 if (!rc && ferror(stream)) {
923 MSG_ERR(
"Error while reading rule from cookiesrc: %s\n",
932 if (line[0] !=
'\0' && line[0] !=
'#') {
933 int domain_end, i = 0;
937 while (line[i] !=
'\0' && !
dIsspace(line[i]))
944 line[domain_end] =
'\0';
948 while (line[i] !=
'\0' && !
dIsspace(line[i]))
958 MSG_WARN(
"DENY rules in cookiesrc can interfere with test.\n");
965 MSG_ERR(
"Cannot run test with cookiesrc default of deny.\n");
975 MSG(
"If you change cookiesrc, remember to stop the DPIs via dpidc.\n");
980 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"ordinary.com",
"/");
989 a_Cookies_set(
"name=val; expires=\"Sun Jan 10 00:00:00 2038\"",
990 "quoted-date.org",
"/", NULL);
991 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"quoted-date.org",
"/");
993 a_Cookies_set(
"name=val; expires=\"Sun Jan 11 00:00:00 1970\"",
994 "quoted-pastdate.org",
"/", NULL);
995 expect(__LINE__,
"",
"http",
"quoted-pastdate.org",
"/");
1000 a_Cookies_set(
"name=val; domain=co.il",
"www.co.il",
"/", NULL);
1001 expect(__LINE__,
"",
"http",
"www.co.il",
"/");
1003 a_Cookies_set(
"name=val; domain=.co.il",
"www.co.il",
"/", NULL);
1004 expect(__LINE__,
"",
"http",
"www.co.il",
"/");
1006 a_Cookies_set(
"name=val; domain=co.il.",
"www.co.il.",
"/", NULL);
1007 expect(__LINE__,
"",
"http",
"www.co.il.",
"/");
1009 a_Cookies_set(
"name=val; domain=.co.il.",
"www.co.il.",
"/", NULL);
1010 expect(__LINE__,
"",
"http",
".www.co.il.",
"/");
1012 a_Cookies_set(
"name=val; domain=co.org",
"www.co.org",
"/", NULL);
1013 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"www.co.org",
"/");
1015 a_Cookies_set(
"name=val; domain=.cp.org",
"www.cp.org",
"/", NULL);
1016 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"www.cp.org",
"/");
1020 a_Cookies_set(
"name=val; domain=.dotdomain.org",
"dotdomain.org",
"/",
1022 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"dotdomain.org",
"/");
1023 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"www.dotdomain.org",
"/");
1026 a_Cookies_set(
"name=val; domain=.hostonly.org",
"hostonly.org",
"/", NULL);
1028 a_Cookies_set(
"name3=val3; domain=hostonly.org",
"hostonly.org",
"/", NULL);
1029 expect(__LINE__,
"Cookie: name=val; name2=val2; name3=val3\r\n",
"http",
1030 "hostonly.org",
"/");
1031 a_Cookies_set(
"name=new; domain=.hostonly.org",
"hostonly.org",
"/", NULL);
1032 expect(__LINE__,
"Cookie: name=new; name2=val2; name3=val3\r\n",
"http",
1033 "hostonly.org",
"/");
1035 expect(__LINE__,
"Cookie: name=new; name2=new2; name3=val3\r\n",
"http",
1036 "hostonly.org",
"/");
1037 a_Cookies_set(
"name3=new3; domain=hostonly.org",
"hostonly.org",
"/", NULL);
1038 expect(__LINE__,
"Cookie: name=new; name2=new2; name3=new3\r\n",
"http",
1039 "hostonly.org",
"/");
1042 a_Cookies_set(
"name=val; domain=www.subdomain.com",
"subdomain.com",
"/",
1044 a_Cookies_set(
"name=val; domain=.www.subdomain.com",
"subdomain.com",
"/",
1046 expect(__LINE__,
"",
"http",
"subdomain.com",
"/");
1047 expect(__LINE__,
"",
"http",
"www.subdomain.com",
"/");
1050 a_Cookies_set(
"name=val; domain=.supdomain.com",
"www.supdomain.com",
"/",
1052 a_Cookies_set(
"name2=val2; domain=supdomain.com",
"www.supdomain.com",
"/",
1054 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1055 "sub2.sub.supdomain.com",
"/");
1056 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1057 "www.supdomain.com",
"/");
1058 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1059 "supdomain.com",
"/");
1062 a_Cookies_set(
"name=val; domain=another.com",
"unrelated.com",
"/", NULL);
1063 expect(__LINE__,
"",
"http",
"another.com",
"/");
1064 a_Cookies_set(
"name=val; domain=another.com",
"a.org",
"/", NULL);
1065 expect(__LINE__,
"",
"http",
"another.com",
"/");
1066 a_Cookies_set(
"name=val; domain=another.com",
"badguys.com",
"/", NULL);
1067 expect(__LINE__,
"",
"http",
"another.com",
"/");
1068 a_Cookies_set(
"name=val; domain=another.com",
"more.badguys.com",
"/",
1070 expect(__LINE__,
"",
"http",
"another.com",
"/");
1071 a_Cookies_set(
"name=val; domain=another.com",
"verybadguys.com",
"/", NULL);
1072 expect(__LINE__,
"",
"http",
"another.com",
"/");
1074 a_Cookies_set(
"name=val; domain=similar.com",
"imilar.com",
"/", NULL);
1075 a_Cookies_set(
"name2=val2; domain=similar.com",
"ssimilar.com",
"/", NULL);
1076 a_Cookies_set(
"name3=val3; domain=.similar.com",
"imilar.com",
"/", NULL);
1077 a_Cookies_set(
"name4=val4; domain=.similar.com",
"timilar.com",
"/", NULL);
1078 a_Cookies_set(
"name4=val4; domain=.similar.com",
"tiimilar.com",
"/", NULL);
1079 expect(__LINE__,
"",
"http",
"similar.com",
"/");
1083 expect(__LINE__,
"",
"http",
"secure.com",
"/");
1084 expect(__LINE__,
"Cookie: name=val\r\n",
"https",
"secure.com",
"/");
1087 a_Cookies_set(
"name=val; HttpOnly",
"httponly.net",
"/", NULL);
1088 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"httponly.net",
"/");
1091 a_Cookies_set(
"name=val; ldkfals",
"gibberish.net",
"/", NULL);
1092 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"gibberish.net",
"/");
1097 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1098 "whitespace.net",
"/");
1104 expect(__LINE__,
"Cookie: name=; name2=\r\n",
"http",
"nonameval.org",
"/");
1106 expect(__LINE__,
"Cookie: name=; name2=\r\n",
"http",
"nonameval.org",
"/");
1111 a_Cookies_set(
"name=val",
"FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
1113 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
1114 "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
"/");
1116 a_Cookies_set(
"name=val",
"::FFFF:129.144.52.38",
"/", NULL);
1117 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"::FFFF:129.144.52.38",
1121 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"127.0.0.1",
"/");
1123 a_Cookies_set(
"name=val; domain=128.0.0.1",
"128.0.0.1",
"/", NULL);
1124 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"128.0.0.1",
"/");
1126 a_Cookies_set(
"name=val; domain=130.0.0.1",
"129.0.0.1",
"/", NULL);
1127 expect(__LINE__,
"",
"http",
"129.0.0.1",
"/");
1128 expect(__LINE__,
"",
"http",
"130.0.0.1",
"/");
1131 a_Cookies_set(
"name=bad; domain=22.0.0.1",
"2.0.0.1",
"/", NULL);
1132 a_Cookies_set(
"name=bad; domain=.0.0.1",
"2.0.0.1",
"/", NULL);
1133 a_Cookies_set(
"name=bad; domain=not-ip.org",
"2.0.0.1",
"/", NULL);
1134 expect(__LINE__,
"",
"http",
"22.0.0.1",
"/");
1135 expect(__LINE__,
"",
"http",
"not-ip.org",
"/");
1136 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"2.0.0.1",
"/");
1139HAD BEEN PLAYING AROUND WITH REAL PUBLIC SUFFIX
1140a_Cookies_set(
"name=val;domain=sub.sub.yokohama.jp",
"sub.sub.yokohama.jp",
"/", NULL);
1141MSG(
"sub sub yokohama should work: %s\n",
1143a_Cookies_set(
"name=val; domain=sub.tokyo.jp",
"sub.sub.tokyo.jp",
"/", NULL);
1144MSG(
"sub tokyo jp should fail: %s\n",
1146a_Cookies_set(
"name=val; domain=pref.chiba.jp",
"sub.pref.chiba.jp",
"/", NULL);
1147MSG(
"pref chiba jp should succeed: %s\n",
1149a_Cookies_set(
"name=val; domain=org",
"www.dillo.org",
"/", NULL);
1150a_Cookies_set(
"name=val; domain=org",
"dillo.org",
"/", NULL);
1151a_Cookies_set(
"name=val; domain=org",
".dillo.org",
"/", NULL);
1152a_Cookies_set(
"name=val; domain=org.",
".dillo.org",
"/", NULL);
1153a_Cookies_set(
"name=val; domain=org.",
".dillo.org.",
"/", NULL);
1154MSG(
"org should fail: %s\n",
1160 MSG(
"Now that everything is full of fake cookies, you should run "
1161 "'dpidc stop', plus delete cookies.txt if necessary.\n");
char * dGetline(FILE *stream)
Get a line from a FILE stream.
char * dStrconcat(const char *s1,...)
Concatenate a NULL-terminated list of strings.
int dStrAsciiCasecmp(const char *s1, const char *s2)
char * dStrstrip(char *s)
Remove leading and trailing whitespace.
char * dStrdup(const char *s)
Dstr * dStr_sized_new(int sz)
Create a new string with a given size.
void dStr_free(Dstr *ds, int all)
Free a dillo string.
void dStr_append_l(Dstr *ds, const char *s, int l)
Append a C string to a Dstr (providing length).
int dUsleep(unsigned long usec)
Portable usleep() function.
char * dGethomedir(void)
Return the home directory in a static string (don't free)
#define dReturn_val_if_fail(expr, val)
static bool_t default_deny
char * a_Dpip_build_cmd(const char *format,...)
Printf like function for building dpip commands.
char * a_Dpip_get_attr(const char *tag, const char *attrname)
Task: given a tag and an attribute name, return its value.
char * a_Dpi_send_blocking_cmd(const char *server_name, const char *cmd)
Send a command to a dpi server, and block until the answer is got.
char * a_Cookies_get_query(const DilloUrl *query_url, const DilloUrl *requester)
Return a string containing cookie data for an HTTP query.
void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url, const char *date)
Set the value corresponding to the cookie string.
static char SharedKey[32]
static int Dpi_start_dpid(void)
static int Dpi_blocking_write(int fd, const char *msg, int msg_len)
static void expires_server_ahead()
static int Dpi_read_comm_keys(int *port)
static int Dpi_make_socket_fd()
static void Dpi_close_fd(int fd)
static int Dpi_get_server_port(const char *server_name)
static int Dpi_blocking_start_dpid(void)
static void expires_extremes()
static void expires_server_behind()
static void expect(int lineno, const char *exp_reply, const char *scheme, const char *host, const char *path)
static char * Dpi_blocking_read(int fd)
static int Dpi_check_dpid(int num_tries)
static int Dpi_check_dpid_ids()
static void expires_date_formats()
static int Dpi_connect_socket(const char *server_name)