return NULL;
if(!inlength) {
- sprintf(&outbuf[0], "%s", NOTHING_STR);
+ snprintf(&outbuf[0], outsize, "%s", NOTHING_STR);
return outbuf;
}
o++;
}
else {
- sprintf(&outbuf[o], HEX_FMT_STR, inbuf[i]);
+ snprintf(&outbuf[o], outsize - o, HEX_FMT_STR, inbuf[i]);
o += HEX_STR_LEN;
}
(use_cached_creds) ? "yes" : "no");
env = getenv("CURL_NTLM_AUTH_TESTNUM");
- if (env) {
+ if(env) {
char *endptr;
long lnum = strtol(env, &endptr, 10);
if((endptr != env + strlen(env)) || (lnum < 1L)) {
exit(1);
}
testnum = lnum;
- } else {
+ }
+ else {
logmsg("Test number not specified in CURL_NTLM_AUTH_TESTNUM");
exit(1);
}
env = getenv("CURL_NTLM_AUTH_SRCDIR");
- if (env) {
+ if(env) {
path = env;
}
}
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);
}
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);
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
int bytestoread = curlx_uztosi(*bufsize - offset);
if(!fgets(*buffer + offset, bytestoread, stream))
- return (offset != 0) ? GPE_OK : GPE_END_OF_FILE ;
+ return (offset != 0) ? GPE_OK : GPE_END_OF_FILE;
length = offset + strlen(*buffer + offset);
if(*(*buffer + length - 1) == '\n')
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
sclose(s);
}
- if (rc == 0) {
+ if(rc == 0) {
/* getaddrinfo() resolve */
struct addrinfo *ai;
struct addrinfo hints;
/* Use parenthesis around functions to stop them from being replaced by
the macro in memdebug.h */
rc = (getaddrinfo)(host, "80", &hints, &ai);
- if (rc == 0)
+ if(rc == 0)
(freeaddrinfo)(ai);
}
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
char *ptr;
if(!strcmp(prot_str, "HTTP")) {
- req->protocol = RPROT_HTTP;
+ req->protocol = RPROT_HTTP;
}
else if(!strcmp(prot_str, "RTSP")) {
- req->protocol = RPROT_RTSP;
+ req->protocol = RPROT_RTSP;
}
else {
- req->protocol = RPROT_NONE;
- logmsg("got unknown protocol %s", prot_str);
- return 1;
+ req->protocol = RPROT_NONE;
+ logmsg("got unknown protocol %s", prot_str);
+ return 1;
}
req->prot_version = prot_major*10 + prot_minor;
char *filename;
if((strlen(doc) + strlen(request)) < 200)
- sprintf(logbuf, "Got request: %s %s %s/%d.%d",
- request, doc, prot_str, prot_major, prot_minor);
+ 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);
else
req->partno = 0;
- sprintf(logbuf, "Requested test number %ld part %ld",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld",
+ req->testno, req->partno);
logmsg("%s", logbuf);
filename = test2file(req->testno);
rtp_scratch[0] = '$';
/* The channel follows and is one byte */
- SET_RTP_PKT_CHN(rtp_scratch ,rtp_channel);
+ SET_RTP_PKT_CHN(rtp_scratch, rtp_channel);
/* Length follows and is a two byte short in network order */
SET_RTP_PKT_LEN(rtp_scratch, rtp_size);
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 {
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",
- doc, prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf),
+ "Received a CONNECT %s HTTP/%d.%d request",
+ doc, prot_major, prot_minor);
logmsg("%s", logbuf);
if(req->prot_version == 10)
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);
}
size_t writeleft;
FILE *dump;
- if (reqbuf == NULL)
+ if(reqbuf == NULL)
return;
- if (totalsize == 0)
+ if(totalsize == 0)
return;
do {
dump = fopen(REQUEST_DUMP, "ab");
- } while ((dump == NULL) && ((error = errno) == EINTR));
- if (dump == NULL) {
+ } while((dump == NULL) && ((error = errno) == EINTR));
+ if(dump == NULL) {
logmsg("Error opening file %s error: %d %s",
REQUEST_DUMP, error, strerror(error));
logmsg("Failed to write request input to " REQUEST_DUMP);
goto storerequest_cleanup;
if(written > 0)
writeleft -= written;
- } while ((writeleft > 0) && ((error = errno) == EINTR));
+ } while((writeleft > 0) && ((error = errno) == EINTR));
if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to " REQUEST_DUMP, totalsize);
}
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);
case RCMD_STREAM:
#define STREAMTHIS "a string to stream 01234567890\n"
count = strlen(STREAMTHIS);
- for (;;) {
+ for(;;) {
written = swrite(sock, STREAMTHIS, count);
if(got_exit_signal)
return -1;
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",
- msglen, msgbuf);
+ snprintf(weare, sizeof(weare),
+ "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
+ msglen, msgbuf);
buffer = weare;
break;
case DOCNUMBER_INTERNAL:
default:
logmsg("Replying to with a 404");
if(req->protocol == RPROT_HTTP) {
- buffer = doc404_HTTP;
- } else {
- buffer = doc404_RTSP;
+ buffer = doc404_HTTP;
+ }
+ else {
+ buffer = doc404_RTSP;
}
break;
}
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) {
if(num > 200)
num = 200;
written = swrite(sock, buffer, num);
- if (written < 0) {
+ if(written < 0) {
sendfailure = TRUE;
break;
}
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;
}
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);
responsesize);
free(ptr);
- if(cmdsize > 0 ) {
+ if(cmdsize > 0) {
char command[32];
int quarters;
int num;
}
flag = 1;
- if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&flag, sizeof(flag))) {
error = SOCKERRNO;
logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s",
if(!wrotepidfile)
goto server_cleanup;
- for (;;) {
+ for(;;) {
msgsock = accept(sock, NULL, NULL);
if(got_exit_signal)
break;
- if (CURL_SOCKET_BAD == msgsock) {
+ if(CURL_SOCKET_BAD == msgsock) {
error = SOCKERRNO;
logmsg("MAJOR ERROR: accept() failed with error: (%d) %s",
error, strerror(error));
* response in many small segments to torture the clients more.
*/
flag = 1;
- if (setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
+ if(setsockopt(msgsock, IPPROTO_TCP, TCP_NODELAY,
(void *)&flag, sizeof(flag)) == -1) {
logmsg("====> TCP_NODELAY failed");
}
clear_advisor_read_lock(SERVERLOGS_LOCK);
}
- if (req.testno == DOCNUMBER_QUIT)
+ if(req.testno == DOCNUMBER_QUIT)
break;
}
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
*
* 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
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;
}
logmsg("'%s'", data);
width = 0;
optr = data;
+ left = sizeof(data);
}
}
if(width)
return FALSE;
logmsg("Received %c%c%c%c (on stdin)",
- buffer[0], buffer[1], buffer[2], buffer[3] );
+ buffer[0], buffer[1], buffer[2], buffer[3]);
if(!memcmp("PING", buffer, 4)) {
/* send reply on stdout, just proving we are alive */
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))
buffer[5] = '\0';
buffer_len = (ssize_t)strtol((char *)buffer, NULL, 16);
- if (buffer_len > (ssize_t)sizeof(buffer)) {
+ if(buffer_len > (ssize_t)sizeof(buffer)) {
logmsg("ERROR: Buffer size (%zu bytes) too small for data size "
"(%zd bytes)", sizeof(buffer), buffer_len);
return FALSE;
me.sa4.sin_family = AF_INET;
me.sa4.sin_port = htons(connectport);
me.sa4.sin_addr.s_addr = INADDR_ANY;
- if (!addr)
+ if(!addr)
addr = "127.0.0.1";
Curl_inet_pton(AF_INET, addr, &me.sa4.sin_addr);
memset(&me.sa6, 0, sizeof(me.sa6));
me.sa6.sin6_family = AF_INET6;
me.sa6.sin6_port = htons(connectport);
- if (!addr)
+ if(!addr)
addr = "::1";
Curl_inet_pton(AF_INET6, addr, &me.sa6.sin6_addr);
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
/* get the number after it */
if(ptr) {
if((strlen(doc) + strlen(request)) < 400)
- sprintf(logbuf, "Got request: %s %s HTTP/%d.%d",
- request, doc, prot_major, prot_minor);
+ 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",
- prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf), "Got a *HUGE* request HTTP/%d.%d",
+ prot_major, prot_minor);
logmsg("%s", logbuf);
if(!strncmp("/verifiedserver", ptr, 15)) {
if(req->testno) {
- sprintf(logbuf, "Requested test number %ld part %ld",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf), "Requested test number %ld part %ld",
+ req->testno, req->partno);
logmsg("%s", logbuf);
/* find and parse <servercmd> for this test */
char *portp = NULL;
unsigned long part=0;
- sprintf(logbuf, "Received a CONNECT %s HTTP/%d.%d request",
- doc, prot_major, prot_minor);
+ snprintf(logbuf, sizeof(logbuf),
+ "Received a CONNECT %s HTTP/%d.%d request",
+ doc, prot_major, prot_minor);
logmsg("%s", logbuf);
req->connect_request = TRUE;
}
if(*p != ']')
logmsg("Invalid CONNECT IPv6 address format");
- else if (*(p+1) != ':')
+ else if(*(p+1) != ':')
logmsg("Invalid CONNECT IPv6 port format");
else
portp = p+1;
else
req->partno = 0;
- sprintf(logbuf, "Requested test number %ld part %ld (from host name)",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf),
+ "Requested test number %ld part %ld (from host name)",
+ req->testno, req->partno);
logmsg("%s", logbuf);
}
else
req->partno = 0;
- sprintf(logbuf, "Requested GOPHER test number %ld part %ld",
- req->testno, req->partno);
+ snprintf(logbuf, sizeof(logbuf),
+ "Requested GOPHER test number %ld part %ld",
+ req->testno, req->partno);
logmsg("%s", logbuf);
}
}
FILE *dump;
const char *dumpfile=is_proxy?REQUEST_PROXY_DUMP:REQUEST_DUMP;
- if (reqbuf == NULL)
+ if(reqbuf == NULL)
return;
- if (totalsize == 0)
+ if(totalsize == 0)
return;
do {
dump = fopen(dumpfile, "ab");
- } while ((dump == NULL) && ((error = errno) == EINTR));
- if (dump == NULL) {
+ } while((dump == NULL) && ((error = errno) == EINTR));
+ if(dump == NULL) {
logmsg("[2] Error opening file %s error: %d %s",
dumpfile, error, strerror(error));
logmsg("Failed to write request input ");
goto storerequest_cleanup;
if(written > 0)
writeleft -= written;
- } while ((writeleft > 0) && ((error = errno) == EINTR));
+ } while((writeleft > 0) && ((error = errno) == EINTR));
if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile);
}
else if(got < 0) {
error = SOCKERRNO;
- if (EAGAIN == error || EWOULDBLOCK == error) {
+ if(EAGAIN == error || EWOULDBLOCK == error) {
/* nothing to read at the moment */
return 0;
}
reqbuf[req->offset] = '\0';
/* at the end of a request dump it to an external file */
- if (fail || req->done_processing)
+ if(fail || req->done_processing)
storerequest(reqbuf, req->pipelining ? req->checkindex : req->offset);
if(got_exit_signal)
return -1;
case RCMD_STREAM:
#define STREAMTHIS "a string to stream 01234567890\n"
count = strlen(STREAMTHIS);
- for (;;) {
+ for(;;) {
written = swrite(sock, STREAMTHIS, count);
if(got_exit_signal)
return -1;
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",
- msglen, msgbuf);
+ snprintf(weare, sizeof(weare),
+ "HTTP/1.1 200 OK\r\nContent-Length: %zu\r\n\r\n%s",
+ msglen, msgbuf);
buffer = weare;
break;
case DOCNUMBER_404:
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);
if(num > 200)
num = 200;
written = swrite(sock, buffer, num);
- if (written < 0) {
+ if(written < 0) {
sendfailure = TRUE;
break;
}
}
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);
responsesize, responsedump);
free(ptr);
- if(cmdsize > 0 ) {
+ if(cmdsize > 0) {
char command[32];
int quarters;
int num;
/* 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;
while(!req->done_processing) {
int rc = get_request(msgsock, req);
- if (rc <= 0) {
+ if(rc <= 0) {
/* Nothing further to read now (possibly because the socket was closed */
return rc;
}
/* socket server is not alive, now check if it was actually a socket.
* Systems which have Unix sockets will also have lstat */
rc = lstat(unix_socket, &statbuf);
- if (0 != rc) {
+ if(0 != rc) {
logmsg("Error binding socket, failed to stat %s: (%d) %s",
unix_socket, errno, strerror(errno));
goto sws_cleanup;
curl_socket_t maxfd = (curl_socket_t)-1;
/* Clear out closed sockets */
- for (socket_idx = num_sockets - 1; socket_idx >= 1; --socket_idx) {
- if (CURL_SOCKET_BAD == all_sockets[socket_idx]) {
+ for(socket_idx = num_sockets - 1; socket_idx >= 1; --socket_idx) {
+ if(CURL_SOCKET_BAD == all_sockets[socket_idx]) {
char* dst = (char *) (all_sockets + socket_idx);
char* src = (char *) (all_sockets + socket_idx + 1);
char* end = (char *) (all_sockets + num_sockets);
FD_ZERO(&input);
FD_ZERO(&output);
- for (socket_idx = 0; socket_idx < num_sockets; ++socket_idx) {
+ for(socket_idx = 0; socket_idx < num_sockets; ++socket_idx) {
/* Listen on all sockets */
FD_SET(all_sockets[socket_idx], &input);
if(all_sockets[socket_idx] > maxfd)
goto sws_cleanup;
rc = select((int)maxfd + 1, &input, &output, NULL, &timeout);
- if (rc < 0) {
+ if(rc < 0) {
error = SOCKERRNO;
logmsg("select() failed with error: (%d) %s",
error, strerror(error));
if(got_exit_signal)
goto sws_cleanup;
- if (rc == 0) {
+ if(rc == 0) {
/* Timed out - try again*/
continue;
}
/* Check if the listening socket is ready to accept */
- if (FD_ISSET(all_sockets[0], &input)) {
+ if(FD_ISSET(all_sockets[0], &input)) {
/* Service all queued connections */
curl_socket_t msgsock;
do {
msgsock = accept_connection(sock);
logmsg("accept_connection %d returned %d", sock, msgsock);
- if (CURL_SOCKET_BAD == msgsock)
+ if(CURL_SOCKET_BAD == msgsock)
goto sws_cleanup;
- } while (msgsock > 0);
+ } while(msgsock > 0);
}
/* Service all connections that are ready */
- for (socket_idx = 1; socket_idx < num_sockets; ++socket_idx) {
- if (FD_ISSET(all_sockets[socket_idx], &input)) {
+ for(socket_idx = 1; socket_idx < num_sockets; ++socket_idx) {
+ if(FD_ISSET(all_sockets[socket_idx], &input)) {
if(got_exit_signal)
goto sws_cleanup;
if(got_exit_signal)
goto sws_cleanup;
- if (rc < 0) {
+ if(rc < 0) {
logmsg("====> Client disconnect %d", req.connmon);
if(req.connmon) {
if(!serverlogslocked)
clear_advisor_read_lock(SERVERLOGS_LOCK);
- if (req.testno == DOCNUMBER_QUIT)
+ if(req.testno == DOCNUMBER_QUIT)
goto sws_cleanup;
}
/* Reset the request, unless we're still in the middle of reading */
- if (rc != 0)
+ if(rc != 0)
init_httprequest(&req);
- } while (rc > 0);
+ } while(rc > 0);
}
}
sws_cleanup:
- for (socket_idx = 1; socket_idx < num_sockets; ++socket_idx)
+ for(socket_idx = 1; socket_idx < num_sockets; ++socket_idx)
if((all_sockets[socket_idx] != sock) &&
(all_sockets[socket_idx] != CURL_SOCKET_BAD))
sclose(all_sockets[socket_idx]);
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
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);
current = !current; /* "incr" current */
b = &bfs[current]; /* look at new buffer */
- if (b->counter == BF_FREE) /* if it's empty */
+ if(b->counter == BF_FREE) /* if it's empty */
read_ahead(test, convert); /* fill it */
*dpp = &b->buf.hdr; /* set caller's ptr */
/*
* fill the input buffer, doing ascii conversions if requested
- * conversions are lf -> cr,lf and cr -> cr, nul
+ * conversions are lf -> cr, lf and cr -> cr, nul
*/
static void read_ahead(struct testcase *test,
int convert /* if true, convert to ascii */)
struct tftphdr *dp;
b = &bfs[nextone]; /* look at "next" buffer */
- if (b->counter != BF_FREE) /* nop if not free */
+ if(b->counter != BF_FREE) /* nop if not free */
return;
nextone = !nextone; /* "incr" next buffer ptr */
dp = &b->buf.hdr;
- if (convert == 0) {
+ if(convert == 0) {
/* The former file reading code did this:
b->counter = read(fileno(file), dp->th_data, SEGSIZE); */
size_t copy_n = MIN(SEGSIZE, test->rcount);
}
p = dp->th_data;
- for (i = 0 ; i < SEGSIZE; i++) {
- if (newline) {
- if (prevchar == '\n')
+ for(i = 0 ; i < SEGSIZE; i++) {
+ if(newline) {
+ if(prevchar == '\n')
c = '\n'; /* lf to cr,lf */
else
c = '\0'; /* cr to cr,nul */
}
else
break;
- if (c == '\n' || c == '\r') {
+ if(c == '\n' || c == '\r') {
prevchar = c;
c = '\r';
newline = 1;
{
bfs[current].counter = ct; /* set size of data to write */
current = !current; /* switch to other buffer */
- if (bfs[current].counter != BF_FREE) /* if not free */
+ if(bfs[current].counter != BF_FREE) /* if not free */
write_behind(test, convert); /* flush it */
bfs[current].counter = BF_ALLOC; /* mark as alloc'd */
*dpp = &bfs[current].buf.hdr;
/*
* Output a buffer to a file, converting from netascii if requested.
- * CR,NUL -> CR and CR,LF => LF.
+ * CR, NUL -> CR and CR, LF => LF.
* Note spec is undefined if we get CR as last byte of file or a
* CR followed by anything else. In this case we leave it alone.
*/
struct tftphdr *dp;
b = &bfs[nextone];
- if (b->counter < -1) /* anything to flush? */
+ if(b->counter < -1) /* anything to flush? */
return 0; /* just nop if nothing to do */
if(!test->ofile) {
nextone = !nextone; /* incr for next time */
writebuf = dp->th_data;
- if (count <= 0)
+ if(count <= 0)
return -1; /* nak logic? */
- if (convert == 0)
+ if(convert == 0)
return write(test->ofile, writebuf, count);
p = writebuf;
ct = count;
- while (ct--) { /* loop over the buffer */
+ while(ct--) { /* loop over the buffer */
c = *p++; /* pick up a character */
- if (prevchar == '\r') { /* if prev char was cr */
- if (c == '\n') /* if have cr,lf then just */
+ if(prevchar == '\r') { /* if prev char was cr */
+ if(c == '\n') /* if have cr,lf then just */
lseek(test->ofile, -1, SEEK_CUR); /* smash lf on top of the cr */
else
- if (c == '\0') /* if have cr,nul then */
+ if(c == '\0') /* if have cr,nul then */
goto skipit; /* just skip over the putc */
/* else just fall through and allow it */
}
srvr_sockaddr_union_t fromaddr;
curl_socklen_t fromaddrlen;
- for (;;) {
+ for(;;) {
#if defined(HAVE_IOCTLSOCKET)
(void) ioctlsocket(f, FIONREAD, &i);
#else
(void) ioctl(f, FIONREAD, &i);
#endif
- if (i) {
+ if(i) {
j++;
#ifdef ENABLE_IPV6
if(!use_ipv6)
}
flag = 1;
- if (0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
+ if(0 != setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&flag, sizeof(flag))) {
error = SOCKERRNO;
logmsg("setsockopt(SO_REUSEADDR) failed with error: (%d) %s",
logmsg("Running %s version on port UDP/%d", ipv_inuse, (int)port);
- for (;;) {
+ for(;;) {
fromlen = sizeof(from);
#ifdef ENABLE_IPV6
if(!use_ipv6)
&from.sa, &fromlen);
if(got_exit_signal)
break;
- if (n < 0) {
+ if(n < 0) {
logmsg("recvfrom");
result = 3;
break;
tp = &buf.hdr;
tp->th_opcode = ntohs(tp->th_opcode);
- if (tp->th_opcode == opcode_RRQ || tp->th_opcode == opcode_WRQ) {
+ if(tp->th_opcode == opcode_RRQ || tp->th_opcode == opcode_WRQ) {
memset(&test, 0, sizeof(test));
- if (do_tftp(&test, tp, n) < 0)
+ if(do_tftp(&test, tp, n) < 0)
break;
free(test.buffer);
}
filename = cp;
do {
bool endofit = true;
- while (cp < &buf.storage[size]) {
- if (*cp == '\0') {
+ while(cp < &buf.storage[size]) {
+ if(*cp == '\0') {
endofit = false;
break;
}
break;
} while(1);
- if (*cp) {
+ if(*cp) {
nak(EBADOP);
fclose(server);
return 3;
/* store input protocol */
fprintf(server, "filename: %s\n", filename);
- for (cp = mode; cp && *cp; cp++)
+ for(cp = mode; cp && *cp; cp++)
if(ISUPPER(*cp))
*cp = (char)tolower((int)*cp);
/* store input protocol */
fclose(server);
- for (pf = formata; pf->f_mode; pf++)
- if (strcmp(pf->f_mode, mode) == 0)
+ for(pf = formata; pf->f_mode; pf++)
+ if(strcmp(pf->f_mode, mode) == 0)
break;
- if (!pf->f_mode) {
+ if(!pf->f_mode) {
nak(EBADOP);
return 2;
}
ecode = validate_access(test, filename, tp->th_opcode);
- if (ecode) {
+ if(ecode) {
nak(ecode);
return 1;
}
(const char*)&recvtimeout, sizeof(recvtimeout));
#endif
- if (tp->th_opcode == opcode_WRQ)
+ if(tp->th_opcode == opcode_WRQ)
recvtftp(test, pf);
else
sendtftp(test, pf);
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);
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");
sap = &ackbuf.hdr;
do {
size = readit(test, &sdp, pf->f_convert);
- if (size < 0) {
+ if(size < 0) {
nak(errno + 100);
return;
}
}
send_data:
- if (swrite(peer, sdp, size + 4) != size + 4) {
+ if(swrite(peer, sdp, size + 4) != size + 4) {
logmsg("write");
return;
}
read_ahead(test, pf->f_convert);
- for ( ; ; ) {
+ for(;;) {
#ifdef HAVE_ALARM
alarm(rexmtval); /* read the ack */
#endif
#endif
if(got_exit_signal)
return;
- if (n < 0) {
+ if(n < 0) {
logmsg("read: fail");
return;
}
sap->th_opcode = ntohs((unsigned short)sap->th_opcode);
sap->th_block = ntohs(sap->th_block);
- if (sap->th_opcode == opcode_ERROR) {
+ if(sap->th_opcode == opcode_ERROR) {
logmsg("got ERROR");
return;
}
- if (sap->th_opcode == opcode_ACK) {
- if (sap->th_block == sendblock) {
+ if(sap->th_opcode == opcode_ACK) {
+ if(sap->th_block == sendblock) {
break;
}
/* Re-synchronize with the other side */
(void) synchnet(peer);
- if (sap->th_block == (sendblock-1)) {
+ if(sap->th_block == (sendblock-1)) {
goto send_data;
}
}
}
sendblock++;
- } while (size == SEGSIZE);
+ } while(size == SEGSIZE);
}
/*
(void) sigsetjmp(timeoutbuf, 1);
#endif
send_ack:
- if (swrite(peer, &ackbuf.storage[0], 4) != 4) {
+ if(swrite(peer, &ackbuf.storage[0], 4) != 4) {
logmsg("write: fail\n");
goto abort;
}
write_behind(test, pf->f_convert);
- for ( ; ; ) {
+ for(;;) {
#ifdef HAVE_ALARM
alarm(rexmtval);
#endif
#endif
if(got_exit_signal)
goto abort;
- if (n < 0) { /* really? */
+ if(n < 0) { /* really? */
logmsg("read: fail\n");
goto abort;
}
rdp->th_opcode = ntohs((unsigned short)rdp->th_opcode);
rdp->th_block = ntohs(rdp->th_block);
- if (rdp->th_opcode == opcode_ERROR)
+ if(rdp->th_opcode == opcode_ERROR)
goto abort;
- if (rdp->th_opcode == opcode_DATA) {
- if (rdp->th_block == recvblock) {
+ if(rdp->th_opcode == opcode_DATA) {
+ if(rdp->th_block == recvblock) {
break; /* normal */
}
/* Re-synchronize with the other side */
(void) synchnet(peer);
- if (rdp->th_block == (recvblock-1))
+ if(rdp->th_block == (recvblock-1))
goto send_ack; /* rexmit */
}
}
size = writeit(test, &rdp, (int)(n - 4), pf->f_convert);
- if (size != (n-4)) { /* ahem */
- if (size < 0)
+ if(size != (n-4)) { /* ahem */
+ if(size < 0)
nak(errno + 100);
else
nak(ENOSPACE);
goto abort;
}
- } while (size == SEGSIZE);
+ } 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)
#endif
if(got_exit_signal)
goto abort;
- if (n >= 4 && /* if read some data */
- rdp->th_opcode == opcode_DATA && /* and got a data block */
- recvblock == rdp->th_block) { /* then my last ack was lost */
+ if(n >= 4 && /* if read some data */
+ rdp->th_opcode == opcode_DATA && /* and got a data block */
+ recvblock == rdp->th_block) { /* then my last ack was lost */
(void) swrite(peer, &ackbuf.storage[0], 4); /* resend final ack */
}
abort:
tp = &buf.hdr;
tp->th_opcode = htons((unsigned short)opcode_ERROR);
tp->th_code = htons((unsigned short)error);
- for (pe = errmsgs; pe->e_code >= 0; pe++)
- if (pe->e_code == error)
+ for(pe = errmsgs; pe->e_code >= 0; pe++)
+ if(pe->e_code == error)
break;
- if (pe->e_code < 0) {
+ if(pe->e_code < 0) {
pe->e_msg = strerror(error - 100);
tp->th_code = EUNDEF; /* set 'undef' errorcode */
}
* report from glibc with FORTIFY_SOURCE */
memcpy(tp->th_msg, pe->e_msg, length + 1);
length += 5;
- if (swrite(peer, &buf.storage[0], length) != length)
+ if(swrite(peer, &buf.storage[0], length) != length)
logmsg("nak: fail\n");
}
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
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;
}
static time_t epoch_offset;
static int known_offset;
- if (!serverlogfile) {
+ if(!serverlogfile) {
fprintf(stderr, "Error: serverlogfile not set\n");
return;
}
char buf[512];
DWORD err = SOCKERRNO;
- if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
- LANG_NEUTRAL, buf, sizeof(buf), NULL))
+ if(!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
+ LANG_NEUTRAL, buf, sizeof(buf), NULL))
snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
- if (msg)
- fprintf(stderr, "%s: ", msg);
+ if(msg)
+ fprintf(stderr, "%s: ", msg);
fprintf(stderr, "%s\n", buf);
}
#endif /* WIN32 */
err = WSAStartup(wVersionRequested, &wsaData);
- if (err != 0) {
+ if(err != 0) {
perror("Winsock init failed");
logmsg("Error initialising winsock -- aborting");
exit(1);
}
- if ( LOBYTE( wsaData.wVersion ) != USE_WINSOCK ||
- HIBYTE( wsaData.wVersion ) != USE_WINSOCK ) {
-
+ if(LOBYTE(wsaData.wVersion) != USE_WINSOCK ||
+ HIBYTE(wsaData.wVersion) != USE_WINSOCK) {
WSACleanup();
perror("Winsock init failed");
logmsg("No suitable winsock.dll found -- aborting");