diff options
| author | Nick White <arch@njw.me.uk> | 2008-05-01 03:02:25 +0000 | 
|---|---|---|
| committer | Nick White <arch@njw.me.uk> | 2008-05-01 03:02:25 +0000 | 
| commit | 5141482351a3373472fc9974cd6059ff254dcf27 (patch) | |
| tree | ff442e9ddc0123c19f63e1244543c396635f154b /src/download.c | |
| parent | 8e215729e7f45b1c9e17f8451046b7b5c04943e6 (diff) | |
Simplified proxy setting internals
Taking advantage of CURL's pre-packaged constants for proxy options
git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-44
Diffstat (limited to 'src/download.c')
| -rw-r--r-- | src/download.c | 68 | 
1 files changed, 18 insertions, 50 deletions
diff --git a/src/download.c b/src/download.c index 948b289..77e65bd 100644 --- a/src/download.c +++ b/src/download.c @@ -35,10 +35,10 @@ int write_func(void *ptr, size_t size, size_t nmemb, FILE *stream)  int update_progress(void *data, double dltotal, double dlnow,  					double ultotal, double ulnow); -extern proxytype proxy_type; +extern int proxy_type;  extern char proxy_addr[STR_MAX];  extern long proxy_port; -extern proxyauth proxy_auth; +extern int proxy_auth;  extern char proxy_user[STR_MAX];  extern char proxy_pass[STR_MAX];  extern CURL *main_curl_handle; @@ -65,35 +65,19 @@ int save_file(CURL *curl_handle, char *uri, char *filepath, long resume_offset)  		curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_func);  		curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, file); -		if(proxy_type != NONE) +		if(proxy_type)  		{ -			if(proxy_type == HTTP) -				curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); -			else if(proxy_type == SOCKS4) -				curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); -			else if(proxy_type == SOCKS5) -				curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - +			curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, proxy_type);  			curl_easy_setopt(curl_handle, CURLOPT_PROXY, proxy_addr); -  			if(proxy_port)  				curl_easy_setopt(curl_handle, CURLOPT_PROXYPORT, proxy_port); - -			if(proxy_auth != NOAUTH) +			if(proxy_auth) +				curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, proxy_auth); +			if(proxy_user[0] && proxy_pass[0])  			{ -				if(proxy_auth == BASIC) -					curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); -				else if(proxy_auth == DIGEST) -					curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST); -				else if(proxy_auth == NTLM) -					curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM); - -				if(proxy_user[0] && proxy_pass[0]) -				{ -					char userpass[STR_MAX]; -					snprintf(userpass, STR_MAX, "%s:%s", proxy_user, proxy_pass); -					curl_easy_setopt(curl_handle, CURLOPT_PROXYUSERPWD, userpass); -				} +				char userpass[STR_MAX]; +				snprintf(userpass, STR_MAX, "%s:%s", proxy_user, proxy_pass); +				curl_easy_setopt(curl_handle, CURLOPT_PROXYUSERPWD, userpass);  			}  		} @@ -164,35 +148,19 @@ double getremotefilesize(CURL *curl_handle, char *uri)  		curl_easy_setopt(curl_handle, CURLOPT_NOBODY, 1);  		curl_easy_setopt(curl_handle, CURLOPT_HEADER, 0); -		if(proxy_type != NONE) +		if(proxy_type)  		{ -			if(proxy_type == HTTP) -				curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); -			else if(proxy_type == SOCKS4) -				curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); -			else if(proxy_type == SOCKS5) -				curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); - +			curl_easy_setopt(curl_handle, CURLOPT_PROXYTYPE, proxy_type);  			curl_easy_setopt(curl_handle, CURLOPT_PROXY, proxy_addr); -  			if(proxy_port)  				curl_easy_setopt(curl_handle, CURLOPT_PROXYPORT, proxy_port); - -			if(proxy_auth != NOAUTH) +			if(proxy_auth) +				curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, proxy_auth); +			if(proxy_user[0] && proxy_pass[0])  			{ -				if(proxy_auth == BASIC) -					curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, CURLAUTH_BASIC); -				else if(proxy_auth == DIGEST) -					curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST); -				else if(proxy_auth == NTLM) -					curl_easy_setopt(curl_handle, CURLOPT_PROXYAUTH, CURLAUTH_NTLM); - -				if(proxy_user[0] && proxy_pass[0]) -				{ -					char userpass[STR_MAX]; -					snprintf(userpass, STR_MAX, "%s:%s", proxy_user, proxy_pass); -					curl_easy_setopt(curl_handle, CURLOPT_PROXYUSERPWD, userpass); -				} +				char userpass[STR_MAX]; +				snprintf(userpass, STR_MAX, "%s:%s", proxy_user, proxy_pass); +				curl_easy_setopt(curl_handle, CURLOPT_PROXYUSERPWD, userpass);  			}  		}  | 
