tests: fix formatting nits

Also:
- lib1948: fix checksrc error TYPEDEFSTRUCT.
  (detected after formatting)

Closes #19754
This commit is contained in:
Viktor Szakats 2025-11-28 21:17:58 +01:00
parent 4be6707910
commit d73efc62c1
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
123 changed files with 684 additions and 805 deletions

View file

@ -26,8 +26,7 @@
static int dnsd_wrotepidfile = 0;
static int dnsd_wroteportfile = 0;
static unsigned short get16bit(const unsigned char **pkt,
size_t *size)
static unsigned short get16bit(const unsigned char **pkt, size_t *size)
{
const unsigned char *p = *pkt;
(*pkt) += 2;
@ -140,7 +139,7 @@ static int store_incoming(const unsigned char *data, size_t size,
fprintf(server, "Z: %x\n", (id & 0x70) >> 4);
fprintf(server, "RCODE: %x\n", (id & 0x0f));
#endif
(void) get16bit(&data, &size);
(void)get16bit(&data, &size);
data += 6; /* skip ANCOUNT, NSCOUNT and ARCOUNT */
size -= 6;
@ -153,10 +152,9 @@ static int store_incoming(const unsigned char *data, size_t size,
qd = get16bit(&data, &size);
fprintf(server, "QNAME %s QTYPE %s\n", name, type2string(qd));
*qtype = qd;
logmsg("Question for '%s' type %x / %s", name, qd,
type2string(qd));
logmsg("Question for '%s' type %x / %s", name, qd, type2string(qd));
(void) get16bit(&data, &size);
(void)get16bit(&data, &size);
*qlen = qsize - size; /* total size of the query */
if(*qlen > qbuflen) {
@ -311,7 +309,7 @@ static int send_response(curl_socket_t sock,
fprintf(stderr, "Not working\n");
return -1;
#else
rc = sendto(sock, (const void *)bytes, (SENDTO3) i, 0, addr, addrlen);
rc = sendto(sock, (const void *)bytes, (SENDTO3)i, 0, addr, addrlen);
if(rc != (ssize_t)i) {
fprintf(stderr, "failed sending %d bytes\n", (int)i);
}
@ -319,7 +317,6 @@ static int send_response(curl_socket_t sock,
return 0;
}
static void read_instructions(void)
{
char file[256];
@ -412,7 +409,7 @@ static int test_dnsd(int argc, char **argv)
#else
""
#endif
);
);
return 0;
}
else if(!strcmp("--pidfile", argv[arg])) {
@ -475,7 +472,7 @@ static int test_dnsd(int argc, char **argv)
}
snprintf(loglockfile, sizeof(loglockfile), "%s/%s/dnsd-%s.lock",
logdir, SERVERLOGS_LOCKDIR, ipv_inuse);
logdir, SERVERLOGS_LOCKDIR, ipv_inuse);
#ifdef _WIN32
if(win32_init())

View file

@ -182,8 +182,8 @@ static int appenddata(char **dst_buf, /* dest buffer */
return GPE_OK;
}
static int decodedata(char **buf, /* dest buffer */
size_t *len) /* dest buffer data length */
static int decodedata(char **buf, /* dest buffer */
size_t *len) /* dest buffer data length */
{
CURLcode error = CURLE_OK;
unsigned char *buf64 = NULL;
@ -254,7 +254,7 @@ int getpart(char **outbuf, size_t *outlen,
char *end;
union {
ssize_t sig;
size_t uns;
size_t uns;
} len;
size_t bufsize = 0;
size_t outalloc = 256;
@ -288,8 +288,7 @@ int getpart(char **outbuf, size_t *outlen,
if('<' != *ptr) {
if(in_wanted_part) {
show(("=> %s", buffer));
error = appenddata(outbuf, outlen, &outalloc, buffer, datalen,
base64);
error = appenddata(outbuf, outlen, &outalloc, buffer, datalen, base64);
if(error)
break;
}
@ -353,7 +352,6 @@ int getpart(char **outbuf, size_t *outlen,
if(in_wanted_part)
break;
}
}
else if(!in_wanted_part) {
/*
@ -411,9 +409,9 @@ int getpart(char **outbuf, size_t *outlen,
/* start of wanted part */
in_wanted_part = 1;
if(strstr(patt, "base64="))
/* bit rough test, but "mostly" functional, */
/* treat wanted part data as base64 encoded */
base64 = 1;
/* bit rough test, but "mostly" functional, */
/* treat wanted part data as base64 encoded */
base64 = 1;
if(strstr(patt, "nonewline=")) {
show(("* setting nonewline\n"));
nonewline = 1;
@ -421,7 +419,6 @@ int getpart(char **outbuf, size_t *outlen,
}
continue;
}
}
if(in_wanted_part) {

View file

@ -156,7 +156,7 @@ static void logprotocol(mqttdir dir,
/* return 0 on success */
static int connack(FILE *dump, curl_socket_t fd)
{
unsigned char packet[]={
unsigned char packet[] = {
MQTT_MSG_CONNACK, 0x02,
0x00, 0x00
};
@ -283,7 +283,6 @@ static size_t encode_length(size_t packetlen,
return bytes;
}
static size_t decode_length(unsigned char *buffer,
size_t buflen, size_t *lenbytes)
{
@ -304,7 +303,6 @@ static size_t decode_length(unsigned char *buffer,
return len;
}
/* return 0 on success */
static int publish(FILE *dump,
curl_socket_t fd, unsigned short packetid,
@ -408,7 +406,7 @@ static int fixedheader(curl_socket_t fd,
static curl_socket_t mqttit(curl_socket_t fd)
{
size_t buff_size = 10*1024;
size_t buff_size = 10 * 1024;
unsigned char *buffer = NULL;
ssize_t rc;
unsigned char byte;
@ -482,8 +480,7 @@ static curl_socket_t mqttit(curl_socket_t fd)
}
if(byte == MQTT_MSG_CONNECT) {
logprotocol(FROM_CLIENT, "CONNECT", remaining_length,
dump, buffer, rc);
logprotocol(FROM_CLIENT, "CONNECT", remaining_length, dump, buffer, rc);
if(memcmp(protocol, buffer, sizeof(protocol))) {
logmsg("Protocol preamble mismatch");
@ -607,8 +604,7 @@ static curl_socket_t mqttit(curl_socket_t fd)
size_t topiclen;
logmsg("Incoming PUBLISH");
logprotocol(FROM_CLIENT, "PUBLISH", remaining_length,
dump, buffer, rc);
logprotocol(FROM_CLIENT, "PUBLISH", remaining_length, dump, buffer, rc);
topiclen = (size_t)(buffer[1 + bytes] << 8) | buffer[2 + bytes];
logmsg("Got %zu bytes topic", topiclen);
@ -754,7 +750,7 @@ static int test_mqttd(int argc, char *argv[])
#else
""
#endif
);
);
return 0;
}
else if(!strcmp("--pidfile", argv[arg])) {
@ -802,8 +798,7 @@ static int test_mqttd(int argc, char *argv[])
if(argc > arg) {
opt = argv[arg];
if(curlx_str_number(&opt, &num, 0xffff)) {
fprintf(stderr, "mqttd: invalid --port argument (%s)\n",
argv[arg]);
fprintf(stderr, "mqttd: invalid --port argument (%s)\n", argv[arg]);
return 0;
}
server_port = (unsigned short)num;

View file

@ -47,7 +47,7 @@ static int test_resolve(int argc, char *argv[])
#else
""
#endif
);
);
return 0;
}
else if(!strcmp("--ipv6", argv[arg])) {
@ -79,7 +79,7 @@ static int test_resolve(int argc, char *argv[])
#ifdef CURLRES_IPV6
"\n --ipv6"
#endif
);
);
return 1;
}

View file

@ -50,10 +50,10 @@ typedef enum {
RPROT_HTTP = 2
} reqprot_t;
#define SET_RTP_PKT_CHN(p,c) ((p)[1] = (char)((c) & 0xFF))
#define SET_RTP_PKT_CHN(p, c) ((p)[1] = (char)((c) & 0xFF))
#define SET_RTP_PKT_LEN(p,l) (((p)[2] = (char)(((l) >> 8) & 0xFF)), \
((p)[3] = (char)((l) & 0xFF)))
#define SET_RTP_PKT_LEN(p, l) (((p)[2] = (char)(((l) >> 8) & 0xFF)), \
((p)[3] = (char)((l) & 0xFF)))
struct rtspd_httprequest {
char reqbuf[150000]; /* buffer area for the incoming request */
@ -105,10 +105,8 @@ struct rtspd_httprequest {
#define END_OF_HEADERS "\r\n\r\n"
/* sent as reply to a QUIT */
static const char *docquit_rtsp =
"HTTP/1.1 200 Goodbye" END_OF_HEADERS;
static const char *docquit_rtsp = "HTTP/1.1 200 Goodbye" END_OF_HEADERS;
/* sent as reply to a CONNECT */
static const char *docconnect =
@ -180,7 +178,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
return 1;
}
req->prot_version = prot_major*10 + prot_minor;
req->prot_version = prot_major * 10 + prot_minor;
/* find the last slash */
ptr = strrchr(doc, '/');
@ -285,8 +283,8 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
if(num < 0)
logmsg("negative pipe size ignored");
else if(num > 0)
req->pipe = num-1; /* decrease by one since we do not count the
first request in this number */
req->pipe = num - 1; /* decrease by one since we do not count
the first request in this number */
}
else if(sscanf(ptr, "skip: %d", &num) == 1) {
logmsg("instructed to skip this number of bytes %d", num);
@ -569,7 +567,7 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize)
writeleft = totalsize;
do {
written = fwrite(&reqbuf[totalsize-writeleft], 1, writeleft, dump);
written = fwrite(&reqbuf[totalsize - writeleft], 1, writeleft, dump);
if(got_exit_signal)
goto storerequest_cleanup;
if(written > 0)
@ -584,7 +582,7 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize)
logmsg("Error writing file %s error (%d) %s", dumpfile,
error, curlx_strerror(error, errbuf, sizeof(errbuf)));
logmsg("Wrote only (%zu bytes) of (%zu bytes) request input to %s",
totalsize-writeleft, totalsize, dumpfile);
totalsize - writeleft, totalsize, dumpfile);
}
storerequest_cleanup:
@ -636,7 +634,7 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req)
/*** end of httprequest init ***/
while(!done_processing && (req->offset < sizeof(req->reqbuf)-1)) {
while(!done_processing && (req->offset < sizeof(req->reqbuf) - 1)) {
if(pipereq_length && pipereq) {
memmove(reqbuf, pipereq, pipereq_length);
got = curlx_uztosz(pipereq_length);
@ -650,7 +648,7 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req)
got = sread(sock, reqbuf + req->offset, req->cl);
else
got = sread(sock, reqbuf + req->offset,
sizeof(req->reqbuf)-1 - req->offset);
sizeof(req->reqbuf) - 1 - req->offset);
}
if(got_exit_signal)
return 1;
@ -686,16 +684,16 @@ static int rtspd_get_request(curl_socket_t sock, struct rtspd_httprequest *req)
}
}
if((req->offset == sizeof(req->reqbuf)-1) && (got > 0)) {
if((req->offset == sizeof(req->reqbuf) - 1) && (got > 0)) {
logmsg("Request would overflow buffer, closing connection");
/* dump request received so far to external file anyway */
reqbuf[sizeof(req->reqbuf)-1] = '\0';
reqbuf[sizeof(req->reqbuf) - 1] = '\0';
fail = 1;
}
else if(req->offset > sizeof(req->reqbuf)-1) {
else if(req->offset > sizeof(req->reqbuf) - 1) {
logmsg("Request buffer overflow, closing connection");
/* dump request received so far to external file anyway */
reqbuf[sizeof(req->reqbuf)-1] = '\0';
reqbuf[sizeof(req->reqbuf) - 1] = '\0';
fail = 1;
}
else
@ -739,10 +737,10 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req)
case RCMD_STREAM: {
static const char streamthis[] = "a string to stream 01234567890\n";
for(;;) {
written = swrite(sock, streamthis, sizeof(streamthis)-1);
written = swrite(sock, streamthis, sizeof(streamthis) - 1);
if(got_exit_signal)
return -1;
if(written != (ssize_t)(sizeof(streamthis)-1)) {
if(written != (ssize_t)(sizeof(streamthis) - 1)) {
logmsg("Stopped streaming");
break;
}
@ -803,7 +801,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req)
}
else {
FILE *stream = test2fopen(req->testno, logdir);
char partbuf[80]="data";
char partbuf[80] = "data";
if(req->partno)
snprintf(partbuf, sizeof(partbuf), "data%ld", req->partno);
if(!stream) {
@ -942,7 +940,7 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req)
if(sendfailure) {
logmsg("Sending response failed. Only (%zu bytes) of "
"(%zu bytes) were sent",
responsesize-count, responsesize);
responsesize - count, responsesize);
free(ptr);
free(cmd);
return -1;
@ -997,7 +995,6 @@ static int rtspd_send_doc(curl_socket_t sock, struct rtspd_httprequest *req)
return 0;
}
static int test_rtspd(int argc, char *argv[])
{
srvr_sockaddr_union_t me;
@ -1031,7 +1028,7 @@ static int test_rtspd(int argc, char *argv[])
#else
""
#endif
);
);
return 0;
}
else if(!strcmp("--pidfile", argv[arg])) {
@ -1126,8 +1123,7 @@ static int test_rtspd(int argc, char *argv[])
}
flag = 1;
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&flag, sizeof(flag))) {
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flag, sizeof(flag))) {
error = SOCKERRNO;
logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s",
error, curlx_strerror(error, errbuf, sizeof(errbuf)));

