222
222
Curl_cstrdup = (curl_strdup_callback)system_strdup;
223
223
Curl_ccalloc = (curl_calloc_callback)calloc;
225
if (flags & CURL_GLOBAL_SSL)
226
if (!Curl_ssl_init()) {
225
if(flags & CURL_GLOBAL_SSL)
226
if(!Curl_ssl_init()) {
227
227
DEBUGF(fprintf(stderr, "Error: Curl_ssl_init failed\n"));
228
228
return CURLE_FAILED_INIT;
231
if (flags & CURL_GLOBAL_WIN32)
232
if (win32_init() != CURLE_OK) {
231
if(flags & CURL_GLOBAL_WIN32)
232
if(win32_init() != CURLE_OK) {
233
233
DEBUGF(fprintf(stderr, "Error: win32_init failed\n"));
234
234
return CURLE_FAILED_INIT;
466
466
return CURLE_BAD_FUNCTION_ARGUMENT;
468
if ( ! (data->share && data->share->hostcache) ) {
470
if (Curl_global_host_cache_use(data) &&
471
(data->dns.hostcachetype != HCACHE_GLOBAL)) {
472
if (data->dns.hostcachetype == HCACHE_PRIVATE)
468
if( ! (data->share && data->share->hostcache) ) {
469
/* this handle is not using a shared dns cache */
471
if(data->set.global_dns_cache &&
472
(data->dns.hostcachetype != HCACHE_GLOBAL)) {
473
/* global dns cache was requested but still isn't */
474
struct curl_hash *ptr;
476
if(data->dns.hostcachetype == HCACHE_PRIVATE)
477
/* if the current cache is private, kill it first */
473
478
Curl_hash_destroy(data->dns.hostcache);
474
data->dns.hostcache = Curl_global_host_cache_get();
475
data->dns.hostcachetype = HCACHE_GLOBAL;
480
ptr = Curl_global_host_cache_init();
482
/* only do this if the global cache init works */
483
data->dns.hostcache = ptr;
484
data->dns.hostcachetype = HCACHE_GLOBAL;
478
if (!data->dns.hostcache) {
488
if(!data->dns.hostcache) {
479
489
data->dns.hostcachetype = HCACHE_PRIVATE;
480
490
data->dns.hostcache = Curl_mk_dnscache();
744
754
data->set.new_directory_perms = 0755; /* Default permissions */
758
* curl_easy_pause() allows an application to pause or unpause a specific
759
* transfer and direction. This function sets the full new state for the
760
* current connection this easy handle operates on.
762
* NOTE: if you have the receiving paused and you call this function to remove
763
* the pausing, you may get your write callback called at this point.
765
* Action is a bitmask consisting of CURLPAUSE_* bits in curl/curl.h
767
CURLcode curl_easy_pause(CURL *curl, int action)
769
struct SessionHandle *data = (struct SessionHandle *)curl;
770
struct SingleRequest *k = &data->req;
771
CURLcode result = CURLE_OK;
773
/* first switch off both pause bits */
774
int newstate = k->keepon &~ (KEEP_READ_PAUSE| KEEP_WRITE_PAUSE);
776
/* set the new desired pause bits */
777
newstate |= ((action & CURLPAUSE_RECV)?KEEP_READ_PAUSE:0) |
778
((action & CURLPAUSE_SEND)?KEEP_WRITE_PAUSE:0);
780
/* put it back in the keepon */
781
k->keepon = newstate;
783
if(!(newstate & KEEP_READ_PAUSE) && data->state.tempwrite) {
784
/* we have a buffer for writing that we now seem to be able to deliver since
785
the receive pausing is lifted! */
787
/* get the pointer, type and length in local copies since the function may
788
return PAUSE again and then we'll get a new copy allocted and stored in
789
the tempwrite variables */
790
char *tempwrite = data->state.tempwrite;
791
size_t tempsize = data->state.tempwritesize;
792
int temptype = data->state.tempwritetype;
795
/* clear tempwrite here just to make sure it gets cleared if there's no
796
further use of it, and make sure we don't clear it after the function
797
invoke as it may have been set to a new value by then */
798
data->state.tempwrite = NULL;
800
/* since the write callback API is define to never exceed
801
CURL_MAX_WRITE_SIZE bytes in a single call, and since we may in fact
802
have more data than that in our buffer here, we must loop sending the
803
data in multiple calls until there's no data left or we get another
806
A tricky part is that the function we call will "buffer" the data
807
itself when it pauses on a particular buffer, so we may need to do some
808
extra trickery if we get a pause return here.
811
chunklen = (tempsize > CURL_MAX_WRITE_SIZE)?CURL_MAX_WRITE_SIZE:tempsize;
813
result = Curl_client_write(data->state.current_conn,
814
temptype, tempwrite, chunklen);
816
/* failures abort the loop at once */
819
if(data->state.tempwrite && (tempsize - chunklen)) {
820
/* Ouch, the reading is again paused and the block we send is now
821
"cached". If this is the final chunk we can leave it like this, but
822
if we have more chunks that is cached after this, we need to free
823
the newly cached one and put back a version that is truly the entire
824
contents that is saved for later
828
free(data->state.tempwrite); /* free the one just cached as it isn't
831
/* note that tempsize is still the size as before the callback was
832
used, and thus the whole piece of data to keep */
833
newptr = malloc(tempsize);
835
result = CURLE_OUT_OF_MEMORY;
836
/* tempwrite will be freed further down */
839
data->state.tempwrite = newptr; /* store new pointer */
840
memcpy(newptr, tempwrite, tempsize);
841
data->state.tempwritesize = tempsize; /* store new size */
842
/* tempwrite will be freed further down */
843
break; /* go back to pausing until further notice */
846
tempsize -= chunklen; /* left after the call above */
847
tempwrite += chunklen; /* advance the pointer */
850
} while((result == CURLE_OK) && tempsize);
852
free(tempwrite); /* this is unconditionally no longer used */
747
858
#ifdef CURL_DOES_CONVERSIONS
749
860
* Curl_convert_to_network() is an internal function
910
1021
in_bytes = out_bytes = length;
911
1022
rc = iconv(data->utf8_cd, &input_ptr, &in_bytes,
912
1023
&output_ptr, &out_bytes);
913
if ((rc == ICONV_ERROR) || (in_bytes != 0)) {
1024
if((rc == ICONV_ERROR) || (in_bytes != 0)) {
916
1027
"The Curl_convert_from_utf8 iconv call failed with errno %i: %s",
917
1028
error, strerror(error));
918
1029
return CURLE_CONV_FAILED;
920
if (output_ptr < input_ptr) {
1031
if(output_ptr < input_ptr) {
921
1032
/* null terminate the now shorter output string */
922
1033
*output_ptr = 0x00;