Newer
Older
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
Daniel Stenberg
committed
* Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
***************************************************************************/
#include "setup.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <time.h>
#include <io.h>
#else
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#endif
#ifdef HAVE_SYS_TIME_H
#ifdef HAVE_NETDB_H
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#ifdef HAVE_NET_IF_H
#include <net/if.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#endif
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
Daniel Stenberg
committed
#ifdef HAVE_SETJMP_H
#include <setjmp.h>
#endif
#ifndef HAVE_SOCKET
#error "We can't compile without socket() support!"
#endif
#endif /* WIN32 */
#ifdef USE_LIBIDN
#include <idna.h>
#include <stringprep.h>
#ifdef HAVE_IDN_FREE_H
#include <idn-free.h>
#else
Daniel Stenberg
committed
void idn_free (void *ptr); /* prototype from idn-free.h, not provided by
libidn 0.4.5's make install! */
#endif
#ifndef HAVE_IDN_FREE
/* if idn_free() was not found in this version of libidn, use plain free()
instead */
#define idn_free(x) (free)(x)
#endif
#include "urldata.h"
#include "netrc.h"
#include "formdata.h"
Daniel Stenberg
committed
#include "sslgen.h"
Daniel Stenberg
committed
#include "transfer.h"
#include "sendf.h"
#include "progress.h"
#include "cookie.h"
#include "strerror.h"
#include "escape.h"
Daniel Stenberg
committed
#include "content_encoding.h"
#include "http_negotiate.h"
Daniel Stenberg
committed
#include "multiif.h"
#include "easyif.h"
Daniel Stenberg
committed
#include "speedcheck.h"
/* And now for the protocols */
#include "ftp.h"
#include "dict.h"
#include "telnet.h"
#include "tftp.h"
Daniel Stenberg
committed
#include "curl_ldap.h"
Daniel Stenberg
committed
#include "url.h"
#include "inet_ntop.h"
Daniel Stenberg
committed
#include "socks.h"
Daniel Stenberg
committed
#include <ca-bundle.h>
#if defined(HAVE_INET_NTOA_R) && !defined(HAVE_INET_NTOA_R_DECL)
#include "inet_ntoa_r.h"
#endif
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
#include "memory.h"
Daniel Stenberg
committed
/* The last #include file should be: */
#include "memdebug.h"
/* Local static prototypes */
static long ConnectionKillOne(struct SessionHandle *data);
Daniel Stenberg
committed
static bool ConnectionExists(struct SessionHandle *data,
struct connectdata *needle,
struct connectdata **usethis);
static long ConnectionStore(struct SessionHandle *data,
struct connectdata *conn);
static bool IsPipeliningPossible(const struct SessionHandle *handle);
static bool IsPipeliningEnabled(const struct SessionHandle *handle);
static void conn_free(struct connectdata *conn);
static void signalPipeClose(struct curl_llist *pipeline);
static struct SessionHandle* gethandleathead(struct curl_llist *pipeline);
Daniel Stenberg
committed
static CURLcode do_init(struct connectdata *conn);
static void do_complete(struct connectdata *conn);
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
static void flush_cookies(struct SessionHandle *data, int cleanup);
#endif
#ifdef CURL_DISABLE_VERBOSE_STRINGS
#define verboseconnect(x) do { } while (0)
#endif
#define MAX_PIPELINE_LENGTH 5
Daniel Stenberg
committed
#ifndef USE_ARES
/* not for ares builds */
#ifndef WIN32
/* not for WIN32 builds */
Daniel Stenberg
committed
#ifdef HAVE_SIGSETJMP
#endif
#ifdef SIGALRM
static
RETSIGTYPE alarmfunc(int sig)
{
/* this is for "-ansi -Wall -pedantic" to stop complaining! (rabe) */
(void)sig;
#ifdef HAVE_SIGSETJMP
siglongjmp(curl_jmpenv, 1);
#endif
return;
}
#endif /* SIGALRM */
#endif /* WIN32 */
#endif /* USE_ARES */
Patrick Monnerat
committed
/*
* Protocol table.
*/
static const struct Curl_handler * const protocols[] = {
Patrick Monnerat
committed
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#ifndef CURL_DISABLE_HTTP
&Curl_handler_http,
#endif
#if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
&Curl_handler_https,
#endif
#ifndef CURL_DISABLE_FTP
&Curl_handler_ftp,
#endif
#if defined(USE_SSL) && !defined(CURL_DISABLE_FTP)
&Curl_handler_ftps,
#endif
#ifndef CURL_DISABLE_TELNET
&Curl_handler_telnet,
#endif
#ifndef CURL_DISABLE_DICT
&Curl_handler_dict,
#endif
#ifndef CURL_DISABLE_LDAP
&Curl_handler_ldap,
#endif
#if !defined(CURL_DISABLE_LDAP) && defined(HAVE_LDAP_SSL)
Patrick Monnerat
committed
&Curl_handler_ldaps,
#endif
#ifndef CURL_DISABLE_FILE
&Curl_handler_file,
#endif
#ifndef CURL_DISABLE_TFTP
&Curl_handler_tftp,
#endif
#ifdef USE_LIBSSH2
&Curl_handler_scp,
&Curl_handler_sftp,
#endif
(struct Curl_handler *) NULL
};
/*
* Dummy handler for undefined protocol schemes.
*/
static const struct Curl_handler Curl_handler_dummy = {
Patrick Monnerat
committed
"<no protocol>", /* scheme */
ZERO_NULL, /* setup_connection */
ZERO_NULL, /* do_it */
ZERO_NULL, /* done */
ZERO_NULL, /* do_more */
ZERO_NULL, /* connect_it */
ZERO_NULL, /* connecting */
ZERO_NULL, /* doing */
ZERO_NULL, /* proto_getsock */
ZERO_NULL, /* doing_getsock */
ZERO_NULL, /* disconnect */
Patrick Monnerat
committed
0, /* defport */
0 /* protocol */
};
void Curl_safefree(void *ptr)
{
if(ptr)
free(ptr);
}
static void close_connections(struct SessionHandle *data)
{
/* Loop through all open connections and kill them one by one */
while(-1 != ConnectionKillOne(data))
; /* empty loop */
}
Daniel Stenberg
committed
void Curl_freeset(struct SessionHandle * data)
{
/* Free all dynamic strings stored in the data->set substructure. */
enum dupstring i;
for(i=(enum dupstring)0; i < STRING_LAST; i++)
Daniel Stenberg
committed
Curl_safefree(data->set.str[i]);
}
static CURLcode setstropt(char **charp, char * s)
Daniel Stenberg
committed
{
/* Release the previous storage at `charp' and replace by a dynamic storage
copy of `s'. Return CURLE_OK or CURLE_OUT_OF_MEMORY. */
Daniel Stenberg
committed
if(*charp) {
Daniel Stenberg
committed
free(*charp);
*charp = (char *) NULL;
}
Daniel Stenberg
committed
if(s) {
Daniel Stenberg
committed
s = strdup(s);
Daniel Stenberg
committed
if(!s)
Daniel Stenberg
committed
return CURLE_OUT_OF_MEMORY;
*charp = s;
}
return CURLE_OK;
}
CURLcode Curl_dupset(struct SessionHandle * dst, struct SessionHandle * src)
{
Daniel Stenberg
committed
enum dupstring i;
/* Copy src->set into dst->set first, then deal with the strings
afterwards */
dst->set = src->set;
/* clear all string pointers first */
memset(dst->set.str, 0, STRING_LAST * sizeof(char *));
/* duplicate all strings */
for(i=(enum dupstring)0; i< STRING_LAST; i++) {
r = setstropt(&dst->set.str[i], src->set.str[i]);
Daniel Stenberg
committed
if(r != CURLE_OK)
Daniel Stenberg
committed
break;
}
/* If a failure occurred, freeing has to be performed externally. */
return r;
}
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
static void flush_cookies(struct SessionHandle *data, int cleanup)
{
Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
if(data->set.str[STRING_COOKIEJAR]) {
if(data->change.cookielist) {
/* If there is a list of cookie files to read, do it first so that
we have all the told files read before we write the new jar */
Curl_cookie_loadfiles(data);
}
/* if we have a destination file for all the cookies to get dumped to */
if(Curl_cookie_output(data->cookies, data->set.str[STRING_COOKIEJAR]))
infof(data, "WARNING: failed to save cookies in %s\n",
data->set.str[STRING_COOKIEJAR]);
}
else {
if(cleanup && data->change.cookielist)
/* since nothing is written, we can just free the list of cookie file
names */
curl_slist_free_all(data->change.cookielist); /* clean up list */
}
if(cleanup && (!data->share || (data->cookies != data->share->cookies))) {
Curl_cookie_cleanup(data->cookies);
}
Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
}
#endif
/*
* This is the internal function curl_easy_cleanup() calls. This should
* cleanup and free all resources associated with this sessionhandle.
*
* NOTE: if we ever add something that attempts to write to a socket or
* similar here, we must ignore SIGPIPE first. It is currently only done
* when curl_easy_perform() is invoked.
*/
Daniel Stenberg
committed
CURLcode Curl_close(struct SessionHandle *data)
struct Curl_multi *m = data->multi;
Daniel Stenberg
committed
#ifdef CURLDEBUG
/* only for debugging, scan through all connections and see if there's a
pipe reference still identifying this handle */
if(data->state.is_in_pipeline)
fprintf(stderr, "CLOSED when in pipeline!\n");
if(data->state.connc && data->state.connc->type == CONNCACHE_MULTI) {
struct conncache *c = data->state.connc;
struct curl_llist *pipeline;
Daniel Stenberg
committed
struct curl_llist_element *curr;
struct connectdata *connptr;
for(i=0; i< c->num; i++) {
connptr = c->connects[i];
if(!connptr)
continue;
pipeline = connptr->send_pipe;
if(pipeline) {
for (curr = pipeline->head; curr; curr=curr->next) {
Daniel Stenberg
committed
if(data == (struct SessionHandle *) curr->ptr) {
fprintf(stderr,
"MAJOR problem we %p are still in send pipe for %p done %d\n",
data, connptr, connptr->bits.done);
}
}
}
pipeline = connptr->recv_pipe;
if(pipeline) {
for (curr = pipeline->head; curr; curr=curr->next) {
Daniel Stenberg
committed
if(data == (struct SessionHandle *) curr->ptr) {
fprintf(stderr,
"MAJOR problem we %p are still in recv pipe for %p done %d\n",
data, connptr, connptr->bits.done);
}
}
}
}
}
#endif
if(m)
/* This handle is still part of a multi handle, take care of this first
and detach this handle from there. */
Daniel Stenberg
committed
Curl_multi_rmeasy(data->multi, data);
Daniel Stenberg
committed
data->magic = 0; /* force a clear AFTER the possibly enforced removal from
the multi handle, since that function uses the magic
field! */
Daniel Stenberg
committed
if(data->state.connc) {
Daniel Stenberg
committed
if(data->state.connc->type == CONNCACHE_PRIVATE) {
/* close all connections still alive that are in the private connection
cache, as we no longer have the pointer left to the shared one. */
close_connections(data);
Daniel Stenberg
committed
/* free the connection cache if allocated privately */
Curl_rm_connc(data->state.connc);
Daniel Stenberg
committed
}
}
if(data->state.shared_conn) {
Daniel Stenberg
committed
/* marked to be used by a pending connection so we can't kill this handle
just yet */
data->state.closed = TRUE;
return CURLE_OK;
}
Daniel Stenberg
committed
if( ! (data->share && data->share->hostcache) ) {
if( !Curl_global_host_cache_use(data)) {
Daniel Stenberg
committed
Curl_hash_destroy(data->dns.hostcache);
}
}
Daniel Stenberg
committed
if(data->state.rangestringalloc)
free(data->state.range);
Daniel Stenberg
committed
/* Free the pathbuffer */
Daniel Stenberg
committed
Curl_safefree(data->state.pathbuffer);
Curl_safefree(data->state.proto.generic);
/* Close down all open SSL info and sessions */
Daniel Stenberg
committed
Curl_ssl_close_all(data);
Daniel Stenberg
committed
Curl_safefree(data->state.first_host);
Curl_safefree(data->state.scratch);
Daniel Stenberg
committed
if(data->change.referer_alloc)
free(data->change.referer);
Daniel Stenberg
committed
if(data->change.url_alloc)
free(data->change.url);
Curl_safefree(data->state.headerbuff);
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
flush_cookies(data, 1);
#endif
Curl_digest_cleanup(data);
Curl_safefree(data->info.contenttype);
Daniel Stenberg
committed
/* this destroys the channel and we cannot use it anymore after this */
ares_destroy(data->state.areschannel);
#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
/* close iconv conversion descriptors */
Daniel Stenberg
committed
if(data->inbound_cd != (iconv_t)-1) {
iconv_close(data->inbound_cd);
}
Daniel Stenberg
committed
if(data->outbound_cd != (iconv_t)-1) {
iconv_close(data->outbound_cd);
}
Daniel Stenberg
committed
if(data->utf8_cd != (iconv_t)-1) {
iconv_close(data->utf8_cd);
}
#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
Daniel Stenberg
committed
/* No longer a dirty share, if it exists */
Daniel Stenberg
committed
if(data->share) {
Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
Daniel Stenberg
committed
data->share->dirty--;
Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
}
Daniel Stenberg
committed
Daniel Stenberg
committed
Curl_freeset(data);
/* create a connection cache of a private or multi type */
struct conncache *Curl_mk_connc(int type,
{
/* It is subject for debate how many default connections to have for a multi
connection cache... */
struct conncache *c;
Daniel Stenberg
committed
if(type == CONNCACHE_PRIVATE) {
default_amount = (amount < 0) ? 5 : amount;
}
else {
default_amount = (amount < 0) ? 10 : amount;
}
c= calloc(sizeof(struct conncache), 1);
if(!c)
return NULL;
Daniel Stenberg
committed
if((size_t)(default_amount) > ((size_t)-1) / sizeof(struct connectdata *))
default_amount = ((size_t)-1) / sizeof(struct connectdata *);
c->connects = calloc(sizeof(struct connectdata *), (size_t)default_amount);
if(!c->connects) {
free(c);
return NULL;
}
c->num = default_amount;
return c;
}
/* Change number of entries of a connection cache */
CURLcode Curl_ch_connc(struct SessionHandle *data,
struct conncache *c,
long newamount)
{
struct connectdata **newptr;
if(newamount < 1)
newamount = 1; /* we better have at least one entry */
if(!c) {
/* we get a NULL pointer passed in as connection cache, which means that
there is no cache created for this SessionHandle just yet, we create a
brand new with the requested size.
*/
data->state.connc = Curl_mk_connc(CONNCACHE_PRIVATE, newamount);
if(!data->state.connc)
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
if(newamount < c->num) {
/* Since this number is *decreased* from the existing number, we must
close the possibly open connections that live on the indexes that
are being removed!
NOTE: for conncache_multi cases we must make sure that we only
close handles not in use.
*/
for(i=newamount; i< c->num; i++)
Curl_disconnect(c->connects[i]);
/* If the most recent connection is no longer valid, mark it
invalid. */
if(data->state.lastconnect <= newamount)
data->state.lastconnect = -1;
}
if(newamount > 0) {
newptr= (struct connectdata **)
realloc(c->connects, sizeof(struct connectdata *) * newamount);
if(!newptr)
/* we closed a few connections in vain, but so what? */
return CURLE_OUT_OF_MEMORY;
/* nullify the newly added pointers */
for(i=c->num; i<newamount; i++)
newptr[i] = NULL;
c->connects = newptr;
c->num = newamount;
}
/* we no longer support less than 1 as size for the connection cache, and
I'm not sure it ever worked to set it to zero */
return CURLE_OK;
}
/* Free a connection cache. This is called from Curl_close() and
curl_multi_cleanup(). */
void Curl_rm_connc(struct conncache *c)
{
if(c->connects) {
for(i = 0; i < c->num; ++i)
conn_free(c->connects[i]);
free(c->connects);
}
free(c);
}
Daniel Stenberg
committed
/**
* Curl_open()
*
* @param curl is a pointer to a sessionhandle pointer that gets set by this
* function.
* @return CURLcode
*/
Daniel Stenberg
committed
CURLcode Curl_open(struct SessionHandle **curl)
CURLcode res = CURLE_OK;
Daniel Stenberg
committed
struct SessionHandle *data;
/* Very simple start-up: alloc the struct, init it with zeroes and return */
Daniel Stenberg
committed
data = (struct SessionHandle *)calloc(1, sizeof(struct SessionHandle));
Daniel Stenberg
committed
/* this is a very serious error */
DEBUGF(fprintf(stderr, "Error: calloc of SessionHandle failed\n"));
Daniel Stenberg
committed
return CURLE_OUT_OF_MEMORY;
data->magic = CURLEASY_MAGIC_NUMBER;
Daniel Stenberg
committed
#ifdef USE_ARES
Daniel Stenberg
committed
if((status = ares_init(&data->state.areschannel)) != ARES_SUCCESS) {
DEBUGF(fprintf(stderr, "Error: ares_init failed\n"));
Daniel Stenberg
committed
free(data);
Daniel Stenberg
committed
if(status == ARES_ENOMEM)
return CURLE_OUT_OF_MEMORY;
else
return CURLE_FAILED_INIT;
Daniel Stenberg
committed
}
/* make sure that all other returns from this function should destroy the
ares channel before returning error! */
#endif
Daniel Stenberg
committed
/* We do some initial setup here, all those fields that can't be just 0 */
data->state.headerbuff=(char*)malloc(HEADERSIZE);
if(!data->state.headerbuff) {
DEBUGF(fprintf(stderr, "Error: malloc of headerbuff failed\n"));
res = CURLE_OUT_OF_MEMORY;
else {
data->state.headersize=HEADERSIZE;
data->set.out = stdout; /* default output to stdout */
data->set.in = stdin; /* default input from stdin */
data->set.err = stderr; /* default stderr to stderr */
/* use fwrite as default function to store output */
data->set.fwrite_func = (curl_write_callback)fwrite;
/* use fread as default function to read input */
data->set.fread_func = (curl_read_callback)fread;
Daniel Stenberg
committed
Daniel Stenberg
committed
/* don't use a seek function by default */
data->set.seek_func = ZERO_NULL;
data->set.seek_client = ZERO_NULL;
/* conversion callbacks for non-ASCII hosts */
data->set.convfromnetwork = ZERO_NULL;
data->set.convtonetwork = ZERO_NULL;
data->set.convfromutf8 = ZERO_NULL;
#if defined(CURL_DOES_CONVERSIONS) && defined(HAVE_ICONV)
/* conversion descriptors for iconv calls */
data->outbound_cd = (iconv_t)-1;
data->inbound_cd = (iconv_t)-1;
data->utf8_cd = (iconv_t)-1;
#endif /* CURL_DOES_CONVERSIONS && HAVE_ICONV */
data->set.infilesize = -1; /* we don't know any size */
Daniel Stenberg
committed
data->set.postfieldsize = -1;
data->set.maxredirs = -1; /* allow any amount by default */
data->state.current_speed = -1; /* init to negative == impossible */
data->set.httpreq = HTTPREQ_GET; /* Default HTTP request */
data->set.ftp_use_epsv = TRUE; /* FTP defaults to EPSV operations */
data->set.ftp_use_eprt = TRUE; /* FTP defaults to EPRT operations */
data->set.ftp_filemethod = FTPFILE_MULTICWD;
data->set.dns_cache_timeout = 60; /* Timeout every 60 seconds by default */
/* make libcurl quiet by default: */
data->set.hide_progress = TRUE; /* CURLOPT_NOPROGRESS changes these */
data->progress.flags |= PGRS_HIDE;
/* Set the default size of the SSL session ID cache */
data->set.ssl.numsessions = 5;
data->set.proxyport = 1080;
data->set.proxytype = CURLPROXY_HTTP; /* defaults to HTTP proxy */
data->set.httpauth = CURLAUTH_BASIC; /* defaults to basic */
data->set.proxyauth = CURLAUTH_BASIC; /* defaults to basic */
Daniel Stenberg
committed
/* This no longer creates a connection cache here. It is instead made on
the first call to curl_easy_perform() or when the handle is added to a
multi stack. */
data->set.ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
type */
data->set.new_file_perms = 0644; /* Default permissions */
data->set.new_directory_perms = 0755; /* Default permissions */
Daniel Stenberg
committed
/* most recent connection is not yet defined */
data->state.lastconnect = -1;
Curl_easy_initHandleData(data);
/*
* libcurl 7.10 introduced SSL verification *by default*! This needs to be
* switched off unless wanted.
*/
data->set.ssl.verifypeer = TRUE;
data->set.ssl.verifyhost = 2;
Daniel Stenberg
committed
data->set.ssl.sessionid = TRUE; /* session ID caching enabled by default */
#ifdef CURL_CA_BUNDLE
/* This is our preferred CA cert bundle since install time */
res = setstropt(&data->set.str[STRING_SSL_CAFILE],
Daniel Stenberg
committed
(char *) CURL_CA_BUNDLE);
#endif
}
if(res) {
ares_destroy(data->state.areschannel);
if(data->state.headerbuff)
free(data->state.headerbuff);
Daniel Stenberg
committed
Curl_freeset(data);
free(data);
data = NULL;
}
else
*curl = data;
CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
va_list param)
char *argptr;
Daniel Stenberg
committed
CURLcode result = CURLE_OK;
#ifndef CURL_DISABLE_HTTP
curl_off_t bigsize;
#endif
switch(option) {
Sterling Hughes
committed
case CURLOPT_DNS_CACHE_TIMEOUT:
data->set.dns_cache_timeout = va_arg(param, long);
Sterling Hughes
committed
break;
Sterling Hughes
committed
{
long use_cache = va_arg(param, long);
Daniel Stenberg
committed
if(use_cache)
Curl_global_host_cache_init();
}
break;
case CURLOPT_SSL_CIPHER_LIST:
/* set a list of cipher we want to use in the SSL connection */
result = setstropt(&data->set.str[STRING_SSL_CIPHER_LIST],
Daniel Stenberg
committed
va_arg(param, char *));
case CURLOPT_RANDOM_FILE:
/*
* This is the path name to a file that contains random data to seed
* the random SSL stuff with. The file is only used for reading.
*/
result = setstropt(&data->set.str[STRING_SSL_RANDOM_FILE],
Daniel Stenberg
committed
va_arg(param, char *));
break;
case CURLOPT_EGDSOCKET:
/*
* The Entropy Gathering Daemon socket pathname
*/
result = setstropt(&data->set.str[STRING_SSL_EGDSOCKET],
Daniel Stenberg
committed
va_arg(param, char *));
break;
case CURLOPT_MAXCONNECTS:
/*
* Set the absolute number of maximum simultaneous alive connection that
* libcurl is allowed to have.
*/
result = Curl_ch_connc(data, data->state.connc, va_arg(param, long));
break;
case CURLOPT_FORBID_REUSE:
/*
* When this transfer is done, it must not be left to be reused by a
* subsequent transfer but shall be closed immediately.
*/
data->set.reuse_forbid = (bool)(0 != va_arg(param, long));
break;
case CURLOPT_FRESH_CONNECT:
/*
* This transfer shall not use a previously cached connection but
* should be made with a fresh new connect!
*/
data->set.reuse_fresh = (bool)(0 != va_arg(param, long));
/*
* Verbose means infof() calls that give a lot of information about
* the connection and transfer procedures as well as internal choices.
*/
/*
* Set to include the header in the general data output stream.
*/
data->set.include_header = (bool)(0 != va_arg(param, long));
/*
* Shut off the internal supported progress meter
*/
data->set.hide_progress = (bool)(0 != va_arg(param, long));
Daniel Stenberg
committed
if(data->set.hide_progress)
else
data->progress.flags &= ~PGRS_HIDE;
/*
* Do not include the body part in the output data stream.
*/
data->set.opt_no_body = (bool)(0 != va_arg(param, long));
if(data->set.opt_no_body)
/* in HTTP lingo, this means using the HEAD request */
data->set.httpreq = HTTPREQ_HEAD;
break;
case CURLOPT_FAILONERROR:
/*
* Don't output the >=300 error code HTML-page, but instead only
* return error.
*/
data->set.http_fail_on_error = (bool)(0 != va_arg(param, long));
case CURLOPT_PUT:
* We want to sent data to the remote host. If this is HTTP, that equals
* using the PUT request.
Daniel Stenberg
committed
if(data->set.upload)
/* If this is HTTP, PUT is what's needed to "upload" */
Daniel Stenberg
committed
data->set.httpreq = HTTPREQ_PUT;
/*
* Try to get the file time of the remote document. The time will
* later (possibly) become available using curl_easy_getinfo().
*/
data->set.get_filetime = (bool)(0 != va_arg(param, long));
case CURLOPT_FTP_CREATE_MISSING_DIRS:
/*
* An FTP option that modifies an upload to create missing directories on
* the server.
data->set.ftp_create_missing_dirs = (bool)(0 != va_arg(param, long));
break;
case CURLOPT_FTP_RESPONSE_TIMEOUT:
/*
* An FTP option that specifies how quickly an FTP response must be
* obtained before it is considered failure.
*/
Daniel Stenberg
committed
data->set.ftp_response_timeout = va_arg( param , long ) * 1000;
case CURLOPT_DIRLISTONLY:
* An option that changes the command to one that asks for a list
* only, no file info details.
*/
data->set.ftp_list_only = (bool)(0 != va_arg(param, long));
case CURLOPT_APPEND:
* We want to upload and append to an existing file.
data->set.ftp_append = (bool)(0 != va_arg(param, long));
case CURLOPT_FTP_FILEMETHOD:
/*
* How do access files over FTP.
*/
data->set.ftp_filemethod = (curl_ftpfile)va_arg(param, long);
/*
* Parse the $HOME/.netrc file
*/
data->set.use_netrc = (enum CURL_NETRC_OPTION)va_arg(param, long);
case CURLOPT_NETRC_FILE:
/*
* Use this file instead of the $HOME/.netrc file
*/
result = setstropt(&data->set.str[STRING_NETRC_FILE],
Daniel Stenberg
committed
va_arg(param, char *));
case CURLOPT_TRANSFERTEXT:
* This option was previously named 'FTPASCII'. Renamed to work with
* more protocols than merely FTP.
*
* Transfer using ASCII (instead of BINARY).
data->set.prefer_ascii = (bool)(0 != va_arg(param, long));
break;
case CURLOPT_TIMECONDITION:
/*
* Set HTTP time condition. This must be one of the defines in the
* curl/curl.h header file.
*/
data->set.timecondition = (curl_TimeCond)va_arg(param, long);
/*
* This is the value to compare with the remote document with the
* method set with CURLOPT_TIMECONDITION
*/
data->set.timevalue = (time_t)va_arg(param, long);
/*
* Set explicit SSL version to try to connect with, as some SSL
* implementations are lame.
*/
Daniel Stenberg
committed
data->set.ssl.version = va_arg(param, long);
#ifndef CURL_DISABLE_HTTP
case CURLOPT_AUTOREFERER:
* Switch on automatic referer that gets set if curl follows locations.
data->set.http_auto_referer = (bool)(0 != va_arg(param, long));
case CURLOPT_ENCODING:
* String to use at the value of Accept-Encoding header.
*
* If the encoding is set to "" we use an Accept-Encoding header that
* encompasses all the encodings we support.
* If the encoding is set to NULL we don't send an Accept-Encoding header
* and ignore an received Content-Encoding header.
*
Daniel Stenberg
committed
argptr = va_arg(param, char *);
result = setstropt(&data->set.str[STRING_ENCODING],
Daniel Stenberg
committed
(argptr && !*argptr)?
(char *) ALL_CONTENT_ENCODINGS: argptr);
break;
case CURLOPT_FOLLOWLOCATION:
* Follow Location: header hints on a HTTP-server.
data->set.http_follow_location = (bool)(0 != va_arg(param, long));
case CURLOPT_UNRESTRICTED_AUTH:
* Send authentication (user+password) when following locations, even when
* hostname changed.
data->set.http_disable_hostname_check_before_authentication =
case CURLOPT_MAXREDIRS:
* The maximum amount of hops you allow curl to follow Location:
* headers. This should mostly be used to detect never-ending loops.
data->set.maxredirs = va_arg(param, long);
case CURLOPT_POST301:
/*
* Obey RFC 2616/10.3.2 and resubmit a POST as a POST after a 301.
*/
data->set.post301 = (bool)(0 != va_arg(param, long));
break;
case CURLOPT_POST:
/* Does this option serve a purpose anymore? Yes it does, when
CURLOPT_POSTFIELDS isn't used and the POST data is read off the
callback! */
Daniel Stenberg
committed
if(va_arg(param, long)) {
data->set.httpreq = HTTPREQ_POST;
Daniel Stenberg
committed
data->set.opt_no_body = FALSE; /* this is implied */
}
else
data->set.httpreq = HTTPREQ_GET;
case CURLOPT_COPYPOSTFIELDS:
Daniel Stenberg
committed
* A string with POST data. Makes curl HTTP POST. Even if it is NULL.
* If needed, CURLOPT_POSTFIELDSIZE must have been set prior to
* CURLOPT_COPYPOSTFIELDS and not altered later.
argptr = va_arg(param, char *);
Daniel Stenberg
committed
if(!argptr || data->set.postfieldsize == -1)
result = setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
* Check that requested length does not overflow the size_t type.
Daniel Stenberg
committed
if((data->set.postfieldsize < 0) ||
((sizeof(curl_off_t) != sizeof(size_t)) &&
(data->set.postfieldsize > (curl_off_t)((size_t)-1))))
result = CURLE_OUT_OF_MEMORY;
else {
char * p;
(void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
/* Allocate even when size == 0. This satisfies the need of possible
later address compare to detect the COPYPOSTFIELDS mode, and
to mark that postfields is used rather than read function or
form data.
*/
p = malloc((size_t)(data->set.postfieldsize?data->set.postfieldsize:1));
Daniel Stenberg
committed
if(!p)
result = CURLE_OUT_OF_MEMORY;
else {
Daniel Stenberg
committed
if(data->set.postfieldsize)
memcpy(p, argptr, (size_t)data->set.postfieldsize);
data->set.str[STRING_COPYPOSTFIELDS] = p;
}
}
data->set.postfields = data->set.str[STRING_COPYPOSTFIELDS];
data->set.httpreq = HTTPREQ_POST;
break;
case CURLOPT_POSTFIELDS:
/*
* Like above, but use static data instead of copying it.
*/
data->set.postfields = va_arg(param, void *);
/* Release old copied data. */
(void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
Daniel Stenberg
committed
data->set.httpreq = HTTPREQ_POST;
case CURLOPT_POSTFIELDSIZE:
* The size of the POSTFIELD data to prevent libcurl to do strlen() to
* figure it out. Enables binary posts.
bigsize = va_arg(param, long);
Daniel Stenberg
committed
if(data->set.postfieldsize < bigsize &&
data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
/* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
(void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
data->set.postfields = NULL;
}
data->set.postfieldsize = bigsize;
break;
case CURLOPT_POSTFIELDSIZE_LARGE:
* The size of the POSTFIELD data to prevent libcurl to do strlen() to
* figure it out. Enables binary posts.
bigsize = va_arg(param, curl_off_t);
Daniel Stenberg
committed
if(data->set.postfieldsize < bigsize &&
data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
/* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
(void) setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
data->set.postfields = NULL;
}
data->set.postfieldsize = bigsize;
/*
* Set to make us do HTTP POST
*/
data->set.httppost = va_arg(param, struct curl_httppost *);
Daniel Stenberg
committed
data->set.httpreq = HTTPREQ_POST_FORM;
Daniel Stenberg
committed
data->set.opt_no_body = FALSE; /* this is implied */
case CURLOPT_REFERER:
* String to set in the HTTP Referer: field.
if(data->change.referer_alloc) {
free(data->change.referer);
data->change.referer_alloc = FALSE;
}
result = setstropt(&data->set.str[STRING_SET_REFERER],
Daniel Stenberg
committed
va_arg(param, char *));
data->change.referer = data->set.str[STRING_SET_REFERER];
case CURLOPT_USERAGENT:
* String to use in the HTTP User-Agent field
result = setstropt(&data->set.str[STRING_USERAGENT],
Daniel Stenberg
committed
va_arg(param, char *));
case CURLOPT_HTTPHEADER:
* Set a list with HTTP headers to use (or replace internals with)
data->set.headers = va_arg(param, struct curl_slist *);
case CURLOPT_HTTP200ALIASES:
* Set a list of aliases for HTTP 200 in response header
data->set.http200aliases = va_arg(param, struct curl_slist *);
#if !defined(CURL_DISABLE_COOKIES)
case CURLOPT_COOKIE:
* Cookie string to send to the remote server in the request.
result = setstropt(&data->set.str[STRING_COOKIE],
Daniel Stenberg
committed
va_arg(param, char *));
case CURLOPT_COOKIEFILE:
* Set cookie file to read and parse. Can be used multiple times.
argptr = (char *)va_arg(param, void *);
if(argptr) {
struct curl_slist *cl;
/* append the cookie file name to the list of file names, and deal with
them later */
cl = curl_slist_append(data->change.cookielist, argptr);
if(!cl)
return CURLE_OUT_OF_MEMORY;
data->change.cookielist = cl; /* store the list for later use */
}
case CURLOPT_COOKIEJAR:
* Set cookie file name to dump all cookies to when we're done.
result = setstropt(&data->set.str[STRING_COOKIEJAR],
Daniel Stenberg
committed
va_arg(param, char *));
* Activate the cookie parser. This may or may not already
* have been made.
data->cookies = Curl_cookie_init(data, NULL, data->cookies,
data->set.cookiesession);
break;
case CURLOPT_COOKIESESSION:
* Set this option to TRUE to start a new "cookie session". It will
* prevent the forthcoming read-cookies-from-file actions to accept
* cookies that are marked as being session cookies, as they belong to a
* previous session.
*
* In the original Netscape cookie spec, "session cookies" are cookies
* with no expire date set. RFC2109 describes the same action if no
* 'Max-Age' is set and RFC2965 includes the RFC2109 description and adds
* a 'Discard' action that can enforce the discard even for cookies that
* have a Max-Age.
*
* We run mostly with the original cookie spec, as hardly anyone implements
* anything else.
data->set.cookiesession = (bool)(0 != va_arg(param, long));
Daniel Stenberg
committed
case CURLOPT_COOKIELIST:
argptr = va_arg(param, char *);
Daniel Stenberg
committed
if(argptr == NULL)
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
if(strequal(argptr, "ALL")) {
/* clear all cookies */
Curl_cookie_clearall(data->cookies);
break;
}
else if(strequal(argptr, "SESS")) {
/* clear session cookies */
Curl_cookie_clearsess(data->cookies);
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
}
else if(strequal(argptr, "FLUSH")) {
/* flush cookies to file */
flush_cookies(data, 0);
break;
}
Daniel Stenberg
committed
Daniel Stenberg
committed
if(!data->cookies)
Daniel Stenberg
committed
/* if cookie engine was not running, activate it */
data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE);
Daniel Stenberg
committed
argptr = strdup(argptr);
if(!argptr) {
result = CURLE_OUT_OF_MEMORY;
break;
}
if(checkprefix("Set-Cookie:", argptr))
Daniel Stenberg
committed
/* HTTP Header format line */
Curl_cookie_add(data, data->cookies, TRUE, argptr + 11, NULL, NULL);
else
/* Netscape format line */
Curl_cookie_add(data, data->cookies, FALSE, argptr, NULL, NULL);
Daniel Stenberg
committed
free(argptr);
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
#endif /* CURL_DISABLE_COOKIES */
case CURLOPT_HTTPGET:
* Set to force us do HTTP GET
if(va_arg(param, long)) {
data->set.httpreq = HTTPREQ_GET;
data->set.upload = FALSE; /* switch off upload */
Daniel Stenberg
committed
data->set.opt_no_body = FALSE; /* this is implied */
}
case CURLOPT_HTTP_VERSION:
/*
* This sets a requested HTTP version to be used. The value is one of
* the listed enums in curl/curl.h.
*/
data->set.httpversion = va_arg(param, long);
break;
case CURLOPT_HTTPPROXYTUNNEL:
* Tunnel operations through the proxy instead of normal proxy use
data->set.tunnel_thru_httpproxy = (bool)(0 != va_arg(param, long));
case CURLOPT_CUSTOMREQUEST:
* Set a custom string to use as request
result = setstropt(&data->set.str[STRING_CUSTOMREQUEST],
Daniel Stenberg
committed
va_arg(param, char *));
/* we don't set
data->set.httpreq = HTTPREQ_CUSTOM;
here, we continue as if we were using the already set type
and this just changes the actual request keyword */
/*
* Explicitly set HTTP proxy port number.
*/
Daniel Stenberg
committed
data->set.proxyport = va_arg(param, long);
case CURLOPT_HTTPAUTH:
/*
* Set HTTP Authentication type BITMASK.
*/
{
long auth = va_arg(param, long);
/* switch off bits we can't support */
Daniel Stenberg
committed
#ifndef USE_NTLM
auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */
#endif
#ifndef HAVE_GSSAPI
auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI */
#endif
if(!auth)
return CURLE_FAILED_INIT; /* no supported types left! */
data->set.httpauth = auth;
}
break;
case CURLOPT_PROXYAUTH:
/*
* Set HTTP Authentication type BITMASK.
*/
{
long auth = va_arg(param, long);
/* switch off bits we can't support */
Daniel Stenberg
committed
#ifndef USE_NTLM
auth &= ~CURLAUTH_NTLM; /* no NTLM without SSL */
#endif
#ifndef HAVE_GSSAPI
auth &= ~CURLAUTH_GSSNEGOTIATE; /* no GSS-Negotiate without GSSAPI */
#endif
if(!auth)
return CURLE_FAILED_INIT; /* no supported types left! */
data->set.proxyauth = auth;
}
break;
#endif /* CURL_DISABLE_HTTP */
Daniel Stenberg
committed
case CURLOPT_PROXY:
/*
* Set proxy server:port to use as HTTP proxy.
*
* If the proxy is set to "" we explicitly say that we don't want to use a
* proxy (even though there might be environment variables saying so).
*
* Setting it to NULL, means no proxy but allows the environment variables
* to decide for us.
*/
result = setstropt(&data->set.str[STRING_PROXY],
Daniel Stenberg
committed
va_arg(param, char *));
Daniel Stenberg
committed
break;
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
case CURLOPT_WRITEHEADER:
/*
* Custom pointer to pass the header write callback function
*/
data->set.writeheader = (void *)va_arg(param, void *);
break;
case CURLOPT_ERRORBUFFER:
/*
* Error buffer provided by the caller to get the human readable
* error string in.
*/
data->set.errorbuffer = va_arg(param, char *);
break;
case CURLOPT_FILE:
/*
* FILE pointer to write to or include in the data write callback
*/
data->set.out = va_arg(param, FILE *);
break;
case CURLOPT_FTPPORT:
/*
* Use FTP PORT, this also specifies which IP address to use
*/
result = setstropt(&data->set.str[STRING_FTPPORT],
Daniel Stenberg
committed
va_arg(param, char *));
data->set.ftp_use_port = (bool)(NULL != data->set.str[STRING_FTPPORT]);
break;
case CURLOPT_FTP_USE_EPRT:
data->set.ftp_use_eprt = (bool)(0 != va_arg(param, long));
break;
case CURLOPT_FTP_USE_EPSV:
data->set.ftp_use_epsv = (bool)(0 != va_arg(param, long));
break;
Daniel Stenberg
committed
case CURLOPT_FTP_SSL_CCC:
data->set.ftp_ccc = (curl_ftpccc)va_arg(param, long);
Daniel Stenberg
committed
break;
case CURLOPT_FTP_SKIP_PASV_IP:
/*
* Enable or disable FTP_SKIP_PASV_IP, which will disable/enable the
* bypass of the IP address in PASV responses.
*/
data->set.ftp_skip_ip = (bool)(0 != va_arg(param, long));
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
case CURLOPT_INFILE:
/*
* FILE pointer to read the file to be uploaded from. Or possibly
* used as argument to the read callback.
*/
data->set.in = va_arg(param, FILE *);
break;
case CURLOPT_INFILESIZE:
/*
* If known, this should inform curl about the file size of the
* to-be-uploaded file.
*/
data->set.infilesize = va_arg(param, long);
break;
case CURLOPT_INFILESIZE_LARGE:
/*
* If known, this should inform curl about the file size of the
* to-be-uploaded file.
*/
data->set.infilesize = va_arg(param, curl_off_t);
break;
case CURLOPT_LOW_SPEED_LIMIT:
/*
* The low speed limit that if transfers are below this for
* CURLOPT_LOW_SPEED_TIME, the transfer is aborted.
*/
data->set.low_speed_limit=va_arg(param, long);
break;
case CURLOPT_MAX_SEND_SPEED_LARGE:
/*
* The max speed limit that sends transfer more than
* CURLOPT_MAX_SEND_PER_SECOND bytes per second the transfer is
* throttled..
*/
data->set.max_send_speed=va_arg(param, curl_off_t);
break;
case CURLOPT_MAX_RECV_SPEED_LARGE:
/*
* The max speed limit that sends transfer more than
* CURLOPT_MAX_RECV_PER_SECOND bytes per second the transfer is
* throttled..
*/
data->set.max_recv_speed=va_arg(param, curl_off_t);
break;
case CURLOPT_LOW_SPEED_TIME:
/*
* The low speed time that if transfers are below the set
* CURLOPT_LOW_SPEED_LIMIT during this time, the transfer is aborted.
*/
data->set.low_speed_time=va_arg(param, long);
break;
case CURLOPT_URL:
/*
* The URL to fetch.
*/
if(data->change.url_alloc) {
/* the already set URL is allocated, free it first! */
free(data->change.url);
data->change.url_alloc=FALSE;
}
result = setstropt(&data->set.str[STRING_SET_URL],
Daniel Stenberg
committed
va_arg(param, char *));
data->change.url = data->set.str[STRING_SET_URL];
Daniel Stenberg
committed
if(data->change.url)
break;
case CURLOPT_PORT:
/*
* The port number to use when getting the URL
*/
data->set.use_port = va_arg(param, long);
break;
case CURLOPT_TIMEOUT:
/*
* The maximum time you allow curl to use for a single transfer
* operation.
*/
Daniel Stenberg
committed
data->set.timeout = va_arg(param, long) * 1000L;
break;
case CURLOPT_TIMEOUT_MS:
data->set.timeout = va_arg(param, long);
break;
Daniel Stenberg
committed
case CURLOPT_CONNECTTIMEOUT:
/*
* The maximum time you allow curl to use to connect.
*/
Daniel Stenberg
committed
data->set.connecttimeout = va_arg(param, long) * 1000L;
break;
case CURLOPT_CONNECTTIMEOUT_MS:
data->set.connecttimeout = va_arg(param, long);
break;
/*
* user:password to use in the operation
*/
result = setstropt(&data->set.str[STRING_USERPWD],
Daniel Stenberg
committed
va_arg(param, char *));
* List of RAW FTP commands to use after a transfer
Daniel Stenberg
committed
data->set.postquote = va_arg(param, struct curl_slist *);
case CURLOPT_PREQUOTE:
/*
* List of RAW FTP commands to use prior to RETR (Wesley Laxton)
*/
data->set.prequote = va_arg(param, struct curl_slist *);
break;
case CURLOPT_QUOTE:
/*
* List of RAW FTP commands to use before a transfer
Daniel Stenberg
committed
data->set.quote = va_arg(param, struct curl_slist *);
case CURLOPT_PROGRESSFUNCTION:
/*
* Progress callback function
*/
Daniel Stenberg
committed
data->set.fprogress = va_arg(param, curl_progress_callback);
Daniel Stenberg
committed
if(data->set.fprogress)
data->progress.callback = TRUE; /* no longer internal */
else
data->progress.callback = FALSE; /* NULL enforces internal */
break;
case CURLOPT_PROGRESSDATA:
/*
* Custom client data to pass to the progress callback
*/
Daniel Stenberg
committed
data->set.progress_client = va_arg(param, void *);
break;
/*
* user:password needed to use the proxy
*/
result = setstropt(&data->set.str[STRING_PROXYUSERPWD],
Daniel Stenberg
committed
va_arg(param, char *));
/*
* What range of the file you want to transfer
*/
result = setstropt(&data->set.str[STRING_SET_RANGE],
Daniel Stenberg
committed
va_arg(param, char *));
/*
* Resume transfer at the give file position
*/
Daniel Stenberg
committed
data->set.set_resume_from = va_arg(param, long);
case CURLOPT_RESUME_FROM_LARGE:
/*
* Resume transfer at the give file position
*/
data->set.set_resume_from = va_arg(param, curl_off_t);
case CURLOPT_DEBUGFUNCTION:
/*
* stderr write callback.
*/
data->set.fdebug = va_arg(param, curl_debug_callback);
/*
* if the callback provided is NULL, it'll use the default callback
*/
break;
case CURLOPT_DEBUGDATA:
/*
* Set to a void * that should receive all error writes. This
* defaults to CURLOPT_STDERR for normal operations.
*/
data->set.debugdata = va_arg(param, void *);
break;
/*
* Set to a FILE * that should receive all error writes. This
* defaults to stderr for normal operations.
*/
Daniel Stenberg
committed
data->set.err = va_arg(param, FILE *);
if(!data->set.err)
data->set.err = stderr;
case CURLOPT_HEADERFUNCTION:
/*
* Set header write callback
*/
Daniel Stenberg
committed
data->set.fwrite_header = va_arg(param, curl_write_callback);
/*
* Set data write callback
*/
data->set.fwrite_func = va_arg(param, curl_write_callback);
if(!data->set.fwrite_func)
/* When set to NULL, reset to our internal default function */
data->set.fwrite_func = (curl_write_callback)fwrite;
/*
* Read data callback
*/
data->set.fread_func = va_arg(param, curl_read_callback);
if(!data->set.fread_func)
/* When set to NULL, reset to our internal default function */
data->set.fread_func = (curl_read_callback)fread;
Daniel Stenberg
committed
case CURLOPT_SEEKFUNCTION:
/*
* Seek callback. Might be NULL.
*/
data->set.seek_func = va_arg(param, curl_seek_callback);
break;
case CURLOPT_SEEKDATA:
/*
* Seek control callback. Might be NULL.
*/
data->set.seek_client = va_arg(param, void *);
break;
case CURLOPT_CONV_FROM_NETWORK_FUNCTION:
/*
* "Convert from network encoding" callback
*/
data->set.convfromnetwork = va_arg(param, curl_conv_callback);
break;
case CURLOPT_CONV_TO_NETWORK_FUNCTION:
/*
* "Convert to network encoding" callback
*/
data->set.convtonetwork = va_arg(param, curl_conv_callback);
break;
case CURLOPT_CONV_FROM_UTF8_FUNCTION:
/*
* "Convert from UTF-8 encoding" callback
*/
data->set.convfromutf8 = va_arg(param, curl_conv_callback);
break;
case CURLOPT_IOCTLFUNCTION:
/*
* I/O control callback. Might be NULL.
*/
data->set.ioctl_func = va_arg(param, curl_ioctl_callback);
break;
case CURLOPT_IOCTLDATA:
/*
* I/O control data pointer. Might be NULL.
*/
data->set.ioctl_client = va_arg(param, void *);
/*
* String that holds file name of the SSL certificate to use
*/
result = setstropt(&data->set.str[STRING_CERT],
Daniel Stenberg
committed
va_arg(param, char *));
* String that holds file type of the SSL certificate to use
result = setstropt(&data->set.str[STRING_CERT_TYPE],
Daniel Stenberg
committed
va_arg(param, char *));
break;
case CURLOPT_SSLKEY:
/*
* String that holds file name of the SSL certificate to use
*/
result = setstropt(&data->set.str[STRING_KEY],
Daniel Stenberg
committed
va_arg(param, char *));
break;
case CURLOPT_SSLKEYTYPE:
/*
* String that holds file type of the SSL certificate to use
*/
result = setstropt(&data->set.str[STRING_KEY_TYPE],
Daniel Stenberg
committed
va_arg(param, char *));
case CURLOPT_KEYPASSWD:
* String that holds the SSL or SSH private key password.
result = setstropt(&data->set.str[STRING_KEY_PASSWD],
Daniel Stenberg
committed
va_arg(param, char *));
break;
case CURLOPT_SSLENGINE:
/*
* String that holds the SSL crypto engine.
*/
argptr = va_arg(param, char *);
Daniel Stenberg
committed
if(argptr && argptr[0])
Daniel Stenberg
committed
result = Curl_ssl_set_engine(data, argptr);
break;
Daniel Stenberg
committed
case CURLOPT_SSLENGINE_DEFAULT:
/*
* flag to set engine as default.
*/
Daniel Stenberg
committed
result = Curl_ssl_set_engine_default(data);
* Kludgy option to enable CRLF conversions. Subject for removal.
Daniel Stenberg
committed
Daniel Stenberg
committed
* Set what interface or address/hostname to bind the socket to when
* performing an operation and thus what from-IP your connection will use.
result = setstropt(&data->set.str[STRING_DEVICE],
Daniel Stenberg
committed
va_arg(param, char *));
Daniel Stenberg
committed
case CURLOPT_LOCALPORT:
/*
* Set what local port to bind the socket to when performing an operation.
*/
data->set.localport = (unsigned short) va_arg(param, long);
break;
case CURLOPT_LOCALPORTRANGE:
/*
* Set number of local ports to try, starting with CURLOPT_LOCALPORT.
*/
data->set.localportrange = (int) va_arg(param, long);
break;
case CURLOPT_KRBLEVEL:
* A string that defines the kerberos security level.
result = setstropt(&data->set.str[STRING_KRB_LEVEL],
Daniel Stenberg
committed
va_arg(param, char *));
data->set.krb = (bool)(NULL != data->set.str[STRING_KRB_LEVEL]);
Daniel Stenberg
committed
case CURLOPT_SSL_VERIFYPEER:
/*
* Enable peer SSL verifying.
*/
Daniel Stenberg
committed
data->set.ssl.verifypeer = va_arg(param, long);
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
case CURLOPT_SSL_VERIFYHOST:
/*
* Enable verification of the CN contained in the peer certificate
*/
Daniel Stenberg
committed
data->set.ssl.verifyhost = va_arg(param, long);
Daniel Stenberg
committed
break;
case CURLOPT_SSL_CTX_FUNCTION:
/*
* Set a SSL_CTX callback
*/
data->set.ssl.fsslctx = va_arg(param, curl_ssl_ctx_callback);
break;
case CURLOPT_SSL_CTX_DATA:
/*
* Set a SSL_CTX callback parameter pointer
*/
data->set.ssl.fsslctxp = va_arg(param, void *);
break;
Daniel Stenberg
committed
case CURLOPT_CAINFO:
/*
* Set CA info for SSL connection. Specify file name of the CA certificate
*/
result = setstropt(&data->set.str[STRING_SSL_CAFILE],
Daniel Stenberg
committed
va_arg(param, char *));
break;
case CURLOPT_CAPATH:
/*
* Set CA path info for SSL connection. Specify directory name of the CA
* certificates which have been prepared using openssl c_rehash utility.
/* This does not work on windows. */
result = setstropt(&data->set.str[STRING_SSL_CAPATH],
Daniel Stenberg
committed
va_arg(param, char *));
Daniel Stenberg
committed
break;
case CURLOPT_TELNETOPTIONS:
/*
* Set a linked list of telnet options
*/
Daniel Stenberg
committed
data->set.telnet_options = va_arg(param, struct curl_slist *);
case CURLOPT_BUFFERSIZE:
/*
* The application kindly asks for a differently sized receive buffer.
* If it seems reasonable, we'll use it.
*/
data->set.buffer_size = va_arg(param, long);
Daniel Stenberg
committed
if((data->set.buffer_size> (BUFSIZE -1 )) ||
(data->set.buffer_size < 1))
data->set.buffer_size = 0; /* huge internal default */
break;
case CURLOPT_NOSIGNAL:
/*
* The application asks not to set any signal() or alarm() handlers,
* even when using a timeout.
*/
data->set.no_signal = (bool)(0 != va_arg(param, long));
case CURLOPT_SHARE:
{
struct Curl_share *set;
set = va_arg(param, struct Curl_share *);
Daniel Stenberg
committed
/* disconnect from old share, if any */
if(data->share) {
Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
Daniel Stenberg
committed
if(data->dns.hostcachetype == HCACHE_SHARED) {
data->dns.hostcache = NULL;
data->dns.hostcachetype = HCACHE_NONE;
}
Daniel Stenberg
committed
if(data->share->cookies == data->cookies)
data->cookies = NULL;
Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
Daniel Stenberg
committed
data->share = NULL;
Daniel Stenberg
committed
/* use new share if it set */
Daniel Stenberg
committed
if(data->share) {
Curl_share_lock(data, CURL_LOCK_DATA_SHARE, CURL_LOCK_ACCESS_SINGLE);
Daniel Stenberg
committed
data->share->dirty++;
Daniel Stenberg
committed
if(data->share->hostcache) {
Daniel Stenberg
committed
/* use shared host cache, first free the private one if any */
if(data->dns.hostcachetype == HCACHE_PRIVATE)
Curl_hash_destroy(data->dns.hostcache);
Daniel Stenberg
committed
data->dns.hostcache = data->share->hostcache;
data->dns.hostcachetype = HCACHE_SHARED;
Daniel Stenberg
committed
}
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_COOKIES)
Daniel Stenberg
committed
if(data->share->cookies) {
/* use shared cookie list, first free own one if any */
Daniel Stenberg
committed
if(data->cookies)
Daniel Stenberg
committed
Curl_cookie_cleanup(data->cookies);
/* enable cookies since we now use a share that uses cookies! */
Daniel Stenberg
committed
data->cookies = data->share->cookies;
}
#endif /* CURL_DISABLE_HTTP */
Daniel Stenberg
committed
Curl_share_unlock(data, CURL_LOCK_DATA_SHARE);
Daniel Stenberg
committed
/* check for host cache not needed,
Daniel Stenberg
committed
case CURLOPT_PROXYTYPE:
/*
* Set proxy type. HTTP/SOCKS4/SOCKS4a/SOCKS5/SOCKS5_HOSTNAME
Daniel Stenberg
committed
*/
data->set.proxytype = (curl_proxytype)va_arg(param, long);
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
case CURLOPT_PRIVATE:
/*
* Set private data pointer.
*/
Daniel Stenberg
committed
data->set.private_data = va_arg(param, void *);
Daniel Stenberg
committed
break;
case CURLOPT_MAXFILESIZE:
/*
* Set the maximum size of a file to download.
*/
data->set.max_filesize = va_arg(param, long);
break;
case CURLOPT_USE_SSL:
Daniel Stenberg
committed
/*
* Make transfers attempt to use SSL/TLS.
Daniel Stenberg
committed
*/
data->set.ftp_ssl = (curl_usessl)va_arg(param, long);
Daniel Stenberg
committed
break;
case CURLOPT_FTPSSLAUTH:
/*
* Set a specific auth for FTP-SSL transfers.
*/
data->set.ftpsslauth = (curl_ftpauth)va_arg(param, long);
break;
case CURLOPT_IPRESOLVE:
data->set.ip_version = va_arg(param, long);
break;
case CURLOPT_MAXFILESIZE_LARGE:
/*
* Set the maximum size of a file to download.
*/
data->set.max_filesize = va_arg(param, curl_off_t);
case CURLOPT_TCP_NODELAY:
/*
* Enable or disable TCP_NODELAY, which will disable/enable the Nagle
* algorithm
*/
data->set.tcp_nodelay = (bool)(0 != va_arg(param, long));
/*
case CURLOPT_SOURCE_URL:
case CURLOPT_SOURCE_USERPWD:
case CURLOPT_SOURCE_QUOTE:
case CURLOPT_SOURCE_PREQUOTE:
case CURLOPT_SOURCE_POSTQUOTE:
These former 3rd party transfer options are deprecated */
Daniel Stenberg
committed
case CURLOPT_FTP_ACCOUNT:
result = setstropt(&data->set.str[STRING_FTP_ACCOUNT],
Daniel Stenberg
committed
va_arg(param, char *));
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
case CURLOPT_IGNORE_CONTENT_LENGTH:
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
case CURLOPT_CONNECT_ONLY:
/*
* No data transfer, set up connection and let application use the socket
*/
data->set.connect_only = (bool)(0 != va_arg(param, long));
Daniel Stenberg
committed
break;
Daniel Stenberg
committed
case CURLOPT_FTP_ALTERNATIVE_TO_USER:
result = setstropt(&data->set.str[STRING_FTP_ALTERNATIVE_TO_USER],
Daniel Stenberg
committed
va_arg(param, char *));
Daniel Stenberg
committed
break;
case CURLOPT_SOCKOPTFUNCTION:
/*
* socket callback function: called after socket() but before connect()
*/
data->set.fsockopt = va_arg(param, curl_sockopt_callback);
break;
case CURLOPT_SOCKOPTDATA:
/*
* socket callback data pointer. Might be NULL.
*/
data->set.sockopt_client = va_arg(param, void *);
break;
case CURLOPT_OPENSOCKETFUNCTION:
/*
* open/create socket callback function: called instead of socket(),
* before connect()
*/
data->set.fopensocket = va_arg(param, curl_opensocket_callback);
break;
case CURLOPT_OPENSOCKETDATA:
/*
* socket callback data pointer. Might be NULL.
*/
data->set.opensocket_client = va_arg(param, void *);
break;
Daniel Stenberg
committed
case CURLOPT_SSL_SESSIONID_CACHE:
data->set.ssl.sessionid = (bool)(0 != va_arg(param, long));
Daniel Stenberg
committed
break;
case CURLOPT_SSH_AUTH_TYPES:
data->set.ssh_auth_types = va_arg(param, long);
break;
case CURLOPT_SSH_PUBLIC_KEYFILE:
/*
* Use this file instead of the $HOME/.ssh/id_dsa.pub file
*/
result = setstropt(&data->set.str[STRING_SSH_PUBLIC_KEY],
Daniel Stenberg
committed
va_arg(param, char *));
break;
case CURLOPT_SSH_PRIVATE_KEYFILE:
/*
* Use this file instead of the $HOME/.ssh/id_dsa file
*/
result = setstropt(&data->set.str[STRING_SSH_PRIVATE_KEY],
Daniel Stenberg
committed
va_arg(param, char *));
case CURLOPT_SSH_HOST_PUBLIC_KEY_MD5:
/*
* Option to allow for the MD5 of the host public key to be checked
* for validation purposes.
*/
result = setstropt(&data->set.str[STRING_SSH_HOST_PUBLIC_KEY_MD5],
va_arg(param, char *));
break;
Daniel Stenberg
committed
case CURLOPT_HTTP_TRANSFER_DECODING:
/*
* disable libcurl transfer encoding is used
*/
data->set.http_te_skip = (bool)(0 == va_arg(param, long));
break;
case CURLOPT_HTTP_CONTENT_DECODING:
/*
* raw data passed to the application when content encoding is used
*/
data->set.http_ce_skip = (bool)(0 == va_arg(param, long));
break;
case CURLOPT_NEW_FILE_PERMS:
/*
* Uses these permissions instead of 0644
*/
data->set.new_file_perms = va_arg(param, long);
break;
case CURLOPT_NEW_DIRECTORY_PERMS:
/*
* Uses these permissions instead of 0755
*/
data->set.new_directory_perms = va_arg(param, long);
break;
Daniel Stenberg
committed
case CURLOPT_PROXY_TRANSFER_MODE:
/*
* set transfer mode (;type=<a|i>) when doing FTP via an HTTP proxy
*/
switch (va_arg(param, long)) {
case 0:
data->set.proxy_transfer_mode = FALSE;
break;
case 1:
data->set.proxy_transfer_mode = TRUE;
break;
default:
/* reserve other values for future use */
result = CURLE_FAILED_INIT;
break;
}
break;
default:
/* unknown tag and its companion, just ignore: */
Daniel Stenberg
committed
result = CURLE_FAILED_INIT; /* correct this */
break;
Daniel Stenberg
committed
return result;
static void conn_free(struct connectdata *conn)
{
Daniel Stenberg
committed
if(!conn)
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
return;
/* close possibly still open sockets */
if(CURL_SOCKET_BAD != conn->sock[SECONDARYSOCKET])
sclose(conn->sock[SECONDARYSOCKET]);
if(CURL_SOCKET_BAD != conn->sock[FIRSTSOCKET])
sclose(conn->sock[FIRSTSOCKET]);
Curl_safefree(conn->user);
Curl_safefree(conn->passwd);
Curl_safefree(conn->proxyuser);
Curl_safefree(conn->proxypasswd);
Curl_safefree(conn->allocptr.proxyuserpwd);
Curl_safefree(conn->allocptr.uagent);
Curl_safefree(conn->allocptr.userpwd);
Curl_safefree(conn->allocptr.accept_encoding);
Curl_safefree(conn->allocptr.rangeline);
Curl_safefree(conn->allocptr.ref);
Curl_safefree(conn->allocptr.host);
Curl_safefree(conn->allocptr.cookiehost);
Curl_safefree(conn->ip_addr_str);
Curl_safefree(conn->trailer);
Curl_safefree(conn->host.rawalloc); /* host name buffer */
Curl_safefree(conn->proxy.rawalloc); /* proxy name buffer */
Daniel Stenberg
committed
Curl_safefree(conn->master_buffer);
Curl_llist_destroy(conn->send_pipe, NULL);
Curl_llist_destroy(conn->recv_pipe, NULL);
/* possible left-overs from the async name resolvers */
#if defined(USE_ARES)
Curl_safefree(conn->async.hostname);
Curl_safefree(conn->async.os_specific);
#elif defined(CURLRES_THREADED)
Curl_destroy_thread_data(&conn->async);
#endif
Daniel Stenberg
committed
Curl_ssl_close(conn, FIRSTSOCKET);
Curl_ssl_close(conn, SECONDARYSOCKET);
Daniel Stenberg
committed
Curl_free_ssl_config(&conn->ssl_config);
free(conn); /* free all the connection oriented data */
}
CURLcode Curl_disconnect(struct connectdata *conn)
struct SessionHandle *data;
if(!conn)
return CURLE_OK; /* this is closed and fine already */
Daniel Stenberg
committed
if(!data) {
DEBUGF(infof(data, "DISCONNECT without easy handle, ignoring\n"));
return CURLE_OK;
}
Daniel Stenberg
committed
#if defined(CURLDEBUG) && defined(AGGRESIVE_TEST)
/* scan for DNS cache entries still marked as in use */
Curl_hash_apply(data->hostcache,
NULL, Curl_scan_cache_used);
#endif
Daniel Stenberg
committed
Curl_expire(data, 0); /* shut off timers */
Daniel Stenberg
committed
Curl_hostcache_prune(data); /* kill old DNS cache entries */
if((conn->ntlm.state != NTLMSTATE_NONE) ||
(conn->proxyntlm.state != NTLMSTATE_NONE)) {
/* Authentication data is a mix of connection-related and sessionhandle-
related stuff. NTLM is connection-related so when we close the shop
we shall forget. */
data->state.authhost.done = FALSE;
data->state.authhost.want;
data->state.authproxy.done = FALSE;
data->state.authproxy.want;
data->state.authproblem = FALSE;
Curl_ntlm_cleanup(conn);
Daniel Stenberg
committed
if(conn->handler->disconnect)
Daniel Stenberg
committed
/* This is set if protocol-specific cleanups should be made */
Patrick Monnerat
committed
conn->handler->disconnect(conn);
Daniel Stenberg
committed
Daniel Stenberg
committed
/* unlink ourselves! */
infof(data, "Closing connection #%ld\n", conn->connectindex);
Daniel Stenberg
committed
if(data->state.connc)
/* only clear the table entry if we still know in which cache we
used to be in */
data->state.connc->connects[conn->connectindex] = NULL;
Daniel Stenberg
committed
if(conn->host.encalloc)
Daniel Stenberg
committed
idn_free(conn->host.encalloc); /* encoded host name buffer, must be freed
with idn_free() since this was allocated
by libidn */
if(conn->proxy.encalloc)
Daniel Stenberg
committed
idn_free(conn->proxy.encalloc); /* encoded proxy name buffer, must be
freed with idn_free() since this was
allocated by libidn */
Daniel Stenberg
committed
Curl_ssl_close(conn, FIRSTSOCKET);
/* Indicate to all handles on the pipe that we're dead */
Daniel Stenberg
committed
if(IsPipeliningEnabled(data)) {
Daniel Stenberg
committed
signalPipeClose(conn->send_pipe);
signalPipeClose(conn->recv_pipe);
}
Loading
Loading full blame...