View file

@ -420,7 +420,7 @@ static DWORD WINAPI select_ws_wait_thread(void *lpParameter)
DWORD type, length, ret;
/* retrieve handles from internal structure */
data = (struct select_ws_wait_data *) lpParameter;
data = (struct select_ws_wait_data *)lpParameter;
if(data) {
handle = data->handle;
handles[0] = data->abort;
@ -434,120 +434,120 @@ static DWORD WINAPI select_ws_wait_thread(void *lpParameter)
/* retrieve the type of file to wait on */
type = GetFileType(handle);
switch(type) {
case FILE_TYPE_DISK:
/* The handle represents a file on disk, this means:
* - WaitForMultipleObjectsEx will always be signalled for it.
* - comparison of current position in file and total size of
* the file can be used to check if we reached the end yet.
*
* Approach: Loop till either the internal event is signalled
* or if the end of the file has already been reached.
*/
while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE)
== WAIT_TIMEOUT) {
/* get total size of file */
length = 0;
size.QuadPart = 0;
size.LowPart = GetFileSize(handle, &length);
if((size.LowPart != INVALID_FILE_SIZE) ||
case FILE_TYPE_DISK:
/* The handle represents a file on disk, this means:
* - WaitForMultipleObjectsEx will always be signalled for it.
* - comparison of current position in file and total size of
* the file can be used to check if we reached the end yet.
*
* Approach: Loop till either the internal event is signalled
* or if the end of the file has already been reached.
*/
while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE)
== WAIT_TIMEOUT) {
/* get total size of file */
length = 0;
size.QuadPart = 0;
size.LowPart = GetFileSize(handle, &length);
if((size.LowPart != INVALID_FILE_SIZE) ||
(GetLastError() == NO_ERROR)) {
size.HighPart = (LONG)length;
/* get the current position within the file */
pos.QuadPart = 0;
pos.LowPart = SetFilePointer(handle, 0, &pos.HighPart, FILE_CURRENT);
if((pos.LowPart != INVALID_SET_FILE_POINTER) ||
(GetLastError() == NO_ERROR)) {
size.HighPart = (LONG)length;
/* get the current position within the file */
pos.QuadPart = 0;
pos.LowPart = SetFilePointer(handle, 0, &pos.HighPart, FILE_CURRENT);
if((pos.LowPart != INVALID_SET_FILE_POINTER) ||
(GetLastError() == NO_ERROR)) {
/* compare position with size, abort if not equal */
if(size.QuadPart == pos.QuadPart) {
/* sleep and continue waiting */
SleepEx(0, FALSE);
continue;
}
}
}
/* there is some data available, stop waiting */
logmsg("[select_ws_wait_thread] data available, DISK: %p", handle);
SetEvent(signal);
}
break;
case FILE_TYPE_CHAR:
/* The handle represents a character input, this means:
* - WaitForMultipleObjectsEx will be signalled on any kind of input,
* including mouse and window size events we do not care about.
*
* Approach: Loop till either the internal event is signalled
* or we get signalled for an actual key-event.
*/
while(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE)
== WAIT_OBJECT_0 + 1) {
/* check if this is an actual console handle */
if(GetConsoleMode(handle, &ret)) {
/* retrieve an event from the console buffer */
length = 0;
if(PeekConsoleInput(handle, &inputrecord, 1, &length)) {
/* check if the event is not an actual key-event */
if(length == 1 && inputrecord.EventType != KEY_EVENT) {
/* purge the non-key-event and continue waiting */
ReadConsoleInput(handle, &inputrecord, 1, &length);
continue;
}
}
}
/* there is some data available, stop waiting */
logmsg("[select_ws_wait_thread] data available, CHAR: %p", handle);
SetEvent(signal);
}
break;
case FILE_TYPE_PIPE:
/* The handle represents an anonymous or named pipe, this means:
* - WaitForMultipleObjectsEx will always be signalled for it.
* - peek into the pipe and retrieve the amount of data available.
*
* Approach: Loop till either the internal event is signalled
* or there is data in the pipe available for reading.
*/
while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE)
== WAIT_TIMEOUT) {
/* peek into the pipe and retrieve the amount of data available */
length = 0;
if(PeekNamedPipe(handle, NULL, 0, NULL, &length, NULL)) {
/* if there is no data available, sleep and continue waiting */
if(length == 0) {
/* compare position with size, abort if not equal */
if(size.QuadPart == pos.QuadPart) {
/* sleep and continue waiting */
SleepEx(0, FALSE);
continue;
}
else {
logmsg("[select_ws_wait_thread] PeekNamedPipe len: %lu", length);
}
}
/* there is some data available, stop waiting */
logmsg("[select_ws_wait_thread] data available, DISK: %p", handle);
SetEvent(signal);
}
break;
case FILE_TYPE_CHAR:
/* The handle represents a character input, this means:
* - WaitForMultipleObjectsEx will be signalled on any kind of input,
* including mouse and window size events we do not care about.
*
* Approach: Loop till either the internal event is signalled
* or we get signalled for an actual key-event.
*/
while(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE)
== WAIT_OBJECT_0 + 1) {
/* check if this is an actual console handle */
if(GetConsoleMode(handle, &ret)) {
/* retrieve an event from the console buffer */
length = 0;
if(PeekConsoleInput(handle, &inputrecord, 1, &length)) {
/* check if the event is not an actual key-event */
if(length == 1 && inputrecord.EventType != KEY_EVENT) {
/* purge the non-key-event and continue waiting */
ReadConsoleInput(handle, &inputrecord, 1, &length);
continue;
}
}
}
/* there is some data available, stop waiting */
logmsg("[select_ws_wait_thread] data available, CHAR: %p", handle);
SetEvent(signal);
}
break;
case FILE_TYPE_PIPE:
/* The handle represents an anonymous or named pipe, this means:
* - WaitForMultipleObjectsEx will always be signalled for it.
* - peek into the pipe and retrieve the amount of data available.
*
* Approach: Loop till either the internal event is signalled
* or there is data in the pipe available for reading.
*/
while(WaitForMultipleObjectsEx(1, handles, FALSE, 0, FALSE)
== WAIT_TIMEOUT) {
/* peek into the pipe and retrieve the amount of data available */
length = 0;
if(PeekNamedPipe(handle, NULL, 0, NULL, &length, NULL)) {
/* if there is no data available, sleep and continue waiting */
if(length == 0) {
SleepEx(0, FALSE);
continue;
}
else {
/* if the pipe has NOT been closed, sleep and continue waiting */
ret = GetLastError();
if(ret != ERROR_BROKEN_PIPE) {
logmsg("[select_ws_wait_thread] PeekNamedPipe error (%lu)", ret);
SleepEx(0, FALSE);
continue;
}
else {
logmsg("[select_ws_wait_thread] pipe closed, PIPE: %p", handle);
}
logmsg("[select_ws_wait_thread] PeekNamedPipe len: %lu", length);
}
/* there is some data available, stop waiting */
logmsg("[select_ws_wait_thread] data available, PIPE: %p", handle);
SetEvent(signal);
}
break;
else {
/* if the pipe has NOT been closed, sleep and continue waiting */
ret = GetLastError();
if(ret != ERROR_BROKEN_PIPE) {
logmsg("[select_ws_wait_thread] PeekNamedPipe error (%lu)", ret);
SleepEx(0, FALSE);
continue;
}
else {
logmsg("[select_ws_wait_thread] pipe closed, PIPE: %p", handle);
}
}
/* there is some data available, stop waiting */
logmsg("[select_ws_wait_thread] data available, PIPE: %p", handle);
SetEvent(signal);
}
break;
default:
/* The handle has an unknown type, try to wait on it */
if(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE)
== WAIT_OBJECT_0 + 1) {
logmsg("[select_ws_wait_thread] data available, HANDLE: %p", handle);
SetEvent(signal);
}
break;
default:
/* The handle has an unknown type, try to wait on it */
if(WaitForMultipleObjectsEx(2, handles, FALSE, INFINITE, FALSE)
== WAIT_OBJECT_0 + 1) {
logmsg("[select_ws_wait_thread] data available, HANDLE: %p", handle);
SetEvent(signal);
}
break;
}
return 0;
@ -658,12 +658,12 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
if(FD_ISSET(wsasock, readfds)) {
FD_SET(wsasock, &readsock);
wsaevents.lNetworkEvents |= FD_READ|FD_ACCEPT|FD_CLOSE;
wsaevents.lNetworkEvents |= FD_READ | FD_ACCEPT | FD_CLOSE;
}
if(FD_ISSET(wsasock, writefds)) {
FD_SET(wsasock, &writesock);
wsaevents.lNetworkEvents |= FD_WRITE|FD_CONNECT|FD_CLOSE;
wsaevents.lNetworkEvents |= FD_WRITE | FD_CONNECT | FD_CLOSE;
}
if(FD_ISSET(wsasock, exceptfds)) {
@ -800,11 +800,11 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
wsaevents.lNetworkEvents |= data[i].wsastate;
/* remove from descriptor set if not ready for read/accept/close */
if(!(wsaevents.lNetworkEvents & (FD_READ|FD_ACCEPT|FD_CLOSE)))
if(!(wsaevents.lNetworkEvents & (FD_READ | FD_ACCEPT | FD_CLOSE)))
FD_CLR(wsasock, readfds);
/* remove from descriptor set if not ready for write/connect */
if(!(wsaevents.lNetworkEvents & (FD_WRITE|FD_CONNECT|FD_CLOSE)))
if(!(wsaevents.lNetworkEvents & (FD_WRITE | FD_CONNECT | FD_CLOSE)))
FD_CLR(wsasock, writefds);
/* remove from descriptor set if not exceptional */
@ -851,10 +851,10 @@ static int select_ws(int nfds, fd_set *readfds, fd_set *writefds,
return ret;
}
#define SOCKFILT_select(a,b,c,d,e) select_ws(a,b,c,d,e)
#define SOCKFILT_select(a, b, c, d, e) select_ws(a, b, c, d, e)
#else
#define SOCKFILT_select(a,b,c,d,e) select(a,b,c,d,e)
#endif /* USE_WINSOCK */
#define SOCKFILT_select(a, b, c, d, e) select(a, b, c, d, e)
#endif /* USE_WINSOCK */
/* Perform the disconnect handshake with sockfilt
* This involves waiting for the disconnect acknowledgment after the DISC
@ -867,46 +867,45 @@ static bool disc_handshake(void)
return FALSE;
do {
unsigned char buffer[BUFFER_SIZE];
ssize_t buffer_len;
if(!read_stdin(buffer, 5))
return FALSE;
logmsg("Received %c%c%c%c (on stdin)",
buffer[0], buffer[1], buffer[2], buffer[3]);
unsigned char buffer[BUFFER_SIZE];
ssize_t buffer_len;
if(!read_stdin(buffer, 5))
return FALSE;
logmsg("Received %c%c%c%c (on stdin)",
buffer[0], buffer[1], buffer[2], buffer[3]);
if(!memcmp("ACKD", buffer, 4)) {
/* got the ack we were waiting for */
break;
}
else if(!memcmp("DISC", buffer, 4)) {
logmsg("Crikey! Client also wants to disconnect");
if(!write_stdout("ACKD\n", 5))
return FALSE;
}
else if(!memcmp("DATA", buffer, 4)) {
/* We must read more data to stay in sync */
logmsg("Throwing away data bytes");
if(!read_data_block(buffer, sizeof(buffer), &buffer_len))
return FALSE;
}
else if(!memcmp("QUIT", buffer, 4)) {
/* just die */
logmsg("quits");
if(!memcmp("ACKD", buffer, 4)) {
/* got the ack we were waiting for */
break;
}
else if(!memcmp("DISC", buffer, 4)) {
logmsg("Crikey! Client also wants to disconnect");
if(!write_stdout("ACKD\n", 5))
return FALSE;
}
else {
logmsg("Unexpected message error; aborting");
/*
* The only other messages that could occur here are PING and PORT,
* and both of them occur at the start of a test when nothing should be
* trying to DISC. Therefore, we should not ever get here, but if we
* do, it is probably due to some kind of unclean shutdown situation so
* us shutting down is what we probably ought to be doing, anyway.
*/
}
else if(!memcmp("DATA", buffer, 4)) {
/* We must read more data to stay in sync */
logmsg("Throwing away data bytes");
if(!read_data_block(buffer, sizeof(buffer), &buffer_len))
return FALSE;
}
}
else if(!memcmp("QUIT", buffer, 4)) {
/* just die */
logmsg("quits");
return FALSE;
}
else {
logmsg("Unexpected message error; aborting");
/*
* The only other messages that could occur here are PING and PORT,
* and both of them occur at the start of a test when nothing should be
* trying to DISC. Therefore, we should not ever get here, but if we
* do, it is probably due to some kind of unclean shutdown situation so
* us shutting down is what we probably ought to be doing, anyway.
*/
return FALSE;
}
} while(TRUE);
return TRUE;
}
@ -1034,7 +1033,6 @@ static bool juggle(curl_socket_t *sockfdp,
} /* switch(*mode) */
do {
/* select() blocking behavior call on blocking descriptors please */
@ -1058,7 +1056,6 @@ static bool juggle(curl_socket_t *sockfdp,
/* timeout */
return TRUE;
if(FD_ISSET(fileno(stdin), &fds_read)) {
ssize_t buffer_len;
/* read from stdin, commands/data to be dealt with and possibly passed on
@ -1146,8 +1143,7 @@ static bool juggle(curl_socket_t *sockfdp,
}
}
if((sockfd != CURL_SOCKET_BAD) && (FD_ISSET(sockfd, &fds_read)) ) {
if((sockfd != CURL_SOCKET_BAD) && (FD_ISSET(sockfd, &fds_read))) {
ssize_t nread_socket;
if(*mode == PASSIVE_LISTEN) {
/* there is no stream set up yet, this is an indication that there is a
@ -1228,7 +1224,7 @@ static int test_sockfilt(int argc, char *argv[])
#else
""
#endif
);
);
return 0;
}
else if(!strcmp("--verbose", argv[arg])) {

View file

@ -289,8 +289,8 @@ static curl_socket_t socks4(curl_socket_t fd,
static curl_socket_t sockit(curl_socket_t fd)
{
unsigned char buffer[2*256 + 16];
unsigned char response[2*256 + 16];
unsigned char buffer[2 * 256 + 16];
unsigned char response[2 * 256 + 16];
ssize_t rc;
unsigned char len;
unsigned char type;
@ -483,7 +483,7 @@ static curl_socket_t sockit(curl_socket_t fd)
case 3:
/* The first octet of the address field contains the number of octets
of name that follow */
fprintf(dump, " %.*s\n", len-1, &address[1]);
fprintf(dump, " %.*s\n", len - 1, &address[1]);
break;
case 4:
/* 16 bytes IPv6 address */
@ -579,8 +579,7 @@ static int tunnel(struct perclient *cp, fd_set *fds)
/* read from client, send to remote */
nread = recv(cp->clientfd, buffer, sizeof(buffer), 0);
if(nread > 0) {
nwrite = send(cp->remotefd, (char *)buffer,
(SEND_TYPE_ARG3)nread, 0);
nwrite = send(cp->remotefd, (char *)buffer, (SEND_TYPE_ARG3)nread, 0);
if(nwrite != nread)
return 1;
cp->fromclient += nwrite;
@ -592,8 +591,7 @@ static int tunnel(struct perclient *cp, fd_set *fds)
/* read from remote, send to client */
nread = recv(cp->remotefd, buffer, sizeof(buffer), 0);
if(nread > 0) {
nwrite = send(cp->clientfd, (char *)buffer,
(SEND_TYPE_ARG3)nread, 0);
nwrite = send(cp->clientfd, (char *)buffer, (SEND_TYPE_ARG3)nread, 0);
if(nwrite != nread)
return 1;
cp->fromremote += nwrite;
@ -725,7 +723,6 @@ static bool socksd_incoming(curl_socket_t listenfd)
cp->used = TRUE;
clients++;
}
}
}
for(i = 0; i < 2; i++) {
@ -777,7 +774,7 @@ static int test_socksd(int argc, char *argv[])
#else
""
#endif
);
);
return 0;
}
else if(!strcmp("--pidfile", argv[arg])) {

View file

@ -51,7 +51,7 @@ static bool sws_prevbounce = FALSE; /* instructs the server to override the
#define RCMD_STREAM 2 /* told to stream */
struct sws_httprequest {
char reqbuf[2*1024*1024]; /* buffer area for the incoming request */
char reqbuf[2 * 1024 * 1024]; /* buffer area for the incoming request */
bool connect_request; /* if a CONNECT */
unsigned short connect_port; /* the port number CONNECT used */
size_t checkindex; /* where to start checking of the request */
@ -138,8 +138,7 @@ static const char *cmdfile = "log/server.cmd";
static const char *end_of_headers = END_OF_HEADERS;
/* sent as reply to a QUIT */
static const char *docquit_sws =
"HTTP/1.1 200 Goodbye" END_OF_HEADERS;
static const char *docquit_sws = "HTTP/1.1 200 Goodbye" END_OF_HEADERS;
/* send back this on 404 file not found */
static const char *doc404 = "HTTP/1.1 404 Not Found\r\n"
@ -169,7 +168,7 @@ static bool socket_domain_is_ip(void)
#endif
return true;
default:
/* case AF_UNIX: */
/* case AF_UNIX: */
return false;
}
}
@ -334,12 +333,10 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
size_t npath = 0; /* httppath length */
if(sscanf(line,
"%" REQUEST_KEYWORD_SIZE_TXT"s ", request) == 1) {
"%" REQUEST_KEYWORD_SIZE_TXT "s ", request) == 1) {
http = strstr(line + strlen(request), "HTTP/");
if(http && sscanf(http, "HTTP/%d.%d",
&prot_major,
&prot_minor) == 2) {
if(http && sscanf(http, "HTTP/%d.%d", &prot_major, &prot_minor) == 2) {
/* between the request keyword and HTTP/ there is a path */
httppath = line + strlen(request);
npath = http - httppath;
@ -361,7 +358,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
if(fine) {
char *ptr;
req->prot_version = prot_major*10 + prot_minor;
req->prot_version = prot_major * 10 + prot_minor;
/* find the last slash */
ptr = &httppath[npath];
@ -746,7 +743,7 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize)
writeleft = totalsize;
do {
written = fwrite(&reqbuf[totalsize-writeleft], 1, writeleft, dump);
written = fwrite(&reqbuf[totalsize - writeleft], 1, writeleft, dump);
if(got_exit_signal)
goto storerequest_cleanup;
if(written > 0)
@ -761,7 +758,7 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize)
logmsg("Error writing file %s error (%d) %s", dumpfile,
error, curlx_strerror(error, errbuf, sizeof(errbuf)));
logmsg("Wrote only (%zu bytes) of (%zu bytes) request input to %s",
totalsize-writeleft, totalsize, dumpfile);
totalsize - writeleft, totalsize, dumpfile);
}
storerequest_cleanup:
@ -876,7 +873,7 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req)
return -1;
}
if(req->offset >= sizeof(req->reqbuf)-1) {
if(req->offset >= sizeof(req->reqbuf) - 1) {
/* buffer is already full; do nothing */
overflow = 1;
}
@ -888,7 +885,7 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req)
got = sread(sock, reqbuf + req->offset, req->cl);
else
got = sread(sock, reqbuf + req->offset,
sizeof(req->reqbuf)-1 - req->offset);
sizeof(req->reqbuf) - 1 - req->offset);
if(got_exit_signal)
return -1;
@ -924,16 +921,16 @@ static int sws_get_request(curl_socket_t sock, struct sws_httprequest *req)
return -1;
}
if(overflow || (req->offset == sizeof(req->reqbuf)-1 && got > 0)) {
if(overflow || (req->offset == sizeof(req->reqbuf) - 1 && got > 0)) {
logmsg("Request would overflow buffer, closing connection");
/* dump request received so far to external file anyway */
reqbuf[sizeof(req->reqbuf)-1] = '\0';
reqbuf[sizeof(req->reqbuf) - 1] = '\0';
fail = 1;
}
else if(req->offset > sizeof(req->reqbuf)-1) {
else if(req->offset > sizeof(req->reqbuf) - 1) {
logmsg("Request buffer overflow, closing connection");
/* dump request received so far to external file anyway */
reqbuf[sizeof(req->reqbuf)-1] = '\0';
reqbuf[sizeof(req->reqbuf) - 1] = '\0';
fail = 1;
}
else
@ -978,10 +975,10 @@ static int sws_send_doc(curl_socket_t sock, struct sws_httprequest *req)
case RCMD_STREAM: {
static const char streamthis[] = "a string to stream 01234567890\n";
for(;;) {
written = swrite(sock, streamthis, sizeof(streamthis)-1);
written = swrite(sock, streamthis, sizeof(streamthis) - 1);
if(got_exit_signal)
return -1;
if(written != (ssize_t)(sizeof(streamthis)-1)) {
if(written != (ssize_t)(sizeof(streamthis) - 1)) {
logmsg("Stopped streaming");
break;
}
@ -1144,7 +1141,7 @@ retry:
if(req->writedelay) {
int msecs_left = req->writedelay;
int intervals = msecs_left / MAX_SLEEP_TIME_MS;
if(msecs_left%MAX_SLEEP_TIME_MS)
if(msecs_left % MAX_SLEEP_TIME_MS)
intervals++;
logmsg("Pausing %d milliseconds after writing %zd bytes",
msecs_left, written);
@ -1172,7 +1169,7 @@ retry:
if(sendfailure) {
logmsg("Sending response failed. Only (%zu bytes) of (%zu bytes) "
"were sent",
responsesize-count, responsesize);
responsesize - count, responsesize);
sws_prevtestno = req->testno;
sws_prevpartno = req->partno;
free(ptr);
@ -1247,9 +1244,7 @@ static curl_socket_t connect_to(const char *ipaddr, unsigned short port)
if(!ipaddr)
return CURL_SOCKET_BAD;
logmsg("about to connect to %s%s%s:%hu",
op_br, ipaddr, cl_br, port);
logmsg("about to connect to %s%s%s:%hu", op_br, ipaddr, cl_br, port);
serverfd = socket(socket_domain, SOCK_STREAM, 0);
if(CURL_SOCKET_BAD == serverfd) {
@ -1389,7 +1384,7 @@ success:
* must accept a new connection and deal with it appropriately.
*/
#define data_or_ctrl(x) ((x)?"DATA":"CTRL")
#define data_or_ctrl(x) ((x) ? "DATA" : "CTRL")
#define SWS_CTRL 0
#define SWS_DATA 1
@ -1644,7 +1639,7 @@ static void http_connect(curl_socket_t *infdp,
}
}
if(serverfd[i] != CURL_SOCKET_BAD) {
len = sizeof(readserver[i])-toc[i];
len = sizeof(readserver[i]) - toc[i];
if(len && FD_ISSET(serverfd[i], &input)) {
/* read from server */
rc = sread(serverfd[i], &readserver[i][toc[i]], len);
@ -1676,7 +1671,7 @@ static void http_connect(curl_socket_t *infdp,
logmsg("[%s] SENT \"%s\"", data_or_ctrl(i),
data_to_hex(readserver[i], rc));
if(toc[i] - rc)
memmove(&readserver[i][0], &readserver[i][rc], toc[i]-rc);
memmove(&readserver[i][0], &readserver[i][rc], toc[i] - rc);
toc[i] -= rc;
}
}
@ -1696,7 +1691,7 @@ static void http_connect(curl_socket_t *infdp,
logmsg("[%s] SENT \"%s\"", data_or_ctrl(i),
data_to_hex(readclient[i], rc));
if(tos[i] - rc)
memmove(&readclient[i][0], &readclient[i][rc], tos[i]-rc);
memmove(&readclient[i][0], &readclient[i][rc], tos[i] - rc);
tos[i] -= rc;
}
}
@ -1826,7 +1821,6 @@ static void http_upgrade(struct sws_httprequest *req)
/* left to implement */
}
/* returns a socket handle, or 0 if there are no more waiting sockets,
or < 0 if there was an error */
static curl_socket_t accept_connection(curl_socket_t sock)
@ -2021,12 +2015,12 @@ static int test_sws(int argc, char *argv[])
if(!strcmp("--version", argv[arg])) {
puts("sws IPv4"
#ifdef USE_IPV6
"/IPv6"
"/IPv6"
#endif
#ifdef USE_UNIX_SOCKETS
"/unix"
"/unix"
#endif
);
);
return 0;
}
else if(!strcmp("--pidfile", argv[arg])) {
@ -2097,8 +2091,7 @@ static int test_sws(int argc, char *argv[])
if(argc > arg) {
opt = argv[arg];
if(curlx_str_number(&opt, &num, 0xffff)) {
fprintf(stderr, "sws: invalid --port argument (%s)\n",
argv[arg]);
fprintf(stderr, "sws: invalid --port argument (%s)\n", argv[arg]);
return 0;
}
port = (unsigned short)num;
@ -2327,9 +2320,9 @@ static int test_sws(int argc, char *argv[])
/* Clear out closed sockets */
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);
char *dst = (char *)(all_sockets + socket_idx);
char *src = (char *)(all_sockets + socket_idx + 1);
char *end = (char *)(all_sockets + num_sockets);
memmove(dst, src, end - src);
num_sockets -= 1;
}

View file

@ -380,7 +380,7 @@ static void read_ahead(struct testcase *test,
}
p = dp->th_data;
for(i = 0 ; i < SEGSIZE; i++) {
for(i = 0; i < SEGSIZE; i++) {
if(newline) {
if(prevchar == '\n')
c = '\n'; /* lf to cr,lf */
@ -536,8 +536,7 @@ static int synchnet(curl_socket_t f /* socket to flush */)
else
fromaddrlen = sizeof(fromaddr.sa6);
#endif
(void)recvfrom(f, rbuf, sizeof(rbuf), 0,
&fromaddr.sa, &fromaddrlen);
(void)recvfrom(f, rbuf, sizeof(rbuf), 0, &fromaddr.sa, &fromaddrlen);
}
else
break;
@ -578,7 +577,7 @@ static int test_tftpd(int argc, char **argv)
#else
""
#endif
);
);
return 0;
}
else if(!strcmp("--pidfile", argv[arg])) {
@ -674,8 +673,7 @@ static int test_tftpd(int argc, char **argv)
}
flag = 1;
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
(void *)&flag, sizeof(flag))) {
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&flag, sizeof(flag))) {
error = SOCKERRNO;
logmsg("setsockopt(SO_REUSEADDR) failed with error (%d) %s",
error, curlx_strerror(error, errbuf, sizeof(errbuf)));
@ -825,7 +823,7 @@ static int test_tftpd(int argc, char **argv)
}
#endif
maxtimeout = 5*TIMEOUT;
maxtimeout = 5 * TIMEOUT;
tp = &trsbuf.hdr;
tp->th_opcode = ntohs(tp->th_opcode);
@ -1076,7 +1074,6 @@ static int tftpd_parse_servercmd(struct testcase *req)
return 0; /* OK! */
}
/*
* Validate file access.
*/
@ -1104,7 +1101,7 @@ static int validate_access(struct testcase *test,
ptr = strrchr(filename, '/');
if(ptr) {
char partbuf[80]="data";
char partbuf[80] = "data";
long partno;
long testno;
const char *pval;
@ -1209,7 +1206,7 @@ static void sendtftp(struct testcase *test, const struct formats *pf)
if(test->writedelay) {
logmsg("Pausing %d seconds before %d bytes", test->writedelay,
size);
curlx_wait_ms(1000*test->writedelay);
curlx_wait_ms(1000 * test->writedelay);
}
send_data:
@ -1249,11 +1246,10 @@ send_data:
}
/* 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);

View file

@ -37,7 +37,7 @@
*/
char *data_to_hex(char *data, size_t len)
{
static char buf[256*3];
static char buf[256 * 3];
size_t i;
char *optr = buf;
char *iptr = data;
@ -177,18 +177,18 @@ int win32_init(void)
}
if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested) ) {
HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested)) {
WSACleanup();
win32_perror("Winsock init failed");
logmsg("No suitable winsock.dll found -- aborting");
return 1;
}
}
#endif /* USE_WINSOCK */
#endif /* USE_WINSOCK */
atexit(win32_cleanup);
return 0;
}
#endif /* _WIN32 */
#endif /* _WIN32 */
/* fopens the test case file */
FILE *test2fopen(long testno, const char *logdir2)
@ -370,8 +370,7 @@ static void exit_signal_handler(int signum)
fd != -1) {
#else
/* !checksrc! disable BANNEDFUNC 1 */
fd = open(serverlogfile,
O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
fd = open(serverlogfile, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
if(fd != -1) {
#endif
static const char msg[] = "exit_signal_handler: called\n";
@ -546,7 +545,7 @@ static SIGHANDLER_T set_signal(int signum, SIGHANDLER_T handler,
#ifdef HAVE_SIGINTERRUPT
if(oldhdlr != SIG_ERR)
siginterrupt(signum, (int) restartable);
siginterrupt(signum, (int)restartable);
#else
(void)restartable;
#endif
@ -693,7 +692,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
return -1;
}
strcpy(sau->sun_path, unix_socket);
rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un));
rc = bind(sock, (struct sockaddr *)sau, sizeof(struct sockaddr_un));
if(rc && SOCKERRNO == SOCKEADDRINUSE) {
struct_stat statbuf;
/* socket already exists. Perhaps it is stale? */
@ -738,7 +737,7 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
return rc;
}
/* stale socket is gone, retry bind */
rc = bind(sock, (struct sockaddr*)sau, sizeof(struct sockaddr_un));
rc = bind(sock, (struct sockaddr *)sau, sizeof(struct sockaddr_un));
}
return rc;
}
@ -805,29 +804,29 @@ curl_socket_t sockdaemon(curl_socket_t sock,
request to let the system choose a non-zero available port. */
switch(socket_domain) {
case AF_INET:
memset(&listener.sa4, 0, sizeof(listener.sa4));
listener.sa4.sin_family = AF_INET;
listener.sa4.sin_addr.s_addr = INADDR_ANY;
listener.sa4.sin_port = htons(*listenport);
rc = bind(sock, &listener.sa, sizeof(listener.sa4));
break;
case AF_INET:
memset(&listener.sa4, 0, sizeof(listener.sa4));
listener.sa4.sin_family = AF_INET;
listener.sa4.sin_addr.s_addr = INADDR_ANY;
listener.sa4.sin_port = htons(*listenport);
rc = bind(sock, &listener.sa, sizeof(listener.sa4));
break;
#ifdef USE_IPV6
case AF_INET6:
memset(&listener.sa6, 0, sizeof(listener.sa6));
listener.sa6.sin6_family = AF_INET6;
listener.sa6.sin6_addr = in6addr_any;
listener.sa6.sin6_port = htons(*listenport);
rc = bind(sock, &listener.sa, sizeof(listener.sa6));
break;
case AF_INET6:
memset(&listener.sa6, 0, sizeof(listener.sa6));
listener.sa6.sin6_family = AF_INET6;
listener.sa6.sin6_addr = in6addr_any;
listener.sa6.sin6_port = htons(*listenport);
rc = bind(sock, &listener.sa, sizeof(listener.sa6));
break;
#endif /* USE_IPV6 */
#ifdef USE_UNIX_SOCKETS
case AF_UNIX:
rc = bind_unix_socket(sock, unix_socket, &listener.sau);
break;
case AF_UNIX:
rc = bind_unix_socket(sock, unix_socket, &listener.sau);
break;
#endif
default:
rc = 1;
default:
rc = 1;
}
if(rc) {