diff options
Diffstat (limited to 'tests/server/sws.c')
-rw-r--r-- | tests/server/sws.c | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/tests/server/sws.c b/tests/server/sws.c index 16485f2f9..e1dfe45d8 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -389,8 +389,13 @@ static int ProcessRequest(struct httprequest *req) int num=0; /* get the custom server control "commands" */ - cmd = (char *)spitout(stream, "reply", "servercmd", &cmdsize); + error = getpart(&cmd, &cmdsize, "reply", "servercmd", stream); fclose(stream); + if(error) { + logmsg("getpart() failed with error: %d", error); + req->open = FALSE; /* closes connection */ + return 1; /* done */ + } if(cmdsize) { logmsg("Found a reply-servercmd section!"); @@ -423,8 +428,9 @@ static int ProcessRequest(struct httprequest *req) else { logmsg("funny instruction found: %s", cmd); } - free(cmd); } + if(cmd) + free(cmd); } } else { @@ -863,13 +869,20 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) return 0; } else { - buffer = spitout(stream, "reply", partbuf, &count); - ptr = (char *)buffer; + error = getpart(&ptr, &count, "reply", partbuf, stream); fclose(stream); + if(error) { + logmsg("getpart() failed with error: %d", error); + return 0; + } + buffer = ptr; } - if(got_exit_signal) + if(got_exit_signal) { + if(ptr) + free(ptr); return -1; + } /* re-open the same file again */ stream=fopen(filename, "rb"); @@ -878,17 +891,30 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file"); + if(ptr) + free(ptr); return 0; } else { /* get the custom server control "commands" */ - cmd = (char *)spitout(stream, "reply", "postcmd", &cmdsize); + error = getpart(&cmd, &cmdsize, "reply", "postcmd", stream); fclose(stream); + if(error) { + logmsg("getpart() failed with error: %d", error); + if(ptr) + free(ptr); + return 0; + } } } - if(got_exit_signal) + if(got_exit_signal) { + if(ptr) + free(ptr); + if(cmd) + free(cmd); return -1; + } /* If the word 'swsclose' is present anywhere in the reply chunk, the connection will be closed after the data has been sent to the requesting @@ -910,6 +936,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) logmsg("fopen() failed with error: %d %s", error, strerror(error)); logmsg("Error opening file: %s", RESPONSE_DUMP); logmsg("couldn't create logfile: " RESPONSE_DUMP); + if(ptr) + free(ptr); + if(cmd) + free(cmd); return -1; } @@ -945,8 +975,13 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) logmsg("Error closing file %s error: %d %s", RESPONSE_DUMP, error, strerror(error)); - if(got_exit_signal) + if(got_exit_signal) { + if(ptr) + free(ptr); + if(cmd) + free(cmd); return -1; + } if(sendfailure) { logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) were sent", |