summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/alpm.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-06-04 18:51:23 +0200
committerDan McGee <dan@archlinux.org>2007-06-05 05:10:49 +0200
commit358cc5804a2df873180e6d9ef2420ab3247f8437 (patch)
tree9254dd518c1873aebe78f548d311202a6f1fe2aa /lib/libalpm/alpm.c
parent6949ab97613de3622a4c392a3d33080164eec794 (diff)
downloadpacman-358cc5804a2df873180e6d9ef2420ab3247f8437.tar.gz
pacman-358cc5804a2df873180e6d9ef2420ab3247f8437.tar.xz
Rip alpm_parse_config out of libalpm
Switch over to the new frontend parseconfig. * Fix a few issues in parseconfig * Remove unused callback upon database registration * Remove conf file related errors from error.c/alpm.h Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/alpm.c')
-rw-r--r--lib/libalpm/alpm.c207
1 files changed, 1 insertions, 206 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index e3aacd27..f2a6270f 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -138,7 +138,7 @@ pmdb_t SYMEXPORT *alpm_db_register(char *treename)
/* Do not register a database if a transaction is on-going */
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL));
- return(_alpm_db_register(treename, NULL));
+ return(_alpm_db_register(treename));
}
/** Unregister a package database
@@ -869,211 +869,6 @@ char SYMEXPORT *alpm_fetch_pkgurl(char *url)
return(_alpm_fetch_pkgurl(url));
}
-/** Parses a configuration file.
- * @param file path to the config file.
- * @param callback a function to be called upon new database creation
- * @param this_section the config current section being parsed
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
-int SYMEXPORT alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this_section)
-{
- FILE *fp = NULL;
- char line[PATH_MAX+1];
- char *ptr = NULL;
- char *key = NULL;
- int linenum = 0;
- char origkey[256];
- char section[256] = "";
- pmdb_t *db = NULL;
-
- ALPM_LOG_FUNC;
-
- fp = fopen(file, "r");
- if(fp == NULL) {
- return(0);
- }
-
- if(this_section != NULL && strlen(this_section) > 0) {
- strncpy(section, this_section, min(255, strlen(this_section)));
- if(!strcmp(section, "local")) {
- RET_ERR(PM_ERR_CONF_LOCAL, -1);
- }
- if(strcmp(section, "options")) {
- db = _alpm_db_register(section, callback);
- }
- }
-
- while(fgets(line, PATH_MAX, fp)) {
- linenum++;
- _alpm_strtrim(line);
- if(strlen(line) == 0 || line[0] == '#') {
- continue;
- }
- if((ptr = strchr(line, '#'))) {
- *ptr = '\0';
- }
- 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';
- _alpm_log(PM_LOG_DEBUG, _("config: new section '%s'"), section);
- if(!strlen(section)) {
- RET_ERR(PM_ERR_CONF_BAD_SECTION, -1);
- }
- if(!strcmp(section, "local")) {
- RET_ERR(PM_ERR_CONF_LOCAL, -1);
- }
- if(strcmp(section, "options")) {
- db = _alpm_db_register(section, callback);
- if(db == NULL) {
- /* pm_errno is set by alpm_db_register */
- return(-1);
- }
- }
- } else {
- /* directive */
- ptr = line;
- key = strsep(&ptr, "=");
- if(key == NULL) {
- RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
- }
- _alpm_strtrim(key);
- strncpy(origkey, key, min(255, strlen(key)));
- key = _alpm_strtoupper(key);
- if(!strlen(section) && strcmp(key, "INCLUDE")) {
- RET_ERR(PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION, -1);
- }
- if(ptr == NULL) {
- if(strcmp(origkey, "NoPassiveFTP") == 0 || strcmp(key, "NOPASSIVEFTP") == 0) {
- alpm_option_set_nopassiveftp(1);
- _alpm_log(PM_LOG_DEBUG, _("config: nopassiveftp"));
- } else if(strcmp(origkey, "UseSyslog") == 0 || strcmp(key, "USESYSLOG") == 0) {
- alpm_option_set_usesyslog(1);
- _alpm_log(PM_LOG_DEBUG, _("config: usesyslog"));
- } else if(strcmp(origkey, "ILoveCandy") == 0 || strcmp(key, "ILOVECANDY") == 0) {
- alpm_option_set_chomp(1);
- _alpm_log(PM_LOG_DEBUG, _("config: chomp"));
- } else if(strcmp(origkey, "UseColor") == 0 || strcmp(key, "USECOLOR") == 0) {
- alpm_option_set_usecolor(1);
- _alpm_log(PM_LOG_DEBUG, _("config: usecolor"));
- } else if(strcmp(origkey, "ShowSize") == 0 || strcmp(key, "SHOWSIZE") == 0) {
- alpm_option_set_showsize(1);
- _alpm_log(PM_LOG_DEBUG, _("config: showsize"));
- } else {
- RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
- }
- } else {
- _alpm_strtrim(ptr);
- if(strcmp(origkey, "Include") == 0 || strcmp(key, "INCLUDE") == 0) {
- char conf[PATH_MAX];
- strncpy(conf, ptr, PATH_MAX);
- _alpm_log(PM_LOG_DEBUG, _("config: including %s"), conf);
- alpm_parse_config(conf, callback, section);
- } else if(strcmp(section, "options") == 0) {
- if(strcmp(origkey, "NoUpgrade") == 0 || strcmp(key, "NOUPGRADE") == 0) {
- char *p = ptr;
- char *q;
-
- while((q = strchr(p, ' '))) {
- *q = '\0';
- alpm_option_add_noupgrade(p);
- _alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
- p = q;
- p++;
- }
- alpm_option_add_noupgrade(p);
- _alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p);
- } else if(strcmp(origkey, "NoExtract") == 0 || strcmp(key, "NOEXTRACT") == 0) {
- char *p = ptr;
- char *q;
-
- while((q = strchr(p, ' '))) {
- *q = '\0';
- alpm_option_add_noextract(p);
- _alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
- p = q;
- p++;
- }
- alpm_option_add_noextract(p);
- _alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p);
- } else if(strcmp(origkey, "IgnorePkg") == 0 || strcmp(key, "IGNOREPKG") == 0) {
- char *p = ptr;
- char *q;
-
- while((q = strchr(p, ' '))) {
- *q = '\0';
- alpm_option_add_ignorepkg(p);
- _alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
- p = q;
- p++;
- }
- alpm_option_add_ignorepkg(p);
- _alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p);
- } else if(strcmp(origkey, "HoldPkg") == 0 || strcmp(key, "HOLDPKG") == 0) {
- char *p = ptr;
- char *q;
-
- while((q = strchr(p, ' '))) {
- *q = '\0';
- alpm_option_add_holdpkg(p);
- _alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
- p = q;
- p++;
- }
- alpm_option_add_holdpkg(p);
- _alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p);
- } else if(strcmp(origkey, "DBPath") == 0 || strcmp(key, "DBPATH") == 0) {
- alpm_option_set_dbpath(ptr);
- _alpm_log(PM_LOG_DEBUG, _("config: dbpath: %s"), ptr);
- } else if(strcmp(origkey, "CacheDir") == 0 || strcmp(key, "CACHEDIR") == 0) {
- alpm_option_set_cachedir(ptr);
- _alpm_log(PM_LOG_DEBUG, _("config: cachedir: %s"), ptr);
- } else if(strcmp(origkey, "RootDir") == 0 || strcmp(key, "ROOTDIR") == 0) {
- alpm_option_set_root(ptr);
- _alpm_log(PM_LOG_DEBUG, _("config: rootdir: %s"), ptr);
- } else if (strcmp(origkey, "LogFile") == 0 || strcmp(key, "LOGFILE") == 0) {
- alpm_option_set_logfile(ptr);
- _alpm_log(PM_LOG_DEBUG, _("config: logfile: %s"), ptr);
- } else if (strcmp(origkey, "LockFile") == 0 || strcmp(key, "LOCKFILE") == 0) {
- alpm_option_set_lockfile(ptr);
- _alpm_log(PM_LOG_DEBUG, _("config: lockfile: %s"), ptr);
- } else if (strcmp(origkey, "XferCommand") == 0 || strcmp(key, "XFERCOMMAND") == 0) {
- alpm_option_set_xfercommand(ptr);
- _alpm_log(PM_LOG_DEBUG, _("config: xfercommand: %s"), ptr);
- } else if (strcmp(origkey, "UpgradeDelay") == 0 || strcmp(key, "UPGRADEDELAY") == 0) {
- /* The config value is in days, we use seconds */
- time_t ud = atol(ptr) * 60 * 60 *24;
- alpm_option_set_upgradedelay(ud);
- _alpm_log(PM_LOG_DEBUG, _("config: upgradedelay: %d"), ud);
- } else {
- RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
- }
- } else {
- if(strcmp(origkey, "Server") == 0 || strcmp(key, "SERVER") == 0) {
- /* let's attempt a replacement for the current repo */
- char *server = _alpm_strreplace(ptr, "$repo", section);
-
- if(alpm_db_setserver(db, server) != 0) {
- /* pm_errno is set by alpm_db_setserver */
- return(-1);
- }
-
- free(server);
- } else {
- RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1);
- }
- }
- line[0] = '\0';
- }
- }
- }
- fclose(fp);
-
- return(0);
-}
-
/** @} */
/* This function is mostly the same as sync.c find_replacements and sysupgrade