tests/server: comply with our code style

This commit is contained in:
Daniel Stenberg 2016-04-03 22:35:43 +02:00
parent a71012c03e
commit a332c4f769
9 changed files with 240 additions and 210 deletions

View File

@ -76,7 +76,7 @@ static char *printable(char *inbuf, size_t inlength)
return NULL;
if(!inlength) {
sprintf(&outbuf[0], "%s", NOTHING_STR);
snprintf(&outbuf[0], outsize, "%s", NOTHING_STR);
return outbuf;
}
@ -98,7 +98,7 @@ static char *printable(char *inbuf, size_t inlength)
o++;
}
else {
sprintf(&outbuf[o], HEX_FMT_STR, inbuf[i]);
snprintf(&outbuf[o], outsize - o, HEX_FMT_STR, inbuf[i]);
o += HEX_STR_LEN;
}
@ -171,7 +171,8 @@ int main(int argc, char *argv[])
exit(1);
}
testnum = lnum;
} else {
}
else {
logmsg("Test number not specified in CURL_NTLM_AUTH_TESTNUM");
exit(1);
}
@ -230,7 +231,8 @@ int main(int argc, char *argv[])
}
else {
size = 0;
error = getpart(&type1_output, &size, "ntlm_auth_type1", "output", stream);
error = getpart(&type1_output, &size, "ntlm_auth_type1", "output",
stream);
fclose(stream);
if(error || size == 0) {
logmsg("getpart() type 1 output failed with error: %d", error);
@ -251,7 +253,8 @@ int main(int argc, char *argv[])
}
else {
size = 0;
error = getpart(&type3_output, &size, "ntlm_auth_type3", "output", stream);
error = getpart(&type3_output, &size, "ntlm_auth_type3", "output",
stream);
fclose(stream);
if(error || size == 0) {
logmsg("getpart() type 3 output failed with error: %d", error);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, 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

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, 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

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, 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
@ -375,10 +375,10 @@ static int ProcessRequest(struct httprequest *req)
char *filename;
if((strlen(doc) + strlen(request)) < 200)
sprintf(logbuf, "Got request: %s %s %s/%d.%d",
snprintf(logbuf, sizeof(logbuf), "Got request: %s %s %s/%d.%d",
request, doc, prot_str, prot_major, prot_minor);
else
sprintf(logbuf, "Got a *HUGE* request %s/%d.%d",
snprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request %s/%d.%d",
prot_str, prot_major, prot_minor);
logmsg("%s", logbuf);
@ -409,7 +409,7 @@ static int ProcessRequest(struct httprequest *req)
else
req->partno = 0;
sprintf(logbuf, "Requested test number %ld part %ld",
snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld",
req->testno, req->partno);
logmsg("%s", logbuf);
@ -501,14 +501,18 @@ static int ProcessRequest(struct httprequest *req)
if(req->rtp_buffer == NULL) {
req->rtp_buffer = rtp_scratch;
req->rtp_buffersize = rtp_size + 4;
} else {
req->rtp_buffer = realloc(req->rtp_buffer, req->rtp_buffersize + rtp_size + 4);
memcpy(req->rtp_buffer + req->rtp_buffersize, rtp_scratch, rtp_size + 4);
}
else {
req->rtp_buffer = realloc(req->rtp_buffer,
req->rtp_buffersize +
rtp_size + 4);
memcpy(req->rtp_buffer + req->rtp_buffersize, rtp_scratch,
rtp_size + 4);
req->rtp_buffersize += rtp_size + 4;
free(rtp_scratch);
}
logmsg("rtp_buffersize is %zu, rtp_size is %d.", req->rtp_buffersize, rtp_size);
logmsg("rtp_buffersize is %zu, rtp_size is %d.",
req->rtp_buffersize, rtp_size);
}
}
else {
@ -529,7 +533,8 @@ static int ProcessRequest(struct httprequest *req)
else {
if(sscanf(req->reqbuf, "CONNECT %" MAXDOCNAMELEN_TXT "s HTTP/%d.%d",
doc, &prot_major, &prot_minor) == 3) {
sprintf(logbuf, "Received a CONNECT %s HTTP/%d.%d request",
snprintf(logbuf, sizeof(logbuf),
"Received a CONNECT %s HTTP/%d.%d request",
doc, prot_major, prot_minor);
logmsg("%s", logbuf);
@ -662,10 +667,11 @@ static int ProcessRequest(struct httprequest *req)
req->ntlm = TRUE; /* NTLM found */
logmsg("Received NTLM type-1, sending back data %ld", req->partno);
}
else if((req->partno >= 1000) && strstr(req->reqbuf, "Authorization: Basic")) {
/* If the client is passing this Basic-header and the part number is already
>=1000, we add 1 to the part number. This allows simple Basic authentication
negotiation to work in the test suite. */
else if((req->partno >= 1000) &&
strstr(req->reqbuf, "Authorization: Basic")) {
/* If the client is passing this Basic-header and the part number is
already >=1000, we add 1 to the part number. This allows simple Basic
authentication negotiation to work in the test suite. */
req->partno += 1;
logmsg("Received Basic request, sending back data %ld", req->partno);
}
@ -815,9 +821,9 @@ static int get_request(curl_socket_t sock, struct httprequest *req)
}
else {
if(req->skip)
/* we are instructed to not read the entire thing, so we make sure to only
read what we're supposed to and NOT read the enire thing the client
wants to send! */
/* we are instructed to not read the entire thing, so we make sure to
only read what we're supposed to and NOT read the enire thing the
client wants to send! */
got = sread(sock, reqbuf + req->offset, req->cl);
else
got = sread(sock, reqbuf + req->offset, REQBUFSIZ-1 - req->offset);
@ -937,9 +943,11 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
case DOCNUMBER_WERULEZ:
/* we got a "friends?" question, reply back that we sure are */
logmsg("Identifying ourselves as friends");
sprintf(msgbuf, "RTSP_SERVER WE ROOLZ: %ld\r\n", (long)getpid());
snprintf(msgbuf, sizeof(msgbuf), "RTSP_SERVER WE ROOLZ: %ld\r\n",
(long)getpid());
msglen = strlen(msgbuf);
sprintf(weare, "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
snprintf(weare, sizeof(weare),
"HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
msglen, msgbuf);
buffer = weare;
break;
@ -959,7 +967,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
logmsg("Replying to with a 404");
if(req->protocol == RPROT_HTTP) {
buffer = doc404_HTTP;
} else {
}
else {
buffer = doc404_RTSP;
}
break;
@ -971,7 +980,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
char *filename = test2file(req->testno);
if(0 != req->partno)
sprintf(partbuf, "data%ld", req->partno);
snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno);
stream=fopen(filename, "rb");
if(!stream) {
@ -1082,7 +1091,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
size_t num = count;
if(num > 200)
num = 200;
written = swrite(sock, req->rtp_buffer + (req->rtp_buffersize - count), num);
written = swrite(sock, req->rtp_buffer + (req->rtp_buffersize - count),
num);
if(written < 0) {
sendfailure = TRUE;
break;
@ -1108,7 +1118,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
if(sendfailure) {
logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) were sent",
logmsg("Sending response failed. Only (%zu bytes) of "
"(%zu bytes) were sent",
responsesize-count, responsesize);
free(ptr);
free(cmd);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, 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
@ -53,31 +53,34 @@
*
* This program is a single-threaded process.
*
* This program is intended to be highly portable and as such it must be kept as
* simple as possible, due to this the only signal handling mechanisms used will
* be those of ANSI C, and used only in the most basic form which is good enough
* for the purpose of this program.
* This program is intended to be highly portable and as such it must be kept
* as simple as possible, due to this the only signal handling mechanisms used
* will be those of ANSI C, and used only in the most basic form which is good
* enough for the purpose of this program.
*
* For the above reason and the specific needs of this program signals SIGHUP,
* SIGPIPE and SIGALRM will be simply ignored on systems where this can be done.
* If possible, signals SIGINT and SIGTERM will be handled by this program as an
* indication to cleanup and finish execution as soon as possible. This will be
* achieved with a single signal handler 'exit_signal_handler' for both signals.
* SIGPIPE and SIGALRM will be simply ignored on systems where this can be
* done. If possible, signals SIGINT and SIGTERM will be handled by this
* program as an indication to cleanup and finish execution as soon as
* possible. This will be achieved with a single signal handler
* 'exit_signal_handler' for both signals.
*
* The 'exit_signal_handler' upon the first SIGINT or SIGTERM received signal
* will just set to one the global var 'got_exit_signal' storing in global var
* 'exit_signal' the signal that triggered this change.
*
* Nothing fancy that could introduce problems is used, the program at certain
* points in its normal flow checks if var 'got_exit_signal' is set and in case
* this is true it just makes its way out of loops and functions in structured
* and well behaved manner to achieve proper program cleanup and termination.
* points in its normal flow checks if var 'got_exit_signal' is set and in
* case this is true it just makes its way out of loops and functions in
* structured and well behaved manner to achieve proper program cleanup and
* termination.
*
* Even with the above mechanism implemented it is worthwile to note that other
* signals might still be received, or that there might be systems on which it
* is not possible to trap and ignore some of the above signals. This implies
* that for increased portability and reliability the program must be coded as
* if no signal was being ignored or handled at all. Enjoy it!
* Even with the above mechanism implemented it is worthwile to note that
* other signals might still be received, or that there might be systems on
* which it is not possible to trap and ignore some of the above signals.
* This implies that for increased portability and reliability the program
* must be coded as if no signal was being ignored or handled at all. Enjoy
* it!
*/
#ifdef HAVE_SIGNAL_H
@ -469,23 +472,28 @@ static void lograw(unsigned char *buffer, ssize_t len)
unsigned char *ptr = buffer;
char *optr = data;
ssize_t width=0;
int left = sizeof(data);
for(i=0; i<len; i++) {
switch(ptr[i]) {
case '\n':
sprintf(optr, "\\n");
snprintf(optr, left, "\\n");
width += 2;
optr += 2;
left-=2;
break;
case '\r':
sprintf(optr, "\\r");
snprintf(optr, left, "\\r");
width += 2;
optr += 2;
left-=2;
break;
default:
sprintf(optr, "%c", (ISGRAPH(ptr[i]) || ptr[i]==0x20) ?ptr[i]:'.');
snprintf(optr, left, "%c", (ISGRAPH(ptr[i]) ||
ptr[i]==0x20) ?ptr[i]:'.');
width++;
optr++;
left--;
break;
}
@ -493,6 +501,7 @@ static void lograw(unsigned char *buffer, ssize_t len)
logmsg("'%s'", data);
width = 0;
optr = data;
left = sizeof(data);
}
}
if(width)
@ -1049,7 +1058,7 @@ static bool juggle(curl_socket_t *sockfdp,
else if(!memcmp("PORT", buffer, 4)) {
/* Question asking us what PORT number we are listening to.
Replies to PORT with "IPv[num]/[port]" */
sprintf((char *)buffer, "%s/%hu\n", ipv_inuse, port);
snprintf((char *)buffer, sizeof(buffer), "%s/%hu\n", ipv_inuse, port);
buffer_len = (ssize_t)strlen((char *)buffer);
snprintf(data, sizeof(data), "PORT\n%04zx\n", buffer_len);
if(!write_stdout(data, 10))

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, 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
@ -491,10 +491,10 @@ static int ProcessRequest(struct httprequest *req)
/* get the number after it */
if(ptr) {
if((strlen(doc) + strlen(request)) < 400)
sprintf(logbuf, "Got request: %s %s HTTP/%d.%d",
snprintf(logbuf, sizeof(logbuf), "Got request: %s %s HTTP/%d.%d",
request, doc, prot_major, prot_minor);
else
sprintf(logbuf, "Got a *HUGE* request HTTP/%d.%d",
snprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request HTTP/%d.%d",
prot_major, prot_minor);
logmsg("%s", logbuf);
@ -527,7 +527,7 @@ static int ProcessRequest(struct httprequest *req)
if(req->testno) {
sprintf(logbuf, "Requested test number %ld part %ld",
snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld",
req->testno, req->partno);
logmsg("%s", logbuf);
@ -548,7 +548,8 @@ static int ProcessRequest(struct httprequest *req)
char *portp = NULL;
unsigned long part=0;
sprintf(logbuf, "Received a CONNECT %s HTTP/%d.%d request",
snprintf(logbuf, sizeof(logbuf),
"Received a CONNECT %s HTTP/%d.%d request",
doc, prot_major, prot_minor);
logmsg("%s", logbuf);
@ -618,7 +619,8 @@ static int ProcessRequest(struct httprequest *req)
else
req->partno = 0;
sprintf(logbuf, "Requested test number %ld part %ld (from host name)",
snprintf(logbuf, sizeof(logbuf),
"Requested test number %ld part %ld (from host name)",
req->testno, req->partno);
logmsg("%s", logbuf);
@ -668,7 +670,8 @@ static int ProcessRequest(struct httprequest *req)
else
req->partno = 0;
sprintf(logbuf, "Requested GOPHER test number %ld part %ld",
snprintf(logbuf, sizeof(logbuf),
"Requested GOPHER test number %ld part %ld",
req->testno, req->partno);
logmsg("%s", logbuf);
}
@ -1076,12 +1079,13 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
case DOCNUMBER_WERULEZ:
/* we got a "friends?" question, reply back that we sure are */
logmsg("Identifying ourselves as friends");
sprintf(msgbuf, "WE ROOLZ: %ld\r\n", (long)getpid());
snprintf(msgbuf, sizeof(msgbuf), "WE ROOLZ: %ld\r\n", (long)getpid());
msglen = strlen(msgbuf);
if(use_gopher)
sprintf(weare, "%s", msgbuf);
snprintf(weare, sizeof(weare), "%s", msgbuf);
else
sprintf(weare, "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
snprintf(weare, sizeof(weare),
"HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
msglen, msgbuf);
buffer = weare;
break;
@ -1103,9 +1107,9 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
const char *section= req->connect_request?"connect":"data";
if(req->partno)
sprintf(partbuf, "%s%ld", section, req->partno);
snprintf(partbuf, sizeof(partbuf), "%s%ld", section, req->partno);
else
sprintf(partbuf, "%s", section);
snprintf(partbuf, sizeof(partbuf), "%s", section);
logmsg("Send response test%ld section <%s>", req->testno, partbuf);
@ -1228,7 +1232,8 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
}
if(sendfailure) {
logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) were sent",
logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) "
"were sent",
responsesize-count, responsesize);
free(ptr);
free(cmd);
@ -1552,7 +1557,8 @@ static void http_connect(curl_socket_t *infdp,
/* connect to the server */
serverfd[DATA] = connect_to(ipaddr, req2.connect_port);
if(serverfd[DATA] != CURL_SOCKET_BAD) {
/* secondary tunnel established, now we have two connections */
/* secondary tunnel established, now we have two
connections */
poll_client_rd[DATA] = TRUE;
poll_client_wr[DATA] = TRUE;
poll_server_rd[DATA] = TRUE;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, 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
@ -41,7 +41,7 @@ int main(int argc, char **argv)
else {
rc = getpart(&part, &partlen, argv[1], argv[2], stdin);
if(rc)
return(rc);
return rc;
for(i = 0; i < partlen; i++)
printf("%c", part[i]);
free(part);

View File

@ -1141,7 +1141,8 @@ static int validate_access(struct testcase *test,
if(!strncmp("verifiedserver", filename, 14)) {
char weare[128];
size_t count = sprintf(weare, "WE ROOLZ: %ld\r\n", (long)getpid());
size_t count = snprintf(weare, sizeof(weare),
"WE ROOLZ: %ld\r\n", (long)getpid());
logmsg("Are-we-friendly question received");
test->buffer = strdup(weare);
@ -1183,7 +1184,7 @@ static int validate_access(struct testcase *test,
file = test2file(testno);
if(0 != partno)
sprintf(partbuf, "data%ld", partno);
snprintf(partbuf, sizeof(partbuf), "data%ld", partno);
if(file) {
FILE *stream=fopen(file, "rb");
@ -1375,7 +1376,8 @@ send_ack:
} while(size == SEGSIZE);
write_behind(test, pf->f_convert);
rap->th_opcode = htons((unsigned short)opcode_ACK); /* send the "final" ack */
rap->th_opcode = htons((unsigned short)opcode_ACK); /* send the "final"
ack */
rap->th_block = htons(recvblock);
(void) swrite(peer, &ackbuf.storage[0], 4);
#if defined(HAVE_ALARM) && defined(SIGALRM)

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2016, 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
@ -77,11 +77,11 @@ char *data_to_hex(char *data, size_t len)
if((data[i] >= 0x20) && (data[i] < 0x7f))
*optr++ = *iptr++;
else {
sprintf(optr, "%%%02x", *iptr++);
snprintf(optr, 4, "%%%02x", *iptr++);
optr+=3;
}
}
*optr=0; /* in case no sprintf() was used */
*optr=0; /* in case no sprintf was used */
return buf;
}
@ -167,7 +167,6 @@ void win32_init(void)
if(LOBYTE(wsaData.wVersion) != USE_WINSOCK ||
HIBYTE(wsaData.wVersion) != USE_WINSOCK) {
WSACleanup();
perror("Winsock init failed");
logmsg("No suitable winsock.dll found -- aborting");