diff options
-rw-r--r-- | src/config.c | 34 | ||||
-rw-r--r-- | src/download.c | 68 | ||||
-rw-r--r-- | src/getht.c | 8 | ||||
-rw-r--r-- | src/getht.h | 17 |
4 files changed, 42 insertions, 85 deletions
diff --git a/src/config.c b/src/config.c index 778ad3b..f0545d3 100644 --- a/src/config.c +++ b/src/config.c @@ -23,10 +23,12 @@ #include "getht.h" -extern proxytype proxy_type; +#include <curl/curl.h> + +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 char issue_uri[STR_MAX]; @@ -61,11 +63,11 @@ int loadconfig(char * htde_path, char * issue_path, int * update) else if(!strcmp(option, "proxy_type")) { if(!strcmp(parameter, "http")) - proxy_type = HTTP; + proxy_type = CURLPROXY_HTTP; else if(!strcmp(parameter, "socks4")) - proxy_type = SOCKS4; + proxy_type = CURLPROXY_SOCKS4; else if(!strcmp(parameter, "socks5")) - proxy_type = SOCKS5; + proxy_type = CURLPROXY_SOCKS5; else fprintf(stderr, "Proxy type %s not known, please use either http, socks4 or socks5\n", @@ -78,11 +80,11 @@ int loadconfig(char * htde_path, char * issue_path, int * update) else if(!strcmp(option, "proxy_auth")) { if(!strcmp(parameter, "basic")) - proxy_auth = BASIC; + proxy_auth = CURLAUTH_BASIC; else if(!strcmp(parameter, "digest")) - proxy_auth = DIGEST; + proxy_auth = CURLAUTH_DIGEST; else if(!strcmp(parameter, "ntlm")) - proxy_auth = NTLM; + proxy_auth = CURLAUTH_NTLM; else fprintf(stderr, "Proxy authentication method %s not known, please use basic, digest or ntlm", @@ -121,26 +123,26 @@ int writefreshconfig(char * htde_path, char * issue_path, int * update) fprintf(config_file, "%s = %i\n", "startup_check", *update); if(issue_uri[0]) fprintf(config_file, "%s = %s\n", "toc_uri", issue_uri); - if(proxy_type != NONE) + if(proxy_type) { - if(proxy_type = HTTP) + if(proxy_type == CURLPROXY_HTTP) fprintf(config_file, "%s = %s\n", "proxy_type", "http"); - else if(proxy_type = SOCKS4) + else if(proxy_type == CURLPROXY_SOCKS4) fprintf(config_file, "%s = %s\n", "proxy_type", "socks4"); - else if(proxy_type = SOCKS5) + else if(proxy_type == CURLPROXY_SOCKS5) fprintf(config_file, "%s = %s\n", "proxy_type", "socks5"); } if(proxy_addr[0]) fprintf(config_file, "%s = %s\n", "proxy_address", proxy_addr); if(proxy_port) fprintf(config_file, "%s = %i\n", "proxy_port", proxy_port); - if(proxy_auth != NOAUTH) + if(proxy_auth) { - if(proxy_auth = BASIC) + if(proxy_auth = CURLAUTH_BASIC) fprintf(config_file, "%s = %s\n", "proxy_auth", "basic"); - else if(proxy_auth = DIGEST) + else if(proxy_auth = CURLAUTH_DIGEST) fprintf(config_file, "%s = %s\n", "proxy_auth", "digest"); - else if(proxy_auth = NTLM) + else if(proxy_auth = CURLAUTH_NTLM) fprintf(config_file, "%s = %s\n", "proxy_auth", "ntlm"); } if(proxy_user[0]) 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); } } diff --git a/src/getht.c b/src/getht.c index 3df802c..5502552 100644 --- a/src/getht.c +++ b/src/getht.c @@ -32,8 +32,8 @@ int update_contents_files(); -proxytype proxy_type; char proxy_addr[STR_MAX]; long proxy_port; -proxyauth proxy_auth; +int proxy_type; char proxy_addr[STR_MAX]; long proxy_port; +int proxy_auth; char proxy_user[STR_MAX]; char proxy_pass[STR_MAX]; char issue_xml[STR_MAX]; char issue_uri[STR_MAX]; @@ -67,10 +67,10 @@ int main(int argc, char *argv[]) int force = 0, update = 0; int verbose = 0, option = 0; - proxy_type = NONE; + proxy_type = 0; proxy_port = 0; proxy_addr[0] = '\0'; - proxy_auth = NOAUTH; + proxy_auth = 0; proxy_user[0] = '\0'; proxy_pass[0] = '\0'; diff --git a/src/getht.h b/src/getht.h index c5f0728..ee5176a 100644 --- a/src/getht.h +++ b/src/getht.h @@ -27,18 +27,5 @@ #define STR_MAX 512 -typedef enum -{ - NONE, - HTTP, - SOCKS4, - SOCKS5 -} proxytype; - -typedef enum -{ - NOAUTH, - BASIC, - DIGEST, - NTLM, -} proxyauth; +char * proxytype; +char * proxyauth; |