Lines Matching refs:req
135 static int ProcessRequest(struct httprequest *req);
242 static int parse_cmdfile(struct httprequest *req) in parse_cmdfile() argument
251 req->testno = testnum; in parse_cmdfile()
260 static int parse_servercmd(struct httprequest *req) in parse_servercmd() argument
265 stream = test2fopen(req->testno, logdir); in parse_servercmd()
266 req->close = FALSE; in parse_servercmd()
267 req->connmon = FALSE; in parse_servercmd()
272 logmsg(" Couldn't open test file %ld", req->testno); in parse_servercmd()
273 req->open = FALSE; /* closes connection */ in parse_servercmd()
287 req->open = FALSE; /* closes connection */ in parse_servercmd()
297 req->auth_req = TRUE; in parse_servercmd()
301 req->rcmd = RCMD_IDLE; in parse_servercmd()
302 req->open = TRUE; in parse_servercmd()
306 req->rcmd = RCMD_STREAM; in parse_servercmd()
311 req->connmon = TRUE; in parse_servercmd()
315 req->upgrade = TRUE; in parse_servercmd()
319 req->close = TRUE; in parse_servercmd()
323 req->skip = num; in parse_servercmd()
327 req->noexpect = TRUE; in parse_servercmd()
331 req->delay = num; in parse_servercmd()
335 req->writedelay = num; in parse_servercmd()
364 static int ProcessRequest(struct httprequest *req) in ProcessRequest() argument
366 char *line = &req->reqbuf[req->checkindex]; in ProcessRequest()
374 req->callcount++; in ProcessRequest()
376 logmsg("Process %zu bytes request%s", req->offset, in ProcessRequest()
377 req->callcount > 1 ? " [CONTINUED]" : ""); in ProcessRequest()
383 (req->testno == DOCNUMBER_NOTHING) && in ProcessRequest()
386 req->testno = DOCNUMBER_WERULEZ; in ProcessRequest()
390 else if(req->testno == DOCNUMBER_NOTHING) { in ProcessRequest()
424 req->prot_version = prot_major*10 + prot_minor; in ProcessRequest()
446 req->testno = DOCNUMBER_WERULEZ; in ProcessRequest()
452 req->testno = DOCNUMBER_QUIT; in ProcessRequest()
458 req->testno = strtol(ptr, &ptr, 10); in ProcessRequest()
460 if(req->testno > 10000) { in ProcessRequest()
461 req->partno = req->testno % 10000; in ProcessRequest()
462 req->testno /= 10000; in ProcessRequest()
465 req->partno = 0; in ProcessRequest()
467 if(req->testno) { in ProcessRequest()
470 req->testno, req->partno); in ProcessRequest()
475 req->testno = DOCNUMBER_NOTHING; in ProcessRequest()
480 if(req->testno == DOCNUMBER_NOTHING) { in ProcessRequest()
484 if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d", in ProcessRequest()
493 req->connect_request = TRUE; in ProcessRequest()
495 if(req->prot_version == 10) in ProcessRequest()
496 req->open = FALSE; /* HTTP 1.0 closes connection by default */ in ProcessRequest()
518 req->testno = part; in ProcessRequest()
528 req->connect_port = curlx_ultous(ulnum); in ProcessRequest()
532 req->connect_port, req->testno); in ProcessRequest()
536 if(req->testno == DOCNUMBER_NOTHING) in ProcessRequest()
538 parse_cmdfile(req); in ProcessRequest()
540 if(req->testno == DOCNUMBER_NOTHING) { in ProcessRequest()
542 req->testno = DOCNUMBER_404; in ProcessRequest()
545 parse_servercmd(req); in ProcessRequest()
547 else if((req->offset >= 3)) { in ProcessRequest()
559 logmsg("- request found to be complete (%ld)", req->testno); in ProcessRequest()
561 if(req->testno == DOCNUMBER_NOTHING) { in ProcessRequest()
565 req->testno = strtol(&testno[9], NULL, 10); in ProcessRequest()
566 logmsg("Found test number %ld in Testno: header!", req->testno); in ProcessRequest()
574 parse_servercmd(req); in ProcessRequest()
591 req->testno = strtol(ptr, &ptr, 10); in ProcessRequest()
593 if(req->testno > 10000) { in ProcessRequest()
594 req->partno = req->testno % 10000; in ProcessRequest()
595 req->testno /= 10000; in ProcessRequest()
598 req->partno = 0; in ProcessRequest()
602 req->testno, req->partno); in ProcessRequest()
622 if((req->cl == 0) && strncasecompare("Content-Length:", line, 15)) { in ProcessRequest()
638 req->open = FALSE; /* closes connection */ in ProcessRequest()
641 if(req->skipall) in ProcessRequest()
642 req->cl = 0; in ProcessRequest()
644 req->cl = clen - req->skip; in ProcessRequest()
647 if(req->skip) in ProcessRequest()
648 logmsg("... but will abort after %zu bytes", req->cl); in ProcessRequest()
655 else if(req->noexpect && in ProcessRequest()
658 if(req->cl) in ProcessRequest()
659 req->cl = 0; in ProcessRequest()
660 req->skipall = TRUE; in ProcessRequest()
665 if(strstr(req->reqbuf, "\r\n0\r\n\r\n")) { in ProcessRequest()
669 else if(strstr(req->reqbuf, "\r\n0\r\n")) { in ProcessRequest()
670 char *last_crlf_char = strstr(req->reqbuf, "\r\n\r\n"); in ProcessRequest()
677 last_crlf_char > strstr(req->reqbuf, "\r\n0\r\n")) in ProcessRequest()
682 else if(already_recv_zeroed_chunk && strstr(req->reqbuf, "\r\n\r\n")) in ProcessRequest()
694 if(!req->auth && strstr(req->reqbuf, "Authorization:")) { in ProcessRequest()
695 req->auth = TRUE; /* Authorization: header present! */ in ProcessRequest()
696 if(req->auth_req) in ProcessRequest()
700 if(strstr(req->reqbuf, "Authorization: Negotiate")) { in ProcessRequest()
706 if(req->testno != prev_testno) { in ProcessRequest()
707 prev_testno = req->testno; in ProcessRequest()
708 prev_partno = req->partno; in ProcessRequest()
711 req->partno = prev_partno; in ProcessRequest()
713 else if(!req->digest && strstr(req->reqbuf, "Authorization: Digest")) { in ProcessRequest()
717 req->partno += 1000; in ProcessRequest()
718 req->digest = TRUE; /* header found */ in ProcessRequest()
719 logmsg("Received Digest request, sending back data %ld", req->partno); in ProcessRequest()
721 else if(!req->ntlm && in ProcessRequest()
722 strstr(req->reqbuf, "Authorization: NTLM TlRMTVNTUAAD")) { in ProcessRequest()
724 req->partno += 1002; in ProcessRequest()
725 req->ntlm = TRUE; /* NTLM found */ in ProcessRequest()
726 logmsg("Received NTLM type-3, sending back data %ld", req->partno); in ProcessRequest()
727 if(req->cl) { in ProcessRequest()
728 logmsg(" Expecting %zu POSTed bytes", req->cl); in ProcessRequest()
731 else if(!req->ntlm && in ProcessRequest()
732 strstr(req->reqbuf, "Authorization: NTLM TlRMTVNTUAAB")) { in ProcessRequest()
734 req->partno += 1001; in ProcessRequest()
735 req->ntlm = TRUE; /* NTLM found */ in ProcessRequest()
736 logmsg("Received NTLM type-1, sending back data %ld", req->partno); in ProcessRequest()
738 else if((req->partno >= 1000) && in ProcessRequest()
739 strstr(req->reqbuf, "Authorization: Basic")) { in ProcessRequest()
743 req->partno += 1; in ProcessRequest()
744 logmsg("Received Basic request, sending back data %ld", req->partno); in ProcessRequest()
746 if(strstr(req->reqbuf, "Connection: close")) in ProcessRequest()
747 req->open = FALSE; /* close connection after this request */ in ProcessRequest()
749 if(req->open && in ProcessRequest()
750 req->prot_version >= 11 && in ProcessRequest()
751 req->reqbuf + req->offset > end + strlen(end_of_headers) && in ProcessRequest()
752 !req->cl && in ProcessRequest()
753 (!strncmp(req->reqbuf, "GET", strlen("GET")) || in ProcessRequest()
754 !strncmp(req->reqbuf, "HEAD", strlen("HEAD")))) { in ProcessRequest()
757 req->checkindex = (end - req->reqbuf) + strlen(end_of_headers); in ProcessRequest()
764 if(req->auth_req && !req->auth) { in ProcessRequest()
769 if(req->upgrade && strstr(req->reqbuf, "Upgrade:")) { in ProcessRequest()
772 req->upgrade_request = TRUE; in ProcessRequest()
776 if(req->cl > 0) { in ProcessRequest()
777 if(req->cl <= req->offset - (end - req->reqbuf) - strlen(end_of_headers)) in ProcessRequest()
843 static void init_httprequest(struct httprequest *req) in init_httprequest() argument
845 req->checkindex = 0; in init_httprequest()
846 req->offset = 0; in init_httprequest()
847 req->testno = DOCNUMBER_NOTHING; in init_httprequest()
848 req->partno = 0; in init_httprequest()
849 req->connect_request = FALSE; in init_httprequest()
850 req->open = TRUE; in init_httprequest()
851 req->auth_req = FALSE; in init_httprequest()
852 req->auth = FALSE; in init_httprequest()
853 req->cl = 0; in init_httprequest()
854 req->digest = FALSE; in init_httprequest()
855 req->ntlm = FALSE; in init_httprequest()
856 req->skip = 0; in init_httprequest()
857 req->skipall = FALSE; in init_httprequest()
858 req->noexpect = FALSE; in init_httprequest()
859 req->delay = 0; in init_httprequest()
860 req->writedelay = 0; in init_httprequest()
861 req->rcmd = RCMD_NORMALREQ; in init_httprequest()
862 req->prot_version = 0; in init_httprequest()
863 req->callcount = 0; in init_httprequest()
864 req->connect_port = 0; in init_httprequest()
865 req->done_processing = 0; in init_httprequest()
866 req->upgrade = 0; in init_httprequest()
867 req->upgrade_request = 0; in init_httprequest()
870 static int send_doc(curl_socket_t sock, struct httprequest *req);
874 static int get_request(curl_socket_t sock, struct httprequest *req) in get_request() argument
877 char *reqbuf = req->reqbuf; in get_request()
881 if(req->upgrade_request) { in get_request()
884 send_doc(sock, req); in get_request()
887 reqbuf[req->offset] = '\0'; in get_request()
888 storerequest(reqbuf, req->offset); in get_request()
889 req->offset = 0; in get_request()
892 if(req->open) { in get_request()
895 got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset); in get_request()
897 req->offset += got; in get_request()
925 if(req->offset) { in get_request()
928 reqbuf[req->offset] = '\0'; in get_request()
929 storerequest(reqbuf, req->offset); in get_request()
930 req->offset = 0; in get_request()
932 init_httprequest(req); in get_request()
937 if(req->offset >= REQBUFSIZ-1) { in get_request()
942 if(req->skip) in get_request()
946 got = sread(sock, reqbuf + req->offset, req->cl); in get_request()
948 got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset); in get_request()
967 reqbuf[req->offset] = '\0'; in get_request()
968 storerequest(reqbuf, req->offset); in get_request()
974 req->offset += (size_t)got; in get_request()
975 reqbuf[req->offset] = '\0'; in get_request()
977 req->done_processing = ProcessRequest(req); in get_request()
982 if(overflow || (req->offset == REQBUFSIZ-1 && got > 0)) { in get_request()
988 else if(req->offset > REQBUFSIZ-1) { in get_request()
995 reqbuf[req->offset] = '\0'; in get_request()
998 if(fail || req->done_processing) in get_request()
999 storerequest(reqbuf, req->offset); in get_request()
1007 static int send_doc(curl_socket_t sock, struct httprequest *req) in send_doc() argument
1028 switch(req->rcmd) { in send_doc()
1050 req->open = FALSE; in send_doc()
1052 if(req->testno < 0) { in send_doc()
1056 switch(req->testno) { in send_doc()
1089 const char *section = req->connect_request ? "connect" : "data"; in send_doc()
1091 if(req->partno) in send_doc()
1092 msnprintf(partbuf, sizeof(partbuf), "%s%ld", section, req->partno); in send_doc()
1096 logmsg("Send response test%ld section <%s>", req->testno, partbuf); in send_doc()
1098 stream = test2fopen(req->testno, logdir); in send_doc()
1120 stream = test2fopen(req->testno, logdir); in send_doc()
1148 if(strstr(buffer, "swsclose") || !count || req->close) { in send_doc()
1195 if(req->writedelay) { in send_doc()
1196 int msecs_left = req->writedelay; in send_doc()
1229 prevtestno = req->testno; in send_doc()
1230 prevpartno = req->partno; in send_doc()
1275 req->open = use_gopher ? FALSE : persistent; in send_doc()
1277 prevtestno = req->testno; in send_doc()
1278 prevpartno = req->partno; in send_doc()
1830 static void http_upgrade(struct httprequest *req) in http_upgrade() argument
1832 (void)req; in http_upgrade()
1833 logmsg("Upgraded to ... %u", req->upgrade_request); in http_upgrade()
1919 static int service_connection(curl_socket_t msgsock, struct httprequest *req, in service_connection() argument
1927 while(!req->done_processing) { in service_connection()
1928 int rc = get_request(msgsock, req); in service_connection()
1937 if((req->testno == prevtestno) && in service_connection()
1938 (req->partno == prevpartno)) { in service_connection()
1939 req->partno++; in service_connection()
1940 logmsg("BOUNCE part number to %ld", req->partno); in service_connection()
1949 send_doc(msgsock, req); in service_connection()
1953 if(req->testno < 0) { in service_connection()
1957 if(!req->open) { in service_connection()
1962 if(req->connect_request) { in service_connection()
1969 http_connect(&msgsock, listensock, connecthost, req->connect_port, in service_connection()
1975 if(req->upgrade_request) { in service_connection()
1977 http_upgrade(req); in service_connection()
1983 if(req->open) { in service_connection()
2008 struct httprequest *req = NULL; in main() local
2175 req = calloc(1, sizeof(*req)); in main()
2176 if(!req) in main()
2321 init_httprequest(req); in main()
2387 if(req->delay) in main()
2388 wait_ms(req->delay); in main()
2402 rc = service_connection(all_sockets[socket_idx], req, sock, in main()
2408 logmsg("====> Client disconnect %d", req->connmon); in main()
2410 if(req->connmon) { in main()
2415 if(!req->open) in main()
2431 if(req->testno == DOCNUMBER_QUIT) in main()
2436 if(rc && !req->upgrade_request) in main()
2450 init_httprequest(req); in main()
2476 free(req); in main()