source cleanup: unify look, style and indent levels

By the use of a the new lib/checksrc.pl script that checks that our
basic source style rules are followed.
This commit is contained in:
Daniel Stenberg 2011-04-20 15:17:42 +02:00
parent 592eda8e3f
commit b903186fa0
88 changed files with 1411 additions and 1577 deletions

View File

@ -184,3 +184,6 @@ $(VCPROJ): vc8proj.head vc8proj.foot Makefile.am
echo "<File RelativePath=\""$$file"\"></File>" $(VCPROJOUT); \ echo "<File RelativePath=\""$$file"\"></File>" $(VCPROJOUT); \
done; \ done; \
cat $(srcdir)/vc8proj.foot $(VCPROJOUT) ) cat $(srcdir)/vc8proj.foot $(VCPROJOUT) )
all-local:
@for i in $(CSOURCES) $(HHEADERS); do $(top_srcdir)/lib/checksrc.pl $(top_srcdir)/lib/$$i; done

View File

@ -424,7 +424,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
if(!conn->async.dns) { if(!conn->async.dns) {
/* a name was not resolved */ /* a name was not resolved */
if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) { if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) {
if (conn->bits.httpproxy) { if(conn->bits.httpproxy) {
failf(data, "Resolving proxy timed out: %s", conn->proxy.dispname); failf(data, "Resolving proxy timed out: %s", conn->proxy.dispname);
rc = CURLE_COULDNT_RESOLVE_PROXY; rc = CURLE_COULDNT_RESOLVE_PROXY;
} }
@ -434,7 +434,7 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
} }
} }
else if(conn->async.done) { else if(conn->async.done) {
if (conn->bits.httpproxy) { if(conn->bits.httpproxy) {
failf(data, "Could not resolve proxy: %s (%s)", conn->proxy.dispname, failf(data, "Could not resolve proxy: %s (%s)", conn->proxy.dispname,
ares_strerror(conn->async.status)); ares_strerror(conn->async.status));
rc = CURLE_COULDNT_RESOLVE_PROXY; rc = CURLE_COULDNT_RESOLVE_PROXY;
@ -542,10 +542,9 @@ Curl_addrinfo *Curl_resolver_getaddrinfo(struct connectdata *conn,
#ifdef ENABLE_IPV6 /* CURLRES_IPV6 */ #ifdef ENABLE_IPV6 /* CURLRES_IPV6 */
/* Otherwise, check if this is an IPv6 address string */ /* Otherwise, check if this is an IPv6 address string */
if (Curl_inet_pton (AF_INET6, hostname, &in6) > 0) { if(Curl_inet_pton (AF_INET6, hostname, &in6) > 0)
/* This must be an IPv6 address literal. */ /* This must be an IPv6 address literal. */
return Curl_ip2addr(AF_INET6, &in6, hostname, port); return Curl_ip2addr(AF_INET6, &in6, hostname, port);
}
switch(conn->ip_version) { switch(conn->ip_version) {
default: default:

View File

@ -193,7 +193,7 @@ static struct thread_sync_data *conn_thread_sync_data(struct connectdata *conn)
static static
void destroy_thread_sync_data(struct thread_sync_data * tsd) void destroy_thread_sync_data(struct thread_sync_data * tsd)
{ {
if (tsd->mtx) { if(tsd->mtx) {
Curl_mutex_destroy(tsd->mtx); Curl_mutex_destroy(tsd->mtx);
free(tsd->mtx); free(tsd->mtx);
} }
@ -201,7 +201,7 @@ void destroy_thread_sync_data(struct thread_sync_data * tsd)
if(tsd->hostname) if(tsd->hostname)
free(tsd->hostname); free(tsd->hostname);
if (tsd->res) if(tsd->res)
Curl_freeaddrinfo(tsd->res); Curl_freeaddrinfo(tsd->res);
memset(tsd,0,sizeof(*tsd)); memset(tsd,0,sizeof(*tsd));
@ -225,7 +225,8 @@ int init_thread_sync_data(struct thread_sync_data * tsd,
#endif #endif
tsd->mtx = malloc(sizeof(curl_mutex_t)); tsd->mtx = malloc(sizeof(curl_mutex_t));
if (tsd->mtx == NULL) goto err_exit; if(tsd->mtx == NULL)
goto err_exit;
Curl_mutex_init(tsd->mtx); Curl_mutex_init(tsd->mtx);
@ -235,7 +236,8 @@ int init_thread_sync_data(struct thread_sync_data * tsd,
* thread during gethostbyname execution. * thread during gethostbyname execution.
*/ */
tsd->hostname = strdup(hostname); tsd->hostname = strdup(hostname);
if (!tsd->hostname) goto err_exit; if(!tsd->hostname)
goto err_exit;
return 1; return 1;
@ -278,9 +280,9 @@ static unsigned int CURL_STDCALL getaddrinfo_thread (void *arg)
rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res); rc = Curl_getaddrinfo_ex(tsd->hostname, service, &tsd->hints, &tsd->res);
if (rc != 0) { if(rc != 0) {
tsd->sock_error = SOCKERRNO; tsd->sock_error = SOCKERRNO;
if (tsd->sock_error == 0) if(tsd->sock_error == 0)
tsd->sock_error = ENOMEM; tsd->sock_error = ENOMEM;
} }
@ -302,9 +304,9 @@ static unsigned int CURL_STDCALL gethostbyname_thread (void *arg)
tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port); tsd->res = Curl_ipv4_resolve_r(tsd->hostname, tsd->port);
if (!tsd->res) { if(!tsd->res) {
tsd->sock_error = SOCKERRNO; tsd->sock_error = SOCKERRNO;
if (tsd->sock_error == 0) if(tsd->sock_error == 0)
tsd->sock_error = ENOMEM; tsd->sock_error = ENOMEM;
} }
@ -328,10 +330,10 @@ static void destroy_async_data (struct Curl_async *async)
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;
if (td->dummy_sock != CURL_SOCKET_BAD) if(td->dummy_sock != CURL_SOCKET_BAD)
sclose(td->dummy_sock); sclose(td->dummy_sock);
if (td->thread_hnd != curl_thread_t_null) if(td->thread_hnd != curl_thread_t_null)
Curl_thread_join(&td->thread_hnd); Curl_thread_join(&td->thread_hnd);
destroy_thread_sync_data(&td->tsd); destroy_thread_sync_data(&td->tsd);
@ -366,7 +368,7 @@ static bool init_resolve_thread (struct connectdata *conn,
td->dummy_sock = CURL_SOCKET_BAD; td->dummy_sock = CURL_SOCKET_BAD;
td->thread_hnd = curl_thread_t_null; td->thread_hnd = curl_thread_t_null;
if (!init_thread_sync_data(&td->tsd, hostname, port, hints)) if(!init_thread_sync_data(&td->tsd, hostname, port, hints))
goto err_exit; goto err_exit;
Curl_safefree(conn->async.hostname); Curl_safefree(conn->async.hostname);
@ -380,7 +382,7 @@ static bool init_resolve_thread (struct connectdata *conn,
* Windows needs at least 1 socket in select(). * Windows needs at least 1 socket in select().
*/ */
td->dummy_sock = socket(AF_INET, SOCK_DGRAM, 0); td->dummy_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (td->dummy_sock == CURL_SOCKET_BAD) if(td->dummy_sock == CURL_SOCKET_BAD)
goto err_exit; goto err_exit;
#endif #endif
@ -428,11 +430,10 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
DEBUGASSERT(conn && td); DEBUGASSERT(conn && td);
/* wait for the thread to resolve the name */ /* wait for the thread to resolve the name */
if (Curl_thread_join(&td->thread_hnd)) { if(Curl_thread_join(&td->thread_hnd))
rc = getaddrinfo_complete(conn); rc = getaddrinfo_complete(conn);
} else { else
DEBUGASSERT(0); DEBUGASSERT(0);
}
conn->async.done = TRUE; conn->async.done = TRUE;
@ -441,11 +442,12 @@ CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,
if(!conn->async.dns) { if(!conn->async.dns) {
/* a name was not resolved */ /* a name was not resolved */
if (conn->bits.httpproxy) { if(conn->bits.httpproxy) {
failf(data, "Could not resolve proxy: %s; %s", failf(data, "Could not resolve proxy: %s; %s",
conn->async.hostname, Curl_strerror(conn, conn->async.status)); conn->async.hostname, Curl_strerror(conn, conn->async.status));
rc = CURLE_COULDNT_RESOLVE_PROXY; rc = CURLE_COULDNT_RESOLVE_PROXY;
} else { }
else {
failf(data, "Could not resolve host: %s; %s", failf(data, "Could not resolve host: %s; %s",
conn->async.hostname, Curl_strerror(conn, conn->async.status)); conn->async.hostname, Curl_strerror(conn, conn->async.status));
rc = CURLE_COULDNT_RESOLVE_HOST; rc = CURLE_COULDNT_RESOLVE_HOST;
@ -474,7 +476,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
*entry = NULL; *entry = NULL;
if (!td) { if(!td) {
DEBUGASSERT(td); DEBUGASSERT(td);
return CURLE_COULDNT_RESOLVE_HOST; return CURLE_COULDNT_RESOLVE_HOST;
} }
@ -483,7 +485,7 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
done = td->tsd.done; done = td->tsd.done;
Curl_mutex_release(td->tsd.mtx); Curl_mutex_release(td->tsd.mtx);
if (done) { if(done) {
getaddrinfo_complete(conn); getaddrinfo_complete(conn);
destroy_async_data(&conn->async); destroy_async_data(&conn->async);
@ -493,20 +495,21 @@ CURLcode Curl_resolver_is_resolved(struct connectdata *conn,
return CURLE_COULDNT_RESOLVE_HOST; return CURLE_COULDNT_RESOLVE_HOST;
} }
*entry = conn->async.dns; *entry = conn->async.dns;
} else { }
else {
/* poll for name lookup done with exponential backoff up to 250ms */ /* poll for name lookup done with exponential backoff up to 250ms */
int elapsed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle); int elapsed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
if (elapsed < 0) if(elapsed < 0)
elapsed = 0; elapsed = 0;
if (td->poll_interval == 0) if(td->poll_interval == 0)
/* Start at 1ms poll interval */ /* Start at 1ms poll interval */
td->poll_interval = 1; td->poll_interval = 1;
else if (elapsed >= td->interval_end) else if(elapsed >= td->interval_end)
/* Back-off exponentially if last interval expired */ /* Back-off exponentially if last interval expired */
td->poll_interval *= 2; td->poll_interval *= 2;
if (td->poll_interval > 250) if(td->poll_interval > 250)
td->poll_interval = 250; td->poll_interval = 250;
td->interval_end = elapsed + td->poll_interval; td->interval_end = elapsed + td->poll_interval;

View File

@ -82,8 +82,7 @@ int Curl_axtls_cleanup(void)
static CURLcode map_error_to_curl(int axtls_err) static CURLcode map_error_to_curl(int axtls_err)
{ {
switch (axtls_err) switch (axtls_err) {
{
case SSL_ERROR_NOT_SUPPORTED: case SSL_ERROR_NOT_SUPPORTED:
case SSL_ERROR_INVALID_VERSION: case SSL_ERROR_INVALID_VERSION:
case -70: /* protocol version alert from server */ case -70: /* protocol version alert from server */
@ -416,7 +415,7 @@ int Curl_axtls_shutdown(struct connectdata *conn, int sockindex)
nread = (ssize_t)SSL_read(conn->ssl[sockindex].ssl, buf, nread = (ssize_t)SSL_read(conn->ssl[sockindex].ssl, buf,
sizeof(buf)); sizeof(buf));
if (nread < SSL_OK){ if(nread < SSL_OK){
failf(data, "close notify alert not received during shutdown"); failf(data, "close notify alert not received during shutdown");
retval = -1; retval = -1;
} }

View File

@ -171,7 +171,7 @@ size_t Curl_base64_encode(struct SessionHandle *data,
indata = (char *)convbuf; indata = (char *)convbuf;
while(insize > 0) { while(insize > 0) {
for (i = inputparts = 0; i < 3; i++) { for(i = inputparts = 0; i < 3; i++) {
if(insize > 0) { if(insize > 0) {
inputparts++; inputparts++;
ibuf[i] = (unsigned char) *indata; ibuf[i] = (unsigned char) *indata;

118
lib/checksrc.pl Executable file
View File

@ -0,0 +1,118 @@
#!/usr/bin/perl
my $file=$ARGV[0];
my $max_column = 79;
my $indent = 2;
sub checkwarn {
my ($num, $col, $file, $line, $msg, $error) = @_;
my $w=$error?"error":"warning";
$col++;
print "$file:$num:$col: $w: $msg\n";
print " $line\n";
if($col < 80) {
my $pref = (' ' x $col);
print "${pref}^\n";
}
}
if(!$file) {
print "checksrc.pl <single C or H file>\n";
exit;
}
my $line = 1;
open(R, "<$file") || die;
my $copyright=0;
while(<R>) {
chomp;
my $l = $_;
my $column = 0;
# check for a copyright statement
if(!$copyright && ($l =~ /copyright .* \d\d\d\d/i)) {
$copyright=1;
}
# detect long lines
if(length($l) > $max_column) {
checkwarn($line, length($l), $file, $l, "Longer than $max_column columns");
}
# detect TAB characters
if($l =~ /^(.*)\t/) {
checkwarn($line, length($1), $file, $l, "Contains TAB character", 1);
}
# detect trailing white space
if($l =~ /^(\S+)[ \t]+\z/) {
checkwarn($line, length($1), $file, $l, "Trailing whitespace");
}
# detect return statements with parenthesis
# doesn't really work unless we filter off typecasts
#if($l =~ /(.*)return \(/) {
# checkwarn($line, length($1)+6, $file, $l, "return with paretheses");
#}
# check spaces after for/if/while
if($l =~ /^(.*)(for|if|while) \(/) {
if($1 =~ / *\#/) {
# this is a #if, treat it differently
}
else {
checkwarn($line, length($1)+length($2), $file, $l,
"$2 with space");
}
}
# check for "} else"
if($l =~ /^(.*)\} else/) {
checkwarn($line, length($1), $file, $l, "else after closing brace on same line");
}
# check for open brace first on line but not first column
# only alert if previous line ended with a close paren and wasn't a cpp
# line
if((($prevl =~ /\)\z/) && ($prevl !~ /^ *#/)) && ($l =~ /^( +)\{/)) {
checkwarn($line, length($1), $file, $l, "badly placed open brace");
}
# if the previous line starts with if/while/for AND ends with an open
# brace, check that this line is indented $indent more steps, if not
# a cpp line
if($prevl =~ /^( *)(if|while|for)\(.*\{\z/) {
my $first = length($1);
# this line has some character besides spaces
if(($l !~ /^ *#/) && ($l =~ /^( *)[^ ]/)) {
my $second = length($1);
my $expect = $first+$indent;
if($expect != $second) {
my $diff = $second - $first;
checkwarn($line, length($1), $file, $l,
"not indented $indent steps, uses $diff)");
}
}
}
# check for // letters, but skip them if a double quote or asterisk was
# on the same line to avoid strings and comments. Not reliable.
#if($l =~ /^([^\"*]*)\/\//) {
# checkwarn($line, length($1), $file, $l, "non-C89 compliant comment",
# 1);
#}
$line++;
$prevl = $l;
}
if(!$copyright) {
checkwarn(1, 0, $file, "", "Missing copyright statement", 1);
}
close(R);

View File

@ -263,7 +263,7 @@ static CURLcode bindlocal(struct connectdata *conn,
/************************************************************* /*************************************************************
* Select device to bind socket to * Select device to bind socket to
*************************************************************/ *************************************************************/
if ( !dev && !port ) if(!dev && !port)
/* no local kind of binding was requested */ /* no local kind of binding was requested */
return CURLE_OK; return CURLE_OK;
@ -315,10 +315,10 @@ static CURLcode bindlocal(struct connectdata *conn,
long ipver = conn->ip_version; long ipver = conn->ip_version;
int rc; int rc;
if (af == AF_INET) if(af == AF_INET)
conn->ip_version = CURL_IPRESOLVE_V4; conn->ip_version = CURL_IPRESOLVE_V4;
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
else if (af == AF_INET6) else if(af == AF_INET6)
conn->ip_version = CURL_IPRESOLVE_V6; conn->ip_version = CURL_IPRESOLVE_V6;
#endif #endif
@ -372,14 +372,14 @@ static CURLcode bindlocal(struct connectdata *conn,
else { else {
/* no device was given, prepare sa to match af's needs */ /* no device was given, prepare sa to match af's needs */
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
if ( af == AF_INET6 ) { if( af == AF_INET6 ) {
si6->sin6_family = AF_INET6; si6->sin6_family = AF_INET6;
si6->sin6_port = htons(port); si6->sin6_port = htons(port);
sizeof_sa = sizeof(struct sockaddr_in6); sizeof_sa = sizeof(struct sockaddr_in6);
} }
else else
#endif #endif
if ( af == AF_INET ) { if( af == AF_INET ) {
si4->sin_family = AF_INET; si4->sin_family = AF_INET;
si4->sin_port = htons(port); si4->sin_port = htons(port);
sizeof_sa = sizeof(struct sockaddr_in); sizeof_sa = sizeof(struct sockaddr_in);
@ -388,7 +388,7 @@ static CURLcode bindlocal(struct connectdata *conn,
for(;;) { for(;;) {
if( bind(sockfd, sock, sizeof_sa) >= 0) { if( bind(sockfd, sock, sizeof_sa) >= 0) {
/* we succeeded to bind */ /* we succeeded to bind */
struct Curl_sockaddr_storage add; struct Curl_sockaddr_storage add;
curl_socklen_t size = sizeof(add); curl_socklen_t size = sizeof(add);
memset(&add, 0, sizeof(struct Curl_sockaddr_storage)); memset(&add, 0, sizeof(struct Curl_sockaddr_storage));
@ -809,8 +809,8 @@ void Curl_sndbufset(curl_socket_t sockfd)
int curval = 0; int curval = 0;
int curlen = sizeof(curval); int curlen = sizeof(curval);
if (getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char *)&curval, &curlen) == 0) if(getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (char *)&curval, &curlen) == 0)
if (curval > val) if(curval > val)
return; return;
setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (const char *)&val, sizeof(val)); setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, (const char *)&val, sizeof(val));
@ -888,7 +888,7 @@ singleipconnect(struct connectdata *conn,
return CURLE_OK; return CURLE_OK;
#if defined(ENABLE_IPV6) && defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID) #if defined(ENABLE_IPV6) && defined(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID)
if (conn->scope && (addr.family == AF_INET6)) if(conn->scope && (addr.family == AF_INET6))
sa6->sin6_scope_id = conn->scope; sa6->sin6_scope_id = conn->scope;
#endif #endif
@ -1067,8 +1067,8 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
/* /*
* Connecting with a Curl_addrinfo chain * Connecting with a Curl_addrinfo chain
*/ */
for (curr_addr = ai, aliasindex=0; curr_addr; for(curr_addr = ai, aliasindex=0; curr_addr;
curr_addr = curr_addr->ai_next, aliasindex++) { curr_addr = curr_addr->ai_next, aliasindex++) {
/* start connecting to the IP curr_addr points to */ /* start connecting to the IP curr_addr points to */
CURLcode res = CURLcode res =

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -95,7 +95,7 @@ inflate_stream(struct connectdata *conn,
/* because the buffer size is fixed, iteratively decompress and transfer to /* because the buffer size is fixed, iteratively decompress and transfer to
the client via client_write. */ the client via client_write. */
for (;;) { for(;;) {
/* (re)set buffer for decompressed output for every iteration */ /* (re)set buffer for decompressed output for every iteration */
z->next_out = (Bytef *)decomp; z->next_out = (Bytef *)decomp;
z->avail_out = DSIZ; z->avail_out = DSIZ;

View File

@ -84,7 +84,7 @@ Example set of cookies:
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#define _MPRINTF_REPLACE /* without this on windows OS we get undefined reference to snprintf */ #define _MPRINTF_REPLACE
#include <curl/mprintf.h> #include <curl/mprintf.h>
#include "urldata.h" #include "urldata.h"
@ -371,7 +371,7 @@ Curl_cookie_add(struct SessionHandle *data,
/* Session cookies have expires set to 0 so if we get that back /* Session cookies have expires set to 0 so if we get that back
from the date parser let's add a second to make it a from the date parser let's add a second to make it a
non-session cookie */ non-session cookie */
if (co->expires == 0) if(co->expires == 0)
co->expires = 1; co->expires = 1;
else if( co->expires < 0 ) else if( co->expires < 0 )
co->expires = 0; co->expires = 0;
@ -398,7 +398,7 @@ Curl_cookie_add(struct SessionHandle *data,
if(Curl_raw_equal("secure", what)) { if(Curl_raw_equal("secure", what)) {
co->secure = TRUE; co->secure = TRUE;
} }
else if (Curl_raw_equal("httponly", what)) { else if(Curl_raw_equal("httponly", what)) {
co->httponly = TRUE; co->httponly = TRUE;
} }
/* else, /* else,
@ -482,7 +482,7 @@ Curl_cookie_add(struct SessionHandle *data,
lines are preceded with #HttpOnly_ and then everything is lines are preceded with #HttpOnly_ and then everything is
as usual, so we skip 10 characters of the line.. as usual, so we skip 10 characters of the line..
*/ */
if (strncmp(lineptr, "#HttpOnly_", 10) == 0) { if(strncmp(lineptr, "#HttpOnly_", 10) == 0) {
lineptr += 10; lineptr += 10;
co->httponly = TRUE; co->httponly = TRUE;
} }
@ -531,7 +531,7 @@ Curl_cookie_add(struct SessionHandle *data,
As far as I can see, it is set to true when the cookie says As far as I can see, it is set to true when the cookie says
.domain.com and to false when the domain is complete www.domain.com .domain.com and to false when the domain is complete www.domain.com
*/ */
co->tailmatch=(bool)Curl_raw_equal(ptr, "TRUE"); /* store information */ co->tailmatch=(bool)Curl_raw_equal(ptr, "TRUE");
break; break;
case 2: case 2:
/* It turns out, that sometimes the file format allows the path /* It turns out, that sometimes the file format allows the path

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -294,7 +294,7 @@ Curl_he2ai(const struct hostent *he, int port)
size_t ss_size; size_t ss_size;
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
if (he->h_addrtype == AF_INET6) if(he->h_addrtype == AF_INET6)
ss_size = sizeof (struct sockaddr_in6); ss_size = sizeof (struct sockaddr_in6);
else else
#endif #endif

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -317,7 +317,7 @@ static int loop(const unsigned char *pattern, const unsigned char *string)
unsigned char charset[CURLFNM_CHSET_SIZE] = { 0 }; unsigned char charset[CURLFNM_CHSET_SIZE] = { 0 };
int rc = 0; int rc = 0;
for (;;) { for(;;) {
switch(state) { switch(state) {
case CURLFNM_LOOP_DEFAULT: case CURLFNM_LOOP_DEFAULT:
if(*p == '*') { if(*p == '*') {

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -50,8 +50,8 @@ Curl_memrchr(const void *s, int c, size_t n)
p += n - 1; p += n - 1;
while (p >= q) { while(p >= q) {
if (*p == (unsigned char)c) if(*p == (unsigned char)c)
return (void *)p; return (void *)p;
p--; p--;
} }

View File

@ -51,7 +51,7 @@ static CURLcode rtmp_setup(struct connectdata *conn);
static CURLcode rtmp_do(struct connectdata *conn, bool *done); static CURLcode rtmp_do(struct connectdata *conn, bool *done);
static CURLcode rtmp_done(struct connectdata *conn, CURLcode, bool premature); static CURLcode rtmp_done(struct connectdata *conn, CURLcode, bool premature);
static CURLcode rtmp_connect(struct connectdata *conn, bool *done); static CURLcode rtmp_connect(struct connectdata *conn, bool *done);
static CURLcode rtmp_disconnect(struct connectdata *conn, bool dead_connection); static CURLcode rtmp_disconnect(struct connectdata *conn, bool dead);
static Curl_recv rtmp_recv; static Curl_recv rtmp_recv;
static Curl_send rtmp_send; static Curl_send rtmp_send;
@ -171,12 +171,12 @@ static CURLcode rtmp_setup(struct connectdata *conn)
{ {
RTMP *r = RTMP_Alloc(); RTMP *r = RTMP_Alloc();
if (!r) if(!r)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
RTMP_Init(r); RTMP_Init(r);
RTMP_SetBufferMS(r, DEF_BUFTIME); RTMP_SetBufferMS(r, DEF_BUFTIME);
if (!RTMP_SetupURL(r, conn->data->change.url)) { if(!RTMP_SetupURL(r, conn->data->change.url)) {
RTMP_Free(r); RTMP_Free(r);
return CURLE_URL_MALFORMAT; return CURLE_URL_MALFORMAT;
} }
@ -194,17 +194,19 @@ static CURLcode rtmp_connect(struct connectdata *conn, bool *done)
/* We have to know if it's a write before we send the /* We have to know if it's a write before we send the
* connect request packet * connect request packet
*/ */
if (conn->data->set.upload) if(conn->data->set.upload)
r->Link.protocol |= RTMP_FEATURE_WRITE; r->Link.protocol |= RTMP_FEATURE_WRITE;
/* For plain streams, use the buffer toggle trick to keep data flowing */ /* For plain streams, use the buffer toggle trick to keep data flowing */
if (!(r->Link.lFlags & RTMP_LF_LIVE) && !(r->Link.protocol & RTMP_FEATURE_HTTP)) if(!(r->Link.lFlags & RTMP_LF_LIVE) &&
!(r->Link.protocol & RTMP_FEATURE_HTTP))
r->Link.lFlags |= RTMP_LF_BUFX; r->Link.lFlags |= RTMP_LF_BUFX;
curlx_nonblock(r->m_sb.sb_socket, FALSE); curlx_nonblock(r->m_sb.sb_socket, FALSE);
setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)); setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO,
(char *)&tv, sizeof(tv));
if (!RTMP_Connect1(r, NULL)) if(!RTMP_Connect1(r, NULL))
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
/* Clients must send a periodic BytesReceived report to the server */ /* Clients must send a periodic BytesReceived report to the server */
@ -220,13 +222,14 @@ static CURLcode rtmp_do(struct connectdata *conn, bool *done)
{ {
RTMP *r = conn->proto.generic; RTMP *r = conn->proto.generic;
if (!RTMP_ConnectStream(r, 0)) if(!RTMP_ConnectStream(r, 0))
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;
if (conn->data->set.upload) { if(conn->data->set.upload) {
Curl_pgrsSetUploadSize(conn->data, conn->data->set.infilesize); Curl_pgrsSetUploadSize(conn->data, conn->data->set.infilesize);
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL); Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL);
} else }
else
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, NULL, -1, NULL); Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, NULL, -1, NULL);
*done = TRUE; *done = TRUE;
return CURLE_OK; return CURLE_OK;
@ -247,7 +250,7 @@ static CURLcode rtmp_disconnect(struct connectdata *conn,
{ {
RTMP *r = conn->proto.generic; RTMP *r = conn->proto.generic;
(void)dead_connection; (void)dead_connection;
if (r) { if(r) {
conn->proto.generic = NULL; conn->proto.generic = NULL;
RTMP_Close(r); RTMP_Close(r);
RTMP_Free(r); RTMP_Free(r);
@ -264,12 +267,13 @@ static ssize_t rtmp_recv(struct connectdata *conn, int sockindex, char *buf,
(void)sockindex; /* unused */ (void)sockindex; /* unused */
nread = RTMP_Read(r, buf, len); nread = RTMP_Read(r, buf, len);
if (nread < 0) { if(nread < 0) {
if (r->m_read.status == RTMP_READ_COMPLETE || if(r->m_read.status == RTMP_READ_COMPLETE ||
r->m_read.status == RTMP_READ_EOF) { r->m_read.status == RTMP_READ_EOF) {
conn->data->req.size = conn->data->req.bytecount; conn->data->req.size = conn->data->req.bytecount;
nread = 0; nread = 0;
} else }
else
*err = CURLE_RECV_ERROR; *err = CURLE_RECV_ERROR;
} }
return nread; return nread;
@ -284,9 +288,9 @@ static ssize_t rtmp_send(struct connectdata *conn, int sockindex,
(void)sockindex; /* unused */ (void)sockindex; /* unused */
num = RTMP_Write(r, (char *)buf, len); num = RTMP_Write(r, (char *)buf, len);
if (num < 0) { if(num < 0)
*err = CURLE_SEND_ERROR; *err = CURLE_SEND_ERROR;
}
return num; return num;
} }
#endif /* USE_LIBRTMP */ #endif /* USE_LIBRTMP */

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -95,7 +95,8 @@ int Curl_thread_join(curl_thread_t *hnd)
#elif defined(USE_THREADS_WIN32) #elif defined(USE_THREADS_WIN32)
curl_thread_t Curl_thread_create(unsigned int (CURL_STDCALL *func) (void*), void *arg) curl_thread_t Curl_thread_create(unsigned int (CURL_STDCALL *func) (void*),
void *arg)
{ {
#ifdef _WIN32_WCE #ifdef _WIN32_WCE
return CreateThread(NULL, 0, func, arg, 0, NULL); return CreateThread(NULL, 0, func, arg, 0, NULL);

View File

@ -124,10 +124,10 @@ cyassl_connect_step1(struct connectdata *conn,
/* load trusted cacert */ /* load trusted cacert */
if(data->set.str[STRING_SSL_CAFILE]) { if(data->set.str[STRING_SSL_CAFILE]) {
if (!SSL_CTX_load_verify_locations(conssl->ctx, if(!SSL_CTX_load_verify_locations(conssl->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 insiste on successfully verifying the server. */ /* Fail if we insiste 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",
@ -161,7 +161,7 @@ cyassl_connect_step1(struct connectdata *conn,
if(data->set.str[STRING_CERT] && data->set.str[STRING_KEY]) { if(data->set.str[STRING_CERT] && data->set.str[STRING_KEY]) {
int file_type = do_file_type(data->set.str[STRING_CERT_TYPE]); int file_type = do_file_type(data->set.str[STRING_CERT_TYPE]);
if (SSL_CTX_use_certificate_file(conssl->ctx, data->set.str[STRING_CERT], if(SSL_CTX_use_certificate_file(conssl->ctx, data->set.str[STRING_CERT],
file_type) != 1) { file_type) != 1) {
failf(data, "unable to use client certificate (no key or wrong pass" failf(data, "unable to use client certificate (no key or wrong pass"
" phrase?)"); " phrase?)");
@ -169,7 +169,7 @@ cyassl_connect_step1(struct connectdata *conn,
} }
file_type = do_file_type(data->set.str[STRING_KEY_TYPE]); file_type = do_file_type(data->set.str[STRING_KEY_TYPE]);
if (SSL_CTX_use_PrivateKey_file(conssl->ctx, data->set.str[STRING_KEY], if(SSL_CTX_use_PrivateKey_file(conssl->ctx, data->set.str[STRING_KEY],
file_type) != 1) { file_type) != 1) {
failf(data, "unable to set private key"); failf(data, "unable to set private key");
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
@ -185,10 +185,10 @@ cyassl_connect_step1(struct connectdata *conn,
NULL); NULL);
/* Let's make an SSL structure */ /* Let's make an SSL structure */
if (conssl->handle) if(conssl->handle)
SSL_free(conssl->handle); SSL_free(conssl->handle);
conssl->handle = SSL_new(conssl->ctx); conssl->handle = SSL_new(conssl->ctx);
if (!conssl->handle) { if(!conssl->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;
} }
@ -206,7 +206,7 @@ cyassl_connect_step1(struct connectdata *conn,
} }
/* pass the raw socket into the SSL layer */ /* pass the raw socket into the SSL layer */
if (!SSL_set_fd(conssl->handle, (int)sockfd)) { if(!SSL_set_fd(conssl->handle, (int)sockfd)) {
failf(data, "SSL: SSL_set_fd failed"); failf(data, "SSL: SSL_set_fd failed");
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
} }
@ -231,16 +231,16 @@ cyassl_connect_step2(struct connectdata *conn,
conn->send[sockindex] = cyassl_send; conn->send[sockindex] = cyassl_send;
ret = SSL_connect(conssl->handle); ret = SSL_connect(conssl->handle);
if (ret != 1) { if(ret != 1) {
char error_buffer[80]; char error_buffer[80];
int detail = SSL_get_error(conssl->handle, ret); int detail = SSL_get_error(conssl->handle, ret);
if (SSL_ERROR_WANT_READ == detail) { if(SSL_ERROR_WANT_READ == detail) {
conssl->connecting_state = ssl_connect_2_reading; conssl->connecting_state = ssl_connect_2_reading;
return CURLE_OK; return CURLE_OK;
} }
if (SSL_ERROR_WANT_WRITE == detail) { if(SSL_ERROR_WANT_WRITE == detail) {
conssl->connecting_state = ssl_connect_2_writing; conssl->connecting_state = ssl_connect_2_writing;
return CURLE_OK; return CURLE_OK;
} }
@ -273,14 +273,14 @@ cyassl_connect_step3(struct connectdata *conn,
our_ssl_sessionid = SSL_get_session(connssl->handle); our_ssl_sessionid = SSL_get_session(connssl->handle);
incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL)); incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL));
if (incache) { if(incache) {
if (old_ssl_sessionid != our_ssl_sessionid) { if(old_ssl_sessionid != our_ssl_sessionid) {
infof(data, "old SSL session ID is stale, removing\n"); infof(data, "old SSL session ID is stale, removing\n");
Curl_ssl_delsessionid(conn, old_ssl_sessionid); Curl_ssl_delsessionid(conn, old_ssl_sessionid);
incache = FALSE; incache = FALSE;
} }
} }
if (!incache) { if(!incache) {
retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid, retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid,
0 /* unknown size */); 0 /* unknown size */);
if(retcode) { if(retcode) {
@ -305,7 +305,7 @@ static ssize_t cyassl_send(struct connectdata *conn,
int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len; int memlen = (len > (size_t)INT_MAX) ? INT_MAX : (int)len;
int rc = SSL_write(conn->ssl[sockindex].handle, mem, memlen); int rc = SSL_write(conn->ssl[sockindex].handle, mem, memlen);
if (rc < 0) { if(rc < 0) {
int err = SSL_get_error(conn->ssl[sockindex].handle, rc); int err = SSL_get_error(conn->ssl[sockindex].handle, rc);
switch(err) { switch(err) {
@ -355,7 +355,7 @@ static ssize_t cyassl_recv(struct connectdata *conn,
int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize; int buffsize = (buffersize > (size_t)INT_MAX) ? INT_MAX : (int)buffersize;
int nread = SSL_read(conn->ssl[num].handle, buf, buffsize); int nread = SSL_read(conn->ssl[num].handle, buf, buffsize);
if (nread < 0) { if(nread < 0) {
int err = SSL_get_error(conn->ssl[num].handle, nread); int err = SSL_get_error(conn->ssl[num].handle, nread);
switch(err) { switch(err) {
@ -405,7 +405,7 @@ int Curl_cyassl_init(void)
bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex) bool Curl_cyassl_data_pending(const struct connectdata* conn, int connindex)
{ {
if (conn->ssl[connindex].handle) /* SSL is in use */ if(conn->ssl[connindex].handle) /* SSL is in use */
return (bool)(0 != SSL_pending(conn->ssl[connindex].handle)); return (bool)(0 != SSL_pending(conn->ssl[connindex].handle));
else else
return FALSE; return FALSE;

View File

@ -279,7 +279,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
int i; int i;
ppath++; ppath++;
for (i = 0; ppath[i]; i++) { for(i = 0; ppath[i]; i++) {
if(ppath[i] == ':') if(ppath[i] == ':')
ppath[i] = ' '; ppath[i] = ' ';
} }

View File

@ -147,7 +147,7 @@ static CURLcode win32_init(void)
#ifdef USE_WINDOWS_SSPI #ifdef USE_WINDOWS_SSPI
{ {
CURLcode err = Curl_sspi_global_init(); CURLcode err = Curl_sspi_global_init();
if (err != CURLE_OK) if(err != CURLE_OK)
return err; return err;
} }
#endif #endif
@ -764,8 +764,8 @@ CURLcode curl_easy_pause(CURL *curl, int action)
k->keepon = newstate; k->keepon = newstate;
if(!(newstate & KEEP_RECV_PAUSE) && data->state.tempwrite) { if(!(newstate & KEEP_RECV_PAUSE) && data->state.tempwrite) {
/* we have a buffer for sending that we now seem to be able to deliver since /* we have a buffer for sending that we now seem to be able to deliver
the receive pausing is lifted! */ since the receive pausing is lifted! */
/* get the pointer, type and length in local copies since the function may /* get the pointer, type and length in local copies since the function may
return PAUSE again and then we'll get a new copy allocted and stored in return PAUSE again and then we'll get a new copy allocted and stored in

View File

@ -98,10 +98,9 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength)
while(length--) { while(length--) {
in = *string; in = *string;
if (Curl_isunreserved(in)) { if(Curl_isunreserved(in))
/* just copy this */ /* just copy this */
ns[strindex++]=in; ns[strindex++]=in;
}
else { else {
/* encode it */ /* encode it */
newlen += 2; /* the size grows with two, since this'll become a %XX */ newlen += 2; /* the size grows with two, since this'll become a %XX */

View File

@ -90,7 +90,8 @@
/* The last #include file should be: */ /* The last #include file should be: */
#include "memdebug.h" #include "memdebug.h"
#if defined(WIN32) || defined(MSDOS) || defined(__EMX__) || defined(__SYMBIAN32__) #if defined(WIN32) || defined(MSDOS) || defined(__EMX__) || \
defined(__SYMBIAN32__)
#define DOS_FILESYSTEM 1 #define DOS_FILESYSTEM 1
#endif #endif
@ -245,18 +246,17 @@ static CURLcode file_connect(struct connectdata *conn, bool *done)
actual_path = real_path; actual_path = real_path;
if((actual_path[0] == '/') && if((actual_path[0] == '/') &&
actual_path[1] && actual_path[1] &&
(actual_path[2] == ':' || actual_path[2] == '|')) (actual_path[2] == ':' || actual_path[2] == '|')) {
{
actual_path[2] = ':'; actual_path[2] = ':';
actual_path++; actual_path++;
} }
/* change path separators from '/' to '\\' for DOS, Windows and OS/2 */ /* change path separators from '/' to '\\' for DOS, Windows and OS/2 */
for (i=0; actual_path[i] != '\0'; ++i) for(i=0; actual_path[i] != '\0'; ++i)
if(actual_path[i] == '/') if(actual_path[i] == '/')
actual_path[i] = '\\'; actual_path[i] = '\\';
fd = open_readonly(actual_path, O_RDONLY|O_BINARY); /* no CR/LF translation */ fd = open_readonly(actual_path, O_RDONLY|O_BINARY);
file->path = actual_path; file->path = actual_path;
#else #else
fd = open_readonly(real_path, O_RDONLY); fd = open_readonly(real_path, O_RDONLY);
@ -536,7 +536,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
} }
/* A high water mark has been specified so we obey... */ /* A high water mark has been specified so we obey... */
if (data->req.maxdownload > 0) if(data->req.maxdownload > 0)
expected_size = data->req.maxdownload; expected_size = data->req.maxdownload;
if(fstated && (expected_size == 0)) if(fstated && (expected_size == 0))
@ -565,7 +565,7 @@ static CURLcode file_do(struct connectdata *conn, bool *done)
if( nread > 0) if( nread > 0)
buf[nread] = 0; buf[nread] = 0;
if (nread <= 0 || expected_size == 0) if(nread <= 0 || expected_size == 0)
break; break;
bytecount += nread; bytecount += nread;

View File

@ -20,87 +20,6 @@
* *
***************************************************************************/ ***************************************************************************/
/*
Debug the form generator stand-alone by compiling this source file with:
gcc -DHAVE_CONFIG_H -I../ -g -D_FORM_DEBUG -DCURLDEBUG -o formdata \
-I../include formdata.c strequal.c memdebug.c mprintf.c strerror.c
(depending on circumstances you may need further externals added)
run the 'formdata' executable the output should end with:
All Tests seem to have worked ...
and the following parts should be there:
Content-Disposition: form-data; name="simple_COPYCONTENTS"
value for simple COPYCONTENTS
Content-Disposition: form-data; name="COPYCONTENTS_+_CONTENTTYPE"
Content-Type: image/gif
value for COPYCONTENTS + CONTENTTYPE
Content-Disposition: form-data; name="PRNAME_+_NAMELENGTH_+_COPYNAME_+_CONTENTSLENGTH"
vlue for PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH
(or you might see P^@RNAME and v^@lue at the start)
Content-Disposition: form-data; name="simple_PTRCONTENTS"
value for simple PTRCONTENTS
Content-Disposition: form-data; name="PTRCONTENTS_+_CONTENTSLENGTH"
vlue for PTRCONTENTS + CONTENTSLENGTH
(or you might see v^@lue at the start)
Content-Disposition: form-data; name="PTRCONTENTS_+_CONTENTSLENGTH_+_CONTENTTYPE"
Content-Type: application/octet-stream
vlue for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE
(or you might see v^@lue at the start)
Content-Disposition: form-data; name="FILE1_+_CONTENTTYPE"; filename="formdata.h"
Content-Type: text/html
...
Content-Disposition: form-data; name="FILE1_+_FILE2"
Content-Type: multipart/mixed, boundary=curlz1s0dkticx49MV1KGcYP5cvfSsz
...
Content-Disposition: attachment; filename="formdata.h"
Content-Type: application/octet-stream
...
Content-Disposition: attachment; filename="Makefile.b32"
Content-Type: application/octet-stream
...
Content-Disposition: form-data; name="FILE1_+_FILE2_+_FILE3"
Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
...
Content-Disposition: attachment; filename="formdata.h"
Content-Type: application/octet-stream
...
Content-Disposition: attachment; filename="Makefile.b32"
Content-Type: application/octet-stream
...
Content-Disposition: attachment; filename="formdata.h"
Content-Type: application/octet-stream
...
Content-Disposition: form-data; name="ARRAY: FILE1_+_FILE2_+_FILE3"
Content-Type: multipart/mixed, boundary=curlirkYPmPwu6FrJ1vJ1u1BmtIufh1
...
Content-Disposition: attachment; filename="formdata.h"
Content-Type: application/octet-stream
...
Content-Disposition: attachment; filename="Makefile.b32"
Content-Type: application/octet-stream
...
Content-Disposition: attachment; filename="formdata.h"
Content-Type: application/octet-stream
...
Content-Disposition: form-data; name="FILECONTENT"
...
*/
#include "setup.h" #include "setup.h"
#include <curl/curl.h> #include <curl/curl.h>
@ -382,7 +301,7 @@ static char *memdup(const char *src, size_t buffer_length)
* CURL_FORMADD_NULL if a null pointer was given for a char * CURL_FORMADD_NULL if a null pointer was given for a char
* CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed * CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed
* CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used * CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used
* CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or an error) * CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error)
* CURL_FORMADD_MEMORY if a HttpPost struct cannot be allocated * CURL_FORMADD_MEMORY if a HttpPost struct cannot be allocated
* CURL_FORMADD_MEMORY if some allocation for string copying failed. * CURL_FORMADD_MEMORY if some allocation for string copying failed.
* CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array * CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array
@ -951,7 +870,7 @@ int curl_formget(struct curl_httppost *form, void *arg,
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;
@ -1478,168 +1397,6 @@ char *Curl_formpostheader(void *formp, size_t *len)
return header; return header;
} }
#ifdef _FORM_DEBUG
int FormAddTest(const char * errormsg,
struct curl_httppost **httppost,
struct curl_httppost **last_post,
...)
{
int result;
va_list arg;
va_start(arg, last_post);
if((result = FormAdd(httppost, last_post, arg)))
fprintf (stderr, "ERROR doing FormAdd ret: %d action: %s\n", result,
errormsg);
va_end(arg);
return result;
}
int main(int argc, argv_item_t argv[])
{
char name1[] = "simple_COPYCONTENTS";
char name2[] = "COPYCONTENTS_+_CONTENTTYPE";
char name3[] = "PTRNAME_+_NAMELENGTH_+_COPYNAME_+_CONTENTSLENGTH";
char name4[] = "simple_PTRCONTENTS";
char name5[] = "PTRCONTENTS_+_CONTENTSLENGTH";
char name6[] = "PTRCONTENTS_+_CONTENTSLENGTH_+_CONTENTTYPE";
char name7[] = "FILE1_+_CONTENTTYPE";
char name8[] = "FILE1_+_FILE2";
char name9[] = "FILE1_+_FILE2_+_FILE3";
char name10[] = "ARRAY: FILE1_+_FILE2_+_FILE3";
char name11[] = "FILECONTENT";
char value1[] = "value for simple COPYCONTENTS";
char value2[] = "value for COPYCONTENTS + CONTENTTYPE";
char value3[] = "value for PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH";
char value4[] = "value for simple PTRCONTENTS";
char value5[] = "value for PTRCONTENTS + CONTENTSLENGTH";
char value6[] = "value for PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE";
char value7[] = "formdata.h";
char value8[] = "Makefile.b32";
char type2[] = "image/gif";
char type6[] = "text/plain";
char type7[] = "text/html";
int name3length = strlen(name3);
int value3length = strlen(value3);
int value5length = strlen(value5);
int value6length = strlen(value6);
int errors = 0;
CURLcode rc;
curl_off_t size;
size_t nread;
char buffer[4096];
struct curl_httppost *httppost=NULL;
struct curl_httppost *last_post=NULL;
struct curl_forms forms[4];
struct FormData *form;
struct Form formread;
(void) argc;
(void) argv;
Curl_srand(); /* Because we do not call curl_global_init() here. */
if(FormAddTest("simple COPYCONTENTS test", &httppost, &last_post,
CURLFORM_COPYNAME, name1, CURLFORM_COPYCONTENTS, value1,
CURLFORM_END))
++errors;
if(FormAddTest("COPYCONTENTS + CONTENTTYPE test", &httppost, &last_post,
CURLFORM_COPYNAME, name2, CURLFORM_COPYCONTENTS, value2,
CURLFORM_CONTENTTYPE, type2, CURLFORM_END))
++errors;
/* make null character at start to check that contentslength works
correctly */
name3[1] = '\0';
value3[1] = '\0';
if(FormAddTest("PTRNAME + NAMELENGTH + COPYNAME + CONTENTSLENGTH test",
&httppost, &last_post,
CURLFORM_PTRNAME, name3, CURLFORM_COPYCONTENTS, value3,
CURLFORM_CONTENTSLENGTH, value3length,
CURLFORM_NAMELENGTH, name3length, CURLFORM_END))
++errors;
if(FormAddTest("simple PTRCONTENTS test", &httppost, &last_post,
CURLFORM_COPYNAME, name4, CURLFORM_PTRCONTENTS, value4,
CURLFORM_END))
++errors;
/* make null character at start to check that contentslength works
correctly */
value5[1] = '\0';
if(FormAddTest("PTRCONTENTS + CONTENTSLENGTH test", &httppost, &last_post,
CURLFORM_COPYNAME, name5, CURLFORM_PTRCONTENTS, value5,
CURLFORM_CONTENTSLENGTH, value5length, CURLFORM_END))
++errors;
/* make null character at start to check that contentslength works
correctly */
value6[1] = '\0';
if(FormAddTest("PTRCONTENTS + CONTENTSLENGTH + CONTENTTYPE test",
&httppost, &last_post,
CURLFORM_COPYNAME, name6, CURLFORM_PTRCONTENTS, value6,
CURLFORM_CONTENTSLENGTH, value6length,
CURLFORM_CONTENTTYPE, type6, CURLFORM_END))
++errors;
if(FormAddTest("FILE + CONTENTTYPE test", &httppost, &last_post,
CURLFORM_COPYNAME, name7, CURLFORM_FILE, value7,
CURLFORM_CONTENTTYPE, type7, CURLFORM_END))
++errors;
if(FormAddTest("FILE1 + FILE2 test", &httppost, &last_post,
CURLFORM_COPYNAME, name8, CURLFORM_FILE, value7,
CURLFORM_FILE, value8, CURLFORM_END))
++errors;
if(FormAddTest("FILE1 + FILE2 + FILE3 test", &httppost, &last_post,
CURLFORM_COPYNAME, name9, CURLFORM_FILE, value7,
CURLFORM_FILE, value8, CURLFORM_FILE, value7, CURLFORM_END))
++errors;
forms[0].option = CURLFORM_FILE;
forms[0].value = value7;
forms[1].option = CURLFORM_FILE;
forms[1].value = value8;
forms[2].option = CURLFORM_FILE;
forms[2].value = value7;
forms[3].option = CURLFORM_END;
if(FormAddTest("FILE1 + FILE2 + FILE3 ARRAY test", &httppost, &last_post,
CURLFORM_COPYNAME, name10, CURLFORM_ARRAY, forms,
CURLFORM_END))
++errors;
if(FormAddTest("FILECONTENT test", &httppost, &last_post,
CURLFORM_COPYNAME, name11, CURLFORM_FILECONTENT, value7,
CURLFORM_END))
++errors;
rc = Curl_getformdata(NULL, &form, httppost, NULL, &size);
if(rc != CURLE_OK) {
if(rc != CURLE_READ_ERROR) {
const char *errortext = curl_easy_strerror(rc);
fprintf(stdout, "\n==> Curl_getformdata error: %s\n", errortext);
}
return 0;
}
Curl_FormInit(&formread, form);
for(;;) {
nread = Curl_FormReader(buffer, 1, sizeof(buffer),
(FILE *)&formread);
if(nread < 1)
break;
fwrite(buffer, nread, 1, stdout);
}
fprintf(stdout, "size: ");
fprintf(stdout, "%" FORMAT_OFF_T, size);
fprintf(stdout, "\n");
if(errors)
fprintf(stdout, "\n==> %d Test(s) failed!\n", errors);
else
fprintf(stdout, "\nAll Tests seem to have worked (please check output)\n");
return 0;
}
#endif /* _FORM_DEBUG */
#else /* CURL_DISABLE_HTTP */ #else /* CURL_DISABLE_HTTP */
CURLFORMcode curl_formadd(struct curl_httppost **httppost, CURLFORMcode curl_formadd(struct curl_httppost **httppost,
struct curl_httppost **last_post, struct curl_httppost **last_post,

View File

@ -274,7 +274,7 @@ static void freedirs(struct ftp_conn *ftpc)
{ {
int i; int i;
if(ftpc->dirs) { if(ftpc->dirs) {
for (i=0; i < ftpc->dirdepth; i++){ for(i=0; i < ftpc->dirdepth; i++){
if(ftpc->dirs[i]) { if(ftpc->dirs[i]) {
free(ftpc->dirs[i]); free(ftpc->dirs[i]);
ftpc->dirs[i]=NULL; ftpc->dirs[i]=NULL;
@ -741,7 +741,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
char *port_sep = NULL; char *port_sep = NULL;
addr = calloc(addrlen+1, 1); addr = calloc(addrlen+1, 1);
if (!addr) if(!addr)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
@ -765,12 +765,11 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
port_min = port_max = 0; port_min = port_max = 0;
strcpy(addr, string_ftpport); strcpy(addr, string_ftpport);
ip_end = NULL; /* this got no port ! */ ip_end = NULL; /* this got no port ! */
} else }
else
#endif #endif
{
/* (ipv4|domain|interface):port(-range) */ /* (ipv4|domain|interface):port(-range) */
strncpy(addr, string_ftpport, ip_end - ip_start ); strncpy(addr, string_ftpport, ip_end - ip_start );
}
} }
else else
/* ipv4|interface */ /* ipv4|interface */
@ -819,20 +818,19 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
if(getsockname(conn->sock[FIRSTSOCKET], sa, &sslen)) { if(getsockname(conn->sock[FIRSTSOCKET], sa, &sslen)) {
failf(data, "getsockname() failed: %s", failf(data, "getsockname() failed: %s",
Curl_strerror(conn, SOCKERRNO) ); Curl_strerror(conn, SOCKERRNO) );
if (addr) if(addr)
free(addr); free(addr);
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
switch(sa->sa_family) switch(sa->sa_family) {
{
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
case AF_INET6: case AF_INET6:
Curl_inet_ntop(sa->sa_family, &sa6->sin6_addr, hbuf, sizeof(hbuf)); Curl_inet_ntop(sa->sa_family, &sa6->sin6_addr, hbuf, sizeof(hbuf));
break; break;
#endif #endif
default: default:
Curl_inet_ntop(sa->sa_family, &sa4->sin_addr, hbuf, sizeof(hbuf)); Curl_inet_ntop(sa->sa_family, &sa4->sin_addr, hbuf, sizeof(hbuf));
break; break;
} }
host = hbuf; /* use this host name */ host = hbuf; /* use this host name */
} }
@ -850,10 +848,10 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
else else
res = NULL; /* failure! */ res = NULL; /* failure! */
if (addr) if(addr)
free(addr); free(addr);
if (res == NULL) { if(res == NULL) {
failf(data, "Curl_resolv failed, we can not recover!"); failf(data, "Curl_resolv failed, we can not recover!");
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
} }
@ -862,7 +860,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
portsock = CURL_SOCKET_BAD; portsock = CURL_SOCKET_BAD;
error = 0; error = 0;
for (ai = res; ai; ai = ai->ai_next) { for(ai = res; ai; ai = ai->ai_next) {
/* /*
* Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype): * Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype):
*/ */
@ -929,7 +927,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
} }
/* maybe all ports were in use already*/ /* maybe all ports were in use already*/
if (port > port_max) { if(port > port_max) {
failf(data, "bind() failed, we ran out of ports!"); failf(data, "bind() failed, we ran out of ports!");
sclose(portsock); sclose(portsock);
return CURLE_FTP_PORT_FAILED; return CURLE_FTP_PORT_FAILED;
@ -966,7 +964,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
conn->bits.ftp_use_eprt = TRUE; conn->bits.ftp_use_eprt = TRUE;
#endif #endif
for (; fcmd != DONE; fcmd++) { for(; fcmd != DONE; fcmd++) {
if(!conn->bits.ftp_use_eprt && (EPRT == fcmd)) if(!conn->bits.ftp_use_eprt && (EPRT == fcmd))
/* if disabled, goto next */ /* if disabled, goto next */
@ -2171,7 +2169,7 @@ static CURLcode ftp_state_get_resp(struct connectdata *conn,
150 ASCII data connection for /bin/ls (137.167.104.91,37445) (0 bytes). 150 ASCII data connection for /bin/ls (137.167.104.91,37445) (0 bytes).
D: D:
150 Opening ASCII mode data connection for /linux/fisk/kpanelrc (0.0.0.0,0) (545 bytes). 150 Opening ASCII mode data connection for [file] (0.0.0.0,0) (545 bytes)
E: E:
125 Data connection already open; Transfer starting. */ 125 Data connection already open; Transfer starting. */
@ -2583,7 +2581,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
if('\"' == *ptr) { if('\"' == *ptr) {
/* it started good */ /* it started good */
ptr++; ptr++;
for (store = dir; *ptr;) { for(store = dir; *ptr;) {
if('\"' == *ptr) { if('\"' == *ptr) {
if('\"' == ptr[1]) { if('\"' == ptr[1]) {
/* "quote-doubling" */ /* "quote-doubling" */
@ -2649,9 +2647,9 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
/* Reply format is like /* Reply format is like
215<space><OS-name><space><commentary> 215<space><OS-name><space><commentary>
*/ */
while (*ptr == ' ') while(*ptr == ' ')
ptr++; ptr++;
for (store = os; *ptr && *ptr != ' ';) for(store = os; *ptr && *ptr != ' ';)
*store++ = *ptr++; *store++ = *ptr++;
*store = '\0'; /* zero terminate */ *store = '\0'; /* zero terminate */
ftpc->server_os = os; ftpc->server_os = os;
@ -2770,7 +2768,7 @@ static CURLcode ftp_statemach_act(struct connectdata *conn)
case FTP_PRET: case FTP_PRET:
if(ftpcode != 200) { if(ftpcode != 200) {
/* there only is this one standard OK return code. */ /* there only is this one standard OK return code. */
failf(data, "PRET command not accepted: %03d", ftpcode); failf(data, "PRET command not accepted: %03d", ftpcode);
return CURLE_FTP_PRET_FAILED; return CURLE_FTP_PRET_FAILED;
} }
@ -3511,7 +3509,7 @@ static CURLcode init_wc_data(struct connectdata *conn)
} }
else { else {
wildcard->pattern = strdup(last_slash); wildcard->pattern = strdup(last_slash);
if (!wildcard->pattern) if(!wildcard->pattern)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
last_slash[0] = '\0'; /* cut file from path */ last_slash[0] = '\0'; /* cut file from path */
} }
@ -3519,7 +3517,7 @@ static CURLcode init_wc_data(struct connectdata *conn)
else { /* there is only 'wildcard pattern' or nothing */ else { /* there is only 'wildcard pattern' or nothing */
if(path[0]) { if(path[0]) {
wildcard->pattern = strdup(path); wildcard->pattern = strdup(path);
if (!wildcard->pattern) if(!wildcard->pattern)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
path[0] = '\0'; path[0] = '\0';
} }
@ -3561,7 +3559,7 @@ static CURLcode init_wc_data(struct connectdata *conn)
/* backup old write_function */ /* backup old write_function */
ftp_tmp->backup.write_function = conn->data->set.fwrite_func; ftp_tmp->backup.write_function = conn->data->set.fwrite_func;
/* parsing write function (callback included directly from ftplistparser.c) */ /* parsing write function */
conn->data->set.fwrite_func = Curl_ftp_parselist; conn->data->set.fwrite_func = Curl_ftp_parselist;
/* backup old file descriptor */ /* backup old file descriptor */
ftp_tmp->backup.file_descriptor = conn->data->set.out; ftp_tmp->backup.file_descriptor = conn->data->set.out;

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -66,7 +66,7 @@ typedef enum {
FTP_STOR_TYPE, /* set type when about to STOR a file */ FTP_STOR_TYPE, /* set type when about to STOR a file */
FTP_SIZE, /* get the remote file's size for head-like request */ FTP_SIZE, /* get the remote file's size for head-like request */
FTP_RETR_SIZE, /* get the remote file's size for RETR */ FTP_RETR_SIZE, /* get the remote file's size for RETR */
FTP_STOR_SIZE, /* get the size for (resumed) STOR */ FTP_STOR_SIZE, /* get the size for STOR */
FTP_REST, /* when used to check if the server supports it in head-like */ FTP_REST, /* when used to check if the server supports it in head-like */
FTP_RETR_REST, /* when asking for "resume" in for RETR */ FTP_RETR_REST, /* when asking for "resume" in for RETR */
FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */ FTP_PORT, /* generic state for PORT, LPRT and EPRT, check count1 */
@ -93,7 +93,8 @@ struct ftp_wc_tmpdata {
typedef enum { typedef enum {
FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */ FTPFILE_MULTICWD = 1, /* as defined by RFC1738 */
FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */ FTPFILE_NOCWD = 2, /* use SIZE / RETR / STOR on the full path */
FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the file */ FTPFILE_SINGLECWD = 3 /* make one CWD, then SIZE / RETR / STOR on the
file */
} curl_ftpfile; } curl_ftpfile;
typedef enum { typedef enum {
@ -147,7 +148,8 @@ struct ftp_conn {
ftpstate state; /* always use ftp.c:state() to change state! */ ftpstate state; /* always use ftp.c:state() to change state! */
char * server_os; /* The target server operating system. */ char * server_os; /* The target server operating system. */
curl_off_t known_filesize; /* file size is different from -1, if wildcard curl_off_t known_filesize; /* file size is different from -1, if wildcard
LIST parsing was done and wc_statemach set it */ LIST parsing was done and wc_statemach set
it */
}; };
#endif /* HEADER_CURL_FTP_H */ #endif /* HEADER_CURL_FTP_H */

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -329,7 +329,8 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
compare = Curl_fnmatch; compare = Curl_fnmatch;
/* filter pattern-corresponding filenames */ /* filter pattern-corresponding filenames */
if(compare(conn->data->set.fnmatch_data, wc->pattern, finfo->filename) == 0) { if(compare(conn->data->set.fnmatch_data, wc->pattern,
finfo->filename) == 0) {
/* discard symlink which is containing multiple " -> " */ /* discard symlink which is containing multiple " -> " */
if((finfo->filetype == CURLFILETYPE_SYMLINK) && finfo->strings.target && if((finfo->filetype == CURLFILETYPE_SYMLINK) && finfo->strings.target &&
(strstr(finfo->strings.target, " -> "))) { (strstr(finfo->strings.target, " -> "))) {
@ -645,7 +646,7 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
parser->state.UNIX.main = PL_UNIX_TIME; parser->state.UNIX.main = PL_UNIX_TIME;
parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART1; parser->state.UNIX.sub.time = PL_UNIX_TIME_PREPART1;
} }
else if (!ISDIGIT(c)) { else if(!ISDIGIT(c)) {
PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST); PL_ERROR(conn, CURLE_FTP_BAD_FILE_LIST);
return bufflen; return bufflen;
} }
@ -960,7 +961,8 @@ size_t Curl_ftp_parselist(char *buffer, size_t size, size_t nmemb,
} }
else { else {
char *endptr; char *endptr;
finfo->size = curlx_strtoofft(finfo->b_data + parser->item_offset, finfo->size = curlx_strtoofft(finfo->b_data +
parser->item_offset,
&endptr, 10); &endptr, 10);
if(!*endptr) { if(!*endptr) {
if(finfo->size == CURL_OFF_T_MAX || if(finfo->size == CURL_OFF_T_MAX ||

View File

@ -132,7 +132,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
*done = TRUE; /* unconditionally */ *done = TRUE; /* unconditionally */
/* Create selector. Degenerate cases: / and /1 => convert to "" */ /* Create selector. Degenerate cases: / and /1 => convert to "" */
if (strlen(path) <= 2) if(strlen(path) <= 2)
sel = (char *)""; sel = (char *)"";
else { else {
char *newp; char *newp;
@ -151,7 +151,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
/* ... and finally unescape */ /* ... and finally unescape */
sel = curl_easy_unescape(data, newp, 0, &len); sel = curl_easy_unescape(data, newp, 0, &len);
if (!sel) if(!sel)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
sel_org = sel; sel_org = sel;
} }
@ -162,7 +162,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
for(;;) { for(;;) {
result = Curl_write(conn, sockfd, sel, k, &amount); result = Curl_write(conn, sockfd, sel, k, &amount);
if (CURLE_OK == result) { /* Which may not have written it all! */ if(CURLE_OK == result) { /* Which may not have written it all! */
result = Curl_client_write(conn, CLIENTWRITE_HEADER, sel, amount); result = Curl_client_write(conn, CLIENTWRITE_HEADER, sel, amount);
if(result) { if(result) {
Curl_safefree(sel_org); Curl_safefree(sel_org);
@ -170,7 +170,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
} }
k -= amount; k -= amount;
sel += amount; sel += amount;
if (k < 1) if(k < 1)
break; /* but it did write it all */ break; /* but it did write it all */
} }
else { else {
@ -195,7 +195,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
/* We can use Curl_sendf to send the terminal \r\n relatively safely and /* We can use Curl_sendf to send the terminal \r\n relatively safely and
save allocing another string/doing another _write loop. */ save allocing another string/doing another _write loop. */
result = Curl_sendf(sockfd, conn, "\r\n"); result = Curl_sendf(sockfd, conn, "\r\n");
if (result != CURLE_OK) { if(result != CURLE_OK) {
failf(data, "Failed sending Gopher request"); failf(data, "Failed sending Gopher request");
return result; return result;
} }

View File

@ -197,14 +197,14 @@ static gnutls_datum load_file (const char *file)
long filelen; long filelen;
void *ptr; void *ptr;
if (!(f = fopen(file, "r"))) if(!(f = fopen(file, "r")))
return loaded_file; return loaded_file;
if (fseek(f, 0, SEEK_END) != 0 if(fseek(f, 0, SEEK_END) != 0
|| (filelen = ftell(f)) < 0 || (filelen = ftell(f)) < 0
|| fseek(f, 0, SEEK_SET) != 0 || fseek(f, 0, SEEK_SET) != 0
|| !(ptr = malloc((size_t)filelen))) || !(ptr = malloc((size_t)filelen)))
goto out; goto out;
if (fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) { if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) {
free(ptr); free(ptr);
goto out; goto out;
} }
@ -282,7 +282,7 @@ static CURLcode handshake(struct connectdata *conn,
if(nonblocking) if(nonblocking)
return CURLE_OK; return CURLE_OK;
} }
else if (rc < 0) { else if(rc < 0) {
failf(data, "gnutls_handshake() failed: %s", gnutls_strerror(rc)); failf(data, "gnutls_handshake() failed: %s", gnutls_strerror(rc));
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
} }
@ -357,7 +357,8 @@ gtls_connect_step1(struct connectdata *conn,
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
rc = gnutls_srp_set_client_credentials(conn->ssl[sockindex].srp_client_cred, rc = gnutls_srp_set_client_credentials(conn->ssl[sockindex].
srp_client_cred,
data->set.ssl.username, data->set.ssl.username,
data->set.ssl.password); data->set.ssl.password);
if(rc != GNUTLS_E_SUCCESS) { if(rc != GNUTLS_E_SUCCESS) {
@ -412,13 +413,13 @@ gtls_connect_step1(struct connectdata *conn,
/* convenient assign */ /* convenient assign */
session = conn->ssl[sockindex].session; session = conn->ssl[sockindex].session;
if ((0 == Curl_inet_pton(AF_INET, conn->host.name, &addr)) && if((0 == Curl_inet_pton(AF_INET, conn->host.name, &addr)) &&
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
(0 == Curl_inet_pton(AF_INET6, conn->host.name, &addr)) && (0 == Curl_inet_pton(AF_INET6, conn->host.name, &addr)) &&
#endif #endif
sni && sni &&
(gnutls_server_name_set(session, GNUTLS_NAME_DNS, conn->host.name, (gnutls_server_name_set(session, GNUTLS_NAME_DNS, conn->host.name,
strlen(conn->host.name)) < 0)) strlen(conn->host.name)) < 0))
infof(data, "WARNING: failed to configure server name indication (SNI) " infof(data, "WARNING: failed to configure server name indication (SNI) "
"TLS extension\n"); "TLS extension\n");
@ -447,7 +448,8 @@ gtls_connect_step1(struct connectdata *conn,
data->set.str[STRING_CERT], data->set.str[STRING_CERT],
data->set.str[STRING_KEY] ? data->set.str[STRING_KEY] ?
data->set.str[STRING_KEY] : data->set.str[STRING_CERT], data->set.str[STRING_KEY] : data->set.str[STRING_CERT],
do_file_type(data->set.str[STRING_CERT_TYPE]) ) != GNUTLS_E_SUCCESS) { do_file_type(data->set.str[STRING_CERT_TYPE]) ) !=
GNUTLS_E_SUCCESS) {
failf(data, "error reading X.509 key or certificate file"); failf(data, "error reading X.509 key or certificate file");
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
} }
@ -458,10 +460,10 @@ gtls_connect_step1(struct connectdata *conn,
if(data->set.ssl.authtype == CURL_TLSAUTH_SRP) { if(data->set.ssl.authtype == CURL_TLSAUTH_SRP) {
rc = gnutls_credentials_set(session, GNUTLS_CRD_SRP, rc = gnutls_credentials_set(session, GNUTLS_CRD_SRP,
conn->ssl[sockindex].srp_client_cred); conn->ssl[sockindex].srp_client_cred);
if (rc != GNUTLS_E_SUCCESS) { if(rc != GNUTLS_E_SUCCESS)
failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc)); failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc));
} }
} else else
#endif #endif
rc = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, rc = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE,
conn->ssl[sockindex].cred); conn->ssl[sockindex].cred);
@ -586,13 +588,13 @@ gtls_connect_step3(struct connectdata *conn,
gnutls_x509_crt_t format */ gnutls_x509_crt_t format */
gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER); gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER);
if (data->set.ssl.issuercert) { if(data->set.ssl.issuercert) {
gnutls_x509_crt_init(&x509_issuer); gnutls_x509_crt_init(&x509_issuer);
issuerp = load_file(data->set.ssl.issuercert); issuerp = load_file(data->set.ssl.issuercert);
gnutls_x509_crt_import(x509_issuer, &issuerp, GNUTLS_X509_FMT_PEM); gnutls_x509_crt_import(x509_issuer, &issuerp, GNUTLS_X509_FMT_PEM);
rc = gnutls_x509_crt_check_issuer(x509_cert,x509_issuer); rc = gnutls_x509_crt_check_issuer(x509_cert,x509_issuer);
unload_file(issuerp); unload_file(issuerp);
if (rc <= 0) { if(rc <= 0) {
failf(data, "server certificate issuer check failed (IssuerCert: %s)", failf(data, "server certificate issuer check failed (IssuerCert: %s)",
data->set.ssl.issuercert?data->set.ssl.issuercert:"none"); data->set.ssl.issuercert?data->set.ssl.issuercert:"none");
return CURLE_SSL_ISSUER_ERROR; return CURLE_SSL_ISSUER_ERROR;
@ -743,7 +745,7 @@ after_server_cert_verification:
gnutls_session_get_data(session, connect_sessionid, &connect_idsize); gnutls_session_get_data(session, connect_sessionid, &connect_idsize);
incache = !(Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL)); incache = !(Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL));
if (incache) { if(incache) {
/* there was one before in the cache, so instead of risking that the /* there was one before in the cache, so instead of risking that the
previous one was rejected, we just kill that and store the new */ previous one was rejected, we just kill that and store the new */
Curl_ssl_delsessionid(conn, ssl_sessionid); Curl_ssl_delsessionid(conn, ssl_sessionid);
@ -869,7 +871,7 @@ static void close_one(struct connectdata *conn,
conn->ssl[idx].cred = NULL; conn->ssl[idx].cred = NULL;
} }
#ifdef USE_TLS_SRP #ifdef USE_TLS_SRP
if (conn->ssl[idx].srp_client_cred) { if(conn->ssl[idx].srp_client_cred) {
gnutls_srp_free_client_credentials(conn->ssl[idx].srp_client_cred); gnutls_srp_free_client_credentials(conn->ssl[idx].srp_client_cred);
conn->ssl[idx].srp_client_cred = NULL; conn->ssl[idx].srp_client_cred = NULL;
} }

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -72,7 +72,7 @@ Curl_hash_init(struct curl_hash *h,
h->table = malloc(slots * sizeof(struct curl_llist *)); h->table = malloc(slots * sizeof(struct curl_llist *));
if(h->table) { if(h->table) {
for (i = 0; i < slots; ++i) { for(i = 0; i < slots; ++i) {
h->table[i] = Curl_llist_alloc((curl_llist_dtor) hash_element_dtor); h->table[i] = Curl_llist_alloc((curl_llist_dtor) hash_element_dtor);
if(!h->table[i]) { if(!h->table[i]) {
while(i--) while(i--)
@ -148,7 +148,7 @@ Curl_hash_add(struct curl_hash *h, void *key, size_t key_len, void *p)
struct curl_llist_element *le; struct curl_llist_element *le;
struct curl_llist *l = FETCH_LIST (h, key, key_len); struct curl_llist *l = FETCH_LIST (h, key, key_len);
for (le = l->head; le; le = le->next) { for(le = l->head; le; le = le->next) {
he = (struct curl_hash_element *) le->ptr; he = (struct curl_hash_element *) le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) { if(h->comp_func(he->key, he->key_len, key, key_len)) {
Curl_llist_remove(l, le, (void *)h); Curl_llist_remove(l, le, (void *)h);
@ -183,7 +183,7 @@ int Curl_hash_delete(struct curl_hash *h, void *key, size_t key_len)
struct curl_hash_element *he; struct curl_hash_element *he;
struct curl_llist *l = FETCH_LIST(h, key, key_len); struct curl_llist *l = FETCH_LIST(h, key, key_len);
for (le = l->head; le; le = le->next) { for(le = l->head; le; le = le->next) {
he = le->ptr; he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) { if(h->comp_func(he->key, he->key_len, key, key_len)) {
Curl_llist_remove(l, le, (void *) h); Curl_llist_remove(l, le, (void *) h);
@ -200,7 +200,7 @@ Curl_hash_pick(struct curl_hash *h, void *key, size_t key_len)
struct curl_hash_element *he; struct curl_hash_element *he;
struct curl_llist *l = FETCH_LIST(h, key, key_len); struct curl_llist *l = FETCH_LIST(h, key, key_len);
for (le = l->head; le; le = le->next) { for(le = l->head; le; le = le->next) {
he = le->ptr; he = le->ptr;
if(h->comp_func(he->key, he->key_len, key, key_len)) { if(h->comp_func(he->key, he->key_len, key, key_len)) {
return he->ptr; return he->ptr;
@ -218,10 +218,10 @@ Curl_hash_apply(curl_hash *h, void *user,
struct curl_llist_element *le; struct curl_llist_element *le;
int i; int i;
for (i = 0; i < h->slots; ++i) { for(i = 0; i < h->slots; ++i) {
for (le = (h->table[i])->head; for(le = (h->table[i])->head;
le; le;
le = le->next) { le = le->next) {
curl_hash_element *el = le->ptr; curl_hash_element *el = le->ptr;
cb(user, el->ptr); cb(user, el->ptr);
} }
@ -234,7 +234,7 @@ Curl_hash_clean(struct curl_hash *h)
{ {
int i; int i;
for (i = 0; i < h->slots; ++i) { for(i = 0; i < h->slots; ++i) {
Curl_llist_destroy(h->table[i], (void *) h); Curl_llist_destroy(h->table[i], (void *) h);
h->table[i] = NULL; h->table[i] = NULL;
} }
@ -251,7 +251,7 @@ Curl_hash_clean_with_criterium(struct curl_hash *h, void *user,
struct curl_llist *list; struct curl_llist *list;
int i; int i;
for (i = 0; i < h->slots; ++i) { for(i = 0; i < h->slots; ++i) {
list = h->table[i]; list = h->table[i];
le = list->head; /* get first list entry */ le = list->head; /* get first list entry */
while(le) { while(le) {
@ -319,7 +319,7 @@ void Curl_hash_print(struct curl_hash *h,
fprintf(stderr, "=Hash dump=\n"); fprintf(stderr, "=Hash dump=\n");
for (i = 0; i < h->slots; i++) { for(i = 0; i < h->slots; i++) {
list = h->table[i]; list = h->table[i];
le = list->head; /* get first list entry */ le = list->head; /* get first list entry */
if(le) { if(le) {

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -59,7 +59,8 @@ Curl_HMAC_init(const HMAC_params * hashparams,
unsigned char b; unsigned char b;
/* Create HMAC context. */ /* Create HMAC context. */
i = sizeof *ctxt + 2 * hashparams->hmac_ctxtsize + hashparams->hmac_resultlen; i = sizeof *ctxt + 2 * hashparams->hmac_ctxtsize +
hashparams->hmac_resultlen;
ctxt = malloc(i); ctxt = malloc(i);
if(!ctxt) if(!ctxt)
@ -84,14 +85,14 @@ Curl_HMAC_init(const HMAC_params * hashparams,
(*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1); (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1);
(*hashparams->hmac_hinit)(ctxt->hmac_hashctxt2); (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt2);
for (i = 0; i < keylen; i++) { for(i = 0; i < keylen; i++) {
b = (unsigned char)(*key ^ hmac_ipad); b = (unsigned char)(*key ^ hmac_ipad);
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &b, 1); (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &b, 1);
b = (unsigned char)(*key++ ^ hmac_opad); b = (unsigned char)(*key++ ^ hmac_opad);
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &b, 1); (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &b, 1);
} }
for (; i < hashparams->hmac_maxkeylen; i++) { for(; i < hashparams->hmac_maxkeylen; i++) {
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &hmac_ipad, 1); (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &hmac_ipad, 1);
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &hmac_opad, 1); (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &hmac_opad, 1);
} }
@ -114,7 +115,8 @@ int Curl_HMAC_final(HMAC_context * ctxt, unsigned char * result)
{ {
const HMAC_params * hashparams = ctxt->hmac_hash; const HMAC_params * hashparams = ctxt->hmac_hash;
/* Do not get result if called with a null parameter: only release storage. */ /* Do not get result if called with a null parameter: only release
storage. */
if(!result) if(!result)
result = (unsigned char *) ctxt->hmac_hashctxt2 + result = (unsigned char *) ctxt->hmac_hashctxt2 +

View File

@ -561,7 +561,7 @@ int Curl_resolv_timeout(struct connectdata *conn,
*entry = NULL; *entry = NULL;
#ifdef USE_ALARM_TIMEOUT #ifdef USE_ALARM_TIMEOUT
if (data->set.no_signal) if(data->set.no_signal)
/* Ignore the timeout when signals are disabled */ /* Ignore the timeout when signals are disabled */
timeout = 0; timeout = 0;
else else
@ -691,7 +691,7 @@ void Curl_resolv_unlock(struct SessionHandle *data, struct Curl_dns_entry *dns)
dns->inuse--; dns->inuse--;
/* only free if nobody is using AND it is not in hostcache (timestamp == /* only free if nobody is using AND it is not in hostcache (timestamp ==
0) */ 0) */
if (dns->inuse == 0 && dns->timestamp == 0) { if(dns->inuse == 0 && dns->timestamp == 0) {
Curl_freeaddrinfo(dns->addr); Curl_freeaddrinfo(dns->addr);
free(dns); free(dns);
} }
@ -709,7 +709,7 @@ static void freednsentry(void *freethis)
/* mark the entry as not in hostcache */ /* mark the entry as not in hostcache */
p->timestamp = 0; p->timestamp = 0;
if (p->inuse == 0) { if(p->inuse == 0) {
Curl_freeaddrinfo(p->addr); Curl_freeaddrinfo(p->addr);
free(p); free(p);
} }

View File

@ -148,7 +148,7 @@ bool Curl_ipvalid(struct connectdata *conn)
static void dump_addrinfo(struct connectdata *conn, const Curl_addrinfo *ai) static void dump_addrinfo(struct connectdata *conn, const Curl_addrinfo *ai)
{ {
printf("dump_addrinfo:\n"); printf("dump_addrinfo:\n");
for ( ; ai; ai = ai->ai_next) { for(; ai; ai = ai->ai_next) {
char buf[INET6_ADDRSTRLEN]; char buf[INET6_ADDRSTRLEN];
printf(" fam %2d, CNAME %s, ", printf(" fam %2d, CNAME %s, ",

View File

@ -202,10 +202,10 @@ char *Curl_copy_header_value(const char *h)
DEBUGASSERT(h); DEBUGASSERT(h);
/* Find the end of the header name */ /* Find the end of the header name */
while (*h && (*h != ':')) while(*h && (*h != ':'))
++h; ++h;
if (*h) if(*h)
/* Skip over colon */ /* Skip over colon */
++h; ++h;
@ -1485,7 +1485,7 @@ static CURLcode expect100(struct SessionHandle *data,
100-continue to the headers which actually speeds up post operations 100-continue to the headers which actually speeds up post operations
(as there is one packet coming back from the web server) */ (as there is one packet coming back from the web server) */
ptr = Curl_checkheaders(data, "Expect:"); ptr = Curl_checkheaders(data, "Expect:");
if (ptr) { if(ptr) {
data->state.expect100header = data->state.expect100header =
Curl_compareheader(ptr, "Expect:", "100-continue"); Curl_compareheader(ptr, "Expect:", "100-continue");
} }
@ -1797,14 +1797,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
redirected request is being out on thin ice. Except if the host name redirected request is being out on thin ice. Except if the host name
is the same as the first one! */ is the same as the first one! */
char *cookiehost = Curl_copy_header_value(ptr); char *cookiehost = Curl_copy_header_value(ptr);
if (!cookiehost) if(!cookiehost)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
if (!*cookiehost) if(!*cookiehost)
/* ignore empty data */ /* ignore empty data */
free(cookiehost); free(cookiehost);
else { else {
char *colon = strchr(cookiehost, ':'); char *colon = strchr(cookiehost, ':');
if (colon) if(colon)
*colon = 0; /* The host must not include an embedded port number */ *colon = 0; /* The host must not include an embedded port number */
Curl_safefree(conn->allocptr.cookiehost); Curl_safefree(conn->allocptr.cookiehost);
conn->allocptr.cookiehost = cookiehost; conn->allocptr.cookiehost = cookiehost;
@ -1882,7 +1882,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
} }
ppath = data->change.url; ppath = data->change.url;
if(checkprefix("ftp://", ppath)) { if(checkprefix("ftp://", ppath)) {
if (data->set.proxy_transfer_mode) { if(data->set.proxy_transfer_mode) {
/* when doing ftp, append ;type=<a|i> if not present */ /* when doing ftp, append ;type=<a|i> if not present */
char *type = strstr(ppath, ";type="); char *type = strstr(ppath, ";type=");
if(type && type[6] && type[7] == 0) { if(type && type[6] && type[7] == 0) {
@ -1899,14 +1899,14 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
char *p = ftp_typecode; char *p = ftp_typecode;
/* avoid sending invalid URLs like ftp://example.com;type=i if the /* avoid sending invalid URLs like ftp://example.com;type=i if the
* user specified ftp://example.com without the slash */ * user specified ftp://example.com without the slash */
if (!*data->state.path && ppath[strlen(ppath) - 1] != '/') { if(!*data->state.path && ppath[strlen(ppath) - 1] != '/') {
*p++ = '/'; *p++ = '/';
} }
snprintf(p, sizeof(ftp_typecode) - 1, ";type=%c", snprintf(p, sizeof(ftp_typecode) - 1, ";type=%c",
data->set.prefer_ascii ? 'a' : 'i'); data->set.prefer_ascii ? 'a' : 'i');
} }
} }
if (conn->bits.user_passwd && !conn->bits.userpwd_in_url) if(conn->bits.user_passwd && !conn->bits.userpwd_in_url)
paste_ftp_userpwd = TRUE; paste_ftp_userpwd = TRUE;
} }
} }
@ -2062,17 +2062,17 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* add the main request stuff */ /* add the main request stuff */
/* GET/HEAD/POST/PUT */ /* GET/HEAD/POST/PUT */
result = Curl_add_bufferf(req_buffer, "%s ", request); result = Curl_add_bufferf(req_buffer, "%s ", request);
if (result) if(result)
return result; return result;
/* url */ /* url */
if (paste_ftp_userpwd) if(paste_ftp_userpwd)
result = Curl_add_bufferf(req_buffer, "ftp://%s:%s@%s", result = Curl_add_bufferf(req_buffer, "ftp://%s:%s@%s",
conn->user, conn->passwd, conn->user, conn->passwd,
ppath + sizeof("ftp://") - 1); ppath + sizeof("ftp://") - 1);
else else
result = Curl_add_buffer(req_buffer, ppath, strlen(ppath)); result = Curl_add_buffer(req_buffer, ppath, strlen(ppath));
if (result) if(result)
return result; return result;
result = Curl_add_bufferf(req_buffer, result = Curl_add_bufferf(req_buffer,
@ -2983,8 +2983,8 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
data->info.httpcode = k->httpcode; data->info.httpcode = k->httpcode;
data->info.httpversion = conn->httpversion; data->info.httpversion = conn->httpversion;
if (!data->state.httpversion || if(!data->state.httpversion ||
data->state.httpversion > conn->httpversion) data->state.httpversion > conn->httpversion)
/* store the lowest server version we encounter */ /* store the lowest server version we encounter */
data->state.httpversion = conn->httpversion; data->state.httpversion = conn->httpversion;
@ -3095,9 +3095,9 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
/* 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 *contenttype = Curl_copy_header_value(k->p); char *contenttype = Curl_copy_header_value(k->p);
if (!contenttype) if(!contenttype)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
if (!*contenttype) if(!*contenttype)
/* ignore empty data */ /* ignore empty data */
free(contenttype); free(contenttype);
else { else {
@ -3301,9 +3301,9 @@ CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
!data->req.location) { !data->req.location) {
/* this is the URL that the server advises us to use instead */ /* this is the URL that the server advises us to use instead */
char *location = Curl_copy_header_value(k->p); char *location = Curl_copy_header_value(k->p);
if (!location) if(!location)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
if (!*location) if(!*location)
/* ignore empty data */ /* ignore empty data */
free(location); free(location);
else { else {

View File

@ -88,8 +88,8 @@ static int get_pair(const char *str, char *value, char *content,
break; break;
case ',': case ',':
if(!starts_with_quote) { if(!starts_with_quote) {
/* this signals the end of the content if we didn't get a starting quote /* this signals the end of the content if we didn't get a starting
and then we do "sloppy" parsing */ quote and then we do "sloppy" parsing */
c=0; /* the end */ c=0; /* the end */
continue; continue;
} }

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -100,7 +100,8 @@ get_gss_name(struct connectdata *conn, bool proxy, gss_name_t *server)
} }
static void static void
log_gss_error(struct connectdata *conn, OM_uint32 error_status, const char *prefix) log_gss_error(struct connectdata *conn, OM_uint32 error_status,
const char *prefix)
{ {
OM_uint32 maj_stat, min_stat; OM_uint32 maj_stat, min_stat;
OM_uint32 msg_ctx = 0; OM_uint32 msg_ctx = 0;
@ -192,47 +193,47 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
#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;
size_t spnegoTokenLength = 0; size_t spnegoTokenLength = 0;
unsigned char * mechToken = NULL; unsigned char * mechToken = NULL;
size_t mechTokenLength = 0; size_t mechTokenLength = 0;
if(input_token.value == NULL)
return CURLE_OUT_OF_MEMORY;
spnegoToken = malloc(input_token.length);
if(spnegoToken == NULL)
return CURLE_OUT_OF_MEMORY;
spnegoTokenLength = input_token.length;
object = OBJ_txt2obj ("1.2.840.113554.1.2.2", 1);
if(!parseSpnegoTargetToken(spnegoToken,
spnegoTokenLength,
NULL,
NULL,
&mechToken,
&mechTokenLength,
NULL,
NULL)) {
free(spnegoToken);
spnegoToken = NULL;
infof(conn->data, "Parse SPNEGO Target Token failed\n");
}
else {
free(input_token.value);
input_token.value = malloc(mechTokenLength);
if(input_token.value == NULL) if(input_token.value == NULL)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
spnegoToken = malloc(input_token.length); memcpy(input_token.value, mechToken,mechTokenLength);
if(spnegoToken == NULL) input_token.length = mechTokenLength;
return CURLE_OUT_OF_MEMORY; free(mechToken);
mechToken = NULL;
spnegoTokenLength = input_token.length; infof(conn->data, "Parse SPNEGO Target Token succeeded\n");
}
object = OBJ_txt2obj ("1.2.840.113554.1.2.2", 1);
if(!parseSpnegoTargetToken(spnegoToken,
spnegoTokenLength,
NULL,
NULL,
&mechToken,
&mechTokenLength,
NULL,
NULL)) {
free(spnegoToken);
spnegoToken = NULL;
infof(conn->data, "Parse SPNEGO Target Token failed\n");
}
else {
free(input_token.value);
input_token.value = malloc(mechTokenLength);
if (input_token.value == NULL)
return CURLE_OUT_OF_MEMORY;
memcpy(input_token.value, mechToken,mechTokenLength);
input_token.length = mechTokenLength;
free(mechToken);
mechToken = NULL;
infof(conn->data, "Parse SPNEGO Target Token succeeded\n");
}
} }
#endif #endif
} }

View File

@ -133,11 +133,11 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
(ret = get_gss_name(conn, proxy, neg_ctx->server_name))) (ret = get_gss_name(conn, proxy, neg_ctx->server_name)))
return ret; return ret;
if (!neg_ctx->max_token_length) { if(!neg_ctx->max_token_length) {
PSecPkgInfo SecurityPackage; PSecPkgInfo SecurityPackage;
ret = s_pSecFn->QuerySecurityPackageInfo((SEC_CHAR *)"Negotiate", ret = s_pSecFn->QuerySecurityPackageInfo((SEC_CHAR *)"Negotiate",
&SecurityPackage); &SecurityPackage);
if (ret != SEC_E_OK) if(ret != SEC_E_OK)
return -1; return -1;
/* Allocate input and output buffers according to the max token size /* Allocate input and output buffers according to the max token size
@ -164,14 +164,14 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
return -1; return -1;
} }
if ( !input_token ) { if(!input_token) {
/* first call in a new negotiation, we have to require credentials, /* first call in a new negotation, we have to require credentials,
and allocate memory for the context */ and allocate memory for the context */
neg_ctx->credentials = (CredHandle *)malloc(sizeof(CredHandle)); neg_ctx->credentials = (CredHandle *)malloc(sizeof(CredHandle));
neg_ctx->context = (CtxtHandle *)malloc(sizeof(CtxtHandle)); neg_ctx->context = (CtxtHandle *)malloc(sizeof(CtxtHandle));
if ( !neg_ctx->credentials || !neg_ctx->context) if( !neg_ctx->credentials || !neg_ctx->context)
return -1; return -1;
neg_ctx->status = neg_ctx->status =
@ -179,7 +179,7 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
SECPKG_CRED_OUTBOUND, NULL, NULL, SECPKG_CRED_OUTBOUND, NULL, NULL,
NULL, NULL, neg_ctx->credentials, NULL, NULL, neg_ctx->credentials,
&lifetime); &lifetime);
if ( neg_ctx->status != SEC_E_OK ) if( neg_ctx->status != SEC_E_OK )
return -1; return -1;
} }
@ -193,7 +193,7 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
out_sec_buff.pvBuffer = neg_ctx->output_token; out_sec_buff.pvBuffer = neg_ctx->output_token;
if (input_token) { if(input_token) {
in_buff_desc.ulVersion = 0; in_buff_desc.ulVersion = 0;
in_buff_desc.cBuffers = 1; in_buff_desc.cBuffers = 1;
in_buff_desc.pBuffers = &out_sec_buff; in_buff_desc.pBuffers = &out_sec_buff;
@ -217,14 +217,14 @@ int Curl_input_negotiate(struct connectdata *conn, bool proxy,
&context_attributes, &context_attributes,
&lifetime); &lifetime);
if ( GSS_ERROR(neg_ctx->status) ) if( GSS_ERROR(neg_ctx->status) )
return -1; return -1;
if ( neg_ctx->status == SEC_I_COMPLETE_NEEDED || if( neg_ctx->status == SEC_I_COMPLETE_NEEDED ||
neg_ctx->status == SEC_I_COMPLETE_AND_CONTINUE ) { neg_ctx->status == SEC_I_COMPLETE_AND_CONTINUE ) {
neg_ctx->status = s_pSecFn->CompleteAuthToken(neg_ctx->context, neg_ctx->status = s_pSecFn->CompleteAuthToken(neg_ctx->context,
&out_buff_desc); &out_buff_desc);
if ( GSS_ERROR(neg_ctx->status) ) if( GSS_ERROR(neg_ctx->status) )
return -1; return -1;
} }

View File

@ -25,10 +25,6 @@
http://davenport.sourceforge.net/ntlm.html http://davenport.sourceforge.net/ntlm.html
http://www.innovation.ch/java/ntlm.html http://www.innovation.ch/java/ntlm.html
Another implementation:
http://lxr.mozilla.org/mozilla/source/security/manager/ssl/src/nsNTLMAuthModule.cpp
*/ */
#ifndef CURL_DISABLE_HTTP #ifndef CURL_DISABLE_HTTP
@ -571,7 +567,7 @@ static void ascii_to_unicode_le(unsigned char *dest, const char *src,
size_t srclen) size_t srclen)
{ {
size_t i; size_t i;
for (i=0; i<srclen; i++) { for(i=0; i<srclen; i++) {
dest[2*i] = (unsigned char)src[i]; dest[2*i] = (unsigned char)src[i];
dest[2*i+1] = '\0'; dest[2*i+1] = '\0';
} }
@ -732,10 +728,10 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
passwdp=""; passwdp="";
#ifdef USE_WINDOWS_SSPI #ifdef USE_WINDOWS_SSPI
if (s_hSecDll == NULL) { if(s_hSecDll == NULL) {
/* not thread safe and leaks - use curl_global_init() to avoid */ /* not thread safe and leaks - use curl_global_init() to avoid */
CURLcode err = Curl_sspi_global_init(); CURLcode err = Curl_sspi_global_init();
if (s_hSecDll == NULL) if(s_hSecDll == NULL)
return err; return err;
} }
#endif #endif
@ -889,25 +885,26 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
#endif #endif
DEBUG_OUT({ DEBUG_OUT({
fprintf(stderr, "**** TYPE1 header flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ", fprintf(stderr, "* TYPE1 header flags=0x%02.2x%02.2x%02.2x%02.2x "
LONGQUARTET(NTLMFLAG_NEGOTIATE_OEM| "0x%08.8x ",
NTLMFLAG_REQUEST_TARGET| LONGQUARTET(NTLMFLAG_NEGOTIATE_OEM|
NTLMFLAG_NEGOTIATE_NTLM_KEY| NTLMFLAG_REQUEST_TARGET|
NTLM2FLAG| NTLMFLAG_NEGOTIATE_NTLM_KEY|
NTLMFLAG_NEGOTIATE_ALWAYS_SIGN), NTLM2FLAG|
NTLMFLAG_NEGOTIATE_OEM| NTLMFLAG_NEGOTIATE_ALWAYS_SIGN),
NTLMFLAG_REQUEST_TARGET| NTLMFLAG_NEGOTIATE_OEM|
NTLMFLAG_NEGOTIATE_NTLM_KEY| NTLMFLAG_REQUEST_TARGET|
NTLM2FLAG| NTLMFLAG_NEGOTIATE_NTLM_KEY|
NTLMFLAG_NEGOTIATE_ALWAYS_SIGN); NTLM2FLAG|
print_flags(stderr, NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
NTLMFLAG_NEGOTIATE_OEM| print_flags(stderr,
NTLMFLAG_REQUEST_TARGET| NTLMFLAG_NEGOTIATE_OEM|
NTLMFLAG_NEGOTIATE_NTLM_KEY| NTLMFLAG_REQUEST_TARGET|
NTLM2FLAG| NTLMFLAG_NEGOTIATE_NTLM_KEY|
NTLMFLAG_NEGOTIATE_ALWAYS_SIGN); NTLM2FLAG|
fprintf(stderr, "\n****\n"); NTLMFLAG_NEGOTIATE_ALWAYS_SIGN);
}); fprintf(stderr, "\n****\n");
});
/* now size is the size of the base64 encoded package size */ /* now size is the size of the base64 encoded package size */
size = Curl_base64_encode(NULL, (char *)ntlmbuf, size, &base64); size = Curl_base64_encode(NULL, (char *)ntlmbuf, size, &base64);
@ -963,14 +960,17 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
type_3.pvBuffer = ntlmbuf; type_3.pvBuffer = ntlmbuf;
type_3.cbBuffer = sizeof(ntlmbuf); type_3.cbBuffer = sizeof(ntlmbuf);
status = s_pSecFn->InitializeSecurityContextA(&ntlm->handle, &ntlm->c_handle, status = s_pSecFn->InitializeSecurityContextA(&ntlm->handle,
(char *) host, &ntlm->c_handle,
ISC_REQ_CONFIDENTIALITY | (char *) host,
ISC_REQ_REPLAY_DETECT | ISC_REQ_CONFIDENTIALITY |
ISC_REQ_CONNECTION, ISC_REQ_REPLAY_DETECT |
0, SECURITY_NETWORK_DREP, &type_2_desc, ISC_REQ_CONNECTION,
0, &ntlm->c_handle, &type_3_desc, 0, SECURITY_NETWORK_DREP,
&attrs, &tsDummy); &type_2_desc,
0, &ntlm->c_handle,
&type_3_desc,
&attrs, &tsDummy);
if(status != SEC_E_OK) if(status != SEC_E_OK)
return CURLE_RECV_ERROR; return CURLE_RECV_ERROR;
@ -1084,7 +1084,7 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
} }
else else
#endif #endif
{ {
#if USE_NTRESPONSES #if USE_NTRESPONSES
unsigned char ntbuffer[0x18]; unsigned char ntbuffer[0x18];
@ -1219,14 +1219,14 @@ CURLcode Curl_output_ntlm(struct connectdata *conn,
} }
DEBUG_OUT({ DEBUG_OUT({
fprintf(stderr, "\n ntresp="); fprintf(stderr, "\n ntresp=");
print_hex(stderr, (char *)&ntlmbuf[ntrespoff], 0x18); print_hex(stderr, (char *)&ntlmbuf[ntrespoff], 0x18);
}); });
#endif #endif
DEBUG_OUT({ DEBUG_OUT({
fprintf(stderr, "\n flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ", fprintf(stderr, "\n flags=0x%02.2x%02.2x%02.2x%02.2x 0x%08.8x ",
LONGQUARTET(ntlm->flags), ntlm->flags); LONGQUARTET(ntlm->flags), ntlm->flags);
print_flags(stderr, ntlm->flags); print_flags(stderr, ntlm->flags);
fprintf(stderr, "\n****\n"); fprintf(stderr, "\n****\n");

View File

@ -164,8 +164,9 @@ CURLcode Curl_proxyCONNECT(struct connectdata *conn,
if(CURLE_OK == result) { if(CURLE_OK == result) {
/* Now send off the request */ /* Now send off the request */
result = Curl_add_buffer_send(req_buffer, conn, result =
&data->info.request_size, 0, sockindex); Curl_add_buffer_send(req_buffer, conn,
&data->info.request_size, 0, sockindex);
} }
req_buffer = NULL; req_buffer = NULL;
if(result) if(result)

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -39,13 +39,13 @@ static wchar_t *_curl_win32_UTF8_to_wchar(const char *str_utf8)
{ {
wchar_t *str_w = NULL; wchar_t *str_w = NULL;
if (str_utf8) { if(str_utf8) {
int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, int str_w_len = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS,
str_utf8, -1, NULL, 0); str_utf8, -1, NULL, 0);
if (str_w_len) { if(str_w_len) {
str_w = (wchar_t *) malloc(str_w_len * sizeof(wchar_t)); str_w = (wchar_t *) malloc(str_w_len * sizeof(wchar_t));
if (str_w) { if(str_w) {
if (MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w, if(MultiByteToWideChar(CP_UTF8, 0, str_utf8, -1, str_w,
str_w_len) == 0) { str_w_len) == 0) {
free(str_w); free(str_w);
str_w = NULL; str_w = NULL;
@ -61,13 +61,13 @@ static const char *_curl_win32_wchar_to_UTF8(const wchar_t *str_w)
{ {
char *str_utf8 = NULL; char *str_utf8 = NULL;
if (str_w) { if(str_w) {
size_t str_utf8_len = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL, size_t str_utf8_len = WideCharToMultiByte(CP_UTF8, 0, str_w, -1, NULL,
0, NULL, NULL); 0, NULL, NULL);
if (str_utf8_len) { if(str_utf8_len) {
str_utf8 = (char *) malloc(str_utf8_len * sizeof(wchar_t)); str_utf8 = (char *) malloc(str_utf8_len * sizeof(wchar_t));
if (str_utf8) { if(str_utf8) {
if (WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, str_utf8_len, if(WideCharToMultiByte(CP_UTF8, 0, str_w, -1, str_utf8, str_utf8_len,
NULL, FALSE) == 0) { NULL, FALSE) == 0) {
(void) GetLastError(); (void) GetLastError();
free((void *)str_utf8); free((void *)str_utf8);
@ -86,9 +86,9 @@ static const char *_curl_win32_wchar_to_UTF8(const wchar_t *str_w)
int curl_win32_idn_to_ascii(const char *in, char **out) int curl_win32_idn_to_ascii(const char *in, char **out)
{ {
wchar_t *in_w = _curl_win32_UTF8_to_wchar(in); wchar_t *in_w = _curl_win32_UTF8_to_wchar(in);
if (in_w) { if(in_w) {
wchar_t punycode[IDN_MAX_LENGTH]; wchar_t punycode[IDN_MAX_LENGTH];
if (IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH) == 0) { if(IdnToAscii(0, in_w, -1, punycode, IDN_MAX_LENGTH) == 0) {
wprintf(L"ERROR %d converting to Punycode\n", GetLastError()); wprintf(L"ERROR %d converting to Punycode\n", GetLastError());
free(in_w); free(in_w);
return 0; return 0;
@ -96,7 +96,7 @@ int curl_win32_idn_to_ascii(const char *in, char **out)
free(in_w); free(in_w);
*out = (char *)_curl_win32_wchar_to_UTF8(punycode); *out = (char *)_curl_win32_wchar_to_UTF8(punycode);
if (!(*out)) { if(!(*out)) {
return 0; return 0;
} }
} }
@ -105,16 +105,16 @@ int curl_win32_idn_to_ascii(const char *in, char **out)
int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8) int curl_win32_ascii_to_idn(const char *in, size_t in_len, char **out_utf8)
{ {
if (in) { if(in) {
WCHAR unicode[IDN_MAX_LENGTH]; WCHAR unicode[IDN_MAX_LENGTH];
if (IdnToUnicode(0, (wchar_t *)in, -1, unicode, IDN_MAX_LENGTH) == 0) { if(IdnToUnicode(0, (wchar_t *)in, -1, unicode, IDN_MAX_LENGTH) == 0) {
wprintf(L"ERROR %d converting to Punycode\n", GetLastError()); wprintf(L"ERROR %d converting to Punycode\n", GetLastError());
return 0; return 0;
} }
else { else {
const char *out_utf8 = _curl_win32_wchar_to_UTF8(unicode); const char *out_utf8 = _curl_win32_wchar_to_UTF8(unicode);
if (!out_utf8) { if(!out_utf8) {
return 0; return 0;
} }
} }

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -76,22 +76,22 @@ char *Curl_if2ip(int af, const char *interface, char *buf, int buf_size)
struct ifaddrs *iface, *head; struct ifaddrs *iface, *head;
char *ip=NULL; char *ip=NULL;
if (getifaddrs(&head) >= 0) { if(getifaddrs(&head) >= 0) {
for (iface=head; iface != NULL; iface=iface->ifa_next) { for(iface=head; iface != NULL; iface=iface->ifa_next) {
if ((iface->ifa_addr != NULL) && if((iface->ifa_addr != NULL) &&
(iface->ifa_addr->sa_family == af) && (iface->ifa_addr->sa_family == af) &&
curl_strequal(iface->ifa_name, interface)) { curl_strequal(iface->ifa_name, interface)) {
void *addr; void *addr;
char scope[12]=""; char scope[12]="";
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
if (af == AF_INET6) { if(af == AF_INET6) {
unsigned int scopeid = 0; unsigned int scopeid = 0;
addr = &((struct sockaddr_in6 *)iface->ifa_addr)->sin6_addr; addr = &((struct sockaddr_in6 *)iface->ifa_addr)->sin6_addr;
#ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID #ifdef HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID
/* Include the scope of this interface as part of the address */ /* Include the scope of this interface as part of the address */
scopeid = ((struct sockaddr_in6 *)iface->ifa_addr)->sin6_scope_id; scopeid = ((struct sockaddr_in6 *)iface->ifa_addr)->sin6_scope_id;
#endif #endif
if (scopeid) if(scopeid)
snprintf(scope, sizeof(scope), "%%%u", scopeid); snprintf(scope, sizeof(scope), "%%%u", scopeid);
} }
else else

View File

@ -99,7 +99,7 @@ static CURLcode imap_do(struct connectdata *conn, bool *done);
static CURLcode imap_done(struct connectdata *conn, static CURLcode imap_done(struct connectdata *conn,
CURLcode, bool premature); CURLcode, bool premature);
static CURLcode imap_connect(struct connectdata *conn, bool *done); static CURLcode imap_connect(struct connectdata *conn, bool *done);
static CURLcode imap_disconnect(struct connectdata *conn, bool dead_connection); static CURLcode imap_disconnect(struct connectdata *conn, bool dead);
static CURLcode imap_multi_statemach(struct connectdata *conn, bool *done); static CURLcode imap_multi_statemach(struct connectdata *conn, bool *done);
static int imap_getsock(struct connectdata *conn, static int imap_getsock(struct connectdata *conn,
curl_socket_t *socks, curl_socket_t *socks,

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2009 - 2011, 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
@ -33,7 +33,8 @@ typedef enum {
a connect */ a connect */
IMAP_LOGIN, IMAP_LOGIN,
IMAP_STARTTLS, IMAP_STARTTLS,
IMAP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS (multi mode only) */ IMAP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS
(multi mode only) */
IMAP_SELECT, IMAP_SELECT,
IMAP_FETCH, IMAP_FETCH,
IMAP_LOGOUT, IMAP_LOGOUT,
@ -48,7 +49,7 @@ struct imap_conn {
imapstate state; /* always use imap.c:state() to change state! */ imapstate state; /* always use imap.c:state() to change state! */
int cmdid; /* id number/index */ int cmdid; /* id number/index */
const char *idstr; /* pointer to a string for which to wait for as id */ const char *idstr; /* pointer to a string for which to wait for as id */
bool ssldone; /* is connect() over SSL done? only relevant in multi mode */ bool ssldone; /* connect() over SSL? only relevant in multi mode */
}; };
extern const struct Curl_handler Curl_handler_imap; extern const struct Curl_handler Curl_handler_imap;

View File

@ -69,8 +69,7 @@ static char *inet_ntop4 (const unsigned char *src, char *dst, size_t size)
((int)((unsigned char)src[3])) & 0xff); ((int)((unsigned char)src[3])) & 0xff);
len = strlen(tmp); len = strlen(tmp);
if(len == 0 || len >= size) if(len == 0 || len >= size) {
{
SET_ERRNO(ENOSPC); SET_ERRNO(ENOSPC);
return (NULL); return (NULL);
} }
@ -105,61 +104,51 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
* Find the longest run of 0x00's in src[] for :: shorthanding. * Find the longest run of 0x00's in src[] for :: shorthanding.
*/ */
memset(words, '\0', sizeof(words)); memset(words, '\0', sizeof(words));
for (i = 0; i < IN6ADDRSZ; i++) for(i = 0; i < IN6ADDRSZ; i++)
words[i/2] |= (src[i] << ((1 - (i % 2)) << 3)); words[i/2] |= (src[i] << ((1 - (i % 2)) << 3));
best.base = -1; best.base = -1;
cur.base = -1; cur.base = -1;
best.len = 0; best.len = 0;
cur.len = 0; cur.len = 0;
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
{ if(words[i] == 0) {
if(words[i] == 0)
{
if(cur.base == -1) if(cur.base == -1)
cur.base = i, cur.len = 1; cur.base = i, cur.len = 1;
else else
cur.len++; cur.len++;
} }
else if(cur.base != -1) else if(cur.base != -1) {
{
if(best.base == -1 || cur.len > best.len) if(best.base == -1 || cur.len > best.len)
best = cur; best = cur;
cur.base = -1; cur.base = -1;
} }
} }
if((cur.base != -1) && (best.base == -1 || cur.len > best.len)) if((cur.base != -1) && (best.base == -1 || cur.len > best.len))
best = cur; best = cur;
if(best.base != -1 && best.len < 2) if(best.base != -1 && best.len < 2)
best.base = -1; best.base = -1;
/* Format the result. */
/* Format the result.
*/
tp = tmp; tp = tmp;
for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) for(i = 0; i < (IN6ADDRSZ / INT16SZ); i++) {
{ /* Are we inside the best run of 0x00's? */
/* Are we inside the best run of 0x00's? if(best.base != -1 && i >= best.base && i < (best.base + best.len)) {
*/
if(best.base != -1 && i >= best.base && i < (best.base + best.len))
{
if(i == best.base) if(i == best.base)
*tp++ = ':'; *tp++ = ':';
continue; continue;
} }
/* Are we following an initial run of 0x00s or any real hex? /* Are we following an initial run of 0x00s or any real hex?
*/ */
if(i != 0) if(i != 0)
*tp++ = ':'; *tp++ = ':';
/* Is this address an encapsulated IPv4? /* Is this address an encapsulated IPv4?
*/ */
if(i == 6 && best.base == 0 && if(i == 6 && best.base == 0 &&
(best.len == 6 || (best.len == 5 && words[5] == 0xffff))) (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
{ if(!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp))) {
if(!inet_ntop4(src+12, tp, sizeof(tmp) - (tp - tmp)))
{
SET_ERRNO(ENOSPC); SET_ERRNO(ENOSPC);
return (NULL); return (NULL);
} }
@ -177,8 +166,7 @@ static char *inet_ntop6 (const unsigned char *src, char *dst, size_t size)
/* Check for overflow, copy, and we're done. /* Check for overflow, copy, and we're done.
*/ */
if((size_t)(tp - tmp) > size) if((size_t)(tp - tmp) > size) {
{
SET_ERRNO(ENOSPC); SET_ERRNO(ENOSPC);
return (NULL); return (NULL);
} }

View File

@ -223,7 +223,7 @@ inet_pton6(const char *src, unsigned char *dst)
if(tp == endp) if(tp == endp)
return (0); return (0);
for (i = 1; i <= n; i++) { for(i = 1; i <= n; i++) {
*(endp - i) = *(colonp + n - i); *(endp - i) = *(colonp + n - i);
*(colonp + n - i) = 0; *(colonp + n - i) = 0;
} }

View File

@ -7,7 +7,7 @@
* *
* Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan * Copyright (c) 1995, 1996, 1997, 1998, 1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* Copyright (c) 2004 - 2010 Daniel Stenberg * Copyright (c) 2004 - 2011 Daniel Stenberg
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -88,9 +88,9 @@ strlcpy (char *dst, const char *src, size_t dst_sz)
size_t n; size_t n;
char *p; char *p;
for (p = dst, n = 0; for(p = dst, n = 0;
n + 1 < dst_sz && *src != '\0'; n + 1 < dst_sz && *src != '\0';
++p, ++src, ++n) ++p, ++src, ++n)
*p = *src; *p = *src;
*p = '\0'; *p = '\0';
if(*src == '\0') if(*src == '\0')

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -47,7 +47,8 @@ extern struct Curl_sec_client_mech Curl_krb5_client_mech;
#endif #endif
CURLcode Curl_krb_kauth(struct connectdata *conn); CURLcode Curl_krb_kauth(struct connectdata *conn);
int Curl_sec_read_msg (struct connectdata *conn, char *, enum protection_level); int Curl_sec_read_msg (struct connectdata *conn, char *,
enum protection_level);
void Curl_sec_end (struct connectdata *); void Curl_sec_end (struct connectdata *);
CURLcode Curl_sec_login (struct connectdata *); CURLcode Curl_sec_login (struct connectdata *);
int Curl_sec_request_prot (struct connectdata *conn, const char *level); int Curl_sec_request_prot (struct connectdata *conn, const char *level);

View File

@ -157,7 +157,8 @@ krb5_encode(void *app_data, const void *from, int length, int level, void **to,
if(maj != GSS_S_COMPLETE) if(maj != GSS_S_COMPLETE)
return -1; return -1;
/* malloc a new buffer, in case gss_release_buffer doesn't work as expected */ /* malloc a new buffer, in case gss_release_buffer doesn't work as
expected */
*to = malloc(enc.length); *to = malloc(enc.length);
if(!*to) if(!*to)
return -1; return -1;
@ -222,7 +223,8 @@ krb5_auth(void *app_data, struct connectdata *conn)
if(maj != GSS_S_COMPLETE) { if(maj != GSS_S_COMPLETE) {
gss_release_name(&min, &gssname); gss_release_name(&min, &gssname);
if(service == srv_host) { if(service == srv_host) {
Curl_failf(data, "Error importing service name %s", input_buffer.value); Curl_failf(data, "Error importing service name %s",
input_buffer.value);
return AUTH_ERROR; return AUTH_ERROR;
} }
service = srv_host; service = srv_host;
@ -327,7 +329,7 @@ static void krb5_end(void *app_data)
{ {
OM_uint32 maj, min; OM_uint32 maj, min;
gss_ctx_id_t *context = app_data; gss_ctx_id_t *context = app_data;
if (*context != GSS_C_NO_CONTEXT) { if(*context != GSS_C_NO_CONTEXT) {
maj = gss_delete_sec_context(&min, context, GSS_C_NO_BUFFER); maj = gss_delete_sec_context(&min, context, GSS_C_NO_BUFFER);
DEBUGASSERT(maj == GSS_S_COMPLETE); DEBUGASSERT(maj == GSS_S_COMPLETE);
} }

View File

@ -46,7 +46,8 @@
#ifdef CURL_LDAP_WIN /* Use Windows LDAP implementation. */ #ifdef CURL_LDAP_WIN /* Use Windows LDAP implementation. */
# include <winldap.h> # include <winldap.h>
# ifndef LDAP_VENDOR_NAME # ifndef LDAP_VENDOR_NAME
# error Your Platform SDK is NOT sufficient for LDAP support! Update your Platform SDK, or disable LDAP support! # error Your Platform SDK is NOT sufficient for LDAP support! \
Update your Platform SDK, or disable LDAP support!
# else # else
# include <winber.h> # include <winber.h>
# endif # endif
@ -255,9 +256,9 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
goto quit; goto quit;
} }
ldap_option = LDAPSSL_VERIFY_SERVER; ldap_option = LDAPSSL_VERIFY_SERVER;
} else {
ldap_option = LDAPSSL_VERIFY_NONE;
} }
else
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",
@ -277,7 +278,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
/* OpenLDAP SDK supports BASE64 files. */ /* OpenLDAP SDK supports BASE64 files. */
if((data->set.str[STRING_CERT_TYPE]) && if((data->set.str[STRING_CERT_TYPE]) &&
(!Curl_raw_equal(data->set.str[STRING_CERT_TYPE], "PEM"))) { (!Curl_raw_equal(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 only supports PEM cert-type!");
status = CURLE_SSL_CERTPROBLEM; status = CURLE_SSL_CERTPROBLEM;
goto quit; goto quit;
} }
@ -295,9 +296,10 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
goto quit; goto quit;
} }
ldap_option = LDAP_OPT_X_TLS_DEMAND; ldap_option = LDAP_OPT_X_TLS_DEMAND;
} else {
ldap_option = LDAP_OPT_X_TLS_NEVER;
} }
else
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",
@ -339,7 +341,8 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
#endif #endif
#endif #endif
#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:%hu", failf(data, "LDAP local: Cannot connect to %s:%hu",
@ -363,9 +366,9 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
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;
} }
rc = ldap_search_s(server, ludp->lud_dn, ludp->lud_scope, rc = ldap_search_s(server, ludp->lud_dn, ludp->lud_scope,
@ -379,8 +382,7 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
for(num = 0, entryIterator = ldap_first_entry(server, result); for(num = 0, entryIterator = ldap_first_entry(server, result);
entryIterator; entryIterator;
entryIterator = ldap_next_entry(server, entryIterator), num++) entryIterator = ldap_next_entry(server, entryIterator), num++) {
{
BerElement *ber = NULL; BerElement *ber = NULL;
char *attribute; /*! suspicious that this isn't 'const' */ char *attribute; /*! suspicious that this isn't 'const' */
char *dn = ldap_get_dn(server, entryIterator); char *dn = ldap_get_dn(server, entryIterator);
@ -392,16 +394,13 @@ static CURLcode Curl_ldap(struct connectdata *conn, bool *done)
dlsize += strlen(dn)+5; dlsize += strlen(dn)+5;
for (attribute = ldap_first_attribute(server, entryIterator, &ber); for(attribute = ldap_first_attribute(server, entryIterator, &ber);
attribute; attribute;
attribute = ldap_next_attribute(server, entryIterator, ber)) attribute = ldap_next_attribute(server, entryIterator, ber)) {
{
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);
@ -515,15 +514,15 @@ static char **split_str (char *str)
char **res, *lasts, *s; char **res, *lasts, *s;
int i; int i;
for (i = 2, s = strchr(str,','); s; i++) for(i = 2, s = strchr(str,','); s; i++)
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;
s = strtok_r(NULL, ",", &lasts), i++) s = strtok_r(NULL, ",", &lasts), i++)
res[i] = s; res[i] = s;
return res; return res;
} }
@ -541,16 +540,16 @@ static bool unescape_elements (void *data, LDAPURLDesc *ludp)
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) {
@ -620,7 +619,7 @@ static int _ldap_url_parse2 (const struct connectdata *conn, LDAPURLDesc *ludp)
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++)
LDAP_TRACE (("attr[%d] '%s'\n", i, ludp->lud_attrs[i])); LDAP_TRACE (("attr[%d] '%s'\n", i, ludp->lud_attrs[i]));
} }
@ -666,7 +665,7 @@ static int _ldap_url_parse2 (const struct connectdata *conn, LDAPURLDesc *ludp)
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:
@ -699,23 +698,23 @@ 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);
} }
free (ludp); free (ludp);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -115,7 +115,8 @@ Curl_llist_remove(struct curl_llist *list, struct curl_llist_element *e,
list->tail = NULL; list->tail = NULL;
else else
e->next->prev = NULL; e->next->prev = NULL;
} else { }
else {
e->prev->next = e->next; e->prev->next = e->next;
if(!e->next) if(!e->next)
list->tail = e->prev; list->tail = e->prev;
@ -149,7 +150,8 @@ Curl_llist_count(struct curl_llist *list)
} }
int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e, int Curl_llist_move(struct curl_llist *list, struct curl_llist_element *e,
struct curl_llist *to_list, struct curl_llist_element *to_e) struct curl_llist *to_list,
struct curl_llist_element *to_e)
{ {
/* Remove element from list */ /* Remove element from list */
if(e == NULL || list->size == 0) if(e == NULL || list->size == 0)

View File

@ -113,19 +113,19 @@ static void MD4Update(MD4_CTX *context, const unsigned char *input,
/* Compute number of bytes mod 64 */ /* Compute number of bytes mod 64 */
bufindex = (unsigned int)((context->count[0] >> 3) & 0x3F); bufindex = (unsigned int)((context->count[0] >> 3) & 0x3F);
/* Update number of bits */ /* Update number of bits */
if ((context->count[0] += ((UINT4)inputLen << 3)) if((context->count[0] += ((UINT4)inputLen << 3))
< ((UINT4)inputLen << 3)) < ((UINT4)inputLen << 3))
context->count[1]++; context->count[1]++;
context->count[1] += ((UINT4)inputLen >> 29); context->count[1] += ((UINT4)inputLen >> 29);
partLen = 64 - bufindex; partLen = 64 - bufindex;
/* Transform as many times as possible. /* Transform as many times as possible.
*/ */
if (inputLen >= partLen) { if(inputLen >= partLen) {
memcpy(&context->buffer[bufindex], input, partLen); memcpy(&context->buffer[bufindex], input, partLen);
MD4Transform (context->state, context->buffer); MD4Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64) for(i = partLen; i + 63 < inputLen; i += 64)
MD4Transform (context->state, &input[i]); MD4Transform (context->state, &input[i]);
bufindex = 0; bufindex = 0;
@ -251,7 +251,7 @@ static void Encode(unsigned char *output, UINT4 *input, unsigned int len)
{ {
unsigned int i, j; unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) { for(i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char)(input[i] & 0xff); output[j] = (unsigned char)(input[i] & 0xff);
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
@ -262,11 +262,12 @@ static void Encode(unsigned char *output, UINT4 *input, unsigned int len)
/* Decodes input (unsigned char) into output (UINT4). Assumes len is /* Decodes input (unsigned char) into output (UINT4). Assumes len is
a multiple of 4. a multiple of 4.
*/ */
static void Decode (UINT4 *output, const unsigned char *input, unsigned int len) static void Decode (UINT4 *output, const unsigned char *input,
unsigned int len)
{ {
unsigned int i, j; unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) for(i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
} }

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -208,7 +208,7 @@ static void MD5_Update (struct md5_ctx *context, /* context */
memcpy(&context->buffer[bufindex], input, partLen); memcpy(&context->buffer[bufindex], input, partLen);
MD5Transform(context->state, context->buffer); MD5Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64) for(i = partLen; i + 63 < inputLen; i += 64)
MD5Transform(context->state, &input[i]); MD5Transform(context->state, &input[i]);
bufindex = 0; bufindex = 0;
@ -345,7 +345,7 @@ static void Encode (unsigned char *output,
{ {
unsigned int i, j; unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) { for(i = 0, j = 0; j < len; i++, j += 4) {
output[j] = (unsigned char)(input[i] & 0xff); output[j] = (unsigned char)(input[i] & 0xff);
output[j+1] = (unsigned char)((input[i] >> 8) & 0xff); output[j+1] = (unsigned char)((input[i] >> 8) & 0xff);
output[j+2] = (unsigned char)((input[i] >> 16) & 0xff); output[j+2] = (unsigned char)((input[i] >> 16) & 0xff);
@ -362,7 +362,7 @@ static void Decode (UINT4 *output,
{ {
unsigned int i, j; unsigned int i, j;
for (i = 0, j = 0; j < len; i++, j += 4) for(i = 0, j = 0; j < len; i++, j += 4)
output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) | output[i] = ((UINT4)input[j]) | (((UINT4)input[j+1]) << 8) |
(((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24); (((UINT4)input[j+2]) << 16) | (((UINT4)input[j+3]) << 24);
} }

View File

@ -8,7 +8,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -47,8 +47,10 @@ extern FILE *logfile;
/* memory functions */ /* memory functions */
CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source); CURL_EXTERN void *curl_domalloc(size_t size, int line, const char *source);
CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line, const char *source); CURL_EXTERN void *curl_docalloc(size_t elements, size_t size, int line,
CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line, const char *source); const char *source);
CURL_EXTERN void *curl_dorealloc(void *ptr, size_t size, int line,
const char *source);
CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source); CURL_EXTERN void curl_dofree(void *ptr, int line, const char *source);
CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source); CURL_EXTERN char *curl_dostrdup(const char *str, int line, const char *source);
CURL_EXTERN void curl_memdebug(const char *logname); CURL_EXTERN void curl_memdebug(const char *logname);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1999 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1999 - 2011, 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
@ -547,67 +547,65 @@ static long dprintf_Pass1(const char *format, va_stack_t *vto, char **endpos,
#endif #endif
/* 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 */
*/ vto[i + 1].data.num.as_signed = (mp_intmax_t)va_arg(arglist, int);
vto[i + 1].data.num.as_signed = (mp_intmax_t)va_arg(arglist, int); }
}
switch (vto[i].type) switch (vto[i].type) {
{ case FORMAT_STRING:
case FORMAT_STRING: vto[i].data.str = va_arg(arglist, char *);
vto[i].data.str = va_arg(arglist, char *); break;
break;
case FORMAT_INTPTR: case FORMAT_INTPTR:
case FORMAT_UNKNOWN: case FORMAT_UNKNOWN:
case FORMAT_PTR: case FORMAT_PTR:
vto[i].data.ptr = va_arg(arglist, void *); vto[i].data.ptr = va_arg(arglist, void *);
break; break;
case FORMAT_INT: case FORMAT_INT:
#ifdef HAVE_LONG_LONG_TYPE #ifdef HAVE_LONG_LONG_TYPE
if((vto[i].flags & FLAGS_LONGLONG) && (vto[i].flags & FLAGS_UNSIGNED)) if((vto[i].flags & FLAGS_LONGLONG) && (vto[i].flags & FLAGS_UNSIGNED))
vto[i].data.num.as_unsigned = vto[i].data.num.as_unsigned =
(mp_uintmax_t)va_arg(arglist, mp_uintmax_t); (mp_uintmax_t)va_arg(arglist, mp_uintmax_t);
else if(vto[i].flags & FLAGS_LONGLONG) else if(vto[i].flags & FLAGS_LONGLONG)
vto[i].data.num.as_signed = vto[i].data.num.as_signed =
(mp_intmax_t)va_arg(arglist, mp_intmax_t); (mp_intmax_t)va_arg(arglist, mp_intmax_t);
else else
#endif #endif
{ {
if((vto[i].flags & FLAGS_LONG) && (vto[i].flags & FLAGS_UNSIGNED)) if((vto[i].flags & FLAGS_LONG) && (vto[i].flags & FLAGS_UNSIGNED))
vto[i].data.num.as_unsigned = vto[i].data.num.as_unsigned =
(mp_uintmax_t)va_arg(arglist, unsigned long); (mp_uintmax_t)va_arg(arglist, unsigned long);
else if(vto[i].flags & FLAGS_LONG) else if(vto[i].flags & FLAGS_LONG)
vto[i].data.num.as_signed = vto[i].data.num.as_signed =
(mp_intmax_t)va_arg(arglist, long); (mp_intmax_t)va_arg(arglist, long);
else if(vto[i].flags & FLAGS_UNSIGNED) else if(vto[i].flags & FLAGS_UNSIGNED)
vto[i].data.num.as_unsigned = vto[i].data.num.as_unsigned =
(mp_uintmax_t)va_arg(arglist, unsigned int); (mp_uintmax_t)va_arg(arglist, unsigned int);
else else
vto[i].data.num.as_signed = vto[i].data.num.as_signed =
(mp_intmax_t)va_arg(arglist, int); (mp_intmax_t)va_arg(arglist, int);
}
break;
case FORMAT_DOUBLE:
vto[i].data.dnum = va_arg(arglist, double);
break;
case FORMAT_WIDTH:
/* Argument has been read. Silently convert it into an integer
* for later use
*/
vto[i].type = FORMAT_INT;
break;
default:
break;
} }
break;
case FORMAT_DOUBLE:
vto[i].data.dnum = va_arg(arglist, double);
break;
case FORMAT_WIDTH:
/* Argument has been read. Silently convert it into an integer
* for later use
*/
vto[i].type = FORMAT_INT;
break;
default:
break;
}
} }
return max_param; return max_param;
@ -914,7 +912,7 @@ static int dprintf_formatf(
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)
@ -1202,45 +1200,3 @@ int curl_mvfprintf(FILE *whereto, const char *format, va_list ap_save)
{ {
return dprintf_formatf(whereto, fputc, format, ap_save); return dprintf_formatf(whereto, fputc, format, ap_save);
} }
#ifdef DPRINTF_DEBUG
int main()
{
char buffer[129];
char *ptr;
#ifdef HAVE_LONG_LONG_TYPE
LONG_LONG_TYPE one=99;
LONG_LONG_TYPE two=100;
LONG_LONG_TYPE test = 0x1000000000LL;
curl_mprintf("%lld %lld %lld\n", one, two, test);
#endif
curl_mprintf("%3d %5d\n", 10, 1998);
ptr=curl_maprintf("test this then baby %s%s%s%s%s%s %d %d %d loser baby get a kiss in yer face now!", "", "pretty long string pretty long string pretty long string pretty long string pretty long string", "/", "/", "/", "pretty long string", 1998, 1999, 2001);
puts(ptr);
memset(ptr, 55, strlen(ptr)+1);
free(ptr);
#if 1
curl_mprintf(buffer, "%s %s %d", "daniel", "stenberg", 19988);
puts(buffer);
curl_mfprintf(stderr, "%s %#08x\n", "dummy", 65);
printf("%s %#08x\n", "dummy", 65);
{
double tryout = 3.14156592;
curl_mprintf(buffer, "%.2g %G %f %e %E", tryout, tryout, tryout, tryout, tryout);
puts(buffer);
printf("%.2g %G %f %e %E\n", tryout, tryout, tryout, tryout, tryout);
}
#endif
return 0;
}
#endif

View File

@ -674,7 +674,7 @@ CURLMcode curl_multi_remove_handle(CURLM *multi_handle,
/* we must call Curl_done() here (if we still "own it") so that we don't /* we must call Curl_done() here (if we still "own it") so that we don't
leave a half-baked one around */ leave a half-baked one around */
if (easy_owns_conn) { if(easy_owns_conn) {
/* Curl_done() clears the conn->data field to lose the association /* Curl_done() clears the conn->data field to lose the association
between the easy handle and the connection between the easy handle and the connection
@ -1128,7 +1128,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
result = CURLM_CALL_MULTI_PERFORM; result = CURLM_CALL_MULTI_PERFORM;
multistate(easy, CURLM_STATE_CONNECT); multistate(easy, CURLM_STATE_CONNECT);
} }
else if (CURLE_OK == easy->result) { else 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);
} }
@ -1265,8 +1265,8 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
result = CURLM_CALL_MULTI_PERFORM; result = CURLM_CALL_MULTI_PERFORM;
} }
} }
else if ((CURLE_SEND_ERROR == easy->result) && else if((CURLE_SEND_ERROR == easy->result) &&
easy->easy_conn->bits.reuse) { easy->easy_conn->bits.reuse) {
/* /*
* In this situation, a connection that we were trying to use * In this situation, a connection that we were trying to use
* may have unexpectedly died. If possible, send the connection * may have unexpectedly died. If possible, send the connection
@ -1292,7 +1292,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
/* When set to retry the connection, we must to go back to /* When set to retry the connection, we must to go back to
* the CONNECT state */ * the CONNECT state */
if(retry) { if(retry) {
if ((drc == CURLE_OK) || (drc == CURLE_SEND_ERROR)) { if((drc == CURLE_OK) || (drc == CURLE_SEND_ERROR)) {
follow = FOLLOW_RETRY; follow = FOLLOW_RETRY;
drc = Curl_follow(data, newurl, follow); drc = Curl_follow(data, newurl, follow);
if(drc == CURLE_OK) { if(drc == CURLE_OK) {
@ -1535,11 +1535,11 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
/* but first check to see if we got a location info even though we're /* but first check to see if we got a location info even though we're
not following redirects */ not following redirects */
if (data->req.location) { if(data->req.location) {
newurl = data->req.location; newurl = data->req.location;
data->req.location = NULL; data->req.location = NULL;
easy->result = Curl_follow(data, newurl, FOLLOW_FAKE); easy->result = Curl_follow(data, newurl, FOLLOW_FAKE);
if (easy->result) if(easy->result)
free(newurl); free(newurl);
} }
@ -1577,7 +1577,7 @@ static CURLMcode multi_runsingle(struct Curl_multi *multi,
* access free'd data, if the connection is free'd and the handle * access free'd data, if the connection is free'd and the handle
* removed before we perform the processing in CURLM_STATE_COMPLETED * removed before we perform the processing in CURLM_STATE_COMPLETED
*/ */
if (easy->easy_conn) if(easy->easy_conn)
easy->easy_conn = NULL; easy->easy_conn = NULL;
} }
@ -1710,7 +1710,7 @@ CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles)
do do
result = multi_runsingle(multi, now, easy); result = multi_runsingle(multi, now, easy);
while (CURLM_CALL_MULTI_PERFORM == result); while(CURLM_CALL_MULTI_PERFORM == result);
if(easy->easy_handle->set.wildcardmatch) { if(easy->easy_handle->set.wildcardmatch) {
/* destruct wildcard structures if it is needed */ /* destruct wildcard structures if it is needed */
@ -1954,29 +1954,29 @@ static void singlesocket(struct Curl_multi *multi,
easy_by_hash = entry->easy->multi_pos; easy_by_hash = entry->easy->multi_pos;
easy_conn = easy_by_hash->easy_conn; easy_conn = easy_by_hash->easy_conn;
if(easy_conn) { if(easy_conn) {
if (easy_conn->recv_pipe && easy_conn->recv_pipe->size > 1) { if(easy_conn->recv_pipe && easy_conn->recv_pipe->size > 1) {
/* the handle should not be removed from the pipe yet */ /* the handle should not be removed from the pipe yet */
remove_sock_from_hash = FALSE; remove_sock_from_hash = FALSE;
/* Update the sockhash entry to instead point to the next in line /* Update the sockhash entry to instead point to the next in line
for the recv_pipe, or the first (in case this particular easy for the recv_pipe, or the first (in case this particular easy
isn't already) */ isn't already) */
if (entry->easy == easy->easy_handle) { if(entry->easy == easy->easy_handle) {
if (isHandleAtHead(easy->easy_handle, easy_conn->recv_pipe)) if(isHandleAtHead(easy->easy_handle, easy_conn->recv_pipe))
entry->easy = easy_conn->recv_pipe->head->next->ptr; entry->easy = easy_conn->recv_pipe->head->next->ptr;
else else
entry->easy = easy_conn->recv_pipe->head->ptr; entry->easy = easy_conn->recv_pipe->head->ptr;
} }
} }
if (easy_conn->send_pipe && easy_conn->send_pipe->size > 1) { if(easy_conn->send_pipe && easy_conn->send_pipe->size > 1) {
/* the handle should not be removed from the pipe yet */ /* the handle should not be removed from the pipe yet */
remove_sock_from_hash = FALSE; remove_sock_from_hash = FALSE;
/* Update the sockhash entry to instead point to the next in line /* Update the sockhash entry to instead point to the next in line
for the send_pipe, or the first (in case this particular easy for the send_pipe, or the first (in case this particular easy
isn't already) */ isn't already) */
if (entry->easy == easy->easy_handle) { if(entry->easy == easy->easy_handle) {
if (isHandleAtHead(easy->easy_handle, easy_conn->send_pipe)) if(isHandleAtHead(easy->easy_handle, easy_conn->send_pipe))
entry->easy = easy_conn->send_pipe->head->next->ptr; entry->easy = easy_conn->send_pipe->head->next->ptr;
else else
entry->easy = easy_conn->send_pipe->head->ptr; entry->easy = easy_conn->send_pipe->head->ptr;
@ -1994,7 +1994,7 @@ static void singlesocket(struct Curl_multi *multi,
either since it never got to know about it */ either since it never got to know about it */
remove_sock_from_hash = FALSE; remove_sock_from_hash = FALSE;
if (remove_sock_from_hash) { if(remove_sock_from_hash) {
multi->socket_cb(easy->easy_handle, multi->socket_cb(easy->easy_handle,
s, s,
CURL_POLL_REMOVE, CURL_POLL_REMOVE,
@ -2116,13 +2116,13 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
the pipeline. If we should write into the socket, take the send_pipe the pipeline. If we should write into the socket, take the send_pipe
head. If we should read from the socket, take the recv_pipe head. */ head. If we should read from the socket, take the recv_pipe head. */
if(data->set.one_easy->easy_conn) { if(data->set.one_easy->easy_conn) {
if ((ev_bitmask & CURL_POLL_OUT) && if((ev_bitmask & CURL_POLL_OUT) &&
data->set.one_easy->easy_conn->send_pipe && data->set.one_easy->easy_conn->send_pipe &&
data->set.one_easy->easy_conn->send_pipe->head) data->set.one_easy->easy_conn->send_pipe->head)
data = data->set.one_easy->easy_conn->send_pipe->head->ptr; data = data->set.one_easy->easy_conn->send_pipe->head->ptr;
else if ((ev_bitmask & CURL_POLL_IN) && else if((ev_bitmask & CURL_POLL_IN) &&
data->set.one_easy->easy_conn->recv_pipe && data->set.one_easy->easy_conn->recv_pipe &&
data->set.one_easy->easy_conn->recv_pipe->head) data->set.one_easy->easy_conn->recv_pipe->head)
data = data->set.one_easy->easy_conn->recv_pipe->head->ptr; data = data->set.one_easy->easy_conn->recv_pipe->head->ptr;
} }
@ -2133,7 +2133,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
do do
result = multi_runsingle(multi, now, data->set.one_easy); result = multi_runsingle(multi, now, data->set.one_easy);
while (CURLM_CALL_MULTI_PERFORM == result); while(CURLM_CALL_MULTI_PERFORM == result);
if(data->set.one_easy->easy_conn && if(data->set.one_easy->easy_conn &&
!(data->set.one_easy->easy_conn->handler->flags & PROTOPT_DIRLOCK)) !(data->set.one_easy->easy_conn->handler->flags & PROTOPT_DIRLOCK))
@ -2171,7 +2171,7 @@ static CURLMcode multi_socket(struct Curl_multi *multi,
if(data) { if(data) {
do do
result = multi_runsingle(multi, now, data->set.one_easy); result = multi_runsingle(multi, now, data->set.one_easy);
while (CURLM_CALL_MULTI_PERFORM == result); while(CURLM_CALL_MULTI_PERFORM == result);
if(CURLM_OK >= result) if(CURLM_OK >= result)
/* get the socket(s) and check if the state has been changed since /* get the socket(s) and check if the state has been changed since
@ -2371,14 +2371,14 @@ static CURLcode addHandleToSendOrPendPipeline(struct SessionHandle *handle,
rc = Curl_addHandleToPipeline(handle, pipeline); rc = Curl_addHandleToPipeline(handle, pipeline);
if (pipeline == conn->send_pipe && sendhead != conn->send_pipe->head) { if(pipeline == conn->send_pipe && sendhead != conn->send_pipe->head) {
/* this is a new one as head, expire it */ /* this is a new one as head, expire it */
conn->writechannel_inuse = FALSE; /* not in use yet */ conn->writechannel_inuse = FALSE; /* not in use yet */
#ifdef DEBUGBUILD #ifdef DEBUGBUILD
infof(conn->data, "%p is at send pipe head!\n", infof(conn->data, "%p is at send pipe head!\n",
conn->send_pipe->head->ptr); conn->send_pipe->head->ptr);
#endif #endif
Curl_expire(conn->send_pipe->head->ptr, 1); Curl_expire(conn->send_pipe->head->ptr, 1);
} }
return rc; return rc;
@ -2390,7 +2390,7 @@ static int checkPendPipeline(struct connectdata *conn)
struct curl_llist_element *sendhead = conn->send_pipe->head; struct curl_llist_element *sendhead = conn->send_pipe->head;
size_t pipeLen = conn->send_pipe->size + conn->recv_pipe->size; size_t pipeLen = conn->send_pipe->size + conn->recv_pipe->size;
if (conn->server_supports_pipelining || pipeLen == 0) { if(conn->server_supports_pipelining || pipeLen == 0) {
struct curl_llist_element *curr = conn->pend_pipe->head; struct curl_llist_element *curr = conn->pend_pipe->head;
const size_t maxPipeLen = const size_t maxPipeLen =
conn->server_supports_pipelining ? MAX_PIPELINE_LENGTH : 1; conn->server_supports_pipelining ? MAX_PIPELINE_LENGTH : 1;
@ -2405,7 +2405,7 @@ static int checkPendPipeline(struct connectdata *conn)
} }
} }
if (result) { if(result) {
conn->now = Curl_tvnow(); conn->now = Curl_tvnow();
/* something moved, check for a new send pipeline leader */ /* something moved, check for a new send pipeline leader */
if(sendhead != conn->send_pipe->head) { if(sendhead != conn->send_pipe->head) {
@ -2746,7 +2746,8 @@ static CURLMcode add_closure(struct Curl_multi *multi,
else else
multi->closure = n; multi->closure = n;
free(cl); free(cl);
} else { }
else {
if(cl->easy_handle == data) if(cl->easy_handle == data)
add = FALSE; add = FALSE;
@ -2756,7 +2757,7 @@ static CURLMcode add_closure(struct Curl_multi *multi,
cl = n; cl = n;
} }
if (add) { if(add) {
cl = calloc(1, sizeof(struct closure)); cl = calloc(1, sizeof(struct closure));
if(!cl) if(!cl)
return CURLM_OUT_OF_MEMORY; return CURLM_OUT_OF_MEMORY;

View File

@ -180,7 +180,7 @@ CURLcode Curl_convert_from_network(struct SessionHandle *data,
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", "Curl_convert_from_network iconv call failed with errno %i: %s",
error, strerror(error)); error, strerror(error));
return CURLE_CONV_FAILED; return CURLE_CONV_FAILED;
} }
@ -296,13 +296,13 @@ void Curl_convert_close(struct SessionHandle *data)
#ifdef HAVE_ICONV #ifdef 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);
} }
#else #else
(void)data; (void)data;

View File

@ -282,9 +282,9 @@ static int is_file(const char *filename)
} }
/* Return on heap allocated filename/nickname of a certificate. The returned /* Return on heap allocated filename/nickname of a certificate. The returned
* string should be later deallocated using free(). *is_nickname is set to TRUE * string should be later deallocated using free(). *is_nickname is set to
* if the given string is treated as nickname; FALSE if the given string is * TRUE if the given string is treated as nickname; FALSE if the given string
* treated as file name. * is treated as file name.
*/ */
static char *fmt_nickname(struct SessionHandle *data, enum dupstring cert_kind, static char *fmt_nickname(struct SessionHandle *data, enum dupstring cert_kind,
bool *is_nickname) bool *is_nickname)
@ -662,7 +662,8 @@ static SECStatus BadCertHandler(void *arg, PRFileDesc *sock)
if(conn->data->set.ssl.verifyhost) { if(conn->data->set.ssl.verifyhost) {
failf(conn->data, "SSL: certificate subject name '%s' does not match " failf(conn->data, "SSL: certificate subject name '%s' does not match "
"target host name '%s'", subject_cn, conn->host.dispname); "target host name '%s'", subject_cn, conn->host.dispname);
} else { }
else {
result = SECSuccess; result = SECSuccess;
infof(conn->data, "warning: SSL: certificate subject name '%s' does not " infof(conn->data, "warning: SSL: certificate subject name '%s' does not "
"match target host name '%s'\n", subject_cn, conn->host.dispname); "match target host name '%s'\n", subject_cn, conn->host.dispname);
@ -778,10 +779,10 @@ static SECStatus check_issuer_cert(PRFileDesc *sock,
issuer = NULL; issuer = NULL;
issuer = PK11_FindCertFromNickname(issuer_nickname, proto_win); issuer = PK11_FindCertFromNickname(issuer_nickname, proto_win);
if ((!cert_issuer) || (!issuer)) if((!cert_issuer) || (!issuer))
res = SECFailure; res = SECFailure;
else if (SECITEM_CompareItem(&cert_issuer->derCert, else if(SECITEM_CompareItem(&cert_issuer->derCert,
&issuer->derCert)!=SECEqual) &issuer->derCert)!=SECEqual)
res = SECFailure; res = SECFailure;
CERT_DestroyCertificate(cert); CERT_DestroyCertificate(cert);
@ -806,8 +807,8 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
struct SessionHandle *data = connssl->data; struct SessionHandle *data = connssl->data;
const char *nickname = connssl->client_nickname; const char *nickname = connssl->client_nickname;
if (mod && nickname && if(mod && nickname &&
0 == strncmp(nickname, pem_nickname, /* length of "PEM Token" */ 9)) { 0 == strncmp(nickname, pem_nickname, /* length of "PEM Token" */ 9)) {
/* use the cert/key provided by PEM reader */ /* use the cert/key provided by PEM reader */
PK11SlotInfo *slot; PK11SlotInfo *slot;
@ -815,20 +816,20 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
*pRetKey = NULL; *pRetKey = NULL;
*pRetCert = PK11_FindCertFromNickname(nickname, proto_win); *pRetCert = PK11_FindCertFromNickname(nickname, proto_win);
if (NULL == *pRetCert) { if(NULL == *pRetCert) {
failf(data, "NSS: client certificate not found: %s", nickname); failf(data, "NSS: client certificate not found: %s", nickname);
return SECFailure; return SECFailure;
} }
slot = PK11_FindSlotByName(pem_slotname); slot = PK11_FindSlotByName(pem_slotname);
if (NULL == slot) { if(NULL == slot) {
failf(data, "NSS: PK11 slot not found: %s", pem_slotname); failf(data, "NSS: PK11 slot not found: %s", pem_slotname);
return SECFailure; return SECFailure;
} }
*pRetKey = PK11_FindPrivateKeyFromCert(slot, *pRetCert, NULL); *pRetKey = PK11_FindPrivateKeyFromCert(slot, *pRetCert, NULL);
PK11_FreeSlot(slot); PK11_FreeSlot(slot);
if (NULL == *pRetKey) { if(NULL == *pRetKey) {
failf(data, "NSS: private key not found for certificate: %s", nickname); failf(data, "NSS: private key not found for certificate: %s", nickname);
return SECFailure; return SECFailure;
} }
@ -839,11 +840,11 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
} }
/* use the default NSS hook */ /* use the default NSS hook */
if (SECSuccess != NSS_GetClientAuthData((void *)nickname, sock, caNames, if(SECSuccess != NSS_GetClientAuthData((void *)nickname, sock, caNames,
pRetCert, pRetKey) pRetCert, pRetKey)
|| NULL == *pRetCert) { || NULL == *pRetCert) {
if (NULL == nickname) if(NULL == nickname)
failf(data, "NSS: client certificate not found (nickname not " failf(data, "NSS: client certificate not found (nickname not "
"specified)"); "specified)");
else else
@ -854,10 +855,10 @@ static SECStatus SelectClientCert(void *arg, PRFileDesc *sock,
/* get certificate nickname if any */ /* get certificate nickname if any */
nickname = (*pRetCert)->nickname; nickname = (*pRetCert)->nickname;
if (NULL == nickname) if(NULL == nickname)
nickname = "[unknown]"; nickname = "[unknown]";
if (NULL == *pRetKey) { if(NULL == *pRetKey) {
failf(data, "NSS: private key not found for certificate: %s", nickname); failf(data, "NSS: private key not found for certificate: %s", nickname);
return SECFailure; return SECFailure;
} }
@ -931,7 +932,8 @@ static CURLcode init_nss(struct SessionHandle *data)
} }
else { else {
char *certpath = char *certpath =
PR_smprintf("%s%s", NSS_VersionCheck("3.12.0") ? "sql:" : "", cert_dir); PR_smprintf("%s%s", NSS_VersionCheck("3.12.0") ? "sql:" : "",
cert_dir);
rv = NSS_Initialize(certpath, "", "", "", NSS_INIT_READONLY); rv = NSS_Initialize(certpath, "", "", "", NSS_INIT_READONLY);
PR_smprintf_free(certpath); PR_smprintf_free(certpath);
} }
@ -957,7 +959,7 @@ static CURLcode init_nss(struct SessionHandle *data)
int Curl_nss_init(void) int Curl_nss_init(void)
{ {
/* curl_global_init() is not thread-safe so this test is ok */ /* curl_global_init() is not thread-safe so this test is ok */
if (nss_initlock == NULL) { if(nss_initlock == NULL) {
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 256); PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 256);
nss_initlock = PR_NewLock(); nss_initlock = PR_NewLock();
nss_crllock = PR_NewLock(); nss_crllock = PR_NewLock();
@ -972,9 +974,10 @@ CURLcode Curl_nss_force_init(struct SessionHandle *data)
{ {
CURLcode rv; CURLcode rv;
if(!nss_initlock) { if(!nss_initlock) {
failf(data, "unable to initialize NSS, curl_global_init() should have been " failf(data,
"called with CURL_GLOBAL_SSL or CURL_GLOBAL_ALL"); "unable to initialize NSS, curl_global_init() should have been "
return CURLE_OUT_OF_MEMORY; "called with CURL_GLOBAL_SSL or CURL_GLOBAL_ALL");
return CURLE_FAILED_INIT;
} }
PR_Lock(nss_initlock); PR_Lock(nss_initlock);
@ -990,7 +993,7 @@ void Curl_nss_cleanup(void)
* as a safety feature. * as a safety feature.
*/ */
PR_Lock(nss_initlock); PR_Lock(nss_initlock);
if (initialized) { if(initialized) {
/* Free references to client certificates held in the SSL session cache. /* Free references to client certificates held in the SSL session cache.
* Omitting this hampers destruction of the security module owning * Omitting this hampers destruction of the security module owning
* the certificates. */ * the certificates. */
@ -1167,7 +1170,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
long time_left; long time_left;
PRUint32 timeout; PRUint32 timeout;
if (connssl->state == ssl_connection_complete) if(connssl->state == ssl_connection_complete)
return CURLE_OK; return CURLE_OK;
connssl->data = data; connssl->data = data;
@ -1240,7 +1243,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
default: default:
case CURL_SSLVERSION_DEFAULT: case CURL_SSLVERSION_DEFAULT:
ssl3 = PR_TRUE; ssl3 = PR_TRUE;
if (data->state.ssl_connect_retry) if(data->state.ssl_connect_retry)
infof(data, "TLS disabled due to previous handshake failure\n"); infof(data, "TLS disabled due to previous handshake failure\n");
else else
tlsv1 = PR_TRUE; tlsv1 = PR_TRUE;
@ -1271,8 +1274,8 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
/* enable all ciphers from enable_ciphers_by_default */ /* enable all ciphers from enable_ciphers_by_default */
cipher_to_enable = enable_ciphers_by_default; cipher_to_enable = enable_ciphers_by_default;
while (SSL_NULL_WITH_NULL_NULL != *cipher_to_enable) { while(SSL_NULL_WITH_NULL_NULL != *cipher_to_enable) {
if (SSL_CipherPrefSet(model, *cipher_to_enable, PR_TRUE) != SECSuccess) { if(SSL_CipherPrefSet(model, *cipher_to_enable, PR_TRUE) != SECSuccess) {
curlerr = CURLE_SSL_CIPHER; curlerr = CURLE_SSL_CIPHER;
goto error; goto error;
} }
@ -1313,7 +1316,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
} }
} }
if (data->set.ssl.CRLfile) { if(data->set.ssl.CRLfile) {
if(SECSuccess != nss_load_crl(data->set.ssl.CRLfile)) { if(SECSuccess != nss_load_crl(data->set.ssl.CRLfile)) {
curlerr = CURLE_SSL_CRL_BADFILE; curlerr = CURLE_SSL_CRL_BADFILE;
goto error; goto error;
@ -1358,7 +1361,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
model = NULL; model = NULL;
/* This is the password associated with the cert that we're using */ /* This is the password associated with the cert that we're using */
if (data->set.str[STRING_KEY_PASSWD]) { if(data->set.str[STRING_KEY_PASSWD]) {
SSL_SetPKCS11PinArg(connssl->handle, data->set.str[STRING_KEY_PASSWD]); SSL_SetPKCS11PinArg(connssl->handle, data->set.str[STRING_KEY_PASSWD]);
} }
@ -1390,7 +1393,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
display_conn_info(conn, connssl->handle); display_conn_info(conn, connssl->handle);
if (data->set.str[STRING_SSL_ISSUERCERT]) { if(data->set.str[STRING_SSL_ISSUERCERT]) {
SECStatus ret = SECFailure; SECStatus ret = SECFailure;
bool is_nickname; bool is_nickname;
char *nickname = fmt_nickname(data, STRING_SSL_ISSUERCERT, &is_nickname); char *nickname = fmt_nickname(data, STRING_SSL_ISSUERCERT, &is_nickname);
@ -1434,7 +1437,7 @@ CURLcode Curl_nss_connect(struct connectdata *conn, int sockindex)
connssl->obj_list = NULL; connssl->obj_list = NULL;
#endif #endif
if (ssl3 && tlsv1 && isTLSIntoleranceError(err)) { if(ssl3 && tlsv1 && isTLSIntoleranceError(err)) {
/* schedule reconnect through Curl_retry_request() */ /* schedule reconnect through Curl_retry_request() */
data->state.ssl_connect_retry = TRUE; data->state.ssl_connect_retry = TRUE;
infof(data, "Error in TLS handshake, trying SSLv3...\n"); infof(data, "Error in TLS handshake, trying SSLv3...\n");

View File

@ -55,7 +55,8 @@
#ifndef _LDAP_PVT_H #ifndef _LDAP_PVT_H
extern int ldap_pvt_url_scheme2proto(const char *); extern int ldap_pvt_url_scheme2proto(const char *);
extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url, LDAP **ld); extern int ldap_init_fd(ber_socket_t fd, int proto, const char *url,
LDAP **ld);
#endif #endif
static CURLcode ldap_setup(struct connectdata *conn); static CURLcode ldap_setup(struct connectdata *conn);
@ -63,7 +64,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done);
static CURLcode ldap_done(struct connectdata *conn, CURLcode, bool); static CURLcode ldap_done(struct connectdata *conn, CURLcode, bool);
static CURLcode ldap_connect(struct connectdata *conn, bool *done); static CURLcode ldap_connect(struct connectdata *conn, bool *done);
static CURLcode ldap_connecting(struct connectdata *conn, bool *done); static CURLcode ldap_connecting(struct connectdata *conn, bool *done);
static CURLcode ldap_disconnect(struct connectdata *conn, bool dead_connection); static CURLcode ldap_disconnect(struct connectdata *conn, bool dead);
static Curl_recv ldap_recv; static Curl_recv ldap_recv;
@ -152,11 +153,11 @@ static CURLcode ldap_setup(struct connectdata *conn)
CURLcode status; CURLcode status;
rc = ldap_url_parse(data->change.url, &lud); rc = ldap_url_parse(data->change.url, &lud);
if (rc != LDAP_URL_SUCCESS) { if(rc != LDAP_URL_SUCCESS) {
const char *msg = "url parsing problem"; const char *msg = "url parsing problem";
status = CURLE_URL_MALFORMAT; status = CURLE_URL_MALFORMAT;
if (rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) { if(rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) {
if (rc == LDAP_URL_ERR_MEM) if(rc == LDAP_URL_ERR_MEM)
status = CURLE_OUT_OF_MEMORY; status = CURLE_OUT_OF_MEMORY;
msg = url_errs[rc]; msg = url_errs[rc];
} }
@ -189,13 +190,13 @@ static CURLcode ldap_connect(struct connectdata *conn, bool *done)
strcpy(hosturl, "ldap"); strcpy(hosturl, "ldap");
ptr = hosturl+4; ptr = hosturl+4;
if (conn->handler->flags & PROTOPT_SSL) if(conn->handler->flags & PROTOPT_SSL)
*ptr++ = 's'; *ptr++ = 's';
snprintf(ptr, sizeof(hosturl)-(ptr-hosturl), "://%s:%d", snprintf(ptr, sizeof(hosturl)-(ptr-hosturl), "://%s:%d",
conn->host.name, conn->remote_port); conn->host.name, conn->remote_port);
rc = ldap_init_fd(conn->sock[FIRSTSOCKET], li->proto, hosturl, &li->ld); rc = ldap_init_fd(conn->sock[FIRSTSOCKET], li->proto, hosturl, &li->ld);
if (rc) { if(rc) {
failf(data, "LDAP local: Cannot connect to %s, %s", failf(data, "LDAP local: Cannot connect to %s, %s",
hosturl, ldap_err2string(rc)); hosturl, ldap_err2string(rc));
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
@ -231,22 +232,23 @@ static CURLcode ldap_connect(struct connectdata *conn, bool *done)
} }
#ifdef USE_SSL #ifdef USE_SSL
if (conn->handler->flags & PROTOPT_SSL) { if(conn->handler->flags & PROTOPT_SSL) {
CURLcode res; CURLcode res;
if (data->state.used_interface == Curl_if_easy) { if(data->state.used_interface == Curl_if_easy) {
res = Curl_ssl_connect(conn, FIRSTSOCKET); res = Curl_ssl_connect(conn, FIRSTSOCKET);
if (res) if(res)
return res; return res;
li->ssldone = TRUE; li->ssldone = TRUE;
} else { }
else {
res = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &li->ssldone); res = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &li->ssldone);
if (res) if(res)
return res; return res;
} }
} }
#endif #endif
if (data->state.used_interface == Curl_if_easy) if(data->state.used_interface == Curl_if_easy)
return ldap_connecting(conn, done); return ldap_connecting(conn, done);
return CURLE_OK; return CURLE_OK;
@ -262,15 +264,16 @@ static CURLcode ldap_connecting(struct connectdata *conn, bool *done)
char *info = NULL; char *info = NULL;
#ifdef USE_SSL #ifdef USE_SSL
if (conn->handler->flags & PROTOPT_SSL) { if(conn->handler->flags & PROTOPT_SSL) {
/* Is the SSL handshake complete yet? */ /* Is the SSL handshake complete yet? */
if (!li->ssldone) { if(!li->ssldone) {
CURLcode res = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET, &li->ssldone); CURLcode res = Curl_ssl_connect_nonblocking(conn, FIRSTSOCKET,
if (res || !li->ssldone) &li->ssldone);
if(res || !li->ssldone)
return res; return res;
} }
/* Have we installed the libcurl SSL handlers into the sockbuf yet? */ /* Have we installed the libcurl SSL handlers into the sockbuf yet? */
if (!li->sslinst) { if(!li->sslinst) {
Sockbuf *sb; Sockbuf *sb;
ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb); ldap_get_option(li->ld, LDAP_OPT_SOCKBUF, &sb);
ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, conn); ber_sockbuf_add_io(sb, &ldapsb_tls, LBER_SBIOD_LEVEL_TRANSPORT, conn);
@ -281,53 +284,54 @@ static CURLcode ldap_connecting(struct connectdata *conn, bool *done)
} }
#endif #endif
if (data->state.used_interface == Curl_if_easy) if(data->state.used_interface == Curl_if_easy)
tvp = NULL; /* let ldap_result block indefinitely */ tvp = NULL; /* let ldap_result block indefinitely */
else else
tvp = &tv; tvp = &tv;
retry: retry:
if (!li->didbind) { if(!li->didbind) {
char *binddn; char *binddn;
struct berval passwd; struct berval passwd;
if (conn->bits.user_passwd) { if(conn->bits.user_passwd) {
binddn = conn->user; binddn = conn->user;
passwd.bv_val = conn->passwd; passwd.bv_val = conn->passwd;
passwd.bv_len = strlen(passwd.bv_val); passwd.bv_len = strlen(passwd.bv_val);
} else { }
else {
binddn = NULL; binddn = NULL;
passwd.bv_val = NULL; passwd.bv_val = NULL;
passwd.bv_len = 0; passwd.bv_len = 0;
} }
rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd, rc = ldap_sasl_bind(li->ld, binddn, LDAP_SASL_SIMPLE, &passwd,
NULL, NULL, &li->msgid); NULL, NULL, &li->msgid);
if (rc) if(rc)
return CURLE_LDAP_CANNOT_BIND; return CURLE_LDAP_CANNOT_BIND;
li->didbind = TRUE; li->didbind = TRUE;
if (tvp) if(tvp)
return CURLE_OK; return CURLE_OK;
} }
rc = ldap_result(li->ld, li->msgid, LDAP_MSG_ONE, tvp, &result); rc = ldap_result(li->ld, li->msgid, LDAP_MSG_ONE, tvp, &result);
if (rc < 0) { if(rc < 0) {
failf(data, "LDAP local: bind ldap_result %s", ldap_err2string(rc)); failf(data, "LDAP local: bind ldap_result %s", ldap_err2string(rc));
return CURLE_LDAP_CANNOT_BIND; return CURLE_LDAP_CANNOT_BIND;
} }
if (rc == 0) { if(rc == 0) {
/* timed out */ /* timed out */
return CURLE_OK; return CURLE_OK;
} }
rc = ldap_parse_result(li->ld, result, &err, NULL, &info, NULL, NULL, 1); rc = ldap_parse_result(li->ld, result, &err, NULL, &info, NULL, NULL, 1);
if (rc) { if(rc) {
failf(data, "LDAP local: bind ldap_parse_result %s", ldap_err2string(rc)); failf(data, "LDAP local: bind ldap_parse_result %s", ldap_err2string(rc));
return CURLE_LDAP_CANNOT_BIND; return CURLE_LDAP_CANNOT_BIND;
} }
/* Try to fallback to LDAPv2? */ /* Try to fallback to LDAPv2? */
if (err == LDAP_PROTOCOL_ERROR) { if(err == LDAP_PROTOCOL_ERROR) {
int proto; int proto;
ldap_get_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto); ldap_get_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
if (proto == LDAP_VERSION3) { if(proto == LDAP_VERSION3) {
ldap_memfree(info); ldap_memfree(info);
proto = LDAP_VERSION2; proto = LDAP_VERSION2;
ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto); ldap_set_option(li->ld, LDAP_OPT_PROTOCOL_VERSION, &proto);
@ -336,7 +340,7 @@ retry:
} }
} }
if (err) { if(err) {
failf(data, "LDAP remote: bind failed %s %s", ldap_err2string(rc), failf(data, "LDAP remote: bind failed %s %s", ldap_err2string(rc),
info ? info : ""); info ? info : "");
return CURLE_LOGIN_DENIED; return CURLE_LOGIN_DENIED;
@ -351,8 +355,8 @@ static CURLcode ldap_disconnect(struct connectdata *conn, bool dead_connection)
ldapconninfo *li = conn->proto.generic; ldapconninfo *li = conn->proto.generic;
(void) dead_connection; (void) dead_connection;
if (li) { if(li) {
if (li->ld) { if(li->ld) {
ldap_unbind_ext(li->ld, NULL, NULL); ldap_unbind_ext(li->ld, NULL, NULL);
li->ld = NULL; li->ld = NULL;
} }
@ -377,11 +381,11 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done)
infof(data, "LDAP local: %s\n", data->change.url); infof(data, "LDAP local: %s\n", data->change.url);
rc = ldap_url_parse(data->change.url, &ludp); rc = ldap_url_parse(data->change.url, &ludp);
if (rc != LDAP_URL_SUCCESS) { if(rc != LDAP_URL_SUCCESS) {
const char *msg = "url parsing problem"; const char *msg = "url parsing problem";
status = CURLE_URL_MALFORMAT; status = CURLE_URL_MALFORMAT;
if (rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) { if(rc > LDAP_URL_SUCCESS && rc <= LDAP_URL_ERR_BADEXTS) {
if (rc == LDAP_URL_ERR_MEM) if(rc == LDAP_URL_ERR_MEM)
status = CURLE_OUT_OF_MEMORY; status = CURLE_OUT_OF_MEMORY;
msg = url_errs[rc]; msg = url_errs[rc];
} }
@ -393,7 +397,7 @@ static CURLcode ldap_do(struct connectdata *conn, bool *done)
ludp->lud_filter, ludp->lud_attrs, 0, ludp->lud_filter, ludp->lud_attrs, 0,
NULL, NULL, NULL, 0, &msgid); NULL, NULL, NULL, 0, &msgid);
ldap_free_urldesc(ludp); ldap_free_urldesc(ludp);
if (rc != LDAP_SUCCESS) { if(rc != LDAP_SUCCESS) {
failf(data, "LDAP local: ldap_search_ext %s", ldap_err2string(rc)); failf(data, "LDAP local: ldap_search_ext %s", ldap_err2string(rc));
return CURLE_LDAP_SEARCH_FAILED; return CURLE_LDAP_SEARCH_FAILED;
} }
@ -412,9 +416,9 @@ static CURLcode ldap_done(struct connectdata *conn, CURLcode res,
(void)res; (void)res;
(void)premature; (void)premature;
if (lr) { if(lr) {
/* if there was a search in progress, abandon it */ /* if there was a search in progress, abandon it */
if (lr->msgid) { if(lr->msgid) {
ldapconninfo *li = conn->proto.generic; ldapconninfo *li = conn->proto.generic;
ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL); ldap_abandon_ext(li->ld, lr->msgid, NULL, NULL);
lr->msgid = 0; lr->msgid = 0;
@ -441,7 +445,7 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
(void)sockindex; (void)sockindex;
rc = ldap_result(li->ld, lr->msgid, LDAP_MSG_RECEIVED, &tv, &result); rc = ldap_result(li->ld, lr->msgid, LDAP_MSG_RECEIVED, &tv, &result);
if (rc < 0) { if(rc < 0) {
failf(data, "LDAP local: search ldap_result %s", ldap_err2string(rc)); failf(data, "LDAP local: search ldap_result %s", ldap_err2string(rc));
*err = CURLE_RECV_ERROR; *err = CURLE_RECV_ERROR;
return -1; return -1;
@ -451,30 +455,32 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
ret = -1; ret = -1;
/* timed out */ /* timed out */
if (result == NULL) if(result == NULL)
return ret; return ret;
for (ent = ldap_first_message(li->ld, result); ent; for(ent = ldap_first_message(li->ld, result); ent;
ent = ldap_next_message(li->ld, ent)) { ent = ldap_next_message(li->ld, ent)) {
struct berval bv, *bvals, **bvp = &bvals; struct berval bv, *bvals, **bvp = &bvals;
int binary = 0, msgtype; int binary = 0, msgtype;
msgtype = ldap_msgtype(ent); msgtype = ldap_msgtype(ent);
if (msgtype == LDAP_RES_SEARCH_RESULT) { if(msgtype == LDAP_RES_SEARCH_RESULT) {
int code; int code;
char *info = NULL; char *info = NULL;
rc = ldap_parse_result(li->ld, ent, &code, NULL, &info, NULL, NULL, 0); rc = ldap_parse_result(li->ld, ent, &code, NULL, &info, NULL, NULL, 0);
if (rc) { if(rc) {
failf(data, "LDAP local: search ldap_parse_result %s", failf(data, "LDAP local: search ldap_parse_result %s",
ldap_err2string(rc)); ldap_err2string(rc));
*err = CURLE_LDAP_SEARCH_FAILED; *err = CURLE_LDAP_SEARCH_FAILED;
} else if (code && code != LDAP_SIZELIMIT_EXCEEDED) { }
else if(code && code != LDAP_SIZELIMIT_EXCEEDED) {
failf(data, "LDAP remote: search failed %s %s", ldap_err2string(rc), failf(data, "LDAP remote: search failed %s %s", ldap_err2string(rc),
info ? info : ""); info ? info : "");
*err = CURLE_LDAP_SEARCH_FAILED; *err = CURLE_LDAP_SEARCH_FAILED;
} else { }
else {
/* successful */ /* successful */
if (code == LDAP_SIZELIMIT_EXCEEDED) if(code == LDAP_SIZELIMIT_EXCEEDED)
infof(data, "There are more than %d entries\n", lr->nument); infof(data, "There are more than %d entries\n", lr->nument);
data->req.size = data->req.bytecount; data->req.size = data->req.bytecount;
*err = CURLE_OK; *err = CURLE_OK;
@ -483,9 +489,9 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
lr->msgid = 0; lr->msgid = 0;
ldap_memfree(info); ldap_memfree(info);
break; break;
} else if (msgtype != LDAP_RES_SEARCH_ENTRY) {
continue;
} }
else if(msgtype != LDAP_RES_SEARCH_ENTRY)
continue;
lr->nument++; lr->nument++;
rc = ldap_get_dn_ber(li->ld, ent, &ber, &bv); rc = ldap_get_dn_ber(li->ld, ent, &ber, &bv);
@ -500,41 +506,42 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1); Curl_client_write(conn, CLIENTWRITE_BODY, (char *)"\n", 1);
data->req.bytecount += bv.bv_len + 5; data->req.bytecount += bv.bv_len + 5;
for (rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp); for(rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp);
rc == LDAP_SUCCESS; rc == LDAP_SUCCESS;
rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp)) { rc = ldap_get_attribute_ber(li->ld, ent, ber, &bv, bvp)) {
int i; int i;
if (bv.bv_val == NULL) break; if(bv.bv_val == NULL) break;
if (bv.bv_len > 7 && !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7)) if(bv.bv_len > 7 && !strncmp(bv.bv_val + bv.bv_len - 7, ";binary", 7))
binary = 1; binary = 1;
else else
binary = 0; binary = 0;
for (i=0; bvals[i].bv_val != NULL; i++) { for(i=0; bvals[i].bv_val != NULL; i++) {
int binval = 0; int binval = 0;
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 *)bv.bv_val, bv.bv_len); Curl_client_write(conn, CLIENTWRITE_BODY, (char *)bv.bv_val,
bv.bv_len);
Curl_client_write(conn, CLIENTWRITE_BODY, (char *)":", 1); Curl_client_write(conn, CLIENTWRITE_BODY, (char *)":", 1);
data->req.bytecount += bv.bv_len + 2; data->req.bytecount += bv.bv_len + 2;
if (!binary) { if(!binary) {
/* check for leading or trailing whitespace */ /* check for leading or trailing whitespace */
if (ISSPACE(bvals[i].bv_val[0]) || if(ISSPACE(bvals[i].bv_val[0]) ||
ISSPACE(bvals[i].bv_val[bvals[i].bv_len-1])) { ISSPACE(bvals[i].bv_val[bvals[i].bv_len-1]))
binval = 1; binval = 1;
} else { else {
/* check for unprintable characters */ /* check for unprintable characters */
unsigned int j; unsigned int j;
for (j=0; j<bvals[i].bv_len; j++) for(j=0; j<bvals[i].bv_len; j++)
if (!ISPRINT(bvals[i].bv_val[j])) { if(!ISPRINT(bvals[i].bv_val[j])) {
binval = 1; binval = 1;
break; break;
} }
} }
} }
if (binary || binval) { if(binary || binval) {
char *val_b64; char *val_b64;
/* Binary value, encode to base64. */ /* Binary value, encode to base64. */
size_t val_b64_sz = Curl_base64_encode(data, size_t val_b64_sz = Curl_base64_encode(data,
@ -548,7 +555,8 @@ static ssize_t ldap_recv(struct connectdata *conn, int sockindex, char *buf,
free(val_b64); free(val_b64);
data->req.bytecount += val_b64_sz; data->req.bytecount += val_b64_sz;
} }
} else { }
else {
Curl_client_write(conn, CLIENTWRITE_BODY, (char *)" ", 1); Curl_client_write(conn, CLIENTWRITE_BODY, (char *)" ", 1);
Curl_client_write(conn, CLIENTWRITE_BODY, bvals[i].bv_val, Curl_client_write(conn, CLIENTWRITE_BODY, bvals[i].bv_val,
bvals[i].bv_len); bvals[i].bv_len);
@ -596,7 +604,7 @@ static int
ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg) ldapsb_tls_ctrl(Sockbuf_IO_Desc *sbiod, int opt, void *arg)
{ {
(void)arg; (void)arg;
if (opt == LBER_SB_OPT_DATA_READY) { if(opt == LBER_SB_OPT_DATA_READY) {
struct connectdata *conn = sbiod->sbiod_pvt; struct connectdata *conn = sbiod->sbiod_pvt;
return Curl_ssl_data_pending(conn, FIRSTSOCKET); return Curl_ssl_data_pending(conn, FIRSTSOCKET);
} }
@ -612,7 +620,7 @@ ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
CURLcode err = CURLE_RECV_ERROR; CURLcode err = CURLE_RECV_ERROR;
ret = li->recv(conn, FIRSTSOCKET, buf, len, &err); ret = li->recv(conn, FIRSTSOCKET, buf, len, &err);
if (ret < 0 && err == CURLE_AGAIN) { if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK); SET_SOCKERRNO(EWOULDBLOCK);
} }
return ret; return ret;
@ -627,7 +635,7 @@ ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
CURLcode err = CURLE_SEND_ERROR; CURLcode err = CURLE_SEND_ERROR;
ret = li->send(conn, FIRSTSOCKET, buf, len, &err); ret = li->send(conn, FIRSTSOCKET, buf, len, &err);
if (ret < 0 && err == CURLE_AGAIN) { if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK); SET_SOCKERRNO(EWOULDBLOCK);
} }
return ret; return ret;

View File

@ -160,7 +160,8 @@ static const struct tzinfo tz[]= {
{"G", +7 * 60}, /* Golf */ {"G", +7 * 60}, /* Golf */
{"H", +8 * 60}, /* Hotel */ {"H", +8 * 60}, /* Hotel */
{"I", +9 * 60}, /* India */ {"I", +9 * 60}, /* India */
/* "J", Juliet is not used as a timezone, to indicate the observer's local time */ /* "J", Juliet is not used as a timezone, to indicate the observer's local
time */
{"K", +10 * 60}, /* Kilo */ {"K", +10 * 60}, /* Kilo */
{"L", +11 * 60}, /* Lima */ {"L", +11 * 60}, /* Lima */
{"M", +12 * 60}, /* Mike */ {"M", +12 * 60}, /* Mike */
@ -282,11 +283,11 @@ static time_t my_timegm(struct my_tm *tm)
year = tm->tm_year + 1900; year = tm->tm_year + 1900;
month = tm->tm_mon; month = tm->tm_mon;
if (month < 0) { if(month < 0) {
year += (11 - month) / 12; year += (11 - month) / 12;
month = 11 - (11 - month) % 12; month = 11 - (11 - month) % 12;
} }
else if (month >= 12) { else if(month >= 12) {
year -= month / 12; year -= month / 12;
month = month % 12; month = month % 12;
} }

View File

@ -431,8 +431,8 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
/* We got an excessive line without newlines and we need to deal /* We got an excessive line without newlines and we need to deal
with it. We keep the first bytes of the line then we throw with it. We keep the first bytes of the line then we throw
away the rest. */ away the rest. */
infof(data, "Excessive server response line length received, %zd bytes." infof(data, "Excessive server response line length received, "
" Stripping\n", gotbytes); "%zd bytes. Stripping\n", gotbytes);
restart = TRUE; restart = TRUE;
/* we keep 40 bytes since all our pingpong protocols are only /* we keep 40 bytes since all our pingpong protocols are only
@ -440,9 +440,9 @@ CURLcode Curl_pp_readresp(curl_socket_t sockfd,
clipamount = 40; clipamount = 40;
} }
else if(pp->nread_resp > BUFSIZE/2) { else if(pp->nread_resp > BUFSIZE/2) {
/* We got a large chunk of data and there's potentially still trailing /* We got a large chunk of data and there's potentially still
data to take care of, so we put any such part in the "cache", clear trailing data to take care of, so we put any such part in the
the buffer to make space and restart. */ "cache", clear the buffer to make space and restart. */
clipamount = perline; clipamount = perline;
restart = TRUE; restart = TRUE;
} }

View File

@ -106,9 +106,9 @@ Curl_polarssl_connect(struct connectdata *conn,
if(data->set.ssl.version == CURL_SSLVERSION_SSLv2) { if(data->set.ssl.version == CURL_SSLVERSION_SSLv2) {
failf(data, "PolarSSL does not support SSLv2"); failf(data, "PolarSSL does not support SSLv2");
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
} else if(data->set.ssl.version == CURL_SSLVERSION_SSLv3) {
sni = FALSE; /* SSLv3 has no SNI */
} }
else if(data->set.ssl.version == CURL_SSLVERSION_SSLv3)
sni = FALSE; /* SSLv3 has no SNI */
havege_init(&conn->ssl[sockindex].hs); havege_init(&conn->ssl[sockindex].hs);
@ -222,12 +222,13 @@ Curl_polarssl_connect(struct connectdata *conn,
#endif #endif
for(;;) { for(;;) {
if (!(ret = ssl_handshake(&conn->ssl[sockindex].ssl))) { if(!(ret = ssl_handshake(&conn->ssl[sockindex].ssl)))
break; break;
} else if(ret != POLARSSL_ERR_NET_TRY_AGAIN) { else if(ret != POLARSSL_ERR_NET_TRY_AGAIN) {
failf(data, "ssl_handshake returned -0x%04X", -ret); failf(data, "ssl_handshake returned -0x%04X", -ret);
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
} else { }
else {
/* wait for data from server... */ /* wait for data from server... */
long timeout_ms = Curl_timeleft(data, NULL, TRUE); long timeout_ms = Curl_timeleft(data, NULL, TRUE);

View File

@ -100,7 +100,7 @@ static CURLcode pop3_do(struct connectdata *conn, bool *done);
static CURLcode pop3_done(struct connectdata *conn, static CURLcode pop3_done(struct connectdata *conn,
CURLcode, bool premature); CURLcode, bool premature);
static CURLcode pop3_connect(struct connectdata *conn, bool *done); static CURLcode pop3_connect(struct connectdata *conn, bool *done);
static CURLcode pop3_disconnect(struct connectdata *conn, bool dead_connection); static CURLcode pop3_disconnect(struct connectdata *conn, bool dead);
static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done); static CURLcode pop3_multi_statemach(struct connectdata *conn, bool *done);
static int pop3_getsock(struct connectdata *conn, static int pop3_getsock(struct connectdata *conn,
curl_socket_t *socks, curl_socket_t *socks,
@ -481,7 +481,7 @@ static CURLcode pop3_list(struct connectdata *conn)
if(result) if(result)
return result; return result;
if (strlen(pop3c->mailbox)) if(strlen(pop3c->mailbox))
state(conn, POP3_LIST_SINGLE); state(conn, POP3_LIST_SINGLE);
else else
state(conn, POP3_LIST); state(conn, POP3_LIST);
@ -773,7 +773,7 @@ CURLcode pop3_perform(struct connectdata *conn,
/* If mailbox is empty, then assume user wants listing for mail IDs, /* If mailbox is empty, then assume user wants listing for mail IDs,
* otherwise, attempt to retrieve the mail-id stored in mailbox * otherwise, attempt to retrieve the mail-id stored in mailbox
*/ */
if (strlen(pop3c->mailbox) && !conn->data->set.ftp_list_only) if(strlen(pop3c->mailbox) && !conn->data->set.ftp_list_only)
result = pop3_retr(conn); result = pop3_retr(conn);
else else
result = pop3_list(conn); result = pop3_list(conn);
@ -896,7 +896,7 @@ static CURLcode pop3_parse_url_path(struct connectdata *conn)
/* url decode the path and use this mailbox */ /* url decode the path and use this mailbox */
pop3c->mailbox = curl_easy_unescape(data, path, 0, NULL); pop3c->mailbox = curl_easy_unescape(data, path, 0, NULL);
if (!pop3c->mailbox) if(!pop3c->mailbox)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
return CURLE_OK; return CURLE_OK;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -369,8 +369,10 @@ int Curl_pgrsUpdate(struct connectdata *conn)
data->state.resume_from); data->state.resume_from);
} }
fprintf(data->set.err, fprintf(data->set.err,
" %% Total %% Received %% Xferd Average Speed Time Time Time Current\n" " %% Total %% Received %% Xferd Average Speed "
" Dload Upload Total Spent Left Speed\n"); "Time Time Time Current\n"
" Dload Upload "
"Total Spent Left Speed\n");
data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */ data->progress.flags |= PGRS_HEADERS_OUT; /* headers are shown */
} }

View File

@ -266,7 +266,7 @@ CURLcode Curl_qsossl_connect(struct connectdata * conn, int sockindex)
connssl->state = ssl_connection_none; connssl->state = ssl_connection_none;
} }
} }
if (rc == CURLE_OK) { if(rc == CURLE_OK) {
connssl->state = ssl_connection_complete; connssl->state = ssl_connection_complete;
conn->recv[sockindex] = qsossl_recv; conn->recv[sockindex] = qsossl_recv;
conn->send[sockindex] = qsossl_send; conn->send[sockindex] = qsossl_send;
@ -347,7 +347,7 @@ int Curl_qsossl_shutdown(struct connectdata * conn, int sockindex)
what = Curl_socket_ready(conn->sock[sockindex], what = Curl_socket_ready(conn->sock[sockindex],
CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT); CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
for (;;) { for(;;) {
if(what < 0) { if(what < 0) {
/* anything that gets here is fatally bad */ /* anything that gets here is fatally bad */
failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO); failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -133,10 +133,10 @@ int Curl_raw_nequal(const char *first, const char *second, size_t max)
*/ */
void Curl_strntoupper(char *dest, const char *src, size_t n) void Curl_strntoupper(char *dest, const char *src, size_t n)
{ {
if (n < 1) if(n < 1)
return; return;
do { do {
*dest++ = Curl_raw_toupper(*src); *dest++ = Curl_raw_toupper(*src);
} while (*src++ && --n); } while(*src++ && --n);
} }

View File

@ -29,7 +29,8 @@
* to be locale independent and only compare strings we know are safe for * to be locale independent and only compare strings we know are safe for
* this. * this.
* *
* The function is capable of comparing a-z case insensitively even for non-ascii. * The function is capable of comparing a-z case insensitively even for
* non-ascii.
*/ */
int Curl_raw_equal(const char *first, const char *second); int Curl_raw_equal(const char *first, const char *second);
int Curl_raw_nequal(const char *first, const char *second, size_t max); int Curl_raw_nequal(const char *first, const char *second, size_t max);

View File

@ -119,11 +119,11 @@ bool Curl_rtsp_connisdead(struct connectdata *check)
/* timeout */ /* timeout */
ret_val = FALSE; ret_val = FALSE;
} }
else if (sval & CURL_CSELECT_ERR) { else if(sval & CURL_CSELECT_ERR) {
/* socket is in an error state */ /* socket is in an error state */
ret_val = TRUE; ret_val = TRUE;
} }
else if ((sval & CURL_CSELECT_IN) && check->data) { else if((sval & CURL_CSELECT_IN) && check->data) {
/* readable with no error. could be closed or could be alive but we can /* readable with no error. could be closed or could be alive but we can
only check if we have a proper SessionHandle for the connection */ only check if we have a proper SessionHandle for the connection */
curl_socket_t connectinfo = Curl_getconnectinfo(check->data, &check); curl_socket_t connectinfo = Curl_getconnectinfo(check->data, &check);
@ -180,7 +180,8 @@ CURLcode Curl_rtsp_done(struct connectdata *conn,
CSeq_sent = rtsp->CSeq_sent; CSeq_sent = rtsp->CSeq_sent;
CSeq_recv = rtsp->CSeq_recv; CSeq_recv = rtsp->CSeq_recv;
if((data->set.rtspreq != RTSPREQ_RECEIVE) && (CSeq_sent != CSeq_recv)) { if((data->set.rtspreq != RTSPREQ_RECEIVE) && (CSeq_sent != CSeq_recv)) {
failf(data, "The CSeq of this request %ld did not match the response %ld", failf(data,
"The CSeq of this request %ld did not match the response %ld",
CSeq_sent, CSeq_recv); CSeq_sent, CSeq_recv);
return CURLE_RTSP_CSEQ_ERROR; return CURLE_RTSP_CSEQ_ERROR;
} }
@ -510,8 +511,9 @@ CURLcode Curl_rtsp(struct connectdata *conn, bool *done)
} }
} }
data->state.expect100header = FALSE; /* RTSP posts are simple/small */ data->state.expect100header = FALSE; /* RTSP posts are simple/small */
} else if(rtspreq == RTSPREQ_GET_PARAMETER) { }
else if(rtspreq == RTSPREQ_GET_PARAMETER) {
/* Check for an empty GET_PARAMETER (heartbeat) request */ /* Check for an empty GET_PARAMETER (heartbeat) request */
data->set.httpreq = HTTPREQ_HEAD; data->set.httpreq = HTTPREQ_HEAD;
data->set.opt_no_body = TRUE; data->set.opt_no_body = TRUE;

View File

@ -10,7 +10,7 @@
* Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan * Copyright (c) 1998, 1999 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden). * (Royal Institute of Technology, Stockholm, Sweden).
* *
* Copyright (C) 2001 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2001 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* All rights reserved. * All rights reserved.
* *
@ -208,17 +208,17 @@ static CURLcode read_data(struct connectdata *conn,
CURLcode ret; CURLcode ret;
ret = socket_read(fd, &len, sizeof(len)); ret = socket_read(fd, &len, sizeof(len));
if (ret != CURLE_OK) if(ret != CURLE_OK)
return ret; return ret;
len = ntohl(len); len = ntohl(len);
tmp = realloc(buf->data, len); tmp = realloc(buf->data, len);
if (tmp == NULL) if(tmp == NULL)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
buf->data = tmp; buf->data = tmp;
ret = socket_read(fd, buf->data, len); ret = socket_read(fd, buf->data, len);
if (ret != CURLE_OK) if(ret != CURLE_OK)
return ret; return ret;
buf->size = conn->mech->decode(conn->app_data, buf->data, len, buf->size = conn->mech->decode(conn->app_data, buf->data, len,
conn->data_prot, conn); conn->data_prot, conn);
@ -522,7 +522,7 @@ static CURLcode choose_mech(struct connectdata *conn)
break; break;
default: default:
if(ret/100 == 5) { if(ret/100 == 5) {
infof(data, "The server does not support the security extensions.\n"); infof(data, "server does not support the security extensions\n");
return CURLE_USE_SSL_FAILED; return CURLE_USE_SSL_FAILED;
} }
break; break;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -355,7 +355,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
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;
@ -402,7 +402,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
if(r == 0) if(r == 0)
return 0; return 0;
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)
continue; continue;
if(ufds[i].revents & POLLHUP) if(ufds[i].revents & POLLHUP)
@ -418,7 +418,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
FD_ZERO(&fds_err); FD_ZERO(&fds_err);
maxfd = (curl_socket_t)-1; maxfd = (curl_socket_t)-1;
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;
@ -466,7 +466,7 @@ int Curl_poll(struct pollfd ufds[], unsigned int nfds, int timeout_ms)
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;

View File

@ -299,7 +299,8 @@ ssize_t Curl_send_plain(struct connectdata *conn, int num,
/* this is just a case of EWOULDBLOCK */ /* this is just a case of EWOULDBLOCK */
bytes_written=0; bytes_written=0;
*code = CURLE_AGAIN; *code = CURLE_AGAIN;
} else { }
else {
failf(conn->data, "Send failure: %s", failf(conn->data, "Send failure: %s",
Curl_strerror(conn, err)); Curl_strerror(conn, err));
conn->data->state.os_errno = err; conn->data->state.os_errno = err;
@ -354,7 +355,8 @@ ssize_t Curl_recv_plain(struct connectdata *conn, int num, char *buf,
) { ) {
/* this is just a case of EWOULDBLOCK */ /* this is just a case of EWOULDBLOCK */
*code = CURLE_AGAIN; *code = CURLE_AGAIN;
} else { }
else {
failf(conn->data, "Recv failure: %s", failf(conn->data, "Recv failure: %s",
Curl_strerror(conn, err)); Curl_strerror(conn, err));
conn->data->state.os_errno = err; conn->data->state.os_errno = err;

View File

@ -26,7 +26,8 @@
* Define WIN32 when build target is Win32 API * Define WIN32 when build target is Win32 API
*/ */
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && !defined(__SYMBIAN32__) #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32) && \
!defined(__SYMBIAN32__)
#define WIN32 #define WIN32
#endif #endif
@ -523,7 +524,8 @@
#if defined(_MSC_VER) && !defined(__POCC__) #if defined(_MSC_VER) && !defined(__POCC__)
# if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_)) # if !defined(HAVE_WINDOWS_H) || ((_MSC_VER < 1300) && !defined(_FILETIME_))
# if !defined(ALLOW_MSVC6_WITHOUT_PSDK) # if !defined(ALLOW_MSVC6_WITHOUT_PSDK)
# error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. "Windows Server 2003 PSDK" # error MSVC 6.0 requires "February 2003 Platform SDK" a.k.a. \
"Windows Server 2003 PSDK"
# else # else
# define CURL_DISABLE_LDAP 1 # define CURL_DISABLE_LDAP 1
# endif # endif
@ -551,7 +553,9 @@ int netware_init(void);
#define LIBIDN_REQUIRED_VERSION "0.4.1" #define LIBIDN_REQUIRED_VERSION "0.4.1"
#if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || defined(USE_QSOSSL) || defined(USE_POLARSSL) || defined(USE_AXTLS) || defined(USE_CYASSL) #if defined(USE_GNUTLS) || defined(USE_SSLEAY) || defined(USE_NSS) || \
defined(USE_QSOSSL) || defined(USE_POLARSSL) || defined(USE_AXTLS) || \
defined(USE_CYASSL)
#define USE_SSL /* SSL support has been enabled */ #define USE_SSL /* SSL support has been enabled */
#endif #endif
@ -560,7 +564,8 @@ int netware_init(void);
#endif #endif
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM) #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_NTLM)
#if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI) || defined(USE_GNUTLS) || defined(USE_NSS) #if defined(USE_SSLEAY) || defined(USE_WINDOWS_SSPI) || \
defined(USE_GNUTLS) || defined(USE_NSS)
#define USE_NTLM #define USE_NTLM
#endif #endif
#endif #endif

View File

@ -96,32 +96,31 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
/* this is a type this share will no longer share */ /* this is a type this share will no longer share */
type = va_arg(param, int); type = va_arg(param, int);
share->specifier &= ~(1<<type); share->specifier &= ~(1<<type);
switch( type ) switch( type ) {
{ case CURL_LOCK_DATA_DNS:
case CURL_LOCK_DATA_DNS: if(share->hostcache) {
if(share->hostcache) { Curl_hash_destroy(share->hostcache);
Curl_hash_destroy(share->hostcache); share->hostcache = NULL;
share->hostcache = NULL; }
} break;
break;
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES) #if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
case CURL_LOCK_DATA_COOKIE: case CURL_LOCK_DATA_COOKIE:
if(share->cookies) { if(share->cookies) {
Curl_cookie_cleanup(share->cookies); Curl_cookie_cleanup(share->cookies);
share->cookies = NULL; share->cookies = NULL;
} }
break; break;
#endif /* CURL_DISABLE_HTTP */ #endif /* CURL_DISABLE_HTTP */
case CURL_LOCK_DATA_SSL_SESSION: case CURL_LOCK_DATA_SSL_SESSION:
break; break;
case CURL_LOCK_DATA_CONNECT: case CURL_LOCK_DATA_CONNECT:
break; break;
default: default:
return CURLSHE_BAD_OPTION; return CURLSHE_BAD_OPTION;
} }
break; break;

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -101,7 +101,7 @@ struct curl_slist *Curl_slist_duplicate(struct curl_slist *inlist)
while(inlist) { while(inlist) {
tmp = curl_slist_append(outlist, inlist->data); tmp = curl_slist_append(outlist, inlist->data);
if (!tmp) { if(!tmp) {
curl_slist_free_all(outlist); curl_slist_free_all(outlist);
return NULL; return NULL;
} }

View File

@ -106,7 +106,7 @@ static CURLcode smtp_do(struct connectdata *conn, bool *done);
static CURLcode smtp_done(struct connectdata *conn, static CURLcode smtp_done(struct connectdata *conn,
CURLcode, bool premature); CURLcode, bool premature);
static CURLcode smtp_connect(struct connectdata *conn, bool *done); static CURLcode smtp_connect(struct connectdata *conn, bool *done);
static CURLcode smtp_disconnect(struct connectdata *conn, bool dead_connection); static CURLcode smtp_disconnect(struct connectdata *conn, bool dead);
static CURLcode smtp_multi_statemach(struct connectdata *conn, bool *done); static CURLcode smtp_multi_statemach(struct connectdata *conn, bool *done);
static int smtp_getsock(struct connectdata *conn, static int smtp_getsock(struct connectdata *conn,
curl_socket_t *socks, curl_socket_t *socks,
@ -240,10 +240,10 @@ static int smtp_endofresp(struct pingpong *pp, int *resp)
line += 5; line += 5;
len -= 5; len -= 5;
for (;;) { for(;;) {
while (len && while(len &&
(*line == ' ' || *line == '\t' || (*line == ' ' || *line == '\t' ||
*line == '\r' || *line == '\n')) { *line == '\r' || *line == '\n')) {
line++; line++;
len--; len--;
} }
@ -251,9 +251,9 @@ static int smtp_endofresp(struct pingpong *pp, int *resp)
if(!len) if(!len)
break; break;
for (wordlen = 0; wordlen < len && line[wordlen] != ' ' && for(wordlen = 0; wordlen < len && line[wordlen] != ' ' &&
line[wordlen] != '\t' && line[wordlen] != '\r' && line[wordlen] != '\t' && line[wordlen] != '\r' &&
line[wordlen] != '\n';) line[wordlen] != '\n';)
wordlen++; wordlen++;
if(wordlen == 5 && !memcmp(line, "LOGIN", 5)) if(wordlen == 5 && !memcmp(line, "LOGIN", 5))
@ -359,7 +359,8 @@ static size_t smtp_auth_plain_data(struct connectdata * conn, char * * outptr)
memcpy(plainauth + ulen + 1, conn->user, ulen); memcpy(plainauth + ulen + 1, conn->user, ulen);
plainauth[2 * ulen + 1] = '\0'; plainauth[2 * ulen + 1] = '\0';
memcpy(plainauth + 2 * ulen + 2, conn->passwd, plen); memcpy(plainauth + 2 * ulen + 2, conn->passwd, plen);
return Curl_base64_encode(conn->data, plainauth, 2 * ulen + plen + 2, outptr); return Curl_base64_encode(conn->data, plainauth, 2 * ulen + plen + 2,
outptr);
} }
static size_t smtp_auth_login_user(struct connectdata * conn, char * * outptr) static size_t smtp_auth_login_user(struct connectdata * conn, char * * outptr)
@ -696,16 +697,16 @@ static CURLcode smtp_state_authcram_resp(struct connectdata *conn,
} }
/* Get the challenge. */ /* Get the challenge. */
for (chlg64 += 4; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++) for(chlg64 += 4; *chlg64 == ' ' || *chlg64 == '\t'; chlg64++)
; ;
chlg = (unsigned char *) NULL; chlg = (unsigned char *) NULL;
chlglen = 0; chlglen = 0;
if(*chlg64 != '=') { if(*chlg64 != '=') {
for (l = strlen(chlg64); l--;) for(l = strlen(chlg64); l--;)
if(chlg64[l] != '\r' && chlg64[l] != '\n' && chlg64[l] != ' ' && if(chlg64[l] != '\r' && chlg64[l] != '\n' && chlg64[l] != ' ' &&
chlg64[l] != '\t') chlg64[l] != '\t')
break; break;
if(++l) { if(++l) {
@ -740,9 +741,10 @@ static CURLcode smtp_state_authcram_resp(struct connectdata *conn,
/* Prepare the reply. */ /* Prepare the reply. */
snprintf(reply, sizeof reply, snprintf(reply, sizeof reply,
"%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", "%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
conn->user, digest[0], digest[1], digest[2], digest[3], digest[4], digest[5], conn->user, digest[0], digest[1], digest[2], digest[3], digest[4],
digest[6], digest[7], digest[8], digest[9], digest[10], digest[11], digest[5],
digest[12], digest[13], digest[14], digest[15]); digest[6], digest[7], digest[8], digest[9], digest[10], digest[11],
digest[12], digest[13], digest[14], digest[15]);
/* Encode it to base64 and send it. */ /* Encode it to base64 and send it. */
l = Curl_base64_encode(data, reply, 0, &rplyb64); l = Curl_base64_encode(data, reply, 0, &rplyb64);
@ -789,7 +791,7 @@ static CURLcode smtp_mail(struct connectdata *conn)
struct SessionHandle *data = conn->data; struct SessionHandle *data = conn->data;
/* send MAIL FROM */ /* send MAIL FROM */
if (data->set.str[STRING_MAIL_FROM][0] == '<') if(data->set.str[STRING_MAIL_FROM][0] == '<')
result = Curl_pp_sendf(&conn->proto.smtpc.pp, "MAIL FROM:%s", result = Curl_pp_sendf(&conn->proto.smtpc.pp, "MAIL FROM:%s",
data->set.str[STRING_MAIL_FROM]); data->set.str[STRING_MAIL_FROM]);
else else
@ -1217,7 +1219,8 @@ static CURLcode smtp_done(struct connectdata *conn, CURLcode status,
result = status; /* use the already set error code */ result = status; /* use the already set error code */
} }
else else
/* TODO: make this work even when the socket is EWOULDBLOCK in this call! */ /* TODO: make this work even when the socket is EWOULDBLOCK in this
call! */
/* write to socket (send away data) */ /* write to socket (send away data) */
result = Curl_write(conn, result = Curl_write(conn,

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 2009 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2009 - 2011, 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
@ -34,7 +34,8 @@ typedef enum {
SMTP_EHLO, SMTP_EHLO,
SMTP_HELO, SMTP_HELO,
SMTP_STARTTLS, SMTP_STARTTLS,
SMTP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS (multi mode only) */ SMTP_UPGRADETLS, /* asynchronously upgrade the connection to SSL/TLS
(multi mode only) */
SMTP_AUTHPLAIN, SMTP_AUTHPLAIN,
SMTP_AUTHLOGIN, SMTP_AUTHLOGIN,
SMTP_AUTHPASSWD, SMTP_AUTHPASSWD,

View File

@ -163,7 +163,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
*((unsigned short*)&socksreq[2]) = htons((unsigned short)remote_port); *((unsigned short*)&socksreq[2]) = htons((unsigned short)remote_port);
/* DNS resolve only for SOCKS4, not SOCKS4a */ /* DNS resolve only for SOCKS4, not SOCKS4a */
if (!protocol4a) { if(!protocol4a) {
struct Curl_dns_entry *dns; struct Curl_dns_entry *dns;
Curl_addrinfo *hp=NULL; Curl_addrinfo *hp=NULL;
int rc; int rc;
@ -227,14 +227,14 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
(int)strlen((char*)socksreq + 8); /* size including NUL */ (int)strlen((char*)socksreq + 8); /* size including NUL */
/* If SOCKS4a, set special invalid IP address 0.0.0.x */ /* If SOCKS4a, set special invalid IP address 0.0.0.x */
if (protocol4a) { if(protocol4a) {
socksreq[4] = 0; socksreq[4] = 0;
socksreq[5] = 0; socksreq[5] = 0;
socksreq[6] = 0; socksreq[6] = 0;
socksreq[7] = 1; socksreq[7] = 1;
/* If still enough room in buffer, also append hostname */ /* If still enough room in buffer, also append hostname */
hostnamelen = (ssize_t)strlen(hostname) + 1; /* length including NUL */ hostnamelen = (ssize_t)strlen(hostname) + 1; /* length including NUL */
if (packetsize + hostnamelen <= SOCKS4REQLEN) if(packetsize + hostnamelen <= SOCKS4REQLEN)
strcpy((char*)socksreq + packetsize, hostname); strcpy((char*)socksreq + packetsize, hostname);
else else
hostnamelen = 0; /* Flag: hostname did not fit in buffer */ hostnamelen = 0; /* Flag: hostname did not fit in buffer */
@ -248,7 +248,7 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
failf(data, "Failed to send SOCKS4 connect request."); failf(data, "Failed to send SOCKS4 connect request.");
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
if (protocol4a && hostnamelen == 0) { if(protocol4a && hostnamelen == 0) {
/* SOCKS4a with very long hostname - send that name separately */ /* SOCKS4a with very long hostname - send that name separately */
hostnamelen = (ssize_t)strlen(hostname) + 1; hostnamelen = (ssize_t)strlen(hostname) + 1;
code = Curl_write_plain(conn, sock, (char *)hostname, hostnamelen, code = Curl_write_plain(conn, sock, (char *)hostname, hostnamelen,
@ -296,10 +296,9 @@ CURLcode Curl_SOCKS4(const char *proxy_name,
} }
/* Result */ /* Result */
switch(socksreq[1]) switch(socksreq[1]) {
{
case 90: case 90:
if (protocol4a) if(protocol4a)
infof(data, "SOCKS4a request granted.\n"); infof(data, "SOCKS4a request granted.\n");
else else
infof(data, "SOCKS4 request granted.\n"); infof(data, "SOCKS4 request granted.\n");
@ -391,8 +390,7 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
ssize_t packetsize = 0; ssize_t packetsize = 0;
/* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */ /* RFC1928 chapter 5 specifies max 255 chars for domain name in packet */
if(!socks5_resolve_local && hostname_len > 255) if(!socks5_resolve_local && hostname_len > 255) {
{
infof(conn->data,"SOCKS5: server resolving disabled for hostnames of " infof(conn->data,"SOCKS5: server resolving disabled for hostnames of "
"length > 255 [actual len=%zu]\n", hostname_len); "length > 255 [actual len=%zu]\n", hostname_len);
socks5_resolve_local = TRUE; socks5_resolve_local = TRUE;
@ -643,9 +641,11 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
if(conn->socks5_gssapi_enctype) { if(conn->socks5_gssapi_enctype) {
failf(data, "SOCKS5 gssapi protection not yet implemented."); failf(data, "SOCKS5 gssapi protection not yet implemented.");
} else }
else
#endif #endif
code = Curl_write_plain(conn, sock, (char *)socksreq, packetsize, &written); code = Curl_write_plain(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;
@ -656,7 +656,8 @@ CURLcode Curl_SOCKS5(const char *proxy_name,
#if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI) #if defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)
if(conn->socks5_gssapi_enctype) { if(conn->socks5_gssapi_enctype) {
failf(data, "SOCKS5 gssapi protection not yet implemented."); failf(data, "SOCKS5 gssapi protection not yet implemented.");
} else }
else
#endif #endif
result = Curl_blockread_all(conn, sock, (char *)socksreq, packetsize, result = Curl_blockread_all(conn, sock, (char *)socksreq, packetsize,
&actualread, timeout); &actualread, timeout);

View File

@ -148,7 +148,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
*/ */
/* prepare service name */ /* prepare service name */
if (strchr(serviceptr,'/')) { if(strchr(serviceptr,'/')) {
service.value = malloc(strlen(serviceptr)); service.value = malloc(strlen(serviceptr));
if(!service.value) if(!service.value)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
@ -438,7 +438,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
gss_delete_sec_context(&gss_status, &gss_context, NULL); gss_delete_sec_context(&gss_status, &gss_context, NULL);
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
} else { }
else {
code = Curl_write_plain(conn, sock, (char *)gss_w_token.value, code = Curl_write_plain(conn, sock, (char *)gss_w_token.value,
gss_w_token.length, &written); gss_w_token.length, &written);
if((code != CURLE_OK) || ((ssize_t)gss_w_token.length != written)) { if((code != CURLE_OK) || ((ssize_t)gss_w_token.length != written)) {

View File

@ -197,7 +197,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
*/ */
/* prepare service name */ /* prepare service name */
if (strchr(service, '/')) { if(strchr(service, '/')) {
service_name = malloc(strlen(service)); service_name = malloc(strlen(service));
if(!service_name) if(!service_name)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
@ -234,15 +234,16 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
cred_handle.dwLower = 0; cred_handle.dwLower = 0;
cred_handle.dwUpper = 0; cred_handle.dwUpper = 0;
sspi_major_status = s_pSecFn->AcquireCredentialsHandleA( NULL, sspi_major_status =
(char *)"Kerberos", s_pSecFn->AcquireCredentialsHandleA( NULL,
SECPKG_CRED_OUTBOUND, (char *)"Kerberos",
NULL, SECPKG_CRED_OUTBOUND,
NULL, NULL,
NULL, NULL,
NULL, NULL,
&cred_handle, NULL,
&expiry); &cred_handle,
&expiry);
if(check_sspi_err(data, sspi_major_status,sspi_minor_status, if(check_sspi_err(data, sspi_major_status,sspi_minor_status,
"AcquireCredentialsHandleA") ) { "AcquireCredentialsHandleA") ) {
@ -408,9 +409,10 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
service_name=NULL; service_name=NULL;
/* Everything is good so far, user was authenticated! */ /* Everything is good so far, user was authenticated! */
sspi_major_status = s_pSecFn->QueryCredentialsAttributes( &cred_handle, sspi_major_status =
SECPKG_CRED_ATTR_NAMES, s_pSecFn->QueryCredentialsAttributes( &cred_handle,
&names); SECPKG_CRED_ATTR_NAMES,
&names);
s_pSecFn->FreeCredentialsHandle(&cred_handle); s_pSecFn->FreeCredentialsHandle(&cred_handle);
if(check_sspi_err(data,sspi_major_status,sspi_minor_status, if(check_sspi_err(data,sspi_major_status,sspi_minor_status,
"QueryCredentialAttributes") ){ "QueryCredentialAttributes") ){
@ -576,7 +578,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
s_pSecFn->DeleteSecurityContext(&sspi_context); s_pSecFn->DeleteSecurityContext(&sspi_context);
return CURLE_COULDNT_CONNECT; return CURLE_COULDNT_CONNECT;
} }
} else { }
else {
code = Curl_write_plain(conn, sock, (char *)sspi_send_token.pvBuffer, code = Curl_write_plain(conn, sock, (char *)sspi_send_token.pvBuffer,
sspi_send_token.cbBuffer, &written); sspi_send_token.cbBuffer, &written);
if((code != CURLE_OK) || (sspi_send_token.cbBuffer != (size_t)written)) { if((code != CURLE_OK) || (sspi_send_token.cbBuffer != (size_t)written)) {
@ -666,7 +669,8 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
memcpy(socksreq,sspi_w_token[1].pvBuffer,sspi_w_token[1].cbBuffer); memcpy(socksreq,sspi_w_token[1].pvBuffer,sspi_w_token[1].cbBuffer);
s_pSecFn->FreeContextBuffer(sspi_w_token[0].pvBuffer); s_pSecFn->FreeContextBuffer(sspi_w_token[0].pvBuffer);
s_pSecFn->FreeContextBuffer(sspi_w_token[1].pvBuffer); s_pSecFn->FreeContextBuffer(sspi_w_token[1].pvBuffer);
} else { }
else {
if(sspi_w_token[0].cbBuffer != 1) { if(sspi_w_token[0].cbBuffer != 1) {
failf(data, "Invalid SSPI encryption response length (%d).", failf(data, "Invalid SSPI encryption response length (%d).",
sspi_w_token[0].cbBuffer); sspi_w_token[0].cbBuffer);
@ -684,7 +688,7 @@ CURLcode Curl_SOCKS5_gssapi_negotiate(int sockindex,
/* For later use if encryption is required /* For later use if encryption is required
conn->socks5_gssapi_enctype = socksreq[0]; conn->socks5_gssapi_enctype = socksreq[0];
if (socksreq[0] != 0) if(socksreq[0] != 0)
conn->socks5_sspi_context = sspi_context; conn->socks5_sspi_context = sspi_context;
else { else {
s_pSecFn->DeleteSecurityContext(&sspi_context); s_pSecFn->DeleteSecurityContext(&sspi_context);

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1997 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1997 - 2011, 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
@ -48,7 +48,7 @@ struct Curl_tree *Curl_splay(struct timeval i,
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)
@ -98,7 +98,7 @@ struct Curl_tree *Curl_splayinsert(struct timeval i,
struct Curl_tree *t, struct Curl_tree *t,
struct Curl_tree *node) struct Curl_tree *node)
{ {
static struct timeval KEY_NOTUSED = {-1,-1}; /* key that will *NEVER* appear */ static struct timeval KEY_NOTUSED = {-1,-1}; /* will *NEVER* appear */
if(node == NULL) if(node == NULL)
return t; return t;
@ -268,7 +268,7 @@ int Curl_splayremovebyaddr(struct Curl_tree *t,
struct Curl_tree *removenode, struct Curl_tree *removenode,
struct Curl_tree **newroot) struct Curl_tree **newroot)
{ {
static struct timeval KEY_NOTUSED = {-1,-1}; /* key that will *NEVER* appear */ static struct timeval KEY_NOTUSED = {-1,-1}; /* will *NEVER* appear */
struct Curl_tree *x; struct Curl_tree *x;
if(!t || !removenode) if(!t || !removenode)
@ -342,7 +342,7 @@ void Curl_splayprint(struct Curl_tree * t, int d, char output)
return; return;
Curl_splayprint(t->larger, d+1, output); Curl_splayprint(t->larger, d+1, output);
for (i=0; i<d; i++) for(i=0; i<d; i++)
if(output) if(output)
fprintf(stderr, " "); fprintf(stderr, " ");
@ -350,7 +350,8 @@ void Curl_splayprint(struct Curl_tree * t, int d, char output)
#ifdef TEST_SPLAY #ifdef TEST_SPLAY
fprintf(stderr, "%ld[%d]", (long)t->key.tv_usec, i); fprintf(stderr, "%ld[%d]", (long)t->key.tv_usec, i);
#else #else
fprintf(stderr, "%ld.%ld[%d]", (long)t->key.tv_sec, (long)t->key.tv_usec, i); fprintf(stderr, "%ld.%ld[%d]", (long)t->key.tv_sec,
(long)t->key.tv_usec, i);
#endif #endif
} }
@ -391,7 +392,7 @@ int main(int argc, argv_item_t argv[])
int i; int i;
root = NULL; /* the empty tree */ root = NULL; /* the empty tree */
for (i = 0; i < MAX; i++) { for(i = 0; i < MAX; i++) {
struct timeval key; struct timeval key;
ptrs[i] = t = malloc(sizeof(struct Curl_tree)); ptrs[i] = t = malloc(sizeof(struct Curl_tree));
if(!t) { if(!t) {
@ -418,7 +419,7 @@ int main(int argc, argv_item_t argv[])
#endif #endif
#if 1 #if 1
for (i = 0; i < MAX; i++) { for(i = 0; i < MAX; i++) {
int rem = (i+7)%MAX; int rem = (i+7)%MAX;
struct Curl_tree *r; struct Curl_tree *r;
printf("Tree look:\n"); printf("Tree look:\n");

View File

@ -139,7 +139,7 @@ static CURLcode sftp_done(struct connectdata *conn,
CURLcode, bool premature); CURLcode, bool premature);
static CURLcode sftp_doing(struct connectdata *conn, static CURLcode sftp_doing(struct connectdata *conn,
bool *dophase_done); bool *dophase_done);
static CURLcode sftp_disconnect(struct connectdata *conn, bool dead_connection); static CURLcode sftp_disconnect(struct connectdata *conn, bool dead);
static static
CURLcode sftp_perform(struct connectdata *conn, CURLcode sftp_perform(struct connectdata *conn,
bool *connected, bool *connected,
@ -567,9 +567,8 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
/* The fingerprint points to static storage (!), don't free() it. */ /* The fingerprint points to static storage (!), don't free() it. */
infof(data, "Fingerprint: "); infof(data, "Fingerprint: ");
for (rc = 0; rc < 16; rc++) { for(rc = 0; rc < 16; rc++)
infof(data, "%02X ", (unsigned char) fingerprint[rc]); infof(data, "%02X ", (unsigned char) fingerprint[rc]);
}
infof(data, "\n"); infof(data, "\n");
#endif /* CURL_LIBSSH2_DEBUG */ #endif /* CURL_LIBSSH2_DEBUG */
@ -582,7 +581,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
char buf[33]; char buf[33];
host_public_key_md5 = libssh2_hostkey_hash(sshc->ssh_session, host_public_key_md5 = libssh2_hostkey_hash(sshc->ssh_session,
LIBSSH2_HOSTKEY_HASH_MD5); LIBSSH2_HOSTKEY_HASH_MD5);
for (i = 0; i < 16; i++) for(i = 0; i < 16; i++)
snprintf(&buf[i*2], 3, "%02x", snprintf(&buf[i*2], 3, "%02x",
(unsigned char) host_public_key_md5[i]); (unsigned char) host_public_key_md5[i]);
if(!strequal(buf, data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5])) { if(!strequal(buf, data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5])) {
@ -1490,7 +1489,7 @@ static CURLcode ssh_statemach_act(struct connectdata *conn, bool *block)
if(data->set.ftp_append) if(data->set.ftp_append)
/* Try to open for append, but create if nonexisting */ /* Try to open for append, but create if nonexisting */
flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_APPEND; flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_CREAT|LIBSSH2_FXF_APPEND;
else if (data->state.resume_from > 0) else if(data->state.resume_from > 0)
/* If we have restart position then open for append */ /* If we have restart position then open for append */
flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_APPEND; flags = LIBSSH2_FXF_WRITE|LIBSSH2_FXF_APPEND;
else else
@ -2521,12 +2520,10 @@ static CURLcode ssh_easy_statemach(struct connectdata *conn,
curl_socket_t sock = conn->sock[FIRSTSOCKET]; curl_socket_t sock = conn->sock[FIRSTSOCKET];
curl_socket_t fd_read = CURL_SOCKET_BAD; curl_socket_t fd_read = CURL_SOCKET_BAD;
curl_socket_t fd_write = CURL_SOCKET_BAD; curl_socket_t fd_write = CURL_SOCKET_BAD;
if (LIBSSH2_SESSION_BLOCK_INBOUND & dir) { if(LIBSSH2_SESSION_BLOCK_INBOUND & dir)
fd_read = sock; fd_read = sock;
} if(LIBSSH2_SESSION_BLOCK_OUTBOUND & dir)
if (LIBSSH2_SESSION_BLOCK_OUTBOUND & dir) {
fd_write = sock; fd_write = sock;
}
/* wait for the socket to become ready */ /* wait for the socket to become ready */
Curl_socket_ready(fd_read, fd_write, Curl_socket_ready(fd_read, fd_write,
(int)(left>1000?1000:left)); /* ignore result */ (int)(left>1000?1000:left)); /* ignore result */
@ -2594,7 +2591,8 @@ static CURLcode ssh_connect(struct connectdata *conn, bool *done)
if(conn->handler->protocol & CURLPROTO_SCP) { if(conn->handler->protocol & CURLPROTO_SCP) {
conn->recv[FIRSTSOCKET] = scp_recv; conn->recv[FIRSTSOCKET] = scp_recv;
conn->send[FIRSTSOCKET] = scp_send; conn->send[FIRSTSOCKET] = scp_send;
} else { }
else {
conn->recv[FIRSTSOCKET] = sftp_recv; conn->recv[FIRSTSOCKET] = sftp_recv;
conn->send[FIRSTSOCKET] = sftp_send; conn->send[FIRSTSOCKET] = sftp_send;
} }
@ -2850,7 +2848,7 @@ static ssize_t scp_recv(struct connectdata *conn, int sockindex,
libssh2_channel_read(conn->proto.sshc.ssh_channel, mem, len); libssh2_channel_read(conn->proto.sshc.ssh_channel, mem, len);
ssh_block2waitfor(conn, (nread == LIBSSH2_ERROR_EAGAIN)?TRUE:FALSE); ssh_block2waitfor(conn, (nread == LIBSSH2_ERROR_EAGAIN)?TRUE:FALSE);
if (nread == LIBSSH2_ERROR_EAGAIN) { if(nread == LIBSSH2_ERROR_EAGAIN) {
*err = CURLE_AGAIN; *err = CURLE_AGAIN;
nread = -1; nread = -1;
} }
@ -3041,7 +3039,7 @@ get_pathname(const char **cpp, char **path)
quot = *cp++; quot = *cp++;
/* Search for terminating quote, unescape some chars */ /* Search for terminating quote, unescape some chars */
for (i = j = 0; i <= strlen(cp); i++) { for(i = j = 0; i <= strlen(cp); i++) {
if(cp[i] == quot) { /* Found quote */ if(cp[i] == quot) { /* Found quote */
i++; i++;
(*path)[j] = '\0'; (*path)[j] = '\0';

View File

@ -294,7 +294,7 @@ void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
for(i=0; i< conn->data->set.ssl.numsessions; i++) { for(i=0; i< conn->data->set.ssl.numsessions; i++) {
struct curl_ssl_session *check = &conn->data->state.session[i]; struct curl_ssl_session *check = &conn->data->state.session[i];
if (check->sessionid == ssl_sessionid) { if(check->sessionid == ssl_sessionid) {
kill_session(check); kill_session(check);
break; break;
} }
@ -346,7 +346,7 @@ CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
store->sessionid = ssl_sessionid; store->sessionid = ssl_sessionid;
store->idsize = idsize; store->idsize = idsize;
store->age = data->state.sessionage; /* set current age */ store->age = data->state.sessionage; /* set current age */
if (store->name) if(store->name)
/* free it if there's one already present */ /* free it if there's one already present */
free(store->name); free(store->name);
store->name = clone_host; /* clone host name */ store->name = clone_host; /* clone host name */

View File

@ -378,22 +378,22 @@ int cert_stuff(struct connectdata *conn,
params.cert = NULL; params.cert = NULL;
/* Does the engine supports LOAD_CERT_CTRL ? */ /* Does the engine supports LOAD_CERT_CTRL ? */
if (!ENGINE_ctrl(data->state.engine, ENGINE_CTRL_GET_CMD_FROM_NAME, if(!ENGINE_ctrl(data->state.engine, ENGINE_CTRL_GET_CMD_FROM_NAME,
0, (void *)cmd_name, NULL)) { 0, (void *)cmd_name, NULL)) {
failf(data, "ssl engine does not support loading certificates"); failf(data, "ssl engine does not support loading certificates");
return 0; return 0;
} }
/* Load the certificate from the engine */ /* Load the certificate from the engine */
if (!ENGINE_ctrl_cmd(data->state.engine, cmd_name, if(!ENGINE_ctrl_cmd(data->state.engine, cmd_name,
0, &params, NULL, 1)) { 0, &params, NULL, 1)) {
failf(data, "ssl engine cannot load client cert with id" failf(data, "ssl engine cannot load client cert with id"
" '%s' [%s]", cert_file, " '%s' [%s]", cert_file,
ERR_error_string(ERR_get_error(), NULL)); ERR_error_string(ERR_get_error(), NULL));
return 0; return 0;
} }
if (!params.cert) { if(!params.cert) {
failf(data, "ssl engine didn't initialized the certificate " failf(data, "ssl engine didn't initialized the certificate "
"properly."); "properly.");
return 0; return 0;
@ -467,7 +467,7 @@ int cert_stuff(struct connectdata *conn,
return 0; return 0;
} }
if (!SSL_CTX_check_private_key (ctx)) { if(!SSL_CTX_check_private_key (ctx)) {
failf(data, "private key from PKCS12 file '%s' " failf(data, "private key from PKCS12 file '%s' "
"does not match certificate in same file", cert_file); "does not match certificate in same file", cert_file);
EVP_PKEY_free(pri); EVP_PKEY_free(pri);
@ -475,15 +475,15 @@ int cert_stuff(struct connectdata *conn,
return 0; return 0;
} }
/* Set Certificate Verification chain */ /* Set Certificate Verification chain */
if (ca && sk_X509_num(ca)) { if(ca && sk_X509_num(ca)) {
for (i = 0; i < sk_X509_num(ca); i++) { for(i = 0; i < sk_X509_num(ca); i++) {
if (!SSL_CTX_add_extra_chain_cert(ctx,sk_X509_value(ca, i))) { if(!SSL_CTX_add_extra_chain_cert(ctx,sk_X509_value(ca, i))) {
failf(data, "cannot add certificate to certificate chain"); failf(data, "cannot add certificate to certificate chain");
EVP_PKEY_free(pri); EVP_PKEY_free(pri);
X509_free(x509); X509_free(x509);
return 0; return 0;
} }
if (!SSL_CTX_add_client_CA(ctx, sk_X509_value(ca, i))) { if(!SSL_CTX_add_client_CA(ctx, sk_X509_value(ca, i))) {
failf(data, "cannot add certificate to client CA list"); failf(data, "cannot add certificate to client CA list");
EVP_PKEY_free(pri); EVP_PKEY_free(pri);
X509_free(x509); X509_free(x509);
@ -788,10 +788,12 @@ 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 {
failf(data, "set default crypto engine '%s' failed", ENGINE_get_id(data->state.engine)); failf(data, "set default crypto engine '%s' failed",
ENGINE_get_id(data->state.engine));
return CURLE_SSL_ENGINE_SETFAILED; return CURLE_SSL_ENGINE_SETFAILED;
} }
} }
@ -810,7 +812,7 @@ struct curl_slist *Curl_ossl_engines_list(struct SessionHandle *data)
struct curl_slist *beg = NULL; struct curl_slist *beg = NULL;
ENGINE *e; ENGINE *e;
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);
@ -998,7 +1000,7 @@ static int asn1_output(const ASN1_UTCTIME *tm,
return 1; return 1;
if(asn1_string[i-1] == 'Z') if(asn1_string[i-1] == 'Z')
gmt=TRUE; gmt=TRUE;
for (i=0; i<10; i++) for(i=0; i<10; i++)
if((asn1_string[i] > '9') || (asn1_string[i] < '0')) if((asn1_string[i] > '9') || (asn1_string[i] < '0'))
return 2; return 2;
@ -1145,7 +1147,7 @@ static CURLcode verifyhost(struct connectdata *conn,
numalts = sk_GENERAL_NAME_num(altnames); numalts = sk_GENERAL_NAME_num(altnames);
/* loop through all alternatives while none has matched */ /* loop through all alternatives while none has matched */
for (i=0; (i<numalts) && (matched != 1); i++) { for(i=0; (i<numalts) && (matched != 1); i++) {
/* get a handle to alternative name number i */ /* get a handle to alternative name number i */
const GENERAL_NAME *check = sk_GENERAL_NAME_value(altnames, i); const GENERAL_NAME *check = sk_GENERAL_NAME_value(altnames, i);
@ -1439,10 +1441,11 @@ ossl_connect_step1(struct connectdata *conn,
default: default:
case CURL_SSLVERSION_DEFAULT: case CURL_SSLVERSION_DEFAULT:
#ifdef USE_TLS_SRP #ifdef USE_TLS_SRP
if (data->set.ssl.authtype == CURL_TLSAUTH_SRP) { if(data->set.ssl.authtype == CURL_TLSAUTH_SRP) {
infof(data, "Set version TLSv1 for SRP authorisation\n"); infof(data, "Set version TLSv1 for SRP authorisation\n");
req_method = TLSv1_client_method() ; req_method = TLSv1_client_method() ;
} else }
else
#endif #endif
/* we try to figure out version */ /* we try to figure out version */
req_method = SSLv23_client_method(); req_method = SSLv23_client_method();
@ -1458,7 +1461,7 @@ ossl_connect_step1(struct connectdata *conn,
return CURLE_NOT_BUILT_IN; return CURLE_NOT_BUILT_IN;
#else #else
#ifdef USE_TLS_SRP #ifdef USE_TLS_SRP
if (data->set.ssl.authtype == CURL_TLSAUTH_SRP) if(data->set.ssl.authtype == CURL_TLSAUTH_SRP)
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
#endif #endif
req_method = SSLv2_client_method(); req_method = SSLv2_client_method();
@ -1467,7 +1470,7 @@ ossl_connect_step1(struct connectdata *conn,
#endif #endif
case CURL_SSLVERSION_SSLv3: case CURL_SSLVERSION_SSLv3:
#ifdef USE_TLS_SRP #ifdef USE_TLS_SRP
if (data->set.ssl.authtype == CURL_TLSAUTH_SRP) if(data->set.ssl.authtype == CURL_TLSAUTH_SRP)
return CURLE_SSL_CONNECT_ERROR; return CURLE_SSL_CONNECT_ERROR;
#endif #endif
req_method = SSLv3_client_method(); req_method = SSLv3_client_method();
@ -1568,11 +1571,11 @@ ossl_connect_step1(struct connectdata *conn,
if(data->set.ssl.authtype == CURL_TLSAUTH_SRP) { if(data->set.ssl.authtype == CURL_TLSAUTH_SRP) {
infof(data, "Using TLS-SRP username: %s\n", data->set.ssl.username); infof(data, "Using TLS-SRP username: %s\n", data->set.ssl.username);
if (!SSL_CTX_set_srp_username(connssl->ctx, data->set.ssl.username)) { if(!SSL_CTX_set_srp_username(connssl->ctx, data->set.ssl.username)) {
failf(data, "Unable to set SRP user name"); failf(data, "Unable to set SRP user name");
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
} }
if (!SSL_CTX_set_srp_password(connssl->ctx,data->set.ssl.password)) { if(!SSL_CTX_set_srp_password(connssl->ctx,data->set.ssl.password)) {
failf(data, "failed setting SRP password"); failf(data, "failed setting SRP password");
return CURLE_BAD_FUNCTION_ARGUMENT; return CURLE_BAD_FUNCTION_ARGUMENT;
} }
@ -1622,13 +1625,13 @@ ossl_connect_step1(struct connectdata *conn,
"none"); "none");
} }
if (data->set.str[STRING_SSL_CRLFILE]) { if(data->set.str[STRING_SSL_CRLFILE]) {
/* tell SSL where to find CRL file that is used to check certificate /* tell SSL where to find CRL file that is used to check certificate
* revocation */ * revocation */
lookup=X509_STORE_add_lookup(connssl->ctx->cert_store,X509_LOOKUP_file()); lookup=X509_STORE_add_lookup(connssl->ctx->cert_store,X509_LOOKUP_file());
if ( !lookup || if(!lookup ||
(!X509_load_crl_file(lookup,data->set.str[STRING_SSL_CRLFILE], (!X509_load_crl_file(lookup,data->set.str[STRING_SSL_CRLFILE],
X509_FILETYPE_PEM)) ) { X509_FILETYPE_PEM)) ) {
failf(data,"error loading CRL file: %s\n", failf(data,"error loading CRL file: %s\n",
data->set.str[STRING_SSL_CRLFILE]); data->set.str[STRING_SSL_CRLFILE]);
return CURLE_SSL_CRL_BADFILE; return CURLE_SSL_CRL_BADFILE;
@ -1675,12 +1678,12 @@ ossl_connect_step1(struct connectdata *conn,
connssl->server_cert = 0x0; connssl->server_cert = 0x0;
#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
if ((0 == Curl_inet_pton(AF_INET, conn->host.name, &addr)) && if((0 == Curl_inet_pton(AF_INET, conn->host.name, &addr)) &&
#ifdef ENABLE_IPV6 #ifdef ENABLE_IPV6
(0 == Curl_inet_pton(AF_INET6, conn->host.name, &addr)) && (0 == Curl_inet_pton(AF_INET6, conn->host.name, &addr)) &&
#endif #endif
sni && sni &&
!SSL_set_tlsext_host_name(connssl->handle, conn->host.name)) !SSL_set_tlsext_host_name(connssl->handle, conn->host.name))
infof(data, "WARNING: failed to configure server name indication (SNI) " infof(data, "WARNING: failed to configure server name indication (SNI) "
"TLS extension\n"); "TLS extension\n");
#endif #endif
@ -1699,9 +1702,9 @@ 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, (int)sockfd)) { if(!SSL_set_fd(connssl->handle, (int)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;
} }
connssl->connecting_state = ssl_connect_2; connssl->connecting_state = ssl_connect_2;
@ -1903,15 +1906,15 @@ static void pubkey_show(struct SessionHandle *data,
#define print_pubkey_BN(_type, _name, _num) \ #define print_pubkey_BN(_type, _name, _num) \
do { \ do { \
if (pubkey->pkey._type->_name != NULL) { \ if(pubkey->pkey._type->_name != NULL) { \
int len = BN_num_bytes(pubkey->pkey._type->_name); \ int len = BN_num_bytes(pubkey->pkey._type->_name); \
if(len < CERTBUFFERSIZE) { \ if(len < CERTBUFFERSIZE) { \
BN_bn2bin(pubkey->pkey._type->_name, (unsigned char*)bufp); \ BN_bn2bin(pubkey->pkey._type->_name, (unsigned char*)bufp); \
bufp[len] = 0; \ bufp[len] = 0; \
pubkey_show(data, _num, #_type, #_name, (unsigned char*)bufp, len); \ pubkey_show(data, _num, #_type, #_name, (unsigned char*)bufp, len); \
} \ } \
} \ } \
} while (0) } while(0)
static int X509V3_ext(struct SessionHandle *data, static int X509V3_ext(struct SessionHandle *data,
int certnum, int certnum,
@ -1924,7 +1927,7 @@ static int X509V3_ext(struct SessionHandle *data,
/* no extensions, bail out */ /* no extensions, bail out */
return 1; return 1;
for (i=0; i<sk_X509_EXTENSION_num(exts); i++) { for(i=0; i<sk_X509_EXTENSION_num(exts); i++) {
ASN1_OBJECT *obj; ASN1_OBJECT *obj;
X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i); X509_EXTENSION *ext = sk_X509_EXTENSION_value(exts, i);
BUF_MEM *biomem; BUF_MEM *biomem;
@ -1960,7 +1963,8 @@ static int X509V3_ext(struct SessionHandle *data,
while((biomem->data[j] == ' ') && (j<(size_t)biomem->length)) while((biomem->data[j] == ' ') && (j<(size_t)biomem->length))
j++; j++;
if(j<(size_t)biomem->length) if(j<(size_t)biomem->length)
ptr+=snprintf(ptr, sizeof(buf)-(ptr-buf), "%s%c", sep, biomem->data[j]); ptr+=snprintf(ptr, sizeof(buf)-(ptr-buf), "%s%c", sep,
biomem->data[j]);
} }
infof(data, " %s\n", buf); infof(data, " %s\n", buf);
@ -1980,7 +1984,7 @@ static void X509_signature(struct SessionHandle *data,
char buf[1024]; char buf[1024];
char *ptr = buf; char *ptr = buf;
int i; int i;
for (i=0; i<sig->length; i++) for(i=0; i<sig->length; i++)
ptr+=snprintf(ptr, sizeof(buf)-(ptr-buf), "%02x:", sig->data[i]); ptr+=snprintf(ptr, sizeof(buf)-(ptr-buf), "%02x:", sig->data[i]);
infof(data, " Signature: %s\n", buf); infof(data, " Signature: %s\n", buf);
@ -2058,7 +2062,7 @@ static CURLcode get_cert_chain(struct connectdata *conn,
} }
infof(data, "--- Certificate chain\n"); infof(data, "--- Certificate chain\n");
for (i=0; i<numcerts; i++) { for(i=0; i<numcerts; i++) {
long value; long value;
ASN1_INTEGER *num; ASN1_INTEGER *num;
ASN1_TIME *certdate; ASN1_TIME *certdate;
@ -2089,7 +2093,7 @@ static CURLcode get_cert_chain(struct connectdata *conn,
push_certinfo(data, i, "Version", bufp); /* hex */ push_certinfo(data, i, "Version", bufp); /* hex */
num=X509_get_serialNumber(x); num=X509_get_serialNumber(x);
if (num->length <= 4) { if(num->length <= 4) {
value = ASN1_INTEGER_get(num); value = ASN1_INTEGER_get(num);
infof(data," Serial Number: %ld (0x%lx)\n", value, value); infof(data," Serial Number: %ld (0x%lx)\n", value, value);
snprintf(bufp, CERTBUFFERSIZE, "%lx", value); snprintf(bufp, CERTBUFFERSIZE, "%lx", value);
@ -2102,7 +2106,7 @@ static CURLcode get_cert_chain(struct connectdata *conn,
if(num->type == V_ASN1_NEG_INTEGER) if(num->type == V_ASN1_NEG_INTEGER)
*ptr++='-'; *ptr++='-';
for (j=0; (j<num->length) && (left>=4); j++) { for(j=0; (j<num->length) && (left>=4); j++) {
/* TODO: length restrictions */ /* TODO: length restrictions */
snprintf(ptr, 3, "%02x%c",num->data[j], snprintf(ptr, 3, "%02x%c",num->data[j],
((j+1 == num->length)?'\n':':')); ((j+1 == num->length)?'\n':':'));
@ -2272,9 +2276,10 @@ static CURLcode servercert(struct connectdata *conn,
deallocating the certificate. */ deallocating the certificate. */
/* e.g. match issuer name with provided issuer certificate */ /* e.g. match issuer name with provided issuer certificate */
if (data->set.str[STRING_SSL_ISSUERCERT]) { if(data->set.str[STRING_SSL_ISSUERCERT]) {
if (! (fp=fopen(data->set.str[STRING_SSL_ISSUERCERT],"r"))) { fp=fopen(data->set.str[STRING_SSL_ISSUERCERT],"r");
if (strict) if(!fp) {
if(strict)
failf(data, "SSL: Unable to open issuer cert (%s)\n", failf(data, "SSL: Unable to open issuer cert (%s)\n",
data->set.str[STRING_SSL_ISSUERCERT]); data->set.str[STRING_SSL_ISSUERCERT]);
X509_free(connssl->server_cert); X509_free(connssl->server_cert);
@ -2282,8 +2287,8 @@ static CURLcode servercert(struct connectdata *conn,
return CURLE_SSL_ISSUER_ERROR; return CURLE_SSL_ISSUER_ERROR;
} }
issuer = PEM_read_X509(fp,NULL,ZERO_NULL,NULL); issuer = PEM_read_X509(fp,NULL,ZERO_NULL,NULL);
if (!issuer) { if(!issuer) {
if (strict) if(strict)
failf(data, "SSL: Unable to read issuer cert (%s)\n", failf(data, "SSL: Unable to read issuer cert (%s)\n",
data->set.str[STRING_SSL_ISSUERCERT]); data->set.str[STRING_SSL_ISSUERCERT]);
X509_free(connssl->server_cert); X509_free(connssl->server_cert);
@ -2292,8 +2297,8 @@ static CURLcode servercert(struct connectdata *conn,
return CURLE_SSL_ISSUER_ERROR; return CURLE_SSL_ISSUER_ERROR;
} }
fclose(fp); fclose(fp);
if (X509_check_issued(issuer,connssl->server_cert) != X509_V_OK) { if(X509_check_issued(issuer,connssl->server_cert) != X509_V_OK) {
if (strict) if(strict)
failf(data, "SSL: Certificate issuer check failed (%s)\n", failf(data, "SSL: Certificate issuer check failed (%s)\n",
data->set.str[STRING_SSL_ISSUERCERT]); data->set.str[STRING_SSL_ISSUERCERT]);
X509_free(connssl->server_cert); X509_free(connssl->server_cert);
@ -2368,14 +2373,14 @@ ossl_connect_step3(struct connectdata *conn,
#endif #endif
incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL)); incache = !(Curl_ssl_getsessionid(conn, &old_ssl_sessionid, NULL));
if (incache) { if(incache) {
if (old_ssl_sessionid != our_ssl_sessionid) { if(old_ssl_sessionid != our_ssl_sessionid) {
infof(data, "old SSL session ID is stale, removing\n"); infof(data, "old SSL session ID is stale, removing\n");
Curl_ssl_delsessionid(conn, old_ssl_sessionid); Curl_ssl_delsessionid(conn, old_ssl_sessionid);
incache = FALSE; incache = FALSE;
} }
} }
if (!incache) { if(!incache) {
retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid, retcode = Curl_ssl_addsessionid(conn, our_ssl_sessionid,
0 /* unknown size */); 0 /* unknown size */);
if(retcode) { if(retcode) {

View File

@ -29,7 +29,7 @@
(defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \ (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
(defined(HAVE_GLIBC_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \ (defined(HAVE_GLIBC_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
(defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)) (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
# error "strerror_r MUST be either POSIX-style, glibc-style or vxworks-style" # error "strerror_r MUST be either POSIX, glibc or vxworks-style"
# endif # endif
#endif #endif
@ -205,7 +205,8 @@ curl_easy_strerror(CURLcode error)
return "Couldn't use specified SSL cipher"; return "Couldn't use specified SSL cipher";
case CURLE_SSL_CACERT: case CURLE_SSL_CACERT:
return "Peer certificate cannot be authenticated with known CA certificates"; return "Peer certificate cannot be authenticated with given CA "
"certificates";
case CURLE_SSL_CACERT_BADFILE: case CURLE_SSL_CACERT_BADFILE:
return "Problem with the SSL CA cert (path? access rights?)"; return "Problem with the SSL CA cert (path? access rights?)";

View File

@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -110,9 +110,9 @@ curlx_strtoll(const char *nptr, char **endptr, int base)
/* Loop handling digits. */ /* Loop handling digits. */
value = 0; value = 0;
overflow = 0; overflow = 0;
for (i = get_char(end[0], base); for(i = get_char(end[0], 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. */

View File

@ -271,8 +271,7 @@ static void negotiate(struct connectdata *conn)
int i; int i;
struct TELNET *tn = (struct TELNET *) conn->data->state.proto.telnet; struct TELNET *tn = (struct TELNET *) conn->data->state.proto.telnet;
for(i = 0;i < CURL_NTELOPTS;i++) for(i = 0;i < CURL_NTELOPTS;i++) {
{
if(tn->us_preferred[i] == CURL_YES) if(tn->us_preferred[i] == CURL_YES)
set_local_option(conn, i, CURL_YES); set_local_option(conn, i, CURL_YES);
@ -288,21 +287,17 @@ 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);
} }
else else {
{
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)
@ -346,80 +341,72 @@ static
void set_remote_option(struct connectdata *conn, int option, int newstate) void set_remote_option(struct connectdata *conn, int option, int newstate)
{ {
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet; struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
if(newstate == CURL_YES) if(newstate == CURL_YES) {
{ switch(tn->him[option]) {
switch(tn->him[option]) case CURL_NO:
{ tn->him[option] = CURL_WANTYES;
case CURL_NO: send_negotiation(conn, CURL_DO, option);
tn->him[option] = CURL_WANTYES; break;
send_negotiation(conn, CURL_DO, option);
break;
case CURL_YES: case CURL_YES:
/* Already enabled */ /* Already enabled */
break; break;
case CURL_WANTNO: case CURL_WANTNO:
switch(tn->himq[option]) switch(tn->himq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Already negotiating for CURL_YES, queue the request */
/* Already negotiating for CURL_YES, queue the request */ tn->himq[option] = CURL_OPPOSITE;
tn->himq[option] = CURL_OPPOSITE;
break;
case CURL_OPPOSITE:
/* Error: already queued an enable request */
break;
}
break; break;
case CURL_OPPOSITE:
/* Error: already queued an enable request */
break;
}
break;
case CURL_WANTYES: case CURL_WANTYES:
switch(tn->himq[option]) switch(tn->himq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Error: already negotiating for enable */
/* Error: already negotiating for enable */
break;
case CURL_OPPOSITE:
tn->himq[option] = CURL_EMPTY;
break;
}
break; break;
case CURL_OPPOSITE:
tn->himq[option] = CURL_EMPTY;
break;
}
break;
} }
} }
else /* NO */ else { /* NO */
{ switch(tn->him[option]) {
switch(tn->him[option]) case CURL_NO:
{ /* Already disabled */
case CURL_NO: break;
/* Already disabled */
break;
case CURL_YES: case CURL_YES:
tn->him[option] = CURL_WANTNO; tn->him[option] = CURL_WANTNO;
send_negotiation(conn, CURL_DONT, option); send_negotiation(conn, CURL_DONT, option);
break; break;
case CURL_WANTNO: case CURL_WANTNO:
switch(tn->himq[option]) switch(tn->himq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Already negotiating for NO */
/* Already negotiating for NO */
break;
case CURL_OPPOSITE:
tn->himq[option] = CURL_EMPTY;
break;
}
break; break;
case CURL_OPPOSITE:
tn->himq[option] = CURL_EMPTY;
break;
}
break;
case CURL_WANTYES: case CURL_WANTYES:
switch(tn->himq[option]) switch(tn->himq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: tn->himq[option] = CURL_OPPOSITE;
tn->himq[option] = CURL_OPPOSITE;
break;
case CURL_OPPOSITE:
break;
}
break; break;
case CURL_OPPOSITE:
break;
}
break;
} }
} }
} }
@ -428,52 +415,47 @@ static
void rec_will(struct connectdata *conn, int option) void rec_will(struct connectdata *conn, int option)
{ {
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet; struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
switch(tn->him[option]) switch(tn->him[option]) {
{ case CURL_NO:
case CURL_NO: if(tn->him_preferred[option] == CURL_YES) {
if(tn->him_preferred[option] == CURL_YES) tn->him[option] = CURL_YES;
{ send_negotiation(conn, CURL_DO, option);
tn->him[option] = CURL_YES; }
send_negotiation(conn, CURL_DO, option); else
} send_negotiation(conn, CURL_DONT, option);
else
{
send_negotiation(conn, CURL_DONT, option);
}
break;
case CURL_YES: break;
/* Already enabled */
break;
case CURL_WANTNO: case CURL_YES:
switch(tn->himq[option]) /* Already enabled */
{ break;
case CURL_EMPTY:
/* Error: DONT answered by WILL */
tn->him[option] = CURL_NO;
break;
case CURL_OPPOSITE:
/* Error: DONT answered by WILL */
tn->him[option] = CURL_YES;
tn->himq[option] = CURL_EMPTY;
break;
}
break;
case CURL_WANTYES: case CURL_WANTNO:
switch(tn->himq[option]) switch(tn->himq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Error: DONT answered by WILL */
tn->him[option] = CURL_YES; tn->him[option] = CURL_NO;
break;
case CURL_OPPOSITE:
tn->him[option] = CURL_WANTNO;
tn->himq[option] = CURL_EMPTY;
send_negotiation(conn, CURL_DONT, option);
break;
}
break; break;
case CURL_OPPOSITE:
/* Error: DONT answered by WILL */
tn->him[option] = CURL_YES;
tn->himq[option] = CURL_EMPTY;
break;
}
break;
case CURL_WANTYES:
switch(tn->himq[option]) {
case CURL_EMPTY:
tn->him[option] = CURL_YES;
break;
case CURL_OPPOSITE:
tn->him[option] = CURL_WANTNO;
tn->himq[option] = CURL_EMPTY;
send_negotiation(conn, CURL_DONT, option);
break;
}
break;
} }
} }
@ -481,44 +463,41 @@ static
void rec_wont(struct connectdata *conn, int option) void rec_wont(struct connectdata *conn, int option)
{ {
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet; struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
switch(tn->him[option]) switch(tn->him[option]) {
{ case CURL_NO:
case CURL_NO: /* Already disabled */
/* Already disabled */ break;
break;
case CURL_YES: case CURL_YES:
tn->him[option] = CURL_NO;
send_negotiation(conn, CURL_DONT, option);
break;
case CURL_WANTNO:
switch(tn->himq[option]) {
case CURL_EMPTY:
tn->him[option] = CURL_NO; tn->him[option] = CURL_NO;
send_negotiation(conn, CURL_DONT, option);
break; break;
case CURL_WANTNO: case CURL_OPPOSITE:
switch(tn->himq[option]) tn->him[option] = CURL_WANTYES;
{ tn->himq[option] = CURL_EMPTY;
case CURL_EMPTY: send_negotiation(conn, CURL_DO, option);
tn->him[option] = CURL_NO;
break;
case CURL_OPPOSITE:
tn->him[option] = CURL_WANTYES;
tn->himq[option] = CURL_EMPTY;
send_negotiation(conn, CURL_DO, option);
break;
}
break; break;
}
break;
case CURL_WANTYES: case CURL_WANTYES:
switch(tn->himq[option]) switch(tn->himq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: tn->him[option] = CURL_NO;
tn->him[option] = CURL_NO;
break;
case CURL_OPPOSITE:
tn->him[option] = CURL_NO;
tn->himq[option] = CURL_EMPTY;
break;
}
break; break;
case CURL_OPPOSITE:
tn->him[option] = CURL_NO;
tn->himq[option] = CURL_EMPTY;
break;
}
break;
} }
} }
@ -526,80 +505,72 @@ static void
set_local_option(struct connectdata *conn, int option, int newstate) set_local_option(struct connectdata *conn, int option, int newstate)
{ {
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet; struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
if(newstate == CURL_YES) if(newstate == CURL_YES) {
{ switch(tn->us[option]) {
switch(tn->us[option]) case CURL_NO:
{ tn->us[option] = CURL_WANTYES;
case CURL_NO: send_negotiation(conn, CURL_WILL, option);
tn->us[option] = CURL_WANTYES; break;
send_negotiation(conn, CURL_WILL, option);
break;
case CURL_YES: case CURL_YES:
/* Already enabled */ /* Already enabled */
break; break;
case CURL_WANTNO: case CURL_WANTNO:
switch(tn->usq[option]) switch(tn->usq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Already negotiating for CURL_YES, queue the request */
/* Already negotiating for CURL_YES, queue the request */ tn->usq[option] = CURL_OPPOSITE;
tn->usq[option] = CURL_OPPOSITE;
break;
case CURL_OPPOSITE:
/* Error: already queued an enable request */
break;
}
break; break;
case CURL_OPPOSITE:
/* Error: already queued an enable request */
break;
}
break;
case CURL_WANTYES: case CURL_WANTYES:
switch(tn->usq[option]) switch(tn->usq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Error: already negotiating for enable */
/* Error: already negotiating for enable */
break;
case CURL_OPPOSITE:
tn->usq[option] = CURL_EMPTY;
break;
}
break; break;
case CURL_OPPOSITE:
tn->usq[option] = CURL_EMPTY;
break;
}
break;
} }
} }
else /* NO */ else { /* NO */
{ switch(tn->us[option]) {
switch(tn->us[option]) case CURL_NO:
{ /* Already disabled */
case CURL_NO: break;
/* Already disabled */
break;
case CURL_YES: case CURL_YES:
tn->us[option] = CURL_WANTNO; tn->us[option] = CURL_WANTNO;
send_negotiation(conn, CURL_WONT, option); send_negotiation(conn, CURL_WONT, option);
break; break;
case CURL_WANTNO: case CURL_WANTNO:
switch(tn->usq[option]) switch(tn->usq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Already negotiating for NO */
/* Already negotiating for NO */
break;
case CURL_OPPOSITE:
tn->usq[option] = CURL_EMPTY;
break;
}
break; break;
case CURL_OPPOSITE:
tn->usq[option] = CURL_EMPTY;
break;
}
break;
case CURL_WANTYES: case CURL_WANTYES:
switch(tn->usq[option]) switch(tn->usq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: tn->usq[option] = CURL_OPPOSITE;
tn->usq[option] = CURL_OPPOSITE;
break;
case CURL_OPPOSITE:
break;
}
break; break;
case CURL_OPPOSITE:
break;
}
break;
} }
} }
} }
@ -608,52 +579,46 @@ static
void rec_do(struct connectdata *conn, int option) void rec_do(struct connectdata *conn, int option)
{ {
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet; struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
switch(tn->us[option]) switch(tn->us[option]) {
{ case CURL_NO:
case CURL_NO: if(tn->us_preferred[option] == CURL_YES) {
if(tn->us_preferred[option] == CURL_YES) tn->us[option] = CURL_YES;
{ send_negotiation(conn, CURL_WILL, option);
tn->us[option] = CURL_YES; }
send_negotiation(conn, CURL_WILL, option); else
} send_negotiation(conn, CURL_WONT, option);
else break;
{
send_negotiation(conn, CURL_WONT, option);
}
break;
case CURL_YES: case CURL_YES:
/* Already enabled */ /* Already enabled */
break; break;
case CURL_WANTNO: case CURL_WANTNO:
switch(tn->usq[option]) switch(tn->usq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: /* Error: DONT answered by WILL */
/* Error: DONT answered by WILL */ tn->us[option] = CURL_NO;
tn->us[option] = CURL_NO;
break;
case CURL_OPPOSITE:
/* Error: DONT answered by WILL */
tn->us[option] = CURL_YES;
tn->usq[option] = CURL_EMPTY;
break;
}
break; break;
case CURL_OPPOSITE:
/* Error: DONT answered by WILL */
tn->us[option] = CURL_YES;
tn->usq[option] = CURL_EMPTY;
break;
}
break;
case CURL_WANTYES: case CURL_WANTYES:
switch(tn->usq[option]) switch(tn->usq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: tn->us[option] = CURL_YES;
tn->us[option] = CURL_YES;
break;
case CURL_OPPOSITE:
tn->us[option] = CURL_WANTNO;
tn->himq[option] = CURL_EMPTY;
send_negotiation(conn, CURL_WONT, option);
break;
}
break; break;
case CURL_OPPOSITE:
tn->us[option] = CURL_WANTNO;
tn->himq[option] = CURL_EMPTY;
send_negotiation(conn, CURL_WONT, option);
break;
}
break;
} }
} }
@ -661,44 +626,41 @@ static
void rec_dont(struct connectdata *conn, int option) void rec_dont(struct connectdata *conn, int option)
{ {
struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet; struct TELNET *tn = (struct TELNET *)conn->data->state.proto.telnet;
switch(tn->us[option]) switch(tn->us[option]) {
{ case CURL_NO:
case CURL_NO: /* Already disabled */
/* Already disabled */ break;
break;
case CURL_YES: case CURL_YES:
tn->us[option] = CURL_NO;
send_negotiation(conn, CURL_WONT, option);
break;
case CURL_WANTNO:
switch(tn->usq[option]) {
case CURL_EMPTY:
tn->us[option] = CURL_NO; tn->us[option] = CURL_NO;
send_negotiation(conn, CURL_WONT, option);
break; break;
case CURL_WANTNO: case CURL_OPPOSITE:
switch(tn->usq[option]) tn->us[option] = CURL_WANTYES;
{ tn->usq[option] = CURL_EMPTY;
case CURL_EMPTY: send_negotiation(conn, CURL_WILL, option);
tn->us[option] = CURL_NO;
break;
case CURL_OPPOSITE:
tn->us[option] = CURL_WANTYES;
tn->usq[option] = CURL_EMPTY;
send_negotiation(conn, CURL_WILL, option);
break;
}
break; break;
}
break;
case CURL_WANTYES: case CURL_WANTYES:
switch(tn->usq[option]) switch(tn->usq[option]) {
{ case CURL_EMPTY:
case CURL_EMPTY: tn->us[option] = CURL_NO;
tn->us[option] = CURL_NO;
break;
case CURL_OPPOSITE:
tn->us[option] = CURL_NO;
tn->usq[option] = CURL_EMPTY;
break;
}
break; break;
case CURL_OPPOSITE:
tn->us[option] = CURL_NO;
tn->usq[option] = CURL_EMPTY;
break;
}
break;
} }
} }
@ -710,20 +672,16 @@ 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));
@ -742,8 +700,7 @@ 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;
} }
@ -803,15 +760,13 @@ static void printsub(struct SessionHandle *data,
} }
break; break;
default: default:
for (i = 2; i < length; i++) for(i = 2; i < length; i++)
infof(data, " %.2x", pointer[i]); infof(data, " %.2x", pointer[i]);
break; break;
} }
if(direction) if(direction)
{
infof(data, "\n"); infof(data, "\n");
}
} }
} }
@ -826,8 +781,7 @@ static CURLcode check_telnet_options(struct connectdata *conn)
/* Add the user name as an environment variable if it /* Add the user name as an environment variable if it
was given on the command line */ was given on the command line */
if(conn->bits.user_passwd) if(conn->bits.user_passwd) {
{
snprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user); snprintf(option_arg, sizeof(option_arg), "USER,%s", conn->user);
tn->telnet_vars = curl_slist_append(tn->telnet_vars, option_arg); tn->telnet_vars = curl_slist_append(tn->telnet_vars, option_arg);
@ -866,7 +820,8 @@ static CURLcode check_telnet_options(struct connectdata *conn)
failf(data, "Unknown telnet option %s", head->data); failf(data, "Unknown telnet option %s", head->data);
return CURLE_UNKNOWN_TELNET_OPTION; return CURLE_UNKNOWN_TELNET_OPTION;
} else { }
else {
failf(data, "Syntax error in telnet option: %s", head->data); failf(data, "Syntax error in telnet option: %s", head->data);
return CURLE_TELNET_OPTION_SYNTAX; return CURLE_TELNET_OPTION_SYNTAX;
} }
@ -981,69 +936,61 @@ CURLcode telrcv(struct connectdata *conn,
#define bufferflush() startskipping() #define bufferflush() startskipping()
while(count--) while(count--) {
{
c = inbuf[in]; c = inbuf[in];
/*infof(data,"In rcv state %d char %d\n", tn->telrcv_state, c);*/ switch (tn->telrcv_state) {
switch (tn->telrcv_state) case CURL_TS_CR:
{ tn->telrcv_state = CURL_TS_DATA;
case CURL_TS_CR: if(c == '\0') {
tn->telrcv_state = CURL_TS_DATA; startskipping();
if(c == '\0') break; /* Ignore \0 after CR */
{ }
startskipping(); writebyte();
break; /* Ignore \0 after CR */ break;
}
writebyte();
break;
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; startskipping();
startskipping();
break;
}
else if(c == '\r')
{
tn->telrcv_state = CURL_TS_CR;
}
writebyte();
break; break;
}
else if(c == '\r')
tn->telrcv_state = CURL_TS_CR;
writebyte();
break;
case CURL_TS_IAC: case CURL_TS_IAC:
process_iac: process_iac:
DEBUGASSERT(startwrite < 0); DEBUGASSERT(startwrite < 0);
switch (c) switch (c) {
{ case CURL_WILL:
case CURL_WILL: tn->telrcv_state = CURL_TS_WILL;
tn->telrcv_state = CURL_TS_WILL; break;
break; case CURL_WONT:
case CURL_WONT: tn->telrcv_state = CURL_TS_WONT;
tn->telrcv_state = CURL_TS_WONT; break;
break; case CURL_DO:
case CURL_DO: tn->telrcv_state = CURL_TS_DO;
tn->telrcv_state = CURL_TS_DO; break;
break; case CURL_DONT:
case CURL_DONT: tn->telrcv_state = CURL_TS_DONT;
tn->telrcv_state = CURL_TS_DONT; break;
break; case CURL_SB:
case CURL_SB: CURL_SB_CLEAR(tn);
CURL_SB_CLEAR(tn); tn->telrcv_state = CURL_TS_SB;
tn->telrcv_state = CURL_TS_SB; break;
break; case CURL_IAC:
case CURL_IAC: tn->telrcv_state = CURL_TS_DATA;
tn->telrcv_state = CURL_TS_DATA; writebyte();
writebyte(); break;
break; case CURL_DM:
case CURL_DM: case CURL_NOP:
case CURL_NOP: case CURL_GA:
case CURL_GA: default:
default: tn->telrcv_state = CURL_TS_DATA;
tn->telrcv_state = CURL_TS_DATA; printoption(data, "RCVD", CURL_IAC, c);
printoption(data, "RCVD", CURL_IAC, c); break;
break;
} }
break; break;
@ -1077,20 +1024,14 @@ CURLcode telrcv(struct connectdata *conn,
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;
}
else else
{
CURL_SB_ACCUM(tn,c); CURL_SB_ACCUM(tn,c);
}
break; break;
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".
* Several things may have happened. An IAC was not doubled, the * Several things may have happened. An IAC was not doubled, the
@ -1165,7 +1106,7 @@ static CURLcode send_telnet_data(struct connectdata *conn,
break; break;
} }
/* handle partial write */ /* handle partial write */
} while (rc == CURLE_OK && total_written < out_count); } while(rc == CURLE_OK && total_written < out_count);
} }
return rc; return rc;
} }
@ -1304,7 +1245,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
objs[1] = stdin_handle; objs[1] = stdin_handle;
/* Tell winsock what events we want to listen to */ /* Tell winsock what events we want to listen to */
if(event_select_func(sockfd, event_handle, FD_READ|FD_CLOSE) == SOCKET_ERROR) { if(event_select_func(sockfd, event_handle, FD_READ|FD_CLOSE) ==
SOCKET_ERROR) {
close_event_func(event_handle); close_event_func(event_handle);
FreeLibrary(wsock2); FreeLibrary(wsock2);
return CURLE_OK; return CURLE_OK;
@ -1317,7 +1259,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
obj_count = 1; obj_count = 1;
/* Check stdin_handle per 100 milliseconds */ /* Check stdin_handle per 100 milliseconds */
wait_timeout = 100; wait_timeout = 100;
} else { }
else {
obj_count = 2; obj_count = 2;
wait_timeout = 1000; wait_timeout = 1000;
} }
@ -1448,7 +1391,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
pfd[0].fd = sockfd; pfd[0].fd = sockfd;
pfd[0].events = POLLIN; pfd[0].events = POLLIN;
if (data->set.is_fread_set) { if(data->set.is_fread_set) {
poll_cnt = 1; poll_cnt = 1;
interval_ms = 100; /* poll user-supplied read function */ interval_ms = 100; /* poll user-supplied read function */
} }
@ -1505,7 +1448,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
} }
nread = 0; nread = 0;
if (poll_cnt == 2) { if(poll_cnt == 2) {
if(pfd[1].revents & POLLIN) { /* read from stdin */ if(pfd[1].revents & POLLIN) { /* read from stdin */
nread = read(0, buf, BUFSIZE - 1); nread = read(0, buf, BUFSIZE - 1);
} }
@ -1513,15 +1456,15 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
else { else {
/* read from user-supplied method */ /* read from user-supplied method */
nread = (int)conn->fread_func(buf, 1, BUFSIZE - 1, conn->fread_in); nread = (int)conn->fread_func(buf, 1, BUFSIZE - 1, conn->fread_in);
if (nread == CURL_READFUNC_ABORT) { if(nread == CURL_READFUNC_ABORT) {
keepon = FALSE; keepon = FALSE;
break; break;
} }
if (nread == CURL_READFUNC_PAUSE) if(nread == CURL_READFUNC_PAUSE)
break; break;
} }
if (nread > 0) { if(nread > 0) {
code = send_telnet_data(conn, buf, nread); code = send_telnet_data(conn, buf, nread);
if(code) { if(code) {
keepon = FALSE; keepon = FALSE;
@ -1530,7 +1473,7 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
total_ul += nread; total_ul += nread;
Curl_pgrsSetUploadCounter(data, total_ul); Curl_pgrsSetUploadCounter(data, total_ul);
} }
else if (nread < 0) else if(nread < 0)
keepon = FALSE; keepon = FALSE;
break; break;
@ -1546,8 +1489,8 @@ static CURLcode telnet_do(struct connectdata *conn, bool *done)
} }
if(Curl_pgrsUpdate(conn)) { if(Curl_pgrsUpdate(conn)) {
code = CURLE_ABORTED_BY_CALLBACK; code = CURLE_ABORTED_BY_CALLBACK;
break; break;
} }
} }
#endif #endif

View File

@ -166,7 +166,8 @@ typedef struct tftp_state_data {
static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event) ; static CURLcode tftp_rx(tftp_state_data_t *state, tftp_event_t event) ;
static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event) ; static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event) ;
static CURLcode tftp_connect(struct connectdata *conn, bool *done); static CURLcode tftp_connect(struct connectdata *conn, bool *done);
static CURLcode tftp_disconnect(struct connectdata *conn, bool dead_connection); static CURLcode tftp_disconnect(struct connectdata *conn,
bool dead_connection);
static CURLcode tftp_do(struct connectdata *conn, bool *done); static CURLcode tftp_do(struct connectdata *conn, bool *done);
static CURLcode tftp_done(struct connectdata *conn, static CURLcode tftp_done(struct connectdata *conn,
CURLcode, bool premature); CURLcode, bool premature);
@ -330,14 +331,14 @@ static const char *tftp_option_get(const char *buf, size_t len,
loc = Curl_strnlen( buf, len ); loc = Curl_strnlen( buf, len );
loc++; /* NULL term */ loc++; /* NULL term */
if (loc >= len) if(loc >= len)
return NULL; return NULL;
*option = buf; *option = buf;
loc += Curl_strnlen( buf+loc, len-loc ); loc += Curl_strnlen( buf+loc, len-loc );
loc++; /* NULL term */ loc++; /* NULL term */
if (loc > len) if(loc > len)
return NULL; return NULL;
*value = &buf[strlen(*option) + 1]; *value = &buf[strlen(*option) + 1];
@ -353,7 +354,7 @@ static CURLcode tftp_parse_option_ack(tftp_state_data_t *state,
/* if OACK doesn't contain blksize option, the default (512) must be used */ /* if OACK doesn't contain blksize option, the default (512) must be used */
state->blksize = TFTP_BLKSIZE_DEFAULT; state->blksize = TFTP_BLKSIZE_DEFAULT;
while (tmp < ptr + len) { while(tmp < ptr + len) {
const char *option, *value; const char *option, *value;
tmp = tftp_option_get(tmp, ptr + len - tmp, &option, &value); tmp = tftp_option_get(tmp, ptr + len - tmp, &option, &value);
@ -383,7 +384,7 @@ static CURLcode tftp_parse_option_ack(tftp_state_data_t *state,
TFTP_BLKSIZE_MIN); TFTP_BLKSIZE_MIN);
return CURLE_TFTP_ILLEGAL; return CURLE_TFTP_ILLEGAL;
} }
else if (blksize > state->requested_blksize) { else if(blksize > state->requested_blksize) {
/* could realloc pkt buffers here, but the spec doesn't call out /* could realloc pkt buffers here, but the spec doesn't call out
* support for the server requesting a bigger blksize than the client * support for the server requesting a bigger blksize than the client
* requests */ * requests */
@ -404,7 +405,7 @@ static CURLcode tftp_parse_option_ack(tftp_state_data_t *state,
/* tsize should be ignored on upload: Who cares about the size of the /* tsize should be ignored on upload: Who cares about the size of the
remote file? */ remote file? */
if (!data->set.upload) { if(!data->set.upload) {
if(!tsize) { if(!tsize) {
failf(data, "invalid tsize -:%s:- value in OACK packet", value); failf(data, "invalid tsize -:%s:- value in OACK packet", value);
return CURLE_TFTP_ILLEGAL; return CURLE_TFTP_ILLEGAL;
@ -716,7 +717,7 @@ static CURLcode tftp_tx(tftp_state_data_t *state, tftp_event_t event)
case TFTP_EVENT_ACK: case TFTP_EVENT_ACK:
case TFTP_EVENT_OACK: case TFTP_EVENT_OACK:
if (event == TFTP_EVENT_ACK) { if(event == TFTP_EVENT_ACK) {
/* Ack the packet */ /* Ack the packet */
rblock = getrpacketblock(&state->rpacket); rblock = getrpacketblock(&state->rpacket);
@ -1170,7 +1171,7 @@ static long tftp_state_timeout(struct connectdata *conn, tftp_event_t *event)
time_t current; time_t current;
tftp_state_data_t *state = (tftp_state_data_t *)conn->proto.tftpc; tftp_state_data_t *state = (tftp_state_data_t *)conn->proto.tftpc;
if (event) if(event)
*event = TFTP_EVENT_NONE; *event = TFTP_EVENT_NONE;
time(&current); time(&current);
@ -1181,8 +1182,8 @@ static long tftp_state_timeout(struct connectdata *conn, tftp_event_t *event)
state->state = TFTP_STATE_FIN; state->state = TFTP_STATE_FIN;
return 0; return 0;
} }
else if (current > state->rx_time+state->retry_time) { else if(current > state->rx_time+state->retry_time) {
if (event) if(event)
*event = TFTP_EVENT_TIMEOUT; *event = TFTP_EVENT_TIMEOUT;
time(&state->rx_time); /* update even though we received nothing */ time(&state->rx_time); /* update even though we received nothing */
} }
@ -1221,8 +1222,8 @@ static CURLcode tftp_easy_statemach(struct connectdata *conn)
timeout_ms = state->retry_time * 1000; timeout_ms = state->retry_time * 1000;
if (data->set.upload) { if(data->set.upload) {
if (data->set.max_send_speed && if(data->set.max_send_speed &&
(data->progress.ulspeed > data->set.max_send_speed)) { (data->progress.ulspeed > data->set.max_send_speed)) {
fd_read = CURL_SOCKET_BAD; fd_read = CURL_SOCKET_BAD;
timeout_ms = Curl_sleep_time(data->set.max_send_speed, timeout_ms = Curl_sleep_time(data->set.max_send_speed,
@ -1233,20 +1234,19 @@ static CURLcode tftp_easy_statemach(struct connectdata *conn)
} }
} }
else { else {
if (data->set.max_recv_speed && if(data->set.max_recv_speed &&
(data->progress.dlspeed > data->set.max_recv_speed)) { (data->progress.dlspeed > data->set.max_recv_speed)) {
fd_read = CURL_SOCKET_BAD; fd_read = CURL_SOCKET_BAD;
timeout_ms = Curl_sleep_time(data->set.max_recv_speed, timeout_ms = Curl_sleep_time(data->set.max_recv_speed,
data->progress.dlspeed, state->blksize); data->progress.dlspeed, state->blksize);
} }
else { else
fd_read = state->sockfd; fd_read = state->sockfd;
}
} }
if(data->set.timeout) { if(data->set.timeout) {
timeout_ms = data->set.timeout - Curl_tvdiff(k->now, k->start); timeout_ms = data->set.timeout - Curl_tvdiff(k->now, k->start);
if (timeout_ms > state->retry_time * 1000) if(timeout_ms > state->retry_time * 1000)
timeout_ms = state->retry_time * 1000; timeout_ms = state->retry_time * 1000;
else if(timeout_ms < 0) else if(timeout_ms < 0)
timeout_ms = 0; timeout_ms = 0;
@ -1259,7 +1259,7 @@ static CURLcode tftp_easy_statemach(struct connectdata *conn)
k->now = Curl_tvnow(); k->now = Curl_tvnow();
/* Force a progress callback if it's been too long */ /* Force a progress callback if it's been too long */
if (Curl_tvdiff(k->now, k->start) >= data->set.timeout) { if(Curl_tvdiff(k->now, k->start) >= data->set.timeout) {
if(Curl_pgrsUpdate(conn)) { if(Curl_pgrsUpdate(conn)) {
tftp_state_machine(state, TFTP_EVENT_ERROR); tftp_state_machine(state, TFTP_EVENT_ERROR);
return CURLE_ABORTED_BY_CALLBACK; return CURLE_ABORTED_BY_CALLBACK;
@ -1279,7 +1279,7 @@ static CURLcode tftp_easy_statemach(struct connectdata *conn)
/* A timeout occurred, but our timeout is variable, so maybe /* A timeout occurred, but our timeout is variable, so maybe
just continue? */ just continue? */
long rtms = state->retry_time * 1000; long rtms = state->retry_time * 1000;
if (Curl_tvdiff(k->now, transaction_start) > rtms) { if(Curl_tvdiff(k->now, transaction_start) > rtms) {
state->event = TFTP_EVENT_TIMEOUT; state->event = TFTP_EVENT_TIMEOUT;
/* Force a look at transfer timeouts */ /* Force a look at transfer timeouts */
check_time = 1; check_time = 1;
@ -1290,7 +1290,7 @@ static CURLcode tftp_easy_statemach(struct connectdata *conn)
} }
else { else {
result = tftp_receive_packet(conn); result = tftp_receive_packet(conn);
if (result == CURLE_OK) if(result == CURLE_OK)
transaction_start = Curl_tvnow(); transaction_start = Curl_tvnow();
if(k->bytecountp) if(k->bytecountp)
@ -1339,7 +1339,7 @@ static CURLcode tftp_multi_statemach(struct connectdata *conn, bool *done)
failf(data, "TFTP response timeout"); failf(data, "TFTP response timeout");
return CURLE_OPERATION_TIMEDOUT; return CURLE_OPERATION_TIMEDOUT;
} }
else if (event != TFTP_EVENT_NONE) { else if(event != TFTP_EVENT_NONE) {
result = tftp_state_machine(state, event); result = tftp_state_machine(state, event);
if(result != CURLE_OK) if(result != CURLE_OK)
return(result); return(result);
@ -1463,7 +1463,7 @@ static CURLcode tftp_do(struct connectdata *conn, bool *done)
/* If tftp_perform() returned an error, use that for return code. If it /* If tftp_perform() returned an error, use that for return code. If it
was OK, see if tftp_translate_code() has an error. */ was OK, see if tftp_translate_code() has an error. */
if (code == CURLE_OK) if(code == CURLE_OK)
/* If we have encountered an internal tftp error, translate it. */ /* If we have encountered an internal tftp error, translate it. */
code = tftp_translate_code(state->error); code = tftp_translate_code(state->error);

View File

@ -509,18 +509,18 @@ static CURLcode readwrite_data(struct SessionHandle *data,
"Rewinding stream by : %zd" "Rewinding stream by : %zd"
" bytes on url %s (zero-length body)\n", " bytes on url %s (zero-length body)\n",
nread, data->state.path); nread, data->state.path);
read_rewind(conn, (size_t)nread); read_rewind(conn, (size_t)nread);
} }
else { else {
infof(data, infof(data,
"Excess found in a non pipelined read:" "Excess found in a non pipelined read:"
" excess = %zd" " excess = %zd"
" url = %s (zero-length body)\n", " url = %s (zero-length body)\n",
nread, data->state.path); nread, data->state.path);
} }
} }
break; break;
} }
} }
#endif /* CURL_DISABLE_HTTP */ #endif /* CURL_DISABLE_HTTP */
@ -629,7 +629,8 @@ static CURLcode readwrite_data(struct SessionHandle *data,
dataleft = conn->chunk.dataleft; dataleft = conn->chunk.dataleft;
if(dataleft != 0) { if(dataleft != 0) {
infof(conn->data, "Leftovers after chunking: %zu bytes", dataleft); infof(conn->data, "Leftovers after chunking: %zu bytes", dataleft);
if(conn->data->multi && Curl_multi_canPipeline(conn->data->multi)) { if(conn->data->multi &&
Curl_multi_canPipeline(conn->data->multi)) {
/* only attempt the rewind if we truly are pipelining */ /* only attempt the rewind if we truly are pipelining */
infof(conn->data, "Rewinding %zu bytes\n",dataleft); infof(conn->data, "Rewinding %zu bytes\n",dataleft);
read_rewind(conn, dataleft); read_rewind(conn, dataleft);
@ -1235,19 +1236,19 @@ long Curl_sleep_time(curl_off_t rate_bps, curl_off_t cur_rate_bps,
curl_off_t min_sleep = 0; curl_off_t min_sleep = 0;
curl_off_t rv = 0; curl_off_t rv = 0;
if (rate_bps == 0) if(rate_bps == 0)
return 0; return 0;
/* If running faster than about .1% of the desired speed, slow /* If running faster than about .1% of the desired speed, slow
* us down a bit. Use shift instead of division as the 0.1% * us down a bit. Use shift instead of division as the 0.1%
* cutoff is arbitrary anyway. * cutoff is arbitrary anyway.
*/ */
if (cur_rate_bps > (rate_bps + (rate_bps >> 10))) { if(cur_rate_bps > (rate_bps + (rate_bps >> 10))) {
/* running too fast, decrease target rate by 1/64th of rate */ /* running too fast, decrease target rate by 1/64th of rate */
rate_bps -= rate_bps >> 6; rate_bps -= rate_bps >> 6;
min_sleep = 1; min_sleep = 1;
} }
else if (cur_rate_bps < (rate_bps - (rate_bps >> 10))) { else if(cur_rate_bps < (rate_bps - (rate_bps >> 10))) {
/* running too slow, increase target rate by 1/64th of rate */ /* running too slow, increase target rate by 1/64th of rate */
rate_bps += rate_bps >> 6; rate_bps += rate_bps >> 6;
} }
@ -1261,7 +1262,7 @@ long Curl_sleep_time(curl_off_t rate_bps, curl_off_t cur_rate_bps,
/* Catch rounding errors and always slow down at least 1ms if /* Catch rounding errors and always slow down at least 1ms if
* we are running too fast. * we are running too fast.
*/ */
if (rv < min_sleep) if(rv < min_sleep)
rv = min_sleep; rv = min_sleep;
/* Bound value to fit in 'long' on 32-bit platform. That's /* Bound value to fit in 'long' on 32-bit platform. That's
@ -1329,14 +1330,14 @@ Transfer(struct connectdata *conn)
k->keepon &= ~KEEP_SEND_HOLD; k->keepon &= ~KEEP_SEND_HOLD;
} }
else { else {
if (data->set.upload && data->set.max_send_speed && if(data->set.upload && data->set.max_send_speed &&
(data->progress.ulspeed > data->set.max_send_speed) ) { (data->progress.ulspeed > data->set.max_send_speed) ) {
/* calculate upload rate-limitation timeout. */ /* calculate upload rate-limitation timeout. */
buffersize = (int)(data->set.buffer_size ? buffersize = (int)(data->set.buffer_size ?
data->set.buffer_size : BUFSIZE); data->set.buffer_size : BUFSIZE);
totmp = (int)Curl_sleep_time(data->set.max_send_speed, totmp = (int)Curl_sleep_time(data->set.max_send_speed,
data->progress.ulspeed, buffersize); data->progress.ulspeed, buffersize);
if (totmp < timeout_ms) if(totmp < timeout_ms)
timeout_ms = totmp; timeout_ms = totmp;
} }
fd_write = CURL_SOCKET_BAD; fd_write = CURL_SOCKET_BAD;
@ -1350,14 +1351,14 @@ Transfer(struct connectdata *conn)
k->keepon &= ~KEEP_RECV_HOLD; k->keepon &= ~KEEP_RECV_HOLD;
} }
else { else {
if ((!data->set.upload) && data->set.max_recv_speed && if((!data->set.upload) && data->set.max_recv_speed &&
(data->progress.dlspeed > data->set.max_recv_speed)) { (data->progress.dlspeed > data->set.max_recv_speed)) {
/* Calculate download rate-limitation timeout. */ /* Calculate download rate-limitation timeout. */
buffersize = (int)(data->set.buffer_size ? buffersize = (int)(data->set.buffer_size ?
data->set.buffer_size : BUFSIZE); data->set.buffer_size : BUFSIZE);
totmp = (int)Curl_sleep_time(data->set.max_recv_speed, totmp = (int)Curl_sleep_time(data->set.max_recv_speed,
data->progress.dlspeed, buffersize); data->progress.dlspeed, buffersize);
if (totmp < timeout_ms) if(totmp < timeout_ms)
timeout_ms = totmp; timeout_ms = totmp;
} }
fd_read = CURL_SOCKET_BAD; fd_read = CURL_SOCKET_BAD;
@ -1393,7 +1394,7 @@ Transfer(struct connectdata *conn)
else if(!totmp) else if(!totmp)
totmp = 1000; totmp = 1000;
if (totmp < timeout_ms) if(totmp < timeout_ms)
timeout_ms = totmp; timeout_ms = totmp;
} }
@ -1815,7 +1816,7 @@ CURLcode Curl_follow(struct SessionHandle *data,
free(data->change.referer); free(data->change.referer);
data->change.referer = strdup(data->change.url); data->change.referer = strdup(data->change.url);
if (!data->change.referer) { if(!data->change.referer) {
data->change.referer_alloc = FALSE; data->change.referer_alloc = FALSE;
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
} }
@ -1829,7 +1830,7 @@ CURLcode Curl_follow(struct SessionHandle *data,
to be absolute and this doesn't seem to be that! to be absolute and this doesn't seem to be that!
*/ */
char *absolute = concat_url(data->change.url, newurl); char *absolute = concat_url(data->change.url, newurl);
if (!absolute) if(!absolute)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
free(newurl); free(newurl);
newurl = absolute; newurl = absolute;
@ -1845,7 +1846,7 @@ CURLcode Curl_follow(struct SessionHandle *data,
size_t newlen = strlen_url(newurl); size_t newlen = strlen_url(newurl);
newest = malloc(newlen+1); /* get memory for this */ newest = malloc(newlen+1); /* get memory for this */
if (!newest) if(!newest)
return CURLE_OUT_OF_MEMORY; return CURLE_OUT_OF_MEMORY;
strcpy_url(newest, newurl); /* create a space-free URL */ strcpy_url(newest, newurl); /* create a space-free URL */
@ -2164,7 +2165,7 @@ static CURLcode Curl_do_perform(struct SessionHandle *data)
res = CURLE_OK; res = CURLE_OK;
follow = FOLLOW_RETRY; follow = FOLLOW_RETRY;
} }
else if (res == CURLE_OK) { else if(res == CURLE_OK) {
/* /*
* We must duplicate the new URL here as the connection data may * We must duplicate the new URL here as the connection data may
* be free()ed in the Curl_done() function. We prefer the newurl * be free()ed in the Curl_done() function. We prefer the newurl
@ -2174,13 +2175,13 @@ static CURLcode Curl_do_perform(struct SessionHandle *data)
if(data->req.newurl) { if(data->req.newurl) {
follow = FOLLOW_REDIR; follow = FOLLOW_REDIR;
newurl = strdup(data->req.newurl); newurl = strdup(data->req.newurl);
if (!newurl) if(!newurl)
res = CURLE_OUT_OF_MEMORY; res = CURLE_OUT_OF_MEMORY;
} }
else if(data->req.location) { else if(data->req.location) {
follow = FOLLOW_FAKE; follow = FOLLOW_FAKE;
newurl = strdup(data->req.location); newurl = strdup(data->req.location);
if (!newurl) if(!newurl)
res = CURLE_OUT_OF_MEMORY; res = CURLE_OUT_OF_MEMORY;
} }
} }

View File

@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2011, 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
@ -36,7 +36,8 @@ typedef enum {
FOLLOW_LAST /* never used */ FOLLOW_LAST /* never used */
} followtype; } followtype;
CURLcode Curl_follow(struct SessionHandle *data, char *newurl, followtype type); CURLcode Curl_follow(struct SessionHandle *data, char *newurl,
followtype type);
CURLcode Curl_readwrite(struct connectdata *conn, bool *done); CURLcode Curl_readwrite(struct connectdata *conn, bool *done);

115
lib/url.c
View File

@ -331,7 +331,7 @@ static CURLcode setstropt_userpwd(char *option, char **user_storage,
} }
separator = strchr(option, ':'); separator = strchr(option, ':');
if (separator != NULL) { if(separator != NULL) {
/* store username part of option */ /* store username part of option */
char * p; char * p;
@ -347,9 +347,8 @@ static CURLcode setstropt_userpwd(char *option, char **user_storage,
} }
/* store password part of option */ /* store password part of option */
if (result == CURLE_OK) { if(result == CURLE_OK)
result = setstropt(pwd_storage, separator+1); result = setstropt(pwd_storage, separator+1);
}
} }
else { else {
result = setstropt(user_storage, option); result = setstropt(user_storage, option);
@ -411,7 +410,7 @@ CURLcode Curl_close(struct SessionHandle *data)
pipeline = connptr->send_pipe; pipeline = connptr->send_pipe;
if(pipeline) { if(pipeline) {
for (curr = pipeline->head; curr; curr=curr->next) { for(curr = pipeline->head; curr; curr=curr->next) {
if(data == (struct SessionHandle *) curr->ptr) { if(data == (struct SessionHandle *) curr->ptr) {
fprintf(stderr, fprintf(stderr,
"problem we %p are still in send pipe for %p done %d\n", "problem we %p are still in send pipe for %p done %d\n",
@ -421,7 +420,7 @@ CURLcode Curl_close(struct SessionHandle *data)
} }
pipeline = connptr->recv_pipe; pipeline = connptr->recv_pipe;
if(pipeline) { if(pipeline) {
for (curr = pipeline->head; curr; curr=curr->next) { for(curr = pipeline->head; curr; curr=curr->next) {
if(data == (struct SessionHandle *) curr->ptr) { if(data == (struct SessionHandle *) curr->ptr) {
fprintf(stderr, fprintf(stderr,
"problem we %p are still in recv pipe for %p done %d\n", "problem we %p are still in recv pipe for %p done %d\n",
@ -431,7 +430,7 @@ CURLcode Curl_close(struct SessionHandle *data)
} }
pipeline = connptr->done_pipe; pipeline = connptr->done_pipe;
if(pipeline) { if(pipeline) {
for (curr = pipeline->head; curr; curr=curr->next) { for(curr = pipeline->head; curr; curr=curr->next) {
if(data == (struct SessionHandle *) curr->ptr) { if(data == (struct SessionHandle *) curr->ptr) {
fprintf(stderr, fprintf(stderr,
"problem we %p are still in done pipe for %p done %d\n", "problem we %p are still in done pipe for %p done %d\n",
@ -441,7 +440,7 @@ CURLcode Curl_close(struct SessionHandle *data)
} }
pipeline = connptr->pend_pipe; pipeline = connptr->pend_pipe;
if(pipeline) { if(pipeline) {
for (curr = pipeline->head; curr; curr=curr->next) { for(curr = pipeline->head; curr; curr=curr->next) {
if(data == (struct SessionHandle *) curr->ptr) { if(data == (struct SessionHandle *) curr->ptr) {
fprintf(stderr, fprintf(stderr,
"problem we %p are still in pend pipe for %p done %d\n", "problem we %p are still in pend pipe for %p done %d\n",
@ -736,7 +735,7 @@ CURLcode Curl_init_userdefined(struct UserDefined *set)
/* set default gssapi service name */ /* set default gssapi service name */
res = setstropt(&set->str[STRING_SOCKS5_GSSAPI_SERVICE], res = setstropt(&set->str[STRING_SOCKS5_GSSAPI_SERVICE],
(char *) CURL_DEFAULT_SOCKS5_GSSAPI_SERVICE); (char *) CURL_DEFAULT_SOCKS5_GSSAPI_SERVICE);
if (res != CURLE_OK) if(res != CURLE_OK)
return res; return res;
#endif #endif
@ -1408,7 +1407,8 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */ auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */
#endif #endif
#ifndef USE_HTTP_NEGOTIATE #ifndef USE_HTTP_NEGOTIATE
auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI or WINDOWS_SSPI */ auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI or
WINDOWS_SSPI */
#endif #endif
if(!auth) if(!auth)
return CURLE_NOT_BUILT_IN; /* no supported types left! */ return CURLE_NOT_BUILT_IN; /* no supported types left! */
@ -1468,7 +1468,8 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */ auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */
#endif #endif
#ifndef USE_HTTP_NEGOTIATE #ifndef USE_HTTP_NEGOTIATE
auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI or WINDOWS_SSPI */ auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI or
WINDOWS_SSPI */
#endif #endif
if(!auth) if(!auth)
return CURLE_NOT_BUILT_IN; /* no supported types left! */ return CURLE_NOT_BUILT_IN; /* no supported types left! */
@ -2483,17 +2484,17 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
case CURLOPT_TLSAUTH_USERNAME: case CURLOPT_TLSAUTH_USERNAME:
result = setstropt(&data->set.str[STRING_TLSAUTH_USERNAME], result = setstropt(&data->set.str[STRING_TLSAUTH_USERNAME],
va_arg(param, char *)); va_arg(param, char *));
if (data->set.str[STRING_TLSAUTH_USERNAME] && !data->set.ssl.authtype) if(data->set.str[STRING_TLSAUTH_USERNAME] && !data->set.ssl.authtype)
data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
break; break;
case CURLOPT_TLSAUTH_PASSWORD: case CURLOPT_TLSAUTH_PASSWORD:
result = setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD], result = setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD],
va_arg(param, char *)); va_arg(param, char *));
if (data->set.str[STRING_TLSAUTH_USERNAME] && !data->set.ssl.authtype) if(data->set.str[STRING_TLSAUTH_USERNAME] && !data->set.ssl.authtype)
data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */ data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
break; break;
case CURLOPT_TLSAUTH_TYPE: case CURLOPT_TLSAUTH_TYPE:
if (strncmp((char *)va_arg(param, char *), "SRP", strlen("SRP")) == 0) if(strncmp((char *)va_arg(param, char *), "SRP", strlen("SRP")) == 0)
data->set.ssl.authtype = CURL_TLSAUTH_SRP; data->set.ssl.authtype = CURL_TLSAUTH_SRP;
else else
data->set.ssl.authtype = CURL_TLSAUTH_NONE; data->set.ssl.authtype = CURL_TLSAUTH_NONE;
@ -2590,19 +2591,19 @@ CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection)
related stuff. NTLM is connection-related so when we close the shop related stuff. NTLM is connection-related so when we close the shop
we shall forget. */ we shall forget. */
if (has_host_ntlm) { if(has_host_ntlm) {
data->state.authhost.done = FALSE; data->state.authhost.done = FALSE;
data->state.authhost.picked = data->state.authhost.picked =
data->state.authhost.want; data->state.authhost.want;
} }
if (has_proxy_ntlm) { if(has_proxy_ntlm) {
data->state.authproxy.done = FALSE; data->state.authproxy.done = FALSE;
data->state.authproxy.picked = data->state.authproxy.picked =
data->state.authproxy.want; data->state.authproxy.want;
} }
if (has_host_ntlm || has_proxy_ntlm) { if(has_host_ntlm || has_proxy_ntlm) {
data->state.authproblem = FALSE; data->state.authproblem = FALSE;
Curl_ntlm_cleanup(conn); Curl_ntlm_cleanup(conn);
@ -2789,8 +2790,8 @@ static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke)
} }
#endif #endif
if (pipe_broke) if(pipe_broke)
data->state.pipe_broke = TRUE; data->state.pipe_broke = TRUE;
Curl_multi_handlePipeBreak(data); Curl_multi_handlePipeBreak(data);
Curl_llist_remove(pipeline, curr, NULL); Curl_llist_remove(pipeline, curr, NULL);
curr = next; curr = next;
@ -3437,7 +3438,7 @@ static void fix_hostname(struct SessionHandle *data,
host->name = host->encalloc; host->name = host->encalloc;
} }
#else #else
infof (data, "IDN support not present, can't parse Unicode (UTF-8) domains"); infof (data, "IDN support not present, can't parse Unicode domains");
#endif #endif
} }
} }
@ -3564,7 +3565,7 @@ static CURLcode findprotocol(struct SessionHandle *data,
/* Scan protocol handler table and match against 'protostr' to set a few /* Scan protocol handler table and match against 'protostr' to set a few
variables based on the URL. Now that the handler may be changed later variables based on the URL. Now that the handler may be changed later
when the protocol specific setup function is called. */ when the protocol specific setup function is called. */
for (pp = protocols; (p = *pp) != NULL; pp++) { for(pp = protocols; (p = *pp) != NULL; pp++) {
if(Curl_raw_equal(p->scheme, protostr)) { if(Curl_raw_equal(p->scheme, protostr)) {
/* Protocol found in table. Check if allowed */ /* Protocol found in table. Check if allowed */
if(!(data->set.allowed_protocols & p->protocol)) if(!(data->set.allowed_protocols & p->protocol))
@ -3692,7 +3693,7 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
* assigned, but the return value is EOF! * assigned, but the return value is EOF!
*/ */
#if defined(__DJGPP__) && (DJGPP_MINOR == 4) #if defined(__DJGPP__) && (DJGPP_MINOR == 4)
if (!(rc == -1 && *conn->host.name)) if(!(rc == -1 && *conn->host.name))
#endif #endif
{ {
failf(data, "<url> malformed"); failf(data, "<url> malformed");
@ -3776,21 +3777,22 @@ static CURLcode parseurlandfillconn(struct SessionHandle *data,
path[0] = '/'; path[0] = '/';
} }
if (conn->host.name[0] == '[') { if(conn->host.name[0] == '[') {
/* This looks like an IPv6 address literal. See if there is an address /* This looks like an IPv6 address literal. See if there is an address
scope. */ scope. */
char *percent = strstr (conn->host.name, "%25"); char *percent = strstr (conn->host.name, "%25");
if (percent) { if(percent) {
char *endp; char *endp;
unsigned long scope = strtoul (percent + 3, &endp, 10); unsigned long scope = strtoul (percent + 3, &endp, 10);
if (*endp == ']') { if(*endp == ']') {
/* The address scope was well formed. Knock it out of the /* The address scope was well formed. Knock it out of the
hostname. */ hostname. */
memmove(percent, endp, strlen(endp)+1); memmove(percent, endp, strlen(endp)+1);
if (!data->state.this_is_a_follow) if(!data->state.this_is_a_follow)
/* Don't honour a scope given in a Location: header */ /* Don't honour a scope given in a Location: header */
conn->scope = (unsigned int)scope; conn->scope = (unsigned int)scope;
} else }
else
infof(data, "Invalid IPv6 address format\n"); infof(data, "Invalid IPv6 address format\n");
} }
} }
@ -3915,9 +3917,9 @@ static bool check_noproxy(const char* name, const char* no_proxy)
else else
namelen = strlen(name); namelen = strlen(name);
for (tok_start = 0; tok_start < no_proxy_len; tok_start = tok_end + 1) { for(tok_start = 0; tok_start < no_proxy_len; tok_start = tok_end + 1) {
while (tok_start < no_proxy_len && while(tok_start < no_proxy_len &&
strchr(separator, no_proxy[tok_start]) != NULL) { strchr(separator, no_proxy[tok_start]) != NULL) {
/* Look for the beginning of the token. */ /* Look for the beginning of the token. */
++tok_start; ++tok_start;
} }
@ -3925,10 +3927,10 @@ static bool check_noproxy(const char* name, const char* no_proxy)
if(tok_start == no_proxy_len) if(tok_start == no_proxy_len)
break; /* It was all trailing separator chars, no more tokens. */ break; /* It was all trailing separator chars, no more tokens. */
for (tok_end = tok_start; tok_end < no_proxy_len && for(tok_end = tok_start; tok_end < no_proxy_len &&
strchr(separator, no_proxy[tok_end]) == NULL; ++tok_end) { strchr(separator, no_proxy[tok_end]) == NULL; ++tok_end)
/* Look for the end of the token. */ /* Look for the end of the token. */
} ;
/* To match previous behaviour, where it was necessary to specify /* To match previous behaviour, where it was necessary to specify
* ".local.com" to prevent matching "notlocal.com", we will leave * ".local.com" to prevent matching "notlocal.com", we will leave
@ -3950,7 +3952,7 @@ static bool check_noproxy(const char* name, const char* no_proxy)
} }
} }
} /* if((tok_end - tok_start) <= namelen) */ } /* if((tok_end - tok_start) <= namelen) */
} /* for (tok_start = 0; tok_start < no_proxy_len; } /* for(tok_start = 0; tok_start < no_proxy_len;
tok_start = tok_end + 1) */ tok_start = tok_end + 1) */
} /* NO_PROXY was specified and it wasn't just an asterisk */ } /* NO_PROXY was specified and it wasn't just an asterisk */
@ -4133,10 +4135,10 @@ static CURLcode parse_proxy(struct SessionHandle *data,
while(*ptr && (ISXDIGIT(*ptr) || (*ptr == ':') || (*ptr == '%') || while(*ptr && (ISXDIGIT(*ptr) || (*ptr == ':') || (*ptr == '%') ||
(*ptr == '.'))) (*ptr == '.')))
ptr++; ptr++;
if(*ptr == ']') { if(*ptr == ']')
/* yeps, it ended nicely with a bracket as well */ /* yeps, it ended nicely with a bracket as well */
*ptr++ = 0; *ptr++ = 0;
} else else
infof(data, "Invalid IPv6 address format\n"); infof(data, "Invalid IPv6 address format\n");
portptr = ptr; portptr = ptr;
/* Note that if this didn't end with a bracket, we still advanced the /* Note that if this didn't end with a bracket, we still advanced the
@ -4508,7 +4510,7 @@ static CURLcode resolve_server(struct SessionHandle *data,
if(rc == CURLRESOLV_PENDING) if(rc == CURLRESOLV_PENDING)
*async = TRUE; *async = TRUE;
else if (rc == CURLRESOLV_TIMEDOUT) else if(rc == CURLRESOLV_TIMEDOUT)
result = CURLE_OPERATION_TIMEDOUT; result = CURLE_OPERATION_TIMEDOUT;
else if(!hostaddr) { else if(!hostaddr) {
@ -4530,7 +4532,7 @@ static CURLcode resolve_server(struct SessionHandle *data,
if(rc == CURLRESOLV_PENDING) if(rc == CURLRESOLV_PENDING)
*async = TRUE; *async = TRUE;
else if (rc == CURLRESOLV_TIMEDOUT) else if(rc == CURLRESOLV_TIMEDOUT)
result = CURLE_OPERATION_TIMEDOUT; result = CURLE_OPERATION_TIMEDOUT;
else if(!hostaddr) { else if(!hostaddr) {
@ -4698,9 +4700,8 @@ static CURLcode create_conn(struct SessionHandle *data,
conn->host.name[0] = 0; conn->host.name[0] = 0;
result = parseurlandfillconn(data, conn, &prot_missing); result = parseurlandfillconn(data, conn, &prot_missing);
if(result != CURLE_OK) { if(result != CURLE_OK)
return result; return result;
}
/************************************************************* /*************************************************************
* No protocol part in URL was used, add it! * No protocol part in URL was used, add it!
@ -5094,7 +5095,7 @@ CURLcode Curl_connect(struct SessionHandle *data,
if((*in_connect)->send_pipe->size || (*in_connect)->recv_pipe->size) if((*in_connect)->send_pipe->size || (*in_connect)->recv_pipe->size)
/* pipelining */ /* pipelining */
*protocol_done = TRUE; *protocol_done = TRUE;
else if (!*asyncp) { else if(!*asyncp) {
/* DNS resolution is done: that's either because this is a reused /* DNS resolution is done: that's either because this is a reused
connection, in which case DNS was unnecessary, or because DNS connection, in which case DNS was unnecessary, or because DNS
really did finish already (synch resolver/fast async resolve) */ really did finish already (synch resolver/fast async resolve) */
@ -5191,7 +5192,7 @@ CURLcode Curl_done(struct connectdata **connp,
*/ */
if(data->set.reuse_forbid || conn->bits.close || premature || if(data->set.reuse_forbid || conn->bits.close || premature ||
(-1 == conn->connectindex)) { (-1 == conn->connectindex)) {
CURLcode res2 = Curl_disconnect(conn, premature); /* close the connection */ CURLcode res2 = Curl_disconnect(conn, premature); /* close connection */
/* If we had an error already, make sure we return that one. But /* If we had an error already, make sure we return that one. But
if we got a new error, return that. */ if we got a new error, return that. */
@ -5296,23 +5297,23 @@ CURLcode Curl_do(struct connectdata **connp, bool *done)
/* This was formerly done in transfer.c, but we better do it here */ /* This was formerly done in transfer.c, but we better do it here */
if((CURLE_SEND_ERROR == result) && conn->bits.reuse) { if((CURLE_SEND_ERROR == result) && conn->bits.reuse) {
/* /*
* If the connection is using an easy handle, call reconnect * If the connection is using an easy handle, call reconnect
* to re-establish the connection. Otherwise, let the multi logic * to re-establish the connection. Otherwise, let the multi logic
* figure out how to re-establish the connection. * figure out how to re-establish the connection.
*/ */
if(!data->multi) { if(!data->multi) {
result = Curl_reconnect_request(connp); result = Curl_reconnect_request(connp);
if(result == CURLE_OK) { if(result == CURLE_OK) {
/* ... finally back to actually retry the DO phase */ /* ... finally back to actually retry the DO phase */
conn = *connp; /* re-assign conn since Curl_reconnect_request conn = *connp; /* re-assign conn since Curl_reconnect_request
creates a new connection */ creates a new connection */
result = conn->handler->do_it(conn, done); result = conn->handler->do_it(conn, done);
}
} }
else }
return result; else
return result;
} }
if((result == CURLE_OK) && *done) if((result == CURLE_OK) && *done)

View File

@ -82,7 +82,8 @@ void Curl_close_connections(struct SessionHandle *data);
void Curl_reset_reqproto(struct connectdata *conn); void Curl_reset_reqproto(struct connectdata *conn);
#define CURL_DEFAULT_PROXY_PORT 1080 /* default proxy port unless specified */ #define CURL_DEFAULT_PROXY_PORT 1080 /* default proxy port unless specified */
#define CURL_DEFAULT_SOCKS5_GSSAPI_SERVICE "rcmd" /* default socks5 gssapi service */ #define CURL_DEFAULT_SOCKS5_GSSAPI_SERVICE "rcmd" /* default socks5 gssapi
service */
CURLcode Curl_connected_proxy(struct connectdata *conn); CURLcode Curl_connected_proxy(struct connectdata *conn);

View File

@ -1358,7 +1358,8 @@ struct UserDefined {
curl_sockopt_callback fsockopt; /* function for setting socket options */ curl_sockopt_callback fsockopt; /* function for setting socket options */
void *sockopt_client; /* pointer to pass to the socket options callback */ void *sockopt_client; /* pointer to pass to the socket options callback */
curl_opensocket_callback fopensocket; /* function for checking/translating curl_opensocket_callback fopensocket; /* function for checking/translating
the address and opening the socket */ the address and opening the
socket */
void* opensocket_client; void* opensocket_client;
void *seek_client; /* pointer to pass to the seek callback */ void *seek_client; /* pointer to pass to the seek callback */
@ -1380,7 +1381,8 @@ struct UserDefined {
long low_speed_limit; /* bytes/second */ long low_speed_limit; /* bytes/second */
long low_speed_time; /* number of seconds */ long low_speed_time; /* number of seconds */
curl_off_t max_send_speed; /* high speed limit in bytes/second for upload */ curl_off_t max_send_speed; /* high speed limit in bytes/second for upload */
curl_off_t max_recv_speed; /* high speed limit in bytes/second for download */ curl_off_t max_recv_speed; /* high speed limit in bytes/second for
download */
curl_off_t set_resume_from; /* continue [ftp] transfer from here */ curl_off_t set_resume_from; /* continue [ftp] transfer from here */
struct curl_slist *headers; /* linked list of extra headers */ struct curl_slist *headers; /* linked list of extra headers */
struct curl_httppost *httppost; /* linked list of POST data */ struct curl_httppost *httppost; /* linked list of POST data */
@ -1494,7 +1496,8 @@ struct UserDefined {
Curl_RtspReq rtspreq; /* RTSP request type */ Curl_RtspReq rtspreq; /* RTSP request type */
long rtspversion; /* like httpversion, for RTSP */ long rtspversion; /* like httpversion, for RTSP */
bool wildcardmatch; /* enable wildcard matching */ bool wildcardmatch; /* enable wildcard matching */
curl_chunk_bgn_callback chunk_bgn; /* called before part of transfer starts */ curl_chunk_bgn_callback chunk_bgn; /* called before part of transfer
starts */
curl_chunk_end_callback chunk_end; /* called after part transferring curl_chunk_end_callback chunk_end; /* called after part transferring
stopped */ stopped */
curl_fnmatch_callback fnmatch; /* callback to decide which file corresponds curl_fnmatch_callback fnmatch; /* callback to decide which file corresponds

View File

@ -123,12 +123,13 @@ char *curl_version(void)
#ifdef USE_LIBRTMP #ifdef USE_LIBRTMP
{ {
char suff[2]; char suff[2];
if (RTMP_LIB_VERSION & 0xff) { if(RTMP_LIB_VERSION & 0xff) {
suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1; suff[0] = (RTMP_LIB_VERSION & 0xff) + 'a' - 1;
suff[1] = '\0'; suff[1] = '\0';
} else {
suff[0] = '\0';
} }
else
suff[0] = '\0';
len = snprintf(ptr, left, " librtmp/%d.%d%s", len = snprintf(ptr, left, " librtmp/%d.%d%s",
RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff, suff); RTMP_LIB_VERSION >> 16, (RTMP_LIB_VERSION >> 8) & 0xff, suff);
/* /*