diff options
author | Aaron Griffin <aaron@archlinux.org> | 2006-11-20 09:10:23 +0000 |
---|---|---|
committer | Aaron Griffin <aaron@archlinux.org> | 2006-11-20 09:10:23 +0000 |
commit | aa1c0ba9f8787fc3b1a1190103e394b0c1c95922 (patch) | |
tree | ed0c9675f7fc5da043a69b36e0b8c6c8e05cb583 /lib | |
parent | b8b9596b13de957566211b0e1db3e473ed66e147 (diff) |
* repo-add script - to add entries to a db file directly from package data (no PKGBUILD)
* libalpm api changes - move from a _getinfo(p, WHAT_WE_WANT) scheme to a
typesafe _get_what_we_want(p) scheme [not 100% complete yet]
* some const correctness changes
* removal of PM_* types in alpm.h in favor of the pm*_t types used throughout
libalpm
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/add.h | 2 | ||||
-rw-r--r-- | lib/libalpm/alpm.c | 340 | ||||
-rw-r--r-- | lib/libalpm/alpm.h | 268 | ||||
-rw-r--r-- | lib/libalpm/be_files.c | 6 | ||||
-rw-r--r-- | lib/libalpm/cache.h | 4 | ||||
-rw-r--r-- | lib/libalpm/conflict.c | 2 | ||||
-rw-r--r-- | lib/libalpm/conflict.h | 5 | ||||
-rw-r--r-- | lib/libalpm/db.c | 25 | ||||
-rw-r--r-- | lib/libalpm/db.h | 23 | ||||
-rw-r--r-- | lib/libalpm/deps.h | 11 | ||||
-rw-r--r-- | lib/libalpm/group.c | 16 | ||||
-rw-r--r-- | lib/libalpm/group.h | 11 | ||||
-rw-r--r-- | lib/libalpm/handle.c | 346 | ||||
-rw-r--r-- | lib/libalpm/handle.h | 51 | ||||
-rw-r--r-- | lib/libalpm/list.c | 4 | ||||
-rw-r--r-- | lib/libalpm/list.h | 8 | ||||
-rw-r--r-- | lib/libalpm/log.c | 11 | ||||
-rw-r--r-- | lib/libalpm/log.h | 7 | ||||
-rw-r--r-- | lib/libalpm/package.c | 304 | ||||
-rw-r--r-- | lib/libalpm/package.h | 18 | ||||
-rw-r--r-- | lib/libalpm/provide.h | 5 | ||||
-rw-r--r-- | lib/libalpm/remove.h | 2 | ||||
-rw-r--r-- | lib/libalpm/server.c | 10 | ||||
-rw-r--r-- | lib/libalpm/server.h | 20 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 33 | ||||
-rw-r--r-- | lib/libalpm/sync.h | 9 | ||||
-rw-r--r-- | lib/libalpm/trans.h | 25 | ||||
-rw-r--r-- | lib/libalpm/util.c | 1 |
28 files changed, 780 insertions, 787 deletions
diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h index 9b77a2ca..d39aa140 100644 --- a/lib/libalpm/add.h +++ b/lib/libalpm/add.h @@ -21,8 +21,8 @@ #ifndef _ALPM_ADD_H #define _ALPM_ADD_H -#include "list.h" #include "db.h" +#include "list.h" #include "trans.h" int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name); diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index b642501b..49cfd0cd 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -65,7 +65,7 @@ pmhandle_t *handle = NULL; enum __pmerrno_t pm_errno; -/** @defgroup alpm_interface Interface Functions +/** \addtogroup alpm_interface Interface Functions * @brief Function to initialize and release libalpm * @{ */ @@ -75,7 +75,7 @@ enum __pmerrno_t pm_errno; * @param root the full path of the root we'll be installing to (usually /) * @return 0 on success, -1 on error (pm_errno is set accordingly) */ -int alpm_initialize(char *root) +int alpm_initialize(const char *root) { char str[PATH_MAX]; @@ -129,40 +129,12 @@ int alpm_release() } /** @} */ -/** @defgroup alpm_options Library Options +/** \addtogroup alpm_options Library Options * @brief Functions to set and get libalpm options * @{ */ -/** Set a library option. - * @param parm the name of the parameter - * @param data the value of the parameter - * @return 0 on success, -1 on error (pm_errno is set accordingly) - */ -int alpm_set_option(unsigned char parm, unsigned long data) -{ - /* Sanity checks */ - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); - - return(_alpm_handle_set_option(handle, parm, data)); -} - -/** Get the value of a library option. - * @param parm the parameter to get - * @param data pointer argument to get the value in - * @return 0 on success, -1 on error (pm_errno is set accordingly) - */ -int alpm_get_option(unsigned char parm, long *data) -{ - /* Sanity checks */ - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); - ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); - - return(_alpm_handle_get_option(handle, parm, data)); -} -/** @} */ - -/** @defgroup alpm_databases Database Functions +/** \addtogroup alpm_databases Database Functions * @brief Frunctions to query and manipulate the database of libalpm * @{ */ @@ -224,36 +196,6 @@ int alpm_db_unregister(pmdb_t *db) return(0); } -/** Get informations about a database. - * @param db database pointer - * @param parm name of the info to get - * @return a void* on success (the value), NULL on error - */ -void *alpm_db_getinfo(PM_DB *db, unsigned char parm) -{ - void *data = NULL; - char path[PATH_MAX]; - pmserver_t *server; - - /* Sanity checks */ - ASSERT(handle != NULL, return(NULL)); - ASSERT(db != NULL, return(NULL)); - - switch(parm) { - case PM_DB_TREENAME: data = db->treename; break; - case PM_DB_FIRSTSERVER: - server = (pmserver_t*)db->servers->data; - snprintf(path, PATH_MAX, "%s://%s%s", server->s_url->scheme, - server->s_url->host, server->s_url->doc); - data = strdup(path); - break; - default: - data = NULL; - } - - return(data); -} - /** Set the serverlist of a database. * @param db database pointer * @param url url of the server @@ -307,7 +249,7 @@ int alpm_db_setserver(pmdb_t *db, const char *url) * @return 0 on success, > 0 on error (pm_errno is set accordingly), < 0 if up * to date */ -int alpm_db_update(int force, PM_DB *db) +int alpm_db_update(int force, pmdb_t *db) { pmlist_t *lp; char path[PATH_MAX]; @@ -455,112 +397,11 @@ pmlist_t *alpm_db_getgrpcache(pmdb_t *db) /** @} */ -/** @defgroup alpm_packages Package Functions +/** \addtogroup alpm_packages Package Functions * @brief Functions to manipulate libalpm packages * @{ */ -/** Get informations about a package. - * @param pkg package pointer - * @param parm name of the info to get - * @return a void* on success (the value), NULL on error - */ -void *alpm_pkg_getinfo(pmpkg_t *pkg, unsigned char parm) -{ - void *data = NULL; - - /* Sanity checks */ - ASSERT(handle != NULL, return(NULL)); - ASSERT(pkg != NULL, return(NULL)); - - /* Update the cache package entry if needed */ - if(pkg->origin == PKG_FROM_CACHE) { - switch(parm) { - /* Desc entry */ - /*case PM_PKG_NAME: - case PM_PKG_VERSION:*/ - case PM_PKG_DESC: - case PM_PKG_GROUPS: - case PM_PKG_URL: - case PM_PKG_LICENSE: - case PM_PKG_ARCH: - case PM_PKG_BUILDDATE: - case PM_PKG_INSTALLDATE: - case PM_PKG_PACKAGER: - case PM_PKG_SIZE: - case PM_PKG_USIZE: - case PM_PKG_REASON: - case PM_PKG_MD5SUM: - case PM_PKG_SHA1SUM: - if(!(pkg->infolevel & INFRQ_DESC)) { - _alpm_log(PM_LOG_DEBUG, _("loading DESC info for '%s'"), pkg->name); - _alpm_db_read(pkg->data, INFRQ_DESC, pkg); - } - break; - /* Depends entry */ - case PM_PKG_DEPENDS: - case PM_PKG_REQUIREDBY: - case PM_PKG_CONFLICTS: - case PM_PKG_PROVIDES: - case PM_PKG_REPLACES: - if(!(pkg->infolevel & INFRQ_DEPENDS)) { - _alpm_log(PM_LOG_DEBUG, "loading DEPENDS info for '%s'", pkg->name); - _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg); - } - break; - /* Files entry */ - case PM_PKG_FILES: - case PM_PKG_BACKUP: - if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_FILES)) { - _alpm_log(PM_LOG_DEBUG, _("loading FILES info for '%s'"), pkg->name); - _alpm_db_read(pkg->data, INFRQ_FILES, pkg); - } - break; - /* Scriptlet */ - case PM_PKG_SCRIPLET: - if(pkg->data == handle->db_local && !(pkg->infolevel & INFRQ_SCRIPLET)) { - _alpm_log(PM_LOG_DEBUG, _("loading SCRIPLET info for '%s'"), pkg->name); - _alpm_db_read(pkg->data, INFRQ_SCRIPLET, pkg); - } - break; - } - } - - switch(parm) { - case PM_PKG_NAME: data = pkg->name; break; - case PM_PKG_VERSION: data = pkg->version; break; - case PM_PKG_DESC: data = pkg->desc; break; - case PM_PKG_GROUPS: data = pkg->groups; break; - case PM_PKG_URL: data = pkg->url; break; - case PM_PKG_ARCH: data = pkg->arch; break; - case PM_PKG_BUILDDATE: data = pkg->builddate; break; - case PM_PKG_BUILDTYPE: data = pkg->buildtype; break; - case PM_PKG_INSTALLDATE: data = pkg->installdate; break; - case PM_PKG_PACKAGER: data = pkg->packager; break; - case PM_PKG_SIZE: data = (void *)(long)pkg->size; break; - case PM_PKG_USIZE: data = (void *)(long)pkg->usize; break; - case PM_PKG_REASON: data = (void *)(long)pkg->reason; break; - case PM_PKG_LICENSE: data = pkg->license; break; - case PM_PKG_REPLACES: data = pkg->replaces; break; - case PM_PKG_MD5SUM: data = pkg->md5sum; break; - case PM_PKG_SHA1SUM: data = pkg->sha1sum; break; - case PM_PKG_DEPENDS: data = pkg->depends; break; - case PM_PKG_REMOVES: data = pkg->removes; break; - case PM_PKG_REQUIREDBY: data = pkg->requiredby; break; - case PM_PKG_PROVIDES: data = pkg->provides; break; - case PM_PKG_CONFLICTS: data = pkg->conflicts; break; - case PM_PKG_FILES: data = pkg->files; break; - case PM_PKG_BACKUP: data = pkg->backup; break; - case PM_PKG_SCRIPLET: data = (void *)(long)pkg->scriptlet; break; - case PM_PKG_DATA: data = pkg->data; break; - default: - data = NULL; - break; - } - - return(data); -} - /** Create a package from a file. * @param filename location of the package tarball * @param pkg address of the package pointer @@ -746,64 +587,11 @@ char *alpm_pkg_name_hasarch(char *pkgname) /** @} */ -/** @defgroup alpm_groups Group Functions - * @brief Functions to get informations about libalpm groups - * @{ - */ - -/** Get informations about a group. - * @param grp group pointer - * @param parm name of the info to get - * @return a void* on success (the value), NULL on error - */ -void *alpm_grp_getinfo(pmgrp_t *grp, unsigned char parm) -{ - void *data = NULL; - - /* Sanity checks */ - ASSERT(grp != NULL, return(NULL)); - - switch(parm) { - case PM_GRP_NAME: data = grp->name; break; - case PM_GRP_PKGNAMES: data = grp->packages; break; - default: - data = NULL; - break; - } - - return(data); -} -/** @} */ - -/** @defgroup alpm_sync Sync Functions +/** \addtogroup alpm_sync Sync Functions * @brief Functions to get informations about libalpm syncs * @{ */ -/** Get informations about a sync. - * @param sync pointer - * @param parm name of the info to get - * @return a void* on success (the value), NULL on error - */ -void *alpm_sync_getinfo(pmsyncpkg_t *sync, unsigned char parm) -{ - void *data; - - /* Sanity checks */ - ASSERT(sync != NULL, return(NULL)); - - switch(parm) { - case PM_SYNC_TYPE: data = (void *)(long)sync->type; break; - case PM_SYNC_PKG: data = sync->pkg; break; - case PM_SYNC_DATA: data = sync->data; break; - default: - data = NULL; - break; - } - - return(data); -} - /** Searches a database * @param db pointer to the package database to search in * @return the list of packages on success, NULL on error @@ -820,7 +608,7 @@ pmlist_t *alpm_db_search(pmdb_t *db) } /** @} */ -/** @defgroup alpm_trans Transaction Functions +/** \addtogroup alpm_trans Transaction Functions * @brief Functions to manipulate libalpm transactions * @{ */ @@ -998,7 +786,7 @@ int alpm_trans_release() } /** @} */ -/** @defgroup alpm_dep Dependency Functions +/** \addtogroup alpm_dep Dependency Functions * @brief Functions to get informations about a libalpm dependency * @{ */ @@ -1030,7 +818,7 @@ void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm) } /** @} */ -/** @defgroup alpm_conflict File Conflicts Functions +/** \addtogroup alpm_conflict File Conflicts Functions * @brief Functions to get informations about a libalpm file conflict * @{ */ @@ -1061,7 +849,7 @@ void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm) } /** @} */ -/** @defgroup alpm_log Logging Functions +/** \addtogroup alpm_log Logging Functions * @brief Functions to log using libalpm * @{ */ @@ -1099,7 +887,7 @@ int alpm_logaction(char *fmt, ...) } /** @} */ -/** @defgroup alpm_list List Functions +/** \addtogroup alpm_list List Functions * @brief Functions to manipulate libalpm linked lists * @{ */ @@ -1128,7 +916,7 @@ pmlist_t *alpm_list_next(pmlist_t *entry) * @param entry the list entry * @return the data on success, NULL on error */ -void *alpm_list_getdata(pmlist_t *entry) +void *alpm_list_getdata(const pmlist_t *entry) { ASSERT(entry != NULL, return(NULL)); @@ -1165,7 +953,7 @@ int alpm_list_free_outer(pmlist_t *entry) * @param list the list to count * @return number of entries on success, NULL on error */ -int alpm_list_count(pmlist_t *list) +int alpm_list_count(const pmlist_t *list) { ASSERT(list != NULL, return(-1)); @@ -1173,7 +961,7 @@ int alpm_list_count(pmlist_t *list) } /** @} */ -/** @defgroup alpm_misc Miscellaneous Functions +/** \addtogroup alpm_misc Miscellaneous Functions * @brief Various libalpm functions * @{ */ @@ -1225,7 +1013,7 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this char *key = NULL; int linenum = 0; char section[256] = ""; - PM_DB *db = NULL; + pmdb_t *db = NULL; fp = fopen(file, "r"); if(fp == NULL) { @@ -1282,12 +1070,17 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this } if(ptr == NULL) { if(!strcmp(key, "NOPASSIVEFTP")) { - alpm_set_option(PM_OPT_NOPASSIVEFTP, (long)1); + alpm_option_set_nopassiveftp(1); + _alpm_log(PM_LOG_DEBUG, _("config: nopassiveftp")); } else if(!strcmp(key, "USESYSLOG")) { - alpm_set_option(PM_OPT_USESYSLOG, (long)1); + alpm_option_set_usesyslog(1); _alpm_log(PM_LOG_DEBUG, _("config: usesyslog")); } else if(!strcmp(key, "ILOVECANDY")) { - alpm_set_option(PM_OPT_CHOMP, (long)1); + alpm_option_set_chomp(1); + _alpm_log(PM_LOG_DEBUG, _("config: chomp")); + } else if(!strcmp(key, "USECOLOR")) { + alpm_option_set_usecolor(1); + _alpm_log(PM_LOG_DEBUG, _("config: usecolor")); } else { RET_ERR(PM_ERR_CONF_BAD_SYNTAX, -1); } @@ -1302,123 +1095,80 @@ int alpm_parse_config(char *file, alpm_cb_db_register callback, const char *this 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) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_noupgrade(p); _alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), p); p = q; p++; } - if(alpm_set_option(PM_OPT_NOUPGRADE, (long)p) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_noupgrade(p); _alpm_log(PM_LOG_DEBUG, _("config: noupgrade: %s"), 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) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_noextract(p); _alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), p); p = q; p++; } - if(alpm_set_option(PM_OPT_NOEXTRACT, (long)p) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_noextract(p); _alpm_log(PM_LOG_DEBUG, _("config: noextract: %s"), 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) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_ignorepkg(p); _alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p); p = q; p++; } - if(alpm_set_option(PM_OPT_IGNOREPKG, (long)p) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_ignorepkg(p); _alpm_log(PM_LOG_DEBUG, _("config: ignorepkg: %s"), p); } else if(!strcmp(key, "HOLDPKG")) { char *p = ptr; char *q; + while((q = strchr(p, ' '))) { *q = '\0'; - if(alpm_set_option(PM_OPT_HOLDPKG, (long)p) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_holdpkg(p); _alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p); p = q; p++; } - if(alpm_set_option(PM_OPT_HOLDPKG, (long)p) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_add_holdpkg(p); _alpm_log(PM_LOG_DEBUG, _("config: holdpkg: %s"), p); } else if(!strcmp(key, "DBPATH")) { /* shave off the leading slash, if there is one */ if(*ptr == '/') { ptr++; } - if(alpm_set_option(PM_OPT_DBPATH, (long)ptr) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_set_dbpath(ptr); _alpm_log(PM_LOG_DEBUG, _("config: dbpath: %s"), ptr); } else if(!strcmp(key, "CACHEDIR")) { /* shave off the leading slash, if there is one */ if(*ptr == '/') { ptr++; } - if(alpm_set_option(PM_OPT_CACHEDIR, (long)ptr) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_set_cachedir(ptr); _alpm_log(PM_LOG_DEBUG, _("config: cachedir: %s"), ptr); } else if (!strcmp(key, "LOGFILE")) { - if(alpm_set_option(PM_OPT_LOGFILE, (long)ptr) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } - _alpm_log(PM_LOG_DEBUG, _("config: log file: %s"), ptr); + alpm_option_set_logfile(ptr); + _alpm_log(PM_LOG_DEBUG, _("config: logfile: %s"), ptr); } else if (!strcmp(key, "XFERCOMMAND")) { - if(alpm_set_option(PM_OPT_XFERCOMMAND, (long)ptr) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + alpm_option_set_xfercommand(ptr); + _alpm_log(PM_LOG_DEBUG, _("config: xfercommand: %s"), ptr); } else if (!strcmp(key, "UPGRADEDELAY")) { /* The config value is in days, we use seconds */ - _alpm_log(PM_LOG_DEBUG, _("config: UpgradeDelay: %i"), (60*60*24) * atol(ptr)); - if(alpm_set_option(PM_OPT_UPGRADEDELAY, (60*60*24) * atol(ptr)) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } - } else if (!strcmp(key, "PROXYSERVER")) { - if(alpm_set_option(PM_OPT_PROXYHOST, (long)ptr) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } - } else if (!strcmp(key, "PROXYPORT")) { - if(alpm_set_option(PM_OPT_PROXYPORT, (long)atoi(ptr)) == -1) { - /* pm_errno is set by alpm_set_option */ - return(-1); - } + long 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); } diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 394001ce..3b5126b1 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -28,6 +28,8 @@ extern "C" { #endif +#include <time.h> /* for time_t */ + /* * Arch Linux Package Management library */ @@ -42,23 +44,25 @@ extern "C" { #define PM_EXT_DB ".db.tar.gz" /* - * Structures (opaque) + * Structures */ -typedef struct __pmlist_t PM_LIST; -typedef struct __pmdb_t PM_DB; -typedef struct __pmpkg_t PM_PKG; -typedef struct __pmgrp_t PM_GRP; -typedef struct __pmsyncpkg_t PM_SYNCPKG; -typedef struct __pmtrans_t PM_TRANS; -typedef struct __pmdepmissing_t PM_DEPMISS; -typedef struct __pmconflict_t PM_CONFLICT; +typedef struct __pmlist_t pmlist_t; +typedef struct __pmdb_t pmdb_t; +typedef struct __pmpkg_t pmpkg_t; +typedef struct __pmgrp_t pmgrp_t; +typedef struct __pmserver_t pmserver_t; +typedef struct __pmtrans_t pmtrans_t; +typedef struct __pmsyncpkg_t pmsyncpkg_t; +typedef struct __pmdepend_t pmdepend_t; +typedef struct __pmdepmissing_t pmdepmissing_t; +typedef struct __pmconflict_t pmconflict_t; /* * Library */ -int alpm_initialize(char *root); +int alpm_initialize(const char *root); int alpm_release(void); /* @@ -74,120 +78,110 @@ int alpm_release(void); #define PM_LOG_FUNCTION 0x20 #define PM_LOG_DOWNLOAD 0x40 +typedef void (*alpm_cb_log)(unsigned short, char *); int alpm_logaction(char *fmt, ...); /* + * Downloading + */ + +typedef void (*alpm_cb_download)(const char *filename, int xfered, int total); + +/* * Options */ #define PM_DLFNM_LEN 22 -/* Parameters */ -enum { - PM_OPT_LOGCB = 1, - PM_OPT_LOGMASK, - PM_OPT_USESYSLOG, - PM_OPT_ROOT, - PM_OPT_DBPATH, - PM_OPT_CACHEDIR, - PM_OPT_LOGFILE, - PM_OPT_LOCALDB, - PM_OPT_SYNCDB, - PM_OPT_NOUPGRADE, - PM_OPT_NOEXTRACT, - PM_OPT_IGNOREPKG, - PM_OPT_UPGRADEDELAY, - /* Download */ - PM_OPT_PROXYHOST, - PM_OPT_PROXYPORT, - PM_OPT_XFERCOMMAND, - PM_OPT_NOPASSIVEFTP, - PM_OPT_DLCB, - PM_OPT_DLFNM, - PM_OPT_DLOFFSET, - PM_OPT_DLT0, - PM_OPT_DLT, - PM_OPT_DLRATE, - PM_OPT_DLXFERED1, - PM_OPT_DLETA_H, - PM_OPT_DLETA_M, - PM_OPT_DLETA_S, - /* End of download */ - PM_OPT_HOLDPKG, - PM_OPT_CHOMP, - PM_OPT_NEEDLES -}; +alpm_cb_log alpm_option_get_logcb(); +void alpm_option_set_logcb(alpm_cb_log cb); + +alpm_cb_download alpm_option_get_dlcb(); +void alpm_option_set_dlcb(alpm_cb_download cb); + +unsigned char alpm_option_get_logmask(); +void alpm_option_set_logmask(unsigned char mask); + +const char *alpm_option_get_root(); +void alpm_option_set_root(const char *root); + +const char *alpm_option_get_dbpath(); +void alpm_option_set_dbpath(const char *dbpath); + +const char *alpm_option_get_cachedir(); +void alpm_option_set_cachedir(const char *cachedir); + +const char *alpm_option_get_logfile(); +void alpm_option_set_logfile(const char *logfile); + +unsigned char alpm_option_get_usesyslog(); +void alpm_option_set_usesyslog(unsigned char usesyslog); + +pmlist_t *alpm_option_get_noupgrades(); +void alpm_option_add_noupgrade(char *pkg); +void alpm_option_set_noupgrades(pmlist_t *noupgrade); + +pmlist_t *alpm_option_get_noextracts(); +void alpm_option_add_noextract(char *pkg); +void alpm_option_set_noextracts(pmlist_t *noextract); + +pmlist_t *alpm_option_get_ignorepkgs(); +void alpm_option_add_ignorepkg(char *pkg); +void alpm_option_set_ignorepkgs(pmlist_t *ignorepkgs); + +pmlist_t *alpm_option_get_holdpkgs(); +void alpm_option_add_holdpkg(char *pkg); +void alpm_option_set_holdpkgs(pmlist_t *holdpkgs); + +time_t alpm_option_get_upgradedelay(); +void alpm_option_set_upgradedelay(time_t delay); + +const char *alpm_option_get_xfercommand(); +void alpm_option_set_xfercommand(const char *cmd); + +unsigned short alpm_option_get_nopassiveftp(); +void alpm_option_set_nopassiveftp(unsigned short nopasv); -int alpm_set_option(unsigned char parm, unsigned long data); -int alpm_get_option(unsigned char parm, long *data); +unsigned short alpm_option_get_chomp(); +void alpm_option_set_chomp(unsigned short chomp); + +pmlist_t *alpm_option_get_needles(); +void alpm_option_add_needle(char *needle); +void alpm_option_set_needles(pmlist_t *needles); + +unsigned short alpm_option_get_usecolor(); +void alpm_option_set_usecolor(unsigned short usecolor); /* * Databases */ -/* Info parameters */ -enum { - PM_DB_TREENAME = 1, - PM_DB_FIRSTSERVER -}; - /* Database registration callback */ -typedef void (*alpm_cb_db_register)(char *, PM_DB *); +typedef void (*alpm_cb_db_register)(char *, pmdb_t *); + +pmdb_t *alpm_db_register(char *treename); +int alpm_db_unregister(pmdb_t *db); -PM_DB *alpm_db_register(char *treename); -int alpm_db_unregister(PM_DB *db); +const char *alpm_db_get_name(pmdb_t *db); +const char *alpm_db_get_url(pmdb_t *db); -void *alpm_db_getinfo(PM_DB *db, unsigned char parm); -int alpm_db_setserver(PM_DB *db, const char *url); +int alpm_db_setserver(pmdb_t *db, const char *url); -int alpm_db_update(int level, PM_DB *db); +int alpm_db_update(int level, pmdb_t *db); -PM_PKG *alpm_db_readpkg(PM_DB *db, char *name); -PM_LIST *alpm_db_getpkgcache(PM_DB *db); -PM_LIST *alpm_db_whatprovides(PM_DB *db, char *name); +pmpkg_t *alpm_db_readpkg(pmdb_t *db, char *name); +pmlist_t *alpm_db_getpkgcache(pmdb_t *db); +pmlist_t *alpm_db_whatprovides(pmdb_t *db, char *name); -PM_GRP *alpm_db_readgrp(PM_DB *db, char *name); -PM_LIST *alpm_db_getgrpcache(PM_DB *db); -PM_LIST *alpm_db_search(PM_DB *db); +pmgrp_t *alpm_db_readgrp(pmdb_t *db, char *name); +pmlist_t *alpm_db_getgrpcache(pmdb_t *db); +pmlist_t *alpm_db_search(pmdb_t *db); /* * Packages */ /* Info parameters */ -enum { - /* Desc entry */ - PM_PKG_NAME = 1, - PM_PKG_VERSION, - PM_PKG_DESC, - PM_PKG_GROUPS, - PM_PKG_URL, - PM_PKG_LICENSE, - PM_PKG_ARCH, - PM_PKG_BUILDDATE, - PM_PKG_BUILDTYPE, - PM_PKG_INSTALLDATE, - PM_PKG_PACKAGER, - PM_PKG_SIZE, - PM_PKG_USIZE, - PM_PKG_REASON, - PM_PKG_MD5SUM, /* Sync DB only */ - PM_PKG_SHA1SUM, /* Sync DB only */ - /* Depends entry */ - PM_PKG_DEPENDS, - PM_PKG_REMOVES, - PM_PKG_REQUIREDBY, - PM_PKG_CONFLICTS, - PM_PKG_PROVIDES, - PM_PKG_REPLACES, /* Sync DB only */ - /* Files entry */ - PM_PKG_FILES, - PM_PKG_BACKUP, - /* Sciplet */ - PM_PKG_SCRIPLET, - /* Misc */ - PM_PKG_DATA -}; /* reasons -- ie, why the package was installed */ #define PM_PKG_REASON_EXPLICIT 0 /* explicitly requested by the user */ @@ -197,27 +191,46 @@ enum { #define PM_PKG_WITHOUT_ARCH 0 /* pkgname-pkgver-pkgrel, used under PM_DBPATH */ #define PM_PKG_WITH_ARCH 1 /* ie, pkgname-pkgver-pkgrel-arch, used under PM_CACHEDIR */ -void *alpm_pkg_getinfo(PM_PKG *pkg, unsigned char parm); -int alpm_pkg_load(char *filename, PM_PKG **pkg); -int alpm_pkg_free(PM_PKG *pkg); -int alpm_pkg_checkmd5sum(PM_PKG *pkg); -int alpm_pkg_checksha1sum(PM_PKG *pkg); +int alpm_pkg_load(char *filename, pmpkg_t **pkg); +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); +const char *alpm_pkg_get_name(pmpkg_t *pkg); +const char *alpm_pkg_get_version(pmpkg_t *pkg); +const char *alpm_pkg_get_desc(pmpkg_t *pkg); +const char *alpm_pkg_get_url(pmpkg_t *pkg); +const char *alpm_pkg_get_builddate(pmpkg_t *pkg); +const char *alpm_pkg_get_buildtype(pmpkg_t *pkg); +const char *alpm_pkg_get_installdate(pmpkg_t *pkg); +const char *alpm_pkg_get_packager(pmpkg_t *pkg); +const char *alpm_pkg_get_md5sum(pmpkg_t *pkg); +const char *alpm_pkg_get_sha1sum(pmpkg_t *pkg); +const char *alpm_pkg_get_arch(pmpkg_t *pkg); +unsigned long alpm_pkg_get_size(pmpkg_t *pkg); +unsigned long alpm_pkg_get_usize(pmpkg_t *pkg); +unsigned char alpm_pkg_get_reason(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_licenses(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_groups(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_depends(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_removes(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_requiredby(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_conflicts(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_provides(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_replaces(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_files(pmpkg_t *pkg); +pmlist_t *alpm_pkg_get_backup(pmpkg_t *pkg); +unsigned char alpm_pkg_has_scriptlet(pmpkg_t *pkg); + /* * Groups */ - -/* Info parameters */ -enum { - PM_GRP_NAME = 1, - PM_GRP_PKGNAMES -}; - -void *alpm_grp_getinfo(PM_GRP *grp, unsigned char parm); +const char *alpm_grp_get_name(pmgrp_t *grp); +pmlist_t *alpm_grp_get_packages(pmgrp_t *grp); /* * Sync @@ -229,14 +242,10 @@ enum { PM_SYNC_TYPE_UPGRADE, PM_SYNC_TYPE_DEPEND }; -/* Info parameters */ -enum { - PM_SYNC_TYPE = 1, - PM_SYNC_PKG, - PM_SYNC_DATA -}; -void *alpm_sync_getinfo(PM_SYNCPKG *sync, unsigned char parm); +unsigned char alpm_sync_get_type(pmsyncpkg_t *sync); +pmpkg_t *alpm_sync_get_package(pmsyncpkg_t *sync); +void *alpm_sync_get_data(pmsyncpkg_t *sync); /* * Transactions @@ -334,8 +343,8 @@ void *alpm_trans_getinfo(unsigned char parm); int alpm_trans_init(unsigned char type, unsigned int flags, alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv, alpm_trans_cb_progress cb_progress); int alpm_trans_sysupgrade(void); int alpm_trans_addtarget(char *target); -int alpm_trans_prepare(PM_LIST **data); -int alpm_trans_commit(PM_LIST **data); +int alpm_trans_prepare(pmlist_t **data); +int alpm_trans_commit(pmlist_t **data); int alpm_trans_release(void); /* @@ -362,7 +371,7 @@ enum { PM_DEP_VERSION }; -void *alpm_dep_getinfo(PM_DEPMISS *miss, unsigned char parm); +void *alpm_dep_getinfo(pmdepmissing_t *miss, unsigned char parm); /* * File conflicts @@ -380,19 +389,19 @@ enum { PM_CONFLICT_CTARGET }; -void *alpm_conflict_getinfo(PM_CONFLICT *conflict, unsigned char parm); +void *alpm_conflict_getinfo(pmconflict_t *conflict, unsigned char parm); /* * Helpers */ -/* PM_LIST */ -PM_LIST *alpm_list_first(PM_LIST *list); -PM_LIST *alpm_list_next(PM_LIST *entry); -void *alpm_list_getdata(PM_LIST *entry); -int alpm_list_free(PM_LIST *entry); -int alpm_list_free_outer(PM_LIST *entry); -int alpm_list_count(PM_LIST *list); +/* pmlist_t */ +pmlist_t *alpm_list_first(pmlist_t *list); +pmlist_t *alpm_list_next(pmlist_t *entry); +void *alpm_list_getdata(const pmlist_t *entry); +int alpm_list_free(pmlist_t *entry); +int alpm_list_free_outer(pmlist_t *entry); +int alpm_list_count(const pmlist_t *list); /* md5sums */ char *alpm_get_md5sum(char *name); @@ -401,7 +410,6 @@ char *alpm_get_sha1sum(char *name); /* * Errors */ - extern enum __pmerrno_t { PM_ERR_MEMORY = 1, PM_ERR_SYSTEM, diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 8f81235f..33dd78b5 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -43,6 +43,7 @@ #include "alpm.h" #include "error.h" #include "handle.h" +#include "package.h" /* This function is used to convert the downloaded db file to the proper backend @@ -199,6 +200,9 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info) _alpm_log(PM_LOG_FUNCTION, _("loading package data for %s : level=%d"), info->name, inforeq); + /* clear out 'line', to be certain - and to make valgrind happy */ + memset(line, 513, 0); + snprintf(path, PATH_MAX, "%s/%s-%s", db->path, info->name, info->version); if(stat(path, &buf)) { /* directory doesn't exist or can't be opened */ @@ -410,7 +414,7 @@ int _alpm_db_read(pmdb_t *db, unsigned int inforeq, pmpkg_t *info) } /* INSTALL */ - if(inforeq & INFRQ_SCRIPLET) { + if(inforeq & INFRQ_SCRIPTLET) { snprintf(path, PATH_MAX, "%s/%s-%s/install", db->path, info->name, info->version); if(!stat(path, &buf)) { info->scriptlet = 1; diff --git a/lib/libalpm/cache.h b/lib/libalpm/cache.h index b1187225..5b366bdf 100644 --- a/lib/libalpm/cache.h +++ b/lib/libalpm/cache.h @@ -21,10 +21,10 @@ #ifndef _ALPM_CACHE_H #define _ALPM_CACHE_H +#include "db.h" #include "list.h" -#include "package.h" #include "group.h" -#include "db.h" +#include "package.h" /* packages */ int _alpm_db_load_pkgcache(pmdb_t *db, unsigned char infolevel); diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c index 18a9f06f..57323c30 100644 --- a/lib/libalpm/conflict.c +++ b/lib/libalpm/conflict.c @@ -35,6 +35,8 @@ #include <sys/stat.h> #include <libintl.h> /* pacman */ +#include "list.h" +#include "trans.h" #include "util.h" #include "error.h" #include "log.h" diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h index a47a585e..7bf8744b 100644 --- a/lib/libalpm/conflict.h +++ b/lib/libalpm/conflict.h @@ -22,15 +22,16 @@ #define _ALPM_CONFLICT_H #include "db.h" +#include "alpm.h" #define CONFLICT_FILE_LEN 512 -typedef struct __pmconflict_t { +struct __pmconflict_t { char target[PKG_NAME_LEN]; unsigned char type; char file[CONFLICT_FILE_LEN]; char ctarget[PKG_NAME_LEN]; -} pmconflict_t; +}; pmlist_t *_alpm_checkconflicts(pmdb_t *db, pmlist_t *packages); pmlist_t *_alpm_db_find_conflicts(pmdb_t *db, pmtrans_t *trans, char *root, pmlist_t **skip_list); diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 641a6f3f..c3e071b0 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -223,4 +223,29 @@ pmdb_t *_alpm_db_register(char *treename, alpm_cb_db_register callback) return(db); } + +const char *alpm_db_get_name(pmdb_t *db) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(db != NULL, return(NULL)); + + return db->treename; +} + +const char *alpm_db_get_url(pmdb_t *db) +{ + char path[PATH_MAX]; + pmserver_t *s; + + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(db != NULL, return(NULL)); + + s = (pmserver_t*)db->servers->data; + + snprintf(path, PATH_MAX, "%s://%s%s", s->s_url->scheme, s->s_url->host, s->s_url->doc); + return strdup(path); +} + /* vim: set noet: */ diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index bffae081..d894c213 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -23,36 +23,31 @@ #ifndef _ALPM_DB_H #define _ALPM_DB_H -#include <limits.h> -#include "package.h" #include "alpm.h" +#include <limits.h> /* Database entries */ -#define INFRQ_NONE 0x00 -#define INFRQ_DESC 0x01 -#define INFRQ_DEPENDS 0x02 -#define INFRQ_FILES 0x04 -#define INFRQ_SCRIPLET 0x08 -#define INFRQ_ALL 0xFF - -#define DB_O_CREATE 0x01 +#define INFRQ_NONE 0x00 +#define INFRQ_DESC 0x01 +#define INFRQ_DEPENDS 0x02 +#define INFRQ_FILES 0x04 +#define INFRQ_SCRIPTLET 0x08 +#define INFRQ_ALL 0xFF /* Database */ -typedef struct __pmdb_t { +struct __pmdb_t { char *path; char treename[PATH_MAX]; void *handle; pmlist_t *pkgcache; pmlist_t *grpcache; pmlist_t *servers; -} pmdb_t; +}; pmdb_t *_alpm_db_new(char *root, char *dbpath, char *treename); void _alpm_db_free(void *data); int _alpm_db_cmp(const void *db1, const void *db2); pmlist_t *_alpm_db_search(pmdb_t *db, pmlist_t *needles); - -/* Prototypes for backends functions */ int _alpm_db_install(pmdb_t *db, const char *dbfile); int _alpm_db_open(pmdb_t *db); void _alpm_db_close(pmdb_t *db); diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index 030020a9..d3269673 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -25,18 +25,21 @@ #include "db.h" #include "sync.h" +#include "alpm.h" -typedef struct __pmdepend_t { +/* Dependency */ +struct __pmdepend_t { unsigned char mod; char name[PKG_NAME_LEN]; char version[PKG_VERSION_LEN]; -} pmdepend_t; +}; -typedef struct __pmdepmissing_t { +/* Missing dependency */ +struct __pmdepmissing_t { char target[PKG_NAME_LEN]; unsigned char type; pmdepend_t depend; -} pmdepmissing_t; +}; pmdepmissing_t *_alpm_depmiss_new(const char *target, unsigned char type, unsigned char depmod, const char *depname, const char *depversion); diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c index a578c777..ecc608d8 100644 --- a/lib/libalpm/group.c +++ b/lib/libalpm/group.c @@ -29,6 +29,7 @@ #include "error.h" #include "log.h" #include "group.h" +#include "list.h" #include "alpm.h" pmgrp_t *_alpm_grp_new() @@ -72,4 +73,19 @@ int _alpm_grp_cmp(const void *g1, const void *g2) return(strcmp(grp1->name, grp2->name)); } +const char *alpm_grp_get_name(pmgrp_t *grp) +{ + /* Sanity checks */ + ASSERT(grp != NULL, return(NULL)); + + return grp->name; +} + +pmlist_t *alpm_grp_get_packages(pmgrp_t *grp) +{ + /* Sanity checks */ + ASSERT(grp != NULL, return(NULL)); + + return grp->packages; +} /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/group.h b/lib/libalpm/group.h index bb3de2a5..86562b10 100644 --- a/lib/libalpm/group.h +++ b/lib/libalpm/group.h @@ -21,18 +21,17 @@ #ifndef _ALPM_GROUP_H #define _ALPM_GROUP_H -#include "list.h" - +/* Groups */ #define GRP_NAME_LEN 256 -/* Groups structure */ -typedef struct __pmgrp_t { +#include "alpm.h" + +struct __pmgrp_t { char name[GRP_NAME_LEN]; pmlist_t *packages; /* List of strings */ -} pmgrp_t; +}; #define FREEGRP(p) do { if(p) { _alpm_grp_free(p); p = NULL; } } while(0) - #define FREELISTGRPS(p) _FREELIST(p, _alpm_grp_free) pmgrp_t *_alpm_grp_new(void); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index dd9d50b6..ddc8d77d 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -31,7 +31,6 @@ #include <syslog.h> #include <libintl.h> #include <time.h> -/////#include <ftplib.h> /* pacman */ #include "util.h" #include "log.h" @@ -105,7 +104,6 @@ int _alpm_handle_free(pmhandle_t *handle) FREE(handle->dbpath); FREE(handle->cachedir); FREE(handle->logfile); - FREE(handle->proxyhost); FREE(handle->xfercommand); FREELIST(handle->dbs_sync); FREELIST(handle->noupgrade); @@ -118,242 +116,130 @@ int _alpm_handle_free(pmhandle_t *handle) return(0); } -int _alpm_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long data) +alpm_cb_log alpm_option_get_logcb() { return handle->logcb; } +alpm_cb_download alpm_option_get_dlcb() { return handle->dlcb; } +unsigned char alpm_option_get_logmask() { return handle->logmask; } +const char *alpm_option_get_root() { return handle->root; } +const char *alpm_option_get_dbpath() { return handle->dbpath; } +const char *alpm_option_get_cachedir() { return handle->cachedir; } +const char *alpm_option_get_logfile() { return handle->logfile; } +unsigned char alpm_option_get_usesyslog() { return handle->usesyslog; } +pmlist_t *alpm_option_get_noupgrades() { return handle->noupgrade; } +pmlist_t *alpm_option_get_noextracts() { return handle->noextract; } +pmlist_t *alpm_option_get_ignorepkgs() { return handle->ignorepkg; } +pmlist_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 alpm_option_get_chomp() { return handle->chomp; } +pmlist_t *alpm_option_get_needles() { return handle->needles; } +unsigned short alpm_option_get_usecolor() { return handle->use_color; } + +pmdb_t *alpm_option_get_localdb(pmhandle_t *handle) { return handle->db_local; } +pmlist_t *alpm_option_get_syncdbs(pmhandle_t *handle) { return handle->dbs_sync; } + +void alpm_option_set_logcb(alpm_cb_log cb) { handle->logcb = cb; } + +void alpm_option_set_dlcb(alpm_cb_download cb) { handle->dlcb = cb; } + +void alpm_option_set_logmask(unsigned char mask) { handle->logmask = mask; } + +void alpm_option_set_root(const char *root) { - /* Sanity checks */ - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + if(handle->root) FREE(handle->root); + if(root) handle->root = strdup(root); +} - char *p; - switch(val) { - case PM_OPT_DBPATH: - if(handle->dbpath) { - FREE(handle->dbpath); - } - handle->dbpath = strdup((data && strlen((char *)data) != 0) ? (char *)data : PM_DBPATH); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_DBPATH set to '%s'"), handle->dbpath); - break; - case PM_OPT_CACHEDIR: - if(handle->cachedir) { - FREE(handle->cachedir); - } - handle->cachedir = strdup((data && strlen((char *)data) != 0) ? (char *)data : PM_CACHEDIR); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_CACHEDIR set to '%s'"), handle->cachedir); - break; - case PM_OPT_LOGFILE: - if((char *)data == NULL || handle->uid != 0) { - return(0); - } - if(handle->logfile) { - FREE(handle->logfile); - } - if(handle->logfd) { - if(fclose(handle->logfd) != 0) { - handle->logfd = NULL; - RET_ERR(PM_ERR_OPT_LOGFILE, -1); - } - handle->logfd = NULL; - } - if((handle->logfd = fopen((char *)data, "a")) == NULL) { - _alpm_log(PM_LOG_ERROR, _("can't open log file %s"), (char *)data); - RET_ERR(PM_ERR_OPT_LOGFILE, -1); - } - handle->logfile = strdup((char *)data); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_LOGFILE set to '%s'"), (char *)data); - break; - case PM_OPT_NOUPGRADE: - if((char *)data && strlen((char *)data) != 0) { - handle->noupgrade = _alpm_list_add(handle->noupgrade, strdup((char *)data)); - _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_NOUPGRADE"), (char *)data); - } else { - FREELIST(handle->noupgrade); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NOUPGRADE flushed")); - } - break; - case PM_OPT_NOEXTRACT: - if((char *)data && strlen((char *)data) != 0) { - handle->noextract = _alpm_list_add(handle->noextract, strdup((char *)data)); - _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_NOEXTRACT"), (char *)data); - } else { - FREELIST(handle->noextract); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NOEXTRACT flushed")); - } - break; - case PM_OPT_IGNOREPKG: - if((char *)data && strlen((char *)data) != 0) { - handle->ignorepkg = _alpm_list_add(handle->ignorepkg, strdup((char *)data)); - _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_IGNOREPKG"), (char *)data); - } else { - FREELIST(handle->ignorepkg); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_IGNOREPKG flushed")); - } - break; - case PM_OPT_HOLDPKG: - if((char *)data && strlen((char *)data) != 0) { - handle->holdpkg = _alpm_list_add(handle->holdpkg, strdup((char *)data)); - _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_HOLDPKG"), (char *)data); - } else { - FREELIST(handle->holdpkg); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_HOLDPKG flushed")); - } - break; - case PM_OPT_NEEDLES: - if((char *)data && strlen((char *)data) != 0) { - handle->needles = _alpm_list_add(handle->needles, strdup((char *)data)); - _alpm_log(PM_LOG_FLOW2, _("'%s' added to PM_OPT_NEEDLES"), (char *)data); - } else { - FREELIST(handle->needles); - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NEEDLES flushed")); - } - break; - case PM_OPT_USESYSLOG: - if(data != 0 && data != 1) { - RET_ERR(PM_ERR_OPT_USESYSLOG, -1); - } - if(handle->usesyslog == data) { - return(0); - } - if(handle->usesyslog) { - closelog(); - } else { - openlog("alpm", 0, LOG_USER); - } - handle->usesyslog = (unsigned short)data; - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_USESYSLOG set to '%d'"), handle->usesyslog); - break; - case PM_OPT_LOGCB: - pm_logcb = (alpm_cb_log)data; - break; - case PM_OPT_DLCB: - pm_dlcb = (download_progress_cb)data; - break; -/* case PM_OPT_DLFNM: - pm_dlfnm = (char *)data; - break; - case PM_OPT_DLOFFSET: - pm_dloffset = (int *)data; - break; - case PM_OPT_DLT0: - pm_dlt0 = (struct timeval *)data; - break; - case PM_OPT_DLT: - pm_dlt = (struct timeval *)data; - break; - case PM_OPT_DLRATE: - pm_dlrate = (float *)data; - break; - case PM_OPT_DLXFERED1: - pm_dlxfered1 = (int *)data; - break; - case PM_OPT_DLETA_H: - pm_dleta_h = (unsigned char *)data; - break; - case PM_OPT_DLETA_M: - pm_dleta_m = (unsigned char *)data; - break; - case PM_OPT_DLETA_S: - pm_dleta_s = (unsigned char *)data; - break; -*/ - case PM_OPT_UPGRADEDELAY: - handle->upgradedelay = data; - break; - case PM_OPT_LOGMASK: - pm_logmask = (unsigned char)data; - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_LOGMASK set to '%02x'"), (unsigned char)data); - break; - case PM_OPT_PROXYHOST: - if(handle->proxyhost) { - FREE(handle->proxyhost); - } - p = strstr((char*)data, "://"); - if(p) { - p += 3; - if(p == NULL || *p == '\0') { - RET_ERR(PM_ERR_SERVER_BAD_LOCATION, -1); - } - data = (long)p; - } -#if defined(__APPLE__) || defined(__OpenBSD__) - handle->proxyhost = strdup((char*)data); -#else - handle->proxyhost = strndup((char*)data, PATH_MAX); -#endif - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_PROXYHOST set to '%s'"), handle->proxyhost); - break; - case PM_OPT_PROXYPORT: - handle->proxyport = (unsigned short)data; - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_PROXYPORT set to '%d'"), handle->proxyport); - break; - case PM_OPT_XFERCOMMAND: - if(handle->xfercommand) { - FREE(handle->xfercommand); - } -#if defined(__APPLE__) || defined(__OpenBSD__) - handle->xfercommand = strdup((char*)data); -#else - handle->xfercommand = strndup((char*)data, PATH_MAX); -#endif - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_XFERCOMMAND set to '%s'"), handle->xfercommand); - break; - case PM_OPT_NOPASSIVEFTP: - handle->nopassiveftp = (unsigned short)data; - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_NOPASSIVEFTP set to '%d'"), handle->nopassiveftp); - break; - case PM_OPT_CHOMP: - handle->chomp = (unsigned short)data; - _alpm_log(PM_LOG_FLOW2, _("PM_OPT_CHOMP set to '%d'"), handle->chomp); - break; - default: - RET_ERR(PM_ERR_WRONG_ARGS, -1); +void alpm_option_set_dbpath(const char *dbpath) +{ + if(handle->dbpath) FREE(handle->dbpath); + if(dbpath) handle->dbpath = strdup(dbpath); +} + +void alpm_option_set_cachedir(const char *cachedir) +{ + if(handle->cachedir) FREE(handle->cachedir); + if(cachedir) handle->cachedir = strdup(cachedir); +} + +void alpm_option_set_logfile(const char *logfile) +{ + if(handle->logfile) { + FREE(handle->logfile); + if(handle->logfd) { + fclose(handle->logfd); + handle->logfd = NULL; + } + } + if(logfile) { + handle->logfile = strdup(logfile); + handle->logfd = fopen(logfile, "a"); } +} - return(0); +void alpm_option_set_usesyslog(unsigned char usesyslog) { handle->usesyslog = usesyslog; } + +void alpm_option_add_noupgrade(char *pkg) +{ + handle->noupgrade = _alpm_list_add(handle->noupgrade, strdup(pkg)); +} +void alpm_option_set_noupgrades(pmlist_t *noupgrade) +{ + if(handle->noupgrade) FREELIST(handle->noupgrade); + if(noupgrade) handle->noupgrade = noupgrade; } -int _alpm_handle_get_option(pmhandle_t *handle, unsigned char val, long *data) +void alpm_option_add_noextract(char *pkg) { - /* Sanity checks */ - ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); + handle->noextract = _alpm_list_add(handle->noextract, strdup(pkg)); +} +void alpm_option_set_noextracts(pmlist_t *noextract) +{ + if(handle->noextract) FREELIST(handle->noextract); + if(noextract) handle->noextract = noextract; +} - switch(val) { - case PM_OPT_ROOT: *data = (long)handle->root; break; - case PM_OPT_DBPATH: *data = (long)handle->dbpath; break; - case PM_OPT_CACHEDIR: *data = (long)handle->cachedir; break; - case PM_OPT_LOCALDB: *data = (long)handle->db_local; break; - case PM_OPT_SYNCDB: *data = (long)handle->dbs_sync; break; - case PM_OPT_LOGFILE: *data = (long)handle->logfile; break; - case PM_OPT_NOUPGRADE: *data = (long)handle->noupgrade; break; - case PM_OPT_NOEXTRACT: *data = (long)handle->noextract; break; - case PM_OPT_IGNOREPKG: *data = (long)handle->ignorepkg; break; - case PM_OPT_HOLDPKG: *data = (long)handle->holdpkg; break; - case PM_OPT_NEEDLES: *data = (long)handle->needles; break; - case PM_OPT_USESYSLOG: *data = handle->usesyslog; break; - case PM_OPT_LOGCB: *data = (long)pm_logcb; break; - case PM_OPT_DLCB: *data = (long)pm_dlcb; break; - case PM_OPT_UPGRADEDELAY: *data = (long)handle->upgradedelay; break; - case PM_OPT_LOGMASK: *data = pm_logmask; break; -/* - case PM_OPT_DLFNM: *data = (long)pm_dlfnm; break; - case PM_OPT_DLOFFSET: *data = (long)pm_dloffset; break; - case PM_OPT_DLT0: *data = (long)pm_dlt0; break; - case PM_OPT_DLT: *data = (long)pm_dlt; break; - case PM_OPT_DLRATE: *data = (long)pm_dlrate; break; - case PM_OPT_DLXFERED1: *data = (long)pm_dlxfered1; break; - case PM_OPT_DLETA_H: *data = (long)pm_dleta_h; break; - case PM_OPT_DLETA_M: *data = (long)pm_dleta_m; break; - case PM_OPT_DLETA_S: *data = (long)pm_dleta_s; break; -*/ - case PM_OPT_PROXYHOST: *data = (long)handle->proxyhost; break; - case PM_OPT_PROXYPORT: *data = handle->proxyport; break; - case PM_OPT_XFERCOMMAND: *data = (long)handle->xfercommand; break; - case PM_OPT_NOPASSIVEFTP: *data = handle->nopassiveftp; break; - case PM_OPT_CHOMP: *data = handle->chomp; break; - default: - RET_ERR(PM_ERR_WRONG_ARGS, -1); - break; - } +void alpm_option_add_ignorepkg(char *pkg) +{ + handle->ignorepkg = _alpm_list_add(handle->ignorepkg, strdup(pkg)); +} +void alpm_option_set_ignorepkgs(pmlist_t *ignorepkgs) +{ + if(handle->ignorepkg) FREELIST(handle->ignorepkg); + if(ignorepkgs) handle->ignorepkg = ignorepkgs; +} - return(0); +void alpm_option_add_holdpkg(char *pkg) +{ + handle->holdpkg = _alpm_list_add(handle->holdpkg, strdup(pkg)); +} +void alpm_option_set_holdpkgs(pmlist_t *holdpkgs) +{ + if(handle->holdpkg) FREELIST(handle->holdpkg); + if(holdpkgs) handle->holdpkg = holdpkgs; +} + +void alpm_option_set_upgradedelay(time_t delay) { handle->upgradedelay = delay; } + +void 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) { handle->nopassiveftp = nopasv; } + +void alpm_option_set_chomp(unsigned short chomp) { handle->chomp = chomp; } + +void alpm_option_add_needle(char *needle) +{ + handle->needles = _alpm_list_add(handle->needles, strdup(needle)); +} +void alpm_option_set_needles(pmlist_t *needles) +{ + if(handle->needles) FREELIST(handle->needles); + if(needles) handle->needles = needles; } +void alpm_option_set_usecolor(unsigned short usecolor) { handle->use_color = usecolor; } -/* vim: set ts=2 sw=2 noet: */ +/* vim: set ts=2 sw=2 et: */ diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 9311f724..41e8a5fe 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -21,17 +21,19 @@ #ifndef _ALPM_HANDLE_H #define _ALPM_HANDLE_H -#include "list.h" #include "db.h" -#include "trans.h" +#include "log.h" +#include "list.h" #include "alpm.h" +#include "trans.h" -typedef enum __pmaccess_t { +typedef enum _pmaccess_t { PM_ACCESS_RO, PM_ACCESS_RW } pmaccess_t; -typedef struct __pmhandle_t { +typedef struct _pmhandle_t { + /* Internal */ pmaccess_t access; uid_t uid; pmdb_t *db_local; @@ -39,24 +41,29 @@ typedef struct __pmhandle_t { FILE *logfd; int lckfd; pmtrans_t *trans; - /* parameters */ - char *root; - char *dbpath; - char *cachedir; - char *logfile; - pmlist_t *noupgrade; /* List of strings */ - pmlist_t *noextract; /* List of strings */ - pmlist_t *ignorepkg; /* List of strings */ - pmlist_t *holdpkg; /* List of strings */ - unsigned char usesyslog; - time_t upgradedelay; + + /* options */ + alpm_cb_log logcb; /* Log callback function */ + alpm_cb_download dlcb; /* Download callback function */ + unsigned char logmask; /* Output mask for logging functions */ + 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?*/ + unsigned char usesyslog; /* Use syslog instead of logfile? */ + + pmlist_t *noupgrade; /* List of packages NOT to be upgraded */ + pmlist_t *noextract; /* List of packages NOT to extrace */ /*TODO is this used?*/ + pmlist_t *ignorepkg; /* List of packages to ignore */ + pmlist_t *holdpkg; /* List of packages which 'hold' pacman */ + + time_t upgradedelay; /* Amount of time to wait before upgrading a package*/ /* servers */ - char *proxyhost; - unsigned short proxyport; - char *xfercommand; - unsigned short nopassiveftp; - unsigned short chomp; /* if eye-candy features should be enabled or not */ - pmlist_t *needles; /* for searching */ + char *xfercommand; /* External download command */ + unsigned short nopassiveftp; /* Don't use PASV ftp connections */ + unsigned short chomp; /* I Love Candy! */ + pmlist_t *needles; /* needles for searching */ /* TODO why is this here? */ + unsigned short use_color; /* enable colorful output */ } pmhandle_t; extern pmhandle_t *handle; @@ -65,8 +72,6 @@ extern pmhandle_t *handle; pmhandle_t *_alpm_handle_new(void); int _alpm_handle_free(pmhandle_t *handle); -int _alpm_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long data); -int _alpm_handle_get_option(pmhandle_t *handle, unsigned char val, long *data); #endif /* _ALPM_HANDLE_H */ diff --git a/lib/libalpm/list.c b/lib/libalpm/list.c index 0f48030b..47c31990 100644 --- a/lib/libalpm/list.c +++ b/lib/libalpm/list.c @@ -187,10 +187,10 @@ pmlist_t *_alpm_list_remove(pmlist_t *haystack, void *needle, _alpm_fn_cmp fn, v return(haystack); } -int _alpm_list_count(pmlist_t *list) +int _alpm_list_count(const pmlist_t *list) { int i; - pmlist_t *lp; + const pmlist_t *lp; for(lp = list, i = 0; lp; lp = lp->next, i++); diff --git a/lib/libalpm/list.h b/lib/libalpm/list.h index abff7819..3fdc01ad 100644 --- a/lib/libalpm/list.h +++ b/lib/libalpm/list.h @@ -21,13 +21,15 @@ #ifndef _ALPM_LIST_H #define _ALPM_LIST_H +#include "alpm.h" + /* Chained list struct */ -typedef struct __pmlist_t { +struct __pmlist_t { void *data; struct __pmlist_t *prev; struct __pmlist_t *next; struct __pmlist_t *last; /* Quick access to last item in list */ -} pmlist_t; +}; #define _FREELIST(p, f) do { if(p) { _alpm_list_free(p, f); p = NULL; } } while(0) #define FREELIST(p) _FREELIST(p, free) @@ -42,7 +44,7 @@ void _alpm_list_free(pmlist_t *list, _alpm_fn_free fn); pmlist_t *_alpm_list_add(pmlist_t *list, void *data); pmlist_t *_alpm_list_add_sorted(pmlist_t *list, void *data, _alpm_fn_cmp fn); pmlist_t *_alpm_list_remove(pmlist_t *haystack, void *needle, _alpm_fn_cmp fn, void **data); -int _alpm_list_count(pmlist_t *list); +int _alpm_list_count(const pmlist_t *list); int _alpm_list_is_in(void *needle, pmlist_t *haystack); int _alpm_list_is_strin(char *needle, pmlist_t *haystack); pmlist_t *_alpm_list_last(pmlist_t *list); diff --git a/lib/libalpm/log.c b/lib/libalpm/log.c index f0dd2b18..2b543ae6 100644 --- a/lib/libalpm/log.c +++ b/lib/libalpm/log.c @@ -27,17 +27,14 @@ #include "alpm.h" #include "log.h" -/* Internal library log mechanism */ -alpm_cb_log pm_logcb = NULL; -unsigned char pm_logmask = 0; - void _alpm_log(unsigned char flag, char *fmt, ...) { - if(pm_logcb == NULL) { + alpm_cb_log logcb = alpm_option_get_logcb(); + if(logcb == NULL) { return; } - if(flag & pm_logmask) { + if(flag & alpm_option_get_logmask()) { char str[LOG_STR_LEN]; va_list args; @@ -45,7 +42,7 @@ void _alpm_log(unsigned char flag, char *fmt, ...) vsnprintf(str, LOG_STR_LEN, fmt, args); va_end(args); - pm_logcb(flag, str); + logcb(flag, str); } } diff --git a/lib/libalpm/log.h b/lib/libalpm/log.h index da1d9966..ab35e72b 100644 --- a/lib/libalpm/log.h +++ b/lib/libalpm/log.h @@ -21,12 +21,7 @@ #ifndef _ALPM_LOG_H #define _ALPM_LOG_H -#define LOG_STR_LEN 256 - -typedef void (*alpm_cb_log)(unsigned short, char *); - -extern alpm_cb_log pm_logcb; -extern unsigned char pm_logmask; +#define LOG_STR_LEN 1024 void _alpm_log(unsigned char flag, char *fmt, ...); diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 1302ebe5..31867551 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -36,6 +36,8 @@ #include "error.h" #include "list.h" #include "package.h" +#include "db.h" +#include "handle.h" #include "alpm.h" pmpkg_t *_alpm_pkg_new(const char *name, const char *version) @@ -241,11 +243,11 @@ static int parse_descfile(char *descfile, pmpkg_t *info, int output) } else if(!strcmp(key, "SIZE")) { char tmp[32]; STRNCPY(tmp, ptr, sizeof(tmp)); - info->size = atol(tmp); + info->size = atol(ptr); } else if(!strcmp(key, "USIZE")) { char tmp[32]; STRNCPY(tmp, ptr, sizeof(tmp)); - info->usize = atol(tmp); + info->usize = atol(ptr); } else if(!strcmp(key, "DEPEND")) { info->depends = _alpm_list_add(info->depends, strdup(ptr)); } else if(!strcmp(key, "REMOVE")) { @@ -509,4 +511,302 @@ int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch) return(0); } +const char *alpm_pkg_get_name(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + return pkg->name; +} + +const char *alpm_pkg_get_version(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + return pkg->version; +} + +const char *alpm_pkg_get_desc(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->desc; +} + +const char *alpm_pkg_get_url(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->url; +} + +const char *alpm_pkg_get_builddate(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->builddate; +} + +const char *alpm_pkg_get_buildtype(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->buildtype; +} + +const char *alpm_pkg_get_installdate(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->installdate; +} + +const char *alpm_pkg_get_packager(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->packager; +} + +const char *alpm_pkg_get_md5sum(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->md5sum; +} + +const char *alpm_pkg_get_sha1sum(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->sha1sum; +} + +const char *alpm_pkg_get_arch(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->arch; +} + +unsigned long alpm_pkg_get_size(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(pkg != NULL, return(-1)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->size; +} + +unsigned long alpm_pkg_get_usize(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(pkg != NULL, return(-1)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->usize; +} + +unsigned char alpm_pkg_get_reason(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(pkg != NULL, return(-1)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->reason; +} + +pmlist_t *alpm_pkg_get_licenses(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->license; +} + +pmlist_t *alpm_pkg_get_groups(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DESC)) { + _alpm_db_read(pkg->data, INFRQ_DESC, pkg); + } + return pkg->groups; +} + +/* depends */ +pmlist_t *alpm_pkg_get_depends(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) { + _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg); + } + return pkg->depends; +} + +pmlist_t *alpm_pkg_get_removes(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) { + _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg); + } + return pkg->removes; +} + +pmlist_t *alpm_pkg_get_requiredby(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) { + _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg); + } + return pkg->requiredby; +} + +pmlist_t *alpm_pkg_get_conflicts(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) { + _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg); + } + return pkg->conflicts; +} + +pmlist_t *alpm_pkg_get_provides(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) { + _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg); + } + return pkg->provides; +} + +pmlist_t *alpm_pkg_get_replaces(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && !(pkg->infolevel & INFRQ_DEPENDS)) { + _alpm_db_read(pkg->data, INFRQ_DEPENDS, pkg); + } + return pkg->replaces; +} + +pmlist_t *alpm_pkg_get_files(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && pkg->data == handle->db_local + && !(pkg->infolevel & INFRQ_FILES)) { + _alpm_db_read(pkg->data, INFRQ_FILES, pkg); + } + return pkg->files; +} + +pmlist_t *alpm_pkg_get_backup(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(NULL)); + ASSERT(pkg != NULL, return(NULL)); + + if(pkg->origin == PKG_FROM_CACHE && pkg->data == handle->db_local + && !(pkg->infolevel & INFRQ_FILES)) { + _alpm_db_read(pkg->data, INFRQ_FILES, pkg); + } + return pkg->backup; +} + +unsigned char alpm_pkg_has_scriptlet(pmpkg_t *pkg) +{ + /* Sanity checks */ + ASSERT(handle != NULL, return(-1)); + ASSERT(pkg != NULL, return(-1)); + + if(pkg->origin == PKG_FROM_CACHE && pkg->data == handle->db_local + && !(pkg->infolevel & INFRQ_SCRIPTLET)) { + _alpm_db_read(pkg->data, INFRQ_SCRIPTLET, pkg); + } + return pkg->scriptlet; +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index d96f8d41..1b834cb8 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -28,13 +28,15 @@ #if defined(__APPLE__) || defined(__sun__) #include <time.h> #endif -#include "list.h" + +#include "alpm.h" enum { PKG_FROM_CACHE = 1, PKG_FROM_FILE }; +/* Packages */ #define PKG_NAME_LEN 256 #define PKG_VERSION_LEN 64 #define PKG_FULLNAME_LEN (PKG_NAME_LEN-1)+1+(PKG_VERSION_LEN-1)+1 @@ -47,7 +49,7 @@ enum { #define PKG_SHA1SUM_LEN 41 #define PKG_ARCH_LEN 32 -typedef struct __pmpkg_t { +struct __pmpkg_t { char name[PKG_NAME_LEN]; char version[PKG_VERSION_LEN]; char desc[PKG_DESC_LEN]; @@ -80,16 +82,9 @@ typedef struct __pmpkg_t { unsigned char origin; void *data; unsigned char infolevel; -} pmpkg_t; - -#define FREEPKG(p) \ -do { \ - if(p) { \ - _alpm_pkg_free(p); \ - p = NULL; \ - } \ -} while(0) +}; +#define FREEPKG(p) do { if(p){_alpm_pkg_free(p); p = NULL;}} while(0) #define FREELISTPKGS(p) _FREELIST(p, _alpm_pkg_free) pmpkg_t* _alpm_pkg_new(const char *name, const char *version); @@ -101,6 +96,7 @@ pmpkg_t *_alpm_pkg_isin(char *needle, pmlist_t *haystack); char *_alpm_pkg_makefilename(pmpkg_t *pkg); int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch); + #endif /* _ALPM_PACKAGE_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/provide.h b/lib/libalpm/provide.h index 7b132200..eb587003 100644 --- a/lib/libalpm/provide.h +++ b/lib/libalpm/provide.h @@ -21,10 +21,9 @@ #ifndef _ALPM_PROVIDE_H #define _ALPM_PROVIDE_H -#include "config.h" - -#include "list.h" #include "db.h" +#include "list.h" +#include "config.h" pmlist_t *_alpm_db_whatprovides(pmdb_t *db, char *package); diff --git a/lib/libalpm/remove.h b/lib/libalpm/remove.h index ac6ff1bf..524e5faa 100644 --- a/lib/libalpm/remove.h +++ b/lib/libalpm/remove.h @@ -21,8 +21,8 @@ #ifndef _ALPM_REMOVE_H #define _ALPM_REMOVE_H -#include "list.h" #include "db.h" +#include "list.h" #include "trans.h" int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name); diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c index 4c0b5e79..90466e32 100644 --- a/lib/libalpm/server.c +++ b/lib/libalpm/server.c @@ -38,8 +38,6 @@ #include "handle.h" #include "log.h" -download_progress_cb pm_dlcb = NULL; - pmserver_t *_alpm_server_new(const char *url) { struct url *u; @@ -172,10 +170,10 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath, downloadTimeout = 10000; /* Make libdownload super verbose... worthwhile for testing */ - if(pm_logmask & PM_LOG_DOWNLOAD) { + if(alpm_option_get_logmask() & PM_LOG_DOWNLOAD) { downloadDebug = 1; } - if(pm_logmask & PM_LOG_DEBUG) { + if(alpm_option_get_logmask() & PM_LOG_DEBUG) { dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "v" : "vp")); } else { dlf = downloadXGet(server->s_url, &ust, (handle->nopassiveftp ? "" : "p")); @@ -229,7 +227,7 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath, } /* Progress 0 - initialize */ - if(pm_dlcb) pm_dlcb(fn, 0, ust.size); + if(handle->dlcb) handle->dlcb(fn, 0, ust.size); int nread = 0; char buffer[PM_DLBUF_LEN]; @@ -238,7 +236,7 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath, while((nwritten += fwrite(buffer, 1, (nread - nwritten), localf)) < nread) ; dltotal_bytes += nread; - if(pm_dlcb) pm_dlcb(fn, dltotal_bytes, ust.size); + if(handle->dlcb) handle->dlcb(fn, dltotal_bytes, ust.size); } fclose(localf); diff --git a/lib/libalpm/server.h b/lib/libalpm/server.h index 5ce848cc..80e9a7e1 100644 --- a/lib/libalpm/server.h +++ b/lib/libalpm/server.h @@ -22,30 +22,22 @@ #define _ALPM_SERVER_H #include "list.h" -#include <time.h> +#include "alpm.h" +#include <time.h> #include <download.h> -#define FREESERVER(p) \ -do { \ - if(p) { \ - _alpm_server_free(p); \ - p = NULL; \ - } \ -} while(0) - +#define FREESERVER(p) do { if(p){_alpm_server_free(p); p = NULL;}} while(0) #define FREELISTSERVERS(p) _FREELIST(p, _alpm_server_free) /* Servers */ -typedef struct __pmserver_t { +struct __pmserver_t { char *path; struct url *s_url; -} pmserver_t; +}; #define PM_DLBUF_LEN (1024 * 10) -typedef void (*download_progress_cb)(const char *filename, int xfered, int total); - pmserver_t *_alpm_server_new(const char *url); void _alpm_server_free(void *data); int _alpm_downloadfiles(pmlist_t *servers, const char *localpath, pmlist_t *files); @@ -54,8 +46,6 @@ int _alpm_downloadfiles_forreal(pmlist_t *servers, const char *localpath, char *_alpm_fetch_pkgurl(char *target); -extern download_progress_cb pm_dlcb; - #endif /* _ALPM_SERVER_H */ /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 9fd1884f..acc48362 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -790,7 +790,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) fname = _alpm_pkg_makefilename(spkg); if(trans->flags & PM_TRANS_FLAG_PRINTURIS) { - EVENT(trans, PM_TRANS_EVT_PRINTURI, alpm_db_getinfo(current, PM_DB_FIRSTSERVER), fname); + EVENT(trans, PM_TRANS_EVT_PRINTURI, (char *)alpm_db_get_url(current), fname); } else { struct stat buf; snprintf(path, PATH_MAX, "%s/%s", ldir, fname); @@ -818,11 +818,8 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, pmlist_t **data) */ _alpm_log(PM_LOG_WARNING, _("couldn't create package cache, using /tmp instead\n")); alpm_logaction(_("warning: couldn't create package cache, using /tmp instead")); - snprintf(ldir, PATH_MAX, "%s/tmp", handle->root); - if(_alpm_handle_set_option(handle, PM_OPT_CACHEDIR, (long)"/tmp") == -1) { - _alpm_log(PM_LOG_WARNING, _("failed to set option CACHEDIR (%s)\n"), alpm_strerror(pm_errno)); - RET_ERR(PM_ERR_RETRIEVE, -1); - } + snprintf(ldir, PATH_MAX, "%stmp", alpm_option_get_root()); + alpm_option_set_cachedir(ldir); varcache = 0; } } @@ -1054,4 +1051,28 @@ error: return(-1); } +unsigned char alpm_sync_get_type(pmsyncpkg_t *sync) +{ + /* Sanity checks */ + ASSERT(sync != NULL, return(-1)); + + return sync->type; +} + +pmpkg_t *alpm_sync_get_package(pmsyncpkg_t *sync) +{ + /* Sanity checks */ + ASSERT(sync != NULL, return(NULL)); + + return sync->pkg; +} + +void *alpm_sync_get_data(pmsyncpkg_t *sync) +{ + /* Sanity checks */ + ASSERT(sync != NULL, return(NULL)); + + return sync->data; +} + /* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index d23dc6d8..f3d5ec02 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -23,15 +23,14 @@ #ifndef _ALPM_SYNC_H #define _ALPM_SYNC_H -#include "db.h" -#include "package.h" -#include "trans.h" +#include "alpm.h" -typedef struct __pmsyncpkg_t { +/* Sync package */ +struct __pmsyncpkg_t { unsigned char type; pmpkg_t *pkg; void *data; -} pmsyncpkg_t; +}; #define FREESYNC(p) do { if(p) { _alpm_sync_free(p); p = NULL; } } while(0) diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h index 95e672b6..49bcceb3 100644 --- a/lib/libalpm/trans.h +++ b/lib/libalpm/trans.h @@ -24,19 +24,10 @@ #ifndef _ALPM_TRANS_H #define _ALPM_TRANS_H -enum { - STATE_IDLE = 0, - STATE_INITIALIZED, - STATE_PREPARED, - STATE_DOWNLOADING, - STATE_COMMITING, - STATE_COMMITED, - STATE_INTERRUPTED -}; - #include "alpm.h" -typedef struct __pmtrans_t { +/* Transaction */ +struct __pmtrans_t { unsigned char type; unsigned int flags; unsigned char state; @@ -46,7 +37,17 @@ typedef struct __pmtrans_t { alpm_trans_cb_event cb_event; alpm_trans_cb_conv cb_conv; alpm_trans_cb_progress cb_progress; -} pmtrans_t; +}; + +enum { + STATE_IDLE = 0, + STATE_INITIALIZED, + STATE_PREPARED, + STATE_DOWNLOADING, + STATE_COMMITING, + STATE_COMMITED, + STATE_INTERRUPTED +}; #define FREETRANS(p) \ do { \ diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index f1f74202..cca43117 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -63,6 +63,7 @@ #include "sync.h" #include "util.h" #include "error.h" +#include "package.h" #include "alpm.h" #ifdef __sun__ |