diff options
Diffstat (limited to 'tests/server')
-rw-r--r-- | tests/server/fake_ntlm.c | 17 | ||||
-rw-r--r-- | tests/server/mqttd.c | 4 | ||||
-rw-r--r-- | tests/server/rtspd.c | 15 | ||||
-rw-r--r-- | tests/server/sws.c | 12 | ||||
-rw-r--r-- | tests/server/tftpd.c | 53 | ||||
-rw-r--r-- | tests/server/util.c | 16 | ||||
-rw-r--r-- | tests/server/util.h | 6 |
7 files changed, 50 insertions, 73 deletions
diff --git a/tests/server/fake_ntlm.c b/tests/server/fake_ntlm.c index c6e36b6f6..c9211f7ea 100644 --- a/tests/server/fake_ntlm.c +++ b/tests/server/fake_ntlm.c @@ -6,7 +6,7 @@ * \___|\___/|_| \_\_____| * * Copyright (C) 2010, Mandy Wu, <mandy.wu@intel.com> - * Copyright (C) 2011 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 2011 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -112,7 +112,6 @@ int main(int argc, char *argv[]) char buf[1024]; char logfilename[256]; FILE *stream; - char *filename; int error; char *type1_input = NULL, *type3_input = NULL; char *type1_output = NULL, *type3_output = NULL; @@ -186,12 +185,10 @@ int main(int argc, char *argv[]) path = env; } - filename = test2file(testnum); - stream = fopen(filename, "rb"); + stream = test2fopen(testnum); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file %ld", testnum); exit(1); } @@ -205,13 +202,11 @@ int main(int argc, char *argv[]) } } - stream = fopen(filename, "rb"); + stream = test2fopen(testnum); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file %ld", testnum); - exit(1); } else { size = 0; @@ -225,11 +220,10 @@ int main(int argc, char *argv[]) while(fgets(buf, sizeof(buf), stdin)) { if(strcmp(buf, type1_input) == 0) { - stream = fopen(filename, "rb"); + stream = test2fopen(testnum); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file %ld", testnum); exit(1); } @@ -247,11 +241,10 @@ int main(int argc, char *argv[]) fflush(stdout); } else if(strncmp(buf, type3_input, strlen(type3_input)) == 0) { - stream = fopen(filename, "rb"); + stream = test2fopen(testnum); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file %ld", testnum); exit(1); } diff --git a/tests/server/mqttd.c b/tests/server/mqttd.c index d9ad5923e..db5723cdd 100644 --- a/tests/server/mqttd.c +++ b/tests/server/mqttd.c @@ -446,7 +446,6 @@ static curl_socket_t mqttit(curl_socket_t fd) size_t remaining_length = 0; size_t bytes = 0; /* remaining length field size in bytes */ char client_id[MAX_CLIENT_ID_LENGTH]; - char *filename; long testno; static const char protocol[7] = { @@ -550,8 +549,7 @@ static curl_socket_t mqttit(curl_socket_t fd) char *data; size_t datalen; logmsg("Found test number %ld", testno); - filename = test2file(testno); - stream = fopen(filename, "rb"); + stream = test2fopen(testno); error = getpart(&data, &datalen, "reply", "data", stream); if(!error) publish(dump, fd, packet_id, topic, data, datalen); diff --git a/tests/server/rtspd.c b/tests/server/rtspd.c index c784fc8ca..2d95d8359 100644 --- a/tests/server/rtspd.c +++ b/tests/server/rtspd.c @@ -247,8 +247,6 @@ static int ProcessRequest(struct httprequest *req) /* get the number after it */ if(ptr) { FILE *stream; - char *filename; - if((strlen(doc) + strlen(request)) < 200) msnprintf(logbuf, sizeof(logbuf), "Got request: %s %s %s/%d.%d", request, doc, prot_str, prot_major, prot_minor); @@ -288,13 +286,11 @@ static int ProcessRequest(struct httprequest *req) req->testno, req->partno); logmsg("%s", logbuf); - filename = test2file(req->testno); + stream = test2fopen(req->testno); - stream = fopen(filename, "rb"); if(!stream) { int error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file %ld", req->testno); req->open = FALSE; /* closes connection */ return 1; /* done */ @@ -849,17 +845,13 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) count = strlen(buffer); } else { - char *filename = test2file(req->testno); + FILE *stream = test2fopen(req->testno); char partbuf[80]="data"; - FILE *stream; if(0 != req->partno) msnprintf(partbuf, sizeof(partbuf), "data%ld", req->partno); - - stream = fopen(filename, "rb"); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file"); return 0; } @@ -879,11 +871,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) } /* re-open the same file again */ - stream = fopen(filename, "rb"); + stream = test2fopen(req->testno); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", filename); logmsg("Couldn't open test file"); free(ptr); return 0; diff --git a/tests/server/sws.c b/tests/server/sws.c index faa1143d9..48ea26d5e 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -235,18 +235,15 @@ static bool socket_domain_is_ip(void) static int parse_servercmd(struct httprequest *req) { FILE *stream; - char *filename; int error; - filename = test2file(req->testno); + stream = test2fopen(req->testno); req->close = FALSE; req->connmon = FALSE; - stream = fopen(filename, "rb"); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg(" [1] Error opening file: %s", filename); logmsg(" Couldn't open test file %ld", req->testno); req->open = FALSE; /* closes connection */ return 1; /* done */ @@ -991,7 +988,6 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) } else { char partbuf[80]; - char *filename = test2file(req->testno); /* select the <data> tag for "normal" requests and the <connect> one for CONNECT requests (within the <reply> section) */ @@ -1004,11 +1000,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) logmsg("Send response test%ld section <%s>", req->testno, partbuf); - stream = fopen(filename, "rb"); + stream = test2fopen(req->testno); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg(" [3] Error opening file: %s", filename); return 0; } else { @@ -1027,11 +1022,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) } /* re-open the same file again */ - stream = fopen(filename, "rb"); + stream = test2fopen(req->testno); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg(" [4] Error opening file: %s", filename); free(ptr); return 0; } diff --git a/tests/server/tftpd.c b/tests/server/tftpd.c index 0c94e1cb7..9972ab0e4 100644 --- a/tests/server/tftpd.c +++ b/tests/server/tftpd.c @@ -944,16 +944,12 @@ static int do_tftp(struct testcase *test, struct tftphdr *tp, ssize_t size) static int parse_servercmd(struct testcase *req) { FILE *stream; - char *filename; int error; - filename = test2file(req->testno); - - stream = fopen(filename, "rb"); + stream = test2fopen(req->testno); if(!stream) { error = errno; logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg(" [1] Error opening file: %s", filename); logmsg(" Couldn't open test file %ld", req->testno); return 1; /* done */ } @@ -1036,7 +1032,7 @@ static int validate_access(struct testcase *test, char partbuf[80]="data"; long partno; long testno; - char *file; + FILE *stream; ptr++; /* skip the slash */ @@ -1061,40 +1057,33 @@ static int validate_access(struct testcase *test, (void)parse_servercmd(test); - file = test2file(testno); + stream = test2fopen(testno); if(0 != partno) msnprintf(partbuf, sizeof(partbuf), "data%ld", partno); - if(file) { - FILE *stream = fopen(file, "rb"); - if(!stream) { - int error = errno; - logmsg("fopen() failed with error: %d %s", error, strerror(error)); - logmsg("Error opening file: %s", file); - logmsg("Couldn't open test file: %s", file); + if(!stream) { + int error = errno; + logmsg("fopen() failed with error: %d %s", error, strerror(error)); + logmsg("Couldn't open test file for test : %d", testno); + return EACCESS; + } + else { + size_t count; + int error = getpart(&test->buffer, &count, "reply", partbuf, stream); + fclose(stream); + if(error) { + logmsg("getpart() failed with error: %d", error); return EACCESS; } - else { - size_t count; - int error = getpart(&test->buffer, &count, "reply", partbuf, stream); - fclose(stream); - if(error) { - logmsg("getpart() failed with error: %d", error); - return EACCESS; - } - if(test->buffer) { - test->rptr = test->buffer; /* set read pointer */ - test->bufsize = count; /* set total count */ - test->rcount = count; /* set data left to read */ - } - else - return EACCESS; + if(test->buffer) { + test->rptr = test->buffer; /* set read pointer */ + test->bufsize = count; /* set total count */ + test->rcount = count; /* set data left to read */ } - + else + return EACCESS; } - else - return EACCESS; } else { logmsg("no slash found in path"); diff --git a/tests/server/util.c b/tests/server/util.c index 169ca5bcb..f576b9c23 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -194,11 +194,21 @@ void win32_cleanup(void) /* set by the main code to point to where the test dir is */ const char *path = "."; -char *test2file(long testno) +FILE *test2fopen(long testno) { - static char filename[256]; + FILE *stream; + char filename[256]; + /* first try the alternative, preprocessed, file */ + msnprintf(filename, sizeof(filename), ALTTEST_DATA_PATH, path, testno); + stream = fopen(filename, "rb"); + if(stream) + return stream; + + /* then try the source version */ msnprintf(filename, sizeof(filename), TEST_DATA_PATH, path, testno); - return filename; + stream = fopen(filename, "rb"); + + return stream; } /* diff --git a/tests/server/util.h b/tests/server/util.h index 9c3fb9f32..73f5f45f6 100644 --- a/tests/server/util.h +++ b/tests/server/util.h @@ -28,6 +28,7 @@ void logmsg(const char *msg, ...); long timediff(struct timeval newer, struct timeval older); #define TEST_DATA_PATH "%s/data/test%ld" +#define ALTTEST_DATA_PATH "%s/log/test%ld" #define SERVERLOGS_LOCK "log/serverlogs.lock" @@ -53,8 +54,9 @@ void win32_init(void); void win32_cleanup(void); #endif /* USE_WINSOCK */ -/* returns the path name to the test case file */ -char *test2file(long testno); +/* fopens the test case file */ +FILE *test2fopen(long testno); + int wait_ms(int timeout_ms); int write_pidfile(const char *filename); int write_portfile(const char *filename, int port); |