1
0
mirror of https://github.com/moparisthebest/curl synced 2024-11-16 22:45:03 -05:00

sws: as last resort, get test number from server cmd file

If it can't be found in the request. Also support --cmdfile to set it to
a custom file name.

runtests.pl always writes this file with the test number in it since a
while back.
This commit is contained in:
Daniel Stenberg 2020-05-14 17:45:40 +02:00
parent f002c850d9
commit a3b0699d5c
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -154,6 +154,10 @@ const char *serverlogfile = DEFAULT_LOGFILE;
#define REQUEST_PROXY_DUMP "log/proxy.input"
#define RESPONSE_PROXY_DUMP "log/proxy.response"
/* file in which additional instructions may be found */
#define DEFAULT_CMDFILE "log/ftpserver.cmd"
const char *cmdfile = DEFAULT_CMDFILE;
/* very-big-path support */
#define MAXDOCNAMELEN 140000
#define MAXDOCNAMELEN_TXT "139999"
@ -231,6 +235,24 @@ static bool socket_domain_is_ip(void)
}
}
/* parse the file on disk that might have a test number for us */
static int parse_cmdfile(struct httprequest *req)
{
int testnum = DOCNUMBER_NOTHING;
char buf[256];
FILE *f = fopen(cmdfile, FOPEN_READTEXT);
if(f) {
while(fgets(buf, sizeof(buf), f)) {
if(1 == sscanf(buf, "Testnum %d", &testnum)) {
logmsg("[%s] cmdfile says testnum %d", cmdfile, testnum);
req->testno = testnum;
}
}
fclose(f);
}
return 0;
}
/* based on the testno, parse the correct server commands */
static int parse_servercmd(struct httprequest *req)
{
@ -488,10 +510,13 @@ static int ProcessRequest(struct httprequest *req)
/* get the number after it */
if(ptr) {
long num;
ptr++; /* skip the dot */
req->testno = strtol(ptr, &ptr, 10);
num = strtol(ptr, &ptr, 10);
if(num) {
req->testno = num;
if(req->testno > 10000) {
req->partno = req->testno % 10000;
req->testno /= 10000;
@ -501,22 +526,26 @@ static int ProcessRequest(struct httprequest *req)
}
else
req->partno = 0;
msnprintf(logbuf, sizeof(logbuf),
"Requested test number %ld part %ld (from host name)",
req->testno, req->partno);
logmsg("%s", logbuf);
}
if(!req->testno) {
if(req->testno != DOCNUMBER_NOTHING) {
logmsg("Requested test number %ld part %ld (from host name)",
req->testno, req->partno);
}
}
}
if(req->testno == DOCNUMBER_NOTHING)
/* might get the test number */
parse_cmdfile(req);
if(req->testno == DOCNUMBER_NOTHING) {
logmsg("Did not find test number in PATH");
req->testno = DOCNUMBER_404;
}
else
parse_servercmd(req);
}
}
else if((req->offset >= 3) && (req->testno == DOCNUMBER_NOTHING)) {
logmsg("** Unusual request. Starts with %02x %02x %02x (%c%c%c)",
line[0], line[1], line[2], line[0], line[1], line[2]);
@ -1886,6 +1915,11 @@ int main(int argc, char *argv[])
if(argc>arg)
serverlogfile = argv[arg++];
}
else if(!strcmp("--cmdfile", argv[arg])) {
arg++;
if(argc>arg)
cmdfile = argv[arg++];
}
else if(!strcmp("--gopher", argv[arg])) {
arg++;
use_gopher = TRUE;