removed space after if and while before the parenthesis for better source code

consistency
This commit is contained in:
Daniel Stenberg 2007-11-05 09:45:09 +00:00
parent af29dcbafb
commit ad6e28073c
24 changed files with 1070 additions and 1068 deletions

View File

@ -101,7 +101,7 @@ size_t Curl_base64_decode(const char *src, unsigned char **outptr)
numQuantums = (length + equalsTerm) / 4; numQuantums = (length + equalsTerm) / 4;
/* Don't allocate a buffer if the decoded length is 0 */ /* Don't allocate a buffer if the decoded length is 0 */
if (numQuantums <= 0) if(numQuantums <= 0)
return 0; return 0;
rawlen = (numQuantums * 3) - equalsTerm; rawlen = (numQuantums * 3) - equalsTerm;

View File

@ -116,7 +116,7 @@ int Curl_nonblock(curl_socket_t sockfd, /* operate on this */
int flags; int flags;
flags = fcntl(sockfd, F_GETFL, 0); flags = fcntl(sockfd, F_GETFL, 0);
if (FALSE != nonblock) if(FALSE != nonblock)
return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); return fcntl(sockfd, F_SETFL, flags | O_NONBLOCK);
else else
return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK)); return fcntl(sockfd, F_SETFL, flags & (~O_NONBLOCK));
@ -165,7 +165,7 @@ int Curl_nonblock(curl_socket_t sockfd, /* operate on this */
#define SETBLOCK 6 #define SETBLOCK 6
#endif #endif
#if (SETBLOCK == 0) #if(SETBLOCK == 0)
#error "no non-blocking method was found/used/set" #error "no non-blocking method was found/used/set"
#endif #endif
} }
@ -233,7 +233,7 @@ static CURLcode bindlocal(struct connectdata *conn,
/************************************************************* /*************************************************************
* Select device to bind socket to * Select device to bind socket to
*************************************************************/ *************************************************************/
if (dev && (strlen(dev)<255) ) { if(dev && (strlen(dev)<255) ) {
struct Curl_dns_entry *h=NULL; struct Curl_dns_entry *h=NULL;
char myhost[256] = ""; char myhost[256] = "";
in_addr_t in; in_addr_t in;
@ -303,11 +303,11 @@ static CURLcode bindlocal(struct connectdata *conn,
* interfaces to go out the external interface. * interfaces to go out the external interface.
* *
*/ */
if (was_iface) { if(was_iface) {
/* Only bind to the interface when specified as interface, not just as a /* Only bind to the interface when specified as interface, not just as a
* hostname or ip address. * hostname or ip address.
*/ */
if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE, if(setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
dev, strlen(dev)+1) != 0) { dev, strlen(dev)+1) != 0) {
/* printf("Failed to BINDTODEVICE, socket: %d device: %s error: %s\n", /* printf("Failed to BINDTODEVICE, socket: %d device: %s error: %s\n",
sockfd, dev, Curl_strerror(SOCKERRNO)); */ sockfd, dev, Curl_strerror(SOCKERRNO)); */
@ -323,12 +323,12 @@ static CURLcode bindlocal(struct connectdata *conn,
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
in6 = Curl_inet_pton (AF_INET6, myhost, (void *)&ipv6_addr); in6 = Curl_inet_pton (AF_INET6, myhost, (void *)&ipv6_addr);
#endif #endif
if (CURL_INADDR_NONE == in && -1 == in6) { if(CURL_INADDR_NONE == in && -1 == in6) {
failf(data,"couldn't find my own IP address (%s)", myhost); failf(data,"couldn't find my own IP address (%s)", myhost);
return CURLE_INTERFACE_FAILED; return CURLE_INTERFACE_FAILED;
} /* end of inet_addr */ } /* end of inet_addr */
if ( h ) { if( h ) {
Curl_addrinfo *addr = h->addr; Curl_addrinfo *addr = h->addr;
sock = addr->ai_addr; sock = addr->ai_addr;
socksize = addr->ai_addrlen; socksize = addr->ai_addrlen;
@ -433,33 +433,33 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
#endif #endif
if (0 != getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize)) if(0 != getsockopt(sockfd, SOL_SOCKET, SO_ERROR, (void *)&err, &errSize))
err = SOCKERRNO; err = SOCKERRNO;
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
/* Old WinCE versions don't support SO_ERROR */ /* Old WinCE versions don't support SO_ERROR */
if (WSAENOPROTOOPT == err) { if(WSAENOPROTOOPT == err) {
SET_SOCKERRNO(0); SET_SOCKERRNO(0);
err = 0; err = 0;
} }
#endif #endif
#ifdef __minix #ifdef __minix
/* Minix 3.1.x doesn't support getsockopt on UDP sockets */ /* Minix 3.1.x doesn't support getsockopt on UDP sockets */
if (EBADIOCTL == err) { if(EBADIOCTL == err) {
SET_SOCKERRNO(0); SET_SOCKERRNO(0);
err = 0; err = 0;
} }
#endif #endif
if ((0 == err) || (EISCONN == err)) if((0 == err) || (EISCONN == err))
/* we are connected, awesome! */ /* we are connected, awesome! */
rc = TRUE; rc = TRUE;
else else
/* This wasn't a successful connect */ /* This wasn't a successful connect */
rc = FALSE; rc = FALSE;
if (error) if(error)
*error = err; *error = err;
#else #else
(void)sockfd; (void)sockfd;
if (error) if(error)
*error = SOCKERRNO; *error = SOCKERRNO;
#endif #endif
return rc; return rc;
@ -504,7 +504,7 @@ static bool trynextip(struct connectdata *conn,
/* try the next address */ /* try the next address */
ai = conn->ip_addr->ai_next; ai = conn->ip_addr->ai_next;
while (ai) { while(ai) {
sockfd = singleipconnect(conn, ai, 0L, connected); sockfd = singleipconnect(conn, ai, 0L, connected);
if(sockfd != CURL_SOCKET_BAD) { if(sockfd != CURL_SOCKET_BAD) {
/* store the new socket descriptor */ /* store the new socket descriptor */
@ -545,7 +545,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
/* subtract the most strict timeout of the ones */ /* subtract the most strict timeout of the ones */
if(data->set.timeout && data->set.connecttimeout) { if(data->set.timeout && data->set.connecttimeout) {
if (data->set.timeout < data->set.connecttimeout) if(data->set.timeout < data->set.connecttimeout)
allow_total = allow = data->set.timeout; allow_total = allow = data->set.timeout;
else else
allow = data->set.connecttimeout; allow = data->set.connecttimeout;
@ -576,7 +576,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
if(WAITCONN_CONNECTED == rc) { if(WAITCONN_CONNECTED == rc) {
int error; int error;
if (verifyconnect(sockfd, &error)) { if(verifyconnect(sockfd, &error)) {
/* we are connected, awesome! */ /* we are connected, awesome! */
*connected = TRUE; *connected = TRUE;
return CURLE_OK; return CURLE_OK;
@ -594,7 +594,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
int error = 0; int error = 0;
/* nope, not connected */ /* nope, not connected */
if (WAITCONN_FDSET_ERROR == rc) { if(WAITCONN_FDSET_ERROR == rc) {
(void)verifyconnect(sockfd, &error); (void)verifyconnect(sockfd, &error);
data->state.os_errno = error; data->state.os_errno = error;
infof(data, "%s\n",Curl_strerror(conn,error)); infof(data, "%s\n",Curl_strerror(conn,error));
@ -628,7 +628,7 @@ static void tcpnodelay(struct connectdata *conn,
#ifdef HAVE_GETPROTOBYNAME #ifdef HAVE_GETPROTOBYNAME
struct protoent *pe = getprotobyname("tcp"); struct protoent *pe = getprotobyname("tcp");
if (pe) if(pe)
proto = pe->p_proto; proto = pe->p_proto;
#endif #endif
@ -703,7 +703,7 @@ singleipconnect(struct connectdata *conn,
CURLSOCKTYPE_IPCXN, addr); CURLSOCKTYPE_IPCXN, addr);
else else
sockfd = socket(addr->family, addr->socktype, addr->protocol); sockfd = socket(addr->family, addr->socktype, addr->protocol);
if (sockfd == CURL_SOCKET_BAD) if(sockfd == CURL_SOCKET_BAD)
return CURL_SOCKET_BAD; return CURL_SOCKET_BAD;
*connected = FALSE; /* default is not connected */ *connected = FALSE; /* default is not connected */
@ -728,7 +728,7 @@ singleipconnect(struct connectdata *conn,
error = data->set.fsockopt(data->set.sockopt_client, error = data->set.fsockopt(data->set.sockopt_client,
sockfd, sockfd,
CURLSOCKTYPE_IPCXN); CURLSOCKTYPE_IPCXN);
if (error) { if(error) {
sclose(sockfd); /* close the socket and bail out */ sclose(sockfd); /* close the socket and bail out */
return CURL_SOCKET_BAD; return CURL_SOCKET_BAD;
} }
@ -836,9 +836,9 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
/* if a timeout is set, use the most restrictive one */ /* if a timeout is set, use the most restrictive one */
if (data->set.timeout > 0) if(data->set.timeout > 0)
timeout_set += 1; timeout_set += 1;
if (data->set.connecttimeout > 0) if(data->set.connecttimeout > 0)
timeout_set += 2; timeout_set += 2;
switch (timeout_set) { switch (timeout_set) {
@ -849,7 +849,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
timeout_ms = data->set.connecttimeout; timeout_ms = data->set.connecttimeout;
break; break;
case 3: case 3:
if (data->set.timeout < data->set.connecttimeout) if(data->set.timeout < data->set.connecttimeout)
timeout_ms = data->set.timeout; timeout_ms = data->set.timeout;
else else
timeout_ms = data->set.connecttimeout; timeout_ms = data->set.connecttimeout;
@ -859,7 +859,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
break; break;
} }
if (timeout_set > 0) { if(timeout_set > 0) {
/* if a timeout was already set, substract elapsed time */ /* if a timeout was already set, substract elapsed time */
timeout_ms -= Curl_tvdiff(before, data->progress.t_startsingle); timeout_ms -= Curl_tvdiff(before, data->progress.t_startsingle);
if(timeout_ms < 0) { if(timeout_ms < 0) {
@ -906,7 +906,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
before = after; before = after;
} /* end of connect-to-each-address loop */ } /* end of connect-to-each-address loop */
if (sockfd == CURL_SOCKET_BAD) { if(sockfd == CURL_SOCKET_BAD) {
/* no good connect was made */ /* no good connect was made */
*sockconn = CURL_SOCKET_BAD; *sockconn = CURL_SOCKET_BAD;
failf(data, "couldn't connect to host"); failf(data, "couldn't connect to host");

View File

@ -57,7 +57,7 @@ static CURLcode
process_zlib_error(struct connectdata *conn, z_stream *z) process_zlib_error(struct connectdata *conn, z_stream *z)
{ {
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
if (z->msg) if(z->msg)
failf (data, "Error while processing content unencoding: %s", failf (data, "Error while processing content unencoding: %s",
z->msg); z->msg);
else else
@ -90,7 +90,7 @@ inflate_stream(struct connectdata *conn,
/* Dynamically allocate a buffer for decompression because it's uncommonly /* Dynamically allocate a buffer for decompression because it's uncommonly
large to hold on the stack */ large to hold on the stack */
decomp = (char*)malloc(DSIZ); decomp = (char*)malloc(DSIZ);
if (decomp == NULL) { if(decomp == NULL) {
return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY); return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
} }
@ -102,39 +102,39 @@ inflate_stream(struct connectdata *conn,
z->avail_out = DSIZ; z->avail_out = DSIZ;
status = inflate(z, Z_SYNC_FLUSH); status = inflate(z, Z_SYNC_FLUSH);
if (status == Z_OK || status == Z_STREAM_END) { if(status == Z_OK || status == Z_STREAM_END) {
allow_restart = 0; allow_restart = 0;
if(DSIZ - z->avail_out) { if(DSIZ - z->avail_out) {
result = Curl_client_write(conn, CLIENTWRITE_BODY, decomp, result = Curl_client_write(conn, CLIENTWRITE_BODY, decomp,
DSIZ - z->avail_out); DSIZ - z->avail_out);
/* if !CURLE_OK, clean up, return */ /* if !CURLE_OK, clean up, return */
if (result) { if(result) {
free(decomp); free(decomp);
return exit_zlib(z, &k->zlib_init, result); return exit_zlib(z, &k->zlib_init, result);
} }
} }
/* Done? clean up, return */ /* Done? clean up, return */
if (status == Z_STREAM_END) { if(status == Z_STREAM_END) {
free(decomp); free(decomp);
if (inflateEnd(z) == Z_OK) if(inflateEnd(z) == Z_OK)
return exit_zlib(z, &k->zlib_init, result); return exit_zlib(z, &k->zlib_init, result);
else else
return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z)); return exit_zlib(z, &k->zlib_init, process_zlib_error(conn, z));
} }
/* Done with these bytes, exit */ /* Done with these bytes, exit */
if (status == Z_OK && z->avail_in == 0) { if(status == Z_OK && z->avail_in == 0) {
free(decomp); free(decomp);
return result; return result;
} }
} }
else if (allow_restart && status == Z_DATA_ERROR) { else if(allow_restart && status == Z_DATA_ERROR) {
/* some servers seem to not generate zlib headers, so this is an attempt /* some servers seem to not generate zlib headers, so this is an attempt
to fix and continue anyway */ to fix and continue anyway */
(void) inflateEnd(z); /* don't care about the return code */ (void) inflateEnd(z); /* don't care about the return code */
if (inflateInit2(z, -MAX_WBITS) != Z_OK) { if(inflateInit2(z, -MAX_WBITS) != Z_OK) {
return process_zlib_error(conn, z); return process_zlib_error(conn, z);
} }
z->next_in = orig_in; z->next_in = orig_in;
@ -158,13 +158,13 @@ Curl_unencode_deflate_write(struct connectdata *conn,
z_stream *z = &k->z; /* zlib state structure */ z_stream *z = &k->z; /* zlib state structure */
/* Initialize zlib? */ /* Initialize zlib? */
if (k->zlib_init == ZLIB_UNINIT) { if(k->zlib_init == ZLIB_UNINIT) {
z->zalloc = (alloc_func)Z_NULL; z->zalloc = (alloc_func)Z_NULL;
z->zfree = (free_func)Z_NULL; z->zfree = (free_func)Z_NULL;
z->opaque = 0; z->opaque = 0;
z->next_in = NULL; z->next_in = NULL;
z->avail_in = 0; z->avail_in = 0;
if (inflateInit(z) != Z_OK) if(inflateInit(z) != Z_OK)
return process_zlib_error(conn, z); return process_zlib_error(conn, z);
k->zlib_init = ZLIB_INIT; k->zlib_init = ZLIB_INIT;
} }
@ -189,16 +189,16 @@ static enum {
const ssize_t totallen = len; const ssize_t totallen = len;
/* The shortest header is 10 bytes */ /* The shortest header is 10 bytes */
if (len < 10) if(len < 10)
return GZIP_UNDERFLOW; return GZIP_UNDERFLOW;
if ((data[0] != GZIP_MAGIC_0) || (data[1] != GZIP_MAGIC_1)) if((data[0] != GZIP_MAGIC_0) || (data[1] != GZIP_MAGIC_1))
return GZIP_BAD; return GZIP_BAD;
method = data[2]; method = data[2];
flags = data[3]; flags = data[3];
if (method != Z_DEFLATED || (flags & RESERVED) != 0) { if(method != Z_DEFLATED || (flags & RESERVED) != 0) {
/* Can't handle this compression method or unknown flag */ /* Can't handle this compression method or unknown flag */
return GZIP_BAD; return GZIP_BAD;
} }
@ -207,28 +207,28 @@ static enum {
len -= 10; len -= 10;
data += 10; data += 10;
if (flags & EXTRA_FIELD) { if(flags & EXTRA_FIELD) {
ssize_t extra_len; ssize_t extra_len;
if (len < 2) if(len < 2)
return GZIP_UNDERFLOW; return GZIP_UNDERFLOW;
extra_len = (data[1] << 8) | data[0]; extra_len = (data[1] << 8) | data[0];
if (len < (extra_len+2)) if(len < (extra_len+2))
return GZIP_UNDERFLOW; return GZIP_UNDERFLOW;
len -= (extra_len + 2); len -= (extra_len + 2);
data += (extra_len + 2); data += (extra_len + 2);
} }
if (flags & ORIG_NAME) { if(flags & ORIG_NAME) {
/* Skip over NUL-terminated file name */ /* Skip over NUL-terminated file name */
while (len && *data) { while(len && *data) {
--len; --len;
++data; ++data;
} }
if (!len || *data) if(!len || *data)
return GZIP_UNDERFLOW; return GZIP_UNDERFLOW;
/* Skip over the NUL */ /* Skip over the NUL */
@ -236,13 +236,13 @@ static enum {
++data; ++data;
} }
if (flags & COMMENT) { if(flags & COMMENT) {
/* Skip over NUL-terminated comment */ /* Skip over NUL-terminated comment */
while (len && *data) { while(len && *data) {
--len; --len;
++data; ++data;
} }
if (!len || *data) if(!len || *data)
return GZIP_UNDERFLOW; return GZIP_UNDERFLOW;
/* Skip over the NUL */ /* Skip over the NUL */
@ -250,8 +250,8 @@ static enum {
++data; ++data;
} }
if (flags & HEAD_CRC) { if(flags & HEAD_CRC) {
if (len < 2) if(len < 2)
return GZIP_UNDERFLOW; return GZIP_UNDERFLOW;
len -= 2; len -= 2;
@ -271,30 +271,30 @@ Curl_unencode_gzip_write(struct connectdata *conn,
z_stream *z = &k->z; /* zlib state structure */ z_stream *z = &k->z; /* zlib state structure */
/* Initialize zlib? */ /* Initialize zlib? */
if (k->zlib_init == ZLIB_UNINIT) { if(k->zlib_init == ZLIB_UNINIT) {
z->zalloc = (alloc_func)Z_NULL; z->zalloc = (alloc_func)Z_NULL;
z->zfree = (free_func)Z_NULL; z->zfree = (free_func)Z_NULL;
z->opaque = 0; z->opaque = 0;
z->next_in = NULL; z->next_in = NULL;
z->avail_in = 0; z->avail_in = 0;
if (strcmp(zlibVersion(), "1.2.0.4") >= 0) { if(strcmp(zlibVersion(), "1.2.0.4") >= 0) {
/* zlib ver. >= 1.2.0.4 supports transparent gzip decompressing */ /* zlib ver. >= 1.2.0.4 supports transparent gzip decompressing */
if (inflateInit2(z, MAX_WBITS+32) != Z_OK) { if(inflateInit2(z, MAX_WBITS+32) != Z_OK) {
return process_zlib_error(conn, z); return process_zlib_error(conn, z);
} }
k->zlib_init = ZLIB_INIT_GZIP; /* Transparent gzip decompress state */ k->zlib_init = ZLIB_INIT_GZIP; /* Transparent gzip decompress state */
} else { } else {
/* we must parse the gzip header ourselves */ /* we must parse the gzip header ourselves */
if (inflateInit2(z, -MAX_WBITS) != Z_OK) { if(inflateInit2(z, -MAX_WBITS) != Z_OK) {
return process_zlib_error(conn, z); return process_zlib_error(conn, z);
} }
k->zlib_init = ZLIB_INIT; /* Initial call state */ k->zlib_init = ZLIB_INIT; /* Initial call state */
} }
} }
if (k->zlib_init == ZLIB_INIT_GZIP) { if(k->zlib_init == ZLIB_INIT_GZIP) {
/* Let zlib handle the gzip decompression entirely */ /* Let zlib handle the gzip decompression entirely */
z->next_in = (Bytef *)k->str; z->next_in = (Bytef *)k->str;
z->avail_in = (uInt)nread; z->avail_in = (uInt)nread;
@ -342,7 +342,7 @@ Curl_unencode_gzip_write(struct connectdata *conn,
*/ */
z->avail_in = (uInt)nread; z->avail_in = (uInt)nread;
z->next_in = malloc(z->avail_in); z->next_in = malloc(z->avail_in);
if (z->next_in == NULL) { if(z->next_in == NULL) {
return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY); return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
} }
memcpy(z->next_in, k->str, z->avail_in); memcpy(z->next_in, k->str, z->avail_in);
@ -366,7 +366,7 @@ Curl_unencode_gzip_write(struct connectdata *conn,
z->avail_in += nread; z->avail_in += nread;
z->next_in = realloc(z->next_in, z->avail_in); z->next_in = realloc(z->next_in, z->avail_in);
if (z->next_in == NULL) { if(z->next_in == NULL) {
free(oldblock); free(oldblock);
return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY); return exit_zlib(z, &k->zlib_init, CURLE_OUT_OF_MEMORY);
} }
@ -404,7 +404,7 @@ Curl_unencode_gzip_write(struct connectdata *conn,
break; break;
} }
if (z->avail_in == 0) { if(z->avail_in == 0) {
/* We don't have any data to inflate; wait until next time */ /* We don't have any data to inflate; wait until next time */
return CURLE_OK; return CURLE_OK;
} }

View File

@ -127,7 +127,7 @@ static CURLcode win32_init(void)
err = WSAStartup(wVersionRequested, &wsaData); err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) if(err != 0)
/* Tell the user that we couldn't find a useable */ /* Tell the user that we couldn't find a useable */
/* winsock.dll. */ /* winsock.dll. */
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
@ -138,7 +138,7 @@ static CURLcode win32_init(void)
/* wVersionRequested in wVersion. wHighVersion contains the */ /* wVersionRequested in wVersion. wHighVersion contains the */
/* highest supported version. */ /* highest supported version. */
if ( LOBYTE( wsaData.wVersion ) != LOBYTE(wVersionRequested) || if( LOBYTE( wsaData.wVersion ) != LOBYTE(wVersionRequested) ||
HIBYTE( wsaData.wVersion ) != HIBYTE(wVersionRequested) ) { HIBYTE( wsaData.wVersion ) != HIBYTE(wVersionRequested) ) {
/* Tell the user that we couldn't find a useable */ /* Tell the user that we couldn't find a useable */
@ -168,7 +168,7 @@ static void idna_init (void)
char buf[60]; char buf[60];
UINT cp = GetACP(); UINT cp = GetACP();
if (!getenv("CHARSET") && cp > 0) { if(!getenv("CHARSET") && cp > 0) {
snprintf(buf, sizeof(buf), "CHARSET=cp%u", cp); snprintf(buf, sizeof(buf), "CHARSET=cp%u", cp);
putenv(buf); putenv(buf);
} }
@ -212,7 +212,7 @@ curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
*/ */
CURLcode curl_global_init(long flags) CURLcode curl_global_init(long flags)
{ {
if (initialized++) if(initialized++)
return CURLE_OK; return CURLE_OK;
/* Setup the default memory functions here (again) */ /* Setup the default memory functions here (again) */
@ -222,14 +222,14 @@ CURLcode curl_global_init(long flags)
Curl_cstrdup = (curl_strdup_callback)system_strdup; Curl_cstrdup = (curl_strdup_callback)system_strdup;
Curl_ccalloc = (curl_calloc_callback)calloc; Curl_ccalloc = (curl_calloc_callback)calloc;
if (flags & CURL_GLOBAL_SSL) if(flags & CURL_GLOBAL_SSL)
if (!Curl_ssl_init()) { if(!Curl_ssl_init()) {
DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n")); DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
if (flags & CURL_GLOBAL_WIN32) if(flags & CURL_GLOBAL_WIN32)
if (win32_init() != CURLE_OK) { if(win32_init() != CURLE_OK) {
DEBUGF(fprintf(stderr, "Error: win32_init failed\n")); DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
@ -267,16 +267,16 @@ CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
CURLcode code = CURLE_OK; CURLcode code = CURLE_OK;
/* Invalid input, return immediately */ /* Invalid input, return immediately */
if (!m || !f || !r || !s || !c) if(!m || !f || !r || !s || !c)
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
/* Already initialized, don't do it again */ /* Already initialized, don't do it again */
if ( initialized ) if( initialized )
return CURLE_OK; return CURLE_OK;
/* Call the actual init function first */ /* Call the actual init function first */
code = curl_global_init(flags); code = curl_global_init(flags);
if (code == CURLE_OK) { if(code == CURLE_OK) {
Curl_cmalloc = m; Curl_cmalloc = m;
Curl_cfree = f; Curl_cfree = f;
Curl_cstrdup = s; Curl_cstrdup = s;
@ -293,18 +293,18 @@ CURLcode curl_global_init_mem(long flags, curl_malloc_callback m,
*/ */
void curl_global_cleanup(void) void curl_global_cleanup(void)
{ {
if (!initialized) if(!initialized)
return; return;
if (--initialized) if(--initialized)
return; return;
Curl_global_host_cache_dtor(); Curl_global_host_cache_dtor();
if (init_flags & CURL_GLOBAL_SSL) if(init_flags & CURL_GLOBAL_SSL)
Curl_ssl_cleanup(); Curl_ssl_cleanup();
if (init_flags & CURL_GLOBAL_WIN32) if(init_flags & CURL_GLOBAL_WIN32)
win32_cleanup(); win32_cleanup();
#ifdef __AMIGA__ #ifdef __AMIGA__
@ -324,7 +324,7 @@ CURL *curl_easy_init(void)
struct SessionHandle *data; struct SessionHandle *data;
/* Make sure we inited the global SSL stuff */ /* Make sure we inited the global SSL stuff */
if (!initialized) { if(!initialized) {
res = curl_global_init(CURL_GLOBAL_DEFAULT); res = curl_global_init(CURL_GLOBAL_DEFAULT);
if(res) { if(res) {
/* something in the global init failed, return nothing */ /* something in the global init failed, return nothing */
@ -465,17 +465,17 @@ CURLcode curl_easy_perform(CURL *curl)
if(!data) if(!data)
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
if ( ! (data->share && data->share->hostcache) ) { if( ! (data->share && data->share->hostcache) ) {
if (Curl_global_host_cache_use(data) && if(Curl_global_host_cache_use(data) &&
(data->dns.hostcachetype != HCACHE_GLOBAL)) { (data->dns.hostcachetype != HCACHE_GLOBAL)) {
if (data->dns.hostcachetype == HCACHE_PRIVATE) if(data->dns.hostcachetype == HCACHE_PRIVATE)
Curl_hash_destroy(data->dns.hostcache); Curl_hash_destroy(data->dns.hostcache);
data->dns.hostcache = Curl_global_host_cache_get(); data->dns.hostcache = Curl_global_host_cache_get();
data->dns.hostcachetype = HCACHE_GLOBAL; data->dns.hostcachetype = HCACHE_GLOBAL;
} }
if (!data->dns.hostcache) { if(!data->dns.hostcache) {
data->dns.hostcachetype = HCACHE_PRIVATE; data->dns.hostcachetype = HCACHE_PRIVATE;
data->dns.hostcache = Curl_mk_dnscache(); data->dns.hostcache = Curl_mk_dnscache();
@ -520,7 +520,7 @@ void Curl_easy_addmulti(struct SessionHandle *data,
void *multi) void *multi)
{ {
data->multi = multi; data->multi = multi;
if (multi == NULL) if(multi == NULL)
/* the association is cleared, mark the easy handle as not used by an /* the association is cleared, mark the easy handle as not used by an
interface */ interface */
data->state.used_interface = Curl_if_none; data->state.used_interface = Curl_if_none;
@ -579,7 +579,7 @@ CURL *curl_easy_duphandle(CURL *incurl)
outcurl->state.headersize=HEADERSIZE; outcurl->state.headersize=HEADERSIZE;
/* copy all userdefined values */ /* copy all userdefined values */
if (Curl_dupset(outcurl, data) != CURLE_OK) if(Curl_dupset(outcurl, data) != CURLE_OK)
break; break;
if(data->state.used_interface == Curl_if_multi) if(data->state.used_interface == Curl_if_multi)
@ -789,7 +789,7 @@ CURLcode Curl_convert_to_network(struct SessionHandle *data,
in_bytes = out_bytes = length; in_bytes = out_bytes = length;
rc = iconv(data->outbound_cd, (const char**)&input_ptr, &in_bytes, rc = iconv(data->outbound_cd, (const char**)&input_ptr, &in_bytes,
&output_ptr, &out_bytes); &output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) { if((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO; error = ERRNO;
failf(data, failf(data,
"The Curl_convert_to_network iconv call failed with errno %i: %s", "The Curl_convert_to_network iconv call failed with errno %i: %s",
@ -849,7 +849,7 @@ CURLcode Curl_convert_from_network(struct SessionHandle *data,
in_bytes = out_bytes = length; in_bytes = out_bytes = length;
rc = iconv(data->inbound_cd, (const char **)&input_ptr, &in_bytes, rc = iconv(data->inbound_cd, (const char **)&input_ptr, &in_bytes,
&output_ptr, &out_bytes); &output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) { if((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO; error = ERRNO;
failf(data, failf(data,
"The Curl_convert_from_network iconv call failed with errno %i: %s", "The Curl_convert_from_network iconv call failed with errno %i: %s",
@ -910,14 +910,14 @@ CURLcode Curl_convert_from_utf8(struct SessionHandle *data,
in_bytes = out_bytes = length; in_bytes = out_bytes = length;
rc = iconv(data->utf8_cd, &input_ptr, &in_bytes, rc = iconv(data->utf8_cd, &input_ptr, &in_bytes,
&output_ptr, &out_bytes); &output_ptr, &out_bytes);
if ((rc == ICONV_ERROR) || (in_bytes != 0)) { if((rc == ICONV_ERROR) || (in_bytes != 0)) {
error = ERRNO; error = ERRNO;
failf(data, failf(data,
"The Curl_convert_from_utf8 iconv call failed with errno %i: %s", "The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
error, strerror(error)); error, strerror(error));
return CURLE_CONV_FAILED; return CURLE_CONV_FAILED;
} }
if (output_ptr < input_ptr) { if(output_ptr < input_ptr) {
/* null terminate the now shorter output string */ /* null terminate the now shorter output string */
*output_ptr = 0x00; *output_ptr = 0x00;
} }

View File

@ -187,7 +187,7 @@ AddHttpPost(char * name, size_t namelength,
else else
return NULL; return NULL;
if (parent_post) { if(parent_post) {
/* now, point our 'more' to the original 'more' */ /* now, point our 'more' to the original 'more' */
post->more = parent_post->more; post->more = parent_post->more;
@ -224,16 +224,16 @@ static FormInfo * AddFormInfo(char *value,
form_info = (FormInfo *)malloc(sizeof(FormInfo)); form_info = (FormInfo *)malloc(sizeof(FormInfo));
if(form_info) { if(form_info) {
memset(form_info, 0, sizeof(FormInfo)); memset(form_info, 0, sizeof(FormInfo));
if (value) if(value)
form_info->value = value; form_info->value = value;
if (contenttype) if(contenttype)
form_info->contenttype = contenttype; form_info->contenttype = contenttype;
form_info->flags = HTTPPOST_FILENAME; form_info->flags = HTTPPOST_FILENAME;
} }
else else
return NULL; return NULL;
if (parent_form_info) { if(parent_form_info) {
/* now, point our 'more' to the original 'more' */ /* now, point our 'more' to the original 'more' */
form_info->more = parent_form_info->more; form_info->more = parent_form_info->more;
@ -316,7 +316,7 @@ static char *memdup(const char *src, size_t buffer_length)
bool add = FALSE; bool add = FALSE;
char *buffer; char *buffer;
if (buffer_length) if(buffer_length)
length = buffer_length; length = buffer_length;
else if(src) { else if(src) {
length = strlen(src); length = strlen(src);
@ -327,13 +327,13 @@ static char *memdup(const char *src, size_t buffer_length)
return strdup((char *)""); return strdup((char *)"");
buffer = (char*)malloc(length+add); buffer = (char*)malloc(length+add);
if (!buffer) if(!buffer)
return NULL; /* fail */ return NULL; /* fail */
memcpy(buffer, src, length); memcpy(buffer, src, length);
/* if length unknown do null termination */ /* if length unknown do null termination */
if (add) if(add)
buffer[length] = '\0'; buffer[length] = '\0';
return buffer; return buffer;
@ -418,16 +418,16 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
/* /*
* Loop through all the options set. Break if we have an error to report. * Loop through all the options set. Break if we have an error to report.
*/ */
while (return_value == CURL_FORMADD_OK) { while(return_value == CURL_FORMADD_OK) {
/* first see if we have more parts of the array param */ /* first see if we have more parts of the array param */
if ( array_state ) { if( array_state ) {
/* get the upcoming option from the given array */ /* get the upcoming option from the given array */
option = forms->option; option = forms->option;
array_value = (char *)forms->value; array_value = (char *)forms->value;
forms++; /* advance this to next entry */ forms++; /* advance this to next entry */
if (CURLFORM_END == option) { if(CURLFORM_END == option) {
/* end of array state */ /* end of array state */
array_state = FALSE; array_state = FALSE;
continue; continue;
@ -436,7 +436,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
else { else {
/* This is not array-state, get next option */ /* This is not array-state, get next option */
option = va_arg(params, CURLformoption); option = va_arg(params, CURLformoption);
if (CURLFORM_END == option) if(CURLFORM_END == option)
break; break;
} }
@ -447,7 +447,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
return_value = CURL_FORMADD_ILLEGAL_ARRAY; return_value = CURL_FORMADD_ILLEGAL_ARRAY;
else { else {
forms = va_arg(params, struct curl_forms *); forms = va_arg(params, struct curl_forms *);
if (forms) if(forms)
array_state = TRUE; array_state = TRUE;
else else
return_value = CURL_FORMADD_NULL; return_value = CURL_FORMADD_NULL;
@ -465,19 +465,19 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
current_form->flags |= HTTPPOST_PTRNAME; /* fall through */ current_form->flags |= HTTPPOST_PTRNAME; /* fall through */
#endif #endif
case CURLFORM_COPYNAME: case CURLFORM_COPYNAME:
if (current_form->name) if(current_form->name)
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
else { else {
char *name = array_state? char *name = array_state?
array_value:va_arg(params, char *); array_value:va_arg(params, char *);
if (name) if(name)
current_form->name = name; /* store for the moment */ current_form->name = name; /* store for the moment */
else else
return_value = CURL_FORMADD_NULL; return_value = CURL_FORMADD_NULL;
} }
break; break;
case CURLFORM_NAMELENGTH: case CURLFORM_NAMELENGTH:
if (current_form->namelength) if(current_form->namelength)
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
else else
current_form->namelength = current_form->namelength =
@ -490,19 +490,19 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
case CURLFORM_PTRCONTENTS: case CURLFORM_PTRCONTENTS:
current_form->flags |= HTTPPOST_PTRCONTENTS; /* fall through */ current_form->flags |= HTTPPOST_PTRCONTENTS; /* fall through */
case CURLFORM_COPYCONTENTS: case CURLFORM_COPYCONTENTS:
if (current_form->value) if(current_form->value)
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
else { else {
char *value = char *value =
array_state?array_value:va_arg(params, char *); array_state?array_value:va_arg(params, char *);
if (value) if(value)
current_form->value = value; /* store for the moment */ current_form->value = value; /* store for the moment */
else else
return_value = CURL_FORMADD_NULL; return_value = CURL_FORMADD_NULL;
} }
break; break;
case CURLFORM_CONTENTSLENGTH: case CURLFORM_CONTENTSLENGTH:
if (current_form->contentslength) if(current_form->contentslength)
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
else else
current_form->contentslength = current_form->contentslength =
@ -511,12 +511,12 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
/* Get contents from a given file name */ /* Get contents from a given file name */
case CURLFORM_FILECONTENT: case CURLFORM_FILECONTENT:
if (current_form->flags != 0) if(current_form->flags != 0)
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
else { else {
const char *filename = array_state? const char *filename = array_state?
array_value:va_arg(params, char *); array_value:va_arg(params, char *);
if (filename) { if(filename) {
current_form->value = strdup(filename); current_form->value = strdup(filename);
if(!current_form->value) if(!current_form->value)
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
@ -536,10 +536,10 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
const char *filename = array_state?array_value: const char *filename = array_state?array_value:
va_arg(params, char *); va_arg(params, char *);
if (current_form->value) { if(current_form->value) {
if (current_form->flags & HTTPPOST_FILENAME) { if(current_form->flags & HTTPPOST_FILENAME) {
if (filename) { if(filename) {
if ((current_form = AddFormInfo(strdup(filename), if((current_form = AddFormInfo(strdup(filename),
NULL, current_form)) == NULL) NULL, current_form)) == NULL)
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
} }
@ -550,7 +550,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
} }
else { else {
if (filename) { if(filename) {
current_form->value = strdup(filename); current_form->value = strdup(filename);
if(!current_form->value) if(!current_form->value)
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
@ -570,10 +570,10 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
const char *filename = array_state?array_value: const char *filename = array_state?array_value:
va_arg(params, char *); va_arg(params, char *);
if (current_form->value) { if(current_form->value) {
if (current_form->flags & HTTPPOST_BUFFER) { if(current_form->flags & HTTPPOST_BUFFER) {
if (filename) { if(filename) {
if ((current_form = AddFormInfo(strdup(filename), if((current_form = AddFormInfo(strdup(filename),
NULL, current_form)) == NULL) NULL, current_form)) == NULL)
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
} }
@ -584,7 +584,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
} }
else { else {
if (filename) { if(filename) {
current_form->value = strdup(filename); current_form->value = strdup(filename);
if(!current_form->value) if(!current_form->value)
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
@ -598,12 +598,12 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
case CURLFORM_BUFFERPTR: case CURLFORM_BUFFERPTR:
current_form->flags |= HTTPPOST_PTRBUFFER; current_form->flags |= HTTPPOST_PTRBUFFER;
if (current_form->buffer) if(current_form->buffer)
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
else { else {
char *buffer = char *buffer =
array_state?array_value:va_arg(params, char *); array_state?array_value:va_arg(params, char *);
if (buffer) if(buffer)
current_form->buffer = buffer; /* store for the moment */ current_form->buffer = buffer; /* store for the moment */
else else
return_value = CURL_FORMADD_NULL; return_value = CURL_FORMADD_NULL;
@ -611,7 +611,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
break; break;
case CURLFORM_BUFFERLENGTH: case CURLFORM_BUFFERLENGTH:
if (current_form->bufferlength) if(current_form->bufferlength)
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
else else
current_form->bufferlength = current_form->bufferlength =
@ -622,10 +622,10 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
{ {
const char *contenttype = const char *contenttype =
array_state?array_value:va_arg(params, char *); array_state?array_value:va_arg(params, char *);
if (current_form->contenttype) { if(current_form->contenttype) {
if (current_form->flags & HTTPPOST_FILENAME) { if(current_form->flags & HTTPPOST_FILENAME) {
if (contenttype) { if(contenttype) {
if ((current_form = AddFormInfo(NULL, if((current_form = AddFormInfo(NULL,
strdup(contenttype), strdup(contenttype),
current_form)) == NULL) current_form)) == NULL)
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
@ -637,7 +637,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
return_value = CURL_FORMADD_OPTION_TWICE; return_value = CURL_FORMADD_OPTION_TWICE;
} }
else { else {
if (contenttype) { if(contenttype) {
current_form->contenttype = strdup(contenttype); current_form->contenttype = strdup(contenttype);
if(!current_form->contenttype) if(!current_form->contenttype)
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
@ -692,7 +692,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
for(form = first_form; for(form = first_form;
form != NULL; form != NULL;
form = form->more) { form = form->more) {
if ( ((!form->name || !form->value) && !post) || if( ((!form->name || !form->value) && !post) ||
( (form->contentslength) && ( (form->contentslength) &&
(form->flags & HTTPPOST_FILENAME) ) || (form->flags & HTTPPOST_FILENAME) ) ||
( (form->flags & HTTPPOST_FILENAME) && ( (form->flags & HTTPPOST_FILENAME) &&
@ -709,7 +709,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
break; break;
} }
else { else {
if ( ((form->flags & HTTPPOST_FILENAME) || if( ((form->flags & HTTPPOST_FILENAME) ||
(form->flags & HTTPPOST_BUFFER)) && (form->flags & HTTPPOST_BUFFER)) &&
!form->contenttype ) { !form->contenttype ) {
/* our contenttype is missing */ /* our contenttype is missing */
@ -721,23 +721,23 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
} }
form->contenttype_alloc = TRUE; form->contenttype_alloc = TRUE;
} }
if ( !(form->flags & HTTPPOST_PTRNAME) && if( !(form->flags & HTTPPOST_PTRNAME) &&
(form == first_form) ) { (form == first_form) ) {
/* copy name (without strdup; possibly contains null characters) */ /* copy name (without strdup; possibly contains null characters) */
form->name = memdup(form->name, form->namelength); form->name = memdup(form->name, form->namelength);
if (!form->name) { if(!form->name) {
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
break; break;
} }
form->name_alloc = TRUE; form->name_alloc = TRUE;
} }
if ( !(form->flags & HTTPPOST_FILENAME) && if( !(form->flags & HTTPPOST_FILENAME) &&
!(form->flags & HTTPPOST_READFILE) && !(form->flags & HTTPPOST_READFILE) &&
!(form->flags & HTTPPOST_PTRCONTENTS) && !(form->flags & HTTPPOST_PTRCONTENTS) &&
!(form->flags & HTTPPOST_PTRBUFFER) ) { !(form->flags & HTTPPOST_PTRBUFFER) ) {
/* copy value (without strdup; possibly contains null characters) */ /* copy value (without strdup; possibly contains null characters) */
form->value = memdup(form->value, form->contentslength); form->value = memdup(form->value, form->contentslength);
if (!form->value) { if(!form->value) {
return_value = CURL_FORMADD_MEMORY; return_value = CURL_FORMADD_MEMORY;
break; break;
} }
@ -756,7 +756,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
break; break;
} }
if (form->contenttype) if(form->contenttype)
prevtype = form->contenttype; prevtype = form->contenttype;
} }
} }
@ -780,7 +780,7 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost,
/* always delete the allocated memory before returning */ /* always delete the allocated memory before returning */
form = first_form; form = first_form;
while (form != NULL) { while(form != NULL) {
FormInfo *delete_form; FormInfo *delete_form;
delete_form = form; delete_form = form;
@ -820,7 +820,7 @@ static CURLcode AddFormData(struct FormData **formp,
{ {
struct FormData *newform = (struct FormData *) struct FormData *newform = (struct FormData *)
malloc(sizeof(struct FormData)); malloc(sizeof(struct FormData));
if (!newform) if(!newform)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
newform->next = NULL; newform->next = NULL;
@ -829,7 +829,7 @@ static CURLcode AddFormData(struct FormData **formp,
length = strlen((char *)line); length = strlen((char *)line);
newform->line = (char *)malloc(length+1); newform->line = (char *)malloc(length+1);
if (!newform->line) { if(!newform->line) {
free(newform); free(newform);
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
@ -845,7 +845,7 @@ static CURLcode AddFormData(struct FormData **formp,
else else
*formp = newform; *formp = newform;
if (size) { if(size) {
if((type == FORM_DATA) || (type == FORM_CONTENT)) if((type == FORM_DATA) || (type == FORM_CONTENT))
*size += length; *size += length;
else { else {
@ -896,7 +896,7 @@ void Curl_formclean(struct FormData **form_ptr)
free(form->line); /* free the line */ free(form->line); /* free the line */
free(form); /* free the struct */ free(form); /* free the struct */
} while ((form = next) != NULL); /* continue */ } while((form = next) != NULL); /* continue */
*form_ptr = NULL; *form_ptr = NULL;
} }
@ -920,13 +920,13 @@ CURLcode Curl_formconvert(struct SessionHandle *data, struct FormData *form)
do { do {
next=form->next; /* the following form line */ next=form->next; /* the following form line */
if (form->type == FORM_DATA) { if(form->type == FORM_DATA) {
rc = Curl_convert_to_network(data, form->line, form->length); rc = Curl_convert_to_network(data, form->line, form->length);
/* Curl_convert_to_network calls failf if unsuccessful */ /* Curl_convert_to_network calls failf if unsuccessful */
if (rc != CURLE_OK) if(rc != CURLE_OK)
return rc; return rc;
} }
} while ((form = next) != NULL); /* continue */ } while((form = next) != NULL); /* continue */
return CURLE_OK; return CURLE_OK;
} }
#endif /* CURL_DOES_CONVERSIONS */ #endif /* CURL_DOES_CONVERSIONS */
@ -944,11 +944,11 @@ int curl_formget(struct curl_httppost *form, void *arg,
struct FormData *data, *ptr; struct FormData *data, *ptr;
rc = Curl_getFormData(&data, form, NULL, &size); rc = Curl_getFormData(&data, form, NULL, &size);
if (rc != CURLE_OK) if(rc != CURLE_OK)
return (int)rc; return (int)rc;
for (ptr = data; ptr; ptr = ptr->next) { for (ptr = data; ptr; ptr = ptr->next) {
if (ptr->type == FORM_FILE) { if(ptr->type == FORM_FILE) {
char buffer[8192]; char buffer[8192];
size_t nread; size_t nread;
struct Form temp; struct Form temp;
@ -957,16 +957,16 @@ int curl_formget(struct curl_httppost *form, void *arg,
do { do {
nread = readfromfile(&temp, buffer, sizeof(buffer)); nread = readfromfile(&temp, buffer, sizeof(buffer));
if ((nread == (size_t) -1) || (nread != append(arg, buffer, nread))) { if((nread == (size_t) -1) || (nread != append(arg, buffer, nread))) {
if (temp.fp) { if(temp.fp) {
fclose(temp.fp); fclose(temp.fp);
} }
Curl_formclean(&data); Curl_formclean(&data);
return -1; return -1;
} }
} while (nread == sizeof(buffer)); } while(nread == sizeof(buffer));
} else { } else {
if (ptr->length != append(arg, ptr->line, ptr->length)) { if(ptr->length != append(arg, ptr->line, ptr->length)) {
Curl_formclean(&data); Curl_formclean(&data);
return -1; return -1;
} }
@ -1005,7 +1005,7 @@ void curl_formfree(struct curl_httppost *form)
free(form->showfilename); /* free the faked file name */ free(form->showfilename); /* free the faked file name */
free(form); /* free the struct */ free(form); /* free the struct */
} while ((form = next) != NULL); /* continue */ } while((form = next) != NULL); /* continue */
} }
#ifndef HAVE_BASENAME #ifndef HAVE_BASENAME
@ -1110,7 +1110,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
"Content-Type: multipart/form-data", "Content-Type: multipart/form-data",
boundary); boundary);
if (result) { if(result) {
free(boundary); free(boundary);
return result; return result;
} }
@ -1123,13 +1123,13 @@ CURLcode Curl_getFormData(struct FormData **finalform,
if(size) { if(size) {
result = AddFormDataf(&form, &size, "\r\n"); result = AddFormDataf(&form, &size, "\r\n");
if (result) if(result)
break; break;
} }
/* boundary */ /* boundary */
result = AddFormDataf(&form, &size, "--%s\r\n", boundary); result = AddFormDataf(&form, &size, "--%s\r\n", boundary);
if (result) if(result)
break; break;
/* Maybe later this should be disabled when a custom_content_type is /* Maybe later this should be disabled when a custom_content_type is
@ -1138,16 +1138,16 @@ CURLcode Curl_getFormData(struct FormData **finalform,
*/ */
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"Content-Disposition: form-data; name=\""); "Content-Disposition: form-data; name=\"");
if (result) if(result)
break; break;
result = AddFormData(&form, FORM_DATA, post->name, post->namelength, result = AddFormData(&form, FORM_DATA, post->name, post->namelength,
&size); &size);
if (result) if(result)
break; break;
result = AddFormDataf(&form, &size, "\""); result = AddFormDataf(&form, &size, "\"");
if (result) if(result)
break; break;
if(post->more) { if(post->more) {
@ -1160,7 +1160,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
"\r\nContent-Type: multipart/mixed," "\r\nContent-Type: multipart/mixed,"
" boundary=%s\r\n", " boundary=%s\r\n",
fileboundary); fileboundary);
if (result) if(result)
break; break;
} }
@ -1183,9 +1183,9 @@ CURLcode Curl_getFormData(struct FormData **finalform,
fileboundary, fileboundary,
(file->showfilename?file->showfilename: (file->showfilename?file->showfilename:
filebasename)); filebasename));
if (filebasename) if(filebasename)
free(filebasename); free(filebasename);
if (result) if(result)
break; break;
} }
else if((post->flags & HTTPPOST_FILENAME) || else if((post->flags & HTTPPOST_FILENAME) ||
@ -1198,10 +1198,10 @@ CURLcode Curl_getFormData(struct FormData **finalform,
"; filename=\"%s\"", "; filename=\"%s\"",
(post->showfilename?post->showfilename: (post->showfilename?post->showfilename:
filebasename)); filebasename));
if (filebasename) if(filebasename)
free(filebasename); free(filebasename);
if (result) if(result)
break; break;
} }
@ -1210,7 +1210,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"\r\nContent-Type: %s", "\r\nContent-Type: %s",
file->contenttype); file->contenttype);
if (result) if(result)
break; break;
} }
@ -1218,11 +1218,11 @@ CURLcode Curl_getFormData(struct FormData **finalform,
while( curList ) { while( curList ) {
/* Process the additional headers specified for this form */ /* Process the additional headers specified for this form */
result = AddFormDataf( &form, &size, "\r\n%s", curList->data ); result = AddFormDataf( &form, &size, "\r\n%s", curList->data );
if (result) if(result)
break; break;
curList = curList->next; curList = curList->next;
} }
if (result) { if(result) {
Curl_formclean(&firstform); Curl_formclean(&firstform);
free(boundary); free(boundary);
return result; return result;
@ -1240,13 +1240,13 @@ CURLcode Curl_getFormData(struct FormData **finalform,
/* this is not a text content, mention our binary encoding */ /* this is not a text content, mention our binary encoding */
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"\r\nContent-Transfer-Encoding: binary"); "\r\nContent-Transfer-Encoding: binary");
if (result) if(result)
break; break;
} }
#endif #endif
result = AddFormDataf(&form, &size, "\r\n\r\n"); result = AddFormDataf(&form, &size, "\r\n\r\n");
if (result) if(result)
break; break;
if((post->flags & HTTPPOST_FILENAME) || if((post->flags & HTTPPOST_FILENAME) ||
@ -1278,14 +1278,14 @@ CURLcode Curl_getFormData(struct FormData **finalform,
*/ */
size_t nread; size_t nread;
char buffer[512]; char buffer[512];
while ((nread = fread(buffer, 1, sizeof(buffer), fileread)) != 0) { while((nread = fread(buffer, 1, sizeof(buffer), fileread)) != 0) {
result = AddFormData(&form, FORM_CONTENT, buffer, nread, &size); result = AddFormData(&form, FORM_CONTENT, buffer, nread, &size);
if (result) if(result)
break; break;
} }
} }
if (result) { if(result) {
Curl_formclean(&firstform); Curl_formclean(&firstform);
free(boundary); free(boundary);
return result; return result;
@ -1305,11 +1305,11 @@ CURLcode Curl_getFormData(struct FormData **finalform,
} }
} }
else if (post->flags & HTTPPOST_BUFFER) { else if(post->flags & HTTPPOST_BUFFER) {
/* include contents of buffer */ /* include contents of buffer */
result = AddFormData(&form, FORM_CONTENT, post->buffer, result = AddFormData(&form, FORM_CONTENT, post->buffer,
post->bufferlength, &size); post->bufferlength, &size);
if (result) if(result)
break; break;
} }
@ -1317,11 +1317,11 @@ CURLcode Curl_getFormData(struct FormData **finalform,
/* include the contents we got */ /* include the contents we got */
result = AddFormData(&form, FORM_CONTENT, post->contents, result = AddFormData(&form, FORM_CONTENT, post->contents,
post->contentslength, &size); post->contentslength, &size);
if (result) if(result)
break; break;
} }
} while ((file = file->more) != NULL); /* for each specified file for this field */ } while((file = file->more) != NULL); /* for each specified file for this field */
if (result) { if(result) {
Curl_formclean(&firstform); Curl_formclean(&firstform);
free(boundary); free(boundary);
return result; return result;
@ -1334,12 +1334,12 @@ CURLcode Curl_getFormData(struct FormData **finalform,
"\r\n--%s--", "\r\n--%s--",
fileboundary); fileboundary);
free(fileboundary); free(fileboundary);
if (result) if(result)
break; break;
} }
} while ((post = post->next) != NULL); /* for each field */ } while((post = post->next) != NULL); /* for each field */
if (result) { if(result) {
Curl_formclean(&firstform); Curl_formclean(&firstform);
free(boundary); free(boundary);
return result; return result;
@ -1349,7 +1349,7 @@ CURLcode Curl_getFormData(struct FormData **finalform,
result = AddFormDataf(&form, &size, result = AddFormDataf(&form, &size,
"\r\n--%s--\r\n", "\r\n--%s--\r\n",
boundary); boundary);
if (result) { if(result) {
Curl_formclean(&firstform); Curl_formclean(&firstform);
free(boundary); free(boundary);
return result; return result;
@ -1488,7 +1488,7 @@ int FormAddTest(const char * errormsg,
int result; int result;
va_list arg; va_list arg;
va_start(arg, last_post); va_start(arg, last_post);
if ((result = FormAdd(httppost, last_post, arg))) if((result = FormAdd(httppost, last_post, arg)))
fprintf (stderr, "ERROR doing FormAdd ret: %d action: %s\n", result, fprintf (stderr, "ERROR doing FormAdd ret: %d action: %s\n", result,
errormsg); errormsg);
va_end(arg); va_end(arg);
@ -1539,11 +1539,11 @@ int main(int argc, argv_item_t argv[])
(void) argc; (void) argc;
(void) argv; (void) argv;
if (FormAddTest("simple COPYCONTENTS test", &httppost, &last_post, if(FormAddTest("simple COPYCONTENTS test", &httppost, &last_post,
CURLFORM_COPYNAME, name1, CURLFORM_COPYCONTENTS, value1, CURLFORM_COPYNAME, name1, CURLFORM_COPYCONTENTS, value1,
CURLFORM_END)) CURLFORM_END))
++errors; ++errors;
if (FormAddTest("COPYCONTENTS + CONTENTTYPE test", &httppost, &last_post, if(FormAddTest("COPYCONTENTS + CONTENTTYPE test", &httppost, &last_post,
CURLFORM_COPYNAME, name2, CURLFORM_COPYCONTENTS, value2, CURLFORM_COPYNAME, name2, CURLFORM_COPYCONTENTS, value2,
CURLFORM_CONTENTTYPE, type2, CURLFORM_END)) CURLFORM_CONTENTTYPE, type2, CURLFORM_END))
++errors; ++errors;
@ -1551,41 +1551,41 @@ int main(int argc, argv_item_t argv[])
correctly */ correctly */
name3[1] = '\0'; name3[1] = '\0';
value3[1] = '\0'; value3[1] = '\0';
if (FormAddTest("PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH test", if(FormAddTest("PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH test",
&httppost, &last_post, &httppost, &last_post,
CURLFORM_PTRNAME, name3, CURLFORM_COPYCONTENTS, value3, CURLFORM_PTRNAME, name3, CURLFORM_COPYCONTENTS, value3,
CURLFORM_CONTENTSLENGTH, value3length, CURLFORM_CONTENTSLENGTH, value3length,
CURLFORM_NAMELENGTH, name3length, CURLFORM_END)) CURLFORM_NAMELENGTH, name3length, CURLFORM_END))
++errors; ++errors;
if (FormAddTest("simple PTRCONTENTS test", &httppost, &last_post, if(FormAddTest("simple PTRCONTENTS test", &httppost, &last_post,
CURLFORM_COPYNAME, name4, CURLFORM_PTRCONTENTS, value4, CURLFORM_COPYNAME, name4, CURLFORM_PTRCONTENTS, value4,
CURLFORM_END)) CURLFORM_END))
++errors; ++errors;
/* make null character at start to check that contentslength works /* make null character at start to check that contentslength works
correctly */ correctly */
value5[1] = '\0'; value5[1] = '\0';
if (FormAddTest("PTRCONTENTS + CONTENTSLENGTH test", &httppost, &last_post, if(FormAddTest("PTRCONTENTS + CONTENTSLENGTH test", &httppost, &last_post,
CURLFORM_COPYNAME, name5, CURLFORM_PTRCONTENTS, value5, CURLFORM_COPYNAME, name5, CURLFORM_PTRCONTENTS, value5,
CURLFORM_CONTENTSLENGTH, value5length, CURLFORM_END)) CURLFORM_CONTENTSLENGTH, value5length, CURLFORM_END))
++errors; ++errors;
/* make null character at start to check that contentslength works /* make null character at start to check that contentslength works
correctly */ correctly */
value6[1] = '\0'; value6[1] = '\0';
if (FormAddTest("PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE test", if(FormAddTest("PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE test",
&httppost, &last_post, &httppost, &last_post,
CURLFORM_COPYNAME, name6, CURLFORM_PTRCONTENTS, value6, CURLFORM_COPYNAME, name6, CURLFORM_PTRCONTENTS, value6,
CURLFORM_CONTENTSLENGTH, value6length, CURLFORM_CONTENTSLENGTH, value6length,
CURLFORM_CONTENTTYPE, type6, CURLFORM_END)) CURLFORM_CONTENTTYPE, type6, CURLFORM_END))
++errors; ++errors;
if (FormAddTest("FILE + CONTENTTYPE test", &httppost, &last_post, if(FormAddTest("FILE + CONTENTTYPE test", &httppost, &last_post,
CURLFORM_COPYNAME, name7, CURLFORM_FILE, value7, CURLFORM_COPYNAME, name7, CURLFORM_FILE, value7,
CURLFORM_CONTENTTYPE, type7, CURLFORM_END)) CURLFORM_CONTENTTYPE, type7, CURLFORM_END))
++errors; ++errors;
if (FormAddTest("FILE1 + FILE2 test", &httppost, &last_post, if(FormAddTest("FILE1 + FILE2 test", &httppost, &last_post,
CURLFORM_COPYNAME, name8, CURLFORM_FILE, value7, CURLFORM_COPYNAME, name8, CURLFORM_FILE, value7,
CURLFORM_FILE, value8, CURLFORM_END)) CURLFORM_FILE, value8, CURLFORM_END))
++errors; ++errors;
if (FormAddTest("FILE1 + FILE2 + FILE3 test", &httppost, &last_post, if(FormAddTest("FILE1 + FILE2 + FILE3 test", &httppost, &last_post,
CURLFORM_COPYNAME, name9, CURLFORM_FILE, value7, CURLFORM_COPYNAME, name9, CURLFORM_FILE, value7,
CURLFORM_FILE, value8, CURLFORM_FILE, value7, CURLFORM_END)) CURLFORM_FILE, value8, CURLFORM_FILE, value7, CURLFORM_END))
++errors; ++errors;
@ -1596,11 +1596,11 @@ int main(int argc, argv_item_t argv[])
forms[2].option = CURLFORM_FILE; forms[2].option = CURLFORM_FILE;
forms[2].value = value7; forms[2].value = value7;
forms[3].option = CURLFORM_END; forms[3].option = CURLFORM_END;
if (FormAddTest("FILE1 + FILE2 + FILE3 ARRAY test", &httppost, &last_post, if(FormAddTest("FILE1 + FILE2 + FILE3 ARRAY test", &httppost, &last_post,
CURLFORM_COPYNAME, name10, CURLFORM_ARRAY, forms, CURLFORM_COPYNAME, name10, CURLFORM_ARRAY, forms,
CURLFORM_END)) CURLFORM_END))
++errors; ++errors;
if (FormAddTest("FILECONTENT test", &httppost, &last_post, if(FormAddTest("FILECONTENT test", &httppost, &last_post,
CURLFORM_COPYNAME, name11, CURLFORM_FILECONTENT, value7, CURLFORM_COPYNAME, name11, CURLFORM_FILECONTENT, value7,
CURLFORM_END)) CURLFORM_END))
++errors; ++errors;
@ -1628,7 +1628,7 @@ int main(int argc, argv_item_t argv[])
fprintf(stdout, "size: "); fprintf(stdout, "size: ");
fprintf(stdout, CURL_FORMAT_OFF_T, size); fprintf(stdout, CURL_FORMAT_OFF_T, size);
fprintf(stdout, "\n"); fprintf(stdout, "\n");
if (errors) if(errors)
fprintf(stdout, "\n==> %d Test(s) failed!\n", errors); fprintf(stdout, "\n==> %d Test(s) failed!\n", errors);
else else
fprintf(stdout, "\nAll Tests seem to have worked (please check output)\n"); fprintf(stdout, "\nAll Tests seem to have worked (please check output)\n");

114
lib/ftp.c
View File

@ -152,9 +152,9 @@ static CURLcode Curl_ftps_setup_connection(struct connectdata * conn);
#endif #endif
/* easy-to-use macro: */ /* easy-to-use macro: */
#define FTPSENDF(x,y,z) if ((result = Curl_ftpsendf(x,y,z)) != CURLE_OK) \ #define FTPSENDF(x,y,z) if((result = Curl_ftpsendf(x,y,z)) != CURLE_OK) \
return result return result
#define NBFTPSENDF(x,y,z) if ((result = Curl_nbftpsendf(x,y,z)) != CURLE_OK) \ #define NBFTPSENDF(x,y,z) if((result = Curl_nbftpsendf(x,y,z)) != CURLE_OK) \
return result return result
@ -307,9 +307,9 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
/* if a timeout is set, use the most restrictive one */ /* if a timeout is set, use the most restrictive one */
if (data->set.timeout > 0) if(data->set.timeout > 0)
timeout_set += 1; timeout_set += 1;
if (data->set.connecttimeout > 0) if(data->set.connecttimeout > 0)
timeout_set += 2; timeout_set += 2;
switch (timeout_set) { switch (timeout_set) {
@ -320,7 +320,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
timeout_ms = data->set.connecttimeout; timeout_ms = data->set.connecttimeout;
break; break;
case 3: case 3:
if (data->set.timeout < data->set.connecttimeout) if(data->set.timeout < data->set.connecttimeout)
timeout_ms = data->set.timeout; timeout_ms = data->set.timeout;
else else
timeout_ms = data->set.connecttimeout; timeout_ms = data->set.connecttimeout;
@ -330,7 +330,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
break; break;
} }
if (timeout_set > 0) { if(timeout_set > 0) {
/* if a timeout was already set, substract elapsed time */ /* if a timeout was already set, substract elapsed time */
timeout_ms -= Curl_tvdiff(Curl_tvnow(), conn->now); timeout_ms -= Curl_tvdiff(Curl_tvnow(), conn->now);
if(timeout_ms < 0) { if(timeout_ms < 0) {
@ -366,7 +366,7 @@ static CURLcode AllowServerConnect(struct connectdata *conn)
} }
sclose(sock); /* close the first socket */ sclose(sock); /* close the first socket */
if (CURL_SOCKET_BAD == s) { if(CURL_SOCKET_BAD == s) {
/* DIE! */ /* DIE! */
failf(data, "Error accept()ing server connect"); failf(data, "Error accept()ing server connect");
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
@ -643,7 +643,7 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
size_t nread; size_t nread;
int cache_skip=0; int cache_skip=0;
if (ftpcode) if(ftpcode)
*ftpcode = 0; /* 0 for errors */ *ftpcode = 0; /* 0 for errors */
*nreadp=0; *nreadp=0;
@ -846,7 +846,7 @@ static CURLcode ftp_state_cwd(struct connectdata *conn)
result = ftp_state_post_cwd(conn); result = ftp_state_post_cwd(conn);
else { else {
ftpc->count2 = 0; ftpc->count2 = 0;
if (conn->bits.reuse && ftpc->entrypath) { if(conn->bits.reuse && ftpc->entrypath) {
/* This is a re-used connection. Since we change directory to where the /* This is a re-used connection. Since we change directory to where the
transfer is taking place, we must first get back to the original dir transfer is taking place, we must first get back to the original dir
where we ended up after login: */ where we ended up after login: */
@ -922,13 +922,13 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
the IP from the control connection */ the IP from the control connection */
sslen = sizeof(ss); sslen = sizeof(ss);
if (getsockname(conn->sock[FIRSTSOCKET], (struct sockaddr *)&ss, &sslen)) { if(getsockname(conn->sock[FIRSTSOCKET], (struct sockaddr *)&ss, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, SOCKERRNO) ); Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
if (sslen > (socklen_t)sizeof(ss)) if(sslen > (socklen_t)sizeof(ss))
sslen = sizeof(ss); sslen = sizeof(ss);
rc = getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf), NULL, rc = getnameinfo((struct sockaddr *)&ss, sslen, hbuf, sizeof(hbuf), NULL,
0, NIFLAGS); 0, NIFLAGS);
@ -960,11 +960,11 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* /*
* Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype): * Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype):
*/ */
if (ai->ai_socktype == 0) if(ai->ai_socktype == 0)
ai->ai_socktype = conn->socktype; ai->ai_socktype = conn->socktype;
portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (portsock == CURL_SOCKET_BAD) { if(portsock == CURL_SOCKET_BAD) {
error = SOCKERRNO; error = SOCKERRNO;
continue; continue;
} }
@ -978,11 +978,11 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* step 3, bind to a suitable local address */ /* step 3, bind to a suitable local address */
/* Try binding the given address. */ /* Try binding the given address. */
if (bind(portsock, ai->ai_addr, ai->ai_addrlen)) { if(bind(portsock, ai->ai_addr, ai->ai_addrlen)) {
/* It failed. Bind the address used for the control connection instead */ /* It failed. Bind the address used for the control connection instead */
sslen = sizeof(ss); sslen = sizeof(ss);
if (getsockname(conn->sock[FIRSTSOCKET], if(getsockname(conn->sock[FIRSTSOCKET],
(struct sockaddr *)sa, &sslen)) { (struct sockaddr *)sa, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, SOCKERRNO) ); Curl_strerror(conn, SOCKERRNO) );
@ -996,7 +996,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
else else
((struct sockaddr_in6 *)sa)->sin6_port =0; ((struct sockaddr_in6 *)sa)->sin6_port =0;
if (sslen > (socklen_t)sizeof(ss)) if(sslen > (socklen_t)sizeof(ss))
sslen = sizeof(ss); sslen = sizeof(ss);
if(bind(portsock, (struct sockaddr *)sa, sslen)) { if(bind(portsock, (struct sockaddr *)sa, sslen)) {
@ -1018,7 +1018,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
/* step 4, listen on the socket */ /* step 4, listen on the socket */
if (listen(portsock, 1)) { if(listen(portsock, 1)) {
failf(data, "socket failure: %s", Curl_strerror(conn, SOCKERRNO)); failf(data, "socket failure: %s", Curl_strerror(conn, SOCKERRNO));
sclose(portsock); sclose(portsock);
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
@ -1054,7 +1054,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
break; break;
} }
if (EPRT == fcmd) { if(EPRT == fcmd) {
/* /*
* Two fine examples from RFC2428; * Two fine examples from RFC2428;
* *
@ -1070,11 +1070,11 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
return result; return result;
break; break;
} }
else if (PORT == fcmd) { else if(PORT == fcmd) {
char *source = myhost; char *source = myhost;
char *dest = tmp; char *dest = tmp;
if ((PORT == fcmd) && ai->ai_family != AF_INET) if((PORT == fcmd) && ai->ai_family != AF_INET)
continue; continue;
/* translate x.x.x.x to x,x,x,x */ /* translate x.x.x.x to x,x,x,x */
@ -1161,19 +1161,19 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if(!addr) { if(!addr) {
/* pick a suitable default here */ /* pick a suitable default here */
if (getsockname(conn->sock[FIRSTSOCKET], if(getsockname(conn->sock[FIRSTSOCKET],
(struct sockaddr *)&sa, &sslen)) { (struct sockaddr *)&sa, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, SOCKERRNO) ); Curl_strerror(conn, SOCKERRNO) );
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
if (sslen > (socklen_t)sizeof(sa)) if(sslen > (socklen_t)sizeof(sa))
sslen = sizeof(sa); sslen = sizeof(sa);
sa_filled_in = TRUE; /* the sa struct is filled in */ sa_filled_in = TRUE; /* the sa struct is filled in */
} }
if (addr || sa_filled_in) { if(addr || sa_filled_in) {
portsock = socket(AF_INET, SOCK_STREAM, 0); portsock = socket(AF_INET, SOCK_STREAM, 0);
if(CURL_SOCKET_BAD != portsock) { if(CURL_SOCKET_BAD != portsock) {
@ -1205,7 +1205,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
} }
porttouse = ntohs(add.sin_port); porttouse = ntohs(add.sin_port);
if ( listen(portsock, 1) < 0 ) { if( listen(portsock, 1) < 0 ) {
failf(data, "listen(2) failed on socket"); failf(data, "listen(2) failed on socket");
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
@ -1484,7 +1484,7 @@ static CURLcode ftp_state_post_mdtm(struct connectdata *conn)
/* Some servers return different sizes for different modes, and thus we /* Some servers return different sizes for different modes, and thus we
must set the proper type before we check the size */ must set the proper type before we check the size */
result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_TYPE); result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_TYPE);
if (result) if(result)
return result; return result;
} }
else else
@ -1659,7 +1659,7 @@ static CURLcode ftp_state_quote(struct connectdata *conn,
result = ftp_state_cwd(conn); result = ftp_state_cwd(conn);
break; break;
case FTP_RETR_PREQUOTE: case FTP_RETR_PREQUOTE:
if (ftp->transfer != FTPTRANSFER_BODY) if(ftp->transfer != FTPTRANSFER_BODY)
state(conn, FTP_STOP); state(conn, FTP_STOP);
else { else {
NBFTPSENDF(conn, "SIZE %s", ftpc->file); NBFTPSENDF(conn, "SIZE %s", ftpc->file);
@ -1724,7 +1724,7 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
if(ptr) { if(ptr) {
newport = (unsigned short)(num & 0xffff); newport = (unsigned short)(num & 0xffff);
if (conn->bits.tunnel_proxy || if(conn->bits.tunnel_proxy ||
data->set.proxytype == CURLPROXY_SOCKS5 || data->set.proxytype == CURLPROXY_SOCKS5 ||
data->set.proxytype == CURLPROXY_SOCKS4) data->set.proxytype == CURLPROXY_SOCKS4)
/* proxy tunnel -> use other host info because ip_addr_str is the /* proxy tunnel -> use other host info because ip_addr_str is the
@ -1759,7 +1759,7 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
* "227 Entering passive mode. 127,0,0,1,4,51" * "227 Entering passive mode. 127,0,0,1,4,51"
*/ */
while(*str) { while(*str) {
if (6 == sscanf(str, "%d,%d,%d,%d,%d,%d", if(6 == sscanf(str, "%d,%d,%d,%d,%d,%d",
&ip[0], &ip[1], &ip[2], &ip[3], &ip[0], &ip[1], &ip[2], &ip[3],
&port[0], &port[1])) &port[0], &port[1]))
break; break;
@ -1778,7 +1778,7 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
infof(data, "Skips %d.%d.%d.%d for data connection, uses %s instead\n", infof(data, "Skips %d.%d.%d.%d for data connection, uses %s instead\n",
ip[0], ip[1], ip[2], ip[3], ip[0], ip[1], ip[2], ip[3],
conn->ip_addr_str); conn->ip_addr_str);
if (conn->bits.tunnel_proxy || if(conn->bits.tunnel_proxy ||
data->set.proxytype == CURLPROXY_SOCKS5 || data->set.proxytype == CURLPROXY_SOCKS5 ||
data->set.proxytype == CURLPROXY_SOCKS4) data->set.proxytype == CURLPROXY_SOCKS4)
/* proxy tunnel -> use other host info because ip_addr_str is the /* proxy tunnel -> use other host info because ip_addr_str is the
@ -1848,7 +1848,7 @@ static CURLcode ftp_state_pasv_resp(struct connectdata *conn,
Curl_resolv_unlock(data, addr); /* we're done using this address */ Curl_resolv_unlock(data, addr); /* we're done using this address */
if (result && ftpc->count1 == 0 && ftpcode == 229) { if(result && ftpc->count1 == 0 && ftpcode == 229) {
infof(data, "got positive EPSV response, but can't connect. " infof(data, "got positive EPSV response, but can't connect. "
"Disabling EPSV\n"); "Disabling EPSV\n");
/* disable it for next transfer */ /* disable it for next transfer */
@ -1936,7 +1936,7 @@ static CURLcode ftp_state_port_resp(struct connectdata *conn,
if(ftpcode != 200) { if(ftpcode != 200) {
/* the command failed */ /* the command failed */
if (EPRT == fcmd) { if(EPRT == fcmd) {
infof(data, "disabling EPRT usage\n"); infof(data, "disabling EPRT usage\n");
conn->bits.ftp_use_eprt = FALSE; conn->bits.ftp_use_eprt = FALSE;
} }
@ -2098,7 +2098,7 @@ static CURLcode ftp_state_post_retr_size(struct connectdata *conn,
struct FTP *ftp = data->reqdata.proto.ftp; struct FTP *ftp = data->reqdata.proto.ftp;
struct ftp_conn *ftpc = &conn->proto.ftpc; struct ftp_conn *ftpc = &conn->proto.ftpc;
if (data->set.max_filesize && (filesize > data->set.max_filesize)) { if(data->set.max_filesize && (filesize > data->set.max_filesize)) {
failf(data, "Maximum file size exceeded"); failf(data, "Maximum file size exceeded");
return CURLE_FILESIZE_EXCEEDED; return CURLE_FILESIZE_EXCEEDED;
} }
@ -2220,7 +2220,7 @@ static CURLcode ftp_state_rest_resp(struct connectdata *conn,
case FTP_REST: case FTP_REST:
default: default:
#ifdef CURL_FTP_HTTPSTYLE_HEAD #ifdef CURL_FTP_HTTPSTYLE_HEAD
if (ftpcode == 350) { if(ftpcode == 350) {
char buffer[24]= { "Accept-ranges: bytes\r\n" }; char buffer[24]= { "Accept-ranges: bytes\r\n" };
result = Curl_client_write(conn, CLIENTWRITE_BOTH, buffer, 0); result = Curl_client_write(conn, CLIENTWRITE_BOTH, buffer, 0);
if(result) if(result)
@ -2231,7 +2231,7 @@ static CURLcode ftp_state_rest_resp(struct connectdata *conn,
break; break;
case FTP_RETR_REST: case FTP_RETR_REST:
if (ftpcode != 350) { if(ftpcode != 350) {
failf(conn->data, "Couldn't use REST"); failf(conn->data, "Couldn't use REST");
result = CURLE_FTP_COULDNT_USE_REST; result = CURLE_FTP_COULDNT_USE_REST;
} }
@ -2497,7 +2497,7 @@ static CURLcode ftp_state_user_resp(struct connectdata *conn,
530 User ... access denied 530 User ... access denied
(the server denies to log the specified user) */ (the server denies to log the specified user) */
if (conn->data->set.str[STRING_FTP_ALTERNATIVE_TO_USER] && if(conn->data->set.str[STRING_FTP_ALTERNATIVE_TO_USER] &&
!conn->data->state.ftp_trying_alternative) { !conn->data->state.ftp_trying_alternative) {
/* Ok, USER failed. Let's try the supplied command. */ /* Ok, USER failed. Let's try the supplied command. */
NBFTPSENDF(conn, "%s", NBFTPSENDF(conn, "%s",
@ -2721,7 +2721,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
break; break;
case FTP_CCC: case FTP_CCC:
if (ftpcode < 500) { if(ftpcode < 500) {
/* First shut down the SSL layer (note: this call will block) */ /* First shut down the SSL layer (note: this call will block) */
result = Curl_ssl_shutdown(conn, FIRSTSOCKET); result = Curl_ssl_shutdown(conn, FIRSTSOCKET);
@ -3024,7 +3024,7 @@ static CURLcode ftp_init(struct connectdata *conn)
/* no need to duplicate them, this connectdata struct won't change */ /* no need to duplicate them, this connectdata struct won't change */
ftp->user = conn->user; ftp->user = conn->user;
ftp->passwd = conn->passwd; ftp->passwd = conn->passwd;
if (isBadFtpString(ftp->user) || isBadFtpString(ftp->passwd)) if(isBadFtpString(ftp->user) || isBadFtpString(ftp->passwd))
return CURLE_URL_MALFORMAT; return CURLE_URL_MALFORMAT;
return CURLE_OK; return CURLE_OK;
@ -3066,7 +3066,7 @@ static CURLcode Curl_ftp_connect(struct connectdata *conn,
ftpc->response_time = 3600000; /* set default response time-out */ ftpc->response_time = 3600000; /* set default response time-out */
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
if (conn->bits.tunnel_proxy && conn->bits.httpproxy) { if(conn->bits.tunnel_proxy && conn->bits.httpproxy) {
/* BLOCKING */ /* BLOCKING */
/* We want "seamless" FTP operations through HTTP proxy tunnel */ /* We want "seamless" FTP operations through HTTP proxy tunnel */
@ -3159,7 +3159,7 @@ static CURLcode Curl_ftp_done(struct connectdata *conn, CURLcode status,
/* the connection stays alive fine even though this happened */ /* the connection stays alive fine even though this happened */
/* fall-through */ /* fall-through */
case CURLE_OK: /* doesn't affect the control connection's status */ case CURLE_OK: /* doesn't affect the control connection's status */
if (!premature) { if(!premature) {
ftpc->ctl_valid = was_ctl_valid; ftpc->ctl_valid = was_ctl_valid;
break; break;
} }
@ -3330,15 +3330,15 @@ CURLcode ftp_sendquote(struct connectdata *conn, struct curl_slist *quote)
CURLcode result; CURLcode result;
item = quote; item = quote;
while (item) { while(item) {
if (item->data) { if(item->data) {
FTPSENDF(conn, "%s", item->data); FTPSENDF(conn, "%s", item->data);
result = Curl_GetFTPResponse(&nread, conn, &ftpcode); result = Curl_GetFTPResponse(&nread, conn, &ftpcode);
if (result) if(result)
return result; return result;
if (ftpcode >= 400) { if(ftpcode >= 400) {
failf(conn->data, "QUOT string not accepted: %s", item->data); failf(conn->data, "QUOT string not accepted: %s", item->data);
return CURLE_QUOTE_ERROR; return CURLE_QUOTE_ERROR;
} }
@ -3377,7 +3377,7 @@ static CURLcode ftp_nb_type(struct connectdata *conn,
CURLcode result; CURLcode result;
char want = (char)(ascii?'A':'I'); char want = (char)(ascii?'A':'I');
if (ftpc->transfertype == want) { if(ftpc->transfertype == want) {
state(conn, newstate); state(conn, newstate);
return ftp_state_type_resp(conn, 200, newstate); return ftp_state_type_resp(conn, 200, newstate);
} }
@ -3493,7 +3493,7 @@ static CURLcode Curl_ftp_nextconnect(struct connectdata *conn)
if(data->set.upload) { if(data->set.upload) {
result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_STOR_TYPE); result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_STOR_TYPE);
if (result) if(result)
return result; return result;
} }
else { else {
@ -3511,14 +3511,14 @@ static CURLcode Curl_ftp_nextconnect(struct connectdata *conn)
/* But only if a body transfer was requested. */ /* But only if a body transfer was requested. */
if(ftp->transfer == FTPTRANSFER_BODY) { if(ftp->transfer == FTPTRANSFER_BODY) {
result = ftp_nb_type(conn, 1, FTP_LIST_TYPE); result = ftp_nb_type(conn, 1, FTP_LIST_TYPE);
if (result) if(result)
return result; return result;
} }
/* otherwise just fall through */ /* otherwise just fall through */
} }
else { else {
result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_RETR_TYPE); result = ftp_nb_type(conn, data->set.prefer_ascii, FTP_RETR_TYPE);
if (result) if(result)
return result; return result;
} }
} }
@ -3612,7 +3612,7 @@ static CURLcode Curl_ftp(struct connectdata *conn, bool *done)
return retcode; return retcode;
retcode = ftp_parse_url_path(conn); retcode = ftp_parse_url_path(conn);
if (retcode) if(retcode)
return retcode; return retcode;
retcode = ftp_regular_transfer(conn, done); retcode = ftp_regular_transfer(conn, done);
@ -3809,7 +3809,7 @@ static CURLcode Curl_ftp_disconnect(struct connectdata *conn)
if(ftpc->entrypath) { if(ftpc->entrypath) {
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
if (data->state.most_recent_ftp_entrypath == ftpc->entrypath) { if(data->state.most_recent_ftp_entrypath == ftpc->entrypath) {
data->state.most_recent_ftp_entrypath = NULL; data->state.most_recent_ftp_entrypath = NULL;
} }
free(ftpc->entrypath); free(ftpc->entrypath);
@ -3922,25 +3922,25 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
} }
else { else {
/* parse the URL path into separate path components */ /* parse the URL path into separate path components */
while ((slash_pos = strchr(cur_pos, '/')) != NULL) { while((slash_pos = strchr(cur_pos, '/')) != NULL) {
/* 1 or 0 to indicate absolute directory */ /* 1 or 0 to indicate absolute directory */
bool absolute_dir = (bool)((cur_pos - data->reqdata.path > 0) && bool absolute_dir = (bool)((cur_pos - data->reqdata.path > 0) &&
(ftpc->dirdepth == 0)); (ftpc->dirdepth == 0));
/* seek out the next path component */ /* seek out the next path component */
if (slash_pos-cur_pos) { if(slash_pos-cur_pos) {
/* we skip empty path components, like "x//y" since the FTP command /* we skip empty path components, like "x//y" since the FTP command
CWD requires a parameter and a non-existant parameter a) doesn't CWD requires a parameter and a non-existant parameter a) doesn't
work on many servers and b) has no effect on the others. */ work on many servers and b) has no effect on the others. */
int len = (int)(slash_pos - cur_pos + absolute_dir); int len = (int)(slash_pos - cur_pos + absolute_dir);
ftpc->dirs[ftpc->dirdepth] = ftpc->dirs[ftpc->dirdepth] =
curl_easy_unescape(conn->data, cur_pos - absolute_dir, len, NULL); curl_easy_unescape(conn->data, cur_pos - absolute_dir, len, NULL);
if (!ftpc->dirs[ftpc->dirdepth]) { /* run out of memory ... */ if(!ftpc->dirs[ftpc->dirdepth]) { /* run out of memory ... */
failf(data, "no memory"); failf(data, "no memory");
freedirs(ftpc); freedirs(ftpc);
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
if (isBadFtpString(ftpc->dirs[ftpc->dirdepth])) { if(isBadFtpString(ftpc->dirs[ftpc->dirdepth])) {
free(ftpc->dirs[ftpc->dirdepth]); free(ftpc->dirs[ftpc->dirdepth]);
freedirs(ftpc); freedirs(ftpc);
return CURLE_URL_MALFORMAT; return CURLE_URL_MALFORMAT;
@ -3975,7 +3975,7 @@ CURLcode ftp_parse_url_path(struct connectdata *conn)
failf(data, "no memory"); failf(data, "no memory");
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
if (isBadFtpString(ftpc->file)) { if(isBadFtpString(ftpc->file)) {
freedirs(ftpc); freedirs(ftpc);
return CURLE_URL_MALFORMAT; return CURLE_URL_MALFORMAT;
} }
@ -4117,7 +4117,7 @@ static CURLcode Curl_ftp_setup_connection(struct connectdata * conn)
/* Unless we have asked to tunnel ftp operations through the proxy, we /* Unless we have asked to tunnel ftp operations through the proxy, we
switch and use HTTP operations only */ switch and use HTTP operations only */
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
if (conn->handler == &Curl_handler_ftp) if(conn->handler == &Curl_handler_ftp)
conn->handler = &Curl_handler_ftp_proxy; conn->handler = &Curl_handler_ftp_proxy;
else { else {
#ifdef USE_SSL #ifdef USE_SSL
@ -4140,10 +4140,10 @@ static CURLcode Curl_ftp_setup_connection(struct connectdata * conn)
* we'll try to get now! */ * we'll try to get now! */
type = strstr(data->reqdata.path, ";type="); type = strstr(data->reqdata.path, ";type=");
if (!type) if(!type)
type = strstr(conn->host.rawalloc, ";type="); type = strstr(conn->host.rawalloc, ";type=");
if (type) { if(type) {
*type = 0; /* it was in the middle of the hostname */ *type = 0; /* it was in the middle of the hostname */
command = (char) toupper((int) type[6]); command = (char) toupper((int) type[6]);

View File

@ -110,18 +110,18 @@ static bool init_resolve_thread(struct connectdata *conn,
defined(DEBUG_THREADING_GETADDRINFO) defined(DEBUG_THREADING_GETADDRINFO)
/* If this is defined, provide tracing */ /* If this is defined, provide tracing */
#define TRACE(args) \ #define TRACE(args) \
do { trace_it("%u: ", __LINE__); trace_it args; } while (0) do { trace_it("%u: ", __LINE__); trace_it args; } while(0)
static void trace_it (const char *fmt, ...) static void trace_it (const char *fmt, ...)
{ {
static int do_trace = -1; static int do_trace = -1;
va_list args; va_list args;
if (do_trace == -1) { if(do_trace == -1) {
const char *env = getenv("CURL_TRACE"); const char *env = getenv("CURL_TRACE");
do_trace = (env && atoi(env) > 0); do_trace = (env && atoi(env) > 0);
} }
if (!do_trace) if(!do_trace)
return; return;
va_start (args, fmt); va_start (args, fmt);
vfprintf (stderr, fmt, args); vfprintf (stderr, fmt, args);
@ -141,7 +141,7 @@ static void dump_addrinfo (struct connectdata *conn, const struct addrinfo *ai)
trace_it(" fam %2d, CNAME %s, ", trace_it(" fam %2d, CNAME %s, ",
ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>"); ai->ai_family, ai->ai_canonname ? ai->ai_canonname : "<none>");
if (Curl_printable_address(ai, buf, sizeof(buf))) if(Curl_printable_address(ai, buf, sizeof(buf)))
trace_it("%s\n", buf); trace_it("%s\n", buf);
else else
trace_it("failed; %s\n", Curl_strerror(conn, SOCKERRNO)); trace_it("failed; %s\n", Curl_strerror(conn, SOCKERRNO));
@ -179,13 +179,13 @@ struct thread_sync_data {
static static
void destroy_thread_sync_data(struct thread_sync_data * tsd) void destroy_thread_sync_data(struct thread_sync_data * tsd)
{ {
if (tsd->hostname) if(tsd->hostname)
free(tsd->hostname); free(tsd->hostname);
if (tsd->event_terminate) if(tsd->event_terminate)
CloseHandle(tsd->event_terminate); CloseHandle(tsd->event_terminate);
if (tsd->mutex_terminate) if(tsd->mutex_terminate)
CloseHandle(tsd->mutex_terminate); CloseHandle(tsd->mutex_terminate);
if (tsd->mutex_waiting) if(tsd->mutex_waiting)
CloseHandle(tsd->mutex_waiting); CloseHandle(tsd->mutex_waiting);
memset(tsd,0,sizeof(*tsd)); memset(tsd,0,sizeof(*tsd));
} }
@ -199,21 +199,21 @@ BOOL init_thread_sync_data(struct thread_data * td,
HANDLE curr_proc = GetCurrentProcess(); HANDLE curr_proc = GetCurrentProcess();
memset(tsd, 0, sizeof(*tsd)); memset(tsd, 0, sizeof(*tsd));
if (!DuplicateHandle(curr_proc, td->mutex_waiting, if(!DuplicateHandle(curr_proc, td->mutex_waiting,
curr_proc, &tsd->mutex_waiting, 0, FALSE, curr_proc, &tsd->mutex_waiting, 0, FALSE,
DUPLICATE_SAME_ACCESS)) { DUPLICATE_SAME_ACCESS)) {
/* failed to duplicate the mutex, no point in continuing */ /* failed to duplicate the mutex, no point in continuing */
destroy_thread_sync_data(tsd); destroy_thread_sync_data(tsd);
return FALSE; return FALSE;
} }
if (!DuplicateHandle(curr_proc, td->mutex_terminate, if(!DuplicateHandle(curr_proc, td->mutex_terminate,
curr_proc, &tsd->mutex_terminate, 0, FALSE, curr_proc, &tsd->mutex_terminate, 0, FALSE,
DUPLICATE_SAME_ACCESS)) { DUPLICATE_SAME_ACCESS)) {
/* failed to duplicate the mutex, no point in continuing */ /* failed to duplicate the mutex, no point in continuing */
destroy_thread_sync_data(tsd); destroy_thread_sync_data(tsd);
return FALSE; return FALSE;
} }
if (!DuplicateHandle(curr_proc, td->event_terminate, if(!DuplicateHandle(curr_proc, td->event_terminate,
curr_proc, &tsd->event_terminate, 0, FALSE, curr_proc, &tsd->event_terminate, 0, FALSE,
DUPLICATE_SAME_ACCESS)) { DUPLICATE_SAME_ACCESS)) {
/* failed to duplicate the event, no point in continuing */ /* failed to duplicate the event, no point in continuing */
@ -224,7 +224,7 @@ BOOL init_thread_sync_data(struct thread_data * td,
* thread during gethostbyname execution. * thread during gethostbyname execution.
*/ */
tsd->hostname = strdup(hostname); tsd->hostname = strdup(hostname);
if (!tsd->hostname) { if(!tsd->hostname) {
/* Memory allocation failed */ /* Memory allocation failed */
destroy_thread_sync_data(tsd); destroy_thread_sync_data(tsd);
return FALSE; return FALSE;
@ -237,15 +237,15 @@ static
BOOL acquire_thread_sync(struct thread_sync_data * tsd) BOOL acquire_thread_sync(struct thread_sync_data * tsd)
{ {
/* is the thread initiator still waiting for us ? */ /* is the thread initiator still waiting for us ? */
if (WaitForSingleObject(tsd->mutex_waiting, 0) == WAIT_TIMEOUT) { if(WaitForSingleObject(tsd->mutex_waiting, 0) == WAIT_TIMEOUT) {
/* yes, it is */ /* yes, it is */
/* Waiting access to event_terminate */ /* Waiting access to event_terminate */
if (WaitForSingleObject(tsd->mutex_terminate, INFINITE) != WAIT_OBJECT_0) { if(WaitForSingleObject(tsd->mutex_terminate, INFINITE) != WAIT_OBJECT_0) {
/* Something went wrong - now just ignoring */ /* Something went wrong - now just ignoring */
} }
else { else {
if (WaitForSingleObject(tsd->event_terminate, 0) != WAIT_TIMEOUT) { if(WaitForSingleObject(tsd->event_terminate, 0) != WAIT_TIMEOUT) {
/* Parent thread signaled us to terminate. /* Parent thread signaled us to terminate.
* This means that all data in conn->async is now destroyed * This means that all data in conn->async is now destroyed
* and we cannot use it. * and we cannot use it.
@ -287,7 +287,7 @@ static unsigned __stdcall gethostbyname_thread (void *arg)
*/ */
struct thread_sync_data tsd = { 0,0,0,NULL }; struct thread_sync_data tsd = { 0,0,0,NULL };
if (!init_thread_sync_data(td, conn->async.hostname, &tsd)) { if(!init_thread_sync_data(td, conn->async.hostname, &tsd)) {
/* thread synchronization data initialization failed */ /* thread synchronization data initialization failed */
return (unsigned)-1; return (unsigned)-1;
} }
@ -302,11 +302,11 @@ static unsigned __stdcall gethostbyname_thread (void *arg)
he = gethostbyname (tsd.hostname); he = gethostbyname (tsd.hostname);
/* is parent thread waiting for us and are we able to access conn members? */ /* is parent thread waiting for us and are we able to access conn members? */
if (acquire_thread_sync(&tsd)) { if(acquire_thread_sync(&tsd)) {
/* Mark that we have obtained the information, and that we are calling /* Mark that we have obtained the information, and that we are calling
* back with it. */ * back with it. */
SetEvent(td->event_resolved); SetEvent(td->event_resolved);
if (he) { if(he) {
rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he); rc = Curl_addrinfo4_callback(conn, CURL_ASYNC_SUCCESS, he);
} }
else { else {
@ -348,7 +348,7 @@ static unsigned __stdcall getaddrinfo_thread (void *arg)
*/ */
struct thread_sync_data tsd = { 0,0,0,NULL }; struct thread_sync_data tsd = { 0,0,0,NULL };
if (!init_thread_sync_data(td, conn->async.hostname, &tsd)) { if(!init_thread_sync_data(td, conn->async.hostname, &tsd)) {
/* thread synchronization data initialization failed */ /* thread synchronization data initialization failed */
return -1; return -1;
} }
@ -365,12 +365,12 @@ static unsigned __stdcall getaddrinfo_thread (void *arg)
rc = getaddrinfo(tsd.hostname, service, &hints, &res); rc = getaddrinfo(tsd.hostname, service, &hints, &res);
/* is parent thread waiting for us and are we able to access conn members? */ /* is parent thread waiting for us and are we able to access conn members? */
if (acquire_thread_sync(&tsd)) { if(acquire_thread_sync(&tsd)) {
/* Mark that we have obtained the information, and that we are calling /* Mark that we have obtained the information, and that we are calling
back with it. */ back with it. */
SetEvent(td->event_resolved); SetEvent(td->event_resolved);
if (rc == 0) { if(rc == 0) {
#ifdef DEBUG_THREADING_GETADDRINFO #ifdef DEBUG_THREADING_GETADDRINFO
dump_addrinfo (conn, res); dump_addrinfo (conn, res);
#endif #endif
@ -397,16 +397,16 @@ static unsigned __stdcall getaddrinfo_thread (void *arg)
*/ */
void Curl_destroy_thread_data (struct Curl_async *async) void Curl_destroy_thread_data (struct Curl_async *async)
{ {
if (async->hostname) if(async->hostname)
free(async->hostname); free(async->hostname);
if (async->os_specific) { if(async->os_specific) {
struct thread_data *td = (struct thread_data*) async->os_specific; struct thread_data *td = (struct thread_data*) async->os_specific;
curl_socket_t sock = td->dummy_sock; curl_socket_t sock = td->dummy_sock;
if (td->mutex_terminate && td->event_terminate) { if(td->mutex_terminate && td->event_terminate) {
/* Signaling resolver thread to terminate */ /* Signaling resolver thread to terminate */
if (WaitForSingleObject(td->mutex_terminate, INFINITE) == WAIT_OBJECT_0) { if(WaitForSingleObject(td->mutex_terminate, INFINITE) == WAIT_OBJECT_0) {
SetEvent(td->event_terminate); SetEvent(td->event_terminate);
ReleaseMutex(td->mutex_terminate); ReleaseMutex(td->mutex_terminate);
} }
@ -415,24 +415,24 @@ void Curl_destroy_thread_data (struct Curl_async *async)
} }
} }
if (td->mutex_terminate) if(td->mutex_terminate)
CloseHandle(td->mutex_terminate); CloseHandle(td->mutex_terminate);
if (td->event_terminate) if(td->event_terminate)
CloseHandle(td->event_terminate); CloseHandle(td->event_terminate);
if (td->event_thread_started) if(td->event_thread_started)
CloseHandle(td->event_thread_started); CloseHandle(td->event_thread_started);
if (sock != CURL_SOCKET_BAD) if(sock != CURL_SOCKET_BAD)
sclose(sock); sclose(sock);
/* destroy the synchronization objects */ /* destroy the synchronization objects */
if (td->mutex_waiting) if(td->mutex_waiting)
CloseHandle(td->mutex_waiting); CloseHandle(td->mutex_waiting);
td->mutex_waiting = NULL; td->mutex_waiting = NULL;
if (td->event_resolved) if(td->event_resolved)
CloseHandle(td->event_resolved); CloseHandle(td->event_resolved);
if (td->thread_hnd) if(td->thread_hnd)
CloseHandle(td->thread_hnd); CloseHandle(td->thread_hnd);
free(async->os_specific); free(async->os_specific);
@ -454,14 +454,14 @@ static bool init_resolve_thread (struct connectdata *conn,
struct thread_data *td = calloc(sizeof(*td), 1); struct thread_data *td = calloc(sizeof(*td), 1);
HANDLE thread_and_event[2] = {0}; HANDLE thread_and_event[2] = {0};
if (!td) { if(!td) {
SET_ERRNO(ENOMEM); SET_ERRNO(ENOMEM);
return FALSE; return FALSE;
} }
Curl_safefree(conn->async.hostname); Curl_safefree(conn->async.hostname);
conn->async.hostname = strdup(hostname); conn->async.hostname = strdup(hostname);
if (!conn->async.hostname) { if(!conn->async.hostname) {
free(td); free(td);
SET_ERRNO(ENOMEM); SET_ERRNO(ENOMEM);
return FALSE; return FALSE;
@ -478,7 +478,7 @@ static bool init_resolve_thread (struct connectdata *conn,
* still waiting, and take initial ownership. * still waiting, and take initial ownership.
*/ */
td->mutex_waiting = CreateMutex(NULL, TRUE, NULL); td->mutex_waiting = CreateMutex(NULL, TRUE, NULL);
if (td->mutex_waiting == NULL) { if(td->mutex_waiting == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
@ -488,7 +488,7 @@ static bool init_resolve_thread (struct connectdata *conn,
* done resolving. Do not signal it. * done resolving. Do not signal it.
*/ */
td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL); td->event_resolved = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_resolved == NULL) { if(td->event_resolved == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
@ -497,7 +497,7 @@ static bool init_resolve_thread (struct connectdata *conn,
* between us and resolver thread. * between us and resolver thread.
*/ */
td->mutex_terminate = CreateMutex(NULL, FALSE, NULL); td->mutex_terminate = CreateMutex(NULL, FALSE, NULL);
if (td->mutex_terminate == NULL) { if(td->mutex_terminate == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
@ -505,7 +505,7 @@ static bool init_resolve_thread (struct connectdata *conn,
/* Create the event used to signal thread that it should terminate. /* Create the event used to signal thread that it should terminate.
*/ */
td->event_terminate = CreateEvent(NULL, TRUE, FALSE, NULL); td->event_terminate = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_terminate == NULL) { if(td->event_terminate == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
@ -513,7 +513,7 @@ static bool init_resolve_thread (struct connectdata *conn,
/* Create the event used by thread to inform it has initialized its own data. /* Create the event used by thread to inform it has initialized its own data.
*/ */
td->event_thread_started = CreateEvent(NULL, TRUE, FALSE, NULL); td->event_thread_started = CreateEvent(NULL, TRUE, FALSE, NULL);
if (td->event_thread_started == NULL) { if(td->event_thread_started == NULL) {
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
SET_ERRNO(EAGAIN); SET_ERRNO(EAGAIN);
return FALSE; return FALSE;
@ -535,7 +535,7 @@ static bool init_resolve_thread (struct connectdata *conn,
(void) hints; (void) hints;
#endif #endif
if (!td->thread_hnd) { if(!td->thread_hnd) {
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
TRACE(("CreateThread() failed; %s\n", Curl_strerror(conn, ERRNO))); TRACE(("CreateThread() failed; %s\n", Curl_strerror(conn, ERRNO)));
#else #else
@ -549,7 +549,7 @@ static bool init_resolve_thread (struct connectdata *conn,
*/ */
thread_and_event[0] = td->thread_hnd; thread_and_event[0] = td->thread_hnd;
thread_and_event[1] = td->event_thread_started; thread_and_event[1] = td->event_thread_started;
if (WaitForMultipleObjects(sizeof(thread_and_event) / if(WaitForMultipleObjects(sizeof(thread_and_event) /
sizeof(thread_and_event[0]), sizeof(thread_and_event[0]),
(const HANDLE*)thread_and_event, FALSE, (const HANDLE*)thread_and_event, FALSE,
INFINITE) == WAIT_FAILED) { INFINITE) == WAIT_FAILED) {
@ -608,9 +608,9 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
td->event_resolved = NULL; td->event_resolved = NULL;
/* has the resolver thread succeeded in resolving our query ? */ /* has the resolver thread succeeded in resolving our query ? */
if (status == WAIT_OBJECT_0) { if(status == WAIT_OBJECT_0) {
/* wait for the thread to exit, it's in the callback sequence */ /* wait for the thread to exit, it's in the callback sequence */
if (WaitForSingleObject(td->thread_hnd, 5000) == WAIT_TIMEOUT) { if(WaitForSingleObject(td->thread_hnd, 5000) == WAIT_TIMEOUT) {
TerminateThread(td->thread_hnd, 0); TerminateThread(td->thread_hnd, 0);
conn->async.done = TRUE; conn->async.done = TRUE;
td->thread_status = (DWORD)-1; td->thread_status = (DWORD)-1;
@ -640,9 +640,9 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
rc = CURLE_OK; rc = CURLE_OK;
if (!conn->async.dns) { if(!conn->async.dns) {
/* a name was not resolved */ /* a name was not resolved */
if (td->thread_status == CURLE_OUT_OF_MEMORY) { if(td->thread_status == CURLE_OUT_OF_MEMORY) {
rc = CURLE_OUT_OF_MEMORY; rc = CURLE_OUT_OF_MEMORY;
failf(data, "Could not resolve host: %s", curl_easy_strerror(rc)); failf(data, "Could not resolve host: %s", curl_easy_strerror(rc));
} }
@ -658,7 +658,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
rc = CURLE_COULDNT_RESOLVE_HOST; rc = CURLE_COULDNT_RESOLVE_HOST;
} }
} }
else if (td->thread_status == (DWORD)-1 || conn->async.status == NO_DATA) { else if(td->thread_status == (DWORD)-1 || conn->async.status == NO_DATA) {
failf(data, "Resolving host timed out: %s", conn->host.name); failf(data, "Resolving host timed out: %s", conn->host.name);
rc = CURLE_OPERATION_TIMEDOUT; rc = CURLE_OPERATION_TIMEDOUT;
} }
@ -684,10 +684,10 @@ CURLcode Curl_is_resolved(struct connectdata *conn,
{ {
*entry = NULL; *entry = NULL;
if (conn->async.done) { if(conn->async.done) {
/* we're done */ /* we're done */
Curl_destroy_thread_data(&conn->async); Curl_destroy_thread_data(&conn->async);
if (!conn->async.dns) { if(!conn->async.dns) {
TRACE(("Curl_is_resolved(): CURLE_COULDNT_RESOLVE_HOST\n")); TRACE(("Curl_is_resolved(): CURLE_COULDNT_RESOLVE_HOST\n"));
return CURLE_COULDNT_RESOLVE_HOST; return CURLE_COULDNT_RESOLVE_HOST;
} }
@ -704,7 +704,7 @@ int Curl_resolv_getsock(struct connectdata *conn,
const struct thread_data *td = const struct thread_data *td =
(const struct thread_data *) conn->async.os_specific; (const struct thread_data *) conn->async.os_specific;
if (td && td->dummy_sock != CURL_SOCKET_BAD) { if(td && td->dummy_sock != CURL_SOCKET_BAD) {
if(numsocks) { if(numsocks) {
/* return one socket waiting for writable, even though this is just /* return one socket waiting for writable, even though this is just
a dummy */ a dummy */
@ -731,12 +731,12 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
*waitp = 0; /* don't wait, we act synchronously */ *waitp = 0; /* don't wait, we act synchronously */
in = inet_addr(hostname); in = inet_addr(hostname);
if (in != CURL_INADDR_NONE) if(in != CURL_INADDR_NONE)
/* This is a dotted IP address 123.123.123.123-style */ /* This is a dotted IP address 123.123.123.123-style */
return Curl_ip2addr(in, hostname, port); return Curl_ip2addr(in, hostname, port);
/* fire up a new resolver thread! */ /* fire up a new resolver thread! */
if (init_resolve_thread(conn, hostname, port, NULL)) { if(init_resolve_thread(conn, hostname, port, NULL)) {
*waitp = TRUE; /* please wait for the response */ *waitp = TRUE; /* please wait for the response */
return NULL; return NULL;
} }
@ -746,7 +746,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
hostname, Curl_strerror(conn, ERRNO)); hostname, Curl_strerror(conn, ERRNO));
h = gethostbyname(hostname); h = gethostbyname(hostname);
if (!h) { if(!h) {
infof(data, "gethostbyname(2) failed for %s:%d; %s\n", infof(data, "gethostbyname(2) failed for %s:%d; %s\n",
hostname, port, Curl_strerror(conn, SOCKERRNO)); hostname, port, Curl_strerror(conn, SOCKERRNO));
return NULL; return NULL;
@ -775,7 +775,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
/* see if we have an IPv6 stack */ /* see if we have an IPv6 stack */
s = socket(PF_INET6, SOCK_DGRAM, 0); s = socket(PF_INET6, SOCK_DGRAM, 0);
if (s == CURL_SOCKET_BAD) { if(s == CURL_SOCKET_BAD) {
/* Some non-IPv6 stacks have been found to make very slow name resolves /* Some non-IPv6 stacks have been found to make very slow name resolves
* when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if * when PF_UNSPEC is used, so thus we switch to a mere PF_INET lookup if
* the stack seems to be a non-ipv6 one. */ * the stack seems to be a non-ipv6 one. */
@ -813,7 +813,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
itoa(port, sbuf, 10); itoa(port, sbuf, 10);
/* fire up a new resolver thread! */ /* fire up a new resolver thread! */
if (init_resolve_thread(conn, hostname, port, &hints)) { if(init_resolve_thread(conn, hostname, port, &hints)) {
*waitp = TRUE; /* please wait for the response */ *waitp = TRUE; /* please wait for the response */
return NULL; return NULL;
} }
@ -823,7 +823,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
hostname, Curl_strerror(conn, ERRNO)); hostname, Curl_strerror(conn, ERRNO));
error = getaddrinfo(hostname, sbuf, &hints, &res); error = getaddrinfo(hostname, sbuf, &hints, &res);
if (error) { if(error) {
infof(data, "getaddrinfo() failed for %s:%d; %s\n", infof(data, "getaddrinfo() failed for %s:%d; %s\n",
hostname, port, Curl_strerror(conn, SOCKERRNO)); hostname, port, Curl_strerror(conn, SOCKERRNO));
return NULL; return NULL;

View File

@ -385,7 +385,7 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
if(pickhost || pickproxy) { if(pickhost || pickproxy) {
data->reqdata.newurl = strdup(data->change.url); /* clone URL */ data->reqdata.newurl = strdup(data->change.url); /* clone URL */
if (!data->reqdata.newurl) if(!data->reqdata.newurl)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
if((data->set.httpreq != HTTPREQ_GET) && if((data->set.httpreq != HTTPREQ_GET) &&
@ -407,12 +407,12 @@ CURLcode Curl_http_auth_act(struct connectdata *conn)
if((data->set.httpreq != HTTPREQ_GET) && if((data->set.httpreq != HTTPREQ_GET) &&
(data->set.httpreq != HTTPREQ_HEAD)) { (data->set.httpreq != HTTPREQ_HEAD)) {
data->reqdata.newurl = strdup(data->change.url); /* clone URL */ data->reqdata.newurl = strdup(data->change.url); /* clone URL */
if (!data->reqdata.newurl) if(!data->reqdata.newurl)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
data->state.authhost.done = TRUE; data->state.authhost.done = TRUE;
} }
} }
if (Curl_http_should_fail(conn)) { if(Curl_http_should_fail(conn)) {
failf (data, "The requested URL returned error: %d", failf (data, "The requested URL returned error: %d",
data->reqdata.keep.httpcode); data->reqdata.keep.httpcode);
code = CURLE_HTTP_RETURNED_ERROR; code = CURLE_HTTP_RETURNED_ERROR;
@ -475,7 +475,7 @@ Curl_http_output_auth(struct connectdata *conn,
authproxy->picked = authproxy->want; authproxy->picked = authproxy->want;
/* Send proxy authentication header if needed */ /* Send proxy authentication header if needed */
if (conn->bits.httpproxy && if(conn->bits.httpproxy &&
(conn->bits.tunnel_proxy == proxytunnel)) { (conn->bits.tunnel_proxy == proxytunnel)) {
#ifdef HAVE_GSSAPI #ifdef HAVE_GSSAPI
if((authproxy->picked == CURLAUTH_GSSNEGOTIATE) && if((authproxy->picked == CURLAUTH_GSSNEGOTIATE) &&
@ -483,7 +483,7 @@ Curl_http_output_auth(struct connectdata *conn,
!GSS_ERROR(data->state.negotiate.status)) { !GSS_ERROR(data->state.negotiate.status)) {
auth="GSS-Negotiate"; auth="GSS-Negotiate";
result = Curl_output_negotiate(conn, TRUE); result = Curl_output_negotiate(conn, TRUE);
if (result) if(result)
return result; return result;
authproxy->done = TRUE; authproxy->done = TRUE;
} }
@ -552,7 +552,7 @@ Curl_http_output_auth(struct connectdata *conn,
!GSS_ERROR(data->state.negotiate.status)) { !GSS_ERROR(data->state.negotiate.status)) {
auth="GSS-Negotiate"; auth="GSS-Negotiate";
result = Curl_output_negotiate(conn, FALSE); result = Curl_output_negotiate(conn, FALSE);
if (result) if(result)
return result; return result;
authhost->done = TRUE; authhost->done = TRUE;
} }
@ -627,7 +627,7 @@ CURLcode Curl_http_input_auth(struct connectdata *conn,
const char *start; const char *start;
struct auth *authp; struct auth *authp;
if (httpcode == 407) { if(httpcode == 407) {
start = header+strlen("Proxy-authenticate:"); start = header+strlen("Proxy-authenticate:");
availp = &data->info.proxyauthavail; availp = &data->info.proxyauthavail;
authp = &data->state.authproxy; authp = &data->state.authproxy;
@ -652,14 +652,14 @@ CURLcode Curl_http_input_auth(struct connectdata *conn,
*/ */
#ifdef HAVE_GSSAPI #ifdef HAVE_GSSAPI
if (checkprefix("GSS-Negotiate", start) || if(checkprefix("GSS-Negotiate", start) ||
checkprefix("Negotiate", start)) { checkprefix("Negotiate", start)) {
*availp |= CURLAUTH_GSSNEGOTIATE; *availp |= CURLAUTH_GSSNEGOTIATE;
authp->avail |= CURLAUTH_GSSNEGOTIATE; authp->avail |= CURLAUTH_GSSNEGOTIATE;
if(authp->picked == CURLAUTH_GSSNEGOTIATE) { if(authp->picked == CURLAUTH_GSSNEGOTIATE) {
/* if exactly this is wanted, go */ /* if exactly this is wanted, go */
int neg = Curl_input_negotiate(conn, (bool)(httpcode == 407), start); int neg = Curl_input_negotiate(conn, (bool)(httpcode == 407), start);
if (neg == 0) { if(neg == 0) {
data->reqdata.newurl = strdup(data->change.url); data->reqdata.newurl = strdup(data->change.url);
data->state.authproblem = (data->reqdata.newurl == NULL); data->state.authproblem = (data->reqdata.newurl == NULL);
} }
@ -758,16 +758,16 @@ int Curl_http_should_fail(struct connectdata *conn)
** If we haven't been asked to fail on error, ** If we haven't been asked to fail on error,
** don't fail. ** don't fail.
*/ */
if (!data->set.http_fail_on_error) if(!data->set.http_fail_on_error)
return 0; return 0;
/* /*
** Any code < 400 is never terminal. ** Any code < 400 is never terminal.
*/ */
if (k->httpcode < 400) if(k->httpcode < 400)
return 0; return 0;
if (data->reqdata.resume_from && if(data->reqdata.resume_from &&
(data->set.httpreq==HTTPREQ_GET) && (data->set.httpreq==HTTPREQ_GET) &&
(k->httpcode == 416)) { (k->httpcode == 416)) {
/* "Requested Range Not Satisfiable", just proceed and /* "Requested Range Not Satisfiable", just proceed and
@ -779,7 +779,7 @@ int Curl_http_should_fail(struct connectdata *conn)
** Any code >= 400 that's not 401 or 407 is always ** Any code >= 400 that's not 401 or 407 is always
** a terminal error ** a terminal error
*/ */
if ((k->httpcode != 401) && if((k->httpcode != 401) &&
(k->httpcode != 407)) (k->httpcode != 407))
return 1; return 1;
@ -986,12 +986,12 @@ CURLcode add_buffer_send(send_buffer *in,
/* this data _may_ contain binary stuff */ /* this data _may_ contain binary stuff */
Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr, Curl_debug(conn->data, CURLINFO_HEADER_OUT, ptr,
(size_t)(amount-included_body_bytes), conn); (size_t)(amount-included_body_bytes), conn);
if (included_body_bytes) if(included_body_bytes)
Curl_debug(conn->data, CURLINFO_DATA_OUT, Curl_debug(conn->data, CURLINFO_DATA_OUT,
ptr+amount-included_body_bytes, ptr+amount-included_body_bytes,
(size_t)included_body_bytes, conn); (size_t)included_body_bytes, conn);
} }
if (included_body_bytes) if(included_body_bytes)
/* since we sent a piece of the body here, up the byte counter for it /* since we sent a piece of the body here, up the byte counter for it
accordingly */ accordingly */
http->writebytecount = included_body_bytes; http->writebytecount = included_body_bytes;
@ -1207,7 +1207,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
conn->bits.proxy_connect_closed = FALSE; conn->bits.proxy_connect_closed = FALSE;
do { do {
if (!conn->bits.tunnel_connecting) { /* BEGIN CONNECT PHASE */ if(!conn->bits.tunnel_connecting) { /* BEGIN CONNECT PHASE */
char *host_port; char *host_port;
send_buffer *req_buffer; send_buffer *req_buffer;
@ -1314,8 +1314,8 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
} }
/* if we're in multi-mode and we would block, return instead for a retry */ /* if we're in multi-mode and we would block, return instead for a retry */
if (Curl_if_multi == data->state.used_interface) { if(Curl_if_multi == data->state.used_interface) {
if (0 == Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD, 0)) if(0 == Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD, 0))
/* return so we'll be called again polling-style */ /* return so we'll be called again polling-style */
return CURLE_OK; return CURLE_OK;
else { else {
@ -1571,7 +1571,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
headers. 'newurl' is set to a new URL if we must loop. */ headers. 'newurl' is set to a new URL if we must loop. */
Curl_http_auth_act(conn); Curl_http_auth_act(conn);
if (closeConnection && data->reqdata.newurl) { if(closeConnection && data->reqdata.newurl) {
/* Connection closed by server. Don't use it anymore */ /* Connection closed by server. Don't use it anymore */
sclose(conn->sock[sockindex]); sclose(conn->sock[sockindex]);
conn->sock[sockindex] = CURL_SOCKET_BAD; conn->sock[sockindex] = CURL_SOCKET_BAD;
@ -1584,7 +1584,7 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
failf(data, "Received HTTP code %d from proxy after CONNECT", failf(data, "Received HTTP code %d from proxy after CONNECT",
k->httpcode); k->httpcode);
if (closeConnection && data->reqdata.newurl) if(closeConnection && data->reqdata.newurl)
conn->bits.proxy_connect_closed = TRUE; conn->bits.proxy_connect_closed = TRUE;
return CURLE_RECV_ERROR; return CURLE_RECV_ERROR;
@ -1634,14 +1634,14 @@ CURLcode Curl_http_connect(struct connectdata *conn, bool *done)
return result; return result;
} }
if (conn->bits.tunnel_connecting) { if(conn->bits.tunnel_connecting) {
/* nothing else to do except wait right now - we're not done here. */ /* nothing else to do except wait right now - we're not done here. */
return CURLE_OK; return CURLE_OK;
} }
if(!data->state.this_is_a_follow) { if(!data->state.this_is_a_follow) {
/* this is not a followed location, get the original host name */ /* this is not a followed location, get the original host name */
if (data->state.first_host) if(data->state.first_host)
/* Free to avoid leaking memory on multiple requests*/ /* Free to avoid leaking memory on multiple requests*/
free(data->state.first_host); free(data->state.first_host);
@ -1692,18 +1692,18 @@ static int Curl_https_getsock(struct connectdata *conn,
curl_socket_t *socks, curl_socket_t *socks,
int numsocks) int numsocks)
{ {
if (conn->protocol & PROT_HTTPS) { if(conn->protocol & PROT_HTTPS) {
struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET]; struct ssl_connect_data *connssl = &conn->ssl[FIRSTSOCKET];
if(!numsocks) if(!numsocks)
return GETSOCK_BLANK; return GETSOCK_BLANK;
if (connssl->connecting_state == ssl_connect_2_writing) { if(connssl->connecting_state == ssl_connect_2_writing) {
/* write mode */ /* write mode */
socks[0] = conn->sock[FIRSTSOCKET]; socks[0] = conn->sock[FIRSTSOCKET];
return GETSOCK_WRITESOCK(0); return GETSOCK_WRITESOCK(0);
} }
else if (connssl->connecting_state == ssl_connect_2_reading) { else if(connssl->connecting_state == ssl_connect_2_reading) {
/* read mode */ /* read mode */
socks[0] = conn->sock[FIRSTSOCKET]; socks[0] = conn->sock[FIRSTSOCKET];
return GETSOCK_READSOCK(0); return GETSOCK_READSOCK(0);
@ -1766,7 +1766,7 @@ CURLcode Curl_http_done(struct connectdata *conn,
conn->fread_func = data->set.fread_func; /* restore */ conn->fread_func = data->set.fread_func; /* restore */
conn->fread_in = data->set.in; /* restore */ conn->fread_in = data->set.in; /* restore */
if (http == NULL) if(http == NULL)
return CURLE_OK; return CURLE_OK;
if(http->send_buffer) { if(http->send_buffer) {
@ -1790,7 +1790,7 @@ CURLcode Curl_http_done(struct connectdata *conn,
else if(HTTPREQ_PUT == data->set.httpreq) else if(HTTPREQ_PUT == data->set.httpreq)
k->bytecount = http->readbytecount + http->writebytecount; k->bytecount = http->readbytecount + http->writebytecount;
if (status != CURLE_OK) if(status != CURLE_OK)
return (status); return (status);
if(!conn->bits.retry && if(!conn->bits.retry &&
@ -1909,7 +1909,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
else else
http = data->reqdata.proto.http; http = data->reqdata.proto.http;
if ( (conn->protocol&(PROT_HTTP|PROT_FTP)) && if( (conn->protocol&(PROT_HTTP|PROT_FTP)) &&
data->set.upload) { data->set.upload) {
httpreq = HTTPREQ_PUT; httpreq = HTTPREQ_PUT;
} }
@ -1990,7 +1990,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
Curl_compareheader(ptr, "Transfer-Encoding:", "chunked"); Curl_compareheader(ptr, "Transfer-Encoding:", "chunked");
} }
else { else {
if (httpreq == HTTPREQ_GET) if(httpreq == HTTPREQ_GET)
conn->bits.upload_chunky = FALSE; conn->bits.upload_chunky = FALSE;
if(conn->bits.upload_chunky) if(conn->bits.upload_chunky)
te = "Transfer-Encoding: chunked\r\n"; te = "Transfer-Encoding: chunked\r\n";
@ -2035,7 +2035,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(((conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTPS)) || if(((conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTPS)) ||
(!(conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTP)) ) (!(conn->protocol&PROT_HTTPS) && (conn->remote_port == PORT_HTTP)) )
/* If (HTTPS on port 443) OR (non-HTTPS on port 80) then don't include /* if(HTTPS on port 443) OR (non-HTTPS on port 80) then don't include
the port number in the host string */ the port number in the host string */
conn->allocptr.host = aprintf("Host: %s%s%s\r\n", conn->allocptr.host = aprintf("Host: %s%s%s\r\n",
conn->bits.ipv6_ip?"[":"", conn->bits.ipv6_ip?"[":"",
@ -2053,7 +2053,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
if (conn->bits.httpproxy && !conn->bits.tunnel_proxy) { if(conn->bits.httpproxy && !conn->bits.tunnel_proxy) {
/* Using a proxy but does not tunnel through it */ /* Using a proxy but does not tunnel through it */
/* The path sent to the proxy is in fact the entire URL. But if the remote /* The path sent to the proxy is in fact the entire URL. But if the remote
@ -2095,9 +2095,9 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
} }
ppath = data->change.url; ppath = data->change.url;
/* when doing ftp, append ;type=<a|i> if not present */ /* when doing ftp, append ;type=<a|i> if not present */
if (checkprefix("ftp://", ppath) || checkprefix("ftps://", ppath)) { if(checkprefix("ftp://", ppath) || checkprefix("ftps://", ppath)) {
char *p = strstr(ppath, ";type="); char *p = strstr(ppath, ";type=");
if (p && p[6] && p[7] == 0) { if(p && p[6] && p[7] == 0) {
switch (toupper((int)((unsigned char)p[6]))) { switch (toupper((int)((unsigned char)p[6]))) {
case 'A': case 'A':
case 'D': case 'D':
@ -2107,7 +2107,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
p = NULL; p = NULL;
} }
} }
if (!p) if(!p)
snprintf(ftp_typecode, sizeof(ftp_typecode), ";type=%c", snprintf(ftp_typecode, sizeof(ftp_typecode), ";type=%c",
data->set.prefer_ascii ? 'a' : 'i'); data->set.prefer_ascii ? 'a' : 'i');
} }

View File

@ -64,13 +64,13 @@ get_gss_name(struct connectdata *conn, bool proxy, gss_name_t *server)
/* IIS uses the <service>@<fqdn> form but uses 'http' as the service name */ /* IIS uses the <service>@<fqdn> form but uses 'http' as the service name */
if (neg_ctx->gss) if(neg_ctx->gss)
service = "KHTTP"; service = "KHTTP";
else else
service = "HTTP"; service = "HTTP";
token.length = strlen(service) + 1 + strlen(proxy ? conn->proxy.name : conn->host.name) + 1; token.length = strlen(service) + 1 + strlen(proxy ? conn->proxy.name : conn->host.name) + 1;
if (token.length + 1 > sizeof(name)) if(token.length + 1 > sizeof(name))
return EMSGSIZE; return EMSGSIZE;
snprintf(name, sizeof(name), "%s@%s", service, proxy ? conn->proxy.name : conn->host.name); snprintf(name, sizeof(name), "%s@%s", service, proxy ? conn->proxy.name : conn->host.name);
@ -102,13 +102,13 @@ log_gss_error(struct connectdata *conn, OM_uint32 error_status, char *prefix)
GSS_C_NO_OID, GSS_C_NO_OID,
&msg_ctx, &msg_ctx,
&status_string); &status_string);
if (sizeof(buf) > len + status_string.length + 1) { if(sizeof(buf) > len + status_string.length + 1) {
snprintf(buf + len, sizeof(buf) - len, snprintf(buf + len, sizeof(buf) - len,
": %s", (char*) status_string.value); ": %s", (char*) status_string.value);
len += status_string.length; len += status_string.length;
} }
gss_release_buffer(&min_stat, &status_string); gss_release_buffer(&min_stat, &status_string);
} while (!GSS_ERROR(maj_stat) && msg_ctx != 0); } while(!GSS_ERROR(maj_stat) && msg_ctx != 0);
infof(conn->data, "%s", buf); infof(conn->data, "%s", buf);
} }
@ -130,15 +130,15 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy, const char *heade
protocol = "GSS-Negotiate"; protocol = "GSS-Negotiate";
gss = TRUE; gss = TRUE;
} }
else if (checkprefix("Negotiate", header)) { else if(checkprefix("Negotiate", header)) {
protocol = "Negotiate"; protocol = "Negotiate";
gss = FALSE; gss = FALSE;
} }
else else
return -1; return -1;
if (neg_ctx->context) { if(neg_ctx->context) {
if (neg_ctx->gss != gss) { if(neg_ctx->gss != gss) {
return -1; return -1;
} }
} }
@ -147,7 +147,7 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy, const char *heade
neg_ctx->gss = gss; neg_ctx->gss = gss;
} }
if (neg_ctx->context && neg_ctx->status == GSS_S_COMPLETE) { if(neg_ctx->context && neg_ctx->status == GSS_S_COMPLETE) {
/* We finished succesfully our part of authentication, but server /* We finished succesfully our part of authentication, but server
* rejected it (since we're again here). Exit with an error since we * rejected it (since we're again here). Exit with an error since we
* can't invent anything better */ * can't invent anything better */
@ -155,7 +155,7 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy, const char *heade
return -1; return -1;
} }
if (neg_ctx->server_name == NULL && if(neg_ctx->server_name == NULL &&
(ret = get_gss_name(conn, proxy, &neg_ctx->server_name))) (ret = get_gss_name(conn, proxy, &neg_ctx->server_name)))
return ret; return ret;
@ -164,14 +164,14 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy, const char *heade
header++; header++;
len = strlen(header); len = strlen(header);
if (len > 0) { if(len > 0) {
int rawlen = Curl_base64_decode(header, (unsigned char **)&input_token.value); int rawlen = Curl_base64_decode(header, (unsigned char **)&input_token.value);
if (rawlen < 0) if(rawlen < 0)
return -1; return -1;
input_token.length = rawlen; input_token.length = rawlen;
#ifdef HAVE_SPNEGO /* Handle SPNEGO */ #ifdef HAVE_SPNEGO /* Handle SPNEGO */
if (checkprefix("Negotiate", header)) { if(checkprefix("Negotiate", header)) {
ASN1_OBJECT * object = NULL; ASN1_OBJECT * object = NULL;
int rc = 1; int rc = 1;
unsigned char * spnegoToken = NULL; unsigned char * spnegoToken = NULL;
@ -180,12 +180,12 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy, const char *heade
size_t mechTokenLength = 0; size_t mechTokenLength = 0;
spnegoToken = malloc(input_token.length); spnegoToken = malloc(input_token.length);
if (input_token.value == NULL) if(input_token.value == NULL)
return ENOMEM; return ENOMEM;
spnegoTokenLength = input_token.length; spnegoTokenLength = input_token.length;
object = OBJ_txt2obj ("1.2.840.113554.1.2.2", 1); object = OBJ_txt2obj ("1.2.840.113554.1.2.2", 1);
if (!parseSpnegoTargetToken(spnegoToken, if(!parseSpnegoTargetToken(spnegoToken,
spnegoTokenLength, spnegoTokenLength,
NULL, NULL,
NULL, NULL,
@ -224,17 +224,17 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy, const char *heade
&output_token, &output_token,
NULL, NULL,
NULL); NULL);
if (input_token.length > 0) if(input_token.length > 0)
gss_release_buffer(&minor_status2, &input_token); gss_release_buffer(&minor_status2, &input_token);
neg_ctx->status = major_status; neg_ctx->status = major_status;
if (GSS_ERROR(major_status)) { if(GSS_ERROR(major_status)) {
/* Curl_cleanup_negotiate(conn->data) ??? */ /* Curl_cleanup_negotiate(conn->data) ??? */
log_gss_error(conn, minor_status, log_gss_error(conn, minor_status,
(char *)"gss_init_sec_context() failed: "); (char *)"gss_init_sec_context() failed: ");
return -1; return -1;
} }
if (output_token.length == 0) { if(output_token.length == 0) {
return -1; return -1;
} }
@ -253,7 +253,7 @@ CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
int len; int len;
#ifdef HAVE_SPNEGO /* Handle SPNEGO */ #ifdef HAVE_SPNEGO /* Handle SPNEGO */
if (checkprefix("Negotiate",neg_ctx->protocol)) { if(checkprefix("Negotiate",neg_ctx->protocol)) {
ASN1_OBJECT * object = NULL; ASN1_OBJECT * object = NULL;
int rc = 1; int rc = 1;
unsigned char * spnegoToken = NULL; unsigned char * spnegoToken = NULL;
@ -262,14 +262,14 @@ CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
size_t responseTokenLength = 0; size_t responseTokenLength = 0;
responseToken = malloc(neg_ctx->output_token.length); responseToken = malloc(neg_ctx->output_token.length);
if ( responseToken == NULL) if( responseToken == NULL)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
memcpy(responseToken, neg_ctx->output_token.value, memcpy(responseToken, neg_ctx->output_token.value,
neg_ctx->output_token.length); neg_ctx->output_token.length);
responseTokenLength = neg_ctx->output_token.length; responseTokenLength = neg_ctx->output_token.length;
object=OBJ_txt2obj ("1.2.840.113554.1.2.2", 1); object=OBJ_txt2obj ("1.2.840.113554.1.2.2", 1);
if (!makeSpnegoInitialToken (object, if(!makeSpnegoInitialToken (object,
responseToken, responseToken,
responseTokenLength, responseTokenLength,
&spnegoToken, &spnegoToken,
@ -295,7 +295,7 @@ CURLcode Curl_output_negotiate(struct connectdata *conn, bool proxy)
neg_ctx->output_token.length, neg_ctx->output_token.length,
&encoded); &encoded);
if (len == 0) if(len == 0)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
conn->allocptr.userpwd = conn->allocptr.userpwd =
@ -310,13 +310,13 @@ void Curl_cleanup_negotiate(struct SessionHandle *data)
OM_uint32 minor_status; OM_uint32 minor_status;
struct negotiatedata *neg_ctx = &data->state.negotiate; struct negotiatedata *neg_ctx = &data->state.negotiate;
if (neg_ctx->context != GSS_C_NO_CONTEXT) if(neg_ctx->context != GSS_C_NO_CONTEXT)
gss_delete_sec_context(&minor_status, &neg_ctx->context, GSS_C_NO_BUFFER); gss_delete_sec_context(&minor_status, &neg_ctx->context, GSS_C_NO_BUFFER);
if (neg_ctx->output_token.length != 0) if(neg_ctx->output_token.length != 0)
gss_release_buffer(&minor_status, &neg_ctx->output_token); gss_release_buffer(&minor_status, &neg_ctx->output_token);
if (neg_ctx->server_name != GSS_C_NO_NAME) if(neg_ctx->server_name != GSS_C_NO_NAME)
gss_release_name(&minor_status, &neg_ctx->server_name); gss_release_name(&minor_status, &neg_ctx->server_name);
memset(neg_ctx, 0, sizeof(*neg_ctx)); memset(neg_ctx, 0, sizeof(*neg_ctx));

View File

@ -198,7 +198,7 @@ static void print_hex(FILE *handle, const char *buf, size_t len)
{ {
const char *p = buf; const char *p = buf;
fprintf(stderr, "0x"); fprintf(stderr, "0x");
while (len-- > 0) while(len-- > 0)
fprintf(stderr, "%02.2x", (unsigned int)*p++); fprintf(stderr, "%02.2x", (unsigned int)*p++);
} }
#else #else
@ -263,7 +263,7 @@ CURLntlm Curl_input_ntlm(struct connectdata *conn,
#ifdef USE_WINDOWS_SSPI #ifdef USE_WINDOWS_SSPI
ntlm->type_2 = malloc(size+1); ntlm->type_2 = malloc(size+1);
if (ntlm->type_2 == NULL) { if(ntlm->type_2 == NULL) {
free(buffer); free(buffer);
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
@ -368,7 +368,7 @@ static void mk_lm_hash(struct SessionHandle *data,
unsigned int i; unsigned int i;
size_t len = strlen(password); size_t len = strlen(password);
if (len > 14) if(len > 14)
len = 14; len = 14;
for (i=0; i<len; i++) for (i=0; i<len; i++)
@ -425,7 +425,7 @@ static CURLcode mk_nt_hash(struct SessionHandle *data,
{ {
size_t len = strlen(password); size_t len = strlen(password);
unsigned char *pw = malloc(len*2); unsigned char *pw = malloc(len*2);
if (!pw) if(!pw)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
utf8_to_unicode_le(pw, password, len); utf8_to_unicode_le(pw, password, len);
@ -465,19 +465,19 @@ static CURLcode mk_nt_hash(struct SessionHandle *data,
static void static void
ntlm_sspi_cleanup(struct ntlmdata *ntlm) ntlm_sspi_cleanup(struct ntlmdata *ntlm)
{ {
if (ntlm->type_2) { if(ntlm->type_2) {
free(ntlm->type_2); free(ntlm->type_2);
ntlm->type_2 = NULL; ntlm->type_2 = NULL;
} }
if (ntlm->has_handles) { if(ntlm->has_handles) {
s_pSecFn->DeleteSecurityContext(&ntlm->c_handle); s_pSecFn->DeleteSecurityContext(&ntlm->c_handle);
s_pSecFn->FreeCredentialsHandle(&ntlm->handle); s_pSecFn->FreeCredentialsHandle(&ntlm->handle);
ntlm->has_handles = 0; ntlm->has_handles = 0;
} }
if (ntlm->p_identity) { if(ntlm->p_identity) {
if (ntlm->identity.User) free(ntlm->identity.User); if(ntlm->identity.User) free(ntlm->identity.User);
if (ntlm->identity.Password) free(ntlm->identity.Password); if(ntlm->identity.Password) free(ntlm->identity.Password);
if (ntlm->identity.Domain) free(ntlm->identity.Domain); if(ntlm->identity.Domain) free(ntlm->identity.Domain);
ntlm->p_identity = NULL; ntlm->p_identity = NULL;
} }
} }
@ -546,7 +546,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
#ifdef USE_WINDOWS_SSPI #ifdef USE_WINDOWS_SSPI
/* If security interface is not yet initialized try to do this */ /* If security interface is not yet initialized try to do this */
if (s_hSecDll == NULL) { if(s_hSecDll == NULL) {
/* Determine Windows version. Security functions are located in /* Determine Windows version. Security functions are located in
* security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP * security.dll on WinNT 4.0 and in secur32.dll on Win9x. Win2K and XP
* contain both these DLLs (security.dll just forwards calls to * contain both these DLLs (security.dll just forwards calls to
@ -555,21 +555,21 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
OSVERSIONINFO osver; OSVERSIONINFO osver;
osver.dwOSVersionInfoSize = sizeof(osver); osver.dwOSVersionInfoSize = sizeof(osver);
GetVersionEx(&osver); GetVersionEx(&osver);
if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT if(osver.dwPlatformId == VER_PLATFORM_WIN32_NT
&& osver.dwMajorVersion == 4) && osver.dwMajorVersion == 4)
s_hSecDll = LoadLibrary("security.dll"); s_hSecDll = LoadLibrary("security.dll");
else else
s_hSecDll = LoadLibrary("secur32.dll"); s_hSecDll = LoadLibrary("secur32.dll");
if (s_hSecDll != NULL) { if(s_hSecDll != NULL) {
INIT_SECURITY_INTERFACE pInitSecurityInterface; INIT_SECURITY_INTERFACE pInitSecurityInterface;
pInitSecurityInterface = pInitSecurityInterface =
(INIT_SECURITY_INTERFACE)GetProcAddress(s_hSecDll, (INIT_SECURITY_INTERFACE)GetProcAddress(s_hSecDll,
"InitSecurityInterfaceA"); "InitSecurityInterfaceA");
if (pInitSecurityInterface != NULL) if(pInitSecurityInterface != NULL)
s_pSecFn = pInitSecurityInterface(); s_pSecFn = pInitSecurityInterface();
} }
} }
if (s_pSecFn == NULL) if(s_pSecFn == NULL)
return CURLE_RECV_ERROR; return CURLE_RECV_ERROR;
#endif #endif
@ -589,10 +589,10 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
ntlm_sspi_cleanup(ntlm); ntlm_sspi_cleanup(ntlm);
user = strchr(userp, '\\'); user = strchr(userp, '\\');
if (!user) if(!user)
user = strchr(userp, '/'); user = strchr(userp, '/');
if (user) { if(user) {
domain = userp; domain = userp;
domlen = user - userp; domlen = user - userp;
user++; user++;
@ -603,19 +603,19 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
domlen = 0; domlen = 0;
} }
if (user && *user) { if(user && *user) {
/* note: initialize all of this before doing the mallocs so that /* note: initialize all of this before doing the mallocs so that
* it can be cleaned up later without leaking memory. * it can be cleaned up later without leaking memory.
*/ */
ntlm->p_identity = &ntlm->identity; ntlm->p_identity = &ntlm->identity;
memset(ntlm->p_identity, 0, sizeof(*ntlm->p_identity)); memset(ntlm->p_identity, 0, sizeof(*ntlm->p_identity));
if ((ntlm->identity.User = (unsigned char *)strdup(user)) == NULL) if((ntlm->identity.User = (unsigned char *)strdup(user)) == NULL)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
ntlm->identity.UserLength = strlen(user); ntlm->identity.UserLength = strlen(user);
if ((ntlm->identity.Password = (unsigned char *)strdup(passwdp)) == NULL) if((ntlm->identity.Password = (unsigned char *)strdup(passwdp)) == NULL)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
ntlm->identity.PasswordLength = strlen(passwdp); ntlm->identity.PasswordLength = strlen(passwdp);
if ((ntlm->identity.Domain = malloc(domlen+1)) == NULL) if((ntlm->identity.Domain = malloc(domlen+1)) == NULL)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
strncpy((char *)ntlm->identity.Domain, domain, domlen); strncpy((char *)ntlm->identity.Domain, domain, domlen);
ntlm->identity.Domain[domlen] = '\0'; ntlm->identity.Domain[domlen] = '\0';
@ -626,7 +626,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
ntlm->p_identity = NULL; ntlm->p_identity = NULL;
} }
if (s_pSecFn->AcquireCredentialsHandle( if(s_pSecFn->AcquireCredentialsHandle(
NULL, (char *)"NTLM", SECPKG_CRED_OUTBOUND, NULL, ntlm->p_identity, NULL, (char *)"NTLM", SECPKG_CRED_OUTBOUND, NULL, ntlm->p_identity,
NULL, NULL, &ntlm->handle, &tsDummy NULL, NULL, &ntlm->handle, &tsDummy
) != SEC_E_OK) { ) != SEC_E_OK) {
@ -650,11 +650,11 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
&ntlm->c_handle, &desc, &ntlm->c_handle, &desc,
&attrs, &tsDummy); &attrs, &tsDummy);
if (status == SEC_I_COMPLETE_AND_CONTINUE || if(status == SEC_I_COMPLETE_AND_CONTINUE ||
status == SEC_I_CONTINUE_NEEDED) { status == SEC_I_CONTINUE_NEEDED) {
s_pSecFn->CompleteAuthToken(&ntlm->c_handle, &desc); s_pSecFn->CompleteAuthToken(&ntlm->c_handle, &desc);
} }
else if (status != SEC_E_OK) { else if(status != SEC_E_OK) {
s_pSecFn->FreeCredentialsHandle(&ntlm->handle); s_pSecFn->FreeCredentialsHandle(&ntlm->handle);
return CURLE_RECV_ERROR; return CURLE_RECV_ERROR;
} }
@ -805,7 +805,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
0, &ntlm->c_handle, &type_3_desc, 0, &ntlm->c_handle, &type_3_desc,
&attrs, &tsDummy); &attrs, &tsDummy);
if (status != SEC_E_OK) if(status != SEC_E_OK)
return CURLE_RECV_ERROR; return CURLE_RECV_ERROR;
size = type_3.cbBuffer; size = type_3.cbBuffer;
@ -827,7 +827,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
if(!user) if(!user)
user = strchr(userp, '/'); user = strchr(userp, '/');
if (user) { if(user) {
domain = userp; domain = userp;
domlen = (user - domain); domlen = (user - domain);
user++; user++;
@ -836,7 +836,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
user = userp; user = userp;
userlen = strlen(user); userlen = strlen(user);
if (gethostname(host, HOSTNAME_MAX)) { if(gethostname(host, HOSTNAME_MAX)) {
infof(conn->data, "gethostname() failed, continuing without!"); infof(conn->data, "gethostname() failed, continuing without!");
hostlen = 0; hostlen = 0;
} }
@ -846,14 +846,14 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
* name, which NTLM doesn't like. * name, which NTLM doesn't like.
*/ */
char *dot = strchr(host, '.'); char *dot = strchr(host, '.');
if (dot) if(dot)
*dot = '\0'; *dot = '\0';
hostlen = strlen(host); hostlen = strlen(host);
} }
#if USE_NTLM2SESSION #if USE_NTLM2SESSION
/* We don't support NTLM2 if we don't have USE_NTRESPONSES */ /* We don't support NTLM2 if we don't have USE_NTRESPONSES */
if (ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) { if(ntlm->flags & NTLMFLAG_NEGOTIATE_NTLM2_KEY) {
unsigned char ntbuffer[0x18]; unsigned char ntbuffer[0x18];
unsigned char tmp[0x18]; unsigned char tmp[0x18];
unsigned char md5sum[MD5_DIGEST_LENGTH]; unsigned char md5sum[MD5_DIGEST_LENGTH];
@ -878,7 +878,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
MD5_Final(md5sum, &MD5pw); MD5_Final(md5sum, &MD5pw);
/* We shall only use the first 8 bytes of md5sum, /* We shall only use the first 8 bytes of md5sum,
but the des code in lm_resp only encrypt the first 8 bytes */ but the des code in lm_resp only encrypt the first 8 bytes */
if (mk_nt_hash(conn->data, passwdp, ntbuffer) == CURLE_OUT_OF_MEMORY) if(mk_nt_hash(conn->data, passwdp, ntbuffer) == CURLE_OUT_OF_MEMORY)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
lm_resp(ntbuffer, md5sum, ntresp); lm_resp(ntbuffer, md5sum, ntresp);
@ -893,7 +893,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
unsigned char lmbuffer[0x18]; unsigned char lmbuffer[0x18];
#if USE_NTRESPONSES #if USE_NTRESPONSES
if (mk_nt_hash(conn->data, passwdp, ntbuffer) == CURLE_OUT_OF_MEMORY) if(mk_nt_hash(conn->data, passwdp, ntbuffer) == CURLE_OUT_OF_MEMORY)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
lm_resp(ntbuffer, &ntlm->nonce[0], ntresp); lm_resp(ntbuffer, &ntlm->nonce[0], ntresp);
#endif #endif
@ -1113,7 +1113,7 @@ Curl_ntlm_cleanup(struct connectdata *conn)
#ifdef USE_WINDOWS_SSPI #ifdef USE_WINDOWS_SSPI
ntlm_sspi_cleanup(&conn->ntlm); ntlm_sspi_cleanup(&conn->ntlm);
ntlm_sspi_cleanup(&conn->proxyntlm); ntlm_sspi_cleanup(&conn->proxyntlm);
if (s_hSecDll != NULL) { if(s_hSecDll != NULL) {
FreeLibrary(s_hSecDll); FreeLibrary(s_hSecDll);
s_hSecDll = NULL; s_hSecDll = NULL;
s_pSecFn = NULL; s_pSecFn = NULL;

View File

@ -111,26 +111,28 @@ inet_pton4(const char *src, unsigned char *dst)
while ((ch = *src++) != '\0') { while ((ch = *src++) != '\0') {
const char *pch; const char *pch;
if ((pch = strchr(digits, ch)) != NULL) { if((pch = strchr(digits, ch)) != NULL) {
unsigned int val = *tp * 10 + (unsigned int)(pch - digits); unsigned int val = *tp * 10 + (unsigned int)(pch - digits);
if (val > 255) if(val > 255)
return (0); return (0);
*tp = (unsigned char)val; *tp = (unsigned char)val;
if (! saw_digit) { if(! saw_digit) {
if (++octets > 4) if(++octets > 4)
return (0); return (0);
saw_digit = 1; saw_digit = 1;
} }
} else if (ch == '.' && saw_digit) { }
if (octets == 4) else if(ch == '.' && saw_digit) {
if(octets == 4)
return (0); return (0);
*++tp = 0; *++tp = 0;
saw_digit = 0; saw_digit = 0;
} else }
else
return (0); return (0);
} }
if (octets < 4) if(octets < 4)
return (0); return (0);
/* bcopy(tmp, dst, INADDRSZ); */ /* bcopy(tmp, dst, INADDRSZ); */
memcpy(dst, tmp, INADDRSZ); memcpy(dst, tmp, INADDRSZ);
@ -165,8 +167,8 @@ inet_pton6(const char *src, unsigned char *dst)
endp = tp + IN6ADDRSZ; endp = tp + IN6ADDRSZ;
colonp = NULL; colonp = NULL;
/* Leading :: requires some special handling. */ /* Leading :: requires some special handling. */
if (*src == ':') if(*src == ':')
if (*++src != ':') if(*++src != ':')
return (0); return (0);
curtok = src; curtok = src;
saw_xdigit = 0; saw_xdigit = 0;
@ -174,25 +176,25 @@ inet_pton6(const char *src, unsigned char *dst)
while ((ch = *src++) != '\0') { while ((ch = *src++) != '\0') {
const char *pch; const char *pch;
if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) if((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
pch = strchr((xdigits = xdigits_u), ch); pch = strchr((xdigits = xdigits_u), ch);
if (pch != NULL) { if(pch != NULL) {
val <<= 4; val <<= 4;
val |= (pch - xdigits); val |= (pch - xdigits);
if (val > 0xffff) if(val > 0xffff)
return (0); return (0);
saw_xdigit = 1; saw_xdigit = 1;
continue; continue;
} }
if (ch == ':') { if(ch == ':') {
curtok = src; curtok = src;
if (!saw_xdigit) { if(!saw_xdigit) {
if (colonp) if(colonp)
return (0); return (0);
colonp = tp; colonp = tp;
continue; continue;
} }
if (tp + INT16SZ > endp) if(tp + INT16SZ > endp)
return (0); return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff; *tp++ = (unsigned char) val & 0xff;
@ -200,7 +202,7 @@ inet_pton6(const char *src, unsigned char *dst)
val = 0; val = 0;
continue; continue;
} }
if (ch == '.' && ((tp + INADDRSZ) <= endp) && if(ch == '.' && ((tp + INADDRSZ) <= endp) &&
inet_pton4(curtok, tp) > 0) { inet_pton4(curtok, tp) > 0) {
tp += INADDRSZ; tp += INADDRSZ;
saw_xdigit = 0; saw_xdigit = 0;
@ -208,13 +210,13 @@ inet_pton6(const char *src, unsigned char *dst)
} }
return (0); return (0);
} }
if (saw_xdigit) { if(saw_xdigit) {
if (tp + INT16SZ > endp) if(tp + INT16SZ > endp)
return (0); return (0);
*tp++ = (unsigned char) (val >> 8) & 0xff; *tp++ = (unsigned char) (val >> 8) & 0xff;
*tp++ = (unsigned char) val & 0xff; *tp++ = (unsigned char) val & 0xff;
} }
if (colonp != NULL) { if(colonp != NULL) {
/* /*
* Since some memmove()'s erroneously fail to handle * Since some memmove()'s erroneously fail to handle
* overlapping regions, we'll do the shift by hand. * overlapping regions, we'll do the shift by hand.
@ -228,7 +230,7 @@ inet_pton6(const char *src, unsigned char *dst)
} }
tp = endp; tp = endp;
} }
if (tp != endp) if(tp != endp)
return (0); return (0);
/* bcopy(tmp, dst, IN6ADDRSZ); */ /* bcopy(tmp, dst, IN6ADDRSZ); */
memcpy(dst, tmp, IN6ADDRSZ); memcpy(dst, tmp, IN6ADDRSZ);

View File

@ -110,7 +110,7 @@ static void _ldap_free_urldesc (LDAPURLDesc *ludp);
#define LDAP_TRACE(x) do { \ #define LDAP_TRACE(x) do { \
_ldap_trace ("%u: ", __LINE__); \ _ldap_trace ("%u: ", __LINE__); \
_ldap_trace x; \ _ldap_trace x; \
} while (0) } while(0)
static void _ldap_trace (const char *fmt, ...); static void _ldap_trace (const char *fmt, ...);
#else #else
@ -191,14 +191,14 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
#else #else
rc = _ldap_url_parse(conn, &ludp); rc = _ldap_url_parse(conn, &ludp);
#endif #endif
if (rc != 0) { if(rc != 0) {
failf(data, "LDAP local: %s", ldap_err2string(rc)); failf(data, "LDAP local: %s", ldap_err2string(rc));
status = CURLE_LDAP_INVALID_URL; status = CURLE_LDAP_INVALID_URL;
goto quit; goto quit;
} }
/* Get the URL scheme ( either ldap or ldaps ) */ /* Get the URL scheme ( either ldap or ldaps ) */
if (strequal(conn->protostr, "LDAPS")) if(strequal(conn->protostr, "LDAPS"))
ldap_ssl = 1; ldap_ssl = 1;
infof(data, "LDAP local: trying to establish %s connection\n", infof(data, "LDAP local: trying to establish %s connection\n",
ldap_ssl ? "encrypted" : "cleartext"); ldap_ssl ? "encrypted" : "cleartext");
@ -208,7 +208,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
#endif #endif
ldap_set_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); ldap_set_option(NULL, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
if (ldap_ssl) { if(ldap_ssl) {
#ifdef HAVE_LDAP_SSL #ifdef HAVE_LDAP_SSL
#ifdef CURL_LDAP_WIN #ifdef CURL_LDAP_WIN
/* Win32 LDAP SDK doesnt support insecure mode without CA! */ /* Win32 LDAP SDK doesnt support insecure mode without CA! */
@ -219,18 +219,18 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
char* ldap_ca = data->set.str[STRING_SSL_CAFILE]; char* ldap_ca = data->set.str[STRING_SSL_CAFILE];
#if defined(CURL_HAS_NOVELL_LDAPSDK) #if defined(CURL_HAS_NOVELL_LDAPSDK)
rc = ldapssl_client_init(NULL, NULL); rc = ldapssl_client_init(NULL, NULL);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ldapssl_client_init %s", ldap_err2string(rc)); failf(data, "LDAP local: ldapssl_client_init %s", ldap_err2string(rc));
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
goto quit; goto quit;
} }
if (data->set.ssl.verifypeer) { if(data->set.ssl.verifypeer) {
/* Novell SDK supports DER or BASE64 files. */ /* Novell SDK supports DER or BASE64 files. */
int cert_type = LDAPSSL_CERT_FILETYPE_B64; int cert_type = LDAPSSL_CERT_FILETYPE_B64;
if ((data->set.str[STRING_CERT_TYPE]) && if((data->set.str[STRING_CERT_TYPE]) &&
(strequal(data->set.str[STRING_CERT_TYPE], "DER"))) (strequal(data->set.str[STRING_CERT_TYPE], "DER")))
cert_type = LDAPSSL_CERT_FILETYPE_DER; cert_type = LDAPSSL_CERT_FILETYPE_DER;
if (!ldap_ca) { if(!ldap_ca) {
failf(data, "LDAP local: ERROR %s CA cert not set!", failf(data, "LDAP local: ERROR %s CA cert not set!",
(cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM")); (cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"));
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
@ -240,7 +240,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
(cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"), (cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"),
ldap_ca); ldap_ca);
rc = ldapssl_add_trusted_cert(ldap_ca, cert_type); rc = ldapssl_add_trusted_cert(ldap_ca, cert_type);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ERROR setting %s CA cert: %s", failf(data, "LDAP local: ERROR setting %s CA cert: %s",
(cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"), (cert_type == LDAPSSL_CERT_FILETYPE_DER ? "DER" : "PEM"),
ldap_err2string(rc)); ldap_err2string(rc));
@ -252,36 +252,36 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
ldap_option = LDAPSSL_VERIFY_NONE; ldap_option = LDAPSSL_VERIFY_NONE;
} }
rc = ldapssl_set_verify_mode(ldap_option); rc = ldapssl_set_verify_mode(ldap_option);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ERROR setting cert verify mode: %s", failf(data, "LDAP local: ERROR setting cert verify mode: %s",
ldap_err2string(rc)); ldap_err2string(rc));
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
goto quit; goto quit;
} }
server = ldapssl_init(conn->host.name, (int)conn->port, 1); server = ldapssl_init(conn->host.name, (int)conn->port, 1);
if (server == NULL) { if(server == NULL) {
failf(data, "LDAP local: Cannot connect to %s:%d", failf(data, "LDAP local: Cannot connect to %s:%d",
conn->host.name, conn->port); conn->host.name, conn->port);
status = CURLE_COULDNT_CONNECT; status = CURLE_COULDNT_CONNECT;
goto quit; goto quit;
} }
#elif defined(LDAP_OPT_X_TLS) #elif defined(LDAP_OPT_X_TLS)
if (data->set.ssl.verifypeer) { if(data->set.ssl.verifypeer) {
/* OpenLDAP SDK supports BASE64 files. */ /* OpenLDAP SDK supports BASE64 files. */
if ((data->set.str[STRING_CERT_TYPE]) && if((data->set.str[STRING_CERT_TYPE]) &&
(!strequal(data->set.str[STRING_CERT_TYPE], "PEM"))) { (!strequal(data->set.str[STRING_CERT_TYPE], "PEM"))) {
failf(data, "LDAP local: ERROR OpenLDAP does only support PEM cert-type!"); failf(data, "LDAP local: ERROR OpenLDAP does only support PEM cert-type!");
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
goto quit; goto quit;
} }
if (!ldap_ca) { if(!ldap_ca) {
failf(data, "LDAP local: ERROR PEM CA cert not set!"); failf(data, "LDAP local: ERROR PEM CA cert not set!");
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
goto quit; goto quit;
} }
infof(data, "LDAP local: using PEM CA cert: %s\n", ldap_ca); infof(data, "LDAP local: using PEM CA cert: %s\n", ldap_ca);
rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, ldap_ca); rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_CACERTFILE, ldap_ca);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ERROR setting PEM CA cert: %s", failf(data, "LDAP local: ERROR setting PEM CA cert: %s",
ldap_err2string(rc)); ldap_err2string(rc));
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
@ -292,14 +292,14 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
ldap_option = LDAP_OPT_X_TLS_NEVER; ldap_option = LDAP_OPT_X_TLS_NEVER;
} }
rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_option); rc = ldap_set_option(NULL, LDAP_OPT_X_TLS_REQUIRE_CERT, &ldap_option);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ERROR setting cert verify mode: %s", failf(data, "LDAP local: ERROR setting cert verify mode: %s",
ldap_err2string(rc)); ldap_err2string(rc));
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
goto quit; goto quit;
} }
server = ldap_init(conn->host.name, (int)conn->port); server = ldap_init(conn->host.name, (int)conn->port);
if (server == NULL) { if(server == NULL) {
failf(data, "LDAP local: Cannot connect to %s:%d", failf(data, "LDAP local: Cannot connect to %s:%d",
conn->host.name, conn->port); conn->host.name, conn->port);
status = CURLE_COULDNT_CONNECT; status = CURLE_COULDNT_CONNECT;
@ -307,7 +307,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
} }
ldap_option = LDAP_OPT_X_TLS_HARD; ldap_option = LDAP_OPT_X_TLS_HARD;
rc = ldap_set_option(server, LDAP_OPT_X_TLS, &ldap_option); rc = ldap_set_option(server, LDAP_OPT_X_TLS, &ldap_option);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ERROR setting SSL/TLS mode: %s", failf(data, "LDAP local: ERROR setting SSL/TLS mode: %s",
ldap_err2string(rc)); ldap_err2string(rc));
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
@ -315,7 +315,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
} }
/* /*
rc = ldap_start_tls_s(server, NULL, NULL); rc = ldap_start_tls_s(server, NULL, NULL);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ERROR starting SSL/TLS mode: %s", failf(data, "LDAP local: ERROR starting SSL/TLS mode: %s",
ldap_err2string(rc)); ldap_err2string(rc));
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
@ -334,7 +334,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
#endif /* CURL_LDAP_USE_SSL */ #endif /* CURL_LDAP_USE_SSL */
} else { } else {
server = ldap_init(conn->host.name, (int)conn->port); server = ldap_init(conn->host.name, (int)conn->port);
if (server == NULL) { if(server == NULL) {
failf(data, "LDAP local: Cannot connect to %s:%d", failf(data, "LDAP local: Cannot connect to %s:%d",
conn->host.name, conn->port); conn->host.name, conn->port);
status = CURLE_COULDNT_CONNECT; status = CURLE_COULDNT_CONNECT;
@ -348,14 +348,14 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
rc = ldap_simple_bind_s(server, rc = ldap_simple_bind_s(server,
conn->bits.user_passwd ? conn->user : NULL, conn->bits.user_passwd ? conn->user : NULL,
conn->bits.user_passwd ? conn->passwd : NULL); conn->bits.user_passwd ? conn->passwd : NULL);
if (!ldap_ssl && rc != 0) { if(!ldap_ssl && rc != 0) {
ldap_proto = LDAP_VERSION2; ldap_proto = LDAP_VERSION2;
ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto); ldap_set_option(server, LDAP_OPT_PROTOCOL_VERSION, &ldap_proto);
rc = ldap_simple_bind_s(server, rc = ldap_simple_bind_s(server,
conn->bits.user_passwd ? conn->user : NULL, conn->bits.user_passwd ? conn->user : NULL,
conn->bits.user_passwd ? conn->passwd : NULL); conn->bits.user_passwd ? conn->passwd : NULL);
} }
if (rc != 0) { if(rc != 0) {
failf(data, "LDAP local: ldap_simple_bind_s %s", ldap_err2string(rc)); failf(data, "LDAP local: ldap_simple_bind_s %s", ldap_err2string(rc));
status = CURLE_LDAP_CANNOT_BIND; status = CURLE_LDAP_CANNOT_BIND;
goto quit; goto quit;
@ -364,7 +364,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
rc = ldap_search_s(server, ludp->lud_dn, ludp->lud_scope, rc = ldap_search_s(server, ludp->lud_dn, ludp->lud_scope,
ludp->lud_filter, ludp->lud_attrs, 0, &result); ludp->lud_filter, ludp->lud_attrs, 0, &result);
if (rc != 0 && rc != LDAP_SIZELIMIT_EXCEEDED) { if(rc != 0 && rc != LDAP_SIZELIMIT_EXCEEDED) {
failf(data, "LDAP remote: %s", ldap_err2string(rc)); failf(data, "LDAP remote: %s", ldap_err2string(rc));
status = CURLE_LDAP_SEARCH_FAILED; status = CURLE_LDAP_SEARCH_FAILED;
goto quit; goto quit;
@ -389,14 +389,14 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
{ {
BerValue **vals = ldap_get_values_len(server, entryIterator, attribute); BerValue **vals = ldap_get_values_len(server, entryIterator, attribute);
if (vals != NULL) if(vals != NULL)
{ {
for (i = 0; (vals[i] != NULL); i++) for (i = 0; (vals[i] != NULL); i++)
{ {
Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\t", 1); Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\t", 1);
Curl_client_write(conn, CLIENTWRITE_BODY, (char *) attribute, 0); Curl_client_write(conn, CLIENTWRITE_BODY, (char *) attribute, 0);
Curl_client_write(conn, CLIENTWRITE_BODY, (char *)": ", 2); Curl_client_write(conn, CLIENTWRITE_BODY, (char *)": ", 2);
if ((strlen(attribute) > 7) && if((strlen(attribute) > 7) &&
(strcmp(";binary", (strcmp(";binary",
(char *)attribute + (char *)attribute +
(strlen((char *)attribute) - 7)) == 0)) { (strlen((char *)attribute) - 7)) == 0)) {
@ -405,7 +405,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
vals[i]->bv_val, vals[i]->bv_val,
vals[i]->bv_len, vals[i]->bv_len,
&val_b64); &val_b64);
if (val_b64_sz > 0) { if(val_b64_sz > 0) {
Curl_client_write(conn, CLIENTWRITE_BODY, val_b64, val_b64_sz); Curl_client_write(conn, CLIENTWRITE_BODY, val_b64, val_b64_sz);
free(val_b64); free(val_b64);
} }
@ -423,23 +423,23 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
ldap_memfree(attribute); ldap_memfree(attribute);
} }
ldap_memfree(dn); ldap_memfree(dn);
if (ber) if(ber)
ber_free(ber, 0); ber_free(ber, 0);
} }
quit: quit:
if (result) { if(result) {
ldap_msgfree(result); ldap_msgfree(result);
LDAP_TRACE (("Received %d entries\n", num)); LDAP_TRACE (("Received %d entries\n", num));
} }
if (rc == LDAP_SIZELIMIT_EXCEEDED) if(rc == LDAP_SIZELIMIT_EXCEEDED)
infof(data, "There are more than %d entries\n", num); infof(data, "There are more than %d entries\n", num);
if (ludp) if(ludp)
ldap_free_urldesc(ludp); ldap_free_urldesc(ludp);
if (server) if(server)
ldap_unbind_s(server); ldap_unbind_s(server);
#if defined(HAVE_LDAP_SSL) && defined(CURL_HAS_NOVELL_LDAPSDK) #if defined(HAVE_LDAP_SSL) && defined(CURL_HAS_NOVELL_LDAPSDK)
if (ldap_ssl) if(ldap_ssl)
ldapssl_client_deinit(); ldapssl_client_deinit();
#endif /* HAVE_LDAP_SSL && CURL_HAS_NOVELL_LDAPSDK */ #endif /* HAVE_LDAP_SSL && CURL_HAS_NOVELL_LDAPSDK */
@ -456,11 +456,11 @@ static void _ldap_trace (const char *fmt, ...)
static int do_trace = -1; static int do_trace = -1;
va_list args; va_list args;
if (do_trace == -1) { if(do_trace == -1) {
const char *env = getenv("CURL_TRACE"); const char *env = getenv("CURL_TRACE");
do_trace = (env && atoi(env) > 0); do_trace = (env && atoi(env) > 0);
} }
if (!do_trace) if(!do_trace)
return; return;
va_start (args, fmt); va_start (args, fmt);
@ -476,15 +476,15 @@ static void _ldap_trace (const char *fmt, ...)
*/ */
static int str2scope (const char *p) static int str2scope (const char *p)
{ {
if (!stricmp(p, "one")) if(!stricmp(p, "one"))
return LDAP_SCOPE_ONELEVEL; return LDAP_SCOPE_ONELEVEL;
if (!stricmp(p, "onetree")) if(!stricmp(p, "onetree"))
return LDAP_SCOPE_ONELEVEL; return LDAP_SCOPE_ONELEVEL;
if (!stricmp(p, "base")) if(!stricmp(p, "base"))
return LDAP_SCOPE_BASE; return LDAP_SCOPE_BASE;
if (!stricmp(p, "sub")) if(!stricmp(p, "sub"))
return LDAP_SCOPE_SUBTREE; return LDAP_SCOPE_SUBTREE;
if (!stricmp( p, "subtree")) if(!stricmp( p, "subtree"))
return LDAP_SCOPE_SUBTREE; return LDAP_SCOPE_SUBTREE;
return (-1); return (-1);
} }
@ -502,7 +502,7 @@ static char **split_str (char *str)
s = strchr(++s,','); s = strchr(++s,',');
res = calloc(i, sizeof(char*)); res = calloc(i, sizeof(char*));
if (!res) if(!res)
return NULL; return NULL;
for (i = 0, s = strtok_r(str, ",", &lasts); s; for (i = 0, s = strtok_r(str, ",", &lasts); s;
@ -518,31 +518,31 @@ static bool unescape_elements (void *data, LDAPURLDesc *ludp)
{ {
int i; int i;
if (ludp->lud_filter) { if(ludp->lud_filter) {
ludp->lud_filter = curl_easy_unescape(data, ludp->lud_filter, 0, NULL); ludp->lud_filter = curl_easy_unescape(data, ludp->lud_filter, 0, NULL);
if (!ludp->lud_filter) if(!ludp->lud_filter)
return (FALSE); return (FALSE);
} }
for (i = 0; ludp->lud_attrs && ludp->lud_attrs[i]; i++) { for (i = 0; ludp->lud_attrs && ludp->lud_attrs[i]; i++) {
ludp->lud_attrs[i] = curl_easy_unescape(data, ludp->lud_attrs[i], 0, NULL); ludp->lud_attrs[i] = curl_easy_unescape(data, ludp->lud_attrs[i], 0, NULL);
if (!ludp->lud_attrs[i]) if(!ludp->lud_attrs[i])
return (FALSE); return (FALSE);
} }
for (i = 0; ludp->lud_exts && ludp->lud_exts[i]; i++) { for (i = 0; ludp->lud_exts && ludp->lud_exts[i]; i++) {
ludp->lud_exts[i] = curl_easy_unescape(data, ludp->lud_exts[i], 0, NULL); ludp->lud_exts[i] = curl_easy_unescape(data, ludp->lud_exts[i], 0, NULL);
if (!ludp->lud_exts[i]) if(!ludp->lud_exts[i])
return (FALSE); return (FALSE);
} }
if (ludp->lud_dn) { if(ludp->lud_dn) {
char *dn = ludp->lud_dn; char *dn = ludp->lud_dn;
char *new_dn = curl_easy_unescape(data, dn, 0, NULL); char *new_dn = curl_easy_unescape(data, dn, 0, NULL);
free(dn); free(dn);
ludp->lud_dn = new_dn; ludp->lud_dn = new_dn;
if (!new_dn) if(!new_dn)
return (FALSE); return (FALSE);
} }
return (TRUE); return (TRUE);
@ -567,7 +567,7 @@ static int _ldap_url_parse2 (const struct connectdata *conn, LDAPURLDesc *ludp)
char *p, *q; char *p, *q;
int i; int i;
if (!conn->data || if(!conn->data ||
!conn->data->reqdata.path || !conn->data->reqdata.path ||
conn->data->reqdata.path[0] != '/' || conn->data->reqdata.path[0] != '/' ||
!checkprefix(conn->protostr, conn->data->change.url)) !checkprefix(conn->protostr, conn->data->change.url))
@ -580,14 +580,14 @@ static int _ldap_url_parse2 (const struct connectdata *conn, LDAPURLDesc *ludp)
/* parse DN (Distinguished Name). /* parse DN (Distinguished Name).
*/ */
ludp->lud_dn = strdup(conn->data->reqdata.path+1); ludp->lud_dn = strdup(conn->data->reqdata.path+1);
if (!ludp->lud_dn) if(!ludp->lud_dn)
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
p = strchr(ludp->lud_dn, '?'); p = strchr(ludp->lud_dn, '?');
LDAP_TRACE (("DN '%.*s'\n", p ? (size_t)(p-ludp->lud_dn) : LDAP_TRACE (("DN '%.*s'\n", p ? (size_t)(p-ludp->lud_dn) :
strlen(ludp->lud_dn), ludp->lud_dn)); strlen(ludp->lud_dn), ludp->lud_dn));
if (!p) if(!p)
goto success; goto success;
*p++ = '\0'; *p++ = '\0';
@ -595,12 +595,12 @@ static int _ldap_url_parse2 (const struct connectdata *conn, LDAPURLDesc *ludp)
/* parse attributes. skip "??". /* parse attributes. skip "??".
*/ */
q = strchr(p, '?'); q = strchr(p, '?');
if (q) if(q)
*q++ = '\0'; *q++ = '\0';
if (*p && *p != '?') { if(*p && *p != '?') {
ludp->lud_attrs = split_str(p); ludp->lud_attrs = split_str(p);
if (!ludp->lud_attrs) if(!ludp->lud_attrs)
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
for (i = 0; ludp->lud_attrs[i]; i++) for (i = 0; ludp->lud_attrs[i]; i++)
@ -608,52 +608,52 @@ static int _ldap_url_parse2 (const struct connectdata *conn, LDAPURLDesc *ludp)
} }
p = q; p = q;
if (!p) if(!p)
goto success; goto success;
/* parse scope. skip "??" /* parse scope. skip "??"
*/ */
q = strchr(p, '?'); q = strchr(p, '?');
if (q) if(q)
*q++ = '\0'; *q++ = '\0';
if (*p && *p != '?') { if(*p && *p != '?') {
ludp->lud_scope = str2scope(p); ludp->lud_scope = str2scope(p);
if (ludp->lud_scope == -1) if(ludp->lud_scope == -1)
return LDAP_INVALID_SYNTAX; return LDAP_INVALID_SYNTAX;
LDAP_TRACE (("scope %d\n", ludp->lud_scope)); LDAP_TRACE (("scope %d\n", ludp->lud_scope));
} }
p = q; p = q;
if (!p) if(!p)
goto success; goto success;
/* parse filter /* parse filter
*/ */
q = strchr(p, '?'); q = strchr(p, '?');
if (q) if(q)
*q++ = '\0'; *q++ = '\0';
if (!*p) if(!*p)
return LDAP_INVALID_SYNTAX; return LDAP_INVALID_SYNTAX;
ludp->lud_filter = p; ludp->lud_filter = p;
LDAP_TRACE (("filter '%s'\n", ludp->lud_filter)); LDAP_TRACE (("filter '%s'\n", ludp->lud_filter));
p = q; p = q;
if (!p) if(!p)
goto success; goto success;
/* parse extensions /* parse extensions
*/ */
ludp->lud_exts = split_str(p); ludp->lud_exts = split_str(p);
if (!ludp->lud_exts) if(!ludp->lud_exts)
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
for (i = 0; ludp->lud_exts[i]; i++) for (i = 0; ludp->lud_exts[i]; i++)
LDAP_TRACE (("exts[%d] '%s'\n", i, ludp->lud_exts[i])); LDAP_TRACE (("exts[%d] '%s'\n", i, ludp->lud_exts[i]));
success: success:
if (!unescape_elements(conn->data, ludp)) if(!unescape_elements(conn->data, ludp))
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
return LDAP_SUCCESS; return LDAP_SUCCESS;
} }
@ -665,11 +665,11 @@ static int _ldap_url_parse (const struct connectdata *conn,
int rc; int rc;
*ludpp = NULL; *ludpp = NULL;
if (!ludp) if(!ludp)
return LDAP_NO_MEMORY; return LDAP_NO_MEMORY;
rc = _ldap_url_parse2 (conn, ludp); rc = _ldap_url_parse2 (conn, ludp);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
_ldap_free_urldesc(ludp); _ldap_free_urldesc(ludp);
ludp = NULL; ludp = NULL;
} }
@ -681,22 +681,22 @@ static void _ldap_free_urldesc (LDAPURLDesc *ludp)
{ {
int i; int i;
if (!ludp) if(!ludp)
return; return;
if (ludp->lud_dn) if(ludp->lud_dn)
free(ludp->lud_dn); free(ludp->lud_dn);
if (ludp->lud_filter) if(ludp->lud_filter)
free(ludp->lud_filter); free(ludp->lud_filter);
if (ludp->lud_attrs) { if(ludp->lud_attrs) {
for (i = 0; ludp->lud_attrs[i]; i++) for (i = 0; ludp->lud_attrs[i]; i++)
free(ludp->lud_attrs[i]); free(ludp->lud_attrs[i]);
free(ludp->lud_attrs); free(ludp->lud_attrs);
} }
if (ludp->lud_exts) { if(ludp->lud_exts) {
for (i = 0; ludp->lud_exts[i]; i++) for (i = 0; ludp->lud_exts[i]; i++)
free(ludp->lud_exts[i]); free(ludp->lud_exts[i]);
free(ludp->lud_exts); free(ludp->lud_exts);

View File

@ -308,9 +308,9 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
long max_param=0; long max_param=0;
long i; long i;
while (*fmt) { while(*fmt) {
if (*fmt++ == '%') { if(*fmt++ == '%') {
if (*fmt == '%') { if(*fmt == '%') {
fmt++; fmt++;
continue; /* while */ continue; /* while */
} }
@ -322,11 +322,11 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
param_num++; param_num++;
this_param = dprintf_DollarString(fmt, &fmt); this_param = dprintf_DollarString(fmt, &fmt);
if (0 == this_param) if(0 == this_param)
/* we got no positional, get the next counter */ /* we got no positional, get the next counter */
this_param = param_num; this_param = param_num;
if (this_param > max_param) if(this_param > max_param)
max_param = this_param; max_param = this_param;
/* /*
@ -340,7 +340,7 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
/* Handle the flags */ /* Handle the flags */
while (dprintf_IsQualifierNoDollar(*fmt)) { while(dprintf_IsQualifierNoDollar(*fmt)) {
switch (*fmt++) { switch (*fmt++) {
case ' ': case ' ':
flags |= FLAGS_SPACE; flags |= FLAGS_SPACE;
@ -357,7 +357,7 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
break; break;
case '.': case '.':
flags |= FLAGS_PREC; flags |= FLAGS_PREC;
if ('*' == *fmt) { if('*' == *fmt) {
/* The precision is picked from a specified parameter */ /* The precision is picked from a specified parameter */
flags |= FLAGS_PRECPARAM; flags |= FLAGS_PRECPARAM;
@ -365,12 +365,12 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
param_num++; param_num++;
i = dprintf_DollarString(fmt, &fmt); i = dprintf_DollarString(fmt, &fmt);
if (i) if(i)
precision = i; precision = i;
else else
precision = param_num; precision = param_num;
if (precision > max_param) if(precision > max_param)
max_param = precision; max_param = precision;
} }
else { else {
@ -382,7 +382,7 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
flags |= FLAGS_SHORT; flags |= FLAGS_SHORT;
break; break;
case 'l': case 'l':
if (flags & FLAGS_LONG) if(flags & FLAGS_LONG)
flags |= FLAGS_LONGLONG; flags |= FLAGS_LONGLONG;
else else
flags |= FLAGS_LONG; flags |= FLAGS_LONG;
@ -410,7 +410,7 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
#endif #endif
break; break;
case '0': case '0':
if (!(flags & FLAGS_LEFT)) if(!(flags & FLAGS_LEFT))
flags |= FLAGS_PAD_NIL; flags |= FLAGS_PAD_NIL;
/* FALLTHROUGH */ /* FALLTHROUGH */
case '1': case '2': case '3': case '4': case '1': case '2': case '3': case '4':
@ -503,7 +503,7 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
vto[i].width = width; vto[i].width = width;
vto[i].precision = precision; vto[i].precision = precision;
if (flags & FLAGS_WIDTHPARAM) { if(flags & FLAGS_WIDTHPARAM) {
/* we have the width specified from a parameter, so we make that /* we have the width specified from a parameter, so we make that
parameter's info setup properly */ parameter's info setup properly */
vto[i].width = width - 1; vto[i].width = width - 1;
@ -513,7 +513,7 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
vto[i].precision = vto[i].width = 0; /* can't use width or precision vto[i].precision = vto[i].width = 0; /* can't use width or precision
of width! */ of width! */
} }
if (flags & FLAGS_PRECPARAM) { if(flags & FLAGS_PRECPARAM) {
/* we have the precision specified from a parameter, so we make that /* we have the precision specified from a parameter, so we make that
parameter's info setup properly */ parameter's info setup properly */
vto[i].precision = precision - 1; vto[i].precision = precision - 1;
@ -533,7 +533,7 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
/* Read the arg list parameters into our data list */ /* Read the arg list parameters into our data list */
for (i=0; i<max_param; i++) { for (i=0; i<max_param; i++) {
if ((i + 1 < max_param) && (vto[i + 1].type == FORMAT_WIDTH)) if((i + 1 < max_param) && (vto[i + 1].type == FORMAT_WIDTH))
{ {
/* Width/precision arguments must be read before the main argument /* Width/precision arguments must be read before the main argument
* they are attached to * they are attached to
@ -620,7 +620,7 @@ static int dprintf_formatf(
created for us */ created for us */
f = (char *)format; f = (char *)format;
while (*f != '\0') { while(*f != '\0') {
/* Format spec modifiers. */ /* Format spec modifiers. */
char alt; char alt;
@ -644,7 +644,7 @@ static int dprintf_formatf(
#endif #endif
long signed_num; long signed_num;
if (*f != '%') { if(*f != '%') {
/* This isn't a format spec, so write everything out until the next one /* This isn't a format spec, so write everything out until the next one
OR end of string is reached. */ OR end of string is reached. */
do { do {
@ -659,7 +659,7 @@ static int dprintf_formatf(
'%' as a conversion specifier, it says "The complete format '%' as a conversion specifier, it says "The complete format
specification shall be `%%'," so we can avoid all the width specification shall be `%%'," so we can avoid all the width
and precision processing. */ and precision processing. */
if (*f == '%') { if(*f == '%') {
++f; ++f;
OUTCHAR('%'); OUTCHAR('%');
continue; continue;
@ -700,12 +700,12 @@ static int dprintf_formatf(
num = p->data.num; num = p->data.num;
if(p->flags & FLAGS_CHAR) { if(p->flags & FLAGS_CHAR) {
/* Character. */ /* Character. */
if (!(p->flags & FLAGS_LEFT)) if(!(p->flags & FLAGS_LEFT))
while (--width > 0) while(--width > 0)
OUTCHAR(' '); OUTCHAR(' ');
OUTCHAR((char) num); OUTCHAR((char) num);
if (p->flags & FLAGS_LEFT) if(p->flags & FLAGS_LEFT)
while (--width > 0) while(--width > 0)
OUTCHAR(' '); OUTCHAR(' ');
break; break;
} }
@ -756,47 +756,47 @@ static int dprintf_formatf(
char *w; char *w;
/* Supply a default precision if none was given. */ /* Supply a default precision if none was given. */
if (prec == -1) if(prec == -1)
prec = 1; prec = 1;
/* Put the number in WORK. */ /* Put the number in WORK. */
w = workend; w = workend;
while (num > 0) { while(num > 0) {
*w-- = digits[num % base]; *w-- = digits[num % base];
num /= base; num /= base;
} }
width -= (long)(workend - w); width -= (long)(workend - w);
prec -= (long)(workend - w); prec -= (long)(workend - w);
if (alt && base == 8 && prec <= 0) { if(alt && base == 8 && prec <= 0) {
*w-- = '0'; *w-- = '0';
--width; --width;
} }
if (prec > 0) { if(prec > 0) {
width -= prec; width -= prec;
while (prec-- > 0) while(prec-- > 0)
*w-- = '0'; *w-- = '0';
} }
if (alt && base == 16) if(alt && base == 16)
width -= 2; width -= 2;
if (is_neg || (p->flags & FLAGS_SHOWSIGN) || (p->flags & FLAGS_SPACE)) if(is_neg || (p->flags & FLAGS_SHOWSIGN) || (p->flags & FLAGS_SPACE))
--width; --width;
if (!(p->flags & FLAGS_LEFT) && !(p->flags & FLAGS_PAD_NIL)) if(!(p->flags & FLAGS_LEFT) && !(p->flags & FLAGS_PAD_NIL))
while (width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
if (is_neg) if(is_neg)
OUTCHAR('-'); OUTCHAR('-');
else if (p->flags & FLAGS_SHOWSIGN) else if(p->flags & FLAGS_SHOWSIGN)
OUTCHAR('+'); OUTCHAR('+');
else if (p->flags & FLAGS_SPACE) else if(p->flags & FLAGS_SPACE)
OUTCHAR(' '); OUTCHAR(' ');
if (alt && base == 16) { if(alt && base == 16) {
OUTCHAR('0'); OUTCHAR('0');
if(p->flags & FLAGS_UPPER) if(p->flags & FLAGS_UPPER)
OUTCHAR('X'); OUTCHAR('X');
@ -804,17 +804,17 @@ static int dprintf_formatf(
OUTCHAR('x'); OUTCHAR('x');
} }
if (!(p->flags & FLAGS_LEFT) && (p->flags & FLAGS_PAD_NIL)) if(!(p->flags & FLAGS_LEFT) && (p->flags & FLAGS_PAD_NIL))
while (width-- > 0) while(width-- > 0)
OUTCHAR('0'); OUTCHAR('0');
/* Write the number. */ /* Write the number. */
while (++w <= workend) { while(++w <= workend) {
OUTCHAR(*w); OUTCHAR(*w);
} }
if (p->flags & FLAGS_LEFT) if(p->flags & FLAGS_LEFT)
while (width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
} }
break; break;
@ -827,9 +827,9 @@ static int dprintf_formatf(
size_t len; size_t len;
str = (char *) p->data.str; str = (char *) p->data.str;
if ( str == NULL) { if( str == NULL) {
/* Write null[] if there's space. */ /* Write null[] if there's space. */
if (prec == -1 || prec >= (long) sizeof(null) - 1) { if(prec == -1 || prec >= (long) sizeof(null) - 1) {
str = null; str = null;
len = sizeof(null) - 1; len = sizeof(null) - 1;
/* Disable quotes around (nil) */ /* Disable quotes around (nil) */
@ -843,24 +843,24 @@ static int dprintf_formatf(
else else
len = strlen(str); len = strlen(str);
if (prec != -1 && (size_t) prec < len) if(prec != -1 && (size_t) prec < len)
len = prec; len = prec;
width -= (long)len; width -= (long)len;
if (p->flags & FLAGS_ALT) if(p->flags & FLAGS_ALT)
OUTCHAR('"'); OUTCHAR('"');
if (!(p->flags&FLAGS_LEFT)) if(!(p->flags&FLAGS_LEFT))
while (width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
while (len-- > 0) while(len-- > 0)
OUTCHAR(*str++); OUTCHAR(*str++);
if (p->flags&FLAGS_LEFT) if(p->flags&FLAGS_LEFT)
while (width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
if (p->flags & FLAGS_ALT) if(p->flags & FLAGS_ALT)
OUTCHAR('"'); OUTCHAR('"');
} }
break; break;
@ -870,7 +870,7 @@ static int dprintf_formatf(
{ {
void *ptr; void *ptr;
ptr = (void *) p->data.ptr; ptr = (void *) p->data.ptr;
if (ptr != NULL) { if(ptr != NULL) {
/* If the pointer is not NULL, write it as a %#x spec. */ /* If the pointer is not NULL, write it as a %#x spec. */
base = 16; base = 16;
digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits; digits = (p->flags & FLAGS_UPPER)? upper_digits : lower_digits;
@ -885,13 +885,13 @@ static int dprintf_formatf(
const char *point; const char *point;
width -= sizeof(strnil) - 1; width -= sizeof(strnil) - 1;
if (p->flags & FLAGS_LEFT) if(p->flags & FLAGS_LEFT)
while (width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
for (point = strnil; *point != '\0'; ++point) for (point = strnil; *point != '\0'; ++point)
OUTCHAR(*point); OUTCHAR(*point);
if (! (p->flags & FLAGS_LEFT)) if(! (p->flags & FLAGS_LEFT))
while (width-- > 0) while(width-- > 0)
OUTCHAR(' '); OUTCHAR(' ');
} }
} }
@ -905,24 +905,24 @@ static int dprintf_formatf(
int len; int len;
width = -1; width = -1;
if (p->flags & FLAGS_WIDTH) if(p->flags & FLAGS_WIDTH)
width = p->width; width = p->width;
else if (p->flags & FLAGS_WIDTHPARAM) else if(p->flags & FLAGS_WIDTHPARAM)
width = vto[p->width].data.num; width = vto[p->width].data.num;
prec = -1; prec = -1;
if (p->flags & FLAGS_PREC) if(p->flags & FLAGS_PREC)
prec = p->precision; prec = p->precision;
else if (p->flags & FLAGS_PRECPARAM) else if(p->flags & FLAGS_PRECPARAM)
prec = vto[p->precision].data.num; prec = vto[p->precision].data.num;
if (p->flags & FLAGS_LEFT) if(p->flags & FLAGS_LEFT)
strcat(formatbuf, "-"); strcat(formatbuf, "-");
if (p->flags & FLAGS_SHOWSIGN) if(p->flags & FLAGS_SHOWSIGN)
strcat(formatbuf, "+"); strcat(formatbuf, "+");
if (p->flags & FLAGS_SPACE) if(p->flags & FLAGS_SPACE)
strcat(formatbuf, " "); strcat(formatbuf, " ");
if (p->flags & FLAGS_ALT) if(p->flags & FLAGS_ALT)
strcat(formatbuf, "#"); strcat(formatbuf, "#");
fptr=&formatbuf[strlen(formatbuf)]; fptr=&formatbuf[strlen(formatbuf)];
@ -939,12 +939,12 @@ static int dprintf_formatf(
fptr += len; fptr += len;
left -= len; left -= len;
} }
if (p->flags & FLAGS_LONG) if(p->flags & FLAGS_LONG)
*fptr++ = 'l'; *fptr++ = 'l';
if (p->flags & FLAGS_FLOATE) if(p->flags & FLAGS_FLOATE)
*fptr++ = (char)((p->flags & FLAGS_UPPER) ? 'E':'e'); *fptr++ = (char)((p->flags & FLAGS_UPPER) ? 'E':'e');
else if (p->flags & FLAGS_FLOATG) else if(p->flags & FLAGS_FLOATG)
*fptr++ = (char)((p->flags & FLAGS_UPPER) ? 'G' : 'g'); *fptr++ = (char)((p->flags & FLAGS_UPPER) ? 'G' : 'g');
else else
*fptr++ = 'f'; *fptr++ = 'f';
@ -963,13 +963,13 @@ static int dprintf_formatf(
case FORMAT_INTPTR: case FORMAT_INTPTR:
/* Answer the count of characters written. */ /* Answer the count of characters written. */
#ifdef ENABLE_64BIT #ifdef ENABLE_64BIT
if (p->flags & FLAGS_LONGLONG) if(p->flags & FLAGS_LONGLONG)
*(LONG_LONG *) p->data.ptr = (LONG_LONG)done; *(LONG_LONG *) p->data.ptr = (LONG_LONG)done;
else else
#endif #endif
if (p->flags & FLAGS_LONG) if(p->flags & FLAGS_LONG)
*(long *) p->data.ptr = (long)done; *(long *) p->data.ptr = (long)done;
else if (!(p->flags & FLAGS_SHORT)) else if(!(p->flags & FLAGS_SHORT))
*(int *) p->data.ptr = (int)done; *(int *) p->data.ptr = (int)done;
else else
*(short *) p->data.ptr = (short)done; *(short *) p->data.ptr = (short)done;

View File

@ -446,14 +446,14 @@ CURLMcode curl_multi_add_handle(CURLM *multi_handle,
/* for multi interface connections, we share DNS cache automatically if the /* for multi interface connections, we share DNS cache automatically if the
easy handle's one is currently private. */ easy handle's one is currently private. */
if (easy->easy_handle->dns.hostcache && if(easy->easy_handle->dns.hostcache &&
(easy->easy_handle->dns.hostcachetype == HCACHE_PRIVATE)) { (easy->easy_handle->dns.hostcachetype == HCACHE_PRIVATE)) {
Curl_hash_destroy(easy->easy_handle->dns.hostcache); Curl_hash_destroy(easy->easy_handle->dns.hostcache);
easy->easy_handle->dns.hostcache = NULL; easy->easy_handle->dns.hostcache = NULL;
easy->easy_handle->dns.hostcachetype = HCACHE_NONE; easy->easy_handle->dns.hostcachetype = HCACHE_NONE;
} }
if (!easy->easy_handle->dns.hostcache || if(!easy->easy_handle->dns.hostcache ||
(easy->easy_handle->dns.hostcachetype == HCACHE_NONE)) { (easy->easy_handle->dns.hostcachetype == HCACHE_NONE)) {
easy->easy_handle->dns.hostcache = multi->hostcache; easy->easy_handle->dns.hostcache = multi->hostcache;
easy->easy_handle->dns.hostcachetype = HCACHE_MULTI; easy->easy_handle->dns.hostcachetype = HCACHE_MULTI;
@ -578,7 +578,7 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
alive connections when this is removed */ alive connections when this is removed */
multi->num_alive--; multi->num_alive--;
if (easy->easy_handle->state.is_in_pipeline && if(easy->easy_handle->state.is_in_pipeline &&
easy->state > CURLM_STATE_DO && easy->state > CURLM_STATE_DO &&
easy->state < CURLM_STATE_COMPLETED) { easy->state < CURLM_STATE_COMPLETED) {
/* If the handle is in a pipeline and has finished sending off its /* If the handle is in a pipeline and has finished sending off its
@ -679,7 +679,7 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
/* NOTE NOTE NOTE /* NOTE NOTE NOTE
We do not touch the easy handle here! */ We do not touch the easy handle here! */
if (easy->msg) if(easy->msg)
free(easy->msg); free(easy->msg);
free(easy); free(easy);
@ -701,7 +701,7 @@ void Curl_multi_handlePipeBreak(struct SessionHandle *data)
{ {
struct Curl_one_easy *one_easy = data->set.one_easy; struct Curl_one_easy *one_easy = data->set.one_easy;
if (one_easy) if(one_easy)
one_easy->easy_conn = NULL; one_easy->easy_conn = NULL;
} }
@ -745,12 +745,12 @@ static int multi_getsock(struct Curl_one_easy *easy,
singlesocket() => multi_getsock(). singlesocket() => multi_getsock().
*/ */
if (easy->easy_handle->state.pipe_broke || if(easy->easy_handle->state.pipe_broke ||
!easy->easy_conn) { !easy->easy_conn) {
return 0; return 0;
} }
if (easy->state > CURLM_STATE_CONNECT && if(easy->state > CURLM_STATE_CONNECT &&
easy->state < CURLM_STATE_COMPLETED) { easy->state < CURLM_STATE_COMPLETED) {
/* Set up ownership correctly */ /* Set up ownership correctly */
easy->easy_conn->data = easy->easy_handle; easy->easy_conn->data = easy->easy_handle;
@ -855,7 +855,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
/* Handle the case when the pipe breaks, i.e., the connection /* Handle the case when the pipe breaks, i.e., the connection
we're using gets cleaned up and we're left with nothing. */ we're using gets cleaned up and we're left with nothing. */
if (easy->easy_handle->state.pipe_broke) { if(easy->easy_handle->state.pipe_broke) {
infof(easy->easy_handle, "Pipe broke: handle 0x%x, url = %s\n", infof(easy->easy_handle, "Pipe broke: handle 0x%x, url = %s\n",
easy, easy->easy_handle->reqdata.path); easy, easy->easy_handle->reqdata.path);
@ -875,13 +875,13 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
break; break;
} }
if (easy->state > CURLM_STATE_CONNECT && if(easy->state > CURLM_STATE_CONNECT &&
easy->state < CURLM_STATE_COMPLETED) { easy->state < CURLM_STATE_COMPLETED) {
/* Make sure we set the connection's current owner */ /* Make sure we set the connection's current owner */
easy->easy_conn->data = easy->easy_handle; easy->easy_conn->data = easy->easy_handle;
} }
if (CURLM_STATE_WAITCONNECT <= easy->state && if(CURLM_STATE_WAITCONNECT <= easy->state &&
easy->state <= CURLM_STATE_DO && easy->state <= CURLM_STATE_DO &&
easy->easy_handle->change.url_changed) { easy->easy_handle->change.url_changed) {
char *gotourl; char *gotourl;
@ -949,7 +949,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
multistate(easy, CURLM_STATE_WAITDO); multistate(easy, CURLM_STATE_WAITDO);
else { else {
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
if (easy->easy_conn->bits.tunnel_connecting) if(easy->easy_conn->bits.tunnel_connecting)
multistate(easy, CURLM_STATE_WAITPROXYCONNECT); multistate(easy, CURLM_STATE_WAITPROXYCONNECT);
else else
#endif #endif
@ -985,7 +985,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
multistate(easy, CURLM_STATE_WAITDO); multistate(easy, CURLM_STATE_WAITDO);
else { else {
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
if (easy->easy_conn->bits.tunnel_connecting) if(easy->easy_conn->bits.tunnel_connecting)
multistate(easy, CURLM_STATE_WAITPROXYCONNECT); multistate(easy, CURLM_STATE_WAITPROXYCONNECT);
else else
#endif #endif
@ -1008,7 +1008,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
easy->result = Curl_http_connect(easy->easy_conn, &protocol_connect); easy->result = Curl_http_connect(easy->easy_conn, &protocol_connect);
if(CURLE_OK == easy->result) { if(CURLE_OK == easy->result) {
if (!easy->easy_conn->bits.tunnel_connecting) if(!easy->easy_conn->bits.tunnel_connecting)
multistate(easy, CURLM_STATE_WAITCONNECT); multistate(easy, CURLM_STATE_WAITCONNECT);
} }
break; break;
@ -1038,7 +1038,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
BUT if we are using a proxy we must change to WAITPROXYCONNECT BUT if we are using a proxy we must change to WAITPROXYCONNECT
*/ */
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
if (easy->easy_conn->bits.tunnel_connecting) if(easy->easy_conn->bits.tunnel_connecting)
multistate(easy, CURLM_STATE_WAITPROXYCONNECT); multistate(easy, CURLM_STATE_WAITPROXYCONNECT);
else else
#endif #endif
@ -1080,7 +1080,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
Curl_isHandleAtHead(easy->easy_handle, Curl_isHandleAtHead(easy->easy_handle,
easy->easy_conn->send_pipe)); easy->easy_conn->send_pipe));
#endif #endif
if (!easy->easy_conn->writechannel_inuse && if(!easy->easy_conn->writechannel_inuse &&
Curl_isHandleAtHead(easy->easy_handle, Curl_isHandleAtHead(easy->easy_handle,
easy->easy_conn->send_pipe)) { easy->easy_conn->send_pipe)) {
/* Grab the channel */ /* Grab the channel */
@ -1222,7 +1222,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
easy->easy_conn->recv_pipe)); easy->easy_conn->recv_pipe));
#endif #endif
/* Wait for our turn to PERFORM */ /* Wait for our turn to PERFORM */
if (!easy->easy_conn->readchannel_inuse && if(!easy->easy_conn->readchannel_inuse &&
Curl_isHandleAtHead(easy->easy_handle, Curl_isHandleAtHead(easy->easy_handle,
easy->easy_conn->recv_pipe)) { easy->easy_conn->recv_pipe)) {
/* Grab the channel */ /* Grab the channel */
@ -1235,7 +1235,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
case CURLM_STATE_TOOFAST: /* limit-rate exceeded in either direction */ case CURLM_STATE_TOOFAST: /* limit-rate exceeded in either direction */
/* if both rates are within spec, resume transfer */ /* if both rates are within spec, resume transfer */
Curl_pgrsUpdate(easy->easy_conn); Curl_pgrsUpdate(easy->easy_conn);
if ( ( ( easy->easy_handle->set.max_send_speed == 0 ) || if( ( ( easy->easy_handle->set.max_send_speed == 0 ) ||
( easy->easy_handle->progress.ulspeed < ( easy->easy_handle->progress.ulspeed <
easy->easy_handle->set.max_send_speed ) ) && easy->easy_handle->set.max_send_speed ) ) &&
( ( easy->easy_handle->set.max_recv_speed == 0 ) || ( ( easy->easy_handle->set.max_recv_speed == 0 ) ||
@ -1247,7 +1247,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
case CURLM_STATE_PERFORM: case CURLM_STATE_PERFORM:
/* check if over speed */ /* check if over speed */
if ( ( ( easy->easy_handle->set.max_send_speed > 0 ) && if( ( ( easy->easy_handle->set.max_send_speed > 0 ) &&
( easy->easy_handle->progress.ulspeed > ( easy->easy_handle->progress.ulspeed >
easy->easy_handle->set.max_send_speed ) ) || easy->easy_handle->set.max_send_speed ) ) ||
( ( easy->easy_handle->set.max_recv_speed > 0 ) && ( ( easy->easy_handle->set.max_recv_speed > 0 ) &&
@ -1266,12 +1266,12 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
k = &easy->easy_handle->reqdata.keep; k = &easy->easy_handle->reqdata.keep;
if (!(k->keepon & KEEP_READ)) { if(!(k->keepon & KEEP_READ)) {
/* We're done reading */ /* We're done reading */
easy->easy_conn->readchannel_inuse = FALSE; easy->easy_conn->readchannel_inuse = FALSE;
} }
if (!(k->keepon & KEEP_WRITE)) { if(!(k->keepon & KEEP_WRITE)) {
/* We're done writing */ /* We're done writing */
easy->easy_conn->writechannel_inuse = FALSE; easy->easy_conn->writechannel_inuse = FALSE;
} }
@ -1337,14 +1337,14 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
easy->easy_conn->recv_pipe); easy->easy_conn->recv_pipe);
easy->easy_handle->state.is_in_pipeline = FALSE; easy->easy_handle->state.is_in_pipeline = FALSE;
if (easy->easy_conn->bits.stream_was_rewound) { if(easy->easy_conn->bits.stream_was_rewound) {
/* This request read past its response boundary so we quickly /* This request read past its response boundary so we quickly
let the other requests consume those bytes since there is no let the other requests consume those bytes since there is no
guarantee that the socket will become active again */ guarantee that the socket will become active again */
result = CURLM_CALL_MULTI_PERFORM; result = CURLM_CALL_MULTI_PERFORM;
} }
if (!easy->easy_handle->state.cancelled) { if(!easy->easy_handle->state.cancelled) {
/* post-transfer command */ /* post-transfer command */
easy->result = Curl_done(&easy->easy_conn, CURLE_OK, FALSE); easy->result = Curl_done(&easy->easy_conn, CURLE_OK, FALSE);
@ -1356,7 +1356,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
break; break;
case CURLM_STATE_COMPLETED: case CURLM_STATE_COMPLETED:
if (easy->easy_handle->state.cancelled) if(easy->easy_handle->state.cancelled)
/* Go into the CANCELLED state if we were cancelled */ /* Go into the CANCELLED state if we were cancelled */
multistate(easy, CURLM_STATE_CANCELLED); multistate(easy, CURLM_STATE_CANCELLED);
@ -1404,7 +1404,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
easy->easy_conn->recv_pipe); easy->easy_conn->recv_pipe);
} }
if (disconnect_conn) { if(disconnect_conn) {
Curl_disconnect(easy->easy_conn); /* disconnect properly */ Curl_disconnect(easy->easy_conn); /* disconnect properly */
/* This is where we make sure that the easy_conn pointer is reset. /* This is where we make sure that the easy_conn pointer is reset.
@ -1417,9 +1417,9 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
} }
} }
} while (easy->easy_handle->change.url_changed); } while(easy->easy_handle->change.url_changed);
if ((CURLM_STATE_COMPLETED == easy->state) && !easy->msg) { if((CURLM_STATE_COMPLETED == easy->state) && !easy->msg) {
if(easy->easy_handle->dns.hostcachetype == HCACHE_MULTI) { if(easy->easy_handle->dns.hostcachetype == HCACHE_MULTI) {
/* clear out the usage of the shared DNS cache */ /* clear out the usage of the shared DNS cache */
easy->easy_handle->dns.hostcache = NULL; easy->easy_handle->dns.hostcache = NULL;
@ -1472,7 +1472,7 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
while(easy != &multi->easy) { while(easy != &multi->easy) {
CURLMcode result; CURLMcode result;
if (easy->easy_handle->state.cancelled && if(easy->easy_handle->state.cancelled &&
easy->state == CURLM_STATE_CANCELLED) { easy->state == CURLM_STATE_CANCELLED) {
/* Remove cancelled handles once it's safe to do so */ /* Remove cancelled handles once it's safe to do so */
Curl_multi_rmeasy(multi_handle, easy->easy_handle); Curl_multi_rmeasy(multi_handle, easy->easy_handle);
@ -1498,7 +1498,7 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
int key = now.tv_sec; /* drop the usec part */ int key = now.tv_sec; /* drop the usec part */
multi->timetree = Curl_splaygetbest(key, multi->timetree, &t); multi->timetree = Curl_splaygetbest(key, multi->timetree, &t);
if (t) { if(t) {
struct SessionHandle *d = t->payload; struct SessionHandle *d = t->payload;
struct timeval* tv = &d->state.expiretime; struct timeval* tv = &d->state.expiretime;
@ -1512,7 +1512,7 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
*running_handles = multi->num_alive; *running_handles = multi->num_alive;
if ( CURLM_OK >= returncode ) if( CURLM_OK >= returncode )
update_timer(multi); update_timer(multi);
return returncode; return returncode;
} }
@ -1578,7 +1578,7 @@ CURLMcode curl_multi_cleanup(CURLM *multi_handle)
Curl_easy_addmulti(easy->easy_handle, NULL); /* clear the association */ Curl_easy_addmulti(easy->easy_handle, NULL); /* clear the association */
if (easy->msg) if(easy->msg)
free(easy->msg); free(easy->msg);
free(easy); free(easy);
easy = nexteasy; easy = nexteasy;
@ -1753,7 +1753,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
/* or should we fall-through and do the timer-based stuff? */ /* or should we fall-through and do the timer-based stuff? */
return result; return result;
} }
else if (s != CURL_SOCKET_TIMEOUT) { else if(s != CURL_SOCKET_TIMEOUT) {
struct Curl_sh_entry *entry = struct Curl_sh_entry *entry =
Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s)); Curl_hash_pick(multi->sockhash, (char *)&s, sizeof(s));
@ -1768,12 +1768,12 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
/* bad bad bad bad bad bad bad */ /* bad bad bad bad bad bad bad */
return CURLM_INTERNAL_ERROR; return CURLM_INTERNAL_ERROR;
if (data->set.one_easy->easy_conn) /* set socket event bitmask */ if(data->set.one_easy->easy_conn) /* set socket event bitmask */
data->set.one_easy->easy_conn->cselect_bits = ev_bitmask; data->set.one_easy->easy_conn->cselect_bits = ev_bitmask;
result = multi_runsingle(multi, data->set.one_easy); result = multi_runsingle(multi, data->set.one_easy);
if (data->set.one_easy->easy_conn) if(data->set.one_easy->easy_conn)
data->set.one_easy->easy_conn->cselect_bits = 0; data->set.one_easy->easy_conn->cselect_bits = 0;
if(CURLM_OK >= result) if(CURLM_OK >= result)
@ -1878,7 +1878,7 @@ CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s,
{ {
CURLMcode result = multi_socket((struct Curl_multi *)multi_handle, FALSE, s, CURLMcode result = multi_socket((struct Curl_multi *)multi_handle, FALSE, s,
0, running_handles); 0, running_handles);
if (CURLM_OK >= result) if(CURLM_OK >= result)
update_timer((struct Curl_multi *)multi_handle); update_timer((struct Curl_multi *)multi_handle);
return result; return result;
} }
@ -1888,7 +1888,7 @@ CURLMcode curl_multi_socket_action(CURLM *multi_handle, curl_socket_t s,
{ {
CURLMcode result = multi_socket((struct Curl_multi *)multi_handle, FALSE, s, CURLMcode result = multi_socket((struct Curl_multi *)multi_handle, FALSE, s,
ev_bitmask, running_handles); ev_bitmask, running_handles);
if (CURLM_OK >= result) if(CURLM_OK >= result)
update_timer((struct Curl_multi *)multi_handle); update_timer((struct Curl_multi *)multi_handle);
return result; return result;
} }
@ -1898,7 +1898,7 @@ CURLMcode curl_multi_socket_all(CURLM *multi_handle, int *running_handles)
{ {
CURLMcode result = multi_socket((struct Curl_multi *)multi_handle, CURLMcode result = multi_socket((struct Curl_multi *)multi_handle,
TRUE, CURL_SOCKET_BAD, 0, running_handles); TRUE, CURL_SOCKET_BAD, 0, running_handles);
if (CURLM_OK >= result) if(CURLM_OK >= result)
update_timer((struct Curl_multi *)multi_handle); update_timer((struct Curl_multi *)multi_handle);
return result; return result;
} }
@ -1945,11 +1945,11 @@ CURLMcode curl_multi_timeout(CURLM *multi_handle,
static int update_timer(struct Curl_multi *multi) static int update_timer(struct Curl_multi *multi)
{ {
long timeout_ms; long timeout_ms;
if (!multi->timer_cb) if(!multi->timer_cb)
return 0; return 0;
if ( multi_timeout(multi, &timeout_ms) != CURLM_OK ) if( multi_timeout(multi, &timeout_ms) != CURLM_OK )
return -1; return -1;
if ( timeout_ms < 0 ) if( timeout_ms < 0 )
return 0; return 0;
/* When multi_timeout() is done, multi->timetree points to the node with the /* When multi_timeout() is done, multi->timetree points to the node with the

View File

@ -283,7 +283,7 @@ nss_load_cert(const char *filename, PRBool cacert)
} }
else { else {
/* A nickname from the NSS internal database */ /* A nickname from the NSS internal database */
if (cacert) if(cacert)
return 0; /* You can't specify an NSS CA nickname this way */ return 0; /* You can't specify an NSS CA nickname this way */
nickname = strdup(filename); nickname = strdup(filename);
goto done; goto done;
@ -296,7 +296,7 @@ nss_load_cert(const char *filename, PRBool cacert)
* for storing certificates. With each new user certificate we increment * for storing certificates. With each new user certificate we increment
* the slot count. We only support 1 user certificate right now. * the slot count. We only support 1 user certificate right now.
*/ */
if (cacert) if(cacert)
slotID = 0; slotID = 0;
else else
slotID = 1; slotID = 1;
@ -308,7 +308,7 @@ nss_load_cert(const char *filename, PRBool cacert)
slot = PK11_FindSlotByName(slotname); slot = PK11_FindSlotByName(slotname);
if (!slot) { if(!slot) {
free(slotname); free(slotname);
free(nickname); free(nickname);
return 0; return 0;
@ -318,7 +318,7 @@ nss_load_cert(const char *filename, PRBool cacert)
PK11_SETATTRS(attrs, CKA_TOKEN, &cktrue, sizeof(CK_BBOOL) ); attrs++; PK11_SETATTRS(attrs, CKA_TOKEN, &cktrue, sizeof(CK_BBOOL) ); attrs++;
PK11_SETATTRS(attrs, CKA_LABEL, (unsigned char *)filename, PK11_SETATTRS(attrs, CKA_LABEL, (unsigned char *)filename,
strlen(filename)+1); attrs++; strlen(filename)+1); attrs++;
if (cacert) { if(cacert) {
PK11_SETATTRS(attrs, CKA_TRUST, &cktrue, sizeof(CK_BBOOL) ); attrs++; PK11_SETATTRS(attrs, CKA_TRUST, &cktrue, sizeof(CK_BBOOL) ); attrs++;
} }
else { else {
@ -348,11 +348,11 @@ done:
/* Double-check that the certificate or nickname requested exists in /* Double-check that the certificate or nickname requested exists in
* either the token or the NSS certificate database. * either the token or the NSS certificate database.
*/ */
if (!cacert) { if(!cacert) {
cert = PK11_FindCertFromNickname((char *)nickname, NULL); cert = PK11_FindCertFromNickname((char *)nickname, NULL);
/* An invalid nickname was passed in */ /* An invalid nickname was passed in */
if (cert == NULL) { if(cert == NULL) {
free(nickname); free(nickname);
PR_SetError(SEC_ERROR_UNKNOWN_CERT, 0); PR_SetError(SEC_ERROR_UNKNOWN_CERT, 0);
return 0; return 0;
@ -533,7 +533,7 @@ static SECStatus nss_Init_Tokens(struct connectdata * conn)
ret = PK11_Authenticate(slot, PR_TRUE, parg); ret = PK11_Authenticate(slot, PR_TRUE, parg);
if(SECSuccess != ret) { if(SECSuccess != ret) {
if (PR_GetError() == SEC_ERROR_BAD_PASSWORD) if(PR_GetError() == SEC_ERROR_BAD_PASSWORD)
infof(conn->data, "The password for token '%s' is incorrect\n", infof(conn->data, "The password for token '%s' is incorrect\n",
PK11_GetTokenName(slot)); PK11_GetTokenName(slot));
status = SECFailure; status = SECFailure;
@ -556,7 +556,7 @@ static SECStatus BadCertHandler(void *arg, PRFileDesc *sock)
CERTCertificate *cert = NULL; CERTCertificate *cert = NULL;
char *subject, *issuer; char *subject, *issuer;
if (conn->data->set.ssl.certverifyresult!=0) if(conn->data->set.ssl.certverifyresult!=0)
return success; return success;
conn->data->set.ssl.certverifyresult=err; conn->data->set.ssl.certverifyresult=err;
@ -568,34 +568,34 @@ static SECStatus BadCertHandler(void *arg, PRFileDesc *sock)
switch(err) { switch(err) {
case SEC_ERROR_CA_CERT_INVALID: case SEC_ERROR_CA_CERT_INVALID:
infof(conn->data, "Issuer certificate is invalid: '%s'\n", issuer); infof(conn->data, "Issuer certificate is invalid: '%s'\n", issuer);
if (conn->data->set.ssl.verifypeer) if(conn->data->set.ssl.verifypeer)
success = SECFailure; success = SECFailure;
break; break;
case SEC_ERROR_UNTRUSTED_ISSUER: case SEC_ERROR_UNTRUSTED_ISSUER:
if (conn->data->set.ssl.verifypeer) if(conn->data->set.ssl.verifypeer)
success = SECFailure; success = SECFailure;
infof(conn->data, "Certificate is signed by an untrusted issuer: '%s'\n", infof(conn->data, "Certificate is signed by an untrusted issuer: '%s'\n",
issuer); issuer);
break; break;
case SSL_ERROR_BAD_CERT_DOMAIN: case SSL_ERROR_BAD_CERT_DOMAIN:
if (conn->data->set.ssl.verifypeer) if(conn->data->set.ssl.verifypeer)
success = SECFailure; success = SECFailure;
infof(conn->data, "common name: %s (does not match '%s')\n", infof(conn->data, "common name: %s (does not match '%s')\n",
subject, conn->host.dispname); subject, conn->host.dispname);
break; break;
case SEC_ERROR_EXPIRED_CERTIFICATE: case SEC_ERROR_EXPIRED_CERTIFICATE:
if (conn->data->set.ssl.verifypeer) if(conn->data->set.ssl.verifypeer)
success = SECFailure; success = SECFailure;
infof(conn->data, "Remote Certificate has expired.\n"); infof(conn->data, "Remote Certificate has expired.\n");
break; break;
default: default:
if (conn->data->set.ssl.verifypeer) if(conn->data->set.ssl.verifypeer)
success = SECFailure; success = SECFailure;
infof(conn->data, "Bad certificate received. Subject = '%s', " infof(conn->data, "Bad certificate received. Subject = '%s', "
"Issuer = '%s'\n", subject, issuer); "Issuer = '%s'\n", subject, issuer);
break; break;
} }
if (success == SECSuccess) if(success == SECSuccess)
infof(conn->data, "SSL certificate verify ok.\n"); infof(conn->data, "SSL certificate verify ok.\n");
PR_Free(subject); PR_Free(subject);
PR_Free(issuer); PR_Free(issuer);
@ -623,10 +623,10 @@ static void display_conn_info(struct connectdata *conn, PRFileDesc *sock)
char timeString[256]; char timeString[256];
PRTime notBefore, notAfter; PRTime notBefore, notAfter;
if (SSL_GetChannelInfo(sock, &channel, sizeof channel) == if(SSL_GetChannelInfo(sock, &channel, sizeof channel) ==
SECSuccess && channel.length == sizeof channel && SECSuccess && channel.length == sizeof channel &&
channel.cipherSuite) { channel.cipherSuite) {
if (SSL_GetCipherSuiteInfo(channel.cipherSuite, if(SSL_GetCipherSuiteInfo(channel.cipherSuite,
&suite, sizeof suite) == SECSuccess) { &suite, sizeof suite) == SECSuccess) {
infof(conn->data, "SSL connection using %s\n", suite.cipherSuiteName); infof(conn->data, "SSL connection using %s\n", suite.cipherSuiteName);
} }
@ -678,7 +678,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
proto_win = SSL_RevealPinArg(sock); proto_win = SSL_RevealPinArg(sock);
if (!nickname) if(!nickname)
return secStatus; return secStatus;
cert = PK11_FindCertFromNickname(nickname, proto_win); cert = PK11_FindCertFromNickname(nickname, proto_win);
@ -708,7 +708,7 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
*pRetKey = privKey; *pRetKey = privKey;
} }
else { else {
if (cert) if(cert)
CERT_DestroyCertificate(cert); CERT_DestroyCertificate(cert);
} }
@ -814,11 +814,11 @@ CURLcode Curl_nss_connect(struct connectdata * conn, int sockindex)
certDir = getenv("SSL_DIR"); /* Look in $SSL_DIR */ certDir = getenv("SSL_DIR"); /* Look in $SSL_DIR */
if (!certDir) { if(!certDir) {
struct stat st; struct stat st;
if (stat(SSL_DIR, &st) == 0) if(stat(SSL_DIR, &st) == 0)
if (S_ISDIR(st.st_mode)) { if(S_ISDIR(st.st_mode)) {
certDir = (char *)SSL_DIR; certDir = (char *)SSL_DIR;
} }
} }
@ -845,8 +845,8 @@ CURLcode Curl_nss_connect(struct connectdata * conn, int sockindex)
mod = SECMOD_LoadUserModule(configstring, NULL, PR_FALSE); mod = SECMOD_LoadUserModule(configstring, NULL, PR_FALSE);
free(configstring); free(configstring);
if (!mod || !mod->loaded) { if(!mod || !mod->loaded) {
if (mod) { if(mod) {
SECMOD_DestroyModule(mod); SECMOD_DestroyModule(mod);
mod = NULL; mod = NULL;
} }
@ -912,31 +912,31 @@ CURLcode Curl_nss_connect(struct connectdata * conn, int sockindex)
if(!data->set.ssl.verifypeer) if(!data->set.ssl.verifypeer)
/* skip the verifying of the peer */ /* skip the verifying of the peer */
; ;
else if (data->set.ssl.CAfile) { else if(data->set.ssl.CAfile) {
int rc = nss_load_cert(data->set.ssl.CAfile, PR_TRUE); int rc = nss_load_cert(data->set.ssl.CAfile, PR_TRUE);
if (!rc) { if(!rc) {
curlerr = CURLE_SSL_CACERT_BADFILE; curlerr = CURLE_SSL_CACERT_BADFILE;
goto error; goto error;
} }
} }
else if (data->set.ssl.CApath) { else if(data->set.ssl.CApath) {
struct stat st; struct stat st;
PRDir *dir; PRDir *dir;
PRDirEntry *entry; PRDirEntry *entry;
if (stat(data->set.ssl.CApath, &st) == -1) { if(stat(data->set.ssl.CApath, &st) == -1) {
curlerr = CURLE_SSL_CACERT_BADFILE; curlerr = CURLE_SSL_CACERT_BADFILE;
goto error; goto error;
} }
if (S_ISDIR(st.st_mode)) { if(S_ISDIR(st.st_mode)) {
int rc; int rc;
dir = PR_OpenDir(data->set.ssl.CApath); dir = PR_OpenDir(data->set.ssl.CApath);
do { do {
entry = PR_ReadDir(dir, PR_SKIP_BOTH | PR_SKIP_HIDDEN); entry = PR_ReadDir(dir, PR_SKIP_BOTH | PR_SKIP_HIDDEN);
if (entry) { if(entry) {
char fullpath[PATH_MAX]; char fullpath[PATH_MAX];
snprintf(fullpath, sizeof(fullpath), "%s/%s", data->set.ssl.CApath, snprintf(fullpath, sizeof(fullpath), "%s/%s", data->set.ssl.CApath,
@ -946,7 +946,7 @@ CURLcode Curl_nss_connect(struct connectdata * conn, int sockindex)
} }
/* This is purposefully tolerant of errors so non-PEM files /* This is purposefully tolerant of errors so non-PEM files
* can be in the same directory */ * can be in the same directory */
} while (entry != NULL); } while(entry != NULL);
PR_CloseDir(dir); PR_CloseDir(dir);
} }
} }
@ -963,7 +963,7 @@ CURLcode Curl_nss_connect(struct connectdata * conn, int sockindex)
nickname = (char *)malloc(PATH_MAX); nickname = (char *)malloc(PATH_MAX);
if(is_file(data->set.str[STRING_CERT])) { if(is_file(data->set.str[STRING_CERT])) {
n = strrchr(data->set.str[STRING_CERT], '/'); n = strrchr(data->set.str[STRING_CERT], '/');
if (n) { if(n) {
n++; /* skip last slash */ n++; /* skip last slash */
snprintf(nickname, PATH_MAX, "PEM Token #%ld:%s", 1, n); snprintf(nickname, PATH_MAX, "PEM Token #%ld:%s", 1, n);
} }
@ -975,7 +975,7 @@ CURLcode Curl_nss_connect(struct connectdata * conn, int sockindex)
free(nickname); free(nickname);
goto error; goto error;
} }
if (!cert_stuff(conn, data->set.str[STRING_CERT], if(!cert_stuff(conn, data->set.str[STRING_CERT],
data->set.str[STRING_KEY])) { data->set.str[STRING_KEY])) {
/* failf() is already done in cert_stuff() */ /* failf() is already done in cert_stuff() */
free(nickname); free(nickname);
@ -1011,10 +1011,10 @@ CURLcode Curl_nss_connect(struct connectdata * conn, int sockindex)
SSL_SetURL(connssl->handle, conn->host.name); SSL_SetURL(connssl->handle, conn->host.name);
/* Force the handshake now */ /* Force the handshake now */
if (SSL_ForceHandshakeWithTimeout(connssl->handle, if(SSL_ForceHandshakeWithTimeout(connssl->handle,
PR_SecondsToInterval(HANDSHAKE_TIMEOUT)) PR_SecondsToInterval(HANDSHAKE_TIMEOUT))
!= SECSuccess) { != SECSuccess) {
if (conn->data->set.ssl.certverifyresult!=0) if(conn->data->set.ssl.certverifyresult!=0)
curlerr = CURLE_SSL_CACERT; curlerr = CURLE_SSL_CACERT;
goto error; goto error;
} }

View File

@ -52,7 +52,7 @@
/* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1] */ /* Winsock and TPF sockets are not in range [0..FD_SETSIZE-1] */
#if defined(USE_WINSOCK) || defined(TPF) #if defined(USE_WINSOCK) || defined(TPF)
#define VERIFY_SOCK(x) do { } while (0) #define VERIFY_SOCK(x) do { } while(0)
#else #else
#define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE)) #define VALID_SOCK(s) (((s) >= 0) && ((s) < FD_SETSIZE))
#define VERIFY_SOCK(x) do { \ #define VERIFY_SOCK(x) do { \
@ -105,9 +105,9 @@ static int wait_ms(int timeout_ms)
#endif #endif
int r = 0; int r = 0;
if (!timeout_ms) if(!timeout_ms)
return 0; return 0;
if (timeout_ms < 0) { if(timeout_ms < 0) {
SET_SOCKERRNO(EINVAL); SET_SOCKERRNO(EINVAL);
return -1; return -1;
} }
@ -126,17 +126,17 @@ static int wait_ms(int timeout_ms)
pending_tv.tv_usec = (pending_ms % 1000) * 1000; pending_tv.tv_usec = (pending_ms % 1000) * 1000;
r = select(0, NULL, NULL, NULL, &pending_tv); r = select(0, NULL, NULL, NULL, &pending_tv);
#endif /* HAVE_POLL_FINE */ #endif /* HAVE_POLL_FINE */
if (r != -1) if(r != -1)
break; break;
error = SOCKERRNO; error = SOCKERRNO;
if ((error == EINVAL) || error_is_EINTR) if((error == EINVAL) || error_is_EINTR)
break; break;
pending_ms = timeout_ms - elapsed_ms; pending_ms = timeout_ms - elapsed_ms;
if (pending_ms <= 0) if(pending_ms <= 0)
break; break;
} while (r == -1); } while(r == -1);
#endif /* USE_WINSOCK */ #endif /* USE_WINSOCK */
if (r) if(r)
r = -1; r = -1;
return r; return r;
} }
@ -189,7 +189,7 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd,
when function is called with a zero timeout or a negative timeout when function is called with a zero timeout or a negative timeout
value indicating a blocking call should be performed. */ value indicating a blocking call should be performed. */
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_ms = timeout_ms; pending_ms = timeout_ms;
initial_tv = curlx_tvnow(); initial_tv = curlx_tvnow();
} }
@ -197,13 +197,13 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd,
#ifdef HAVE_POLL_FINE #ifdef HAVE_POLL_FINE
num = 0; num = 0;
if (readfd != CURL_SOCKET_BAD) { if(readfd != CURL_SOCKET_BAD) {
pfd[num].fd = readfd; pfd[num].fd = readfd;
pfd[num].events = POLLRDNORM|POLLIN|POLLRDBAND|POLLPRI; pfd[num].events = POLLRDNORM|POLLIN|POLLRDBAND|POLLPRI;
pfd[num].revents = 0; pfd[num].revents = 0;
num++; num++;
} }
if (writefd != CURL_SOCKET_BAD) { if(writefd != CURL_SOCKET_BAD) {
pfd[num].fd = writefd; pfd[num].fd = writefd;
pfd[num].events = POLLWRNORM|POLLOUT; pfd[num].events = POLLWRNORM|POLLOUT;
pfd[num].revents = 0; pfd[num].revents = 0;
@ -211,41 +211,41 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd,
} }
do { do {
if (timeout_ms < 0) if(timeout_ms < 0)
pending_ms = -1; pending_ms = -1;
else if (!timeout_ms) else if(!timeout_ms)
pending_ms = 0; pending_ms = 0;
r = poll(pfd, num, pending_ms); r = poll(pfd, num, pending_ms);
if (r != -1) if(r != -1)
break; break;
error = SOCKERRNO; error = SOCKERRNO;
if ((error == EINVAL) || error_is_EINTR) if((error == EINVAL) || error_is_EINTR)
break; break;
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_ms = timeout_ms - elapsed_ms; pending_ms = timeout_ms - elapsed_ms;
if (pending_ms <= 0) if(pending_ms <= 0)
break; break;
} }
} while (r == -1); } while(r == -1);
if (r < 0) if(r < 0)
return -1; return -1;
if (r == 0) if(r == 0)
return 0; return 0;
ret = 0; ret = 0;
num = 0; num = 0;
if (readfd != CURL_SOCKET_BAD) { if(readfd != CURL_SOCKET_BAD) {
if (pfd[num].revents & (POLLRDNORM|POLLIN|POLLERR|POLLHUP)) if(pfd[num].revents & (POLLRDNORM|POLLIN|POLLERR|POLLHUP))
ret |= CURL_CSELECT_IN; ret |= CURL_CSELECT_IN;
if (pfd[num].revents & (POLLRDBAND|POLLPRI|POLLNVAL)) if(pfd[num].revents & (POLLRDBAND|POLLPRI|POLLNVAL))
ret |= CURL_CSELECT_ERR; ret |= CURL_CSELECT_ERR;
num++; num++;
} }
if (writefd != CURL_SOCKET_BAD) { if(writefd != CURL_SOCKET_BAD) {
if (pfd[num].revents & (POLLWRNORM|POLLOUT)) if(pfd[num].revents & (POLLWRNORM|POLLOUT))
ret |= CURL_CSELECT_OUT; ret |= CURL_CSELECT_OUT;
if (pfd[num].revents & (POLLERR|POLLHUP|POLLNVAL)) if(pfd[num].revents & (POLLERR|POLLHUP|POLLNVAL))
ret |= CURL_CSELECT_ERR; ret |= CURL_CSELECT_ERR;
} }
@ -257,7 +257,7 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd,
maxfd = (curl_socket_t)-1; maxfd = (curl_socket_t)-1;
FD_ZERO(&fds_read); FD_ZERO(&fds_read);
if (readfd != CURL_SOCKET_BAD) { if(readfd != CURL_SOCKET_BAD) {
VERIFY_SOCK(readfd); VERIFY_SOCK(readfd);
FD_SET(readfd, &fds_read); FD_SET(readfd, &fds_read);
FD_SET(readfd, &fds_err); FD_SET(readfd, &fds_err);
@ -265,54 +265,54 @@ int Curl_socket_ready(curl_socket_t readfd, curl_socket_t writefd,
} }
FD_ZERO(&fds_write); FD_ZERO(&fds_write);
if (writefd != CURL_SOCKET_BAD) { if(writefd != CURL_SOCKET_BAD) {
VERIFY_SOCK(writefd); VERIFY_SOCK(writefd);
FD_SET(writefd, &fds_write); FD_SET(writefd, &fds_write);
FD_SET(writefd, &fds_err); FD_SET(writefd, &fds_err);
if (writefd > maxfd) if(writefd > maxfd)
maxfd = writefd; maxfd = writefd;
} }
ptimeout = (timeout_ms < 0) ? NULL : &pending_tv; ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
do { do {
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_tv.tv_sec = pending_ms / 1000; pending_tv.tv_sec = pending_ms / 1000;
pending_tv.tv_usec = (pending_ms % 1000) * 1000; pending_tv.tv_usec = (pending_ms % 1000) * 1000;
} }
else if (!timeout_ms) { else if(!timeout_ms) {
pending_tv.tv_sec = 0; pending_tv.tv_sec = 0;
pending_tv.tv_usec = 0; pending_tv.tv_usec = 0;
} }
r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout); r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
if (r != -1) if(r != -1)
break; break;
error = SOCKERRNO; error = SOCKERRNO;
if ((error == EINVAL) || (error == EBADF) || error_is_EINTR) if((error == EINVAL) || (error == EBADF) || error_is_EINTR)
break; break;
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_ms = timeout_ms - elapsed_ms; pending_ms = timeout_ms - elapsed_ms;
if (pending_ms <= 0) if(pending_ms <= 0)
break; break;
} }
} while (r == -1); } while(r == -1);
if (r < 0) if(r < 0)
return -1; return -1;
if (r == 0) if(r == 0)
return 0; return 0;
ret = 0; ret = 0;
if (readfd != CURL_SOCKET_BAD) { if(readfd != CURL_SOCKET_BAD) {
if (FD_ISSET(readfd, &fds_read)) if(FD_ISSET(readfd, &fds_read))
ret |= CURL_CSELECT_IN; ret |= CURL_CSELECT_IN;
if (FD_ISSET(readfd, &fds_err)) if(FD_ISSET(readfd, &fds_err))
ret |= CURL_CSELECT_ERR; ret |= CURL_CSELECT_ERR;
} }
if (writefd != CURL_SOCKET_BAD) { if(writefd != CURL_SOCKET_BAD) {
if (FD_ISSET(writefd, &fds_write)) if(FD_ISSET(writefd, &fds_write))
ret |= CURL_CSELECT_OUT; ret |= CURL_CSELECT_OUT;
if (FD_ISSET(writefd, &fds_err)) if(FD_ISSET(writefd, &fds_err))
ret |= CURL_CSELECT_ERR; ret |= CURL_CSELECT_ERR;
} }
@ -355,15 +355,15 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
int error; int error;
int r; int r;
if (ufds) { if(ufds) {
for (i = 0; i < nfds; i++) { for (i = 0; i < nfds; i++) {
if (ufds[i].fd != CURL_SOCKET_BAD) { if(ufds[i].fd != CURL_SOCKET_BAD) {
fds_none = FALSE; fds_none = FALSE;
break; break;
} }
} }
} }
if (fds_none) { if(fds_none) {
r = wait_ms(timeout_ms); r = wait_ms(timeout_ms);
return r; return r;
} }
@ -373,7 +373,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
when function is called with a zero timeout or a negative timeout when function is called with a zero timeout or a negative timeout
value indicating a blocking call should be performed. */ value indicating a blocking call should be performed. */
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_ms = timeout_ms; pending_ms = timeout_ms;
initial_tv = curlx_tvnow(); initial_tv = curlx_tvnow();
} }
@ -381,22 +381,22 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
#ifdef HAVE_POLL_FINE #ifdef HAVE_POLL_FINE
do { do {
if (timeout_ms < 0) if(timeout_ms < 0)
pending_ms = -1; pending_ms = -1;
else if (!timeout_ms) else if(!timeout_ms)
pending_ms = 0; pending_ms = 0;
r = poll(ufds, nfds, pending_ms); r = poll(ufds, nfds, pending_ms);
if (r != -1) if(r != -1)
break; break;
error = SOCKERRNO; error = SOCKERRNO;
if ((error == EINVAL) || error_is_EINTR) if((error == EINVAL) || error_is_EINTR)
break; break;
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_ms = timeout_ms - elapsed_ms; pending_ms = timeout_ms - elapsed_ms;
if (pending_ms <= 0) if(pending_ms <= 0)
break; break;
} }
} while (r == -1); } while(r == -1);
#else /* HAVE_POLL_FINE */ #else /* HAVE_POLL_FINE */
@ -407,18 +407,18 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
for (i = 0; i < nfds; i++) { for (i = 0; i < nfds; i++) {
ufds[i].revents = 0; ufds[i].revents = 0;
if (ufds[i].fd == CURL_SOCKET_BAD) if(ufds[i].fd == CURL_SOCKET_BAD)
continue; continue;
VERIFY_SOCK(ufds[i].fd); VERIFY_SOCK(ufds[i].fd);
if (ufds[i].events & (POLLIN|POLLOUT|POLLPRI| if(ufds[i].events & (POLLIN|POLLOUT|POLLPRI|
POLLRDNORM|POLLWRNORM|POLLRDBAND)) { POLLRDNORM|POLLWRNORM|POLLRDBAND)) {
if (ufds[i].fd > maxfd) if(ufds[i].fd > maxfd)
maxfd = ufds[i].fd; maxfd = ufds[i].fd;
if (ufds[i].events & (POLLRDNORM|POLLIN)) if(ufds[i].events & (POLLRDNORM|POLLIN))
FD_SET(ufds[i].fd, &fds_read); FD_SET(ufds[i].fd, &fds_read);
if (ufds[i].events & (POLLWRNORM|POLLOUT)) if(ufds[i].events & (POLLWRNORM|POLLOUT))
FD_SET(ufds[i].fd, &fds_write); FD_SET(ufds[i].fd, &fds_write);
if (ufds[i].events & (POLLRDBAND|POLLPRI)) if(ufds[i].events & (POLLRDBAND|POLLPRI))
FD_SET(ufds[i].fd, &fds_err); FD_SET(ufds[i].fd, &fds_err);
} }
} }
@ -426,44 +426,44 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
ptimeout = (timeout_ms < 0) ? NULL : &pending_tv; ptimeout = (timeout_ms < 0) ? NULL : &pending_tv;
do { do {
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_tv.tv_sec = pending_ms / 1000; pending_tv.tv_sec = pending_ms / 1000;
pending_tv.tv_usec = (pending_ms % 1000) * 1000; pending_tv.tv_usec = (pending_ms % 1000) * 1000;
} }
else if (!timeout_ms) { else if(!timeout_ms) {
pending_tv.tv_sec = 0; pending_tv.tv_sec = 0;
pending_tv.tv_usec = 0; pending_tv.tv_usec = 0;
} }
r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout); r = select((int)maxfd + 1, &fds_read, &fds_write, &fds_err, ptimeout);
if (r != -1) if(r != -1)
break; break;
error = SOCKERRNO; error = SOCKERRNO;
if ((error == EINVAL) || (error == EBADF) || error_is_EINTR) if((error == EINVAL) || (error == EBADF) || error_is_EINTR)
break; break;
if (timeout_ms > 0) { if(timeout_ms > 0) {
pending_ms = timeout_ms - elapsed_ms; pending_ms = timeout_ms - elapsed_ms;
if (pending_ms <= 0) if(pending_ms <= 0)
break; break;
} }
} while (r == -1); } while(r == -1);
if (r < 0) if(r < 0)
return -1; return -1;
if (r == 0) if(r == 0)
return 0; return 0;
r = 0; r = 0;
for (i = 0; i < nfds; i++) { for (i = 0; i < nfds; i++) {
ufds[i].revents = 0; ufds[i].revents = 0;
if (ufds[i].fd == CURL_SOCKET_BAD) if(ufds[i].fd == CURL_SOCKET_BAD)
continue; continue;
if (FD_ISSET(ufds[i].fd, &fds_read)) if(FD_ISSET(ufds[i].fd, &fds_read))
ufds[i].revents |= POLLIN; ufds[i].revents |= POLLIN;
if (FD_ISSET(ufds[i].fd, &fds_write)) if(FD_ISSET(ufds[i].fd, &fds_write))
ufds[i].revents |= POLLOUT; ufds[i].revents |= POLLOUT;
if (FD_ISSET(ufds[i].fd, &fds_err)) if(FD_ISSET(ufds[i].fd, &fds_err))
ufds[i].revents |= POLLPRI; ufds[i].revents |= POLLPRI;
if (ufds[i].revents != 0) if(ufds[i].revents != 0)
r++; r++;
} }

View File

@ -67,12 +67,12 @@ static struct curl_slist *slist_get_last(struct curl_slist *list)
struct curl_slist *item; struct curl_slist *item;
/* if caller passed us a NULL, return now */ /* if caller passed us a NULL, return now */
if (!list) if(!list)
return NULL; return NULL;
/* loop through to find the last item */ /* loop through to find the last item */
item = list; item = list;
while (item->next) { while(item->next) {
item = item->next; item = item->next;
} }
return item; return item;
@ -92,7 +92,7 @@ struct curl_slist *curl_slist_append(struct curl_slist *list,
struct curl_slist *new_item; struct curl_slist *new_item;
new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist)); new_item = (struct curl_slist *) malloc(sizeof(struct curl_slist));
if (new_item) { if(new_item) {
char *dupdata = strdup(data); char *dupdata = strdup(data);
if(dupdata) { if(dupdata) {
new_item->next = NULL; new_item->next = NULL;
@ -106,7 +106,7 @@ struct curl_slist *curl_slist_append(struct curl_slist *list,
else else
return NULL; return NULL;
if (list) { if(list) {
last = slist_get_last(list); last = slist_get_last(list);
last->next = new_item; last->next = new_item;
return list; return list;
@ -122,19 +122,19 @@ void curl_slist_free_all(struct curl_slist *list)
struct curl_slist *next; struct curl_slist *next;
struct curl_slist *item; struct curl_slist *item;
if (!list) if(!list)
return; return;
item = list; item = list;
do { do {
next = item->next; next = item->next;
if (item->data) { if(item->data) {
free(item->data); free(item->data);
} }
free(item); free(item);
item = next; item = next;
} while (next); } while(next);
} }
#ifdef CURL_DO_LINEEND_CONV #ifdef CURL_DO_LINEEND_CONV
@ -150,14 +150,14 @@ static size_t convert_lineends(struct SessionHandle *data,
char *inPtr, *outPtr; char *inPtr, *outPtr;
/* sanity check */ /* sanity check */
if ((startPtr == NULL) || (size < 1)) { if((startPtr == NULL) || (size < 1)) {
return(size); return(size);
} }
if (data->state.prev_block_had_trailing_cr == TRUE) { if(data->state.prev_block_had_trailing_cr == TRUE) {
/* The previous block of incoming data /* The previous block of incoming data
had a trailing CR, which was turned into a LF. */ had a trailing CR, which was turned into a LF. */
if (*startPtr == '\n') { if(*startPtr == '\n') {
/* This block of incoming data starts with the /* This block of incoming data starts with the
previous block's LF so get rid of it */ previous block's LF so get rid of it */
memcpy(startPtr, startPtr+1, size-1); memcpy(startPtr, startPtr+1, size-1);
@ -170,11 +170,11 @@ static size_t convert_lineends(struct SessionHandle *data,
/* find 1st CR, if any */ /* find 1st CR, if any */
inPtr = outPtr = memchr(startPtr, '\r', size); inPtr = outPtr = memchr(startPtr, '\r', size);
if (inPtr) { if(inPtr) {
/* at least one CR, now look for CRLF */ /* at least one CR, now look for CRLF */
while (inPtr < (startPtr+size-1)) { while(inPtr < (startPtr+size-1)) {
/* note that it's size-1, so we'll never look past the last byte */ /* note that it's size-1, so we'll never look past the last byte */
if (memcmp(inPtr, "\r\n", 2) == 0) { if(memcmp(inPtr, "\r\n", 2) == 0) {
/* CRLF found, bump past the CR and copy the NL */ /* CRLF found, bump past the CR and copy the NL */
inPtr++; inPtr++;
*outPtr = *inPtr; *outPtr = *inPtr;
@ -182,7 +182,7 @@ static size_t convert_lineends(struct SessionHandle *data,
data->state.crlf_conversions++; data->state.crlf_conversions++;
} }
else { else {
if (*inPtr == '\r') { if(*inPtr == '\r') {
/* lone CR, move LF instead */ /* lone CR, move LF instead */
*outPtr = '\n'; *outPtr = '\n';
} }
@ -195,9 +195,9 @@ static size_t convert_lineends(struct SessionHandle *data,
inPtr++; inPtr++;
} /* end of while loop */ } /* end of while loop */
if (inPtr < startPtr+size) { if(inPtr < startPtr+size) {
/* handle last byte */ /* handle last byte */
if (*inPtr == '\r') { if(*inPtr == '\r') {
/* deal with a CR at the end of the buffer */ /* deal with a CR at the end of the buffer */
*outPtr = '\n'; /* copy a NL instead */ *outPtr = '\n'; /* copy a NL instead */
/* note that a CRLF might be split across two blocks */ /* note that a CRLF might be split across two blocks */
@ -210,7 +210,7 @@ static size_t convert_lineends(struct SessionHandle *data,
outPtr++; outPtr++;
inPtr++; inPtr++;
} }
if (outPtr < startPtr+size) { if(outPtr < startPtr+size) {
/* tidy up by null terminating the now shorter data */ /* tidy up by null terminating the now shorter data */
*outPtr = '\0'; *outPtr = '\0';
} }
@ -285,7 +285,7 @@ CURLcode Curl_sendf(curl_socket_t sockfd, struct connectdata *conn,
write_len = strlen(s); write_len = strlen(s);
sptr = s; sptr = s;
while (1) { while(1) {
/* Write the buffer to the socket */ /* Write the buffer to the socket */
res = Curl_write(conn, sockfd, sptr, write_len, &bytes_written); res = Curl_write(conn, sockfd, sptr, write_len, &bytes_written);
@ -355,13 +355,13 @@ CURLcode Curl_write(struct connectdata *conn,
CURLcode retcode; CURLcode retcode;
int num = (sockfd == conn->sock[SECONDARYSOCKET]); int num = (sockfd == conn->sock[SECONDARYSOCKET]);
if (conn->ssl[num].use) if(conn->ssl[num].use)
/* only TRUE if SSL enabled */ /* only TRUE if SSL enabled */
bytes_written = Curl_ssl_send(conn, num, mem, len); bytes_written = Curl_ssl_send(conn, num, mem, len);
#ifdef USE_LIBSSH2 #ifdef USE_LIBSSH2
else if (conn->protocol & PROT_SCP) else if(conn->protocol & PROT_SCP)
bytes_written = Curl_scp_send(conn, num, mem, len); bytes_written = Curl_scp_send(conn, num, mem, len);
else if (conn->protocol & PROT_SFTP) else if(conn->protocol & PROT_SFTP)
bytes_written = Curl_sftp_send(conn, num, mem, len); bytes_written = Curl_sftp_send(conn, num, mem, len);
#endif /* !USE_LIBSSH2 */ #endif /* !USE_LIBSSH2 */
else if(conn->sec_complete) else if(conn->sec_complete)
@ -389,7 +389,7 @@ CURLcode Curl_client_write(struct connectdata *conn,
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
size_t wrote; size_t wrote;
if (data->state.cancelled) { if(data->state.cancelled) {
/* We just suck everything into a black hole */ /* We just suck everything into a black hole */
return CURLE_OK; return CURLE_OK;
} }
@ -415,7 +415,7 @@ CURLcode Curl_client_write(struct connectdata *conn,
} }
/* If the previous block of data ended with CR and this block of data is /* If the previous block of data ended with CR and this block of data is
just a NL, then the length might be zero */ just a NL, then the length might be zero */
if (len) { if(len) {
wrote = data->set.fwrite_func(ptr, 1, len, data->set.out); wrote = data->set.fwrite_func(ptr, 1, len, data->set.out);
} }
else { else {
@ -485,7 +485,7 @@ int Curl_read(struct connectdata *conn, /* connection data */
size_t bytestocopy = MIN(conn->buf_len - conn->read_pos, sizerequested); size_t bytestocopy = MIN(conn->buf_len - conn->read_pos, sizerequested);
/* Copy from our master buffer first if we have some unread data there*/ /* Copy from our master buffer first if we have some unread data there*/
if (bytestocopy > 0) { if(bytestocopy > 0) {
memcpy(buf, conn->master_buffer + conn->read_pos, bytestocopy); memcpy(buf, conn->master_buffer + conn->read_pos, bytestocopy);
conn->read_pos += bytestocopy; conn->read_pos += bytestocopy;
conn->bits.stream_was_rewound = FALSE; conn->bits.stream_was_rewound = FALSE;
@ -512,10 +512,10 @@ int Curl_read(struct connectdata *conn, /* connection data */
} }
} }
#ifdef USE_LIBSSH2 #ifdef USE_LIBSSH2
else if (conn->protocol & (PROT_SCP|PROT_SFTP)) { else if(conn->protocol & (PROT_SCP|PROT_SFTP)) {
if(conn->protocol & PROT_SCP) if(conn->protocol & PROT_SCP)
nread = Curl_scp_recv(conn, num, buffertofill, bytesfromsocket); nread = Curl_scp_recv(conn, num, buffertofill, bytesfromsocket);
else if (conn->protocol & PROT_SFTP) else if(conn->protocol & PROT_SFTP)
nread = Curl_sftp_recv(conn, num, buffertofill, bytesfromsocket); nread = Curl_sftp_recv(conn, num, buffertofill, bytesfromsocket);
#ifdef LIBSSH2CHANNEL_EAGAIN #ifdef LIBSSH2CHANNEL_EAGAIN
if((nread == LIBSSH2CHANNEL_EAGAIN) || (nread == 0)) if((nread == LIBSSH2CHANNEL_EAGAIN) || (nread == 0))
@ -545,7 +545,7 @@ int Curl_read(struct connectdata *conn, /* connection data */
} }
} }
if (nread >= 0) { if(nread >= 0) {
if(pipelining) { if(pipelining) {
memcpy(buf, conn->master_buffer, nread); memcpy(buf, conn->master_buffer, nread);
conn->buf_len = nread; conn->buf_len = nread;
@ -573,7 +573,7 @@ static int showit(struct SessionHandle *data, curl_infotype type,
case CURLINFO_HEADER_OUT: case CURLINFO_HEADER_OUT:
/* assume output headers are ASCII */ /* assume output headers are ASCII */
/* copy the data into my buffer so the original is unchanged */ /* copy the data into my buffer so the original is unchanged */
if (size > BUFSIZE) { if(size > BUFSIZE) {
size = BUFSIZE; /* truncate if necessary */ size = BUFSIZE; /* truncate if necessary */
buf[BUFSIZE] = '\0'; buf[BUFSIZE] = '\0';
} }

View File

@ -136,7 +136,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
/* get timeout */ /* get timeout */
if(data->set.timeout && data->set.connecttimeout) { if(data->set.timeout && data->set.connecttimeout) {
if (data->set.timeout < data->set.connecttimeout) if(data->set.timeout < data->set.connecttimeout)
timeout = data->set.timeout; timeout = data->set.timeout;
else else
timeout = data->set.connecttimeout; timeout = data->set.connecttimeout;
@ -186,7 +186,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
*/ */
if(dns) if(dns)
hp=dns->addr; hp=dns->addr;
if (hp) { if(hp) {
char buf[64]; char buf[64];
unsigned short ip[4]; unsigned short ip[4];
Curl_printable_address(hp, buf, sizeof(buf)); Curl_printable_address(hp, buf, sizeof(buf));
@ -216,7 +216,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
* This is currently not supporting "Identification Protocol (RFC1413)". * This is currently not supporting "Identification Protocol (RFC1413)".
*/ */
socksreq[8] = 0; /* ensure empty userid is NUL-terminated */ socksreq[8] = 0; /* ensure empty userid is NUL-terminated */
if (proxy_name) if(proxy_name)
strlcat((char*)socksreq + 8, proxy_name, sizeof(socksreq) - 8); strlcat((char*)socksreq + 8, proxy_name, sizeof(socksreq) - 8);
/* /*
@ -230,7 +230,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
/* Send request */ /* Send request */
code = Curl_write(conn, sock, (char *)socksreq, packetsize, &written); code = Curl_write(conn, sock, (char *)socksreq, packetsize, &written);
if ((code != CURLE_OK) || (written != packetsize)) { if((code != CURLE_OK) || (written != packetsize)) {
failf(data, "Failed to send SOCKS4 connect request."); failf(data, "Failed to send SOCKS4 connect request.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
@ -240,7 +240,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
/* Receive response */ /* Receive response */
result = blockread_all(conn, sock, (char *)socksreq, packetsize, result = blockread_all(conn, sock, (char *)socksreq, packetsize,
&actualread, timeout); &actualread, timeout);
if ((result != CURLE_OK) || (actualread != packetsize)) { if((result != CURLE_OK) || (actualread != packetsize)) {
failf(data, "Failed to receive SOCKS4 connect request ack."); failf(data, "Failed to receive SOCKS4 connect request ack.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
@ -265,7 +265,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
*/ */
/* wrong version ? */ /* wrong version ? */
if (socksreq[0] != 0) { if(socksreq[0] != 0) {
failf(data, failf(data,
"SOCKS4 reply has wrong version, version should be 4."); "SOCKS4 reply has wrong version, version should be 4.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
@ -362,7 +362,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
/* get timeout */ /* get timeout */
if(data->set.timeout && data->set.connecttimeout) { if(data->set.timeout && data->set.connecttimeout) {
if (data->set.timeout < data->set.connecttimeout) if(data->set.timeout < data->set.connecttimeout)
timeout = data->set.timeout; timeout = data->set.timeout;
else else
timeout = data->set.connecttimeout; timeout = data->set.connecttimeout;
@ -402,7 +402,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
code = Curl_write(conn, sock, (char *)socksreq, (2 + (int)socksreq[1]), code = Curl_write(conn, sock, (char *)socksreq, (2 + (int)socksreq[1]),
&written); &written);
if ((code != CURLE_OK) || (written != (2 + (int)socksreq[1]))) { if((code != CURLE_OK) || (written != (2 + (int)socksreq[1]))) {
failf(data, "Unable to send initial SOCKS5 request."); failf(data, "Unable to send initial SOCKS5 request.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
@ -428,20 +428,20 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
Curl_nonblock(sock, FALSE); Curl_nonblock(sock, FALSE);
result=blockread_all(conn, sock, (char *)socksreq, 2, &actualread, timeout); result=blockread_all(conn, sock, (char *)socksreq, 2, &actualread, timeout);
if ((result != CURLE_OK) || (actualread != 2)) { if((result != CURLE_OK) || (actualread != 2)) {
failf(data, "Unable to receive initial SOCKS5 response."); failf(data, "Unable to receive initial SOCKS5 response.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
if (socksreq[0] != 5) { if(socksreq[0] != 5) {
failf(data, "Received invalid version in initial SOCKS5 response."); failf(data, "Received invalid version in initial SOCKS5 response.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
if (socksreq[1] == 0) { if(socksreq[1] == 0) {
/* Nothing to do, no authentication needed */ /* Nothing to do, no authentication needed */
; ;
} }
else if (socksreq[1] == 2) { else if(socksreq[1] == 2) {
/* Needs user name and password */ /* Needs user name and password */
size_t userlen, pwlen; size_t userlen, pwlen;
int len; int len;
@ -471,20 +471,20 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
len += pwlen; len += pwlen;
code = Curl_write(conn, sock, (char *)socksreq, len, &written); code = Curl_write(conn, sock, (char *)socksreq, len, &written);
if ((code != CURLE_OK) || (len != written)) { if((code != CURLE_OK) || (len != written)) {
failf(data, "Failed to send SOCKS5 sub-negotiation request."); failf(data, "Failed to send SOCKS5 sub-negotiation request.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
result=blockread_all(conn, sock, (char *)socksreq, 2, &actualread, result=blockread_all(conn, sock, (char *)socksreq, 2, &actualread,
timeout); timeout);
if ((result != CURLE_OK) || (actualread != 2)) { if((result != CURLE_OK) || (actualread != 2)) {
failf(data, "Unable to receive SOCKS5 sub-negotiation response."); failf(data, "Unable to receive SOCKS5 sub-negotiation response.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
/* ignore the first (VER) byte */ /* ignore the first (VER) byte */
if (socksreq[1] != 0) { /* status */ if(socksreq[1] != 0) { /* status */
failf(data, "User was rejected by the SOCKS5 server (%d %d).", failf(data, "User was rejected by the SOCKS5 server (%d %d).",
socksreq[0], socksreq[1]); socksreq[0], socksreq[1]);
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
@ -494,13 +494,13 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
} }
else { else {
/* error */ /* error */
if (socksreq[1] == 1) { if(socksreq[1] == 1) {
failf(data, failf(data,
"SOCKS5 GSSAPI per-message authentication is not supported."); "SOCKS5 GSSAPI per-message authentication is not supported.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
else if (socksreq[1] == 255) { else if(socksreq[1] == 255) {
if (!proxy_name || !*proxy_name) { if(!proxy_name || !*proxy_name) {
failf(data, failf(data,
"No authentication method was acceptable. (It is quite likely" "No authentication method was acceptable. (It is quite likely"
" that the SOCKS5 server wanted a username/password, since none" " that the SOCKS5 server wanted a username/password, since none"
@ -542,7 +542,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
*/ */
if(dns) if(dns)
hp=dns->addr; hp=dns->addr;
if (hp) { if(hp) {
char buf[64]; char buf[64];
unsigned short ip[4]; unsigned short ip[4];
Curl_printable_address(hp, buf, sizeof(buf)); Curl_printable_address(hp, buf, sizeof(buf));
@ -572,24 +572,24 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
const int packetsize = 10; const int packetsize = 10;
code = Curl_write(conn, sock, (char *)socksreq, packetsize, &written); code = Curl_write(conn, sock, (char *)socksreq, packetsize, &written);
if ((code != CURLE_OK) || (written != packetsize)) { if((code != CURLE_OK) || (written != packetsize)) {
failf(data, "Failed to send SOCKS5 connect request."); failf(data, "Failed to send SOCKS5 connect request.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
result = blockread_all(conn, sock, (char *)socksreq, packetsize, result = blockread_all(conn, sock, (char *)socksreq, packetsize,
&actualread, timeout); &actualread, timeout);
if ((result != CURLE_OK) || (actualread != packetsize)) { if((result != CURLE_OK) || (actualread != packetsize)) {
failf(data, "Failed to receive SOCKS5 connect request ack."); failf(data, "Failed to receive SOCKS5 connect request ack.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
if (socksreq[0] != 5) { /* version */ if(socksreq[0] != 5) { /* version */
failf(data, failf(data,
"SOCKS5 reply has wrong version, version should be 5."); "SOCKS5 reply has wrong version, version should be 5.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
if (socksreq[1] != 0) { /* Anything besides 0 is an error */ if(socksreq[1] != 0) { /* Anything besides 0 is an error */
failf(data, failf(data,
"Can't complete SOCKS5 connection to %d.%d.%d.%d:%d. (%d)", "Can't complete SOCKS5 connection to %d.%d.%d.%d:%d. (%d)",
(unsigned char)socksreq[4], (unsigned char)socksreq[5], (unsigned char)socksreq[4], (unsigned char)socksreq[5],

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1997 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1997 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
@ -42,37 +42,37 @@ struct Curl_tree *Curl_splay(int i, struct Curl_tree *t)
struct Curl_tree N, *l, *r, *y; struct Curl_tree N, *l, *r, *y;
int comp; int comp;
if (t == NULL) if(t == NULL)
return t; return t;
N.smaller = N.larger = NULL; N.smaller = N.larger = NULL;
l = r = &N; l = r = &N;
for (;;) { for (;;) {
comp = compare(i, t->key); comp = compare(i, t->key);
if (comp < 0) { if(comp < 0) {
if (t->smaller == NULL) if(t->smaller == NULL)
break; break;
if (compare(i, t->smaller->key) < 0) { if(compare(i, t->smaller->key) < 0) {
y = t->smaller; /* rotate smaller */ y = t->smaller; /* rotate smaller */
t->smaller = y->larger; t->smaller = y->larger;
y->larger = t; y->larger = t;
t = y; t = y;
if (t->smaller == NULL) if(t->smaller == NULL)
break; break;
} }
r->smaller = t; /* link smaller */ r->smaller = t; /* link smaller */
r = t; r = t;
t = t->smaller; t = t->smaller;
} }
else if (comp > 0) { else if(comp > 0) {
if (t->larger == NULL) if(t->larger == NULL)
break; break;
if (compare(i, t->larger->key) > 0) { if(compare(i, t->larger->key) > 0) {
y = t->larger; /* rotate larger */ y = t->larger; /* rotate larger */
t->larger = y->smaller; t->larger = y->smaller;
y->smaller = t; y->smaller = t;
t = y; t = y;
if (t->larger == NULL) if(t->larger == NULL)
break; break;
} }
l->larger = t; /* link larger */ l->larger = t; /* link larger */
@ -97,12 +97,12 @@ struct Curl_tree *Curl_splayinsert(int i,
struct Curl_tree *t, struct Curl_tree *t,
struct Curl_tree *node) struct Curl_tree *node)
{ {
if (node == NULL) if(node == NULL)
return t; return t;
if (t != NULL) { if(t != NULL) {
t = Curl_splay(i,t); t = Curl_splay(i,t);
if (compare(i, t->key)==0) { if(compare(i, t->key)==0) {
/* There already exists a node in the tree with the very same key. Build /* There already exists a node in the tree with the very same key. Build
a linked list of nodes. We make the new 'node' struct the new master a linked list of nodes. We make the new 'node' struct the new master
node and make the previous node the first one in the 'same' list. */ node and make the previous node the first one in the 'same' list. */
@ -123,10 +123,10 @@ struct Curl_tree *Curl_splayinsert(int i,
} }
} }
if (t == NULL) { if(t == NULL) {
node->smaller = node->larger = NULL; node->smaller = node->larger = NULL;
} }
else if (compare(i, t->key) < 0) { else if(compare(i, t->key) < 0) {
node->smaller = t->smaller; node->smaller = t->smaller;
node->larger = t; node->larger = t;
t->smaller = NULL; t->smaller = NULL;
@ -156,11 +156,11 @@ struct Curl_tree *Curl_splayremove(int i, struct Curl_tree *t,
*removed = NULL; /* default to no removed */ *removed = NULL; /* default to no removed */
if (t==NULL) if(t==NULL)
return NULL; return NULL;
t = Curl_splay(i,t); t = Curl_splay(i,t);
if (compare(i, t->key) == 0) { /* found it */ if(compare(i, t->key) == 0) { /* found it */
/* FIRST! Check if there is a list with identical sizes */ /* FIRST! Check if there is a list with identical sizes */
if((x = t->same)) { if((x = t->same)) {
@ -176,7 +176,7 @@ struct Curl_tree *Curl_splayremove(int i, struct Curl_tree *t,
return x; /* new root */ return x; /* new root */
} }
if (t->smaller == NULL) { if(t->smaller == NULL) {
x = t->larger; x = t->larger;
} }
else { else {
@ -199,7 +199,7 @@ struct Curl_tree *Curl_splaygetbest(int i, struct Curl_tree *t,
{ {
struct Curl_tree *x; struct Curl_tree *x;
if (!t) { if(!t) {
*removed = NULL; /* none removed since there was no root */ *removed = NULL; /* none removed since there was no root */
return NULL; return NULL;
} }
@ -216,7 +216,7 @@ struct Curl_tree *Curl_splaygetbest(int i, struct Curl_tree *t,
} }
} }
if (compare(i, t->key) >= 0) { /* found it */ if(compare(i, t->key) >= 0) { /* found it */
/* FIRST! Check if there is a list with identical sizes */ /* FIRST! Check if there is a list with identical sizes */
x = t->same; x = t->same;
if(x) { if(x) {
@ -232,7 +232,7 @@ struct Curl_tree *Curl_splaygetbest(int i, struct Curl_tree *t,
return x; /* new root */ return x; /* new root */
} }
if (t->smaller == NULL) { if(t->smaller == NULL) {
x = t->larger; x = t->larger;
} }
else { else {
@ -265,14 +265,14 @@ int Curl_splayremovebyaddr(struct Curl_tree *t,
{ {
struct Curl_tree *x; struct Curl_tree *x;
if (!t || !removenode) if(!t || !removenode)
return 1; return 1;
if(KEY_NOTUSED == removenode->key) { if(KEY_NOTUSED == removenode->key) {
/* Key set to NOTUSED means it is a subnode within a 'same' linked list /* Key set to NOTUSED means it is a subnode within a 'same' linked list
and thus we can unlink it easily. The 'smaller' link of a subnode and thus we can unlink it easily. The 'smaller' link of a subnode
links to the parent node. */ links to the parent node. */
if (removenode->smaller == NULL) if(removenode->smaller == NULL)
return 3; return 3;
removenode->smaller->same = removenode->same; removenode->smaller->same = removenode->same;
@ -312,7 +312,7 @@ int Curl_splayremovebyaddr(struct Curl_tree *t,
} }
else { else {
/* Remove the root node */ /* Remove the root node */
if (t->smaller == NULL) if(t->smaller == NULL)
x = t->larger; x = t->larger;
else { else {
x = Curl_splay(removenode->key, t->smaller); x = Curl_splay(removenode->key, t->smaller);
@ -332,7 +332,7 @@ void Curl_splayprint(struct Curl_tree * t, int d, char output)
struct Curl_tree *node; struct Curl_tree *node;
int i; int i;
int count; int count;
if (t == NULL) if(t == NULL)
return; return;
Curl_splayprint(t->larger, d+1, output); Curl_splayprint(t->larger, d+1, output);

View File

@ -238,7 +238,7 @@ static int ossl_seed(struct SessionHandle *data)
RAND_add(area, len, (len >> 1)); RAND_add(area, len, (len >> 1));
free(area); /* now remove the random junk */ free(area); /* now remove the random junk */
} while (!RAND_status()); } while(!RAND_status());
} }
#endif #endif
@ -366,7 +366,7 @@ int cert_stuff(struct connectdata *conn,
EVP_PKEY *pri; EVP_PKEY *pri;
f = fopen(cert_file,"rb"); f = fopen(cert_file,"rb");
if (!f) { if(!f) {
failf(data, "could not open PKCS12 file '%s'", cert_file); failf(data, "could not open PKCS12 file '%s'", cert_file);
return 0; return 0;
} }
@ -375,7 +375,7 @@ int cert_stuff(struct connectdata *conn,
PKCS12_PBE_add(); PKCS12_PBE_add();
if (!PKCS12_parse(p12, data->set.str[STRING_KEY_PASSWD], &pri, &x509, if(!PKCS12_parse(p12, data->set.str[STRING_KEY_PASSWD], &pri, &x509,
NULL)) { NULL)) {
failf(data, failf(data,
"could not parse PKCS12 file, check password, OpenSSL error %s", "could not parse PKCS12 file, check password, OpenSSL error %s",
@ -483,7 +483,7 @@ int cert_stuff(struct connectdata *conn,
} }
ssl=SSL_new(ctx); ssl=SSL_new(ctx);
if (NULL == ssl) { if(NULL == ssl) {
failf(data,"unable to create an SSL structure\n"); failf(data,"unable to create an SSL structure\n");
return 0; return 0;
} }
@ -564,7 +564,7 @@ int Curl_ossl_init(void)
SSL_load_error_strings(); SSL_load_error_strings();
/* Setup all the global SSL stuff */ /* Setup all the global SSL stuff */
if (!SSLeay_add_ssl_algorithms()) if(!SSLeay_add_ssl_algorithms())
return 0; return 0;
return 1; return 1;
@ -609,10 +609,10 @@ int Curl_ossl_check_cxn(struct connectdata *conn)
char buf; char buf;
rc = SSL_peek(conn->ssl[FIRSTSOCKET].handle, (void*)&buf, 1); rc = SSL_peek(conn->ssl[FIRSTSOCKET].handle, (void*)&buf, 1);
if (rc > 0) if(rc > 0)
return 1; /* connection still in place */ return 1; /* connection still in place */
if (rc == 0) if(rc == 0)
return 0; /* connection has been closed */ return 0; /* connection has been closed */
return -1; /* connection status unknown */ return -1; /* connection status unknown */
@ -625,17 +625,17 @@ CURLcode Curl_ossl_set_engine(struct SessionHandle *data, const char *engine)
#if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H) #if defined(USE_SSLEAY) && defined(HAVE_OPENSSL_ENGINE_H)
ENGINE *e = ENGINE_by_id(engine); ENGINE *e = ENGINE_by_id(engine);
if (!e) { if(!e) {
failf(data, "SSL Engine '%s' not found", engine); failf(data, "SSL Engine '%s' not found", engine);
return (CURLE_SSL_ENGINE_NOTFOUND); return (CURLE_SSL_ENGINE_NOTFOUND);
} }
if (data->state.engine) { if(data->state.engine) {
ENGINE_finish(data->state.engine); ENGINE_finish(data->state.engine);
ENGINE_free(data->state.engine); ENGINE_free(data->state.engine);
data->state.engine = NULL; data->state.engine = NULL;
} }
if (!ENGINE_init(e)) { if(!ENGINE_init(e)) {
char buf[256]; char buf[256];
ENGINE_free(e); ENGINE_free(e);
@ -657,8 +657,8 @@ CURLcode Curl_ossl_set_engine(struct SessionHandle *data, const char *engine)
CURLcode Curl_ossl_set_engine_default(struct SessionHandle *data) CURLcode Curl_ossl_set_engine_default(struct SessionHandle *data)
{ {
#ifdef HAVE_OPENSSL_ENGINE_H #ifdef HAVE_OPENSSL_ENGINE_H
if (data->state.engine) { if(data->state.engine) {
if (ENGINE_set_default(data->state.engine, ENGINE_METHOD_ALL) > 0) { if(ENGINE_set_default(data->state.engine, ENGINE_METHOD_ALL) > 0) {
infof(data,"set default crypto engine '%s'\n", ENGINE_get_id(data->state.engine)); infof(data,"set default crypto engine '%s'\n", ENGINE_get_id(data->state.engine));
} }
else { else {
@ -683,11 +683,11 @@ struct curl_slist *Curl_ossl_engines_list(struct SessionHandle *data)
for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) { for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) {
list = curl_slist_append(list, ENGINE_get_id(e)); list = curl_slist_append(list, ENGINE_get_id(e));
if (list == NULL) { if(list == NULL) {
curl_slist_free_all(beg); curl_slist_free_all(beg);
return NULL; return NULL;
} }
else if (beg == NULL) { else if(beg == NULL) {
beg = list; beg = list;
} }
} }
@ -919,26 +919,26 @@ static int Curl_ASN1_UTCTIME_output(struct connectdata *conn,
static int hostmatch(const char *hostname, const char *pattern) static int hostmatch(const char *hostname, const char *pattern)
{ {
while (1) { while(1) {
char c = *pattern++; char c = *pattern++;
if (c == '\0') if(c == '\0')
return (*hostname ? HOST_NOMATCH : HOST_MATCH); return (*hostname ? HOST_NOMATCH : HOST_MATCH);
if (c == '*') { if(c == '*') {
c = *pattern; c = *pattern;
if (c == '\0') /* "*\0" matches anything remaining */ if(c == '\0') /* "*\0" matches anything remaining */
return HOST_MATCH; return HOST_MATCH;
while (*hostname) { while(*hostname) {
/* The only recursive function in libcurl! */ /* The only recursive function in libcurl! */
if (hostmatch(hostname++,pattern) == HOST_MATCH) if(hostmatch(hostname++,pattern) == HOST_MATCH)
return HOST_MATCH; return HOST_MATCH;
} }
break; break;
} }
if (toupper(c) != toupper(*hostname++)) if(toupper(c) != toupper(*hostname++))
break; break;
} }
return HOST_NOMATCH; return HOST_NOMATCH;
@ -947,14 +947,14 @@ static int hostmatch(const char *hostname, const char *pattern)
static int static int
cert_hostcheck(const char *match_pattern, const char *hostname) cert_hostcheck(const char *match_pattern, const char *hostname)
{ {
if (!match_pattern || !*match_pattern || if(!match_pattern || !*match_pattern ||
!hostname || !*hostname) /* sanity check */ !hostname || !*hostname) /* sanity check */
return 0; return 0;
if(curl_strequal(hostname,match_pattern)) /* trivial case */ if(curl_strequal(hostname,match_pattern)) /* trivial case */
return 1; return 1;
if (hostmatch(hostname,match_pattern) == HOST_MATCH) if(hostmatch(hostname,match_pattern) == HOST_MATCH)
return 1; return 1;
return 0; return 0;
} }
@ -1042,7 +1042,7 @@ static CURLcode verifyhost(struct connectdata *conn,
"I checked the 0.9.6 and 0.9.8 sources before my patch and "I checked the 0.9.6 and 0.9.8 sources before my patch and
it always 0-terminates an IA5String." it always 0-terminates an IA5String."
*/ */
if (cert_hostcheck(altptr, conn->host.name)) if(cert_hostcheck(altptr, conn->host.name))
matched = TRUE; matched = TRUE;
break; break;
@ -1073,15 +1073,15 @@ static CURLcode verifyhost(struct connectdata *conn,
unsigned char *peer_CN = nulstr; unsigned char *peer_CN = nulstr;
X509_NAME *name = X509_get_subject_name(server_cert) ; X509_NAME *name = X509_get_subject_name(server_cert) ;
if (name) if(name)
while ((j=X509_NAME_get_index_by_NID(name,NID_commonName,i))>=0) while((j=X509_NAME_get_index_by_NID(name,NID_commonName,i))>=0)
i=j; i=j;
/* we have the name entry and we will now convert this to a string /* we have the name entry and we will now convert this to a string
that we can use for comparison. Doing this we support BMPstring, that we can use for comparison. Doing this we support BMPstring,
UTF8 etc. */ UTF8 etc. */
if (i>=0) { if(i>=0) {
ASN1_STRING *tmp = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i)); ASN1_STRING *tmp = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name,i));
/* In OpenSSL 0.9.7d and earlier, ASN1_STRING_to_UTF8 fails if the input /* In OpenSSL 0.9.7d and earlier, ASN1_STRING_to_UTF8 fails if the input
@ -1089,11 +1089,11 @@ static CURLcode verifyhost(struct connectdata *conn,
string manually to avoid the problem. This code can be made string manually to avoid the problem. This code can be made
conditional in the future when OpenSSL has been fixed. Work-around conditional in the future when OpenSSL has been fixed. Work-around
brought by Alexis S. L. Carvalho. */ brought by Alexis S. L. Carvalho. */
if (tmp && ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) { if(tmp && ASN1_STRING_type(tmp) == V_ASN1_UTF8STRING) {
j = ASN1_STRING_length(tmp); j = ASN1_STRING_length(tmp);
if (j >= 0) { if(j >= 0) {
peer_CN = OPENSSL_malloc(j+1); peer_CN = OPENSSL_malloc(j+1);
if (peer_CN) { if(peer_CN) {
memcpy(peer_CN, ASN1_STRING_data(tmp), j); memcpy(peer_CN, ASN1_STRING_data(tmp), j);
peer_CN[j] = '\0'; peer_CN[j] = '\0';
} }
@ -1103,7 +1103,7 @@ static CURLcode verifyhost(struct connectdata *conn,
j = ASN1_STRING_to_UTF8(&peer_CN, tmp); j = ASN1_STRING_to_UTF8(&peer_CN, tmp);
} }
if (peer_CN == nulstr) if(peer_CN == nulstr)
peer_CN = NULL; peer_CN = NULL;
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
else { else {
@ -1111,14 +1111,14 @@ static CURLcode verifyhost(struct connectdata *conn,
size_t rc; size_t rc;
rc = Curl_convert_from_utf8(data, peer_CN, strlen(peer_CN)); rc = Curl_convert_from_utf8(data, peer_CN, strlen(peer_CN));
/* Curl_convert_from_utf8 calls failf if unsuccessful */ /* Curl_convert_from_utf8 calls failf if unsuccessful */
if (rc != CURLE_OK) { if(rc != CURLE_OK) {
OPENSSL_free(peer_CN); OPENSSL_free(peer_CN);
return rc; return rc;
} }
} }
#endif /* CURL_DOES_CONVERSIONS */ #endif /* CURL_DOES_CONVERSIONS */
if (!peer_CN) { if(!peer_CN) {
failf(data, failf(data,
"SSL: unable to obtain common name from peer certificate"); "SSL: unable to obtain common name from peer certificate");
return CURLE_PEER_FAILED_VERIFICATION; return CURLE_PEER_FAILED_VERIFICATION;
@ -1149,7 +1149,7 @@ static CURLcode verifyhost(struct connectdata *conn,
static const char *ssl_msg_type(int ssl_ver, int msg) static const char *ssl_msg_type(int ssl_ver, int msg)
{ {
if (ssl_ver == SSL2_VERSION_MAJOR) { if(ssl_ver == SSL2_VERSION_MAJOR) {
switch (msg) { switch (msg) {
case SSL2_MT_ERROR: case SSL2_MT_ERROR:
return "Error"; return "Error";
@ -1171,7 +1171,7 @@ static const char *ssl_msg_type(int ssl_ver, int msg)
return "Client CERT"; return "Client CERT";
} }
} }
else if (ssl_ver == SSL3_VERSION_MAJOR) { else if(ssl_ver == SSL3_VERSION_MAJOR) {
switch (msg) { switch (msg) {
case SSL3_MT_HELLO_REQUEST: case SSL3_MT_HELLO_REQUEST:
return "Hello request"; return "Hello request";
@ -1221,7 +1221,7 @@ static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
char ssl_buf[1024]; char ssl_buf[1024];
int ver, msg_type, txt_len; int ver, msg_type, txt_len;
if (!conn || !conn->data || !conn->data->set.fdebug || if(!conn || !conn->data || !conn->data->set.fdebug ||
(direction != 0 && direction != 1)) (direction != 0 && direction != 1))
return; return;
@ -1234,7 +1234,7 @@ static void ssl_tls_trace(int direction, int ssl_ver, int content_type,
* always pass-up content-type as 0. But the interesting message-type * always pass-up content-type as 0. But the interesting message-type
* is at 'buf[0]'. * is at 'buf[0]'.
*/ */
if (ssl_ver == SSL3_VERSION_MAJOR && content_type != 0) if(ssl_ver == SSL3_VERSION_MAJOR && content_type != 0)
tls_rt_name = tls_rt_type(content_type); tls_rt_name = tls_rt_type(content_type);
else else
tls_rt_name = ""; tls_rt_name = "";
@ -1290,7 +1290,7 @@ Curl_ossl_connect_step1(struct connectdata *conn,
break; break;
} }
if (connssl->ctx) if(connssl->ctx)
SSL_CTX_free(connssl->ctx); SSL_CTX_free(connssl->ctx);
connssl->ctx = SSL_CTX_new(req_method); connssl->ctx = SSL_CTX_new(req_method);
@ -1300,14 +1300,14 @@ Curl_ossl_connect_step1(struct connectdata *conn,
} }
#ifdef SSL_CTRL_SET_MSG_CALLBACK #ifdef SSL_CTRL_SET_MSG_CALLBACK
if (data->set.fdebug && data->set.verbose) { if(data->set.fdebug && data->set.verbose) {
/* the SSL trace callback is only used for verbose logging so we only /* the SSL trace callback is only used for verbose logging so we only
inform about failures of setting it */ inform about failures of setting it */
if (!SSL_CTX_callback_ctrl(connssl->ctx, SSL_CTRL_SET_MSG_CALLBACK, if(!SSL_CTX_callback_ctrl(connssl->ctx, SSL_CTRL_SET_MSG_CALLBACK,
(void (*)(void))ssl_tls_trace)) { (void (*)(void))ssl_tls_trace)) {
infof(data, "SSL: couldn't set callback!\n"); infof(data, "SSL: couldn't set callback!\n");
} }
else if (!SSL_CTX_ctrl(connssl->ctx, SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, else if(!SSL_CTX_ctrl(connssl->ctx, SSL_CTRL_SET_MSG_CALLBACK_ARG, 0,
conn)) { conn)) {
infof(data, "SSL: couldn't set callback argument!\n"); infof(data, "SSL: couldn't set callback argument!\n");
} }
@ -1330,7 +1330,7 @@ Curl_ossl_connect_step1(struct connectdata *conn,
* non-blocking. It doesn't seem to care, but just return with * non-blocking. It doesn't seem to care, but just return with
* SSL_ERROR_WANT_x. * SSL_ERROR_WANT_x.
*/ */
if (data->state.used_interface == Curl_if_multi) if(data->state.used_interface == Curl_if_multi)
SSL_CTX_ctrl(connssl->ctx, BIO_C_SET_NBIO, 1, NULL); SSL_CTX_ctrl(connssl->ctx, BIO_C_SET_NBIO, 1, NULL);
#endif #endif
@ -1354,13 +1354,13 @@ Curl_ossl_connect_step1(struct connectdata *conn,
} }
} }
if (data->set.str[STRING_SSL_CAFILE] || data->set.str[STRING_SSL_CAPATH]) { if(data->set.str[STRING_SSL_CAFILE] || data->set.str[STRING_SSL_CAPATH]) {
/* tell SSL where to find CA certificates that are used to verify /* tell SSL where to find CA certificates that are used to verify
the servers certificate. */ the servers certificate. */
if (!SSL_CTX_load_verify_locations(connssl->ctx, if(!SSL_CTX_load_verify_locations(connssl->ctx,
data->set.str[STRING_SSL_CAFILE], data->set.str[STRING_SSL_CAFILE],
data->set.str[STRING_SSL_CAPATH])) { data->set.str[STRING_SSL_CAPATH])) {
if (data->set.ssl.verifypeer) { if(data->set.ssl.verifypeer) {
/* Fail if we insist on successfully verifying the server. */ /* Fail if we insist on successfully verifying the server. */
failf(data,"error setting certificate verify locations:\n" failf(data,"error setting certificate verify locations:\n"
" CAfile: %s\n CApath: %s\n", " CAfile: %s\n CApath: %s\n",
@ -1408,10 +1408,10 @@ Curl_ossl_connect_step1(struct connectdata *conn,
} }
/* Lets make an SSL structure */ /* Lets make an SSL structure */
if (connssl->handle) if(connssl->handle)
SSL_free(connssl->handle); SSL_free(connssl->handle);
connssl->handle = SSL_new(connssl->ctx); connssl->handle = SSL_new(connssl->ctx);
if (!connssl->handle) { if(!connssl->handle) {
failf(data, "SSL: couldn't create a context (handle)!"); failf(data, "SSL: couldn't create a context (handle)!");
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
@ -1422,7 +1422,7 @@ Curl_ossl_connect_step1(struct connectdata *conn,
/* Check if there's a cached ID we can/should use here! */ /* Check if there's a cached ID we can/should use here! */
if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)) { if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)) {
/* we got a session id, use it! */ /* we got a session id, use it! */
if (!SSL_set_session(connssl->handle, ssl_sessionid)) { if(!SSL_set_session(connssl->handle, ssl_sessionid)) {
failf(data, "SSL: SSL_set_session failed: %s", failf(data, "SSL: SSL_set_session failed: %s",
ERR_error_string(ERR_get_error(),NULL)); ERR_error_string(ERR_get_error(),NULL));
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
@ -1432,7 +1432,7 @@ Curl_ossl_connect_step1(struct connectdata *conn,
} }
/* pass the raw socket into the SSL layers */ /* pass the raw socket into the SSL layers */
if (!SSL_set_fd(connssl->handle, sockfd)) { if(!SSL_set_fd(connssl->handle, sockfd)) {
failf(data, "SSL: SSL_set_fd failed: %s", failf(data, "SSL: SSL_set_fd failed: %s",
ERR_error_string(ERR_get_error(),NULL)); ERR_error_string(ERR_get_error(),NULL));
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
@ -1545,7 +1545,7 @@ Curl_ossl_connect_step2(struct connectdata *conn,
* (RST connection etc.), OpenSSL gives no explanation whatsoever and * (RST connection etc.), OpenSSL gives no explanation whatsoever and
* the SO_ERROR is also lost. * the SO_ERROR is also lost.
*/ */
if (CURLE_SSL_CONNECT_ERROR == rc && errdetail == 0) { if(CURLE_SSL_CONNECT_ERROR == rc && errdetail == 0) {
failf(data, "Unknown SSL protocol error in connection to %s:%d ", failf(data, "Unknown SSL protocol error in connection to %s:%d ",
conn->host.name, conn->port); conn->host.name, conn->port);
return rc; return rc;
@ -1704,19 +1704,19 @@ Curl_ossl_connect_common(struct connectdata *conn,
curl_socket_t sockfd = conn->sock[sockindex]; curl_socket_t sockfd = conn->sock[sockindex];
long timeout_ms; long timeout_ms;
if (ssl_connect_1==connssl->connecting_state) { if(ssl_connect_1==connssl->connecting_state) {
retcode = Curl_ossl_connect_step1(conn, sockindex); retcode = Curl_ossl_connect_step1(conn, sockindex);
if (retcode) if(retcode)
return retcode; return retcode;
} }
timeout_ms = 0; timeout_ms = 0;
while (ssl_connect_2 == connssl->connecting_state || while(ssl_connect_2 == connssl->connecting_state ||
ssl_connect_2_reading == connssl->connecting_state || ssl_connect_2_reading == connssl->connecting_state ||
ssl_connect_2_writing == connssl->connecting_state) { ssl_connect_2_writing == connssl->connecting_state) {
/* if ssl is expecting something, check if it's available. */ /* if ssl is expecting something, check if it's available. */
if (connssl->connecting_state == ssl_connect_2_reading if(connssl->connecting_state == ssl_connect_2_reading
|| connssl->connecting_state == ssl_connect_2_writing) { || connssl->connecting_state == ssl_connect_2_writing) {
int writefd = ssl_connect_2_writing== int writefd = ssl_connect_2_writing==
@ -1730,7 +1730,7 @@ Curl_ossl_connect_common(struct connectdata *conn,
/* readable or writable, go loop in the outer loop */ /* readable or writable, go loop in the outer loop */
break; break;
else if(0 == what) { else if(0 == what) {
if (nonblocking) { if(nonblocking) {
*done = FALSE; *done = FALSE;
return CURLE_OK; return CURLE_OK;
} }
@ -1750,19 +1750,19 @@ Curl_ossl_connect_common(struct connectdata *conn,
/* get the timeout from step2 to avoid computing it twice. */ /* get the timeout from step2 to avoid computing it twice. */
retcode = Curl_ossl_connect_step2(conn, sockindex, &timeout_ms); retcode = Curl_ossl_connect_step2(conn, sockindex, &timeout_ms);
if (retcode) if(retcode)
return retcode; return retcode;
} /* repeat step2 until all transactions are done. */ } /* repeat step2 until all transactions are done. */
if (ssl_connect_3==connssl->connecting_state) { if(ssl_connect_3==connssl->connecting_state) {
retcode = Curl_ossl_connect_step3(conn, sockindex); retcode = Curl_ossl_connect_step3(conn, sockindex);
if (retcode) if(retcode)
return retcode; return retcode;
} }
if (ssl_connect_done==connssl->connecting_state) { if(ssl_connect_done==connssl->connecting_state) {
*done = TRUE; *done = TRUE;
} }
else { else {
@ -1791,7 +1791,7 @@ Curl_ossl_connect(struct connectdata *conn,
bool done = FALSE; bool done = FALSE;
retcode = Curl_ossl_connect_common(conn, sockindex, FALSE, &done); retcode = Curl_ossl_connect_common(conn, sockindex, FALSE, &done);
if (retcode) if(retcode)
return retcode; return retcode;
DEBUGASSERT(done); DEBUGASSERT(done);
@ -1892,7 +1892,7 @@ size_t Curl_ossl_version(char *buffer, size_t size)
return snprintf(buffer, size, "yassl/%s", YASSL_VERSION); return snprintf(buffer, size, "yassl/%s", YASSL_VERSION);
#else /* YASSL_VERSION */ #else /* YASSL_VERSION */
#if (SSLEAY_VERSION_NUMBER >= 0x905000) #if(SSLEAY_VERSION_NUMBER >= 0x905000)
{ {
char sub[2]; char sub[2];
unsigned long ssleay_value; unsigned long ssleay_value;
@ -1919,7 +1919,7 @@ size_t Curl_ossl_version(char *buffer, size_t size)
#else /* SSLEAY_VERSION_NUMBER is less than 0.9.5 */ #else /* SSLEAY_VERSION_NUMBER is less than 0.9.5 */
#if (SSLEAY_VERSION_NUMBER >= 0x900000) #if(SSLEAY_VERSION_NUMBER >= 0x900000)
return snprintf(buffer, size, "OpenSSL/%lx.%lx.%lx", return snprintf(buffer, size, "OpenSSL/%lx.%lx.%lx",
(SSLEAY_VERSION_NUMBER>>28)&0xff, (SSLEAY_VERSION_NUMBER>>28)&0xff,
(SSLEAY_VERSION_NUMBER>>20)&0xff, (SSLEAY_VERSION_NUMBER>>20)&0xff,

View File

@ -40,7 +40,7 @@
/* Range tests can be used for alphanum decoding if characters are consecutive, /* Range tests can be used for alphanum decoding if characters are consecutive,
like in ASCII. Else an array is scanned. Determine this condition now. */ like in ASCII. Else an array is scanned. Determine this condition now. */
#if ('9' - '0') != 9 || ('Z' - 'A') != 25 || ('z' - 'a') != 25 #if('9' - '0') != 9 || ('Z' - 'A') != 25 || ('z' - 'a') != 25
#include <string.h> #include <string.h>
#define NO_RANGE_TEST #define NO_RANGE_TEST
@ -67,35 +67,35 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
/* Skip leading whitespace. */ /* Skip leading whitespace. */
end = (char *)nptr; end = (char *)nptr;
while (ISSPACE(end[0])) { while(ISSPACE(end[0])) {
end++; end++;
} }
/* Handle the sign, if any. */ /* Handle the sign, if any. */
if (end[0] == '-') { if(end[0] == '-') {
is_negative = 1; is_negative = 1;
end++; end++;
} }
else if (end[0] == '+') { else if(end[0] == '+') {
end++; end++;
} }
else if (end[0] == '\0') { else if(end[0] == '\0') {
/* We had nothing but perhaps some whitespace -- there was no number. */ /* We had nothing but perhaps some whitespace -- there was no number. */
if (endptr) { if(endptr) {
*endptr = end; *endptr = end;
} }
return 0; return 0;
} }
/* Handle special beginnings, if present and allowed. */ /* Handle special beginnings, if present and allowed. */
if (end[0] == '0' && end[1] == 'x') { if(end[0] == '0' && end[1] == 'x') {
if (base == 16 || base == 0) { if(base == 16 || base == 0) {
end += 2; end += 2;
base = 16; base = 16;
} }
} }
else if (end[0] == '0') { else if(end[0] == '0') {
if (base == 8 || base == 0) { if(base == 8 || base == 0) {
end++; end++;
base = 8; base = 8;
} }
@ -104,7 +104,7 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
/* Matching strtol, if the base is 0 and it doesn't look like /* Matching strtol, if the base is 0 and it doesn't look like
* the number is octal or hex, we assume it's base 10. * the number is octal or hex, we assume it's base 10.
*/ */
if (base == 0) { if(base == 0) {
base = 10; base = 10;
} }
@ -115,7 +115,7 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
i != -1; i != -1;
end++, i = get_char(end[0], base)) { end++, i = get_char(end[0], base)) {
newval = base * value + i; newval = base * value + i;
if (newval < value) { if(newval < value) {
/* We've overflowed. */ /* We've overflowed. */
overflow = 1; overflow = 1;
break; break;
@ -124,14 +124,14 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
value = newval; value = newval;
} }
if (!overflow) { if(!overflow) {
if (is_negative) { if(is_negative) {
/* Fix the sign. */ /* Fix the sign. */
value *= -1; value *= -1;
} }
} }
else { else {
if (is_negative) if(is_negative)
value = CURL_LLONG_MIN; value = CURL_LLONG_MIN;
else else
value = CURL_LLONG_MAX; value = CURL_LLONG_MAX;
@ -139,7 +139,7 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
SET_ERRNO(ERANGE); SET_ERRNO(ERANGE);
} }
if (endptr) if(endptr)
*endptr = end; *endptr = end;
return value; return value;
@ -159,13 +159,13 @@ static int get_char(char c, int base)
{ {
#ifndef NO_RANGE_TEST #ifndef NO_RANGE_TEST
int value = -1; int value = -1;
if (c <= '9' && c >= '0') { if(c <= '9' && c >= '0') {
value = c - '0'; value = c - '0';
} }
else if (c <= 'Z' && c >= 'A') { else if(c <= 'Z' && c >= 'A') {
value = c - 'A' + 10; value = c - 'A' + 10;
} }
else if (c <= 'z' && c >= 'a') { else if(c <= 'z' && c >= 'a') {
value = c - 'a' + 10; value = c - 'a' + 10;
} }
#else #else
@ -174,16 +174,16 @@ static int get_char(char c, int base)
cp = memchr(valchars, c, 10 + 26 + 26); cp = memchr(valchars, c, 10 + 26 + 26);
if (!cp) if(!cp)
return -1; return -1;
value = cp - valchars; value = cp - valchars;
if (value >= 10 + 26) if(value >= 10 + 26)
value -= 26; /* Lowercase. */ value -= 26; /* Lowercase. */
#endif #endif
if (value >= base) { if(value >= base) {
value = -1; value = -1;
} }

View File

@ -86,7 +86,7 @@
#define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer; #define CURL_SB_CLEAR(x) x->subpointer = x->subbuffer;
#define CURL_SB_TERM(x) { x->subend = x->subpointer; CURL_SB_CLEAR(x); } #define CURL_SB_TERM(x) { x->subend = x->subpointer; CURL_SB_CLEAR(x); }
#define CURL_SB_ACCUM(x,c) \ #define CURL_SB_ACCUM(x,c) \
if (x->subpointer < (x->subbuffer+sizeof x->subbuffer)) { \ if(x->subpointer < (x->subbuffer+sizeof x->subbuffer)) { \
*x->subpointer++ = (c); \ *x->subpointer++ = (c); \
} }
@ -96,7 +96,7 @@
#define CURL_SB_LEN(x) (x->subend - x->subpointer) #define CURL_SB_LEN(x) (x->subend - x->subpointer)
#ifdef CURL_DISABLE_VERBOSE_STRINGS #ifdef CURL_DISABLE_VERBOSE_STRINGS
#define printoption(a,b,c,d) do { } while (0) #define printoption(a,b,c,d) do { } while(0)
#endif #endif
#ifdef USE_WINSOCK #ifdef USE_WINSOCK
@ -213,7 +213,7 @@ check_wsock2 ( struct SessionHandle *data )
/* We must've called this once already, so this call */ /* We must've called this once already, so this call */
/* should always succeed. But, just in case... */ /* should always succeed. But, just in case... */
if (err != 0) { if(err != 0) {
failf(data,"WSAStartup failed (%d)",err); failf(data,"WSAStartup failed (%d)",err);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
@ -223,7 +223,7 @@ check_wsock2 ( struct SessionHandle *data )
WSACleanup(); WSACleanup();
/* Check that our version is supported */ /* Check that our version is supported */
if (LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) || if(LOBYTE(wsaData.wVersion) != LOBYTE(wVersionRequested) ||
HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested)) { HIBYTE(wsaData.wVersion) != HIBYTE(wVersionRequested)) {
/* Our version isn't supported */ /* Our version isn't supported */
failf(data,"insufficient winsock version to support " failf(data,"insufficient winsock version to support "
@ -283,11 +283,11 @@ static void printoption(struct SessionHandle *data,
const char *fmt; const char *fmt;
const char *opt; const char *opt;
if (data->set.verbose) if(data->set.verbose)
{ {
if (cmd == CURL_IAC) if(cmd == CURL_IAC)
{ {
if (CURL_TELCMD_OK(option)) if(CURL_TELCMD_OK(option))
infof(data, "%s IAC %s\n", direction, CURL_TELCMD(option)); infof(data, "%s IAC %s\n", direction, CURL_TELCMD(option));
else else
infof(data, "%s IAC %d\n", direction, option); infof(data, "%s IAC %d\n", direction, option);
@ -296,11 +296,11 @@ static void printoption(struct SessionHandle *data,
{ {
fmt = (cmd == CURL_WILL) ? "WILL" : (cmd == CURL_WONT) ? "WONT" : fmt = (cmd == CURL_WILL) ? "WILL" : (cmd == CURL_WONT) ? "WONT" :
(cmd == CURL_DO) ? "DO" : (cmd == CURL_DONT) ? "DONT" : 0; (cmd == CURL_DO) ? "DO" : (cmd == CURL_DONT) ? "DONT" : 0;
if (fmt) if(fmt)
{ {
if (CURL_TELOPT_OK(option)) if(CURL_TELOPT_OK(option))
opt = CURL_TELOPT(option); opt = CURL_TELOPT(option);
else if (option == CURL_TELOPT_EXOPL) else if(option == CURL_TELOPT_EXOPL)
opt = "EXOPL"; opt = "EXOPL";
else else
opt = NULL; opt = NULL;
@ -705,30 +705,30 @@ static void printsub(struct SessionHandle *data,
{ {
unsigned int i = 0; unsigned int i = 0;
if (data->set.verbose) if(data->set.verbose)
{ {
if (direction) if(direction)
{ {
infof(data, "%s IAC SB ", (direction == '<')? "RCVD":"SENT"); infof(data, "%s IAC SB ", (direction == '<')? "RCVD":"SENT");
if (length >= 3) if(length >= 3)
{ {
int j; int j;
i = pointer[length-2]; i = pointer[length-2];
j = pointer[length-1]; j = pointer[length-1];
if (i != CURL_IAC || j != CURL_SE) if(i != CURL_IAC || j != CURL_SE)
{ {
infof(data, "(terminated by "); infof(data, "(terminated by ");
if (CURL_TELOPT_OK(i)) if(CURL_TELOPT_OK(i))
infof(data, "%s ", CURL_TELOPT(i)); infof(data, "%s ", CURL_TELOPT(i));
else if (CURL_TELCMD_OK(i)) else if(CURL_TELCMD_OK(i))
infof(data, "%s ", CURL_TELCMD(i)); infof(data, "%s ", CURL_TELCMD(i));
else else
infof(data, "%d ", i); infof(data, "%d ", i);
if (CURL_TELOPT_OK(j)) if(CURL_TELOPT_OK(j))
infof(data, "%s", CURL_TELOPT(j)); infof(data, "%s", CURL_TELOPT(j));
else if (CURL_TELCMD_OK(j)) else if(CURL_TELCMD_OK(j))
infof(data, "%s", CURL_TELCMD(j)); infof(data, "%s", CURL_TELCMD(j));
else else
infof(data, "%d", j); infof(data, "%d", j);
@ -737,13 +737,13 @@ static void printsub(struct SessionHandle *data,
} }
length -= 2; length -= 2;
} }
if (length < 1) if(length < 1)
{ {
infof(data, "(Empty suboption?)"); infof(data, "(Empty suboption?)");
return; return;
} }
if (CURL_TELOPT_OK(pointer[0])) { if(CURL_TELOPT_OK(pointer[0])) {
switch(pointer[0]) { switch(pointer[0]) {
case CURL_TELOPT_TTYPE: case CURL_TELOPT_TTYPE:
case CURL_TELOPT_XDISPLOC: case CURL_TELOPT_XDISPLOC:
@ -803,7 +803,7 @@ static void printsub(struct SessionHandle *data,
break; break;
} }
if (direction) if(direction)
{ {
infof(data, "\n"); infof(data, "\n");
} }
@ -965,7 +965,7 @@ void telrcv(struct connectdata *conn,
{ {
case CURL_TS_CR: case CURL_TS_CR:
tn->telrcv_state = CURL_TS_DATA; tn->telrcv_state = CURL_TS_DATA;
if (c == '\0') if(c == '\0')
{ {
break; /* Ignore \0 after CR */ break; /* Ignore \0 after CR */
} }
@ -974,7 +974,7 @@ void telrcv(struct connectdata *conn,
continue; continue;
case CURL_TS_DATA: case CURL_TS_DATA:
if (c == CURL_IAC) if(c == CURL_IAC)
{ {
tn->telrcv_state = CURL_TS_IAC; tn->telrcv_state = CURL_TS_IAC;
break; break;
@ -1049,7 +1049,7 @@ void telrcv(struct connectdata *conn,
continue; continue;
case CURL_TS_SB: case CURL_TS_SB:
if (c == CURL_IAC) if(c == CURL_IAC)
{ {
tn->telrcv_state = CURL_TS_SE; tn->telrcv_state = CURL_TS_SE;
} }
@ -1060,9 +1060,9 @@ void telrcv(struct connectdata *conn,
continue; continue;
case CURL_TS_SE: case CURL_TS_SE:
if (c != CURL_SE) if(c != CURL_SE)
{ {
if (c != CURL_IAC) if(c != CURL_IAC)
{ {
/* /*
* This is an error. We only expect to get "IAC IAC" or "IAC SE". * This is an error. We only expect to get "IAC IAC" or "IAC SE".
@ -1161,20 +1161,20 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
** make sure have it. ** make sure have it.
*/ */
code = check_wsock2(data); code = check_wsock2(data);
if (code) if(code)
return code; return code;
/* OK, so we have WinSock 2.0. We need to dynamically */ /* OK, so we have WinSock 2.0. We need to dynamically */
/* load ws2_32.dll and get the function pointers we need. */ /* load ws2_32.dll and get the function pointers we need. */
wsock2 = LoadLibrary("WS2_32.DLL"); wsock2 = LoadLibrary("WS2_32.DLL");
if (wsock2 == NULL) { if(wsock2 == NULL) {
failf(data,"failed to load WS2_32.DLL (%d)", ERRNO); failf(data,"failed to load WS2_32.DLL (%d)", ERRNO);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
} }
/* Grab a pointer to WSACreateEvent */ /* Grab a pointer to WSACreateEvent */
create_event_func = GetProcAddress(wsock2,"WSACreateEvent"); create_event_func = GetProcAddress(wsock2,"WSACreateEvent");
if (create_event_func == NULL) { if(create_event_func == NULL) {
failf(data,"failed to find WSACreateEvent function (%d)", failf(data,"failed to find WSACreateEvent function (%d)",
ERRNO); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
@ -1183,7 +1183,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* And WSACloseEvent */ /* And WSACloseEvent */
close_event_func = GetProcAddress(wsock2,"WSACloseEvent"); close_event_func = GetProcAddress(wsock2,"WSACloseEvent");
if (close_event_func == NULL) { if(close_event_func == NULL) {
failf(data,"failed to find WSACloseEvent function (%d)", failf(data,"failed to find WSACloseEvent function (%d)",
ERRNO); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
@ -1192,7 +1192,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* And WSAEventSelect */ /* And WSAEventSelect */
event_select_func = GetProcAddress(wsock2,"WSAEventSelect"); event_select_func = GetProcAddress(wsock2,"WSAEventSelect");
if (event_select_func == NULL) { if(event_select_func == NULL) {
failf(data,"failed to find WSAEventSelect function (%d)", failf(data,"failed to find WSAEventSelect function (%d)",
ERRNO); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
@ -1201,7 +1201,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* And WSAEnumNetworkEvents */ /* And WSAEnumNetworkEvents */
enum_netevents_func = GetProcAddress(wsock2,"WSAEnumNetworkEvents"); enum_netevents_func = GetProcAddress(wsock2,"WSAEnumNetworkEvents");
if (enum_netevents_func == NULL) { if(enum_netevents_func == NULL) {
failf(data,"failed to find WSAEnumNetworkEvents function (%d)", failf(data,"failed to find WSAEnumNetworkEvents function (%d)",
ERRNO); ERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
@ -1215,7 +1215,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* First, create a sockets event object */ /* First, create a sockets event object */
event_handle = (WSAEVENT)create_event_func(); event_handle = (WSAEVENT)create_event_func();
if (event_handle == WSA_INVALID_EVENT) { if(event_handle == WSA_INVALID_EVENT) {
failf(data,"WSACreateEvent failed (%d)", SOCKERRNO); failf(data,"WSACreateEvent failed (%d)", SOCKERRNO);
FreeLibrary(wsock2); FreeLibrary(wsock2);
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
@ -1343,7 +1343,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
} }
/* We called WSACreateEvent, so call WSACloseEvent */ /* We called WSACreateEvent, so call WSACloseEvent */
if (close_event_func(event_handle) == FALSE) { if(close_event_func(event_handle) == FALSE) {
infof(data,"WSACloseEvent failed (%d)", SOCKERRNO); infof(data,"WSACloseEvent failed (%d)", SOCKERRNO);
} }
@ -1354,7 +1354,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
enum_netevents_func = NULL; enum_netevents_func = NULL;
/* We called LoadLibrary, so call FreeLibrary */ /* We called LoadLibrary, so call FreeLibrary */
if (!FreeLibrary(wsock2)) if(!FreeLibrary(wsock2))
infof(data,"FreeLibrary(wsock2) failed (%d)", ERRNO); infof(data,"FreeLibrary(wsock2) failed (%d)", ERRNO);
#else #else
pfd[0].fd = sockfd; pfd[0].fd = sockfd;
@ -1363,7 +1363,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
pfd[1].events = POLLIN; pfd[1].events = POLLIN;
interval_ms = 1 * 1000; interval_ms = 1 * 1000;
while (keepon) { while(keepon) {
switch (Curl_poll(pfd, 2, interval_ms)) { switch (Curl_poll(pfd, 2, interval_ms)) {
case -1: /* error, stop reading */ case -1: /* error, stop reading */
keepon = FALSE; keepon = FALSE;
@ -1396,7 +1396,7 @@ static CURLcode Curl_telnet(struct connectdata *conn, bool *done)
/* if we receive 0 or less here, the server closed the connection and /* if we receive 0 or less here, the server closed the connection and
we bail out from this! */ we bail out from this! */
if (nread <= 0) { if(nread <= 0) {
keepon = FALSE; keepon = FALSE;
break; break;
} }

View File

@ -188,12 +188,12 @@ checkhttpprefix(struct SessionHandle *data,
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
/* convert from the network encoding using a scratch area */ /* convert from the network encoding using a scratch area */
char *scratch = calloc(1, strlen(s)+1); char *scratch = calloc(1, strlen(s)+1);
if (NULL == scratch) { if(NULL == scratch) {
failf (data, "Failed to calloc memory for conversion!"); failf (data, "Failed to calloc memory for conversion!");
return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */ return FALSE; /* can't return CURLE_OUT_OF_MEMORY so return FALSE */
} }
strcpy(scratch, s); strcpy(scratch, s);
if (CURLE_OK != Curl_convert_from_network(data, scratch, strlen(s)+1)) { if(CURLE_OK != Curl_convert_from_network(data, scratch, strlen(s)+1)) {
/* Curl_convert_from_network calls failf if unsuccessful */ /* Curl_convert_from_network calls failf if unsuccessful */
free(scratch); free(scratch);
return FALSE; /* can't return CURLE_foobar so return FALSE */ return FALSE; /* can't return CURLE_foobar so return FALSE */
@ -201,15 +201,15 @@ checkhttpprefix(struct SessionHandle *data,
s = scratch; s = scratch;
#endif /* CURL_DOES_CONVERSIONS */ #endif /* CURL_DOES_CONVERSIONS */
while (head) { while(head) {
if (checkprefix(head->data, s)) { if(checkprefix(head->data, s)) {
rc = TRUE; rc = TRUE;
break; break;
} }
head = head->next; head = head->next;
} }
if ((rc != TRUE) && (checkprefix("HTTP/", s))) { if((rc != TRUE) && (checkprefix("HTTP/", s))) {
rc = TRUE; rc = TRUE;
} }
@ -292,7 +292,7 @@ static void read_rewind(struct connectdata *conn,
size_t show; size_t show;
show = MIN(conn->buf_len - conn->read_pos, sizeof(buf)-1); show = MIN(conn->buf_len - conn->read_pos, sizeof(buf)-1);
if (conn->master_buffer) { if(conn->master_buffer) {
memcpy(buf, conn->master_buffer + conn->read_pos, show); memcpy(buf, conn->master_buffer + conn->read_pos, show);
buf[show] = '\0'; buf[show] = '\0';
} }
@ -333,7 +333,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if((k->keepon & (KEEP_READ|KEEP_READ_HOLD)) == KEEP_READ) { if((k->keepon & (KEEP_READ|KEEP_READ_HOLD)) == KEEP_READ) {
fd_read = conn->sockfd; fd_read = conn->sockfd;
#if defined(USE_LIBSSH2) #if defined(USE_LIBSSH2)
if (conn->protocol & (PROT_SCP|PROT_SFTP)) if(conn->protocol & (PROT_SCP|PROT_SFTP))
select_res |= CURL_CSELECT_IN; select_res |= CURL_CSELECT_IN;
#endif /* USE_LIBSSH2 */ #endif /* USE_LIBSSH2 */
} else } else
@ -344,7 +344,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
else else
fd_write = CURL_SOCKET_BAD; fd_write = CURL_SOCKET_BAD;
if (!select_res) { /* Call for select()/poll() only, if read/write/error if(!select_res) { /* Call for select()/poll() only, if read/write/error
status is not known. */ status is not known. */
select_res = Curl_socket_ready(fd_read, fd_write, 0); select_res = Curl_socket_ready(fd_read, fd_write, 0);
} }
@ -371,7 +371,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
size_t bytestoread = buffersize; size_t bytestoread = buffersize;
int readrc; int readrc;
if (k->size != -1 && !k->header) { if(k->size != -1 && !k->header) {
/* make sure we don't read "too much" if we can help it since we /* make sure we don't read "too much" if we can help it since we
might be pipelining and then someone else might want to read what might be pipelining and then someone else might want to read what
follows! */ follows! */
@ -393,7 +393,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if(result>0) if(result>0)
return result; return result;
if ((k->bytecount == 0) && (k->writebytecount == 0)) { if((k->bytecount == 0) && (k->writebytecount == 0)) {
Curl_pgrsTime(data, TIMER_STARTTRANSFER); Curl_pgrsTime(data, TIMER_STARTTRANSFER);
if(k->wait100_after_headers) if(k->wait100_after_headers)
/* set time stamp to compare with when waiting for the 100 */ /* set time stamp to compare with when waiting for the 100 */
@ -405,10 +405,10 @@ CURLcode Curl_readwrite(struct connectdata *conn,
is_empty_data = (bool)((nread == 0) && (k->bodywrites == 0)); is_empty_data = (bool)((nread == 0) && (k->bodywrites == 0));
/* NULL terminate, allowing string ops to be used */ /* NULL terminate, allowing string ops to be used */
if (0 < nread || is_empty_data) { if(0 < nread || is_empty_data) {
k->buf[nread] = 0; k->buf[nread] = 0;
} }
else if (0 >= nread) { else if(0 >= nread) {
/* if we receive 0 or less here, the server closed the connection /* if we receive 0 or less here, the server closed the connection
and we bail out from this! */ and we bail out from this! */
DEBUGF(infof(data, "nread <= 0, server closed connection, bailing\n")); DEBUGF(infof(data, "nread <= 0, server closed connection, bailing\n"));
@ -422,7 +422,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* Since this is a two-state thing, we check if we are parsing /* Since this is a two-state thing, we check if we are parsing
headers at the moment or not. */ headers at the moment or not. */
if (k->header) { if(k->header) {
/* we are in parse-the-header-mode */ /* we are in parse-the-header-mode */
bool stop_reading = FALSE; bool stop_reading = FALSE;
@ -439,11 +439,11 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* data is in network encoding so use 0x0a instead of '\n' */ /* data is in network encoding so use 0x0a instead of '\n' */
k->end_ptr = memchr(k->str_start, 0x0a, nread); k->end_ptr = memchr(k->str_start, 0x0a, nread);
if (!k->end_ptr) { if(!k->end_ptr) {
/* Not a complete header line within buffer, append the data to /* Not a complete header line within buffer, append the data to
the end of the headerbuff. */ the end of the headerbuff. */
if (k->hbuflen + nread >= data->state.headersize) { if(k->hbuflen + nread >= data->state.headersize) {
/* We enlarge the header buffer as it is too small */ /* We enlarge the header buffer as it is too small */
char *newbuff; char *newbuff;
size_t newsize=CURLMAX((k->hbuflen+nread)*3/2, size_t newsize=CURLMAX((k->hbuflen+nread)*3/2,
@ -461,7 +461,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
memcpy(k->hbufp, k->str, nread); memcpy(k->hbufp, k->str, nread);
k->hbufp += nread; k->hbufp += nread;
k->hbuflen += nread; k->hbuflen += nread;
if (!k->headerline && (k->hbuflen>5)) { if(!k->headerline && (k->hbuflen>5)) {
/* make a first check that this looks like a HTTP header */ /* make a first check that this looks like a HTTP header */
if(!checkhttpprefix(data, data->state.headerbuff)) { if(!checkhttpprefix(data, data->state.headerbuff)) {
/* this is not the beginning of a HTTP first header line */ /* this is not the beginning of a HTTP first header line */
@ -488,7 +488,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
* fit in the allocated header buffer, or else we enlarge * fit in the allocated header buffer, or else we enlarge
* it. * it.
*/ */
if (k->hbuflen + full_length >= if(k->hbuflen + full_length >=
data->state.headersize) { data->state.headersize) {
char *newbuff; char *newbuff;
size_t newsize=CURLMAX((k->hbuflen+full_length)*3/2, size_t newsize=CURLMAX((k->hbuflen+full_length)*3/2,
@ -537,23 +537,23 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* headers are in network encoding so /* headers are in network encoding so
use 0x0a and 0x0d instead of '\n' and '\r' */ use 0x0a and 0x0d instead of '\n' and '\r' */
if ((0x0a == *k->p) || (0x0d == *k->p)) { if((0x0a == *k->p) || (0x0d == *k->p)) {
size_t headerlen; size_t headerlen;
/* Zero-length header line means end of headers! */ /* Zero-length header line means end of headers! */
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
if (0x0d == *k->p) { if(0x0d == *k->p) {
*k->p = '\r'; /* replace with CR in host encoding */ *k->p = '\r'; /* replace with CR in host encoding */
k->p++; /* pass the CR byte */ k->p++; /* pass the CR byte */
} }
if (0x0a == *k->p) { if(0x0a == *k->p) {
*k->p = '\n'; /* replace with LF in host encoding */ *k->p = '\n'; /* replace with LF in host encoding */
k->p++; /* pass the LF byte */ k->p++; /* pass the LF byte */
} }
#else #else
if ('\r' == *k->p) if('\r' == *k->p)
k->p++; /* pass the \r byte */ k->p++; /* pass the \r byte */
if ('\n' == *k->p) if('\n' == *k->p)
k->p++; /* pass the \n byte */ k->p++; /* pass the \n byte */
#endif /* CURL_DOES_CONVERSIONS */ #endif /* CURL_DOES_CONVERSIONS */
@ -568,7 +568,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
k->header = TRUE; k->header = TRUE;
k->headerline = 0; /* restart the header line counter */ k->headerline = 0; /* restart the header line counter */
/* if we did wait for this do enable write now! */ /* if we did wait for this do enable write now! */
if (k->write_after_100_header) { if(k->write_after_100_header) {
k->write_after_100_header = FALSE; k->write_after_100_header = FALSE;
k->keepon |= KEEP_WRITE; k->keepon |= KEEP_WRITE;
@ -590,7 +590,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
} }
} }
if (417 == k->httpcode) { if(417 == k->httpcode) {
/* /*
* we got: "417 Expectation Failed" this means: * we got: "417 Expectation Failed" this means:
* we have made a HTTP call and our Expect Header * we have made a HTTP call and our Expect Header
@ -606,7 +606,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
* When all the headers have been parsed, see if we should give * When all the headers have been parsed, see if we should give
* up and return an error. * up and return an error.
*/ */
if (Curl_http_should_fail(conn)) { if(Curl_http_should_fail(conn)) {
failf (data, "The requested URL returned error: %d", failf (data, "The requested URL returned error: %d",
k->httpcode); k->httpcode);
return CURLE_HTTP_RETURNED_ERROR; return CURLE_HTTP_RETURNED_ERROR;
@ -616,7 +616,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* now, only output this if the header AND body are requested: /* now, only output this if the header AND body are requested:
*/ */
writetype = CLIENTWRITE_HEADER; writetype = CLIENTWRITE_HEADER;
if (data->set.include_header) if(data->set.include_header)
writetype |= CLIENTWRITE_BODY; writetype |= CLIENTWRITE_BODY;
headerlen = k->p - data->state.headerbuff; headerlen = k->p - data->state.headerbuff;
@ -633,7 +633,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
data->reqdata.keep.deductheadercount = data->reqdata.keep.deductheadercount =
(100 == k->httpcode)?data->reqdata.keep.headerbytecount:0; (100 == k->httpcode)?data->reqdata.keep.headerbytecount:0;
if (data->reqdata.resume_from && if(data->reqdata.resume_from &&
(data->set.httpreq==HTTPREQ_GET) && (data->set.httpreq==HTTPREQ_GET) &&
(k->httpcode == 416)) { (k->httpcode == 416)) {
/* "Requested Range Not Satisfiable" */ /* "Requested Range Not Satisfiable" */
@ -721,7 +721,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
* Checks for special headers coming up. * Checks for special headers coming up.
*/ */
if (!k->headerline++) { if(!k->headerline++) {
/* This is the first header, it MUST be the error code line /* This is the first header, it MUST be the error code line
or else we consider this to be the body right away! */ or else we consider this to be the body right away! */
int httpversion_major; int httpversion_major;
@ -741,7 +741,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
res = Curl_convert_from_network(data, res = Curl_convert_from_network(data,
&scratch[0], &scratch[0],
SCRATCHSIZE); SCRATCHSIZE);
if (CURLE_OK != res) { if(CURLE_OK != res) {
/* Curl_convert_from_network calls failf if unsuccessful */ /* Curl_convert_from_network calls failf if unsuccessful */
return res; return res;
} }
@ -754,7 +754,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
&httpversion_major, &httpversion_major,
&k->httpversion, &k->httpversion,
&k->httpcode); &k->httpcode);
if (nc==3) { if(nc==3) {
k->httpversion += 10 * httpversion_major; k->httpversion += 10 * httpversion_major;
} }
else { else {
@ -767,8 +767,8 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* If user has set option HTTP200ALIASES, /* If user has set option HTTP200ALIASES,
compare header line against list of aliases compare header line against list of aliases
*/ */
if (!nc) { if(!nc) {
if (checkhttpprefix(data, k->p)) { if(checkhttpprefix(data, k->p)) {
nc = 1; nc = 1;
k->httpcode = 200; k->httpcode = 200;
k->httpversion = 10; k->httpversion = 10;
@ -776,7 +776,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
} }
} }
if (nc) { if(nc) {
data->info.httpcode = k->httpcode; data->info.httpcode = k->httpcode;
data->info.httpversion = k->httpversion; data->info.httpversion = k->httpversion;
@ -788,11 +788,11 @@ CURLcode Curl_readwrite(struct connectdata *conn,
* depending on how authentication is working. Other codes * depending on how authentication is working. Other codes
* are definitely errors, so give up here. * are definitely errors, so give up here.
*/ */
if (data->set.http_fail_on_error && (k->httpcode >= 400) && if(data->set.http_fail_on_error && (k->httpcode >= 400) &&
((k->httpcode != 401) || !conn->bits.user_passwd) && ((k->httpcode != 401) || !conn->bits.user_passwd) &&
((k->httpcode != 407) || !conn->bits.proxy_user_passwd) ) { ((k->httpcode != 407) || !conn->bits.proxy_user_passwd) ) {
if (data->reqdata.resume_from && if(data->reqdata.resume_from &&
(data->set.httpreq==HTTPREQ_GET) && (data->set.httpreq==HTTPREQ_GET) &&
(k->httpcode == 416)) { (k->httpcode == 416)) {
/* "Requested Range Not Satisfiable", just proceed and /* "Requested Range Not Satisfiable", just proceed and
@ -848,7 +848,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
#ifdef CURL_DOES_CONVERSIONS #ifdef CURL_DOES_CONVERSIONS
/* convert from the network encoding */ /* convert from the network encoding */
result = Curl_convert_from_network(data, k->p, strlen(k->p)); result = Curl_convert_from_network(data, k->p, strlen(k->p));
if (CURLE_OK != result) { if(CURLE_OK != result) {
return(result); return(result);
} }
/* Curl_convert_from_network calls failf if unsuccessful */ /* Curl_convert_from_network calls failf if unsuccessful */
@ -858,10 +858,10 @@ CURLcode Curl_readwrite(struct connectdata *conn,
the header completely if we get a 416 response as then we're the header completely if we get a 416 response as then we're
resuming a document that we don't get, and this header contains resuming a document that we don't get, and this header contains
info about the true size of the document we didn't get now. */ info about the true size of the document we didn't get now. */
if (!k->ignorecl && !data->set.ignorecl && if(!k->ignorecl && !data->set.ignorecl &&
checkprefix("Content-Length:", k->p)) { checkprefix("Content-Length:", k->p)) {
contentlength = curlx_strtoofft(k->p+15, NULL, 10); contentlength = curlx_strtoofft(k->p+15, NULL, 10);
if (data->set.max_filesize && if(data->set.max_filesize &&
contentlength > data->set.max_filesize) { contentlength > data->set.max_filesize) {
failf(data, "Maximum file size exceeded"); failf(data, "Maximum file size exceeded");
return CURLE_FILESIZE_EXCEEDED; return CURLE_FILESIZE_EXCEEDED;
@ -884,7 +884,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
} }
} }
/* check for Content-Type: header lines to get the mime-type */ /* check for Content-Type: header lines to get the mime-type */
else if (checkprefix("Content-Type:", k->p)) { else if(checkprefix("Content-Type:", k->p)) {
char *start; char *start;
char *end; char *end;
size_t len; size_t len;
@ -913,7 +913,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
Curl_safefree(data->info.contenttype); Curl_safefree(data->info.contenttype);
data->info.contenttype = malloc(len + 1); data->info.contenttype = malloc(len + 1);
if (NULL == data->info.contenttype) if(NULL == data->info.contenttype)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
/* copy the content-type string */ /* copy the content-type string */
@ -957,7 +957,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
conn->bits.close = FALSE; /* don't close when done */ conn->bits.close = FALSE; /* don't close when done */
infof(data, "HTTP/1.0 connection set to keep alive!\n"); infof(data, "HTTP/1.0 connection set to keep alive!\n");
} }
else if (Curl_compareheader(k->p, "Connection:", "close")) { else if(Curl_compareheader(k->p, "Connection:", "close")) {
/* /*
* [RFC 2616, section 8.1.2.1] * [RFC 2616, section 8.1.2.1]
* "Connection: close" is HTTP/1.1 language and means that * "Connection: close" is HTTP/1.1 language and means that
@ -966,7 +966,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
*/ */
conn->bits.close = TRUE; /* close when done */ conn->bits.close = TRUE; /* close when done */
} }
else if (Curl_compareheader(k->p, else if(Curl_compareheader(k->p,
"Transfer-Encoding:", "chunked")) { "Transfer-Encoding:", "chunked")) {
/* /*
* [RFC 2616, section 3.6.1] A 'chunked' transfer encoding * [RFC 2616, section 3.6.1] A 'chunked' transfer encoding
@ -982,7 +982,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
Curl_httpchunk_init(conn); Curl_httpchunk_init(conn);
} }
else if (checkprefix("Trailer:", k->p) || else if(checkprefix("Trailer:", k->p) ||
checkprefix("Trailers:", k->p)) { checkprefix("Trailers:", k->p)) {
/* /*
* This test helps Curl_httpchunk_read() to determine to look * This test helps Curl_httpchunk_read() to determine to look
@ -995,7 +995,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
conn->bits.trailerHdrPresent = TRUE; conn->bits.trailerHdrPresent = TRUE;
} }
else if (checkprefix("Content-Encoding:", k->p) && else if(checkprefix("Content-Encoding:", k->p) &&
data->set.str[STRING_ENCODING]) { data->set.str[STRING_ENCODING]) {
/* /*
* Process Content-Encoding. Look for the values: identity, * Process Content-Encoding. Look for the values: identity,
@ -1013,18 +1013,18 @@ CURLcode Curl_readwrite(struct connectdata *conn,
; /* empty loop */ ; /* empty loop */
/* Record the content-encoding for later use */ /* Record the content-encoding for later use */
if (checkprefix("identity", start)) if(checkprefix("identity", start))
k->content_encoding = IDENTITY; k->content_encoding = IDENTITY;
else if (checkprefix("deflate", start)) else if(checkprefix("deflate", start))
k->content_encoding = DEFLATE; k->content_encoding = DEFLATE;
else if (checkprefix("gzip", start) else if(checkprefix("gzip", start)
|| checkprefix("x-gzip", start)) || checkprefix("x-gzip", start))
k->content_encoding = GZIP; k->content_encoding = GZIP;
else if (checkprefix("compress", start) else if(checkprefix("compress", start)
|| checkprefix("x-compress", start)) || checkprefix("x-compress", start))
k->content_encoding = COMPRESS; k->content_encoding = COMPRESS;
} }
else if (checkprefix("Content-Range:", k->p)) { else if(checkprefix("Content-Range:", k->p)) {
/* Content-Range: bytes [num]- /* Content-Range: bytes [num]-
Content-Range: bytes: [num]- Content-Range: bytes: [num]-
Content-Range: [num]- Content-Range: [num]-
@ -1042,7 +1042,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
k->offset = curlx_strtoofft(ptr, NULL, 10); k->offset = curlx_strtoofft(ptr, NULL, 10);
if (data->reqdata.resume_from == k->offset) if(data->reqdata.resume_from == k->offset)
/* we asked for a resume and we got it */ /* we asked for a resume and we got it */
k->content_range = TRUE; k->content_range = TRUE;
} }
@ -1077,7 +1077,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if(result) if(result)
return result; return result;
} }
else if ((k->httpcode >= 300 && k->httpcode < 400) && else if((k->httpcode >= 300 && k->httpcode < 400) &&
checkprefix("Location:", k->p)) { checkprefix("Location:", k->p)) {
if(data->set.http_follow_location) { if(data->set.http_follow_location) {
/* this is the URL that the server advices us to get instead */ /* this is the URL that the server advices us to get instead */
@ -1119,7 +1119,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
*/ */
writetype = CLIENTWRITE_HEADER; writetype = CLIENTWRITE_HEADER;
if (data->set.include_header) if(data->set.include_header)
writetype |= CLIENTWRITE_BODY; writetype |= CLIENTWRITE_BODY;
if(data->set.verbose) if(data->set.verbose)
@ -1137,7 +1137,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
k->hbufp = data->state.headerbuff; k->hbufp = data->state.headerbuff;
k->hbuflen = 0; k->hbuflen = 0;
} }
while (!stop_reading && *k->str); /* header line within buffer */ while(!stop_reading && *k->str); /* header line within buffer */
if(stop_reading) if(stop_reading)
/* We've stopped dealing with input, get out of the do-while loop */ /* We've stopped dealing with input, get out of the do-while loop */
@ -1152,7 +1152,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* This is not an 'else if' since it may be a rest from the header /* This is not an 'else if' since it may be a rest from the header
parsing, where the beginning of the buffer is headers and the end parsing, where the beginning of the buffer is headers and the end
is non-headers. */ is non-headers. */
if (k->str && !k->header && (nread > 0 || is_empty_data)) { if(k->str && !k->header && (nread > 0 || is_empty_data)) {
if(0 == k->bodywrites && !is_empty_data) { if(0 == k->bodywrites && !is_empty_data) {
/* These checks are only made the first time we are about to /* These checks are only made the first time we are about to
@ -1160,7 +1160,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
if(conn->protocol&PROT_HTTP) { if(conn->protocol&PROT_HTTP) {
/* HTTP-only checks */ /* HTTP-only checks */
if (data->reqdata.newurl) { if(data->reqdata.newurl) {
if(conn->bits.close) { if(conn->bits.close) {
/* Abort after the headers if "follow Location" is set /* Abort after the headers if "follow Location" is set
and we're set to close anyway. */ and we're set to close anyway. */
@ -1174,7 +1174,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
k->ignorebody = TRUE; k->ignorebody = TRUE;
infof(data, "Ignoring the response-body\n"); infof(data, "Ignoring the response-body\n");
} }
if (data->reqdata.resume_from && !k->content_range && if(data->reqdata.resume_from && !k->content_range &&
(data->set.httpreq==HTTPREQ_GET) && (data->set.httpreq==HTTPREQ_GET) &&
!k->ignorebody) { !k->ignorebody) {
/* we wanted to resume a download, although the server doesn't /* we wanted to resume a download, although the server doesn't
@ -1263,7 +1263,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
Push it back to be read on the next pass. */ Push it back to be read on the next pass. */
dataleft = conn->chunk.dataleft; dataleft = conn->chunk.dataleft;
if (dataleft != 0) { if(dataleft != 0) {
infof(conn->data, "Leftovers after chunking. " infof(conn->data, "Leftovers after chunking. "
" Rewinding %d bytes\n",dataleft); " Rewinding %d bytes\n",dataleft);
read_rewind(conn, dataleft); read_rewind(conn, dataleft);
@ -1278,7 +1278,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* The 'excess' amount below can't be more than BUFSIZE which /* The 'excess' amount below can't be more than BUFSIZE which
always will fit in a size_t */ always will fit in a size_t */
size_t excess = (size_t)(k->bytecount + nread - k->maxdownload); size_t excess = (size_t)(k->bytecount + nread - k->maxdownload);
if (excess > 0 && !k->ignorebody) { if(excess > 0 && !k->ignorebody) {
infof(data, infof(data,
"Rewinding stream by : %d" "Rewinding stream by : %d"
" bytes on url %s (size = %" FORMAT_OFF_T " bytes on url %s (size = %" FORMAT_OFF_T
@ -1360,9 +1360,9 @@ CURLcode Curl_readwrite(struct connectdata *conn,
return result; return result;
} }
} /* if (! header and data to read ) */ } /* if(! header and data to read ) */
if (is_empty_data) { if(is_empty_data) {
/* if we received nothing, the server closed the connection and we /* if we received nothing, the server closed the connection and we
are done */ are done */
k->keepon &= ~KEEP_READ; k->keepon &= ~KEEP_READ;
@ -1381,7 +1381,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
ssize_t bytes_written; ssize_t bytes_written;
bool writedone=TRUE; bool writedone=TRUE;
if ((k->bytecount == 0) && (k->writebytecount == 0)) if((k->bytecount == 0) && (k->writebytecount == 0))
Curl_pgrsTime(data, TIMER_STARTTRANSFER); Curl_pgrsTime(data, TIMER_STARTTRANSFER);
didwhat |= KEEP_WRITE; didwhat |= KEEP_WRITE;
@ -1427,7 +1427,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* the signed int typecase of nread of for systems that has /* the signed int typecase of nread of for systems that has
unsigned size_t */ unsigned size_t */
if (nread<=0) { if(nread<=0) {
/* done */ /* done */
k->keepon &= ~KEEP_WRITE; /* we're done writing */ k->keepon &= ~KEEP_WRITE; /* we're done writing */
writedone = TRUE; writedone = TRUE;
@ -1446,9 +1446,9 @@ CURLcode Curl_readwrite(struct connectdata *conn,
/* convert LF to CRLF if so asked */ /* convert LF to CRLF if so asked */
#ifdef CURL_DO_LINEEND_CONV #ifdef CURL_DO_LINEEND_CONV
/* always convert if we're FTPing in ASCII mode */ /* always convert if we're FTPing in ASCII mode */
if ((data->set.crlf) || (data->set.prefer_ascii)) { if((data->set.crlf) || (data->set.prefer_ascii)) {
#else #else
if (data->set.crlf) { if(data->set.crlf) {
#endif /* CURL_DO_LINEEND_CONV */ #endif /* CURL_DO_LINEEND_CONV */
if(data->state.scratch == NULL) if(data->state.scratch == NULL)
data->state.scratch = malloc(2*BUFSIZE); data->state.scratch = malloc(2*BUFSIZE);
@ -1463,10 +1463,10 @@ CURLcode Curl_readwrite(struct connectdata *conn,
* must be used instead of the escape sequences \r & \n. * must be used instead of the escape sequences \r & \n.
*/ */
for(i = 0, si = 0; i < nread; i++, si++) { for(i = 0, si = 0; i < nread; i++, si++) {
if (data->reqdata.upload_fromhere[i] == 0x0a) { if(data->reqdata.upload_fromhere[i] == 0x0a) {
data->state.scratch[si++] = 0x0d; data->state.scratch[si++] = 0x0d;
data->state.scratch[si] = 0x0a; data->state.scratch[si] = 0x0a;
if (!data->set.crlf) { if(!data->set.crlf) {
/* we're here only because FTP is in ASCII mode... /* we're here only because FTP is in ASCII mode...
bump infilesize for the LF we just added */ bump infilesize for the LF we just added */
data->set.infilesize++; data->set.infilesize++;
@ -1550,7 +1550,7 @@ CURLcode Curl_readwrite(struct connectdata *conn,
} }
else { else {
/* no read no write, this is a timeout? */ /* no read no write, this is a timeout? */
if (k->write_after_100_header) { if(k->write_after_100_header) {
/* This should allow some time for the header to arrive, but only a /* This should allow some time for the header to arrive, but only a
very short time as otherwise it'll be too much wasted times too very short time as otherwise it'll be too much wasted times too
often. */ often. */
@ -1577,12 +1577,12 @@ CURLcode Curl_readwrite(struct connectdata *conn,
result = CURLE_ABORTED_BY_CALLBACK; result = CURLE_ABORTED_BY_CALLBACK;
else else
result = Curl_speedcheck(data, k->now); result = Curl_speedcheck(data, k->now);
if (result) if(result)
return result; return result;
if (data->set.timeout && if(data->set.timeout &&
(Curl_tvdiff(k->now, k->start) >= data->set.timeout)) { (Curl_tvdiff(k->now, k->start) >= data->set.timeout)) {
if (k->size != -1) { if(k->size != -1) {
failf(data, "Operation timed out after %ld milliseconds with %" failf(data, "Operation timed out after %ld milliseconds with %"
FORMAT_OFF_T " out of %" FORMAT_OFF_T " bytes received", FORMAT_OFF_T " out of %" FORMAT_OFF_T " bytes received",
data->set.timeout, k->bytecount, k->size); data->set.timeout, k->bytecount, k->size);
@ -1680,7 +1680,7 @@ CURLcode Curl_readwrite_init(struct connectdata *conn)
Curl_pgrsSetUploadCounter(data, 0); Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0); Curl_pgrsSetDownloadCounter(data, 0);
if (!conn->bits.getheader) { if(!conn->bits.getheader) {
k->header = FALSE; k->header = FALSE;
if(k->size > 0) if(k->size > 0)
Curl_pgrsSetDownloadSize(data, k->size); Curl_pgrsSetDownloadSize(data, k->size);
@ -1702,7 +1702,7 @@ CURLcode Curl_readwrite_init(struct connectdata *conn)
Thus, we must check if the request has been sent before we set the Thus, we must check if the request has been sent before we set the
state info where we wait for the 100-return code state info where we wait for the 100-return code
*/ */
if (data->state.expect100header && if(data->state.expect100header &&
(data->reqdata.proto.http->sending == HTTPSEND_BODY)) { (data->reqdata.proto.http->sending == HTTPSEND_BODY)) {
/* wait with write until we either got 100-continue or a timeout */ /* wait with write until we either got 100-continue or a timeout */
k->write_after_100_header = TRUE; k->write_after_100_header = TRUE;
@ -1819,14 +1819,14 @@ Transfer(struct connectdata *conn)
if(!conn->bits.getheader && conn->bits.no_body) if(!conn->bits.getheader && conn->bits.no_body)
return CURLE_OK; return CURLE_OK;
while (!done) { while(!done) {
curl_socket_t fd_read; curl_socket_t fd_read;
curl_socket_t fd_write; curl_socket_t fd_write;
/* limit-rate logic: if speed exceeds threshold, then do not include fd in /* limit-rate logic: if speed exceeds threshold, then do not include fd in
select set. The current speed is recalculated in each Curl_readwrite() select set. The current speed is recalculated in each Curl_readwrite()
call */ call */
if ((k->keepon & KEEP_WRITE) && if((k->keepon & KEEP_WRITE) &&
(!data->set.max_send_speed || (!data->set.max_send_speed ||
(data->progress.ulspeed < data->set.max_send_speed) )) { (data->progress.ulspeed < data->set.max_send_speed) )) {
fd_write = conn->writesockfd; fd_write = conn->writesockfd;
@ -1838,7 +1838,7 @@ Transfer(struct connectdata *conn)
k->keepon |= KEEP_WRITE_HOLD; /* hold it */ k->keepon |= KEEP_WRITE_HOLD; /* hold it */
} }
if ((k->keepon & KEEP_READ) && if((k->keepon & KEEP_READ) &&
(!data->set.max_recv_speed || (!data->set.max_recv_speed ||
(data->progress.dlspeed < data->set.max_recv_speed)) ) { (data->progress.dlspeed < data->set.max_recv_speed)) ) {
fd_read = conn->sockfd; fd_read = conn->sockfd;
@ -2034,7 +2034,7 @@ CURLcode Curl_follow(struct SessionHandle *data,
char *newest; char *newest;
if(!retry) { if(!retry) {
if ((data->set.maxredirs != -1) && if((data->set.maxredirs != -1) &&
(data->set.followlocation >= data->set.maxredirs)) { (data->set.followlocation >= data->set.maxredirs)) {
failf(data,"Maximum (%d) redirects followed", data->set.maxredirs); failf(data,"Maximum (%d) redirects followed", data->set.maxredirs);
return CURLE_TOO_MANY_REDIRECTS; return CURLE_TOO_MANY_REDIRECTS;
@ -2350,7 +2350,7 @@ Curl_connect_host(struct SessionHandle *data,
the Curl_connect(), we detect it here and act as if we are redirected the Curl_connect(), we detect it here and act as if we are redirected
to the new URL */ to the new URL */
urlchanged = data->change.url_changed; urlchanged = data->change.url_changed;
if ((CURLE_OK == res) && urlchanged) { if((CURLE_OK == res) && urlchanged) {
res = Curl_done(conn, res, FALSE); res = Curl_done(conn, res, FALSE);
if(CURLE_OK == res) { if(CURLE_OK == res) {
char *gotourl = strdup(data->change.url); char *gotourl = strdup(data->change.url);
@ -2359,7 +2359,7 @@ Curl_connect_host(struct SessionHandle *data,
free(gotourl); free(gotourl);
} }
} }
} while (urlchanged && res == CURLE_OK); } while(urlchanged && res == CURLE_OK);
return res; return res;
} }

192
lib/url.c
View File

@ -300,15 +300,15 @@ static CURLcode Curl_setstropt(char **charp, char * s)
/* Release the previous storage at `charp' and replace by a dynamic storage /* Release the previous storage at `charp' and replace by a dynamic storage
copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */ copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */
if (*charp) { if(*charp) {
free(*charp); free(*charp);
*charp = (char *) NULL; *charp = (char *) NULL;
} }
if (s) { if(s) {
s = strdup(s); s = strdup(s);
if (!s) if(!s)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
*charp = s; *charp = s;
@ -332,7 +332,7 @@ CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src)
/* duplicate all strings */ /* duplicate all strings */
for(i=(enum dupstring)0; i< STRING_LAST; i++) { for(i=(enum dupstring)0; i< STRING_LAST; i++) {
r = Curl_setstropt(&dst->set.str[i], src->set.str[i]); r = Curl_setstropt(&dst->set.str[i], src->set.str[i]);
if (r != CURLE_OK) if(r != CURLE_OK)
break; break;
} }
@ -454,8 +454,8 @@ CURLcode Curl_close(struct SessionHandle *data)
return CURLE_OK; return CURLE_OK;
} }
if ( ! (data->share && data->share->hostcache) ) { if( ! (data->share && data->share->hostcache) ) {
if ( !Curl_global_host_cache_use(data)) { if( !Curl_global_host_cache_use(data)) {
Curl_hash_destroy(data->dns.hostcache); Curl_hash_destroy(data->dns.hostcache);
} }
} }
@ -493,19 +493,19 @@ CURLcode Curl_close(struct SessionHandle *data)
#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV) #if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
/* close iconv conversion descriptors */ /* close iconv conversion descriptors */
if (data->inbound_cd != (iconv_t)-1) { if(data->inbound_cd != (iconv_t)-1) {
iconv_close(data->inbound_cd); iconv_close(data->inbound_cd);
} }
if (data->outbound_cd != (iconv_t)-1) { if(data->outbound_cd != (iconv_t)-1) {
iconv_close(data->outbound_cd); iconv_close(data->outbound_cd);
} }
if (data->utf8_cd != (iconv_t)-1) { if(data->utf8_cd != (iconv_t)-1) {
iconv_close(data->utf8_cd); iconv_close(data->utf8_cd);
} }
#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */ #endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
/* No longer a dirty share, if it exists */ /* No longer a dirty share, if it exists */
if (data->share) { if(data->share) {
Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE); Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
data->share->dirty--; data->share->dirty--;
Curl_share_unlock(data, CURL_LOCK_DATA_SHARE); Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
@ -526,7 +526,7 @@ struct conncache *Curl_mk_connc(int type,
struct conncache *c; struct conncache *c;
long default_amount; long default_amount;
if (type == CONNCACHE_PRIVATE) { if(type == CONNCACHE_PRIVATE) {
default_amount = (amount < 0) ? 5 : amount; default_amount = (amount < 0) ? 5 : amount;
} }
else { else {
@ -537,7 +537,7 @@ struct conncache *Curl_mk_connc(int type,
if(!c) if(!c)
return NULL; return NULL;
if ((size_t)(default_amount) > ((size_t)-1) / sizeof(struct connectdata *)) if((size_t)(default_amount) > ((size_t)-1) / sizeof(struct connectdata *))
default_amount = ((size_t)-1) / sizeof(struct connectdata *); default_amount = ((size_t)-1) / sizeof(struct connectdata *);
c->connects = calloc(sizeof(struct connectdata *), (size_t)default_amount); c->connects = calloc(sizeof(struct connectdata *), (size_t)default_amount);
@ -650,10 +650,10 @@ CURLcode Curl_open(struct SessionHandle **curl)
data->magic = CURLEASY_MAGIC_NUMBER; data->magic = CURLEASY_MAGIC_NUMBER;
#ifdef USE_ARES #ifdef USE_ARES
if ((status = ares_init(&data->state.areschannel)) != ARES_SUCCESS) { if((status = ares_init(&data->state.areschannel)) != ARES_SUCCESS) {
DEBUGF(fprintf(stderr, "Error: ares_init failed\n")); DEBUGF(fprintf(stderr, "Error: ares_init failed\n"));
free(data); free(data);
if (status == ARES_ENOMEM) if(status == ARES_ENOMEM)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
else else
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
@ -775,7 +775,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
case CURLOPT_DNS_USE_GLOBAL_CACHE: case CURLOPT_DNS_USE_GLOBAL_CACHE:
{ {
long use_cache = va_arg(param, long); long use_cache = va_arg(param, long);
if (use_cache) if(use_cache)
Curl_global_host_cache_init(); Curl_global_host_cache_init();
data->set.global_dns_cache = (bool)(0 != use_cache); data->set.global_dns_cache = (bool)(0 != use_cache);
@ -1032,14 +1032,14 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
*/ */
argptr = va_arg(param, char *); argptr = va_arg(param, char *);
if (!argptr || data->set.postfieldsize == -1) if(!argptr || data->set.postfieldsize == -1)
result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr); result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
else { else {
/* /*
* Check that requested length does not overflow the size_t type. * Check that requested length does not overflow the size_t type.
*/ */
if ((data->set.postfieldsize < 0) || if((data->set.postfieldsize < 0) ||
((sizeof(curl_off_t) != sizeof(size_t)) && ((sizeof(curl_off_t) != sizeof(size_t)) &&
(data->set.postfieldsize > (curl_off_t)((size_t)-1)))) (data->set.postfieldsize > (curl_off_t)((size_t)-1))))
result = CURLE_OUT_OF_MEMORY; result = CURLE_OUT_OF_MEMORY;
@ -1055,10 +1055,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
*/ */
p = malloc((size_t)(data->set.postfieldsize?data->set.postfieldsize:1)); p = malloc((size_t)(data->set.postfieldsize?data->set.postfieldsize:1));
if (!p) if(!p)
result = CURLE_OUT_OF_MEMORY; result = CURLE_OUT_OF_MEMORY;
else { else {
if (data->set.postfieldsize) if(data->set.postfieldsize)
memcpy(p, argptr, data->set.postfieldsize); memcpy(p, argptr, data->set.postfieldsize);
data->set.str[STRING_COPYPOSTFIELDS] = p; data->set.str[STRING_COPYPOSTFIELDS] = p;
@ -1087,7 +1087,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
*/ */
bigsize = va_arg(param, long); bigsize = va_arg(param, long);
if (data->set.postfieldsize < bigsize && if(data->set.postfieldsize < bigsize &&
data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) { data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
/* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */ /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
(void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL); (void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
@ -1104,7 +1104,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
*/ */
bigsize = va_arg(param, curl_off_t); bigsize = va_arg(param, curl_off_t);
if (data->set.postfieldsize < bigsize && if(data->set.postfieldsize < bigsize &&
data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) { data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
/* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */ /* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
(void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL); (void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
@ -1475,7 +1475,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
result = Curl_setstropt(&data->set.str[STRING_SET_URL], result = Curl_setstropt(&data->set.str[STRING_SET_URL],
va_arg(param, char *)); va_arg(param, char *));
data->change.url = data->set.str[STRING_SET_URL]; data->change.url = data->set.str[STRING_SET_URL];
if (data->change.url) if(data->change.url)
data->change.url_changed = TRUE; data->change.url_changed = TRUE;
break; break;
case CURLOPT_PORT: case CURLOPT_PORT:
@ -1694,7 +1694,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
* String that holds the SSL crypto engine. * String that holds the SSL crypto engine.
*/ */
argptr = va_arg(param, char *); argptr = va_arg(param, char *);
if (argptr && argptr[0]) if(argptr && argptr[0])
result = Curl_ssl_set_engine(data, argptr); result = Curl_ssl_set_engine(data, argptr);
break; break;
@ -1849,7 +1849,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
if(data->share->cookies) { if(data->share->cookies) {
/* use shared cookie list, first free own one if any */ /* use shared cookie list, first free own one if any */
if (data->cookies) if(data->cookies)
Curl_cookie_cleanup(data->cookies); Curl_cookie_cleanup(data->cookies);
data->cookies = data->share->cookies; data->cookies = data->share->cookies;
} }
@ -2049,7 +2049,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
static void conn_free(struct connectdata *conn) static void conn_free(struct connectdata *conn)
{ {
if (!conn) if(!conn)
return; return;
/* close possibly still open sockets */ /* close possibly still open sockets */
@ -2161,7 +2161,7 @@ CURLcode Curl_disconnect(struct connectdata *conn)
Curl_ssl_close(conn, FIRSTSOCKET); Curl_ssl_close(conn, FIRSTSOCKET);
/* Indicate to all handles on the pipe that we're dead */ /* Indicate to all handles on the pipe that we're dead */
if (IsPipeliningEnabled(data)) { if(IsPipeliningEnabled(data)) {
signalPipeClose(conn->send_pipe); signalPipeClose(conn->send_pipe);
signalPipeClose(conn->recv_pipe); signalPipeClose(conn->recv_pipe);
} }
@ -2192,7 +2192,7 @@ static bool SocketIsDead(curl_socket_t sock)
static bool IsPipeliningPossible(const struct SessionHandle *handle) static bool IsPipeliningPossible(const struct SessionHandle *handle)
{ {
if (handle->multi && Curl_multi_canPipeline(handle->multi) && if(handle->multi && Curl_multi_canPipeline(handle->multi) &&
(handle->set.httpreq == HTTPREQ_GET || (handle->set.httpreq == HTTPREQ_GET ||
handle->set.httpreq == HTTPREQ_HEAD) && handle->set.httpreq == HTTPREQ_HEAD) &&
handle->set.httpversion != CURL_HTTP_VERSION_1_0) handle->set.httpversion != CURL_HTTP_VERSION_1_0)
@ -2203,7 +2203,7 @@ static bool IsPipeliningPossible(const struct SessionHandle *handle)
static bool IsPipeliningEnabled(const struct SessionHandle *handle) static bool IsPipeliningEnabled(const struct SessionHandle *handle)
{ {
if (handle->multi && Curl_multi_canPipeline(handle->multi)) if(handle->multi && Curl_multi_canPipeline(handle->multi))
return TRUE; return TRUE;
return FALSE; return FALSE;
@ -2219,7 +2219,7 @@ CURLcode Curl_addHandleToPipeline(struct SessionHandle *data,
infof(data, "PIPE when no PIPE supposed!\n"); infof(data, "PIPE when no PIPE supposed!\n");
} }
#endif #endif
if (!Curl_llist_insert_next(pipeline, pipeline->tail, data)) if(!Curl_llist_insert_next(pipeline, pipeline->tail, data))
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
return CURLE_OK; return CURLE_OK;
} }
@ -2231,8 +2231,8 @@ int Curl_removeHandleFromPipeline(struct SessionHandle *handle,
struct curl_llist_element *curr; struct curl_llist_element *curr;
curr = pipeline->head; curr = pipeline->head;
while (curr) { while(curr) {
if (curr->ptr == handle) { if(curr->ptr == handle) {
Curl_llist_remove(pipeline, curr, NULL); Curl_llist_remove(pipeline, curr, NULL);
return 1; /* we removed a handle */ return 1; /* we removed a handle */
} }
@ -2248,7 +2248,7 @@ static void Curl_printPipeline(struct curl_llist *pipeline)
struct curl_llist_element *curr; struct curl_llist_element *curr;
curr = pipeline->head; curr = pipeline->head;
while (curr) { while(curr) {
struct SessionHandle *data = (struct SessionHandle *) curr->ptr; struct SessionHandle *data = (struct SessionHandle *) curr->ptr;
infof(data, "Handle in pipeline: %s\n", data->reqdata.path); infof(data, "Handle in pipeline: %s\n", data->reqdata.path);
curr = curr->next; curr = curr->next;
@ -2260,7 +2260,7 @@ bool Curl_isHandleAtHead(struct SessionHandle *handle,
struct curl_llist *pipeline) struct curl_llist *pipeline)
{ {
struct curl_llist_element *curr = pipeline->head; struct curl_llist_element *curr = pipeline->head;
if (curr) { if(curr) {
return (bool)(curr->ptr == handle); return (bool)(curr->ptr == handle);
} }
@ -2270,7 +2270,7 @@ bool Curl_isHandleAtHead(struct SessionHandle *handle,
static struct SessionHandle* gethandleathead(struct curl_llist *pipeline) static struct SessionHandle* gethandleathead(struct curl_llist *pipeline)
{ {
struct curl_llist_element *curr = pipeline->head; struct curl_llist_element *curr = pipeline->head;
if (curr) { if(curr) {
return (struct SessionHandle *) curr->ptr; return (struct SessionHandle *) curr->ptr;
} }
@ -2281,11 +2281,11 @@ static void signalPipeClose(struct curl_llist *pipeline)
{ {
struct curl_llist_element *curr; struct curl_llist_element *curr;
if (!pipeline) if(!pipeline)
return; return;
curr = pipeline->head; curr = pipeline->head;
while (curr) { while(curr) {
struct curl_llist_element *next = curr->next; struct curl_llist_element *next = curr->next;
struct SessionHandle *data = (struct SessionHandle *) curr->ptr; struct SessionHandle *data = (struct SessionHandle *) curr->ptr;
@ -2336,7 +2336,7 @@ ConnectionExists(struct SessionHandle *data,
pipeLen = check->send_pipe->size + check->recv_pipe->size; pipeLen = check->send_pipe->size + check->recv_pipe->size;
if (check->connectindex == -1) { if(check->connectindex == -1) {
check->connectindex = i; /* Set this appropriately since it might have check->connectindex = i; /* Set this appropriately since it might have
been set to -1 when the easy was removed been set to -1 when the easy was removed
from the multi */ from the multi */
@ -2351,7 +2351,7 @@ ConnectionExists(struct SessionHandle *data,
#ifdef CURLRES_ASYNCH #ifdef CURLRES_ASYNCH
/* ip_addr_str is NULL only if the resolving of the name hasn't completed /* ip_addr_str is NULL only if the resolving of the name hasn't completed
yet and until then we don't re-use this connection */ yet and until then we don't re-use this connection */
if (!check->ip_addr_str) { if(!check->ip_addr_str) {
infof(data, infof(data,
"Connection #%ld hasn't finished name resolve, can't reuse\n", "Connection #%ld hasn't finished name resolve, can't reuse\n",
check->connectindex); check->connectindex);
@ -2359,13 +2359,13 @@ ConnectionExists(struct SessionHandle *data,
} }
#endif #endif
if ((check->sock[FIRSTSOCKET] == CURL_SOCKET_BAD) || check->bits.close) { if((check->sock[FIRSTSOCKET] == CURL_SOCKET_BAD) || check->bits.close) {
/* Don't pick a connection that hasn't connected yet or that is going to /* Don't pick a connection that hasn't connected yet or that is going to
get closed. */ get closed. */
infof(data, "Connection #%ld isn't open enough, can't reuse\n", infof(data, "Connection #%ld isn't open enough, can't reuse\n",
check->connectindex); check->connectindex);
#ifdef CURLDEBUG #ifdef CURLDEBUG
if (check->recv_pipe->size > 0) { if(check->recv_pipe->size > 0) {
infof(data, "BAD! Unconnected #%ld has a non-empty recv pipeline!\n", infof(data, "BAD! Unconnected #%ld has a non-empty recv pipeline!\n",
check->connectindex); check->connectindex);
} }
@ -2373,21 +2373,21 @@ ConnectionExists(struct SessionHandle *data,
continue; continue;
} }
if (pipeLen >= MAX_PIPELINE_LENGTH) { if(pipeLen >= MAX_PIPELINE_LENGTH) {
infof(data, "Connection #%ld has its pipeline full, can't reuse\n", infof(data, "Connection #%ld has its pipeline full, can't reuse\n",
check->connectindex); check->connectindex);
continue; continue;
} }
if (canPipeline) { if(canPipeline) {
/* Make sure the pipe has only GET requests */ /* Make sure the pipe has only GET requests */
struct SessionHandle* sh = gethandleathead(check->send_pipe); struct SessionHandle* sh = gethandleathead(check->send_pipe);
struct SessionHandle* rh = gethandleathead(check->recv_pipe); struct SessionHandle* rh = gethandleathead(check->recv_pipe);
if (sh) { if(sh) {
if(!IsPipeliningPossible(sh)) if(!IsPipeliningPossible(sh))
continue; continue;
} }
else if (rh) { else if(rh) {
if(!IsPipeliningPossible(rh)) if(!IsPipeliningPossible(rh))
continue; continue;
} }
@ -2451,7 +2451,7 @@ ConnectionExists(struct SessionHandle *data,
} }
if(match) { if(match) {
if (!IsPipeliningEnabled(data)) { if(!IsPipeliningEnabled(data)) {
/* The check for a dead socket makes sense only in the /* The check for a dead socket makes sense only in the
non-pipelining case */ non-pipelining case */
bool dead = SocketIsDead(check->sock[FIRSTSOCKET]); bool dead = SocketIsDead(check->sock[FIRSTSOCKET]);
@ -2468,7 +2468,7 @@ ConnectionExists(struct SessionHandle *data,
check->inuse = TRUE; /* mark this as being in use so that no other check->inuse = TRUE; /* mark this as being in use so that no other
handle in a multi stack may nick it */ handle in a multi stack may nick it */
if (canPipeline) { if(canPipeline) {
/* Mark the connection as being in a pipeline */ /* Mark the connection as being in a pipeline */
check->is_in_pipeline = TRUE; check->is_in_pipeline = TRUE;
} }
@ -2534,7 +2534,7 @@ static void
ConnectionDone(struct connectdata *conn) ConnectionDone(struct connectdata *conn)
{ {
conn->inuse = FALSE; conn->inuse = FALSE;
if (!conn->send_pipe && !conn->recv_pipe) if(!conn->send_pipe && !conn->recv_pipe)
conn->is_in_pipeline = FALSE; conn->is_in_pipeline = FALSE;
} }
@ -2763,7 +2763,7 @@ CURLcode Curl_protocol_connect(struct connectdata *conn,
/* it has started, possibly even completed but that knowledge isn't stored /* it has started, possibly even completed but that knowledge isn't stored
in this bit! */ in this bit! */
if (!result) if(!result)
conn->bits.protoconnstart = TRUE; conn->bits.protoconnstart = TRUE;
} }
@ -2778,8 +2778,8 @@ static bool is_ASCII_name(const char *hostname)
{ {
const unsigned char *ch = (const unsigned char*)hostname; const unsigned char *ch = (const unsigned char*)hostname;
while (*ch) { while(*ch) {
if (*ch++ & 0x80) if(*ch++ & 0x80)
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
@ -2802,24 +2802,24 @@ static bool tld_check_name(struct SessionHandle *data,
/* Convert (and downcase) ACE-name back into locale's character set */ /* Convert (and downcase) ACE-name back into locale's character set */
rc = idna_to_unicode_lzlz(ace_hostname, &uc_name, 0); rc = idna_to_unicode_lzlz(ace_hostname, &uc_name, 0);
if (rc != IDNA_SUCCESS) if(rc != IDNA_SUCCESS)
return (FALSE); return (FALSE);
rc = tld_check_lz(uc_name, &err_pos, NULL); rc = tld_check_lz(uc_name, &err_pos, NULL);
#ifndef CURL_DISABLE_VERBOSE_STRINGS #ifndef CURL_DISABLE_VERBOSE_STRINGS
#ifdef HAVE_TLD_STRERROR #ifdef HAVE_TLD_STRERROR
if (rc != TLD_SUCCESS) if(rc != TLD_SUCCESS)
tld_errmsg = (char *)tld_strerror((Tld_rc)rc); tld_errmsg = (char *)tld_strerror((Tld_rc)rc);
#endif #endif
if (rc == TLD_INVALID) if(rc == TLD_INVALID)
infof(data, "WARNING: %s; pos %u = `%c'/0x%02X\n", infof(data, "WARNING: %s; pos %u = `%c'/0x%02X\n",
tld_errmsg, err_pos, uc_name[err_pos], tld_errmsg, err_pos, uc_name[err_pos],
uc_name[err_pos] & 255); uc_name[err_pos] & 255);
else if (rc != TLD_SUCCESS) else if(rc != TLD_SUCCESS)
infof(data, "WARNING: TLD check for %s failed; %s\n", infof(data, "WARNING: TLD check for %s failed; %s\n",
uc_name, tld_errmsg); uc_name, tld_errmsg);
#endif /* CURL_DISABLE_VERBOSE_STRINGS */ #endif /* CURL_DISABLE_VERBOSE_STRINGS */
if (uc_name) if(uc_name)
idn_free(uc_name); idn_free(uc_name);
return (bool)(rc == TLD_SUCCESS); return (bool)(rc == TLD_SUCCESS);
} }
@ -2842,13 +2842,13 @@ static void fix_hostname(struct SessionHandle *data,
/************************************************************* /*************************************************************
* Check name for non-ASCII and convert hostname to ACE form. * Check name for non-ASCII and convert hostname to ACE form.
*************************************************************/ *************************************************************/
if (!is_ASCII_name(host->name) && if(!is_ASCII_name(host->name) &&
stringprep_check_version(LIBIDN_REQUIRED_VERSION)) { stringprep_check_version(LIBIDN_REQUIRED_VERSION)) {
char *ace_hostname = NULL; char *ace_hostname = NULL;
int rc = idna_to_ascii_lz(host->name, &ace_hostname, 0); int rc = idna_to_ascii_lz(host->name, &ace_hostname, 0);
infof (data, "Input domain encoded as `%s'\n", infof (data, "Input domain encoded as `%s'\n",
stringprep_locale_charset ()); stringprep_locale_charset ());
if (rc != IDNA_SUCCESS) if(rc != IDNA_SUCCESS)
infof(data, "Failed to convert %s to ACE; %s\n", infof(data, "Failed to convert %s to ACE; %s\n",
host->name, Curl_idn_strerror(conn,rc)); host->name, Curl_idn_strerror(conn,rc));
else { else {
@ -2937,7 +2937,7 @@ static CURLcode ParseURLAndFillConnection(struct SessionHandle *data,
/* clear path */ /* clear path */
path[0]=0; path[0]=0;
if (2 > sscanf(data->change.url, if(2 > sscanf(data->change.url,
"%15[^\n:]://%[^\n/]%[^\n]", "%15[^\n:]://%[^\n/]%[^\n]",
conn->protostr, conn->protostr,
conn->host.name, path)) { conn->host.name, path)) {
@ -2965,9 +2965,9 @@ static CURLcode ParseURLAndFillConnection(struct SessionHandle *data,
if(checkprefix("FTP.", conn->host.name)) if(checkprefix("FTP.", conn->host.name))
strcpy(conn->protostr, "ftp"); strcpy(conn->protostr, "ftp");
else if (checkprefix("DICT.", conn->host.name)) else if(checkprefix("DICT.", conn->host.name))
strcpy(conn->protostr, "DICT"); strcpy(conn->protostr, "DICT");
else if (checkprefix("LDAP.", conn->host.name)) else if(checkprefix("LDAP.", conn->host.name))
strcpy(conn->protostr, "LDAP"); strcpy(conn->protostr, "LDAP");
else { else {
strcpy(conn->protostr, "http"); strcpy(conn->protostr, "http");
@ -3053,8 +3053,8 @@ static CURLcode setup_range(struct SessionHandle *data)
struct HandleData *req = &data->reqdata; struct HandleData *req = &data->reqdata;
req->resume_from = data->set.set_resume_from; req->resume_from = data->set.set_resume_from;
if (req->resume_from || data->set.str[STRING_SET_RANGE]) { if(req->resume_from || data->set.str[STRING_SET_RANGE]) {
if (req->rangestringalloc) if(req->rangestringalloc)
free(req->range); free(req->range);
if(req->resume_from) if(req->resume_from)
@ -3092,14 +3092,14 @@ static CURLcode setup_connection_internals(struct SessionHandle *data,
/* Scan protocol handler table. */ /* Scan protocol handler table. */
for (pp = protocols; (p = *pp) != NULL; pp++) for (pp = protocols; (p = *pp) != NULL; pp++)
if (strequal(p->scheme, conn->protostr)) { if(strequal(p->scheme, conn->protostr)) {
/* Protocol found in table. Perform setup complement if some. */ /* Protocol found in table. Perform setup complement if some. */
conn->handler = p; conn->handler = p;
if (p->setup_connection) { if(p->setup_connection) {
result = (*p->setup_connection)(conn); result = (*p->setup_connection)(conn);
if (result != CURLE_OK) if(result != CURLE_OK)
return result; return result;
p = conn->handler; /* May have changed. */ p = conn->handler; /* May have changed. */
@ -3229,7 +3229,7 @@ static char *detect_proxy(struct connectdata *conn)
conn->bits.httpproxy = TRUE; conn->bits.httpproxy = TRUE;
} }
} }
} /* if (!nope) - it wasn't specified non-proxy */ } /* if(!nope) - it wasn't specified non-proxy */
} /* NO_PROXY wasn't specified or '*' */ } /* NO_PROXY wasn't specified or '*' */
if(no_proxy) if(no_proxy)
free(no_proxy); free(no_proxy);
@ -3338,7 +3338,7 @@ static CURLcode parse_proxy(struct SessionHandle *data,
/* Get port number off proxy.server.com:1080 */ /* Get port number off proxy.server.com:1080 */
prox_portno = strchr(portptr, ':'); prox_portno = strchr(portptr, ':');
if (prox_portno) { if(prox_portno) {
*prox_portno = 0x0; /* cut off number from host name */ *prox_portno = 0x0; /* cut off number from host name */
prox_portno ++; prox_portno ++;
/* now set the local port number */ /* now set the local port number */
@ -3507,18 +3507,18 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->bits.ftp_use_epsv = data->set.ftp_use_epsv; conn->bits.ftp_use_epsv = data->set.ftp_use_epsv;
conn->bits.ftp_use_eprt = data->set.ftp_use_eprt; conn->bits.ftp_use_eprt = data->set.ftp_use_eprt;
if (data->multi && Curl_multi_canPipeline(data->multi) && if(data->multi && Curl_multi_canPipeline(data->multi) &&
!conn->master_buffer) { !conn->master_buffer) {
/* Allocate master_buffer to be used for pipelining */ /* Allocate master_buffer to be used for pipelining */
conn->master_buffer = calloc(BUFSIZE, sizeof (char)); conn->master_buffer = calloc(BUFSIZE, sizeof (char));
if (!conn->master_buffer) if(!conn->master_buffer)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
/* Initialize the pipeline lists */ /* Initialize the pipeline lists */
conn->send_pipe = Curl_llist_alloc((curl_llist_dtor) llist_dtor); conn->send_pipe = Curl_llist_alloc((curl_llist_dtor) llist_dtor);
conn->recv_pipe = Curl_llist_alloc((curl_llist_dtor) llist_dtor); conn->recv_pipe = Curl_llist_alloc((curl_llist_dtor) llist_dtor);
if (!conn->send_pipe || !conn->recv_pipe) if(!conn->send_pipe || !conn->recv_pipe)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
/* This initing continues below, see the comment "Continue connectdata /* This initing continues below, see the comment "Continue connectdata
@ -3556,7 +3556,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->host.name[0] = 0; conn->host.name[0] = 0;
result = ParseURLAndFillConnection(data, conn); result = ParseURLAndFillConnection(data, conn);
if (result != CURLE_OK) { if(result != CURLE_OK) {
return result; return result;
} }
@ -3565,14 +3565,14 @@ static CURLcode CreateConnection(struct SessionHandle *data,
*************************************************************/ *************************************************************/
if(conn->bits.proxy_user_passwd) { if(conn->bits.proxy_user_passwd) {
result = parse_proxy_auth(data, conn); result = parse_proxy_auth(data, conn);
if (result != CURLE_OK) if(result != CURLE_OK)
return result; return result;
} }
/************************************************************* /*************************************************************
* Detect what (if any) proxy to use * Detect what (if any) proxy to use
*************************************************************/ *************************************************************/
if (data->set.str[STRING_PROXY]) { if(data->set.str[STRING_PROXY]) {
proxy = strdup(data->set.str[STRING_PROXY]); proxy = strdup(data->set.str[STRING_PROXY]);
/* if global proxy is set, this is it */ /* if global proxy is set, this is it */
if(NULL == proxy) { if(NULL == proxy) {
@ -3581,9 +3581,9 @@ static CURLcode CreateConnection(struct SessionHandle *data,
} }
} }
if (!proxy) if(!proxy)
proxy = detect_proxy(conn); proxy = detect_proxy(conn);
if (proxy && !*proxy) { if(proxy && !*proxy) {
free(proxy); /* Don't bother with an empty proxy string */ free(proxy); /* Don't bother with an empty proxy string */
proxy = NULL; proxy = NULL;
} }
@ -3614,7 +3614,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
* Setup internals depending on protocol * Setup internals depending on protocol
*************************************************************/ *************************************************************/
result = setup_connection_internals(data, conn); result = setup_connection_internals(data, conn);
if (result != CURLE_OK) { if(result != CURLE_OK) {
Curl_safefree(proxy); Curl_safefree(proxy);
return result; return result;
} }
@ -3625,11 +3625,11 @@ static CURLcode CreateConnection(struct SessionHandle *data,
* host name, so that we can re-use an existing connection * host name, so that we can re-use an existing connection
* that may exist registered to the same proxy host. * that may exist registered to the same proxy host.
***********************************************************************/ ***********************************************************************/
if (proxy) { if(proxy) {
result = parse_proxy(data, conn, proxy); result = parse_proxy(data, conn, proxy);
/* parse_proxy has freed the proxy string, so don't try to use it again */ /* parse_proxy has freed the proxy string, so don't try to use it again */
proxy = NULL; proxy = NULL;
if (result != CURLE_OK) if(result != CURLE_OK)
return result; return result;
} }
@ -3704,7 +3704,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
user[0] =0; /* to make everything well-defined */ user[0] =0; /* to make everything well-defined */
passwd[0]=0; passwd[0]=0;
if (conn->protocol & (PROT_FTP|PROT_HTTP|PROT_SCP|PROT_SFTP)) { if(conn->protocol & (PROT_FTP|PROT_HTTP|PROT_SCP|PROT_SFTP)) {
/* This is a FTP, HTTP, SCP or SFTP URL, we will now try to extract the /* This is a FTP, HTTP, SCP or SFTP URL, we will now try to extract the
* possible user+password pair in a string like: * possible user+password pair in a string like:
* ftp://user:password@ftp.my.site:8021/README */ * ftp://user:password@ftp.my.site:8021/README */
@ -3721,7 +3721,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
* set user/passwd, but doing that first adds more cases here :-( * set user/passwd, but doing that first adds more cases here :-(
*/ */
if (data->set.use_netrc != CURL_NETRC_REQUIRED) { if(data->set.use_netrc != CURL_NETRC_REQUIRED) {
/* We could use the one in the URL */ /* We could use the one in the URL */
conn->bits.user_passwd = 1; /* enable user+password */ conn->bits.user_passwd = 1; /* enable user+password */
@ -3747,7 +3747,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
the unconverted name, it'll be wrong but what the heck */ the unconverted name, it'll be wrong but what the heck */
free(newname); free(newname);
} }
if (passwd[0]) { if(passwd[0]) {
/* we have a password found in the URL, decode it! */ /* we have a password found in the URL, decode it! */
char *newpasswd=curl_easy_unescape(data, passwd, 0, NULL); char *newpasswd=curl_easy_unescape(data, passwd, 0, NULL);
if(!newpasswd) if(!newpasswd)
@ -3810,7 +3810,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
data->change.url_alloc = TRUE; data->change.url_alloc = TRUE;
} }
} }
else if (tmp) { else if(tmp) {
/* no CURLOPT_PORT given, extract the one from the URL */ /* no CURLOPT_PORT given, extract the one from the URL */
char *rest; char *rest;
@ -3818,11 +3818,11 @@ static CURLcode CreateConnection(struct SessionHandle *data,
port=strtoul(tmp+1, &rest, 10); /* Port number must be decimal */ port=strtoul(tmp+1, &rest, 10); /* Port number must be decimal */
if (rest != (tmp+1) && *rest == '\0') { if(rest != (tmp+1) && *rest == '\0') {
/* The colon really did have only digits after it, /* The colon really did have only digits after it,
* so it is either a port number or a mistake */ * so it is either a port number or a mistake */
if (port > 0xffff) { /* Single unix standard says port numbers are if(port > 0xffff) { /* Single unix standard says port numbers are
* 16 bits long */ * 16 bits long */
failf(data, "Port number too large: %lu", port); failf(data, "Port number too large: %lu", port);
return CURLE_URL_MALFORMAT; return CURLE_URL_MALFORMAT;
@ -3842,7 +3842,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
* user_password is set in "inherit initial knowledge' above, * user_password is set in "inherit initial knowledge' above,
* so it doesn't have to be set in this block * so it doesn't have to be set in this block
*/ */
if (data->set.str[STRING_USERPWD] != NULL) { if(data->set.str[STRING_USERPWD] != NULL) {
/* the name is given, get user+password */ /* the name is given, get user+password */
sscanf(data->set.str[STRING_USERPWD], sscanf(data->set.str[STRING_USERPWD],
"%" MAX_CURL_USER_LENGTH_TXT "[^:]:" "%" MAX_CURL_USER_LENGTH_TXT "[^:]:"
@ -3851,7 +3851,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
} }
conn->bits.netrc = FALSE; conn->bits.netrc = FALSE;
if (data->set.use_netrc != CURL_NETRC_IGNORED) { if(data->set.use_netrc != CURL_NETRC_IGNORED) {
if(Curl_parsenetrc(conn->host.name, if(Curl_parsenetrc(conn->host.name,
user, passwd, user, passwd,
data->set.str[STRING_NETRC_FILE])) { data->set.str[STRING_NETRC_FILE])) {
@ -3870,7 +3870,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
} }
/* If our protocol needs a password and we have none, use the defaults */ /* If our protocol needs a password and we have none, use the defaults */
if ( (conn->protocol & PROT_FTP) && if( (conn->protocol & PROT_FTP) &&
!conn->bits.user_passwd) { !conn->bits.user_passwd) {
conn->user = strdup(CURL_DEFAULT_USER); conn->user = strdup(CURL_DEFAULT_USER);
@ -3941,7 +3941,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
/* get the user+password information from the old_conn struct since it may /* get the user+password information from the old_conn struct since it may
* be new for this request even when we re-use an existing connection */ * be new for this request even when we re-use an existing connection */
conn->bits.user_passwd = old_conn->bits.user_passwd; conn->bits.user_passwd = old_conn->bits.user_passwd;
if (conn->bits.user_passwd) { if(conn->bits.user_passwd) {
/* use the new user namd and password though */ /* use the new user namd and password though */
Curl_safefree(conn->user); Curl_safefree(conn->user);
Curl_safefree(conn->passwd); Curl_safefree(conn->passwd);
@ -3952,7 +3952,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
} }
conn->bits.proxy_user_passwd = old_conn->bits.proxy_user_passwd; conn->bits.proxy_user_passwd = old_conn->bits.proxy_user_passwd;
if (conn->bits.proxy_user_passwd) { if(conn->bits.proxy_user_passwd) {
/* use the new proxy user name and proxy password though */ /* use the new proxy user name and proxy password though */
Curl_safefree(conn->proxyuser); Curl_safefree(conn->proxyuser);
Curl_safefree(conn->proxypasswd); Curl_safefree(conn->proxypasswd);
@ -3963,7 +3963,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
} }
/* host can change, when doing keepalive with a proxy ! */ /* host can change, when doing keepalive with a proxy ! */
if (conn->bits.proxy) { if(conn->bits.proxy) {
free(conn->host.rawalloc); free(conn->host.rawalloc);
conn->host=old_conn->host; conn->host=old_conn->host;
} }
@ -4013,7 +4013,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
conn->fread_func = data->set.fread_func; conn->fread_func = data->set.fread_func;
conn->fread_in = data->set.in; conn->fread_in = data->set.in;
if ((conn->protocol&PROT_HTTP) && if((conn->protocol&PROT_HTTP) &&
data->set.upload && data->set.upload &&
(data->set.infilesize == -1) && (data->set.infilesize == -1) &&
(data->set.httpversion != CURL_HTTP_VERSION_1_0)) { (data->set.httpversion != CURL_HTTP_VERSION_1_0)) {
@ -4098,7 +4098,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
hostaddr = NULL; hostaddr = NULL;
/* we'll need to clear conn->dns_entry later in Curl_disconnect() */ /* we'll need to clear conn->dns_entry later in Curl_disconnect() */
if (conn->bits.proxy) if(conn->bits.proxy)
fix_hostname(data, conn, &conn->host); fix_hostname(data, conn, &conn->host);
} }
else { else {
@ -4261,7 +4261,7 @@ static CURLcode SetupConnection(struct connectdata *conn,
authentication information */ authentication information */
if(conn->bits.proxy_connect_closed) { if(conn->bits.proxy_connect_closed) {
/* reset the error buffer */ /* reset the error buffer */
if (data->set.errorbuffer) if(data->set.errorbuffer)
data->set.errorbuffer[0] = '\0'; data->set.errorbuffer[0] = '\0';
data->state.errorbuf = FALSE; data->state.errorbuf = FALSE;
continue; continue;
@ -4291,7 +4291,7 @@ static CURLcode SetupConnection(struct connectdata *conn,
* characters (you get mangled text files, and corrupted binary files when * characters (you get mangled text files, and corrupted binary files when
* you download to stdout and redirect it to a file). */ * you download to stdout and redirect it to a file). */
if ((data->set.out)->_handle == NULL) { if((data->set.out)->_handle == NULL) {
_fsetmode(stdout, "b"); _fsetmode(stdout, "b");
} }
#endif #endif
@ -4332,7 +4332,7 @@ CURLcode Curl_connect(struct SessionHandle *data,
} }
} }
else { else {
if ((*in_connect)->is_in_pipeline) if((*in_connect)->is_in_pipeline)
data->state.is_in_pipeline = TRUE; data->state.is_in_pipeline = TRUE;
} }
@ -4528,7 +4528,7 @@ CURLcode Curl_do_more(struct connectdata *conn)
void Curl_reset_reqproto(struct connectdata *conn) void Curl_reset_reqproto(struct connectdata *conn)
{ {
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
if (data->reqdata.proto.generic && data->reqdata.current_conn != conn) { if(data->reqdata.proto.generic && data->reqdata.current_conn != conn) {
free(data->reqdata.proto.generic); free(data->reqdata.proto.generic);
data->reqdata.proto.generic = NULL; data->reqdata.proto.generic = NULL;
} }