* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * 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;
}