#define REQBUFSIZ 150000
#define REQBUFSIZ_TXT "149999"
+long prevtestno=-1; /* previous test number we served */
+long prevpartno=-1; /* previous part number we served */
+bool prevbounce; /* instructs the server to increase the part number for
+ a test in case the identical testno+partno request
+ shows up again */
+
struct httprequest {
char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */
int offset; /* size of the incoming request */
long testno; /* test number found in the request */
- int partno; /* part number found in the request */
+ long partno; /* part number found in the request */
int open; /* keep connection open info, as found in the request */
bool auth_req; /* authentication required, don't wait for body unless
there's an Authorization header */
-
bool auth; /* Authorization header present in the incoming request */
size_t cl; /* Content-Length of the incoming request */
bool digest; /* Authorization digest header found */
if(ptr) {
FILE *stream;
char *filename;
- char *cmd = NULL;
- size_t cmdsize = 0;
if((strlen(doc) + strlen(request)) < 200)
sprintf(logbuf, "Got request: %s %s HTTP/%d.%d",
else
req->partno = 0;
- sprintf(logbuf, "Reqested test number %ld part %d",
+ sprintf(logbuf, "Reqested test number %ld part %ld",
req->testno, req->partno);
logmsg(logbuf);
return 0;
}
else {
+ char *cmd = NULL;
+ size_t cmdsize = 0;
+
/* get the custom server control "commands" */
cmd = (char *)spitout(stream, "reply", "servercmd", &cmdsize);
fclose(stream);
logmsg("instructed to require authorization header");
req->auth_req = TRUE;
}
+ free(cmd);
}
}
}
}
if(strstr(req->reqbuf, "Connection: close"))
req->open = FALSE; /* close connection after this request */
-
+
if(req->cl && (req->auth || !req->auth_req)) {
if(req->cl <= strlen(end+strlen(END_OF_HEADERS)))
return 1; /* done */
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 */
char *filename = test2file(req->testno);
if(0 != req->partno)
- sprintf(partbuf, "data%d", req->partno);
+ sprintf(partbuf, "data%ld", req->partno);
stream=fopen(filename, "rb");
if(!stream) {
persistant = FALSE;
logmsg("connection close instruction swsclose found in response");
}
+ if(strstr(buffer, "swsbounce")) {
+ prevbounce = TRUE;
+ logmsg("enable \"swsbounce\" in the next request");
+ }
+ else
+ prevbounce = FALSE;
do {
written = swrite(sock, buffer, count);
req->open = persistant;
+ prevtestno = req->testno;
+ prevpartno = req->partno;
+
return 0;
}
/* non-zero means error, break out of loop */
break;
+ if(prevbounce) {
+ /* bounce treatment requested */
+ if((req.testno == prevtestno) &&
+ (req.partno == prevpartno)) {
+ req.partno++;
+ logmsg("BOUNCE part number to %ld", req.partno);
+ }
+ }
+
send_doc(msgsock, &req);
if((req.testno < 0) && (req.testno != DOCNUMBER_CONNECT)) {