]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
sws: as last resort, get test number from server cmd file
authorDaniel Stenberg <daniel@haxx.se>
Thu, 14 May 2020 15:45:40 +0000 (17:45 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 15 May 2020 06:28:56 +0000 (08:28 +0200)
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.

tests/server/sws.c

index 48ea26d5e33efda4717503f2cbb9224d92db9d4a..49790f03adc1a99a83823bc3a8e91e84d4152690 100644 (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,34 +510,41 @@ 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(req->testno > 10000) {
-          req->partno = req->testno % 10000;
-          req->testno /= 10000;
+        if(num) {
+          req->testno = num;
+          if(req->testno > 10000) {
+            req->partno = req->testno % 10000;
+            req->testno /= 10000;
 
-          logmsg("found test %d in requested host name", req->testno);
+            logmsg("found test %d in requested host name", req->testno);
 
+          }
+          else
+            req->partno = 0;
         }
-        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 != DOCNUMBER_NOTHING) {
+          logmsg("Requested test number %ld part %ld (from host name)",
+                 req->testno, req->partno);
+        }
       }
+    }
 
-      if(!req->testno) {
-        logmsg("Did not find test number in PATH");
-        req->testno = DOCNUMBER_404;
-      }
-      else
-        parse_servercmd(req);
+    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)",
@@ -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;