X-Git-Url: https://git.librecmc.org/?p=oweals%2Fopkg-lede.git;a=blobdiff_plain;f=libopkg%2Fopkg_conf.c;h=4b2ad03bbb10498af65cdb2e367528d384bddebc;hp=57c670edca340313346383c989dd1dcecf621379;hb=94b0a6bec6a0d3301e28385ee3fdf4c19f67b866;hpb=11af232b19155c76002b5ca1f2b0e89d75699d3a diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c index 57c670e..4b2ad03 100644 --- a/libopkg/opkg_conf.c +++ b/libopkg/opkg_conf.c @@ -50,7 +50,7 @@ static int set_and_load_pkg_src_list(opkg_conf_t *conf, static int set_and_load_pkg_dest_list(opkg_conf_t *conf, nv_pair_list_t *nv_pair_list, char * lists_dir); -int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options) +void opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options) { opkg_option_t tmp[] = { { "cache", OPKG_OPT_TYPE_STRING, &conf->cache}, @@ -80,6 +80,9 @@ int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options) { "signature_ca_file", OPKG_OPT_TYPE_STRING, &conf->signature_ca_file }, { "signature_ca_path", OPKG_OPT_TYPE_STRING, &conf->signature_ca_path }, #endif +#if defined(HAVE_PATHFINDER) + { "check_x509_path", OPKG_OPT_TYPE_INT, &conf->check_x509_path }, +#endif #if defined(HAVE_SSLCURL) && defined(HAVE_CURL) { "ssl_engine", OPKG_OPT_TYPE_STRING, &conf->ssl_engine }, { "ssl_cert", OPKG_OPT_TYPE_STRING, &conf->ssl_cert }, @@ -94,14 +97,8 @@ int opkg_init_options_array(const opkg_conf_t *conf, opkg_option_t **options) { NULL } }; - *options = (opkg_option_t *)calloc(1, sizeof(tmp)); - if ( options == NULL ){ - fprintf(stderr,"%s: Unable to allocate memory\n",__FUNCTION__); - return -1; - } - + *options = xcalloc(1, sizeof(tmp)); memcpy(*options, tmp, sizeof(tmp)); - return 0; }; static void opkg_conf_override_string(char **conf_str, char *arg_str) @@ -135,6 +132,10 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args) memset(conf, 0, sizeof(opkg_conf_t)); +#if defined(HAVE_PATHFINDER) + conf->check_x509_path = 1; +#endif + pkg_src_list_init(&conf->pkg_src_list); nv_pair_list_init(&tmp_dest_nv_pair_list); @@ -186,7 +187,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args) pkg_hash_init("pkg-hash", &conf->pkg_hash, OPKG_CONF_DEFAULT_HASH_LEN); hash_table_init("file-hash", &conf->file_hash, OPKG_CONF_DEFAULT_HASH_LEN); hash_table_init("obs-file-hash", &conf->obs_file_hash, OPKG_CONF_DEFAULT_HASH_LEN); - lists_dir=(char *)malloc(1); + lists_dir=xmalloc(1); lists_dir[0]='\0'; if (args->conf_file) { struct stat stat_buf; @@ -200,7 +201,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args) } if (strlen(lists_dir)<=1 ){ - lists_dir = realloc(lists_dir,strlen(OPKG_CONF_LISTS_DIR)+2); + lists_dir = xrealloc(lists_dir,strlen(OPKG_CONF_LISTS_DIR)+2); sprintf (lists_dir,"%s",OPKG_CONF_LISTS_DIR); } @@ -211,7 +212,7 @@ int opkg_conf_init(opkg_conf_t *conf, const args_t *args) lists_dir = tmp; } - pending_dir = calloc(1, strlen(lists_dir)+strlen("/pending")+5); + pending_dir = xcalloc(1, strlen(lists_dir)+strlen("/pending")+5); snprintf(pending_dir,strlen(lists_dir)+strlen("/pending") ,"%s%s",lists_dir,"/pending"); conf->lists_dir = xstrdup(lists_dir); @@ -369,12 +370,6 @@ void opkg_conf_deinit(opkg_conf_t *conf) pkg_src_list_deinit(&conf->pkg_src_list); pkg_dest_list_deinit(&conf->pkg_dest_list); nv_pair_list_deinit(&conf->arch_list); - if (&conf->pkg_hash) - pkg_hash_deinit(&conf->pkg_hash); - if (&conf->file_hash) - hash_table_deinit(&conf->file_hash); - if (&conf->obs_file_hash) - hash_table_deinit(&conf->obs_file_hash); opkg_conf_free_string(&conf->offline_root); opkg_conf_free_string(&conf->offline_root_path); @@ -424,9 +419,15 @@ void opkg_conf_deinit(opkg_conf_t *conf) } opkg_message(conf, OPKG_DEBUG, "hash_table[%s] n_buckets=%d n_elements=%d max_conflicts=%d n_conflicts=%d\n", hash->name, hash->n_entries, hash->n_elements, c, n_conflicts); - hash_table_deinit(hash); } } + + if (&conf->pkg_hash) + pkg_hash_deinit(&conf->pkg_hash); + if (&conf->file_hash) + hash_table_deinit(&conf->file_hash); + if (&conf->obs_file_hash) + hash_table_deinit(&conf->obs_file_hash); } static int opkg_conf_set_default_dest(opkg_conf_t *conf, @@ -518,8 +519,7 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, #define regmatch_size 12 regmatch_t regmatch[regmatch_size]; - if (opkg_init_options_array(conf, &options)<0) - return ENOMEM; + opkg_init_options_array(conf, &options); if (file == NULL) { fprintf(stderr, "%s: failed to open %s: %s\n", @@ -568,29 +568,29 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, /* This has to be so ugly to deal with optional quotation marks */ if (regmatch[2].rm_so > 0) { - type = strndup(line + regmatch[2].rm_so, + type = xstrndup(line + regmatch[2].rm_so, regmatch[2].rm_eo - regmatch[2].rm_so); } else { - type = strndup(line + regmatch[3].rm_so, + type = xstrndup(line + regmatch[3].rm_so, regmatch[3].rm_eo - regmatch[3].rm_so); } if (regmatch[5].rm_so > 0) { - name = strndup(line + regmatch[5].rm_so, + name = xstrndup(line + regmatch[5].rm_so, regmatch[5].rm_eo - regmatch[5].rm_so); } else { - name = strndup(line + regmatch[6].rm_so, + name = xstrndup(line + regmatch[6].rm_so, regmatch[6].rm_eo - regmatch[6].rm_so); } if (regmatch[8].rm_so > 0) { - value = strndup(line + regmatch[8].rm_so, + value = xstrndup(line + regmatch[8].rm_so, regmatch[8].rm_eo - regmatch[8].rm_so); } else { - value = strndup(line + regmatch[9].rm_so, + value = xstrndup(line + regmatch[9].rm_so, regmatch[9].rm_eo - regmatch[9].rm_so); } extra = NULL; if (regmatch[11].rm_so > 0) { - extra = strndup (line + regmatch[11].rm_so, + extra = xstrndup (line + regmatch[11].rm_so, regmatch[11].rm_eo - regmatch[11].rm_so); } @@ -619,12 +619,7 @@ static int opkg_conf_parse_file(opkg_conf_t *conf, const char *filename, } else if (strcmp(type, "dest") == 0) { nv_pair_list_append(tmp_dest_nv_pair_list, name, value); } else if (strcmp(type, "lists_dir") == 0) { - *lists_dir = realloc(*lists_dir,strlen(value)+1); - if (*lists_dir == NULL) { - opkg_message(conf, OPKG_ERROR, "ERROR: Not enough memory\n"); - free(options); - return EINVAL; - } + *lists_dir = xrealloc(*lists_dir,strlen(value)+1); sprintf (*lists_dir,"%s",value); } else if (strcmp(type, "arch") == 0) { opkg_message(conf, OPKG_INFO, "supported arch %s priority (%s)\n", name, value);