/* return 0 on success, non-zero on failure */ static int get_request(int sock, struct httprequest *req) { int fail= FALSE; char *reqbuf = req->reqbuf; /*** Init the httpreqest structure properly for the upcoming request ***/ memset(req, 0, sizeof(struct httprequest)); /* here's what should not be 0 from the start */ req->testno = DOCNUMBER_NOTHING; /* safe default */ req->open = TRUE; /* connection should remain open and wait for more commands */ /*** end of httprequest init ***/ while (req->offset < REQBUFSIZ) { int got = sread(sock, reqbuf + req->offset, REQBUFSIZ - req->offset); if (got <= 0) { if (got < 0) { perror("recv"); logmsg("recv() returned error"); return DOCNUMBER_INTERNAL; } logmsg("Connection closed by client"); reqbuf[req->offset]=0; /* dump the request receivied so far to the external file */ storerequest(reqbuf); return DOCNUMBER_INTERNAL; } req->offset += got; reqbuf[req->offset] = 0; if(ProcessRequest(req)) break; } if (req->offset >= REQBUFSIZ) { logmsg("Request buffer overflow, closing connection"); reqbuf[REQBUFSIZ-1]=0; fail = TRUE; /* dump the request to an external file anyway */ } else reqbuf[req->offset]=0; /* dump the request to an external file */ storerequest(reqbuf); return fail; /* success */ }
/* return 0 on success, non-zero on failure */ static int get_request(curl_socket_t sock, struct httprequest *req) { int error; int fail = 0; int done_processing = 0; char *reqbuf = req->reqbuf; ssize_t got = 0; char *pipereq = NULL; size_t pipereq_length = 0; if(req->pipelining) { pipereq = reqbuf + req->checkindex; pipereq_length = req->offset - req->checkindex; } /*** Init the httprequest structure properly for the upcoming request ***/ req->checkindex = 0; req->offset = 0; req->testno = DOCNUMBER_NOTHING; req->partno = 0; req->open = TRUE; req->auth_req = FALSE; req->auth = FALSE; req->cl = 0; req->digest = FALSE; req->ntlm = FALSE; req->pipe = 0; req->skip = 0; req->rcmd = RCMD_NORMALREQ; req->protocol = RPROT_NONE; req->prot_version = 0; req->pipelining = FALSE; req->rtp_buffer = NULL; req->rtp_buffersize = 0; /*** end of httprequest init ***/ while(!done_processing && (req->offset < REQBUFSIZ-1)) { if(pipereq_length && pipereq) { memmove(reqbuf, pipereq, pipereq_length); got = pipereq_length; pipereq_length = 0; } else { if(req->skip) /* we are instructed to not read the entire thing, so we make sure to only read what we're supposed to and NOT read the enire thing the client wants to send! */ got = sread(sock, reqbuf + req->offset, req->cl); else got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset); } if(got_exit_signal) return 1; if(got == 0) { logmsg("Connection closed by client"); fail = 1; } else if(got < 0) { error = SOCKERRNO; logmsg("recv() returned error: (%d) %s", error, strerror(error)); fail = 1; } if(fail) { /* dump the request received so far to the external file */ reqbuf[req->offset] = '\0'; storerequest(reqbuf, req->offset); return 1; } logmsg("Read %zd bytes", got); req->offset += (size_t)got; reqbuf[req->offset] = '\0'; done_processing = ProcessRequest(req); if(got_exit_signal) return 1; if(done_processing && req->pipe) { logmsg("Waiting for another piped request"); done_processing = 0; req->pipe--; } } if((req->offset == REQBUFSIZ-1) && (got > 0)) { logmsg("Request would overflow buffer, closing connection"); /* dump request received so far to external file anyway */ reqbuf[REQBUFSIZ-1] = '\0'; fail = 1; } else if(req->offset > REQBUFSIZ-1) { logmsg("Request buffer overflow, closing connection"); /* dump request received so far to external file anyway */ reqbuf[REQBUFSIZ-1] = '\0'; fail = 1; } else reqbuf[req->offset] = '\0'; /* dump the request to an external file */ storerequest(reqbuf, req->pipelining ? req->checkindex : req->offset); if(got_exit_signal) return 1; return fail; /* return 0 on success */ }
/* return 0 on success, non-zero on failure */ static int get_request(curl_socket_t sock, struct httprequest *req) { int fail = 0; char *reqbuf = req->reqbuf; ssize_t got = 0; char *pipereq; int pipereq_length = 0; if(req->pipelining) { pipereq = reqbuf + req->checkindex; pipereq_length = req->offset - req->checkindex; } /*** Init the httpreqest structure properly for the upcoming request ***/ req->checkindex = 0; req->offset = 0; req->testno = DOCNUMBER_NOTHING; req->partno = 0; req->open = TRUE; req->auth_req = FALSE; req->auth = FALSE; req->cl = 0; req->digest = FALSE; req->ntlm = FALSE; req->pipe = 0; req->rcmd = RCMD_NORMALREQ; req->prot_version = 0; req->pipelining = FALSE; /*** end of httprequest init ***/ while (req->offset < REQBUFSIZ-1) { if(pipereq_length) { memmove(reqbuf, pipereq, pipereq_length); got = pipereq_length; pipereq_length = 0; } else got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset); if (got <= 0) { if (got < 0) { logmsg("recv() returned error: %d", SOCKERRNO); return DOCNUMBER_INTERNAL; } logmsg("Connection closed by client"); reqbuf[req->offset] = '\0'; /* dump the request receivied so far to the external file */ storerequest(reqbuf, req->offset); return DOCNUMBER_INTERNAL; } logmsg("Read %d bytes", got); req->offset += got; reqbuf[req->offset] = '\0'; if(ProcessRequest(req)) { if(req->pipe--) { logmsg("Waiting for another piped request"); continue; } break; } } if((req->offset == REQBUFSIZ-1) && (got > 0)) { logmsg("Request would overflow buffer, closing connection"); /* dump request received so far to external file anyway */ reqbuf[REQBUFSIZ-1] = '\0'; fail = 1; } else if(req->offset > REQBUFSIZ-1) { logmsg("Request buffer overflow, closing connection"); /* dump request received so far to external file anyway */ reqbuf[REQBUFSIZ-1] = '\0'; fail = 1; } else reqbuf[req->offset] = '\0'; /* dump the request to an external file */ storerequest(reqbuf, req->pipelining ? req->checkindex : req->offset); return fail; /* return 0 on success */ }
static int get_request(int sock, int *part) { static char reqbuf[REQBUFSIZ], doc[MAXDOCNAMELEN]; static char request[REQUEST_KEYWORD_SIZE]; unsigned int offset = 0; int prot_major, prot_minor; char logbuf[256]; *part = 0; /* part zero equals none */ while (offset < REQBUFSIZ) { int got = recv(sock, reqbuf + offset, REQBUFSIZ - offset, 0); if (got <= 0) { if (got < 0) { perror("recv"); return -1; } logmsg("Connection closed by client"); return -1; } offset += got; reqbuf[offset] = 0; if(ProcessRequest(reqbuf)) break; } if (offset >= REQBUFSIZ) { logmsg("Request buffer overflow, closing connection"); return -1; } reqbuf[offset]=0; logmsg("Received a request"); /* dump the request to an external file */ storerequest(reqbuf); if (sscanf(reqbuf, "%" REQBUFSIZ_TXT"s %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d", request, doc, &prot_major, &prot_minor) == 4) { char *ptr; int test_no=0; /* find the last slash */ ptr = strrchr(doc, '/'); /* get the number after it */ if(ptr) { if((strlen(doc) + strlen(request)) < 200) sprintf(logbuf, "Got request: %s %s HTTP/%d.%d", request, doc, prot_major, prot_minor); else sprintf(logbuf, "Got a *HUGE* request HTTP/%d.%d", prot_major, prot_minor); logmsg(logbuf); if(!strncmp("/verifiedserver", ptr, 15)) { logmsg("Are-we-friendly question received"); return -2; } ptr++; /* skip the slash */ test_no = strtol(ptr, &ptr, 10); if(test_no > 10000) { *part = test_no % 10000; test_no /= 10000; } sprintf(logbuf, "Found test number %d in path", test_no); logmsg(logbuf); } else { logmsg("Did not find test number in PATH"); } return test_no; } logmsg("Got illegal request"); fprintf(stderr, "Got illegal request\n"); return -1; }