5
5
* | (__| |_| | _ <| |___
6
6
* \___|\___/|_| \_\_____|
8
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
8
* Copyright (C) 1998 - 2009, Daniel Stenberg, <daniel@haxx.se>, et al.
10
10
* This software is licensed as described in the file COPYING, which
11
11
* you should have received as part of this distribution. The terms
18
18
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19
19
* KIND, either express or implied.
21
* $Id: easy.c,v 1.120 2008-05-12 21:43:29 bagder Exp $
21
* $Id: easy.c,v 1.133 2009-01-29 20:32:31 yangtse Exp $
22
22
***************************************************************************/
103
103
/* The last #include file should be: */
104
104
#include "memdebug.h"
107
106
/* win32_cleanup() is for win32 socket cleanup functionality, the opposite
108
107
of win32_init() */
109
108
static void win32_cleanup(void)
113
#ifdef USE_WINDOWS_SSPI
114
Curl_sspi_global_cleanup();
114
118
/* win32_init() performs win32 socket initialization to properly setup the
115
119
stack to allow networking */
116
120
static CURLcode win32_init(void)
118
123
WORD wVersionRequested;
122
127
#if defined(ENABLE_IPV6) && (USE_WINSOCK < 2)
123
128
Error IPV6_requires_winsock2
126
131
wVersionRequested = MAKEWORD(USE_WINSOCK, USE_WINSOCK);
128
err = WSAStartup(wVersionRequested, &wsaData);
133
res = WSAStartup(wVersionRequested, &wsaData);
131
136
/* Tell the user that we couldn't find a useable */
132
137
/* winsock.dll. */
133
138
return CURLE_FAILED_INIT;
147
152
return CURLE_FAILED_INIT;
149
154
/* The Windows Sockets DLL is acceptable. Proceed. */
157
#ifdef USE_WINDOWS_SSPI
159
CURLcode err = Curl_sspi_global_init();
154
/* These functions exist merely to prevent compiler warnings */
155
static CURLcode win32_init(void) { return CURLE_OK; }
156
static void win32_cleanup(void) { }
159
168
#ifdef USE_LIBIDN
161
170
* Initialise use of IDNA library.
217
230
curl_calloc_callback Curl_ccalloc;
233
#if defined(_MSC_VER) && defined(_DLL)
234
# pragma warning(default:4232) /* MSVC extension, dllimport identity */
221
238
* curl_global_init() globally initializes cURL given a bitwise set of the
222
239
* different features of what to initialize.
485
502
/* global dns cache was requested but still isn't */
486
503
struct curl_hash *ptr;
488
if(data->dns.hostcachetype == HCACHE_PRIVATE)
505
if(data->dns.hostcachetype == HCACHE_PRIVATE) {
489
506
/* if the current cache is private, kill it first */
490
507
Curl_hash_destroy(data->dns.hostcache);
508
data->dns.hostcachetype = HCACHE_NONE;
509
data->dns.hostcache = NULL;
492
512
ptr = Curl_global_host_cache_init();
582
602
bool fail = TRUE;
583
603
struct SessionHandle *data=(struct SessionHandle *)incurl;
585
struct SessionHandle *outcurl = (struct SessionHandle *)
586
calloc(sizeof(struct SessionHandle), 1);
605
struct SessionHandle *outcurl = calloc(sizeof(struct SessionHandle), 1);
588
607
if(NULL == outcurl)
589
608
return NULL; /* failure */
595
614
* get setup on-demand in the code, as that would probably decrease
596
615
* the likeliness of us forgetting to init a buffer here in the future.
598
outcurl->state.headerbuff=(char*)malloc(HEADERSIZE);
617
outcurl->state.headerbuff = malloc(HEADERSIZE);
599
618
if(!outcurl->state.headerbuff) {
605
624
if(Curl_dupset(outcurl, data) != CURLE_OK)
608
if(data->state.used_interface == Curl_if_multi)
609
outcurl->state.connc = data->state.connc;
611
outcurl->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, -1);
613
if(!outcurl->state.connc)
627
/* the connection cache is setup on demand */
628
outcurl->state.connc = NULL;
616
630
outcurl->state.lastconnect = -1;
708
722
/* zero out UserDefined data: */
709
723
Curl_freeset(data);
710
724
memset(&data->set, 0, sizeof(struct UserDefined));
725
(void)Curl_init_userdefined(&data->set);
712
727
/* zero out Progress data: */
713
728
memset(&data->progress, 0, sizeof(struct Progress));
715
730
/* init Handle data */
716
731
Curl_easy_initHandleData(data);
718
/* The remainder of these calls have been taken from Curl_open() */
720
data->set.out = stdout; /* default output to stdout */
721
data->set.in = stdin; /* default input from stdin */
722
data->set.err = stderr; /* default stderr to stderr */
724
/* use fwrite as default function to store output */
725
data->set.fwrite_func = (curl_write_callback)fwrite;
727
/* use fread as default function to read input */
728
data->set.fread_func = (curl_read_callback)fread;
730
data->set.infilesize = -1; /* we don't know any size */
731
data->set.postfieldsize = -1; /* unknown size */
732
data->set.maxredirs = -1; /* allow any amount by default */
733
data->progress.flags |= PGRS_HIDE;
733
734
data->state.current_speed = -1; /* init to negative == impossible */
735
data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */
736
data->set.ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
737
data->set.ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
739
data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
741
/* make libcurl quiet by default: */
742
data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
743
data->progress.flags |= PGRS_HIDE;
745
/* Set the default size of the SSL session ID cache */
746
data->set.ssl.numsessions = 5;
748
data->set.proxyport = CURL_DEFAULT_PROXY_PORT; /* from url.h */
749
data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
750
data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */
751
data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */
754
* libcurl 7.10 introduced SSL verification *by default*! This needs to be
755
* switched off unless wanted.
757
data->set.ssl.verifypeer = TRUE;
758
data->set.ssl.verifyhost = 2;
759
/* This is our prefered CA cert bundle/path since install time */
760
#if defined(CURL_CA_BUNDLE)
761
(void) curl_easy_setopt(curl, CURLOPT_CAINFO, (char *) CURL_CA_BUNDLE);
762
#elif defined(CURL_CA_PATH)
763
(void) curl_easy_setopt(curl, CURLOPT_CAPATH, (char *) CURL_CA_PATH);
766
data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
768
data->set.new_file_perms = 0644; /* Default permissions */
769
data->set.new_directory_perms = 0755; /* Default permissions */
803
768
return PAUSE again and then we'll get a new copy allocted and stored in
804
769
the tempwrite variables */
805
770
char *tempwrite = data->state.tempwrite;
771
char *freewrite = tempwrite; /* store this pointer to free it later */
806
772
size_t tempsize = data->state.tempwritesize;
807
773
int temptype = data->state.tempwritetype;
828
794
result = Curl_client_write(data->state.current_conn,
829
795
temptype, tempwrite, chunklen);
831
797
/* failures abort the loop at once */
834
800
if(data->state.tempwrite && (tempsize - chunklen)) {
835
801
/* Ouch, the reading is again paused and the block we send is now
836
802
"cached". If this is the final chunk we can leave it like this, but
837
if we have more chunks that is cached after this, we need to free
803
if we have more chunks that are cached after this, we need to free
838
804
the newly cached one and put back a version that is truly the entire
839
805
contents that is saved for later
843
free(data->state.tempwrite); /* free the one just cached as it isn't
846
809
/* note that tempsize is still the size as before the callback was
847
810
used, and thus the whole piece of data to keep */
848
newptr = malloc(tempsize);
811
newptr = realloc(data->state.tempwrite, tempsize);
814
free(data->state.tempwrite); /* free old area */
815
data->state.tempwrite = NULL;
850
816
result = CURLE_OUT_OF_MEMORY;
851
817
/* tempwrite will be freed further down */
966
933
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
967
CURL_ICONV_CODESET_OF_HOST,
968
CURL_ICONV_CODESET_OF_NETWORK,
969
error, strerror(error));
934
CURL_ICONV_CODESET_OF_HOST,
935
CURL_ICONV_CODESET_OF_NETWORK,
936
error, strerror(error));
970
937
return CURLE_CONV_FAILED;
1027
994
"The iconv_open(\"%s\", \"%s\") call failed with errno %i: %s",
1028
CURL_ICONV_CODESET_OF_HOST,
1029
CURL_ICONV_CODESET_FOR_UTF8,
1030
error, strerror(error));
995
CURL_ICONV_CODESET_OF_HOST,
996
CURL_ICONV_CODESET_FOR_UTF8,
997
error, strerror(error));
1031
998
return CURLE_CONV_FAILED;
1039
1006
if((rc == ICONV_ERROR) || (in_bytes != 0)) {
1042
"The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
1043
error, strerror(error));
1009
"The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
1010
error, strerror(error));
1044
1011
return CURLE_CONV_FAILED;
1046
1013
if(output_ptr < input_ptr) {