mirror of
https://github.com/curl/curl.git
synced 2026-08-25 06:03:32 +03:00
tests/server: comply with our code style
This commit is contained in:
parent
a71012c03e
commit
a332c4f769
9 changed files with 240 additions and 210 deletions
|
|
@ -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
|
||||
|
|
@ -353,15 +353,15 @@ static int ProcessRequest(struct httprequest *req)
|
|||
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;
|
||||
|
|
@ -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",
|
||||
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);
|
||||
|
||||
|
|
@ -409,8 +409,8 @@ static int ProcessRequest(struct httprequest *req)
|
|||
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);
|
||||
|
|
@ -488,7 +488,7 @@ static int ProcessRequest(struct httprequest *req)
|
|||
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);
|
||||
|
|
@ -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,8 +533,9 @@ 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",
|
||||
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)
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
@ -723,15 +729,15 @@ static void storerequest(char *reqbuf, size_t totalsize)
|
|||
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);
|
||||
|
|
@ -746,7 +752,7 @@ static void storerequest(char *reqbuf, size_t totalsize)
|
|||
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);
|
||||
|
|
@ -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);
|
||||
|
|
@ -908,7 +914,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
|
|||
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;
|
||||
|
|
@ -937,10 +943,12 @@ 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",
|
||||
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:
|
||||
|
|
@ -958,9 +966,10 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
|
|||
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;
|
||||
}
|
||||
|
|
@ -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) {
|
||||
|
|
@ -1058,7 +1067,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
|
|||
if(num > 200)
|
||||
num = 200;
|
||||
written = swrite(sock, buffer, num);
|
||||
if (written < 0) {
|
||||
if(written < 0) {
|
||||
sendfailure = TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
@ -1119,7 +1130,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req)
|
|||
responsesize);
|
||||
free(ptr);
|
||||
|
||||
if(cmdsize > 0 ) {
|
||||
if(cmdsize > 0) {
|
||||
char command[32];
|
||||
int quarters;
|
||||
int num;
|
||||
|
|
@ -1278,7 +1289,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
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",
|
||||
|
|
@ -1331,12 +1342,12 @@ int main(int argc, char *argv[])
|
|||
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));
|
||||
|
|
@ -1360,7 +1371,7 @@ int main(int argc, char *argv[])
|
|||
* 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");
|
||||
}
|
||||
|
|
@ -1424,7 +1435,7 @@ int main(int argc, char *argv[])
|
|||
clear_advisor_read_lock(SERVERLOGS_LOCK);
|
||||
}
|
||||
|
||||
if (req.testno == DOCNUMBER_QUIT)
|
||||
if(req.testno == DOCNUMBER_QUIT)
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue