summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2005-02-21 00:10:08 +0000
committerJason Woodward2005-02-21 00:10:08 +0000
commita41b7c82a4600cb353c85ab87b627e3996a634cb (patch)
tree755db0cf6486487d3f841cf80def2a564d9bbfc8 /src
parent678a60b86186172562d23dbf4e9d502a8a95eca7 (diff)
downloadslapt-get-a41b7c82a4600cb353c85ab87b627e3996a634cb.tar.gz
configuration sources now dynamically created instead of static arrays
Diffstat (limited to 'src')
-rw-r--r--src/configuration.c84
-rw-r--r--src/configuration.h9
-rw-r--r--src/package.c30
3 files changed, 67 insertions, 56 deletions
diff --git a/src/configuration.c b/src/configuration.c
index bb45122..35caec3 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -30,7 +30,6 @@ rc_config *read_rc_config(const char *file_name){
global_config = slapt_malloc( sizeof *global_config );
/* initialize */
- global_config->sources.count = FALSE;
global_config->download_only = FALSE;
global_config->simulate = FALSE;
global_config->ignore_excludes = FALSE;
@@ -46,6 +45,9 @@ rc_config *read_rc_config(const char *file_name){
global_config->working_dir[0] = '\0';
global_config->remove_obsolete = FALSE;
global_config->progress_cb = NULL;
+ global_config->sources = slapt_malloc(sizeof *global_config->sources );
+ global_config->sources->url = slapt_malloc(sizeof *global_config->sources->url );
+ global_config->sources->count = 0;
rc = open_file(file_name,"r");
if( rc == NULL ) exit(1);
@@ -62,37 +64,8 @@ rc_config *read_rc_config(const char *file_name){
if( strstr(getline_buffer,SOURCE_TOKEN) != NULL ){ /* SOURCE URL */
- /* make sure we stay within the limits of MAX_SOURCES */
- if( global_config->sources.count == MAX_SOURCES ){
- fprintf(stderr,_("Maximum number of sources (%d) exceeded.\n"),MAX_SOURCES);
- continue;
- }
-
- if( strlen(getline_buffer) > strlen(SOURCE_TOKEN) ){
- if( (strlen(getline_buffer) - strlen(SOURCE_TOKEN)) >= MAX_SOURCE_URL_LEN ){
- fprintf(stderr,_("Maximum length of source (%d) exceeded.\n"),MAX_SOURCE_URL_LEN);
- continue;
- }
- strncpy(
- global_config->sources.url[global_config->sources.count],
- getline_buffer + strlen(SOURCE_TOKEN),
- (strlen(getline_buffer) - strlen(SOURCE_TOKEN))
- );
- global_config->sources.url[global_config->sources.count][
- (strlen(getline_buffer) - strlen(SOURCE_TOKEN))
- ] = '\0';
-
- /* make sure our url has a trailing '/' */
- if( global_config->sources.url[global_config->sources.count]
- [
- strlen(global_config->sources.url[global_config->sources.count]) - 1
- ] != '/'
- ){
- strcat(global_config->sources.url[global_config->sources.count],"/");
- }
- ++global_config->sources.count;
-
- }
+ if( strlen(getline_buffer) > strlen(SOURCE_TOKEN) )
+ add_source(global_config->sources,getline_buffer + strlen(SOURCE_TOKEN));
} else if( strstr(getline_buffer,WORKINGDIR_TOKEN) != NULL ){ /* WORKING DIR */
@@ -125,7 +98,7 @@ rc_config *read_rc_config(const char *file_name){
global_config->exclude_list->excludes = slapt_malloc( sizeof *global_config->exclude_list->excludes );
global_config->exclude_list->count = 0;
}
- if( global_config->sources.count == 0 ){
+ if( global_config->sources->count == 0 ){
fprintf(stderr,_("SOURCE directive not set within %s.\n"),file_name);
return NULL;
}
@@ -160,12 +133,18 @@ void working_dir_init(const rc_config *global_config){
void free_rc_config(rc_config *global_config){
unsigned int i;
- for(i = 0; i < global_config->exclude_list->count; i++){
+ for(i = 0; i < global_config->exclude_list->count; ++i){
free(global_config->exclude_list->excludes[i]);
}
-
free(global_config->exclude_list->excludes);
free(global_config->exclude_list);
+
+ for(i = 0; i < global_config->sources->count; ++i){
+ free(global_config->sources->url[i]);
+ }
+ free(global_config->sources->url);
+ free(global_config->sources);
+
free(global_config);
}
@@ -217,7 +196,7 @@ static struct exclude_list *parse_exclude(char *line){
return list;
}
-void add_exclude(struct exclude_list *list, char *e){
+void add_exclude(struct exclude_list *list,const char *e){
char **realloc_tmp;
realloc_tmp = realloc( list->excludes, sizeof *list->excludes * (list->count + 1) );
@@ -231,3 +210,36 @@ void add_exclude(struct exclude_list *list, char *e){
}
+void add_source(struct source_list *list,const char *s){
+ char **realloc_tmp;
+
+ realloc_tmp = realloc(list->url,sizeof *list->url * (list->count + 1) );
+
+ if( realloc_tmp == NULL ) return;
+
+ list->url = realloc_tmp;
+
+ if( s[strlen(s) - 1] != '/' ){
+ list->url[ list->count ] = slapt_malloc(
+ sizeof *list->url[list->count] * (strlen(s) + 2)
+ );
+ list->url[list->count] = strncat(
+ list->url[list->count],
+ s,
+ strlen(s) - 1
+ );
+ list->url[list->count] = strncat(
+ list->url[list->count],
+ "/",
+ strlen("/")
+ );
+ list->url[list->count][strlen(s) + 1] = '\0';
+ }else{
+ list->url[ list->count ] = strndup(s,strlen(s));
+ list->url[ list->count ][strlen(s)] = '\0';
+ }
+
+ ++list->count;
+
+}
+
diff --git a/src/configuration.h b/src/configuration.h
index 7ac27ca..dcb7d45 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -20,8 +20,6 @@
#define WORKINGDIR_TOKEN "WORKINGDIR="
#define WORKINGDIR_TOKEN_LEN 256
#define EXCLUDE_TOKEN "EXCLUDE="
-#define MAX_SOURCES 20
-#define MAX_SOURCE_URL_LEN 400
struct exclude_list {
char **excludes;
@@ -29,12 +27,12 @@ struct exclude_list {
};
struct source_list {
- char url[MAX_SOURCES][MAX_SOURCE_URL_LEN];
+ char **url;
unsigned int count;
};
typedef struct {
- struct source_list sources;
+ struct source_list *sources;
char working_dir[WORKINGDIR_TOKEN_LEN];
BOOL_T download_only;
BOOL_T dist_upgrade;
@@ -56,4 +54,5 @@ typedef struct {
rc_config *read_rc_config(const char *file_name);
void working_dir_init(const rc_config *global_config);
void free_rc_config(rc_config *global_config);
-void add_exclude(struct exclude_list *list, char *e);
+void add_exclude(struct exclude_list *list,const char *e);
+void add_source(struct source_list *list,const char *s);
diff --git a/src/package.c b/src/package.c
index e38af30..6fdb10d 100644
--- a/src/package.c
+++ b/src/package.c
@@ -1564,7 +1564,7 @@ int update_pkg_cache(const rc_config *global_config){
}
/* go through each package source and download the meta data */
- for(i = 0; i < global_config->sources.count; i++){
+ for(i = 0; i < global_config->sources->count; i++){
FILE *tmp_pkg_f,*tmp_patch_f,*tmp_checksum_f;
struct pkg_list *available_pkgs = NULL;
struct pkg_list *patch_pkgs = NULL;
@@ -1575,9 +1575,9 @@ int update_pkg_cache(const rc_config *global_config){
/* download our PKG_LIST */
- printf(_("Retrieving package data [%s]..."),global_config->sources.url[i]);
- pkg_filename = gen_filename_from_url(global_config->sources.url[i],PKG_LIST);
- pkg_head = head_mirror_data(global_config->sources.url[i],PKG_LIST);
+ printf(_("Retrieving package data [%s]..."),global_config->sources->url[i]);
+ pkg_filename = gen_filename_from_url(global_config->sources->url[i],PKG_LIST);
+ pkg_head = head_mirror_data(global_config->sources->url[i],PKG_LIST);
pkg_local_head = read_head_cache(pkg_filename);
/* open for reading if cached, otherwise write it from the downloaded data */
@@ -1588,7 +1588,7 @@ int update_pkg_cache(const rc_config *global_config){
}else{
if( global_config->dl_stats == TRUE ) printf("\n");
if( (tmp_pkg_f = open_file(pkg_filename,"w+b")) == NULL ) exit(1);
- if( get_mirror_data_from_source(tmp_pkg_f,global_config,global_config->sources.url[i],PKG_LIST) == 0 ){
+ if( get_mirror_data_from_source(tmp_pkg_f,global_config,global_config->sources->url[i],PKG_LIST) == 0 ){
rewind(tmp_pkg_f); /* make sure we are back at the front of the file */
available_pkgs = parse_packages_txt(tmp_pkg_f);
if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
@@ -1610,9 +1610,9 @@ int update_pkg_cache(const rc_config *global_config){
/* download PATCHES_LIST */
- printf(_("Retrieving patch list [%s]..."),global_config->sources.url[i]);
- patch_filename = gen_filename_from_url(global_config->sources.url[i],PATCHES_LIST);
- patch_head = head_mirror_data(global_config->sources.url[i],PATCHES_LIST);
+ printf(_("Retrieving patch list [%s]..."),global_config->sources->url[i]);
+ patch_filename = gen_filename_from_url(global_config->sources->url[i],PATCHES_LIST);
+ patch_head = head_mirror_data(global_config->sources->url[i],PATCHES_LIST);
patch_local_head = read_head_cache(patch_filename);
/* open for reading if cached, otherwise write it from the downloaded data */
@@ -1623,7 +1623,7 @@ int update_pkg_cache(const rc_config *global_config){
}else{
if( global_config->dl_stats == TRUE ) printf("\n");
if( (tmp_patch_f = open_file(patch_filename,"w+b")) == NULL ) exit (1);
- if( get_mirror_data_from_source(tmp_patch_f,global_config,global_config->sources.url[i],PATCHES_LIST) == 0 ){
+ if( get_mirror_data_from_source(tmp_patch_f,global_config,global_config->sources->url[i],PATCHES_LIST) == 0 ){
rewind(tmp_patch_f); /* make sure we are back at the front of the file */
patch_pkgs = parse_packages_txt(tmp_patch_f);
if( global_config->dl_stats == FALSE ) printf(_("Done\n"));
@@ -1642,9 +1642,9 @@ int update_pkg_cache(const rc_config *global_config){
/* download checksum file */
- printf(_("Retrieving checksum list [%s]..."), global_config->sources.url[i]);
- checksum_filename = gen_filename_from_url(global_config->sources.url[i],CHECKSUM_FILE);
- checksum_head = head_mirror_data(global_config->sources.url[i],CHECKSUM_FILE);
+ printf(_("Retrieving checksum list [%s]..."), global_config->sources->url[i]);
+ checksum_filename = gen_filename_from_url(global_config->sources->url[i],CHECKSUM_FILE);
+ checksum_head = head_mirror_data(global_config->sources->url[i],CHECKSUM_FILE);
checksum_local_head = read_head_cache(checksum_filename);
/* open for reading if cached, otherwise write it from the downloaded data */
@@ -1655,7 +1655,7 @@ int update_pkg_cache(const rc_config *global_config){
if( global_config->dl_stats == TRUE ) printf("\n");
if( (tmp_checksum_f = open_file(checksum_filename,"w+b")) == NULL ) exit(1);
if( get_mirror_data_from_source(
- tmp_checksum_f,global_config,global_config->sources.url[i],CHECKSUM_FILE
+ tmp_checksum_f,global_config,global_config->sources->url[i],CHECKSUM_FILE
) != 0
){
source_dl_failed = 1;
@@ -1694,8 +1694,8 @@ int update_pkg_cache(const rc_config *global_config){
printf(_("Done\n"));
/* write package listings to disk */
- write_pkg_data(global_config->sources.url[i],pkg_list_fh_tmp,available_pkgs);
- write_pkg_data(global_config->sources.url[i],pkg_list_fh_tmp,patch_pkgs);
+ write_pkg_data(global_config->sources->url[i],pkg_list_fh_tmp,available_pkgs);
+ write_pkg_data(global_config->sources->url[i],pkg_list_fh_tmp,patch_pkgs);
}
if ( available_pkgs ) free_pkg_list(available_pkgs);