From fe92b3a849126f0bdc4469c236caafae28dceab8 Mon Sep 17 00:00:00 2001 From: Nick White Date: Thu, 8 May 2008 16:23:17 +0100 Subject: Switched to using config structure from global variables --- src/config.c | 90 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 41 insertions(+), 49 deletions(-) (limited to 'src/config.c') diff --git a/src/config.c b/src/config.c index e89bc94..1f02b4b 100644 --- a/src/config.c +++ b/src/config.c @@ -25,22 +25,14 @@ #include -extern int proxy_type; -extern char proxy_addr[STR_MAX]; -extern long proxy_port; -extern int proxy_auth; -extern char proxy_user[STR_MAX]; -extern char proxy_pass[STR_MAX]; -extern char issue_uri[STR_MAX]; - -int loadconfig(char * htde_path, char * save_path, int * update) +int loadconfig(char * getht_path, struct config * options) /* Loads variables from config file to extern and passed * variables. */ { FILE * config_file; char filepath[STR_MAX]; - snprintf(filepath, STR_MAX, "%s/config.ini", htde_path); + snprintf(filepath, STR_MAX, "%s/config.ini", getht_path); if((config_file = fopen(filepath,"r")) == NULL) { @@ -55,45 +47,45 @@ int loadconfig(char * htde_path, char * save_path, int * update) if(option[0] == '#'); /* ignore lines beginning with a hash */ else if(!strcmp(option, "savepath")) - strncpy(save_path, parameter, STR_MAX); + strncpy(options->save_path, parameter, STR_MAX); else if(!strcmp(option, "startup_check")) - *update = atoi(parameter); + options->startup_check = atoi(parameter); else if(!strcmp(option, "toc_uri")) - strncpy(issue_uri, parameter, STR_MAX); + strncpy(options->issue_uri, parameter, STR_MAX); else if(!strcmp(option, "proxy_type")) { if(!strcmp(parameter, "http")) - proxy_type = CURLPROXY_HTTP; + options->proxy.type = CURLPROXY_HTTP; else if(!strcmp(parameter, "socks4")) - proxy_type = CURLPROXY_SOCKS4; + options->proxy.type = CURLPROXY_SOCKS4; else if(!strcmp(parameter, "socks5")) - proxy_type = CURLPROXY_SOCKS5; + options->proxy.type = CURLPROXY_SOCKS5; else fprintf(stderr, "Proxy type %s not known, please use either http, socks4 or socks5\n", parameter); } else if(!strcmp(option, "proxy_address")) - strncpy(proxy_addr, parameter, STR_MAX); + strncpy(options->proxy.address, parameter, STR_MAX); else if(!strcmp(option, "proxy_port")) - proxy_port = (long) atoi(parameter); + options->proxy.port = (long) atoi(parameter); else if(!strcmp(option, "proxy_auth")) { if(!strcmp(parameter, "basic")) - proxy_auth = CURLAUTH_BASIC; + options->proxy.auth = CURLAUTH_BASIC; else if(!strcmp(parameter, "digest")) - proxy_auth = CURLAUTH_DIGEST; + options->proxy.auth = CURLAUTH_DIGEST; else if(!strcmp(parameter, "ntlm")) - proxy_auth = CURLAUTH_NTLM; + options->proxy.auth = CURLAUTH_NTLM; else fprintf(stderr, "Proxy authentication method %s not known, please use basic, digest or ntlm", parameter); } else if(!strcmp(option, "proxy_user")) - strncpy(proxy_user, parameter, STR_MAX); + strncpy(options->proxy.user, parameter, STR_MAX); else if(!strcmp(option, "proxy_pass")) - strncpy(proxy_pass, parameter, STR_MAX); + strncpy(options->proxy.pass, parameter, STR_MAX); else fprintf(stderr, "Option '%s' not recognised, ignoring\n", option); } @@ -101,13 +93,13 @@ int loadconfig(char * htde_path, char * save_path, int * update) return 0; } -int writefreshconfig(char * htde_path, char * save_path, int * update) +int writefreshconfig(char * getht_path, struct config * options) /* Write a new config file according to extern and passed variables. */ { FILE * config_file; char filepath[STR_MAX]; - snprintf(filepath, STR_MAX, "%s/config.ini", htde_path); + snprintf(filepath, STR_MAX, "%s/config.ini", getht_path); if((config_file = fopen(filepath,"w")) == NULL) { @@ -117,50 +109,50 @@ int writefreshconfig(char * htde_path, char * save_path, int * update) else fprintf(stdout,"Writing a fresh config file to %s.\n",filepath); - if(save_path[0]) - fprintf(config_file, "%s = %s\n", "savepath", save_path); - if(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) + if(options->save_path[0]) + fprintf(config_file, "%s = %s\n", "savepath", options->save_path); + if(options->startup_check) + fprintf(config_file, "%s = %i\n", "startup_check", options->startup_check); + if(options->issue_uri[0]) + fprintf(config_file, "%s = %s\n", "toc_uri", options->issue_uri); + if(options->proxy.type) { - if(proxy_type == CURLPROXY_HTTP) + if(options->proxy.type == CURLPROXY_HTTP) fprintf(config_file, "%s = %s\n", "proxy_type", "http"); - else if(proxy_type == CURLPROXY_SOCKS4) + else if(options->proxy.type == CURLPROXY_SOCKS4) fprintf(config_file, "%s = %s\n", "proxy_type", "socks4"); - else if(proxy_type == CURLPROXY_SOCKS5) + else if(options->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) + if(options->proxy.address[0]) + fprintf(config_file, "%s = %s\n", "proxy_address", options->proxy.address); + if(options->proxy.port) + fprintf(config_file, "%s = %i\n", "proxy_port", options->proxy.port); + if(options->proxy.auth) { - if(proxy_auth = CURLAUTH_BASIC) + if(options->proxy.auth = CURLAUTH_BASIC) fprintf(config_file, "%s = %s\n", "proxy_auth", "basic"); - else if(proxy_auth = CURLAUTH_DIGEST) + else if(options->proxy.auth = CURLAUTH_DIGEST) fprintf(config_file, "%s = %s\n", "proxy_auth", "digest"); - else if(proxy_auth = CURLAUTH_NTLM) + else if(options->proxy.auth = CURLAUTH_NTLM) fprintf(config_file, "%s = %s\n", "proxy_auth", "ntlm"); } - if(proxy_user[0]) - fprintf(config_file, "%s = %s\n", "proxy_user", proxy_user); - if(proxy_pass[0]) - fprintf(config_file, "%s = %s\n", "proxy_pass", proxy_pass); + if(options->proxy.user[0]) + fprintf(config_file, "%s = %s\n", "proxy_user", options->proxy.user); + if(options->proxy.pass[0]) + fprintf(config_file, "%s = %s\n", "proxy_pass", options->proxy.pass); return 0; } -int updateconfig(char * htde_path, char * save_path, int * update) +int updateconfig(char * getht_path, struct config * options) /* Read existing config file, and rewrite any variables which differ * in memory. */ { FILE * config_file; char filepath[STR_MAX]; - snprintf(filepath, STR_MAX, "%s/config.ini", htde_path); + snprintf(filepath, STR_MAX, "%s/config.ini", getht_path); if((config_file = fopen(filepath,"rw")) == NULL) { -- cgit v1.2.3