1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 23:58:49 -05:00

Added "swsbounce" magic: if this keyword is present in a <data> section it

sets the "swsbounce" magic mode. If there follows a request for the SAME
test number and the SAME part number, this mode will make the server bump
the part number internally and thus return a different <dataNUM> section
than it otherwise would.

Test case 153 uses this in case you need an example. It is pretty involved
and hard-to-use, but then the situation is pretty special over all. Enjoy.
This commit is contained in:
Daniel Stenberg 2004-03-31 11:50:44 +00:00
parent ce446dbdc2
commit 2ff9f55001

View File

@ -74,15 +74,20 @@
#define REQBUFSIZ 150000 #define REQBUFSIZ 150000
#define REQBUFSIZ_TXT "149999" #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 { struct httprequest {
char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */ char reqbuf[REQBUFSIZ]; /* buffer area for the incoming request */
int offset; /* size of the incoming request */ int offset; /* size of the incoming request */
long testno; /* test number found in the 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 */ int open; /* keep connection open info, as found in the request */
bool auth_req; /* authentication required, don't wait for body unless bool auth_req; /* authentication required, don't wait for body unless
there's an Authorization header */ there's an Authorization header */
bool auth; /* Authorization header present in the incoming request */ bool auth; /* Authorization header present in the incoming request */
size_t cl; /* Content-Length of the incoming request */ size_t cl; /* Content-Length of the incoming request */
bool digest; /* Authorization digest header found */ bool digest; /* Authorization digest header found */
@ -226,8 +231,6 @@ int ProcessRequest(struct httprequest *req)
if(ptr) { if(ptr) {
FILE *stream; FILE *stream;
char *filename; char *filename;
char *cmd = NULL;
size_t cmdsize = 0;
if((strlen(doc) + strlen(request)) < 200) if((strlen(doc) + strlen(request)) < 200)
sprintf(logbuf, "Got request: %s %s HTTP/%d.%d", sprintf(logbuf, "Got request: %s %s HTTP/%d.%d",
@ -260,7 +263,7 @@ int ProcessRequest(struct httprequest *req)
else else
req->partno = 0; req->partno = 0;
sprintf(logbuf, "Reqested test number %ld part %d", sprintf(logbuf, "Reqested test number %ld part %ld",
req->testno, req->partno); req->testno, req->partno);
logmsg(logbuf); logmsg(logbuf);
@ -273,6 +276,9 @@ int ProcessRequest(struct httprequest *req)
return 0; return 0;
} }
else { else {
char *cmd = NULL;
size_t cmdsize = 0;
/* get the custom server control "commands" */ /* get the custom server control "commands" */
cmd = (char *)spitout(stream, "reply", "servercmd", &cmdsize); cmd = (char *)spitout(stream, "reply", "servercmd", &cmdsize);
fclose(stream); fclose(stream);
@ -284,6 +290,7 @@ int ProcessRequest(struct httprequest *req)
logmsg("instructed to require authorization header"); logmsg("instructed to require authorization header");
req->auth_req = TRUE; req->auth_req = TRUE;
} }
free(cmd);
} }
} }
} }
@ -392,7 +399,7 @@ int ProcessRequest(struct httprequest *req)
} }
if(strstr(req->reqbuf, "Connection: close")) if(strstr(req->reqbuf, "Connection: close"))
req->open = FALSE; /* close connection after this request */ req->open = FALSE; /* close connection after this request */
if(req->cl && (req->auth || !req->auth_req)) { if(req->cl && (req->auth || !req->auth_req)) {
if(req->cl <= strlen(end+strlen(END_OF_HEADERS))) if(req->cl <= strlen(end+strlen(END_OF_HEADERS)))
return 1; /* done */ return 1; /* done */
@ -426,7 +433,6 @@ static int get_request(int sock, struct httprequest *req)
char *reqbuf = req->reqbuf; char *reqbuf = req->reqbuf;
/*** Init the httpreqest structure properly for the upcoming request ***/ /*** Init the httpreqest structure properly for the upcoming request ***/
memset(req, 0, sizeof(struct httprequest)); memset(req, 0, sizeof(struct httprequest));
/* here's what should not be 0 from the start */ /* here's what should not be 0 from the start */
@ -530,7 +536,7 @@ static int send_doc(int sock, struct httprequest *req)
char *filename = test2file(req->testno); char *filename = test2file(req->testno);
if(0 != req->partno) if(0 != req->partno)
sprintf(partbuf, "data%d", req->partno); sprintf(partbuf, "data%ld", req->partno);
stream=fopen(filename, "rb"); stream=fopen(filename, "rb");
if(!stream) { if(!stream) {
@ -569,6 +575,12 @@ static int send_doc(int sock, struct httprequest *req)
persistant = FALSE; persistant = FALSE;
logmsg("connection close instruction swsclose found in response"); 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 { do {
written = swrite(sock, buffer, count); written = swrite(sock, buffer, count);
@ -613,6 +625,9 @@ static int send_doc(int sock, struct httprequest *req)
req->open = persistant; req->open = persistant;
prevtestno = req->testno;
prevpartno = req->partno;
return 0; return 0;
} }
@ -734,6 +749,15 @@ int main(int argc, char *argv[])
/* non-zero means error, break out of loop */ /* non-zero means error, break out of loop */
break; 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); send_doc(msgsock, &req);
if((req.testno < 0) && (req.testno != DOCNUMBER_CONNECT)) { if((req.testno < 0) && (req.testno != DOCNUMBER_CONNECT)) {