diff options
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/alpm.c | 206 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 21 | ||||
-rw-r--r-- | lib/libalpm/db.c | 17 | ||||
-rw-r--r-- | lib/libalpm/db.h | 2 | ||||
-rw-r--r-- | lib/libalpm/error.c | 9 | ||||
-rw-r--r-- | lib/libalpm/handle.c | 57 | ||||
-rw-r--r-- | lib/libalpm/handle.h | 11 |
7 files changed, 36 insertions, 287 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 1944ddce..135ac373 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -100,210 +100,4 @@ int SYMEXPORT alpm_release() * @brief Various libalpm functions */ -/** 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) - * @addtogroup alpm_misc - */ -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); -} - /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 66711c1f..7d374b47 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -137,19 +137,10 @@ void alpm_option_set_xfercommand(const char *cmd); unsigned short alpm_option_get_nopassiveftp(); void alpm_option_set_nopassiveftp(unsigned short nopasv); -unsigned short alpm_option_get_chomp(); -void alpm_option_set_chomp(unsigned short chomp); - alpm_list_t *alpm_option_get_needles(); void alpm_option_add_needle(char *needle); void alpm_option_set_needles(alpm_list_t *needles); -unsigned short alpm_option_get_usecolor(); -void alpm_option_set_usecolor(unsigned short usecolor); - -unsigned short alpm_option_get_showsize(); -void alpm_option_set_showsize(unsigned short showsize); - pmdb_t *alpm_option_get_localdb(); alpm_list_t *alpm_option_get_syncdbs(); @@ -157,10 +148,7 @@ alpm_list_t *alpm_option_get_syncdbs(); * Databases */ -/* Database registration callback */ -typedef void (*alpm_cb_db_register)(const char *, pmdb_t *); - -pmdb_t *alpm_db_register(char *treename); +pmdb_t *alpm_db_register(const char *treename); int alpm_db_unregister(pmdb_t *db); const char *alpm_db_get_name(pmdb_t *db); @@ -205,8 +193,6 @@ int alpm_pkg_free(pmpkg_t *pkg); int alpm_pkg_checkmd5sum(pmpkg_t *pkg); int alpm_pkg_checksha1sum(pmpkg_t *pkg); char *alpm_fetch_pkgurl(char *url); -int alpm_parse_config(char *file, alpm_cb_db_register callback, - const char *this_section); int alpm_pkg_vercmp(const char *ver1, const char *ver2); char *alpm_pkg_name_hasarch(char *pkgname); @@ -465,11 +451,6 @@ enum _pmerrno_t { PM_ERR_DB_SYNC, PM_ERR_RETRIEVE, PM_ERR_PKG_HOLD, - /* Configuration file */ - PM_ERR_CONF_BAD_SECTION, - PM_ERR_CONF_LOCAL, - PM_ERR_CONF_BAD_SYNTAX, - PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION, PM_ERR_INVALID_REGEX, /* Downloading */ PM_ERR_CONNECT_FAILED, diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index a3226335..e6c784cc 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -64,7 +64,7 @@ * @param treename the name of the repository * @return a pmdb_t* on success (the value), NULL on error */ -pmdb_t SYMEXPORT *alpm_db_register(char *treename) +pmdb_t SYMEXPORT *alpm_db_register(const char *treename) { ALPM_LOG_FUNC; @@ -74,14 +74,14 @@ 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 * @param db pointer to the package database to unregister * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -int alpm_db_unregister(pmdb_t *db) +int SYMEXPORT alpm_db_unregister(pmdb_t *db) { int found = 0; @@ -126,7 +126,7 @@ int alpm_db_unregister(pmdb_t *db) * @param url url of the server * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -int alpm_db_setserver(pmdb_t *db, const char *url) +int SYMEXPORT alpm_db_setserver(pmdb_t *db, const char *url) { int found = 0; @@ -597,7 +597,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles) return(ret); } -pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback) +pmdb_t *_alpm_db_register(const char *treename) { struct stat buf; pmdb_t *db; @@ -626,6 +626,10 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback) /* make sure the database directory exists */ dbpath = alpm_option_get_dbpath(); + if(!dbpath) { + _alpm_log(PM_LOG_WARNING, _("database path is undefined")); + RET_ERR(PM_ERR_DB_OPEN, NULL); + } snprintf(path, PATH_MAX, "%s%s", dbpath, treename); if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) { _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"), @@ -646,9 +650,6 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback) RET_ERR(PM_ERR_DB_OPEN, NULL); } - /* Only call callback on NEW registration. */ - if(callback) callback(treename, db); - if(strcmp(treename, "local") == 0) { handle->db_local = db; } else { diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index 1cc90309..d8d6f2be 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -52,7 +52,7 @@ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename); void _alpm_db_free(pmdb_t *db); int _alpm_db_cmp(const void *db1, const void *db2); alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles); -pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback); +pmdb_t *_alpm_db_register(const char *treename); /* be.c, backend specific calls */ int _alpm_db_install(pmdb_t *db, const char *dbfile); diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c index aa930b9e..0775567c 100644 --- a/lib/libalpm/error.c +++ b/lib/libalpm/error.c @@ -138,15 +138,6 @@ char SYMEXPORT *alpm_strerror(int err) case PM_ERR_PKG_HOLD: /* TODO wow this is not descriptive at all... what does this mean? */ return _("not confirmed"); - /* Configuration file */ - case PM_ERR_CONF_BAD_SECTION: - return _("bad configuration section name"); - case PM_ERR_CONF_LOCAL: - return _("'local' is reserved and cannot be used as a repository name"); - case PM_ERR_CONF_BAD_SYNTAX: - return _("syntax error in config file"); - case PM_ERR_CONF_DIRECTIVE_OUTSIDE_SECTION: - return _("all directives must belong to a section"); case PM_ERR_INVALID_REGEX: return _("invalid regular expression"); /* Downloading */ diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index d2e3dd0d..45f4e8af 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -122,25 +122,22 @@ void _alpm_handle_free(pmhandle_t *handle) FREE(handle); } -alpm_cb_log alpm_option_get_logcb() { return (handle ? handle->logcb : NULL); } -alpm_cb_download alpm_option_get_dlcb() { return (handle ? handle->dlcb : NULL); } +alpm_cb_log SYMEXPORT alpm_option_get_logcb() { return (handle ? handle->logcb : NULL); } +alpm_cb_download SYMEXPORT alpm_option_get_dlcb() { return (handle ? handle->dlcb : NULL); } unsigned short SYMEXPORT alpm_option_get_logmask() { return handle->logmask; } const char SYMEXPORT *alpm_option_get_root() { return handle->root; } const char SYMEXPORT *alpm_option_get_dbpath() { return handle->dbpath; } const char SYMEXPORT *alpm_option_get_cachedir() { return handle->cachedir; } const char SYMEXPORT *alpm_option_get_logfile() { return handle->logfile; } const char SYMEXPORT *alpm_option_get_lockfile() { return handle->lockfile; } -unsigned short alpm_option_get_usesyslog() { return handle->usesyslog; } -alpm_list_t *alpm_option_get_noupgrades() { return handle->noupgrade; } -alpm_list_t *alpm_option_get_noextracts() { return handle->noextract; } -alpm_list_t *alpm_option_get_ignorepkgs() { return handle->ignorepkg; } -alpm_list_t *alpm_option_get_holdpkgs() { return handle->holdpkg; } -time_t alpm_option_get_upgradedelay() { return handle->upgradedelay; } -const char *alpm_option_get_xfercommand() { return handle->xfercommand; } -unsigned short alpm_option_get_nopassiveftp() { return handle->nopassiveftp; } -unsigned short SYMEXPORT alpm_option_get_chomp() { return handle->chomp; } -unsigned short alpm_option_get_usecolor() { return handle->use_color; } -unsigned short SYMEXPORT alpm_option_get_showsize() { return handle->showsize; } +unsigned short SYMEXPORT alpm_option_get_usesyslog() { return handle->usesyslog; } +alpm_list_t SYMEXPORT *alpm_option_get_noupgrades() { return handle->noupgrade; } +alpm_list_t SYMEXPORT *alpm_option_get_noextracts() { return handle->noextract; } +alpm_list_t SYMEXPORT *alpm_option_get_ignorepkgs() { return handle->ignorepkg; } +alpm_list_t SYMEXPORT *alpm_option_get_holdpkgs() { return handle->holdpkg; } +time_t SYMEXPORT alpm_option_get_upgradedelay() { return handle->upgradedelay; } +const char SYMEXPORT *alpm_option_get_xfercommand() { return handle->xfercommand; } +unsigned short SYMEXPORT alpm_option_get_nopassiveftp() { return handle->nopassiveftp; } pmdb_t SYMEXPORT *alpm_option_get_localdb() { return handle->db_local; } alpm_list_t SYMEXPORT *alpm_option_get_syncdbs() @@ -215,7 +212,7 @@ void SYMEXPORT alpm_option_set_cachedir(const char *cachedir) } } -void alpm_option_set_logfile(const char *logfile) +void SYMEXPORT alpm_option_set_logfile(const char *logfile) { ALPM_LOG_FUNC; @@ -240,27 +237,27 @@ void SYMEXPORT alpm_option_set_lockfile(const char *lockfile) } } -void alpm_option_set_usesyslog(unsigned short usesyslog) +void SYMEXPORT alpm_option_set_usesyslog(unsigned short usesyslog) { handle->usesyslog = usesyslog; } -void alpm_option_add_noupgrade(char *pkg) +void SYMEXPORT alpm_option_add_noupgrade(char *pkg) { handle->noupgrade = alpm_list_add(handle->noupgrade, strdup(pkg)); } -void alpm_option_set_noupgrades(alpm_list_t *noupgrade) +void SYMEXPORT alpm_option_set_noupgrades(alpm_list_t *noupgrade) { if(handle->noupgrade) FREELIST(handle->noupgrade); if(noupgrade) handle->noupgrade = noupgrade; } -void alpm_option_add_noextract(char *pkg) +void SYMEXPORT alpm_option_add_noextract(char *pkg) { handle->noextract = alpm_list_add(handle->noextract, strdup(pkg)); } -void alpm_option_set_noextracts(alpm_list_t *noextract) +void SYMEXPORT alpm_option_set_noextracts(alpm_list_t *noextract) { if(handle->noextract) FREELIST(handle->noextract); if(noextract) handle->noextract = noextract; @@ -276,42 +273,30 @@ void alpm_option_set_ignorepkgs(alpm_list_t *ignorepkgs) if(ignorepkgs) handle->ignorepkg = ignorepkgs; } -void alpm_option_add_holdpkg(char *pkg) +void SYMEXPORT alpm_option_add_holdpkg(char *pkg) { handle->holdpkg = alpm_list_add(handle->holdpkg, strdup(pkg)); } -void alpm_option_set_holdpkgs(alpm_list_t *holdpkgs) +void SYMEXPORT alpm_option_set_holdpkgs(alpm_list_t *holdpkgs) { if(handle->holdpkg) FREELIST(handle->holdpkg); if(holdpkgs) handle->holdpkg = holdpkgs; } -void alpm_option_set_upgradedelay(time_t delay) +void SYMEXPORT alpm_option_set_upgradedelay(time_t delay) { handle->upgradedelay = delay; } -void alpm_option_set_xfercommand(const char *cmd) +void SYMEXPORT alpm_option_set_xfercommand(const char *cmd) { if(handle->xfercommand) FREE(handle->xfercommand); if(cmd) handle->xfercommand = strdup(cmd); } -void alpm_option_set_nopassiveftp(unsigned short nopasv) +void SYMEXPORT alpm_option_set_nopassiveftp(unsigned short nopasv) { handle->nopassiveftp = nopasv; } -void alpm_option_set_chomp(unsigned short chomp) { handle->chomp = chomp; } - -void alpm_option_set_usecolor(unsigned short usecolor) -{ - handle->use_color = usecolor; -} - -void alpm_option_set_showsize(unsigned short showsize) -{ - handle->showsize = showsize; -} - /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 4e4166f9..adf2bb49 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -48,26 +48,23 @@ typedef struct _pmhandle_t { /* options */ alpm_cb_log logcb; /* Log callback function */ alpm_cb_download dlcb; /* Download callback function */ - unsigned short logmask; /* Output mask for logging functions */ + unsigned short logmask; /* Output mask for logging functions */ /* TODO move to frontend */ char *root; /* Root path, default '/' */ char *dbpath; /* Base path to pacman's DBs */ char *cachedir; /* Base path to pacman's cache */ char *logfile; /* Name of the file to log to */ /*TODO is this used?*/ char *lockfile; /* Name of the lock file */ - unsigned short usesyslog; /* Use syslog instead of logfile? */ + unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */ alpm_list_t *noupgrade; /* List of packages NOT to be upgraded */ - alpm_list_t *noextract; /* List of packages NOT to extrace */ /*TODO is this used?*/ + alpm_list_t *noextract; /* List of packages NOT to extract */ /*TODO is this used?*/ alpm_list_t *ignorepkg; /* List of packages to ignore */ alpm_list_t *holdpkg; /* List of packages which 'hold' pacman */ - time_t upgradedelay; /* Amount of time to wait before upgrading a package*/ + time_t upgradedelay; /* Amount of time to wait before upgrading a package */ /* servers */ char *xfercommand; /* External download command */ unsigned short nopassiveftp; /* Don't use PASV ftp connections */ - unsigned short chomp; /* I Love Candy! */ - unsigned short use_color; /* enable colorful output */ - unsigned short showsize; /* Show individual package sizes */ } pmhandle_t; extern pmhandle_t *handle; |