diff options
Diffstat (limited to 'src/pacman/conf.c')
-rw-r--r-- | src/pacman/conf.c | 296 |
1 files changed, 6 insertions, 290 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 1caefd32..dc7b64b6 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -34,8 +34,6 @@ #include "download.h" #include "conf.h" -#define min(X, Y) ((X) < (Y) ? (X) : (Y)) - extern list_t *pmc_syncs; config_t *config_new() @@ -56,303 +54,21 @@ int config_free(config_t *config) } FREE(config->root); - FREE(config->dbpath); - FREE(config->cachedir); FREE(config->configfile); FREELIST(config->op_s_ignore); - FREE(config->proxyhost); - FREE(config->xfercommand); - FREELIST(config->holdpkg); free(config); return(0); } -int parseconfig(char *file, config_t *config) +void cb_db_register(char *section, PM_DB *db) { - FILE *fp = NULL; - char line[PATH_MAX+1]; - char *ptr = NULL; - char *key = NULL; - int linenum = 0; - char section[256] = ""; - sync_t *sync = NULL; - - if(config == NULL) { - return(-1); - } - - fp = fopen(file, "r"); - if(fp == NULL) { - return(0); - } - - while(fgets(line, PATH_MAX, fp)) { - linenum++; - strtrim(line); - if(strlen(line) == 0 || line[0] == '#') { - continue; - } - if(line[0] == '[' && line[strlen(line)-1] == ']') { - /* new config section */ - ptr = line; - ptr++; - strncpy(section, ptr, min(255, strlen(ptr)-1)); - section[min(255, strlen(ptr)-1)] = '\0'; - vprint(_("config: new section '%s'\n"), section); - if(!strlen(section)) { - ERR(NL, _("config: line %d: bad section name\n"), linenum); - return(1); - } - if(!strcmp(section, "local")) { - ERR(NL, _("config: line %d: '%s' is reserved and cannot be used as a package tree\n"), - linenum, section); - return(1); - } - if(strcmp(section, "options")) { - list_t *i; - int found = 0; - for(i = pmc_syncs; i && !found; i = i->next) { - sync = (sync_t *)i->data; - if(!strcmp(sync->treename, section)) { - found = 1; - } - } - if(!found) { - /* start a new sync record */ - MALLOC(sync, sizeof(sync_t)); - sync->treename = strdup(section); - sync->servers = NULL; - pmc_syncs = list_add(pmc_syncs, sync); - } - } - } else { - /* directive */ - ptr = line; - key = strsep(&ptr, "="); - if(key == NULL) { - ERR(NL, _("config: line %d: syntax error\n"), linenum); - return(1); - } - strtrim(key); - key = strtoupper(key); - if(!strlen(section) && strcmp(key, "INCLUDE")) { - ERR(NL, _("config: line %d: all directives must belong to a section\n"), linenum); - return(1); - } - if(ptr == NULL) { - if(!strcmp(key, "NOPASSIVEFTP")) { - config->nopassiveftp = 1; - vprint(_("config: nopassiveftp\n")); - } else if(!strcmp(key, "USESYSLOG")) { - if(alpm_set_option(PM_OPT_USESYSLOG, (long)1) == -1) { - ERR(NL, _("failed to set option USESYSLOG (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: usesyslog\n")); - } else if(!strcmp(key, "ILOVECANDY")) { - config->chomp = 1; - } else { - ERR(NL, _("config: line %d: syntax error\n"), linenum); - return(1); - } - } else { - strtrim(ptr); - if(!strcmp(key, "INCLUDE")) { - char conf[PATH_MAX]; - strncpy(conf, ptr, PATH_MAX); - vprint(_("config: including %s\n"), conf); - parseconfig(conf, config); - } else if(!strcmp(section, "options")) { - if(!strcmp(key, "NOUPGRADE")) { - char *p = ptr; - char *q; - while((q = strchr(p, ' '))) { - *q = '\0'; - if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) { - ERR(NL, _("failed to set option NOUPGRADE (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: noupgrade: %s\n"), p); - p = q; - p++; - } - if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) { - ERR(NL, _("failed to set option NOUPGRADE (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: noupgrade: %s\n"), p); - } else if(!strcmp(key, "NOEXTRACT")) { - char *p = ptr; - char *q; - while((q = strchr(p, ' '))) { - *q = '\0'; - if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) { - ERR(NL, _("failed to set option NOEXTRACT (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: noextract: %s\n"), p); - p = q; - p++; - } - if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) { - ERR(NL, _("failed to set option NOEXTRACT (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: noextract: %s\n"), p); - } else if(!strcmp(key, "IGNOREPKG")) { - char *p = ptr; - char *q; - while((q = strchr(p, ' '))) { - *q = '\0'; - if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) { - ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: ignorepkg: %s\n"), p); - p = q; - p++; - } - if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) { - ERR(NL, _("failed to set option IGNOREPKG (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: ignorepkg: %s\n"), p); - } else if(!strcmp(key, "HOLDPKG")) { - char *p = ptr; - char *q; - while((q = strchr(p, ' '))) { - *q = '\0'; - config->holdpkg = list_add(config->holdpkg, strdup(p)); - vprint(_("config: holdpkg: %s\n"), p); - p = q; - p++; - } - config->holdpkg = list_add(config->holdpkg, strdup(p)); - vprint(_("config: holdpkg: %s\n"), p); - } else if(!strcmp(key, "DBPATH")) { - /* shave off the leading slash, if there is one */ - if(*ptr == '/') { - ptr++; - } - FREE(config->dbpath); - config->dbpath = strdup(ptr); - vprint(_("config: dbpath: %s\n"), ptr); - } else if(!strcmp(key, "CACHEDIR")) { - /* shave off the leading slash, if there is one */ - if(*ptr == '/') { - ptr++; - } - FREE(config->cachedir); - config->cachedir = strdup(ptr); - vprint(_("config: cachedir: %s\n"), ptr); - } else if (!strcmp(key, "LOGFILE")) { - if(alpm_set_option(PM_OPT_LOGFILE, (long)ptr) == -1) { - ERR(NL, _("failed to set option LOGFILE (%s)\n"), alpm_strerror(pm_errno)); - return(1); - } - vprint(_("config: log file: %s\n"), ptr); - } else if (!strcmp(key, "XFERCOMMAND")) { - FREE(config->xfercommand); - config->xfercommand = strndup(ptr, PATH_MAX); - vprint(_("config: xfercommand: %s\n"), config->xfercommand); - } else if (!strcmp(key, "PROXYSERVER")) { - char *p; - if(config->proxyhost) { - FREE(config->proxyhost); - } - p = strstr(ptr, "://"); - if(p) { - p += 3; - if(p == NULL || *p == '\0') { - ERR(NL, _("config: line %d: bad server location\n"), linenum); - return(1); - } - ptr = p; - } - config->proxyhost = strndup(ptr, PATH_MAX); - vprint(_("config: proxyserver: %s\n"), config->proxyhost); - } else if (!strcmp(key, "PROXYPORT")) { - config->proxyport = (unsigned short)atoi(ptr); - vprint(_("config: proxyport: %u\n"), config->proxyport); - } else { - ERR(NL, _("config: line %d: syntax error\n"), linenum); - return(1); - } - } else { - if(!strcmp(key, "SERVER")) { - /* parse our special url */ - server_t *server; - char *p; - - MALLOC(server, sizeof(server_t)); - server->server = server->path = NULL; - server->protocol = NULL; + sync_t *sync; - p = strstr(ptr, "://"); - if(p == NULL) { - ERR(NL, _("config: line %d: bad server location\n"), linenum); - return(1); - } - *p = '\0'; - p++; p++; p++; - if(p == NULL || *p == '\0') { - ERR(NL, _("config: line %d: bad server location\n"), linenum); - return(1); - } - server->protocol = strdup(ptr); - if(!strcmp(server->protocol, "ftp") || !strcmp(server->protocol, "http")) { - char *slash; - /* split the url into domain and path */ - slash = strchr(p, '/'); - if(slash == NULL) { - /* no path included, default to / */ - server->path = strdup("/"); - } else { - /* add a trailing slash if we need to */ - if(slash[strlen(slash)-1] == '/') { - server->path = strdup(slash); - } else { - if((server->path = (char *)malloc(strlen(slash)+2)) == NULL) { - ERR(NL, _("could not allocate %d bytes\n"), sizeof(strlen(slash+2))); - return(1); - } - sprintf(server->path, "%s/", slash); - } - *slash = '\0'; - } - server->server = strdup(p); - } else if(!strcmp(server->protocol, "file")){ - /* add a trailing slash if we need to */ - if(p[strlen(p)-1] == '/') { - server->path = strdup(p); - } else { - server->path = (char *)malloc(strlen(p)+2); - if(server->path == NULL) { - ERR(NL, _("could not allocate %d bytes\n"), sizeof(strlen(p+2))); - return(1); - } - sprintf(server->path, "%s/", p); - } - } else { - ERR(NL, _("config: line %d: protocol %s is not supported\n"), linenum, ptr); - return(1); - } - /* add to the list */ - vprint(_("config: %s: server: %s %s %s\n"), section, server->protocol, server->server, server->path); - sync->servers = list_add(sync->servers, server); - } else { - ERR(NL, _("config: line %d: syntax error\n"), linenum); - return(1); - } - } - line[0] = '\0'; - } - } - } - fclose(fp); - - return(0); + MALLOC(sync, sizeof(sync_t)); + sync->treename = strdup(section); + sync->db = db; + pmc_syncs = list_add(pmc_syncs, sync); } /* vim: set ts=2 sw=2 noet: */ |