conf.c: store repo settings in dedicated struct
Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
parent
92febc847c
commit
2aa85c3bfd
|
@ -151,6 +151,15 @@ int config_free(config_t *oldconfig)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void config_repo_free(config_repo_t *repo)
|
||||||
|
{
|
||||||
|
if(repo == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
FREELIST(repo->servers);
|
||||||
|
free(repo);
|
||||||
|
}
|
||||||
|
|
||||||
/** Helper function for download_with_xfercommand() */
|
/** Helper function for download_with_xfercommand() */
|
||||||
static char *get_filename(const char *url)
|
static char *get_filename(const char *url)
|
||||||
{
|
{
|
||||||
|
@ -768,14 +777,10 @@ static int setup_libalpm(void)
|
||||||
* calling library methods.
|
* calling library methods.
|
||||||
*/
|
*/
|
||||||
struct section_t {
|
struct section_t {
|
||||||
/* useful for all sections */
|
|
||||||
const char *name;
|
const char *name;
|
||||||
|
config_repo_t *repo;
|
||||||
int is_options;
|
int is_options;
|
||||||
int parse_options;
|
int parse_options;
|
||||||
/* db section option gathering */
|
|
||||||
alpm_list_t *servers;
|
|
||||||
alpm_siglevel_t siglevel;
|
|
||||||
alpm_db_usage_t usage;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int process_usage(alpm_list_t *values, alpm_db_usage_t *usage,
|
static int process_usage(alpm_list_t *values, alpm_db_usage_t *usage,
|
||||||
|
@ -816,6 +821,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
|
||||||
int line, struct section_t *section)
|
int line, struct section_t *section)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
config_repo_t *repo = section->repo;
|
||||||
|
|
||||||
if(strcmp(key, "Server") == 0) {
|
if(strcmp(key, "Server") == 0) {
|
||||||
if(!value) {
|
if(!value) {
|
||||||
|
@ -823,7 +829,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
|
||||||
file, line, key);
|
file, line, key);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
} else {
|
} else {
|
||||||
section->servers = alpm_list_add(section->servers, strdup(value));
|
repo->servers = alpm_list_add(repo->servers, strdup(value));
|
||||||
}
|
}
|
||||||
} else if(strcmp(key, "SigLevel") == 0) {
|
} else if(strcmp(key, "SigLevel") == 0) {
|
||||||
if(!value) {
|
if(!value) {
|
||||||
|
@ -833,10 +839,10 @@ static int _parse_repo(const char *key, char *value, const char *file,
|
||||||
alpm_list_t *values = NULL;
|
alpm_list_t *values = NULL;
|
||||||
setrepeatingoption(value, "SigLevel", &values);
|
setrepeatingoption(value, "SigLevel", &values);
|
||||||
if(values) {
|
if(values) {
|
||||||
if(section->siglevel == ALPM_SIG_USE_DEFAULT) {
|
if(repo->siglevel == ALPM_SIG_USE_DEFAULT) {
|
||||||
section->siglevel = config->siglevel;
|
repo->siglevel = config->siglevel;
|
||||||
}
|
}
|
||||||
ret = process_siglevel(values, §ion->siglevel, file, line);
|
ret = process_siglevel(values, &repo->siglevel, file, line);
|
||||||
FREELIST(values);
|
FREELIST(values);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -844,7 +850,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
|
||||||
alpm_list_t *values = NULL;
|
alpm_list_t *values = NULL;
|
||||||
setrepeatingoption(value, "Usage", &values);
|
setrepeatingoption(value, "Usage", &values);
|
||||||
if(values) {
|
if(values) {
|
||||||
if(process_usage(values, §ion->usage, file, line)) {
|
if(process_usage(values, &repo->usage, file, line)) {
|
||||||
FREELIST(values);
|
FREELIST(values);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -870,51 +876,42 @@ static int _parse_repo(const char *key, char *value, const char *file,
|
||||||
*/
|
*/
|
||||||
static int finish_section(struct section_t *section)
|
static int finish_section(struct section_t *section)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
alpm_db_t *db;
|
alpm_db_t *db;
|
||||||
|
config_repo_t *repo = section->repo;
|
||||||
|
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config: finish section '%s'\n", section->name);
|
pm_printf(ALPM_LOG_DEBUG, "config: finish section '%s'\n", section->name);
|
||||||
|
|
||||||
/* parsing options (or nothing)- nothing to do except free the pieces */
|
/* parsing options (or nothing)- nothing to do except free the pieces */
|
||||||
if(!section->name || section->parse_options || section->is_options) {
|
if(section->parse_options || !section->repo) {
|
||||||
goto cleanup;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we are not looking at options sections only, register a db */
|
/* if we are not looking at options sections only, register a db */
|
||||||
db = alpm_register_syncdb(config->handle, section->name, section->siglevel);
|
db = alpm_register_syncdb(config->handle, section->name, repo->siglevel);
|
||||||
if(db == NULL) {
|
if(db == NULL) {
|
||||||
pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
|
pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
|
||||||
section->name, alpm_strerror(alpm_errno(config->handle)));
|
section->name, alpm_strerror(alpm_errno(config->handle)));
|
||||||
ret = 1;
|
return 1;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pm_printf(ALPM_LOG_DEBUG,
|
pm_printf(ALPM_LOG_DEBUG,
|
||||||
"setting usage of %d for %s repoistory\n",
|
"setting usage of %d for %s repository\n",
|
||||||
section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage,
|
repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage,
|
||||||
section->name);
|
section->name);
|
||||||
alpm_db_set_usage(db, section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage);
|
alpm_db_set_usage(db, repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage);
|
||||||
|
|
||||||
for(i = section->servers; i; i = alpm_list_next(i)) {
|
for(i = repo->servers; i; i = alpm_list_next(i)) {
|
||||||
char *value = i->data;
|
char *value = i->data;
|
||||||
if(_add_mirror(db, value) != 0) {
|
if(_add_mirror(db, value) != 0) {
|
||||||
pm_printf(ALPM_LOG_ERROR,
|
pm_printf(ALPM_LOG_ERROR,
|
||||||
_("could not add mirror '%s' to database '%s' (%s)\n"),
|
_("could not add mirror '%s' to database '%s' (%s)\n"),
|
||||||
value, section->name, alpm_strerror(alpm_errno(config->handle)));
|
value, section->name, alpm_strerror(alpm_errno(config->handle)));
|
||||||
ret = 1;
|
return 1;
|
||||||
goto cleanup;
|
|
||||||
}
|
}
|
||||||
free(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
alpm_list_free(section->servers);
|
|
||||||
section->servers = NULL;
|
|
||||||
section->siglevel = ALPM_SIG_USE_DEFAULT;
|
|
||||||
section->name = NULL;
|
|
||||||
section->usage = 0;
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _parse_directive(const char *file, int linenum, const char *name,
|
static int _parse_directive(const char *file, int linenum, const char *name,
|
||||||
|
@ -922,13 +919,20 @@ static int _parse_directive(const char *file, int linenum, const char *name,
|
||||||
{
|
{
|
||||||
struct section_t *section = data;
|
struct section_t *section = data;
|
||||||
if(!key && !value) {
|
if(!key && !value) {
|
||||||
int ret = finish_section(section);
|
int ret = finish_section(data);
|
||||||
pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
|
|
||||||
section->name = name;
|
section->name = name;
|
||||||
if(name && strcmp(name, "options") == 0) {
|
pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
|
||||||
|
config_repo_free(section->repo);
|
||||||
|
section->repo = NULL;
|
||||||
|
section->is_options = 0;
|
||||||
|
if(!name) {
|
||||||
|
/* end of file, do nothing */
|
||||||
|
} else if(strcmp(name, "options") == 0) {
|
||||||
section->is_options = 1;
|
section->is_options = 1;
|
||||||
} else {
|
} else if(!section->parse_options) {
|
||||||
section->is_options = 0;
|
section->repo = calloc(sizeof(config_repo_t), 1);
|
||||||
|
section->repo->siglevel = ALPM_SIG_USE_DEFAULT;
|
||||||
|
section->repo->usage = 0;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -942,7 +946,7 @@ static int _parse_directive(const char *file, int linenum, const char *name,
|
||||||
if(section->parse_options && section->is_options) {
|
if(section->parse_options && section->is_options) {
|
||||||
/* we are either in options ... */
|
/* we are either in options ... */
|
||||||
return _parse_options(key, value, file, linenum);
|
return _parse_options(key, value, file, linenum);
|
||||||
} else if(!section->parse_options && !section->is_options) {
|
} else if(!section->parse_options && section->repo) {
|
||||||
/* ... or in a repo section */
|
/* ... or in a repo section */
|
||||||
return _parse_repo(key, value, file, linenum, section);
|
return _parse_repo(key, value, file, linenum, section);
|
||||||
}
|
}
|
||||||
|
@ -959,8 +963,6 @@ int parseconfig(const char *file)
|
||||||
int ret;
|
int ret;
|
||||||
struct section_t section;
|
struct section_t section;
|
||||||
memset(§ion, 0, sizeof(struct section_t));
|
memset(§ion, 0, sizeof(struct section_t));
|
||||||
section.siglevel = ALPM_SIG_USE_DEFAULT;
|
|
||||||
section.usage = 0;
|
|
||||||
/* the config parse is a two-pass affair. We first parse the entire thing for
|
/* the config parse is a two-pass affair. We first parse the entire thing for
|
||||||
* the [options] section so we can get all default and path options set.
|
* the [options] section so we can get all default and path options set.
|
||||||
* Next, we go back and parse everything but [options]. */
|
* Next, we go back and parse everything but [options]. */
|
||||||
|
|
|
@ -34,6 +34,12 @@ typedef struct __colstr_t {
|
||||||
const char *nocolor;
|
const char *nocolor;
|
||||||
} colstr_t;
|
} colstr_t;
|
||||||
|
|
||||||
|
typedef struct __config_repo_t {
|
||||||
|
alpm_list_t *servers;
|
||||||
|
alpm_db_usage_t usage;
|
||||||
|
alpm_siglevel_t siglevel;
|
||||||
|
} config_repo_t;
|
||||||
|
|
||||||
typedef struct __config_t {
|
typedef struct __config_t {
|
||||||
unsigned short op;
|
unsigned short op;
|
||||||
unsigned short quiet;
|
unsigned short quiet;
|
||||||
|
@ -208,6 +214,8 @@ void enable_colors(int colors);
|
||||||
config_t *config_new(void);
|
config_t *config_new(void);
|
||||||
int config_free(config_t *oldconfig);
|
int config_free(config_t *oldconfig);
|
||||||
|
|
||||||
|
void config_repo_free(config_repo_t *repo);
|
||||||
|
|
||||||
int config_set_arch(const char *arch);
|
int config_set_arch(const char *arch);
|
||||||
int parseconfig(const char *file);
|
int parseconfig(const char *file);
|
||||||
#endif /* _PM_CONF_H */
|
#endif /* _PM_CONF_H */
|
||||||
|
|
Loading…
Reference in New Issue