sws: support <servercmd> for CONNECT requests
I moved out the servercmd parsing into a its own function called parse_servercmd() and made sure it gets used also when the test number is extracted from CONNECT requests. It turned out sws didn't do that previously!
This commit is contained in:
parent
6398c8bba8
commit
176f7ea3bb
@ -314,91 +314,12 @@ static void restore_signal_handlers(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ProcessRequest(struct httprequest *req)
|
/* based on the testno, parse the correct server commands */
|
||||||
|
static int parse_servercmd(struct httprequest *req)
|
||||||
{
|
{
|
||||||
char *line=&req->reqbuf[req->checkindex];
|
|
||||||
bool chunked = FALSE;
|
|
||||||
static char request[REQUEST_KEYWORD_SIZE];
|
|
||||||
static char doc[MAXDOCNAMELEN];
|
|
||||||
char logbuf[456];
|
|
||||||
int prot_major, prot_minor;
|
|
||||||
char *end;
|
|
||||||
int error;
|
|
||||||
end = strstr(line, end_of_headers);
|
|
||||||
|
|
||||||
req->callcount++;
|
|
||||||
|
|
||||||
logmsg("Process %d bytes request%s", req->offset,
|
|
||||||
req->callcount > 1?" [CONTINUED]":"");
|
|
||||||
|
|
||||||
/* try to figure out the request characteristics as soon as possible, but
|
|
||||||
only once! */
|
|
||||||
|
|
||||||
if(use_gopher &&
|
|
||||||
(req->testno == DOCNUMBER_NOTHING) &&
|
|
||||||
!strncmp("/verifiedserver", line, 15)) {
|
|
||||||
logmsg("Are-we-friendly question received");
|
|
||||||
req->testno = DOCNUMBER_WERULEZ;
|
|
||||||
return 1; /* done */
|
|
||||||
}
|
|
||||||
|
|
||||||
else if((req->testno == DOCNUMBER_NOTHING) &&
|
|
||||||
sscanf(line,
|
|
||||||
"%" REQUEST_KEYWORD_SIZE_TXT"s %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
|
|
||||||
request,
|
|
||||||
doc,
|
|
||||||
&prot_major,
|
|
||||||
&prot_minor) == 4) {
|
|
||||||
char *ptr;
|
|
||||||
|
|
||||||
req->prot_version = prot_major*10 + prot_minor;
|
|
||||||
|
|
||||||
/* find the last slash */
|
|
||||||
ptr = strrchr(doc, '/');
|
|
||||||
|
|
||||||
/* get the number after it */
|
|
||||||
if(ptr) {
|
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
char *filename;
|
char *filename;
|
||||||
|
int error;
|
||||||
if((strlen(doc) + strlen(request)) < 400)
|
|
||||||
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("%s", logbuf);
|
|
||||||
|
|
||||||
if(!strncmp("/verifiedserver", ptr, 15)) {
|
|
||||||
logmsg("Are-we-friendly question received");
|
|
||||||
req->testno = DOCNUMBER_WERULEZ;
|
|
||||||
return 1; /* done */
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!strncmp("/quit", ptr, 5)) {
|
|
||||||
logmsg("Request-to-quit received");
|
|
||||||
req->testno = DOCNUMBER_QUIT;
|
|
||||||
return 1; /* done */
|
|
||||||
}
|
|
||||||
|
|
||||||
ptr++; /* skip the slash */
|
|
||||||
|
|
||||||
/* skip all non-numericals following the slash */
|
|
||||||
while(*ptr && !ISDIGIT(*ptr))
|
|
||||||
ptr++;
|
|
||||||
|
|
||||||
req->testno = strtol(ptr, &ptr, 10);
|
|
||||||
|
|
||||||
if(req->testno > 10000) {
|
|
||||||
req->partno = req->testno % 10000;
|
|
||||||
req->testno /= 10000;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
req->partno = 0;
|
|
||||||
|
|
||||||
sprintf(logbuf, "Requested test number %ld part %ld",
|
|
||||||
req->testno, req->partno);
|
|
||||||
logmsg("%s", logbuf);
|
|
||||||
|
|
||||||
filename = test2file(req->testno);
|
filename = test2file(req->testno);
|
||||||
|
|
||||||
@ -465,7 +386,7 @@ static int ProcessRequest(struct httprequest *req)
|
|||||||
req->writedelay = num;
|
req->writedelay = num;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logmsg("funny instruction found: %s", cmd);
|
logmsg("Unknown <servercmd> instruction found: %s", cmd);
|
||||||
}
|
}
|
||||||
/* try to deal with CRLF or just LF */
|
/* try to deal with CRLF or just LF */
|
||||||
check = strchr(cmd, '\r');
|
check = strchr(cmd, '\r');
|
||||||
@ -488,6 +409,94 @@ static int ProcessRequest(struct httprequest *req)
|
|||||||
if(orgcmd)
|
if(orgcmd)
|
||||||
free(orgcmd);
|
free(orgcmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0; /* OK! */
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ProcessRequest(struct httprequest *req)
|
||||||
|
{
|
||||||
|
char *line=&req->reqbuf[req->checkindex];
|
||||||
|
bool chunked = FALSE;
|
||||||
|
static char request[REQUEST_KEYWORD_SIZE];
|
||||||
|
static char doc[MAXDOCNAMELEN];
|
||||||
|
char logbuf[456];
|
||||||
|
int prot_major, prot_minor;
|
||||||
|
char *end = strstr(line, end_of_headers);
|
||||||
|
|
||||||
|
req->callcount++;
|
||||||
|
|
||||||
|
logmsg("Process %d bytes request%s", req->offset,
|
||||||
|
req->callcount > 1?" [CONTINUED]":"");
|
||||||
|
|
||||||
|
/* try to figure out the request characteristics as soon as possible, but
|
||||||
|
only once! */
|
||||||
|
|
||||||
|
if(use_gopher &&
|
||||||
|
(req->testno == DOCNUMBER_NOTHING) &&
|
||||||
|
!strncmp("/verifiedserver", line, 15)) {
|
||||||
|
logmsg("Are-we-friendly question received");
|
||||||
|
req->testno = DOCNUMBER_WERULEZ;
|
||||||
|
return 1; /* done */
|
||||||
|
}
|
||||||
|
|
||||||
|
else if((req->testno == DOCNUMBER_NOTHING) &&
|
||||||
|
sscanf(line,
|
||||||
|
"%" REQUEST_KEYWORD_SIZE_TXT"s %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
|
||||||
|
request,
|
||||||
|
doc,
|
||||||
|
&prot_major,
|
||||||
|
&prot_minor) == 4) {
|
||||||
|
char *ptr;
|
||||||
|
|
||||||
|
req->prot_version = prot_major*10 + prot_minor;
|
||||||
|
|
||||||
|
/* find the last slash */
|
||||||
|
ptr = strrchr(doc, '/');
|
||||||
|
|
||||||
|
/* get the number after it */
|
||||||
|
if(ptr) {
|
||||||
|
if((strlen(doc) + strlen(request)) < 400)
|
||||||
|
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("%s", logbuf);
|
||||||
|
|
||||||
|
if(!strncmp("/verifiedserver", ptr, 15)) {
|
||||||
|
logmsg("Are-we-friendly question received");
|
||||||
|
req->testno = DOCNUMBER_WERULEZ;
|
||||||
|
return 1; /* done */
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!strncmp("/quit", ptr, 5)) {
|
||||||
|
logmsg("Request-to-quit received");
|
||||||
|
req->testno = DOCNUMBER_QUIT;
|
||||||
|
return 1; /* done */
|
||||||
|
}
|
||||||
|
|
||||||
|
ptr++; /* skip the slash */
|
||||||
|
|
||||||
|
/* skip all non-numericals following the slash */
|
||||||
|
while(*ptr && !ISDIGIT(*ptr))
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
req->testno = strtol(ptr, &ptr, 10);
|
||||||
|
|
||||||
|
if(req->testno > 10000) {
|
||||||
|
req->partno = req->testno % 10000;
|
||||||
|
req->testno /= 10000;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
req->partno = 0;
|
||||||
|
|
||||||
|
sprintf(logbuf, "Requested test number %ld part %ld",
|
||||||
|
req->testno, req->partno);
|
||||||
|
logmsg("%s", logbuf);
|
||||||
|
|
||||||
|
/* find and parse <servercmd> for this test */
|
||||||
|
parse_servercmd(req);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
|
if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
|
||||||
@ -532,6 +541,9 @@ static int ProcessRequest(struct httprequest *req)
|
|||||||
req->testno = req->connect_port?req->connect_port:DOCNUMBER_CONNECT;
|
req->testno = req->connect_port?req->connect_port:DOCNUMBER_CONNECT;
|
||||||
else
|
else
|
||||||
req->testno = req->connect_port?DOCNUMBER_CONNECT:DOCNUMBER_BADCONNECT;
|
req->testno = req->connect_port?DOCNUMBER_CONNECT:DOCNUMBER_BADCONNECT;
|
||||||
|
|
||||||
|
/* find and parse <servercmd> for this test */
|
||||||
|
parse_servercmd(req);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
logmsg("Did not find test number in PATH");
|
logmsg("Did not find test number in PATH");
|
||||||
@ -1979,7 +1991,7 @@ int main(int argc, char *argv[])
|
|||||||
if(got_exit_signal)
|
if(got_exit_signal)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
logmsg("====> Client disconnect");
|
logmsg("====> Client disconnect %d", req.connmon);
|
||||||
|
|
||||||
if(req.connmon) {
|
if(req.connmon) {
|
||||||
const char *keepopen="[DISCONNECT]\n";
|
const char *keepopen="[DISCONNECT]\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user