* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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
- * are also available at http://curl.haxx.se/docs/copyright.html.
+ * are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
/* 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]);