From 36f702ba826f2d3bebb4df3232c1b2b64a03f8a5 Mon Sep 17 00:00:00 2001 From: Andrew Gregory Date: Mon, 22 Jul 2013 02:46:46 -0400 Subject: conf.c: move repo parsing out of _parseconfig Signed-off-by: Andrew Gregory Signed-off-by: Allan McRae --- src/pacman/conf.c | 65 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/pacman/conf.c b/src/pacman/conf.c index e9a29e37..ca49749d 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -752,6 +752,43 @@ struct section_t { alpm_list_t *servers; }; +static int _parse_repo(const char *key, char *value, const char *file, + int line, struct section_t *section) +{ + int ret = 0; + + if(strcmp(key, "Server") == 0) { + if(!value) { + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), + file, line, key); + ret = 1; + } else { + section->servers = alpm_list_add(section->servers, strdup(value)); + } + } else if(strcmp(key, "SigLevel") == 0) { + if(!value) { + pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), + file, line, key); + } else { + alpm_list_t *values = NULL; + setrepeatingoption(value, "SigLevel", &values); + if(values) { + if(section->siglevel == ALPM_SIG_USE_DEFAULT) { + section->siglevel = config->siglevel; + } + ret = process_siglevel(values, §ion->siglevel, file, line); + FREELIST(values); + } + } + } else { + pm_printf(ALPM_LOG_WARNING, + _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), + file, line, key, section->name); + } + + return ret; +} + /** * Wrap up a section once we have reached the end of it. This should be called * when a subsequent section is encountered, or when we have reached the end of @@ -946,32 +983,8 @@ static int _parseconfig(const char *file, struct section_t *section, int depth) } } else if(!section->parse_options && !section->is_options) { /* ... or in a repo section */ - if(strcmp(key, "Server") == 0) { - if(value == NULL) { - pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"), - file, linenum, key); - ret = 1; - goto cleanup; - } - section->servers = alpm_list_add(section->servers, strdup(value)); - } else if(strcmp(key, "SigLevel") == 0) { - alpm_list_t *values = NULL; - setrepeatingoption(value, "SigLevel", &values); - if(values) { - if(section->siglevel == ALPM_SIG_USE_DEFAULT) { - section->siglevel = config->siglevel; - } - if(process_siglevel(values, §ion->siglevel, file, linenum)) { - FREELIST(values); - ret = 1; - goto cleanup; - } - FREELIST(values); - } - } else { - pm_printf(ALPM_LOG_WARNING, - _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), - file, linenum, key, section->name); + if((ret = _parse_repo(key, value, file, linenum, section)) != 0) { + goto cleanup; } } } -- cgit v1.2.3-24-g4f1b