32#include <sys/socket.h>
34#include <netinet/in.h>
39#define MSG_INNARDS(prefix, ...) \
41 printf(prefix __VA_ARGS__); \
45#define MSG(...) MSG_INNARDS("", __VA_ARGS__)
46#define MSG_WARN(...) MSG_INNARDS("** WARNING **: ", __VA_ARGS__)
47#define MSG_ERR(...) MSG_INNARDS("** ERROR **: ", __VA_ARGS__)
68 const int buf_sz = 8*1024;
69 char buf[buf_sz], *msg = NULL;
73 st = read(fd, buf, buf_sz);
84 }
while (st == buf_sz);
86 msg = (dstr->
len > 0) ? dstr->
str : NULL;
98 while (st < 0 && errno == EINTR);
105 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) != -1) {
118 char *fname, *rcline = NULL, *tail;
122 if ((In = fopen(fname,
"r")) == NULL) {
124 }
else if ((rcline =
dGetline(In)) == NULL) {
125 MSG_ERR(
"[Dpi_read_comm_keys] empty file: %s\n", fname);
127 *port = strtol(rcline, &tail, 10);
128 for (i = 0; *tail &&
dIsxdigit(tail[i+1]); ++i)
143 struct sockaddr_in sin;
144 const socklen_t sin_sz =
sizeof(sin);
145 int sock_fd, dpid_port, ret = -1;
148 memset(&sin, 0,
sizeof(sin));
149 sin.sin_family = AF_INET;
150 sin.sin_addr.s_addr = inet_addr(
"127.0.0.1");
153 sin.sin_port = htons(dpid_port);
155 MSG(
"Dpi_check_dpid_ids: sock_fd=%d %s\n", sock_fd,
dStrerror(errno));
156 }
else if (connect(sock_fd, (
struct sockaddr *)&sin, sin_sz) == -1) {
170 while (sent < msg_len) {
171 st = write(fd, msg + sent, msg_len - sent);
173 if (errno == EINTR) {
183 return (sent == msg_len) ? 1 : -1;
193 int st_pipe[2], ret = 1;
205 if (execl(path1,
"dpid", (
char*)NULL) == -1) {
207 if (execlp(
"dpid",
"dpid", (
char*)NULL) == -1) {
210 MSG(
"Dpi_start_dpid (child): can't write to pipe.\n");
213 _exit (EXIT_FAILURE);
216 }
else if (pid < 0) {
227 MSG(
"Dpi_start_dpid: can't start dpid\n");
244 static int starting = 0;
245 int check_st = 1, ret = 2;
248 _MSG(
"Dpi_check_dpid: check_st=%d\n", check_st);
261 }
else if (++starting < num_tries) {
270 _MSG(
"Dpi_check_dpid:: %s\n",
271 (ret == 0) ?
"OK" : (ret == 1 ?
"EAGAIN" :
"ERROR"));
283 MSG(
"Dpi_blocking_start_dpid: try %d\n", ++
try);
300 int sock_fd = -1, dpi_port = -1;
301 int dpid_port, ok = 0;
302 struct sockaddr_in sin;
303 char *cmd, *request, *rply = NULL, *port_str;
307 _MSG(
"Dpi_get_server_port:: server_name = [%s]\n", server_name);
316 sin_sz =
sizeof(sin);
317 memset(&sin, 0,
sizeof(sin));
318 sin.sin_family = AF_INET;
319 sin.sin_addr.s_addr = inet_addr(
"127.0.0.1");
320 sin.sin_port = htons(dpid_port);
322 connect(sock_fd, (
struct sockaddr *)&sin, sin_sz) == -1) {
332 _MSG(
"[%s]\n", request);
345 MSG(
"Dpi_get_server_port: can't read server port from dpid.\n");
354 if (strcmp(cmd,
"send_data") == 0) {
356 _MSG(
"Dpi_get_server_port: rply=%s\n", rply);
357 _MSG(
"Dpi_get_server_port: port_str=%s\n", port_str);
358 dpi_port = strtol(port_str, NULL, 10);
367 return ok ? dpi_port : -1;
373 struct sockaddr_in sin;
374 int sock_fd, dpi_port, ret = -1;
379 _MSG(
"Dpi_connect_socket:: can't get port number for %s\n", server_name);
382 _MSG(
"Dpi_connect_socket: server=%s port=%d\n", server_name, dpi_port);
385 memset(&sin, 0,
sizeof(sin));
386 sin.sin_family = AF_INET;
387 sin.sin_addr.s_addr = inet_addr(
"127.0.0.1");
388 sin.sin_port = htons(dpi_port);
391 perror(
"[dpi::socket]");
392 }
else if (connect(sock_fd, (
void*)&sin,
sizeof(sin)) == -1) {
393 MSG(
"[dpi::connect] errno:%d %s\n", errno,
dStrerror(errno));
397 MSG_ERR(
"[Dpi_connect_socket] Can't make auth message.\n");
399 MSG_ERR(
"[Dpi_connect_socket] Can't send auth message.\n");
404 if (sock_fd != -1 && ret == -1)
422 MSG_ERR(
"[a_Dpi_send_blocking_cmd] Can't connect to server.\n");
424 MSG_ERR(
"[a_Dpi_send_blocking_cmd] Can't send message.\n");
426 MSG_ERR(
"[a_Dpi_send_blocking_cmd] Can't read message.\n");
438 char *cmd, *dpip_tag;
442 "set_cookie", cookie,
446 "set_cookie", cookie,
450 _MSG(
"a_Cookies_set: dpip_tag = {%s}\n", dpip_tag);
459 char *cmd, *dpip_tag, *query;
462 "get_cookie", scheme,
466 _MSG(
"cookies.c: a_Dpi_send_blocking_cmd cmd = {%s}\n", cmd);
468 _MSG(
"cookies.c: after a_Dpi_send_blocking_cmd resp={%s}\n", dpip_tag);
471 if (dpip_tag != NULL) {
481static void expect(
int lineno,
const char *exp_reply,
482 const char *scheme,
const char *host,
const char *
path)
486 if (strcmp(reply, exp_reply)) {
487 MSG(
"line %d: EXPECTED: %s GOT: %s\n", lineno, exp_reply, reply);
518 expect(__LINE__,
"Cookie: 7=1; 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; "
519 "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; "
520 "20=1; 21=1\r\n",
"http",
"toomany.com",
"/path/");
523 expect(__LINE__,
"Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; "
524 "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; "
525 "20=1; 21=1\r\n",
"http",
"toomany.com",
"/");
528 expect(__LINE__,
"Cookie: 2=1; 3=1; 4=1; 5=1; 6=1; 8=1; 9=1; 10=1; "
529 "11=1; 12=1; 13=1; 14=1; 15=1; 16=1; 17=1; 18=1; 19=1; "
530 "20=1; 21=1; 22=1\r\n",
"http",
"toomany.com",
"/path/");
535 time_t t = time(NULL)+1000;
536 char *server_date =
dStrdup(ctime(&t));
538 a_Cookies_set(
"name=val; max-age=0",
"maxage0.com",
"/", NULL);
539 expect(__LINE__,
"",
"http",
"maxage0.com",
"/");
541 a_Cookies_set(
"name=val; max-age=-0",
"maxage-0.com",
"/", NULL);
542 expect(__LINE__,
"",
"http",
"maxage-0.com",
"/");
544 a_Cookies_set(
"name=val; max-age=100",
"maxage100.com",
"/", NULL);
545 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage100.com",
"/");
547 a_Cookies_set(
"name=val; max-age=-100",
"maxage-100.com",
"/", NULL);
548 expect(__LINE__,
"",
"http",
"maxage-100.com",
"/");
550 a_Cookies_set(
"name=val; max-age=2000000000",
"maxage2bil.com",
"/", NULL);
551 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage2bil.com",
"/");
553 a_Cookies_set(
"name=val; max-age=3000000000",
"maxage3bil.com",
"/", NULL);
554 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage3bil.com",
"/");
556 a_Cookies_set(
"name=val; max-age=7000000000",
"maxage7bil.com",
"/", NULL);
557 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage7bil.com",
"/");
559 a_Cookies_set(
"name=val; max-age=-2000000000",
"maxage-2bil.com",
"/",NULL);
560 expect(__LINE__,
"",
"http",
"maxage-2bil.com",
"/");
562 a_Cookies_set(
"name=val; max-age=-3000000000",
"maxage-3bil.com",
"/",NULL);
563 expect(__LINE__,
"",
"http",
"maxage-3bil.com",
"/");
565 a_Cookies_set(
"name=val; max-age=-7000000000",
"maxage-7bil.com",
"/",NULL);
566 expect(__LINE__,
"",
"http",
"maxage-7bil.com",
"/");
570 a_Cookies_set(
"name=val; max-age=0",
"maxage0s.com",
"/", server_date);
571 expect(__LINE__,
"",
"http",
"maxage0s.com",
"/");
573 a_Cookies_set(
"name=val; max-age=100",
"maxage100s.com",
"/", server_date);
574 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxage100s.com",
"/");
576 a_Cookies_set(
"name=val; max-age=-100",
"maxage-100s.com",
"/",server_date);
577 expect(__LINE__,
"",
"http",
"maxage-100s.com",
"/");
580 a_Cookies_set(
"name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010",
581 "maxagelater.com",
"/", NULL);
582 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxagelater.com",
"/");
584 a_Cookies_set(
"name=val; max-age=90; expires=Wed Jan 20 01:26:32 2010",
585 "maxagelaters.com",
"/", server_date);
586 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"maxagelaters.com",
"/");
594 time_t t = time(NULL)+1000;
595 char *server_date =
dStrdup(ctime(&t));
596 time_t expt = t + 1000;
597 char *exp_date =
dStrdup(ctime(&expt));
599 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
601 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e2000s1000.com",
"/");
604 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e2000s1000s.com",
"/");
608 exp_date =
dStrdup(ctime(&expt));
610 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
612 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e500s1000.com",
"/");
615 expect(__LINE__,
"",
"http",
"e500s1000s.com",
"/");
619 exp_date =
dStrdup(ctime(&expt));
621 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
623 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e1000s1000.com",
"/");
626 expect(__LINE__,
"",
"http",
"e1000s1000s.com",
"/");
630 exp_date =
dStrdup(ctime(&expt));
632 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
634 expect(__LINE__,
"",
"http",
"e0s1000.com",
"/");
637 expect(__LINE__,
"",
"http",
"e0s1000s.com",
"/");
646 time_t t = time(NULL)-1000;
647 char *server_date =
dStrdup(ctime(&t));
649 time_t expt = t + 1000;
650 char *exp_date =
dStrdup(ctime(&expt));
652 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
654 expect(__LINE__,
"",
"http",
"e0s-1000.com",
"/");
657 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e0s-1000s.com",
"/");
661 exp_date =
dStrdup(ctime(&expt));
663 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
665 expect(__LINE__,
"",
"http",
"e-500s-1000.com",
"/");
668 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"e-500s-1000s.com",
"/");
672 exp_date =
dStrdup(ctime(&expt));
674 string =
dStrconcat(
"name=val; expires=", exp_date, NULL);
676 expect(__LINE__,
"",
"http",
"e-1000s-1000.com",
"/");
678 a_Cookies_set(
string,
"e-1000s-1000s.com",
"/", server_date);
679 expect(__LINE__,
"",
"http",
"e-1000s-1000s.com",
"/");
690 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1801",
"expmin.com",
692 expect(__LINE__,
"",
"http",
"expmin.com",
"/");
694 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1901",
"expmin2.com",
696 expect(__LINE__,
"",
"http",
"expmin2.com",
"/");
698 a_Cookies_set(
"name=val; expires=Wed Dec 31 23:59:59 1969",
"expneg.com",
700 expect(__LINE__,
"",
"http",
"expneg.com",
"/");
702 a_Cookies_set(
"name=val; expires=Thu, 01-January-70 00:00:00 GMT",
703 "expepoch.com",
"/", NULL);
704 expect(__LINE__,
"",
"http",
"expepoch.com",
"/");
707 a_Cookies_set(
"name=val; expires=Tue Jan 19 03:14:07 2038",
"expmax.com",
709 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"expmax.com",
"/");
711 a_Cookies_set(
"name=val; expires=Sun January 1 00:00:00 2040",
712 "pastmax.com",
"/", NULL);
713 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"pastmax.com",
"/");
716 server_date =
dStrdup(ctime(&t));
718 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1901",
"expmina.com",
720 expect(__LINE__,
"",
"http",
"expmina.com",
"/");
722 a_Cookies_set(
"name=val; expires=Wed Dec 31 23:59:59 1969",
"expnega.com",
724 expect(__LINE__,
"",
"http",
"expnega.com",
"/");
726 a_Cookies_set(
"name=val; expires=Thu Jan 1 00:00:00 1970",
"expepocha.com",
728 expect(__LINE__,
"",
"http",
"expepocha.com",
"/");
730 a_Cookies_set(
"name=val; expires=Tue Jan 19 03:14:07 2038",
"expmaxa.com",
732 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"expmaxa.com",
"/");
734 a_Cookies_set(
"name=val; expires=Thu, 01-Jan-40 00:00:00 GMT",
735 "pastmaxa.com",
"/", server_date);
736 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"pastmaxa.com",
"/");
740 server_date =
dStrdup(ctime(&t));
742 a_Cookies_set(
"name=val; expires=Fri Dec 13 20:45:52 1901",
"expminb.com",
744 expect(__LINE__,
"",
"http",
"expminb.com",
"/");
746 a_Cookies_set(
"name=val; expires=Wed Dec 31 23:59:59 1969",
"expnegb.com",
748 expect(__LINE__,
"",
"http",
"expnegb.com",
"/");
750 a_Cookies_set(
"name=val; expires=Thu Jan 1 00:00:00 1970",
"expepochb.com",
752 expect(__LINE__,
"",
"http",
"expepochb.com",
"/");
754 a_Cookies_set(
"name=val; expires=Tue Jan 19 03:14:07 2038",
"expmaxb.com",
756 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"expmaxb.com",
"/");
758 a_Cookies_set(
"name=val; expires=Sun Jan 1 00:00:00 2040",
"pastmaxb.com",
760 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"pastmaxb.com",
"/");
773 a_Cookies_set(
"name=val; expires=Mon, 10-Dec-2037 17:02:24 GMT",
774 "format1.com",
"/", NULL);
775 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format1.com",
"/");
778 a_Cookies_set(
"name=val; expires=Wed, 09 Dec 2037 16:27:23 GMT",
779 "format2.com",
"/", NULL);
780 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format2.com",
"/");
786 a_Cookies_set(
"name=val; expires=Thursday, 01-Jan-2036 00:00:00 GMT",
787 "format3.com",
"/", NULL);
788 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format3.com",
"/");
791 a_Cookies_set(
"name=val; expires=Mon Dec 10 16:32:30 2037 GMT",
792 "format4.com",
"/", NULL);
793 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format4.com",
"/");
798 a_Cookies_set(
"name=val; expires=Wednesday, 01-Jan-37 00:00:00 GMT",
799 "format5.com",
"/", NULL);
800 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format5.com",
"/");
803 a_Cookies_set(
"name=val; expires=Mon, 10-Dec-37 20:35:03 GMT",
804 "format6.com",
"/", NULL);
805 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format6.com",
"/");
811 a_Cookies_set(
"name=val; expires=Wed, 1 Jan 2035 00:00:00 GMT",
812 "format7.com",
"/", NULL);
813 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format7.com",
"/");
816 a_Cookies_set(
"name=val; expires=Saturday, 8-Dec-2035 21:24:09 GMT",
817 "format8.com",
"/", NULL);
818 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format8.com",
"/");
824 a_Cookies_set(
"name=val; expires=Thu, 31 Dec 23:55:55 2037 GMT",
825 "format9.com",
"/", NULL);
826 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"format9.com",
"/");
831 a_Cookies_set(
"name=val; expires=Sun, 9 Dec 2036 13:42:05 GMT",
832 "formata.com",
"/", NULL);
833 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formata.com",
"/");
839 a_Cookies_set(
"name=val; expires=Wed Dec 12 2037 08:44:07 GMT-0500 (EST)",
840 "formatb.com",
"/", NULL);
841 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formatb.com",
"/");
843 a_Cookies_set(
"name=val; expires=Sun, 1-Jan-2035 00:00:00 GMT",
844 "formatc.com",
"/", NULL);
845 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formatc.com",
"/");
852 a_Cookies_set(
"name=val; expires=Sat, 07 Jul 2035 21:41:24 -0000",
853 "formatd.com",
"/", NULL);
854 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"formatd.com",
"/");
861 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p1.com",
"/");
863 a_Cookies_set(
"name=val; path=/dir1",
"p2.com",
"/dir2", NULL);
864 expect(__LINE__,
"",
"http",
"p2.com",
"/");
865 expect(__LINE__,
"",
"http",
"p2.com",
"/d");
866 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p2.com",
"/dir1");
867 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p2.com",
"/dir1/");
868 expect(__LINE__,
"",
"http",
"p2.com",
"/dir2");
869 expect(__LINE__,
"",
"http",
"p2.com",
"/dir11");
871 a_Cookies_set(
"name=val; path=dir1",
"p3.com",
"/dir2", NULL);
872 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p3.com",
"/");
873 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p3.com",
"/dir1");
874 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p3.com",
"/dir2");
876 a_Cookies_set(
"name=val; path=/dir1/",
"p4.com",
"/dir2", NULL);
877 expect(__LINE__,
"",
"http",
"p4.com",
"/");
880 expect(__LINE__,
"",
"http",
"p4.com",
"/dir1");
881 expect(__LINE__,
"",
"http",
"p4.com",
"/dir11");
882 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p4.com",
"/dir1/");
883 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p4.com",
"/dir1/sub");
886 expect(__LINE__,
"",
"http",
"p5.com",
"/");
887 expect(__LINE__,
"",
"http",
"p5.com",
"/bir");
888 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p5.com",
"/dir");
889 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p5.com",
"/dir/");
892 expect(__LINE__,
"",
"http",
"p6.com",
"/dir/");
893 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p6.com",
"/dir/subdir");
894 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"p6.com",
"/dir/subdir/s");
899 const int line_maxlen = 4096;
902 char line[line_maxlen];
907 stream = fopen(filename,
"r");
911 MSG_ERR(
"Cannot run test; cannot open cookiesrc.\n");
916 while (!feof(stream)) {
920 rc = fgets(line, line_maxlen, stream);
921 if (!rc && ferror(stream)) {
922 MSG_ERR(
"Error while reading rule from cookiesrc: %s\n",
931 if (line[0] !=
'\0' && line[0] !=
'#') {
932 int domain_end, i = 0;
936 while (line[i] !=
'\0' && !
dIsspace(line[i]))
943 line[domain_end] =
'\0';
947 while (line[i] !=
'\0' && !
dIsspace(line[i]))
957 MSG_WARN(
"DENY rules in cookiesrc can interfere with test.\n");
964 MSG_ERR(
"Cannot run test with cookiesrc default of deny.\n");
974 MSG(
"If you change cookiesrc, remember to stop the DPIs via dpidc.\n");
979 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"ordinary.com",
"/");
988 a_Cookies_set(
"name=val; expires=\"Sun Jan 10 00:00:00 2038\"",
989 "quoted-date.org",
"/", NULL);
990 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"quoted-date.org",
"/");
992 a_Cookies_set(
"name=val; expires=\"Sun Jan 11 00:00:00 1970\"",
993 "quoted-pastdate.org",
"/", NULL);
994 expect(__LINE__,
"",
"http",
"quoted-pastdate.org",
"/");
999 a_Cookies_set(
"name=val; domain=co.il",
"www.co.il",
"/", NULL);
1000 expect(__LINE__,
"",
"http",
"www.co.il",
"/");
1002 a_Cookies_set(
"name=val; domain=.co.il",
"www.co.il",
"/", NULL);
1003 expect(__LINE__,
"",
"http",
"www.co.il",
"/");
1005 a_Cookies_set(
"name=val; domain=co.il.",
"www.co.il.",
"/", NULL);
1006 expect(__LINE__,
"",
"http",
"www.co.il.",
"/");
1008 a_Cookies_set(
"name=val; domain=.co.il.",
"www.co.il.",
"/", NULL);
1009 expect(__LINE__,
"",
"http",
".www.co.il.",
"/");
1011 a_Cookies_set(
"name=val; domain=co.org",
"www.co.org",
"/", NULL);
1012 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"www.co.org",
"/");
1014 a_Cookies_set(
"name=val; domain=.cp.org",
"www.cp.org",
"/", NULL);
1015 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"www.cp.org",
"/");
1019 a_Cookies_set(
"name=val; domain=.dotdomain.org",
"dotdomain.org",
"/",
1021 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"dotdomain.org",
"/");
1022 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"www.dotdomain.org",
"/");
1025 a_Cookies_set(
"name=val; domain=.hostonly.org",
"hostonly.org",
"/", NULL);
1027 a_Cookies_set(
"name3=val3; domain=hostonly.org",
"hostonly.org",
"/", NULL);
1028 expect(__LINE__,
"Cookie: name=val; name2=val2; name3=val3\r\n",
"http",
1029 "hostonly.org",
"/");
1030 a_Cookies_set(
"name=new; domain=.hostonly.org",
"hostonly.org",
"/", NULL);
1031 expect(__LINE__,
"Cookie: name=new; name2=val2; name3=val3\r\n",
"http",
1032 "hostonly.org",
"/");
1034 expect(__LINE__,
"Cookie: name=new; name2=new2; name3=val3\r\n",
"http",
1035 "hostonly.org",
"/");
1036 a_Cookies_set(
"name3=new3; domain=hostonly.org",
"hostonly.org",
"/", NULL);
1037 expect(__LINE__,
"Cookie: name=new; name2=new2; name3=new3\r\n",
"http",
1038 "hostonly.org",
"/");
1041 a_Cookies_set(
"name=val; domain=www.subdomain.com",
"subdomain.com",
"/",
1043 a_Cookies_set(
"name=val; domain=.www.subdomain.com",
"subdomain.com",
"/",
1045 expect(__LINE__,
"",
"http",
"subdomain.com",
"/");
1046 expect(__LINE__,
"",
"http",
"www.subdomain.com",
"/");
1049 a_Cookies_set(
"name=val; domain=.supdomain.com",
"www.supdomain.com",
"/",
1051 a_Cookies_set(
"name2=val2; domain=supdomain.com",
"www.supdomain.com",
"/",
1053 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1054 "sub2.sub.supdomain.com",
"/");
1055 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1056 "www.supdomain.com",
"/");
1057 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1058 "supdomain.com",
"/");
1061 a_Cookies_set(
"name=val; domain=another.com",
"unrelated.com",
"/", NULL);
1062 expect(__LINE__,
"",
"http",
"another.com",
"/");
1063 a_Cookies_set(
"name=val; domain=another.com",
"a.org",
"/", NULL);
1064 expect(__LINE__,
"",
"http",
"another.com",
"/");
1065 a_Cookies_set(
"name=val; domain=another.com",
"badguys.com",
"/", NULL);
1066 expect(__LINE__,
"",
"http",
"another.com",
"/");
1067 a_Cookies_set(
"name=val; domain=another.com",
"more.badguys.com",
"/",
1069 expect(__LINE__,
"",
"http",
"another.com",
"/");
1070 a_Cookies_set(
"name=val; domain=another.com",
"verybadguys.com",
"/", NULL);
1071 expect(__LINE__,
"",
"http",
"another.com",
"/");
1073 a_Cookies_set(
"name=val; domain=similar.com",
"imilar.com",
"/", NULL);
1074 a_Cookies_set(
"name2=val2; domain=similar.com",
"ssimilar.com",
"/", NULL);
1075 a_Cookies_set(
"name3=val3; domain=.similar.com",
"imilar.com",
"/", NULL);
1076 a_Cookies_set(
"name4=val4; domain=.similar.com",
"timilar.com",
"/", NULL);
1077 a_Cookies_set(
"name4=val4; domain=.similar.com",
"tiimilar.com",
"/", NULL);
1078 expect(__LINE__,
"",
"http",
"similar.com",
"/");
1082 expect(__LINE__,
"",
"http",
"secure.com",
"/");
1083 expect(__LINE__,
"Cookie: name=val\r\n",
"https",
"secure.com",
"/");
1086 a_Cookies_set(
"name=val; HttpOnly",
"httponly.net",
"/", NULL);
1087 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"httponly.net",
"/");
1090 a_Cookies_set(
"name=val; ldkfals",
"gibberish.net",
"/", NULL);
1091 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"gibberish.net",
"/");
1096 expect(__LINE__,
"Cookie: name=val; name2=val2\r\n",
"http",
1097 "whitespace.net",
"/");
1103 expect(__LINE__,
"Cookie: name=; name2=\r\n",
"http",
"nonameval.org",
"/");
1105 expect(__LINE__,
"Cookie: name=; name2=\r\n",
"http",
"nonameval.org",
"/");
1110 a_Cookies_set(
"name=val",
"FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
1112 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
1113 "FEDC:BA98:7654:3210:FEDC:BA98:7654:3210",
"/");
1115 a_Cookies_set(
"name=val",
"::FFFF:129.144.52.38",
"/", NULL);
1116 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"::FFFF:129.144.52.38",
1120 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"127.0.0.1",
"/");
1122 a_Cookies_set(
"name=val; domain=128.0.0.1",
"128.0.0.1",
"/", NULL);
1123 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"128.0.0.1",
"/");
1125 a_Cookies_set(
"name=val; domain=130.0.0.1",
"129.0.0.1",
"/", NULL);
1126 expect(__LINE__,
"",
"http",
"129.0.0.1",
"/");
1127 expect(__LINE__,
"",
"http",
"130.0.0.1",
"/");
1130 a_Cookies_set(
"name=bad; domain=22.0.0.1",
"2.0.0.1",
"/", NULL);
1131 a_Cookies_set(
"name=bad; domain=.0.0.1",
"2.0.0.1",
"/", NULL);
1132 a_Cookies_set(
"name=bad; domain=not-ip.org",
"2.0.0.1",
"/", NULL);
1133 expect(__LINE__,
"",
"http",
"22.0.0.1",
"/");
1134 expect(__LINE__,
"",
"http",
"not-ip.org",
"/");
1135 expect(__LINE__,
"Cookie: name=val\r\n",
"http",
"2.0.0.1",
"/");
1138HAD BEEN PLAYING AROUND WITH REAL PUBLIC SUFFIX
1139a_Cookies_set(
"name=val;domain=sub.sub.yokohama.jp",
"sub.sub.yokohama.jp",
"/", NULL);
1140MSG(
"sub sub yokohama should work: %s\n",
1142a_Cookies_set(
"name=val; domain=sub.tokyo.jp",
"sub.sub.tokyo.jp",
"/", NULL);
1143MSG(
"sub tokyo jp should fail: %s\n",
1145a_Cookies_set(
"name=val; domain=pref.chiba.jp",
"sub.pref.chiba.jp",
"/", NULL);
1146MSG(
"pref chiba jp should succeed: %s\n",
1148a_Cookies_set(
"name=val; domain=org",
"www.dillo.org",
"/", NULL);
1149a_Cookies_set(
"name=val; domain=org",
"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);
1153MSG(
"org should fail: %s\n",
1159 MSG(
"Now that everything is full of fake cookies, you should run "
1160 "'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)
static int dIsspace(unsigned char c)
#define dReturn_val_if_fail(expr, val)
static int dIsxdigit(unsigned char c)
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.
void a_Cookies_set(Dlist *cookie_strings, const DilloUrl *set_url, const char *date)
Set the value corresponding to the cookie string.
char * a_Cookies_get_query(const DilloUrl *query_url, const DilloUrl *requester, int is_root_url)
Return a string containing cookie data for an HTTP query.
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)