diff options
author | Nick White <arch@njw.me.uk> | 2007-05-26 22:18:56 +0000 |
---|---|---|
committer | Nick White <arch@njw.me.uk> | 2007-05-26 22:18:56 +0000 |
commit | 5b4f728bc58d137dd946030d8c11b309b1216743 (patch) | |
tree | b7b4335fa70b7cbefc8663f68e60ac818dd9ca3c /src | |
parent | 0ccfa432206769a540be50c6e39295c58bf4ea56 (diff) |
General cleanup, Add alt url config options
Removed unused & unnecessary findnewestiss
Replaces strcpy with strncpy to eliminate possible buffer overruns
Added a couple of config options to allow use of alternative
toc urls
git-archimport-id: getht@sv.gnu.org/getht--mainline--0.1--patch-29
Diffstat (limited to 'src')
-rw-r--r-- | src/config.c | 10 | ||||
-rw-r--r-- | src/getht.c | 42 |
2 files changed, 19 insertions, 33 deletions
diff --git a/src/config.c b/src/config.c index 57807b1..8279f54 100644 --- a/src/config.c +++ b/src/config.c @@ -30,6 +30,8 @@ extern long proxy_port; extern proxyauth proxy_auth; extern char proxy_user[STR_MAX]; extern char proxy_pass[STR_MAX]; +extern char issue_url[STR_MAX]; +extern char media_url[STR_MAX]; int loadconfig(char * htde_path, char * issue_path, int * update) /* Loads variables from config file to extern and passed @@ -56,6 +58,10 @@ int loadconfig(char * htde_path, char * issue_path, int * update) strncpy(issue_path, parameter, STR_MAX); else if(!strcmp(option, "startup_check")) *update = atoi(parameter); + else if(!strcmp(option, "toc_url")) + strncpy(issue_url, parameter, STR_MAX); + else if(!strcmp(option, "mediatoc_url")) + strncpy(media_url, parameter, STR_MAX); else if(!strcmp(option, "proxy_type")) { if(!strcmp(parameter, "http")) @@ -117,6 +123,10 @@ int writefreshconfig(char * htde_path, char * issue_path, int * update) fprintf(config_file, "%s = %s\n", "issuepath", issue_path); if(update) fprintf(config_file, "%s = %i\n", "startup_check", *update); + if(issue_url[0]) + fprintf(config_file, "%s = %s\n", "toc_url", issue_url); + if(media_url[0]) + fprintf(config_file, "%s = %s\n", "mediatoc_url", media_url); if(proxy_type != NONE) { if(proxy_type = HTTP) diff --git a/src/getht.c b/src/getht.c index b9a18b7..a00df27 100644 --- a/src/getht.c +++ b/src/getht.c @@ -39,6 +39,7 @@ proxytype proxy_type; char proxy_addr[STR_MAX]; long proxy_port; proxyauth proxy_auth; char proxy_user[STR_MAX]; char proxy_pass[STR_MAX]; char issue_xml[STR_MAX]; char media_xml[STR_MAX]; char media_rev[STR_MAX]; +char issue_url[STR_MAX]; char media_url[STR_MAX]; CURL *main_curl_handle; int main(int argc, char *argv[]) @@ -61,6 +62,9 @@ int main(int argc, char *argv[]) snprintf(media_xml,STR_MAX, "%s/%s", getht_path, MED_XML_FILE); snprintf(media_rev,STR_MAX,"%s/%s",getht_path,MED_REVGZ_FILE); + strncpy(issue_url,XML_TOC_URL,STR_MAX); + strncpy(media_url,MEDIA_TOC_URL,STR_MAX); + snprintf(save_path,STR_MAX,"%s/hinduism_today",getenv("HOME")); int downall = 0, downallmedia = 0; @@ -78,7 +82,7 @@ int main(int argc, char *argv[]) proxy_pass[0] = '\0'; if(loadconfig(getht_path, &save_path, &update) != 0) - writefreshconfig(getht_path, &save_path, &update); + writefreshconfig(getht_path, &save_path, &update, &issue_url, &media_url); if(!opendir(save_path)) if(mkdir(save_path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) @@ -148,12 +152,10 @@ int main(int argc, char *argv[]) option = 1; break; case 't': - strcpy(issue_xml, strdup(optarg)); - option = 1; + strncpy(issue_xml, strdup(optarg), STR_MAX); break; case 'x': - strcpy(media_xml, strdup(optarg)); - option = 1; + strncpy(media_xml, strdup(optarg), STR_MAX); break; case 'h': showusage(); @@ -277,7 +279,7 @@ int main(int argc, char *argv[]) int update_contents_files() /* Returns 0 on success, 1 on failure */ { - if(save_file(NULL, XML_TOC_URL, issue_xml)) + if(save_file(NULL, issue_url, issue_xml)) return 1; char isstitle[STR_MAX]; @@ -295,7 +297,7 @@ int update_contents_files() if(media_accounted_for(media_xml, &date)) { - if(save_file(NULL, MEDIA_TOC_URL, media_rev)) + if(save_file(NULL, media_url, media_rev)) return 1; med ** temp_med; @@ -310,29 +312,3 @@ int update_contents_files() return 0; } - -int findnewestiss(iss ** issue, int no_of_issues) -/* returns newest issue indice */ -{ - iss * tmp_issue; issdates newest; - int new_iss; - - new_iss = -1; - newest.year = 0; newest.firstmonth = 0; newest.lastmonth = 0; - - int i; - - for(i = 0; i <= no_of_issues; i++) - { - if(issue[i]->date.year > newest.year || - (issue[i]->date.year == newest.year && issue[i]->date.firstmonth > newest.firstmonth)) - { - newest.year = issue[i]->date.year; - newest.firstmonth = issue[i]->date.firstmonth; - newest.lastmonth = issue[i]->date.lastmonth; - new_iss = i; - } - } - - return new_iss; -} |