1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-12-22 15:58:50 -05:00

* Enforce const char* params when using strings

* Unified some functions names "package" -> "pkg" for consistency
* Removed the goofy 'faketarget' stuff used for dep testing
* Renamed alpm_pkg_isin -> alpm_pkg_find
* Renamed alpm_db_readpkg -> alpm_db_get_pkg
This commit is contained in:
Aaron Griffin 2007-02-26 08:38:48 +00:00
parent 52376150fa
commit 8fbdd03cce
17 changed files with 54 additions and 107 deletions

View File

@ -58,55 +58,6 @@
#include "remove.h"
#include "handle.h"
static int add_faketarget(pmtrans_t *trans, char *name)
{
char *ptr, *p;
char *str = NULL;
pmpkg_t *dummy = NULL;
ALPM_LOG_FUNC;
dummy = _alpm_pkg_new(NULL, NULL);
if(dummy == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
/* Format: field1=value1|field2=value2|...
* Valid fields are "name", "version" and "depend"
*/
str = strdup(name);
ptr = str;
while((p = strsep(&ptr, "|")) != NULL) {
char *q;
if(p[0] == 0) {
continue;
}
q = strchr(p, '=');
if(q == NULL) { /* not a valid token */
continue;
}
if(strncmp("name", p, q-p) == 0) {
STRNCPY(dummy->name, q+1, PKG_NAME_LEN);
} else if(strncmp("version", p, q-p) == 0) {
STRNCPY(dummy->version, q+1, PKG_VERSION_LEN);
} else if(strncmp("depend", p, q-p) == 0) {
dummy->depends = alpm_list_add(dummy->depends, strdup(q+1));
} else {
_alpm_log(PM_LOG_ERROR, _("could not parse token %s"), p);
}
}
FREE(str);
if(dummy->name[0] == 0 || dummy->version[0] == 0) {
FREEPKG(dummy);
RET_ERR(PM_ERR_PKG_INVALID_NAME, -1);
}
/* add the package to the transaction */
trans->packages = alpm_list_add(trans->packages, dummy);
return(0);
}
int SYMHIDDEN _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
{
pmpkg_t *info = NULL;
@ -121,11 +72,6 @@ int SYMHIDDEN _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(name != NULL && strlen(name) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
/* Check if we need to add a fake target to the transaction. */
if(strchr(name, '|')) {
return(add_faketarget(trans, name));
}
_alpm_log(PM_LOG_DEBUG, _("loading target '%s'"), name);
/* TODO FS#5120 we need a better way to check if a package is a valid package,

View File

@ -330,7 +330,7 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
* @param name of the package
* @return the package entry on success, NULL on error
*/
pmpkg_t SYMEXPORT *alpm_db_readpkg(pmdb_t *db, char *name)
pmpkg_t SYMEXPORT *alpm_db_get_pkg(pmdb_t *db, const char *name)
{
ALPM_LOG_FUNC;
@ -362,7 +362,7 @@ alpm_list_t SYMEXPORT *alpm_db_getpkgcache(pmdb_t *db)
* @param name name of the package
* @return the list of packages on success, NULL on error
*/
alpm_list_t SYMEXPORT *alpm_db_whatprovides(pmdb_t *db, char *name)
alpm_list_t SYMEXPORT *alpm_db_whatprovides(pmdb_t *db, const char *name)
{
ALPM_LOG_FUNC;
@ -379,7 +379,7 @@ alpm_list_t SYMEXPORT *alpm_db_whatprovides(pmdb_t *db, char *name)
* @param name of the group
* @return the groups entry on success, NULL on error
*/
pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, char *name)
pmgrp_t SYMEXPORT *alpm_db_readgrp(pmdb_t *db, const char *name)
{
ALPM_LOG_FUNC;
@ -1153,7 +1153,7 @@ alpm_list_t *alpm_get_upgrades()
for(j = syncpkgs; j && !replace; j=j->next) {
sync = j->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) {
if(_alpm_pkg_isin(spkg->name, sync->data)) {
if(_alpm_pkg_find(spkg->name, sync->data)) {
replace=1;
}
}

View File

@ -161,7 +161,7 @@ alpm_list_t *alpm_option_get_syncdbs();
*/
/* Database registration callback */
typedef void (*alpm_cb_db_register)(char *, pmdb_t *);
typedef void (*alpm_cb_db_register)(const char *, pmdb_t *);
pmdb_t *alpm_db_register(char *treename);
int alpm_db_unregister(pmdb_t *db);
@ -173,11 +173,11 @@ int alpm_db_setserver(pmdb_t *db, const char *url);
int alpm_db_update(int level, pmdb_t *db);
pmpkg_t *alpm_db_readpkg(pmdb_t *db, char *name);
pmpkg_t *alpm_db_get_pkg(pmdb_t *db, const char *name);
alpm_list_t *alpm_db_getpkgcache(pmdb_t *db);
alpm_list_t *alpm_db_whatprovides(pmdb_t *db, char *name);
alpm_list_t *alpm_db_whatprovides(pmdb_t *db, const char *name);
pmgrp_t *alpm_db_readgrp(pmdb_t *db, char *name);
pmgrp_t *alpm_db_readgrp(pmdb_t *db, const char *name);
alpm_list_t *alpm_db_getgrpcache(pmdb_t *db);
alpm_list_t *alpm_db_search(pmdb_t *db, alpm_list_t* needles);
@ -242,7 +242,7 @@ unsigned short alpm_pkg_has_scriptlet(pmpkg_t *pkg);
* Groups
*/
const char *alpm_grp_get_name(pmgrp_t *grp);
alpm_list_t *alpm_grp_get_packages(pmgrp_t *grp);
alpm_list_t *alpm_grp_get_pkgs(pmgrp_t *grp);
/*
* Sync
@ -256,7 +256,7 @@ typedef enum _pmsynctype_t {
} pmsynctype_t;
pmsynctype_t alpm_sync_get_type(pmsyncpkg_t *sync);
pmpkg_t *alpm_sync_get_package(pmsyncpkg_t *sync);
pmpkg_t *alpm_sync_get_pkg(pmsyncpkg_t *sync);
void *alpm_sync_get_data(pmsyncpkg_t *sync);
/*
@ -348,7 +348,7 @@ typedef void (*alpm_trans_cb_progress)(pmtransprog_t, char *, int, int, int);
pmtranstype_t alpm_trans_get_type();
unsigned int alpm_trans_get_flags();
alpm_list_t * alpm_trans_get_targets();
alpm_list_t * alpm_trans_get_packages();
alpm_list_t * alpm_trans_get_pkgs();
int alpm_trans_init(pmtranstype_t type, unsigned int flags,
alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress cb_progress);

View File

@ -106,7 +106,7 @@ void _alpm_db_rewind(pmdb_t *db)
rewinddir(db->handle);
}
pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, pmdbinfrq_t inforeq)
pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target, pmdbinfrq_t inforeq)
{
struct dirent *ent = NULL;
struct stat sbuf;

View File

@ -187,7 +187,7 @@ int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
return(0);
}
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, char *target)
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target)
{
ALPM_LOG_FUNC;
@ -201,7 +201,7 @@ pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, char *target)
return(NULL);
}
return(_alpm_pkg_isin(target, pkgcache));
return(_alpm_pkg_find(target, pkgcache));
}
/* Returns a new group cache from db.
@ -286,7 +286,7 @@ alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db)
return(db->grpcache);
}
pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, char *target)
pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target)
{
alpm_list_t *i;

View File

@ -33,12 +33,12 @@ int _alpm_db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg);
int _alpm_db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg);
alpm_list_t *_alpm_db_get_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel);
int _alpm_db_ensure_pkgcache(pmdb_t *db, pmdbinfrq_t infolevel);
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, char *target);
pmpkg_t *_alpm_db_get_pkgfromcache(pmdb_t *db, const char *target);
/* groups */
int _alpm_db_load_grpcache(pmdb_t *db);
void _alpm_db_free_grpcache(pmdb_t *db);
alpm_list_t *_alpm_db_get_grpcache(pmdb_t *db);
pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, char *target);
pmgrp_t *_alpm_db_get_grpfromcache(pmdb_t *db, const char *target);
#endif /* _ALPM_CACHE_H */

View File

@ -51,7 +51,7 @@
#include "cache.h"
#include "alpm.h"
pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename)
{
pmdb_t *db;
@ -150,7 +150,7 @@ alpm_list_t *_alpm_db_search(pmdb_t *db, alpm_list_t *needles)
return(ret);
}
pmdb_t *_alpm_db_register(char *treename, alpm_cb_db_register callback)
pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
{
struct stat buf;
pmdb_t *db;

View File

@ -47,18 +47,18 @@ struct __pmdb_t {
};
/* db.c, database general calls */
pmdb_t *_alpm_db_new(char *root, char *dbpath, char *treename);
pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename);
void _alpm_db_free(void *data);
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(char *treename, alpm_cb_db_register callback);
pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback);
/* be.c, backend specific calls */
int _alpm_db_install(pmdb_t *db, const char *dbfile);
int _alpm_db_open(pmdb_t *db);
void _alpm_db_close(pmdb_t *db);
void _alpm_db_rewind(pmdb_t *db);
pmpkg_t *_alpm_db_scan(pmdb_t *db, char *target, pmdbinfrq_t inforeq);
pmpkg_t *_alpm_db_scan(pmdb_t *db, const char *target, pmdbinfrq_t inforeq);
int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
int _alpm_db_write(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq);
int _alpm_db_remove(pmdb_t *db, pmpkg_t *info);

View File

@ -150,7 +150,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
for(k = i->next; k; k = k->next) {
q = (pmpkg_t *)k->data;
if(!strcmp(dep.name, q->name)) {
if(!_alpm_pkg_isin(q->name, tmptargs)) {
if(!_alpm_pkg_find(q->name, tmptargs)) {
change = 1;
tmptargs = alpm_list_add(tmptargs, q);
}
@ -158,7 +158,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
}
for(l = q->provides; l; l = l->next) {
if(!strcmp(dep.name, (char*)l->data)) {
if(!_alpm_pkg_isin((char*)l->data, tmptargs)) {
if(!_alpm_pkg_find((char*)l->data, tmptargs)) {
change = 1;
tmptargs = alpm_list_add(tmptargs, q);
}
@ -167,7 +167,7 @@ alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode)
}
}
}
if(!_alpm_pkg_isin(p->name, tmptargs)) {
if(!_alpm_pkg_find(p->name, tmptargs)) {
tmptargs = alpm_list_add(tmptargs, p);
}
}
@ -231,7 +231,7 @@ alpm_list_t *_alpm_checkdeps(pmtrans_t *trans, pmdb_t *db, pmtranstype_t op,
/* hmmm... package isn't installed.. */
continue;
}
if(_alpm_pkg_isin(p->name, packages)) {
if(_alpm_pkg_find(p->name, packages)) {
/* this package also in the upgrade list, so don't worry about it */
continue;
}
@ -443,7 +443,7 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets)
{
alpm_list_t *i;
if(_alpm_pkg_isin(pkg->name, targets)) {
if(_alpm_pkg_find(pkg->name, targets)) {
return(0);
}
@ -456,7 +456,7 @@ static int can_remove_package(pmdb_t *db, pmpkg_t *pkg, alpm_list_t *targets)
/* see if other packages need it */
for(i = alpm_pkg_get_requiredby(pkg); i; i = i->next) {
pmpkg_t *reqpkg = _alpm_db_get_pkgfromcache(db, i->data);
if(reqpkg && !_alpm_pkg_isin(reqpkg->name, targets)) {
if(reqpkg && !_alpm_pkg_find(reqpkg->name, targets)) {
return(0);
}
}
@ -606,14 +606,14 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *syncpkg,
pm_errno = PM_ERR_UNSATISFIED_DEPS;
goto error;
}
if(_alpm_pkg_isin(sync->name, list)) {
if(_alpm_pkg_find(sync->name, list)) {
/* this dep is already in the target list */
_alpm_log(PM_LOG_DEBUG, _("dependency %s is already in the target list -- skipping"),
sync->name);
continue;
}
if(!_alpm_pkg_isin(sync->name, trail)) {
if(!_alpm_pkg_find(sync->name, trail)) {
/* check pmo_ignorepkg and pmo_s_ignore to make sure we haven't pulled in
* something we're not supposed to.
*/

View File

@ -84,7 +84,7 @@ const char SYMEXPORT *alpm_grp_get_name(pmgrp_t *grp)
return grp->name;
}
alpm_list_t SYMEXPORT *alpm_grp_get_packages(pmgrp_t *grp)
alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(pmgrp_t *grp)
{
ALPM_LOG_FUNC;

View File

@ -182,12 +182,12 @@ int _alpm_pkg_cmp(const void *p1, const void *p2)
* Returns: 0 on success, 1 on error
*
*/
static int parse_descfile(char *descfile, pmpkg_t *info)
static int parse_descfile(const char *descfile, pmpkg_t *info)
{
FILE* fp = NULL;
char line[PATH_MAX];
char* ptr = NULL;
char* key = NULL;
char *ptr = NULL;
char *key = NULL;
int linenum = 0;
ALPM_LOG_FUNC;
@ -278,7 +278,7 @@ static int parse_descfile(char *descfile, pmpkg_t *info)
return(0);
}
pmpkg_t *_alpm_pkg_load(char *pkgfile)
pmpkg_t *_alpm_pkg_load(const char *pkgfile)
{
char *expath;
int ret = ARCHIVE_OK;
@ -453,7 +453,7 @@ error:
/* Test for existence of a package in a alpm_list_t*
* of pmpkg_t*
*/
pmpkg_t *_alpm_pkg_isin(char *needle, alpm_list_t *haystack)
pmpkg_t *_alpm_pkg_find(const char *needle, alpm_list_t *haystack)
{
alpm_list_t *lp;
@ -473,9 +473,10 @@ pmpkg_t *_alpm_pkg_isin(char *needle, alpm_list_t *haystack)
return(NULL);
}
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
int _alpm_pkg_splitname(const char *target, char *name, char *version, int witharch)
{
char tmp[PKG_FULLNAME_LEN+7];
const char *t;
char *p, *q;
ALPM_LOG_FUNC;
@ -485,12 +486,12 @@ int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch)
}
/* trim path name (if any) */
if((p = strrchr(target, '/')) == NULL) {
p = target;
if((t = strrchr(target, '/')) == NULL) {
t = target;
} else {
p++;
t++;
}
STRNCPY(tmp, p, PKG_FULLNAME_LEN+7);
STRNCPY(tmp, t, PKG_FULLNAME_LEN+7);
/* trim file extension (if any) */
if((p = strstr(tmp, PM_EXT_PKG))) {
*p = '\0';

View File

@ -103,9 +103,9 @@ pmpkg_t *_alpm_pkg_dup(pmpkg_t *pkg);
void _alpm_pkg_free(void *data);
int _alpm_pkg_cmp(const void *p1, const void *p2);
int alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg);
pmpkg_t *_alpm_pkg_load(char *pkgfile);
pmpkg_t *_alpm_pkg_isin(char *needle, alpm_list_t *haystack);
int _alpm_pkg_splitname(char *target, char *name, char *version, int witharch);
pmpkg_t *_alpm_pkg_load(const char *pkgfile);
pmpkg_t *_alpm_pkg_find(const char *needle, alpm_list_t *haystack);
int _alpm_pkg_splitname(const char *target, char *name, char *version, int witharch);
int _alpm_pkg_istoonew(pmpkg_t *pkg);
void _alpm_pkg_update_requiredby(pmpkg_t *pkg);

View File

@ -31,7 +31,7 @@
/* return a alpm_list_t of packages in "db" that provide "package"
*/
alpm_list_t *_alpm_db_whatprovides(pmdb_t *db, char *package)
alpm_list_t *_alpm_db_whatprovides(pmdb_t *db, const char *package)
{
alpm_list_t *pkgs = NULL;
alpm_list_t *lp;

View File

@ -25,7 +25,7 @@
#include "alpm_list.h"
#include "config.h"
alpm_list_t *_alpm_db_whatprovides(pmdb_t *db, char *package);
alpm_list_t *_alpm_db_whatprovides(pmdb_t *db, const char *package);
#endif /* _ALPM_PROVIDE_H */

View File

@ -69,7 +69,7 @@ int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
if(_alpm_pkg_isin(name, trans->packages)) {
if(_alpm_pkg_find(name, trans->packages)) {
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}

View File

@ -221,7 +221,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
for(j = trans->packages; j && !replace; j=j->next) {
sync = j->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) {
if(_alpm_pkg_isin(spkg->name, sync->data)) {
if(_alpm_pkg_find(spkg->name, sync->data)) {
replace=1;
}
}
@ -501,7 +501,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
for(j = trans->packages; j && !found; j = j->next) {
sync = j->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) {
if(_alpm_pkg_isin(miss->depend.name, sync->data)) {
if(_alpm_pkg_find(miss->depend.name, sync->data)) {
found = 1;
}
}
@ -929,7 +929,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
alpm_list_t *j;
for(j = sync->data; j; j = j->next) {
pmpkg_t *pkg = j->data;
if(!_alpm_pkg_isin(pkg->name, tr->packages)) {
if(!_alpm_pkg_find(pkg->name, tr->packages)) {
if(_alpm_trans_addtarget(tr, pkg->name) == -1) {
goto error;
}
@ -1072,7 +1072,7 @@ pmsynctype_t SYMEXPORT alpm_sync_get_type(pmsyncpkg_t *sync)
return sync->type;
}
pmpkg_t SYMEXPORT *alpm_sync_get_package(pmsyncpkg_t *sync)
pmpkg_t SYMEXPORT *alpm_sync_get_pkg(pmsyncpkg_t *sync)
{
/* Sanity checks */
ASSERT(sync != NULL, return(NULL));

View File

@ -270,7 +270,7 @@ int _alpm_trans_update_depends(pmtrans_t *trans, pmpkg_t *pkg)
}
if(trans->packages && trans->type == PM_TRANS_TYPE_REMOVE) {
if(_alpm_pkg_isin(dep.name, handle->trans->packages)) {
if(_alpm_pkg_find(dep.name, handle->trans->packages)) {
continue;
}
}
@ -364,7 +364,7 @@ alpm_list_t * alpm_trans_get_targets()
return handle->trans->targets;
}
alpm_list_t SYMEXPORT * alpm_trans_get_packages()
alpm_list_t SYMEXPORT * alpm_trans_get_pkgs()
{
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));