From 90037b85d1a6c46979729d0735eef094516dc31f Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Wed, 9 Jun 2004 08:23:55 +0000 Subject: Alexander Krasnostavsky's fix to make libcurl build fine with configure --disable-http, which thus builds a libcurl without HTTP support. --- lib/url.c | 480 ++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 249 insertions(+), 231 deletions(-) (limited to 'lib/url.c') diff --git a/lib/url.c b/lib/url.c index b53dcd1c4..2bc9e53c6 100644 --- a/lib/url.c +++ b/lib/url.c @@ -238,6 +238,8 @@ CURLcode Curl_close(struct SessionHandle *data) Curl_cookie_cleanup(data->cookies); } Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE); + + Curl_digest_cleanup(data); #endif /* free the connection cache */ @@ -245,8 +247,6 @@ CURLcode Curl_close(struct SessionHandle *data) Curl_safefree(data->info.contenttype); - Curl_digest_cleanup(data); - #ifdef USE_ARES /* this destroys the channel and we cannot use it anymore after this */ ares_destroy(data->state.areschannel); @@ -555,27 +555,6 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) */ data->set.netrc_file = va_arg(param, char *); break; - case CURLOPT_FOLLOWLOCATION: - /* - * Follow Location: header hints on a HTTP-server. - */ - data->set.http_follow_location = va_arg(param, long)?TRUE:FALSE; - break; - case CURLOPT_UNRESTRICTED_AUTH: - /* - * Send authentication (user+password) when following locations, even when - * hostname changed. - */ - data->set.http_disable_hostname_check_before_authentication = - va_arg(param, long)?TRUE:FALSE; - break; - 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_TRANSFERTEXT: /* * This option was previously named 'FTPASCII'. Renamed to work with @@ -607,117 +586,86 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) data->set.ssl.version = va_arg(param, long); 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)va_arg(param, long); - break; - #ifndef CURL_DISABLE_HTTP - case CURLOPT_COOKIEFILE: + case CURLOPT_AUTOREFERER: /* - * Set cookie file to read and parse. Can be used multiple times. + * Switch on automatic referer that gets set if curl follows locations. */ - cookiefile = (char *)va_arg(param, void *); - if(cookiefile) { - 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, cookiefile); - - if(!cl) - return CURLE_OUT_OF_MEMORY; - - data->change.cookielist = cl; - } + data->set.http_auto_referer = va_arg(param, long)?1:0; break; - case CURLOPT_COOKIEJAR: + case CURLOPT_ENCODING: /* - * Set cookie file name to dump all cookies to when we're done. + * 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. + * */ - data->set.cookiejar = (char *)va_arg(param, void *); + data->set.encoding = va_arg(param, char *); + if(data->set.encoding && !*data->set.encoding) + data->set.encoding = (char*)ALL_CONTENT_ENCODINGS; + break; + case CURLOPT_FOLLOWLOCATION: /* - * Activate the cookie parser. This may or may not already - * have been made. + * Follow Location: header hints on a HTTP-server. */ - data->cookies = Curl_cookie_init(data, NULL, data->cookies, - data->set.cookiesession); + data->set.http_follow_location = va_arg(param, long)?TRUE:FALSE; break; -#endif - case CURLOPT_WRITEHEADER: + case CURLOPT_UNRESTRICTED_AUTH: /* - * Custom pointer to pass the header write callback function + * Send authentication (user+password) when following locations, even when + * hostname changed. */ - data->set.writeheader = (void *)va_arg(param, void *); + data->set.http_disable_hostname_check_before_authentication = + va_arg(param, long)?TRUE:FALSE; break; - case CURLOPT_COOKIE: + + case CURLOPT_MAXREDIRS: /* - * Cookie string to send to the remote server in the request. + * The maximum amount of hops you allow curl to follow Location: + * headers. This should mostly be used to detect never-ending loops. */ - data->set.cookie = va_arg(param, char *); + data->set.maxredirs = va_arg(param, long); 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 *); + + 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! */ + if(va_arg(param, long)) + data->set.httpreq = HTTPREQ_POST; break; - case CURLOPT_FILE: + + case CURLOPT_POSTFIELDS: /* - * FILE pointer to write to or include in the data write callback + * A string with POST data. Makes curl HTTP POST. */ - data->set.out = va_arg(param, FILE *); + data->set.postfields = va_arg(param, char *); + if(data->set.postfields) + data->set.httpreq = HTTPREQ_POST; break; - case CURLOPT_FTPPORT: + + case CURLOPT_POSTFIELDSIZE: /* - * Use FTP PORT, this also specifies which IP address to use + * The size of the POSTFIELD data to prevent libcurl to do strlen() to + * figure it out. Enables binary posts. */ - data->set.ftpport = va_arg(param, char *); - data->set.ftp_use_port = data->set.ftpport?1:0; - break; - - case CURLOPT_FTP_USE_EPRT: - data->set.ftp_use_eprt = va_arg(param, long)?TRUE:FALSE; - break; - - case CURLOPT_FTP_USE_EPSV: - data->set.ftp_use_epsv = va_arg(param, long)?TRUE:FALSE; + data->set.postfieldsize = va_arg(param, long); break; - case CURLOPT_HTTPHEADER: + case CURLOPT_POSTFIELDSIZE_LARGE: /* - * Set a list with HTTP headers to use (or replace internals with) + * The size of the POSTFIELD data to prevent libcurl to do strlen() to + * figure it out. Enables binary posts. */ - data->set.headers = va_arg(param, struct curl_slist *); + data->set.postfieldsize = va_arg(param, curl_off_t); break; - case CURLOPT_CUSTOMREQUEST: - /* - * Set a custom string to use as request - */ - data->set.customrequest = 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 */ - break; case CURLOPT_HTTPPOST: /* * Set to make us do HTTP POST @@ -727,116 +675,134 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) data->set.httpreq = HTTPREQ_POST_FORM; break; - case CURLOPT_HTTPGET: + case CURLOPT_REFERER: /* - * Set to force us do HTTP GET + * String to set in the HTTP Referer: field. */ - if(va_arg(param, long)) { - data->set.httpreq = HTTPREQ_GET; - data->set.upload = FALSE; /* switch off upload */ + if(data->change.referer_alloc) { + free(data->change.referer); + data->change.referer_alloc = FALSE; } + data->set.set_referer = va_arg(param, char *); + data->change.referer = data->set.set_referer; break; - case CURLOPT_INFILE: + case CURLOPT_USERAGENT: /* - * FILE pointer to read the file to be uploaded from. Or possibly - * used as argument to the read callback. + * String to use in the HTTP User-Agent field */ - data->set.in = va_arg(param, FILE *); + data->set.useragent = va_arg(param, char *); break; - case CURLOPT_INFILESIZE: + + case CURLOPT_HTTPHEADER: /* - * If known, this should inform curl about the file size of the - * to-be-uploaded file. + * Set a list with HTTP headers to use (or replace internals with) */ - data->set.infilesize = va_arg(param, long); + data->set.headers = va_arg(param, struct curl_slist *); break; - case CURLOPT_INFILESIZE_LARGE: + + case CURLOPT_HTTP200ALIASES: /* - * If known, this should inform curl about the file size of the - * to-be-uploaded file. + * Set a list of aliases for HTTP 200 in response header */ - data->set.infilesize = va_arg(param, curl_off_t); + data->set.http200aliases = va_arg(param, struct curl_slist *); break; - case CURLOPT_LOW_SPEED_LIMIT: + + case CURLOPT_COOKIE: /* - * The low speed limit that if transfers are below this for - * CURLOPT_LOW_SPEED_TIME, the transfer is aborted. + * Cookie string to send to the remote server in the request. */ - data->set.low_speed_limit=va_arg(param, long); + data->set.cookie = va_arg(param, char *); break; - case CURLOPT_LOW_SPEED_TIME: + + case CURLOPT_COOKIEFILE: /* - * The low speed time that if transfers are below the set - * CURLOPT_LOW_SPEED_LIMIT during this time, the transfer is aborted. + * Set cookie file to read and parse. Can be used multiple times. */ - data->set.low_speed_time=va_arg(param, long); + cookiefile = (char *)va_arg(param, void *); + if(cookiefile) { + 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, cookiefile); + + if(!cl) + return CURLE_OUT_OF_MEMORY; + + data->change.cookielist = cl; + } break; - case CURLOPT_URL: + + case CURLOPT_COOKIEJAR: /* - * The URL to fetch. + * Set cookie file name to dump all cookies to when we're done. */ - if(data->change.url_alloc) { - /* the already set URL is allocated, free it first! */ - free(data->change.url); - data->change.url_alloc=FALSE; - } - data->set.set_url = va_arg(param, char *); - data->change.url = data->set.set_url; - data->change.url_changed = TRUE; - break; - case CURLOPT_PORT: + data->set.cookiejar = (char *)va_arg(param, void *); + /* - * The port number to use when getting the URL + * Activate the cookie parser. This may or may not already + * have been made. */ - data->set.use_port = 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! */ - if(va_arg(param, long)) - data->set.httpreq = HTTPREQ_POST; + data->cookies = Curl_cookie_init(data, NULL, data->cookies, + data->set.cookiesession); break; - case CURLOPT_POSTFIELDS: + + case CURLOPT_COOKIESESSION: /* - * A string with POST data. Makes curl HTTP POST. + * 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.postfields = va_arg(param, char *); - if(data->set.postfields) - data->set.httpreq = HTTPREQ_POST; + data->set.cookiesession = (bool)va_arg(param, long); break; - case CURLOPT_POSTFIELDSIZE: + + case CURLOPT_HTTPGET: /* - * The size of the POSTFIELD data to prevent libcurl to do strlen() to - * figure it out. Enables binary posts. + * Set to force us do HTTP GET */ - data->set.postfieldsize = va_arg(param, long); + if(va_arg(param, long)) { + data->set.httpreq = HTTPREQ_GET; + data->set.upload = FALSE; /* switch off upload */ + } break; - case CURLOPT_POSTFIELDSIZE_LARGE: + + case CURLOPT_HTTP_VERSION: /* - * The size of the POSTFIELD data to prevent libcurl to do strlen() to - * figure it out. Enables binary posts. + * This sets a requested HTTP version to be used. The value is one of + * the listed enums in curl/curl.h. */ - data->set.postfieldsize = va_arg(param, curl_off_t); + data->set.httpversion = va_arg(param, long); break; - case CURLOPT_REFERER: + + case CURLOPT_HTTPPROXYTUNNEL: /* - * String to set in the HTTP Referer: field. + * Tunnel operations through the proxy instead of normal proxy use */ - if(data->change.referer_alloc) { - free(data->change.referer); - data->change.referer_alloc = FALSE; - } - data->set.set_referer = va_arg(param, char *); - data->change.referer = data->set.set_referer; + data->set.tunnel_thru_httpproxy = va_arg(param, long)?TRUE:FALSE; break; - case CURLOPT_AUTOREFERER: + + case CURLOPT_CUSTOMREQUEST: /* - * Switch on automatic referer that gets set if curl follows locations. + * Set a custom string to use as request */ - data->set.http_auto_referer = va_arg(param, long)?1:0; + data->set.customrequest = 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 */ break; + case CURLOPT_PROXY: /* * Set proxy server:port to use as HTTP proxy. @@ -857,58 +823,13 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) data->set.set_proxy = va_arg(param, char *); data->change.proxy = data->set.set_proxy; break; - case CURLOPT_HTTPPROXYTUNNEL: - /* - * Tunnel operations through the proxy instead of normal proxy use - */ - data->set.tunnel_thru_httpproxy = va_arg(param, long)?TRUE:FALSE; - break; + case CURLOPT_PROXYPORT: /* * Explicitly set HTTP proxy port number. */ data->set.proxyport = va_arg(param, long); break; - case CURLOPT_TIMEOUT: - /* - * The maximum time you allow curl to use for a single transfer - * operation. - */ - data->set.timeout = va_arg(param, long); - break; - case CURLOPT_CONNECTTIMEOUT: - /* - * The maximum time you allow curl to use to connect. - */ - data->set.connecttimeout = va_arg(param, long); - break; - 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); - break; - case CURLOPT_USERAGENT: - /* - * String to use in the HTTP User-Agent field - */ - data->set.useragent = va_arg(param, char *); - break; - 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. - * - */ - data->set.encoding = va_arg(param, char *); - if(data->set.encoding && !*data->set.encoding) - data->set.encoding = (char*)ALL_CONTENT_ENCODINGS; - break; case CURLOPT_HTTPAUTH: /* @@ -949,6 +870,110 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) data->set.proxyauth = auth; } break; +#endif /* CURL_DISABLE_HTTP */ + + 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 + */ + data->set.ftpport = va_arg(param, char *); + data->set.ftp_use_port = data->set.ftpport?1:0; + break; + + case CURLOPT_FTP_USE_EPRT: + data->set.ftp_use_eprt = va_arg(param, long)?TRUE:FALSE; + break; + + case CURLOPT_FTP_USE_EPSV: + data->set.ftp_use_epsv = va_arg(param, long)?TRUE:FALSE; + break; + + 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_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; + } + data->set.set_url = va_arg(param, char *); + data->change.url = data->set.set_url; + data->change.url_changed = TRUE; + 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. + */ + data->set.timeout = va_arg(param, long); + break; + case CURLOPT_CONNECTTIMEOUT: + /* + * The maximum time you allow curl to use to connect. + */ + data->set.connecttimeout = va_arg(param, long); + break; case CURLOPT_USERPWD: /* @@ -1262,22 +1287,22 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) data->hostcache = data->share->hostcache; } - +#ifndef CURL_DISABLE_HTTP if(data->share->cookies) { /* use shared cookie list, first free own one if any */ if (data->cookies) Curl_cookie_cleanup(data->cookies); data->cookies = data->share->cookies; } - +#endif /* CURL_DISABLE_HTTP */ Curl_share_unlock(data, CURL_LOCK_DATA_SHARE); } - +#ifndef CURL_DISABLE_HTTP /* check cookie list is set */ if(!data->cookies) data->cookies = Curl_cookie_init(data, NULL, NULL, TRUE ); - +#endif /* CURL_DISABLE_HTTP */ /* check for host cache not needed, * it will be done by curl_easy_perform */ } @@ -1297,13 +1322,6 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option, ...) data->set.private = va_arg(param, char *); break; - case CURLOPT_HTTP200ALIASES: - /* - * Set a list of aliases for HTTP 200 in response header - */ - data->set.http200aliases = va_arg(param, struct curl_slist *); - break; - case CURLOPT_MAXFILESIZE: /* * Set the maximum size of a file to download. -- cgit v1.2.3