rpmdb.c   rpmdb.c 
skipping to change at line 29 skipping to change at line 29
#define _RPMBF_INTERNAL #define _RPMBF_INTERNAL
#include <rpmbf.h> #include <rpmbf.h>
#include <rpmtypes.h> #include <rpmtypes.h>
#define _RPMTAG_INTERNAL #define _RPMTAG_INTERNAL
#include "header_internal.h" /* XXX for HEADERFLAG_MAPPED */ #include "header_internal.h" /* XXX for HEADERFLAG_MAPPED */
#define _RPMDB_INTERNAL #define _RPMDB_INTERNAL
#include "rpmdb.h" #include "rpmdb.h"
#include "pkgio.h" #include "pkgio.h"
#include "fprint.h" #include "fprint.h"
#include "legacy.h" #include "legacy.h"
#include "debug.h" #include "debug.h"
#if defined(__LCLINT__) #if defined(__LCLINT__)
#define UINT32_T u_int32_t #define UINT32_T u_int32_t
#else #else
#define UINT32_T rpmuint32_t #define UINT32_T rpmuint32_t
skipping to change at line 53 skipping to change at line 54
typedef rpmuint32_t u_int32_t; typedef rpmuint32_t u_int32_t;
#endif #endif
/*@access dbiIndexSet@*/ /*@access dbiIndexSet@*/
/*@access dbiIndexItem@*/ /*@access dbiIndexItem@*/
/*@access miRE@*/ /*@access miRE@*/
/*@access Header@*/ /* XXX compared with NULL */ /*@access Header@*/ /* XXX compared with NULL */
/*@access rpmmi@*/ /*@access rpmmi@*/
/*@access rpmts@*/ /* XXX compared with NULL */ /*@access rpmts@*/ /* XXX compared with NULL */
#ifdef __cplusplus
GENfree(dbiIndex *)
GENfree(dbiIndexSet)
GENfree(dbiIndexItem)
#endif /* __cplusplus */
/*@unchecked@*/ /*@unchecked@*/
int _rpmdb_debug = 0; int _rpmdb_debug = 0;
/*@unchecked@*/ /*@unchecked@*/
int _rpmmi_debug = 0; int _rpmmi_debug = 0;
#define _DBI_FLAGS 0 #define _DBI_FLAGS 0
#define _DBI_PERMS 0644 #define _DBI_PERMS 0644
#define _DBI_MAJOR -1 #define _DBI_MAJOR -1
skipping to change at line 114 skipping to change at line 121
if (!(dbiTagStr && *dbiTagStr)) { if (!(dbiTagStr && *dbiTagStr)) {
dbiTagStr = _free(dbiTagStr); dbiTagStr = _free(dbiTagStr);
dbiTagStr = xstrdup(_dbiTagStr_default); dbiTagStr = xstrdup(_dbiTagStr_default);
} }
#ifdef NOISY #ifdef NOISY
if (_rpmdb_debug) if (_rpmdb_debug)
fprintf(stderr, "--> %s(%p, %p) dbiTagStr %s\n", __FUNCTION__, dbiTagsP, db iNTagsP, dbiTagStr); fprintf(stderr, "--> %s(%p, %p) dbiTagStr %s\n", __FUNCTION__, dbiTagsP, db iNTagsP, dbiTagStr);
#endif #endif
/* Always allocate package index */ /* Always allocate package index */
dbiTags = xcalloc(1, sizeof(*dbiTags)); dbiTags = (tagStore_t) xcalloc(1, sizeof(*dbiTags));
dbiTags[dbiNTags].str = xstrdup("Packages"); dbiTags[dbiNTags].str = xstrdup("Packages");
dbiTags[dbiNTags].tag = RPMDBI_PACKAGES; dbiTags[dbiNTags].tag = RPMDBI_PACKAGES;
dbiTags[dbiNTags].iob = NULL; dbiTags[dbiNTags].iob = NULL;
dbiNTags++; dbiNTags++;
for (o = dbiTagStr; o && *o; o = oe) { for (o = dbiTagStr; o && *o; o = oe) {
while (*o && xisspace((int)*o)) while (*o && xisspace((int)*o))
o++; o++;
if (*o == '\0') if (*o == '\0')
break; break;
skipping to change at line 146 skipping to change at line 153
if (dbiTags != NULL) if (dbiTags != NULL)
for (dbix = 0; dbix < dbiNTags; dbix++) { for (dbix = 0; dbix < dbiNTags; dbix++) {
if (tag == dbiTags[dbix].tag) { if (tag == dbiTags[dbix].tag) {
bingo = 1; bingo = 1;
/*@innerbreak@*/ break; /*@innerbreak@*/ break;
} }
} }
if (bingo) if (bingo)
continue; continue;
dbiTags = xrealloc(dbiTags, (dbiNTags + 1) * sizeof(*dbiTags)); dbiTags = (tagStore_t) xrealloc(dbiTags, (dbiNTags + 1) * sizeof(*db iTags));
dbiTags[dbiNTags].str = xstrdup(o); dbiTags[dbiNTags].str = xstrdup(o);
dbiTags[dbiNTags].tag = tag; dbiTags[dbiNTags].tag = tag;
dbiTags[dbiNTags].iob = NULL; dbiTags[dbiNTags].iob = NULL;
#ifdef NOISY #ifdef NOISY
if (_rpmdb_debug) { if (_rpmdb_debug) {
fprintf(stderr, "\t%u %s(", (unsigned)dbiNTags, o); fprintf(stderr, "\t%u %s(", (unsigned)dbiNTags, o);
if (tag & 0x40000000) if (tag & 0x40000000)
fprintf(stderr, "0x%x)\n", tag); fprintf(stderr, "0x%x)\n", tag);
else else
fprintf(stderr, "%d)\n", tag); fprintf(stderr, "%d)\n", tag);
skipping to change at line 187 skipping to change at line 194
/*@-exportheadervar -declundef @*/ /*@-exportheadervar -declundef @*/
/*@observer@*/ /*@unchecked@*/ /*@observer@*/ /*@unchecked@*/
extern struct _dbiVec db3vec; extern struct _dbiVec db3vec;
/*@=exportheadervar =declundef @*/ /*@=exportheadervar =declundef @*/
#define DB3vec &db3vec #define DB3vec &db3vec
/*@=redecl@*/ /*@=redecl@*/
#else #else
#define DB3vec NULL #define DB3vec NULL
#endif #endif
#ifdef HAVE_SQLITE3_H #if defined(HAVE_SQLITE3_H) /* XXX test --with-sqlite=external */
#define SQLITE_HACK
/*@-exportheadervar -declundef @*/ /*@-exportheadervar -declundef @*/
/*@observer@*/ /*@unchecked@*/ /*@observer@*/ /*@unchecked@*/
extern struct _dbiVec sqlitevec; extern struct _dbiVec sqlitevec;
/*@=exportheadervar =declundef @*/ /*@=exportheadervar =declundef @*/
#define SQLITEvec &sqlitevec #define SQLITEvec &sqlitevec
/*@=redecl@*/ /*@=redecl@*/
#else #else
#define SQLITEvec NULL #define SQLITEvec NULL
#endif #endif
skipping to change at line 295 skipping to change at line 301
/*@-redef@*/ /*@-redef@*/
union _dbswap { union _dbswap {
uint64_t ul; uint64_t ul;
uint32_t ui; uint32_t ui;
uint16_t us; uint16_t us;
uint8_t uc[8]; uint8_t uc[8];
}; };
/*@=redef@*/ /*@=redef@*/
/*@unchecked@*/ /*@unchecked@*/
static union _dbswap _endian = { .ui = 0x11223344 }; static union _dbswap _endian = { 0x11223344 };
static inline uint64_t _ntoh_ul(uint64_t ul) static inline uint64_t _ntoh_ul(uint64_t ul)
/*@*/ /*@*/
{ {
union _dbswap _a; union _dbswap _a;
_a.ul = ul; _a.ul = ul;
if (_endian.uc[0] == 0x44) { if (_endian.uc[0] == 0x44) {
uint8_t _b, *_c = _a.uc; \ uint8_t _b, *_c = _a.uc; \
_b = _c[7]; _c[7] = _c[0]; _c[0] = _b; \ _b = _c[7]; _c[7] = _c[0]; _c[0] = _b; \
_b = _c[6]; _c[6] = _c[1]; _c[1] = _b; \ _b = _c[6]; _c[6] = _c[1]; _c[1] = _b; \
skipping to change at line 362 skipping to change at line 368
typedef struct _setSwap_s { typedef struct _setSwap_s {
union _dbswap hdr; union _dbswap hdr;
union _dbswap tag; union _dbswap tag;
uint32_t fp; uint32_t fp;
} * setSwap; } * setSwap;
/* XXX assumes hdrNum is first int in dbiIndexItem */ /* XXX assumes hdrNum is first int in dbiIndexItem */
static int hdrNumCmp(const void * one, const void * two) static int hdrNumCmp(const void * one, const void * two)
/*@*/ /*@*/
{ {
const int * a = one, * b = two; const int * a = (const int *) one;
const int * b = (const int *) two;
return (*a - *b); return (*a - *b);
} }
/** /**
* Append element(s) to set of index database items. * Append element(s) to set of index database items.
* @param set set of index database items * @param set set of index database items
* @param recs array of items to append to set * @param recs array of items to append to set
* @param nrecs number of items * @param nrecs number of items
* @param recsize size of an array item * @param recsize size of an array item
* @param sortset should resulting set be sorted? * @param sortset should resulting set be sorted?
* @return 0 success, 1 failure (bad args) * @return 0 success, 1 failure (bad args)
*/ */
static int dbiAppendSet(dbiIndexSet set, const void * recs, static int dbiAppendSet(dbiIndexSet set, const void * recs,
int nrecs, size_t recsize, int sortset) int nrecs, size_t recsize, int sortset)
/*@modifies *set @*/ /*@modifies *set @*/
{ {
const char * rptr = recs; const char * rptr = (const char *) recs;
size_t rlen = (recsize < sizeof(*(set->recs))) size_t rlen = (recsize < sizeof(*(set->recs)))
? recsize : sizeof(*(set->recs)); ? recsize : sizeof(*(set->recs));
if (set == NULL || recs == NULL || nrecs <= 0 || recsize == 0) if (set == NULL || recs == NULL || nrecs <= 0 || recsize == 0)
return 1; return 1;
set->recs = xrealloc(set->recs, set->recs = (dbiIndexItem) xrealloc(set->recs,
(set->count + nrecs) * sizeof(*(set->recs))); (set->count + nrecs) * sizeof(*(set->recs)));
memset(set->recs + set->count, 0, nrecs * sizeof(*(set->recs))); memset(set->recs + set->count, 0, nrecs * sizeof(*(set->recs)));
while (nrecs-- > 0) { while (nrecs-- > 0) {
/*@-mayaliasunique@*/ /*@-mayaliasunique@*/
memcpy(set->recs + set->count, rptr, rlen); memcpy(set->recs + set->count, rptr, rlen);
/*@=mayaliasunique@*/ /*@=mayaliasunique@*/
rptr += recsize; rptr += recsize;
set->count++; set->count++;
skipping to change at line 457 skipping to change at line 464
int mi_modified; int mi_modified;
uint32_t mi_prevoffset; /* header instance (big endian) */ uint32_t mi_prevoffset; /* header instance (big endian) */
uint32_t mi_offset; /* header instance (big endian) */ uint32_t mi_offset; /* header instance (big endian) */
uint32_t mi_bntag; /* base name tag (native endian) */ uint32_t mi_bntag; /* base name tag (native endian) */
/*@refcounted@*/ /*@null@*/ /*@refcounted@*/ /*@null@*/
rpmbf mi_bf; /* Iterator instance Bloom filter. * / rpmbf mi_bf; /* Iterator instance Bloom filter. * /
int mi_nre; int mi_nre;
/*@only@*/ /*@null@*/ /*@only@*/ /*@null@*/
miRE mi_re; miRE mi_re;
#if defined(__LCLINT__)
/*@refs@*/
int nrefs; /*!< (unused) keep splint happy */
#endif
}; };
/*@unchecked@*/ /*@unchecked@*/
static rpmdb rpmdbRock; static rpmdb rpmdbRock;
/*@unchecked@*/ /*@exposed@*/ /*@null@*/ /*@unchecked@*/ /*@exposed@*/ /*@null@*/
static rpmmi rpmmiRock; static rpmmi rpmmiRock;
int rpmdbCheckTerminate(int terminate) int rpmdbCheckTerminate(int terminate)
/*@globals rpmdbRock, rpmmiRock @*/ /*@globals rpmdbRock, rpmmiRock @*/
skipping to change at line 584 skipping to change at line 595
/*@-modobserver@*/ /*@-modobserver@*/
str = headerSprintf(h, qfmt, NULL, headerCompoundFormats, &errstr); str = headerSprintf(h, qfmt, NULL, headerCompoundFormats, &errstr);
/*@=modobserver@*/ /*@=modobserver@*/
if (str == NULL) if (str == NULL)
rpmlog(RPMLOG_ERR, _("incorrect format: \"%s\": %s\n"), qfmt, errstr ); rpmlog(RPMLOG_ERR, _("incorrect format: \"%s\": %s\n"), qfmt, errstr );
return str; return str;
} }
/** /**
* Write added/removed header info. * Write added/removed header info into %{_hrmib_path}.
* @param db rpm database * @param db rpm database
* @param h header * @param h header
* @param adding adding an rpmdb header? * @param adding adding an rpmdb header?
* @return 0 on success * @return 0 on success
*/ */
static int rpmdbExportInfo(/*@unused@*/ rpmdb db, Header h, int adding) static int rpmdbExportHR_MIB(/*@unused@*/ rpmdb db, Header h, int adding)
/*@globals headerCompoundFormats, rpmGlobalMacroContext, h_errno, /*@globals headerCompoundFormats, rpmGlobalMacroContext, h_errno,
fileSystem, internalState @*/ fileSystem, internalState @*/
/*@modifies h, rpmGlobalMacroContext, /*@modifies h, rpmGlobalMacroContext,
fileSystem, internalState @*/ fileSystem, internalState @*/
{ {
static int oneshot; static int oneshot;
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
const char * fn = NULL; const char * fn = NULL;
int rc = -1;
int xx; int xx;
{ const char * fnfmt = rpmGetPath("%{?_hrmib_path}", NULL); { const char * fnfmt = rpmGetPath("%{?_hrmib_path}", NULL);
if (fnfmt && *fnfmt) if (fnfmt && *fnfmt)
fn = queryHeader(h, fnfmt); fn = queryHeader(h, fnfmt);
fnfmt = _free(fnfmt); fnfmt = _free(fnfmt);
} }
if (fn == NULL) if (fn == NULL)
goto exit; goto exit;
skipping to change at line 646 skipping to change at line 658
stamp.modtime = he->p.ui32p[0]; stamp.modtime = he->p.ui32p[0];
if (!Utime(fn, &stamp)) if (!Utime(fn, &stamp))
rpmlog(RPMLOG_DEBUG, " +++ %s\n", fn); rpmlog(RPMLOG_DEBUG, " +++ %s\n", fn);
} }
he->p.ptr = _free(he->p.ptr); he->p.ptr = _free(he->p.ptr);
} }
} else { } else {
if (!Unlink(fn)) if (!Unlink(fn))
rpmlog(RPMLOG_DEBUG, " --- %s\n", fn); rpmlog(RPMLOG_DEBUG, " --- %s\n", fn);
} }
rc = 0;
exit: exit:
fn = _free(fn); fn = _free(fn);
return 0; return rc;
}
static const char l10n_sql_init[] = "\
CREATE TABLE IF NOT EXISTS l10n (\n\
k TEXT UNIQUE PRIMARY KEY NOT NULL,\n\
v TEXT NOT NULL\n\
);\n\
";
static const char l10n_sql_qfmt[] =
#include "wdj_l10n_sqlite"
;
/**
* Update added header info into %{__l10ndir} sqlite3 database.
* @param db rpm database
* @param h header
* @param adding adding an rpmdb header?
* @return 0 on success
*/
static int rpmdbExportL10N_SQL(/*@unused@*/ rpmdb db, Header h, int adding)
/*@globals headerCompoundFormats, rpmGlobalMacroContext, h_errno,
fileSystem, internalState @*/
/*@modifies h, rpmGlobalMacroContext,
fileSystem, internalState @*/
{
static int oneshot;
char * fn = NULL;
char * t = NULL;
int rc = 0; /* XXX errors? */
/* If directory isn't configured, don't bother. */
fn = rpmGetPath("%{?__l10ndir:%{__l10ndir}/sqldb}", NULL);
if (!(fn && *fn)) {
oneshot = -1;
goto exit;
}
/* Lazily create the directory in chroot's if configured. */
if (!oneshot) {
char * _fn = xstrdup(fn);
char * dn = dirname(_fn);
static mode_t _mode = 0755;
static uid_t _uid = 0;
static gid_t _gid = 0;
/* If not a directory, then disable, else don't retry. */
errno = 0;
oneshot = (rpmioMkpath(dn, _mode, _uid, _gid) ? -1 : 1);
_fn = _free(_fn);
if (oneshot > 0) {
t = rpmExpand("%{sql -echo ", fn, ":\n", l10n_sql_init, "}", NUL
L);
t = _free(t);
}
}
/* If directory is AWOL, don't bother. */
if (oneshot < 0)
goto exit;
if (adding) {
/* XXX macro expand before headerSprintf? */
/* XXX skip gpg(...)? */
const char * SQL = queryHeader(h, (char *)l10n_sql_qfmt);
t = rpmExpand("%{sql -echo ", fn, ":\n",
"BEGIN TRANSACTION;\n",
SQL,
"COMMIT TRANSACTION;\n",
"}", NULL);
t = _free(t);
SQL = _free(SQL);
} else
assert(0); /* XXX remove on erase? */
exit:
t = _free(t);
fn = _free(fn);
return rc;
}
/**
* Write added/removed header info.
* @param db rpm database
* @param h header
* @param adding adding an rpmdb header?
* @return 0 on success
*/
static int rpmdbExportInfo(/*@unused@*/ rpmdb db, Header h, int adding)
/*@globals headerCompoundFormats, rpmGlobalMacroContext, h_errno,
fileSystem, internalState @*/
/*@modifies h, rpmGlobalMacroContext,
fileSystem, internalState @*/
{
int rc = 0;
int xx;
/* Add/remove stamp file in %{?_hrmib_path} (if configured). */
xx = rpmdbExportHR_MIB(db, h, adding);
/* Add localization %{?__l10ndir} sqlite3 database (if configured). */
if (adding)
xx = rpmdbExportL10N_SQL(db, h, adding);
(void)xx;
return rc;
} }
/*@unchecked@*/ /*@only@*/ /*@null@*/ /*@unchecked@*/ /*@only@*/ /*@null@*/
rpmioPool _rpmdbPool; rpmioPool _rpmdbPool;
static rpmdb rpmdbGetPool(/*@null@*/ rpmioPool pool) static rpmdb rpmdbGetPool(/*@null@*/ rpmioPool pool)
/*@globals _rpmdbPool, fileSystem @*/ /*@globals _rpmdbPool, fileSystem @*/
/*@modifies pool, _rpmdbPool, fileSystem @*/ /*@modifies pool, _rpmdbPool, fileSystem @*/
{ {
rpmdb db; rpmdb db;
skipping to change at line 717 skipping to change at line 833
rpmTag tagn = (rpmTag)(tag >= 0 ? tag : -tag); rpmTag tagn = (rpmTag)(tag >= 0 ? tag : -tag);
size_t dbix; size_t dbix;
if (db == NULL || db->_dbi == NULL) if (db == NULL || db->_dbi == NULL)
return 0; return 0;
if (db->db_tags != NULL) if (db->db_tags != NULL)
for (dbix = 0; dbix < db->db_ndbi; dbix++) { for (dbix = 0; dbix < db->db_ndbi; dbix++) {
if (db->db_tags[dbix].tag != tagn) if (db->db_tags[dbix].tag != tagn)
continue; continue;
db->db_tags[dbix].tag = tag; db->db_tags[dbix].tag = (rpmTag) tag;
return 0; return 0;
} }
return 0; return 0;
} }
int rpmdbCloseDBI(rpmdb db, int tag) int rpmdbCloseDBI(rpmdb db, int tag)
{ {
size_t dbix; size_t dbix;
int rc = 0; int rc = 0;
skipping to change at line 917 skipping to change at line 1033
rpmlog(RPMLOG_ERR, _("no dbpath has been set\n")); rpmlog(RPMLOG_ERR, _("no dbpath has been set\n"));
db->db_root = _free(db->db_root); db->db_root = _free(db->db_root);
db->db_home = _free(db->db_home); db->db_home = _free(db->db_home);
db = (rpmdb) rpmioPutPool((rpmioItem)db); db = (rpmdb) rpmioPutPool((rpmioItem)db);
/*@-globstate@*/ return NULL; /*@=globstate@*/ /*@-globstate@*/ return NULL; /*@=globstate@*/
} }
db->db_flags = (flags >= 0) ? flags : _DB_FLAGS; db->db_flags = (flags >= 0) ? flags : _DB_FLAGS;
db->db_mode = (mode >= 0) ? mode : _DB_MODE; db->db_mode = (mode >= 0) ? mode : _DB_MODE;
db->db_perms = (perms > 0) ? perms : _DB_PERMS; db->db_perms = (perms > 0) ? perms : _DB_PERMS;
#if defined(WITH_DB)
db->db_api = _DB_MAJOR; db->db_api = _DB_MAJOR;
#else
/* XXX FIXME: hotwired sqlite3 if %_dbapi isn't defined */
db->db_api = rpmExpandNumeric("%{?_dbapi}%{!?_dbapi:4}");
#endif
db->db_errpfx = rpmExpand( (epfx && *epfx ? epfx : _DB_ERRPFX), NULL); db->db_errpfx = rpmExpand( (epfx && *epfx ? epfx : _DB_ERRPFX), NULL);
db->db_remove_env = 0; db->db_remove_env = 0;
db->db_chrootDone = 0; db->db_chrootDone = 0;
db->db_maxkey = 0; db->db_maxkey = 0;
db->db_errcall = NULL; db->db_errcall = NULL;
db->db_errfile = NULL; db->db_errfile = NULL;
db->db_malloc = NULL; db->db_malloc = NULL;
db->db_realloc = NULL; db->db_realloc = NULL;
db->db_free = NULL; db->db_free = NULL;
skipping to change at line 940 skipping to change at line 1061
db->db_next = NULL; db->db_next = NULL;
db->db_opens = 0; db->db_opens = 0;
db->db_dbenv = NULL; db->db_dbenv = NULL;
db->db_txn = NULL; db->db_txn = NULL;
db->db_logc = NULL; db->db_logc = NULL;
db->db_mpf = NULL; db->db_mpf = NULL;
dbiTagsInit(&db->db_tags, &db->db_ndbi); dbiTagsInit(&db->db_tags, &db->db_ndbi);
db->_dbi = xcalloc(db->db_ndbi, sizeof(*db->_dbi)); db->_dbi = (dbiIndex *) xcalloc(db->db_ndbi, sizeof(*db->_dbi));
memset(&db->db_getops, 0, sizeof(db->db_getops)); memset(&db->db_getops, 0, sizeof(db->db_getops));
memset(&db->db_putops, 0, sizeof(db->db_putops)); memset(&db->db_putops, 0, sizeof(db->db_putops));
memset(&db->db_delops, 0, sizeof(db->db_delops)); memset(&db->db_delops, 0, sizeof(db->db_delops));
/*@-globstate@*/ /*@-globstate@*/
return rpmdbLink(db, __FUNCTION__); return (rpmdb) rpmdbLink(db, __FUNCTION__);
/*@=globstate@*/ /*@=globstate@*/
} }
/*@=exportheader =globs =mods @*/ /*@=exportheader =globs =mods @*/
static int rpmdbOpenDatabase(/*@null@*/ const char * prefix, static int rpmdbOpenDatabase(/*@null@*/ const char * prefix,
/*@null@*/ const char * dbpath, /*@null@*/ const char * dbpath,
int _dbapi, /*@null@*/ /*@out@*/ rpmdb *dbp, int _dbapi, /*@null@*/ /*@out@*/ rpmdb *dbp,
int mode, mode_t perms, int flags) int mode, mode_t perms, int flags)
/*@globals rpmdbRock, rpmGlobalMacroContext, h_errno, /*@globals rpmdbRock, rpmGlobalMacroContext, h_errno,
fileSystem, internalState @*/ fileSystem, internalState @*/
skipping to change at line 1056 skipping to change at line 1177
/*@i@*/ *dbp = db; /*@i@*/ *dbp = db;
/*@=assignexpose =newreftrans@*/ /*@=assignexpose =newreftrans@*/
} }
return rc; return rc;
} }
/* XXX python/rpmmodule.c */ /* XXX python/rpmmodule.c */
int rpmdbOpen (const char * prefix, rpmdb *dbp, int mode, mode_t perms) int rpmdbOpen (const char * prefix, rpmdb *dbp, int mode, mode_t perms)
{ {
int _dbapi = rpmExpandNumeric("%{?_dbapi}"); int _dbapi;
#if defined(WITH_DB)
_dbapi = _DB_MAJOR;
#elif defined(WITH_SQLITE)
_dbapi = 4; /* XXX FIXME: hotwired sqlite3 */
#else
_dbapi = rpmExpandNumeric("%{?_dbapi}");
#endif
return rpmdbOpenDatabase(prefix, NULL, _dbapi, dbp, mode, perms, 0); return rpmdbOpenDatabase(prefix, NULL, _dbapi, dbp, mode, perms, 0);
} }
int rpmdbCount(rpmdb db, rpmTag tag, const void * keyp, size_t keylen) int rpmdbCount(rpmdb db, rpmTag tag, const void * keyp, size_t keylen)
{ {
unsigned int count = 0; unsigned int count = 0;
DBC * dbcursor = NULL; DBC * dbcursor = NULL;
DBT k = DBT_INIT; DBT k = DBT_INIT;
DBT v = DBT_INIT; DBT v = DBT_INIT;
dbiIndex dbi; dbiIndex dbi;
skipping to change at line 1078 skipping to change at line 1206
int xx; int xx;
if (db == NULL || keyp == NULL) if (db == NULL || keyp == NULL)
return 0; return 0;
dbi = dbiOpen(db, tag, 0); dbi = dbiOpen(db, tag, 0);
if (dbi == NULL) if (dbi == NULL)
return 0; return 0;
if (keylen == 0) if (keylen == 0)
keylen = strlen(keyp); keylen = strlen((char *)keyp);
/*@-temptrans@*/ /*@-temptrans@*/
k.data = (void *) keyp; k.data = (void *) keyp;
/*@=temptrans@*/ /*@=temptrans@*/
k.size = (UINT32_T) keylen; k.size = (UINT32_T) keylen;
xx = dbiCopen(dbi, dbiTxnid(dbi), &dbcursor, 0); xx = dbiCopen(dbi, dbiTxnid(dbi), &dbcursor, 0);
rc = dbiGet(dbi, dbcursor, &k, &v, DB_SET); rc = dbiGet(dbi, dbcursor, &k, &v, DB_SET);
switch (rc) { switch (rc) {
case 0: case 0:
skipping to change at line 1166 skipping to change at line 1294
const char * se; const char * se;
char * t; char * t;
char * te; char * te;
/* Find the PCRE pattern length, including escapes. */ /* Find the PCRE pattern length, including escapes. */
for (se = s; *se != '\0'; se++, nt++) for (se = s; *se != '\0'; se++, nt++)
if (strchr(_REchars, *se)) nt++; if (strchr(_REchars, *se)) nt++;
nt += strlen(_pre) + strlen(_post); nt += strlen(_pre) + strlen(_post);
/* Build the PCRE pattern, escaping characters as needed. */ /* Build the PCRE pattern, escaping characters as needed. */
te = t = xmalloc(nt + 1); te = t = (char *) xmalloc(nt + 1);
te = stpcpy(te, _pre); te = stpcpy(te, _pre);
for (se = s; *se != '\0'; *te++ = *se++) for (se = s; *se != '\0'; *te++ = *se++)
if (strchr(_REchars, *se)) *te++ = '\\'; if (strchr(_REchars, *se)) *te++ = '\\';
te = stpcpy(te, _post); te = stpcpy(te, _post);
*te = '\0'; *te = '\0';
/*@-dependenttrans@*/ /*@-dependenttrans@*/
return t; return t;
/*@=dependenttrans@*/ /*@=dependenttrans@*/
} }
skipping to change at line 1242 skipping to change at line 1370
/* If partial match on stem won't help, just iterate. */ /* If partial match on stem won't help, just iterate. */
nb = stemEnd(pat) - pat; nb = stemEnd(pat) - pat;
if (nb == 0) { if (nb == 0) {
k.doff = 0; k.doff = 0;
goto doit; goto doit;
} }
/* Remove the escapes in the stem. */ /* Remove the escapes in the stem. */
{ char *be; { char *be;
b = be = xmalloc(nb + 1); b = be = (char *) xmalloc(nb + 1);
while (nb--) { while (nb--) {
if ((*be = *pat++) != '\\') if ((*be = *pat++) != '\\')
be++; be++;
} }
*be = '\0'; *be = '\0';
} }
nb = strlen(b); nb = strlen(b);
/* Set stem length for partial match retrieve. */ /* Set stem length for partial match retrieve. */
k.flags = DB_DBT_PARTIAL; k.flags = DB_DBT_PARTIAL;
skipping to change at line 1307 skipping to change at line 1435
if (mire && mireRegexec(mire, s, ns) < 0) if (mire && mireRegexec(mire, s, ns) < 0)
continue; continue;
/* Get a native endian copy of the primary package key. */ /* Get a native endian copy of the primary package key. */
memcpy(&hdrNum, p.data, sizeof(hdrNum)); memcpy(&hdrNum, p.data, sizeof(hdrNum));
hdrNum = _ntoh_ui(hdrNum); hdrNum = _ntoh_ui(hdrNum);
/* Collect primary keys. */ /* Collect primary keys. */
if (matches) { if (matches) {
if (set == NULL) if (set == NULL)
set = xcalloc(1, sizeof(*set)); set = (dbiIndexSet) xcalloc(1, sizeof(*set));
/* XXX TODO: sort/uniqify set? */ /* XXX TODO: sort/uniqify set? */
(void) dbiAppendSet(set, &hdrNum, 1, sizeof(hdrNum), 0); (void) dbiAppendSet(set, &hdrNum, 1, sizeof(hdrNum), 0);
} }
/* Collect secondary keys. */ /* Collect secondary keys. */
if (argvp) { if (argvp) {
char * a = memcpy(xmalloc(ns+1), s, ns); char * a = (char *) memcpy(xmalloc(ns+1), s, ns);
a[ns] = '\0'; a[ns] = '\0';
xx = argvAdd(&av, a); xx = argvAdd(&av, a);
a = _free(a); a = _free(a);
} }
} }
xx = dbiCclose(dbi, dbcursor, 0); xx = dbiCclose(dbi, dbcursor, 0);
dbcursor = NULL; dbcursor = NULL;
switch (rc) { switch (rc) {
skipping to change at line 1385 skipping to change at line 1513
assert(mi->mi_rpmtag == _tag); assert(mi->mi_rpmtag == _tag);
#endif #endif
/* Retrieve set of headers that contain the base name. */ /* Retrieve set of headers that contain the base name. */
rc = dbiMireKeys(mi->mi_db, _tag, _mode, bn, &set, NULL); rc = dbiMireKeys(mi->mi_db, _tag, _mode, bn, &set, NULL);
if (rc == 0 && set != NULL) { if (rc == 0 && set != NULL) {
rpmuint32_t tagNum = hashFunctionString(0, bn, 0); rpmuint32_t tagNum = hashFunctionString(0, bn, 0);
/* Set tagNum to the hash of the basename. */ /* Set tagNum to the hash of the basename. */
for (i = 0; i < set->count; i++) for (i = 0; i < set->count; i++)
set->recs[i].tagNum = tagNum; set->recs[i].tagNum = tagNum;
if (mi->mi_set == NULL) if (mi->mi_set == NULL)
mi->mi_set = xcalloc(1, sizeof(*mi->mi_set)); mi->mi_set = (dbiIndexSet) xcalloc(1, sizeof(*mi->mi_set));
(void) dbiAppendSet(mi->mi_set, set->recs, set->count, sizeof(*set-> recs), 0); (void) dbiAppendSet(mi->mi_set, set->recs, set->count, sizeof(*set-> recs), 0);
} }
rc = 0; rc = 0;
exit: exit:
if (_rpmmi_debug) if (_rpmmi_debug)
fprintf(stderr, "<-- %s(%p, \"%s\")\trc %d set %p %p[%u]\n", __FUNCTION__, mi, bn, rc, set, (set ? set->recs : NULL), (unsigned)(set ? set->count : 0) ); fprintf(stderr, "<-- %s(%p, \"%s\")\trc %d set %p %p[%u]\n", __FUNCTION__, mi, bn, rc, set, (set ? set->recs : NULL), (unsigned)(set ? set->count : 0) );
set = dbiFreeIndexSet(set); set = dbiFreeIndexSet(set);
return rc; return rc;
} }
skipping to change at line 1551 skipping to change at line 1679
/*@-nullstate@*/ /*@-nullstate@*/
return rc; return rc;
/*@=nullstate@*/ /*@=nullstate@*/
} }
static void rpmmiFini(void * _mi) static void rpmmiFini(void * _mi)
/*@globals rpmmiRock @*/ /*@globals rpmmiRock @*/
/*@modifies _mi, rpmmiRock @*/ /*@modifies _mi, rpmmiRock @*/
{ {
rpmmi mi = _mi; rpmmi mi = (rpmmi) _mi;
rpmmi * prev, next; rpmmi * prev, next;
dbiIndex dbi; dbiIndex dbi;
int xx; int xx;
prev = &rpmmiRock; prev = &rpmmiRock;
while ((next = *prev) != NULL && next != mi) while ((next = *prev) != NULL && next != mi)
prev = &next->mi_next; prev = &next->mi_next;
if (next) { if (next) {
/*@i@*/ *prev = next->mi_next; /*@i@*/ *prev = next->mi_next;
next->mi_next = NULL; next->mi_next = NULL;
skipping to change at line 1734 skipping to change at line 1862
case '[': case '[':
brackets = 1; brackets = 1;
/*@switchbreak@*/ break; /*@switchbreak@*/ break;
case ']': case ']':
if (c != (int) '[') brackets = 0; if (c != (int) '[') brackets = 0;
/*@switchbreak@*/ break; /*@switchbreak@*/ break;
} }
c = (int) *s; c = (int) *s;
} }
pat = t = xmalloc(nb); pat = t = (char *) xmalloc(nb);
if (pattern[0] != '^') *t++ = '^'; if (pattern[0] != '^') *t++ = '^';
/* Copy pattern, escaping periods, prefixing splats with period. */ /* Copy pattern, escaping periods, prefixing splats with period. */
c = (int) '\0'; c = (int) '\0';
brackets = 0; brackets = 0;
for (s = pattern; *s != '\0'; s++, t++) { for (s = pattern; *s != '\0'; s++, t++) {
switch (*s) { switch (*s) {
case '.': case '.':
case '+': case '+':
skipping to change at line 1815 skipping to change at line 1943
return rc; return rc;
/* Leading '!' inverts pattern match sense, like "grep -v". */ /* Leading '!' inverts pattern match sense, like "grep -v". */
if (*pattern == '!') { if (*pattern == '!') {
notmatch = 1; notmatch = 1;
pattern++; pattern++;
} }
nmire = mireNew(mode, tag); nmire = mireNew(mode, tag);
assert(nmire != NULL); assert(nmire != NULL);
allpat = mireDup(nmire->tag, &nmire->mode, pattern); allpat = mireDup((rpmTag)nmire->tag, &nmire->mode, pattern);
if (nmire->mode == RPMMIRE_DEFAULT) if (nmire->mode == RPMMIRE_DEFAULT)
nmire->mode = defmode; nmire->mode = defmode;
rc = mireRegcomp(nmire, allpat); rc = mireRegcomp(nmire, allpat);
if (rc) if (rc)
goto exit; goto exit;
if (mi->mi_re == NULL) { if (mi->mi_re == NULL) {
mi->mi_re = mireGetPool(_mirePool); mi->mi_re = mireGetPool(_mirePool);
mire = mireLink(mi->mi_re); mire = mireLink(mi->mi_re);
} else { } else {
void *use = mi->mi_re->_item.use; yarnLock use = mi->mi_re->_item.use;
void *pool = mi->mi_re->_item.pool; void *pool = mi->mi_re->_item.pool;
mi->mi_re = xrealloc(mi->mi_re, (mi->mi_nre + 1) * sizeof(*mi->mi_re )); mi->mi_re = (miRE) xrealloc(mi->mi_re, (mi->mi_nre + 1) * sizeof(*mi ->mi_re));
if (_mire_debug) if (_mire_debug)
fprintf(stderr, " mire %p[%u] realloc\n", mi->mi_re, mi->mi_nre+1); fprintf(stderr, " mire %p[%u] realloc\n", mi->mi_re, mi->mi_nre+1);
mire = mi->mi_re + mi->mi_nre; mire = mi->mi_re + mi->mi_nre;
memset(mire, 0, sizeof(*mire)); memset(mire, 0, sizeof(*mire));
/* XXX ensure no segfault, copy the use/pool from 1st item. */ /* XXX ensure no segfault, copy the use/pool from 1st item. */
/*@-assignexpose@*/ /*@-assignexpose@*/
mire->_item.use = use; mire->_item.use = use;
mire->_item.pool = pool; mire->_item.pool = pool;
/*@=assignexpose@*/ /*@=assignexpose@*/
} }
skipping to change at line 1894 skipping to change at line 2022
* Convert binary blob to printable hex string. * Convert binary blob to printable hex string.
* @param data binary data * @param data binary data
* @param size size of data in bytes * @param size size of data in bytes
* @return malloc'd hex string * @return malloc'd hex string
*/ */
/*@only@*/ /*@only@*/
static char * bin2hex(const void *data, size_t size) static char * bin2hex(const void *data, size_t size)
/*@*/ /*@*/
{ {
static char hex[] = "0123456789abcdef"; static char hex[] = "0123456789abcdef";
const char * s = data; const char * s = (const char *) data;
char * t, * val; char * t, * val;
val = t = xmalloc(size * 2 + 1); val = t = (char *) xmalloc(size * 2 + 1);
while (size-- > 0) { while (size-- > 0) {
unsigned i; unsigned i;
i = (unsigned) *s++; i = (unsigned) *s++;
*t++ = hex[ (i >> 4) & 0xf ]; *t++ = hex[ (i >> 4) & 0xf ];
*t++ = hex[ (i ) & 0xf ]; *t++ = hex[ (i ) & 0xf ];
} }
*t = '\0'; *t = '\0';
return val; return val;
} }
skipping to change at line 1918 skipping to change at line 2046
/** /**
* Return iterator selector match. * Return iterator selector match.
* @param mi rpm database iterator * @param mi rpm database iterator
* @return 1 if header should be skipped * @return 1 if header should be skipped
*/ */
/*@-onlytrans@*/ /* XXX miRE array, not refcounted. */ /*@-onlytrans@*/ /* XXX miRE array, not refcounted. */
static int mireSkip (const rpmmi mi) static int mireSkip (const rpmmi mi)
/*@globals internalState @*/ /*@globals internalState @*/
/*@modifies mi->mi_re, internalState @*/ /*@modifies mi->mi_re, internalState @*/
{ {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
char numbuf[32]; char numbuf[32];
miRE mire; miRE mire;
int ntags = 0; int ntags = 0;
int nmatches = 0; int nmatches = 0;
int i; int i;
int rc; int rc;
if (mi->mi_h == NULL) /* XXX can't happen */ if (mi->mi_h == NULL) /* XXX can't happen */
return 1; return 1;
/* /*
* Apply tag tests, implicitly "||" for multiple patterns/values of a * Apply tag tests, implicitly "||" for multiple patterns/values of a
* single tag, implicitly "&&" between multiple tag patterns. * single tag, implicitly "&&" between multiple tag patterns.
*/ */
if ((mire = mi->mi_re) == NULL) if ((mire = mi->mi_re) == NULL)
return 0; return 0;
for (i = 0; i < mi->mi_nre; i++, mire++) { for (i = 0; i < mi->mi_nre; i++, mire++) {
int anymatch; int anymatch;
he->tag = mire->tag; he->tag = (rpmTag) mire->tag;
if (!headerGet(mi->mi_h, he, 0)) { if (!headerGet(mi->mi_h, he, 0)) {
if (he->tag != RPMTAG_EPOCH) { if (he->tag != RPMTAG_EPOCH) {
ntags++; ntags++;
continue; continue;
} }
he->t = RPM_UINT32_TYPE; he->t = RPM_UINT32_TYPE;
he->p.ui32p = xcalloc(1, sizeof(*he->p.ui32p)); he->p.ui32p = (rpmuint32_t *) xcalloc(1, sizeof(*he->p.ui32p));
he->c = 1; he->c = 1;
} }
anymatch = 0; /* no matches yet */ anymatch = 0; /* no matches yet */
while (1) { while (1) {
unsigned j; unsigned j;
switch (he->t) { switch (he->t) {
case RPM_UINT8_TYPE: case RPM_UINT8_TYPE:
for (j = 0; j < (unsigned) he->c; j++) { for (j = 0; j < (unsigned) he->c; j++) {
sprintf(numbuf, "%u", (unsigned) he->p.ui8p[j]); sprintf(numbuf, "%u", (unsigned) he->p.ui8p[j]);
skipping to change at line 2353 skipping to change at line 2481
fprintf(stderr, "<-- %s(%p, %p[%u], %d) rc %d h# %u\n", __FUNCTION__, mi, h drNums, (unsigned)nHdrNums, sorted, rc, (unsigned) (hdrNums ? hdrNums[0] : 0)); fprintf(stderr, "<-- %s(%p, %p[%u], %d) rc %d h# %u\n", __FUNCTION__, mi, h drNums, (unsigned)nHdrNums, sorted, rc, (unsigned) (hdrNums ? hdrNums[0] : 0));
return rc; return rc;
} }
int rpmmiGrow(rpmmi mi, const uint32_t * hdrNums, int nHdrNums) int rpmmiGrow(rpmmi mi, const uint32_t * hdrNums, int nHdrNums)
{ {
int rc = (mi == NULL || hdrNums == NULL || nHdrNums <= 0); int rc = (mi == NULL || hdrNums == NULL || nHdrNums <= 0);
if (!rc) { if (!rc) {
if (mi->mi_set == NULL) if (mi->mi_set == NULL)
mi->mi_set = xcalloc(1, sizeof(*mi->mi_set)); mi->mi_set = (dbiIndexSet) xcalloc(1, sizeof(*mi->mi_set));
(void) dbiAppendSet(mi->mi_set, hdrNums, nHdrNums, sizeof(*hdrNums), 0); (void) dbiAppendSet(mi->mi_set, hdrNums, nHdrNums, sizeof(*hdrNums), 0);
} }
if (_rpmmi_debug) if (_rpmmi_debug)
fprintf(stderr, "<-- %s(%p, %p[%u]) rc %d h# %u\n", __FUNCTION__, mi, hdrNu ms, (unsigned)nHdrNums, rc, (unsigned) (hdrNums ? hdrNums[0] : 0)); fprintf(stderr, "<-- %s(%p, %p[%u]) rc %d h# %u\n", __FUNCTION__, mi, hdrNu ms, (unsigned)nHdrNums, rc, (unsigned) (hdrNums ? hdrNums[0] : 0));
return rc; return rc;
} }
/*@-dependenttrans -exposetrans -globstate @*/ /*@-dependenttrans -exposetrans -globstate @*/
rpmmi rpmmiInit(rpmdb db, rpmTag tag, const void * keyp, size_t keylen) rpmmi rpmmiInit(rpmdb db, rpmTag tag, const void * keyp, size_t keylen)
{ {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
rpmmi mi = NULL; rpmmi mi = NULL;
dbiIndexSet set = NULL; dbiIndexSet set = NULL;
dbiIndex dbi = NULL; dbiIndex dbi = NULL;
int usePatterns = 0; int usePatterns = 0;
if (db == NULL) if (db == NULL)
goto exit; goto exit;
(void) rpmdbCheckSignals(); (void) rpmdbCheckSignals();
skipping to change at line 2422 skipping to change at line 2550
#ifdef NOTYET /* XXX non-configured tag indices force NULL return */ #ifdef NOTYET /* XXX non-configured tag indices force NULL return */
assert(dbi != NULL); /* XXX sanity */ assert(dbi != NULL); /* XXX sanity */
#else #else
if (dbi == NULL) if (dbi == NULL)
goto exit; goto exit;
#endif #endif
mi = rpmmiGetPool(_rpmmiPool); mi = rpmmiGetPool(_rpmmiPool);
(void)rpmioLinkPoolItem((rpmioItem)mi, __FUNCTION__, __FILE__, __LINE__ ); (void)rpmioLinkPoolItem((rpmioItem)mi, __FUNCTION__, __FILE__, __LINE__ );
/* XXX FIXME: prints unprintable characters (while debugging). */
if (_rpmmi_debug || (dbi && dbi->dbi_debug)) if (_rpmmi_debug || (dbi && dbi->dbi_debug))
fprintf(stderr, "--> %s(%p, %s, %p[%u]=\"%s\") dbi %p mi %p\n", __FUNCTION_ _, db, tagName(tag), keyp, (unsigned)keylen, (keylen == 0 || ((const char * )keyp)[keylen] == '\0' ? (const char *)keyp : "???"), dbi, mi); fprintf(stderr, "--> %s(%p, %s, %p[%u]=\"%s\") dbi %p mi %p\n", __FUNCTION_ _, db, tagName(tag), keyp, (unsigned)keylen, (keylen == 0 || ((const char * )keyp)[keylen] == '\0' ? (const char *)keyp : "???"), dbi, mi);
/* Chain cursors for teardown on abnormal exit. */ /* Chain cursors for teardown on abnormal exit. */
mi->mi_next = rpmmiRock; mi->mi_next = rpmmiRock;
rpmmiRock = mi; rpmmiRock = mi;
if (tag == RPMDBI_PACKAGES && keyp == NULL) { if (tag == RPMDBI_PACKAGES && keyp == NULL) {
/* Special case #1: sequentially iterate Packages database. */ /* Special case #1: sequentially iterate Packages database. */
assert(keylen == 0); assert(keylen == 0);
/* This should be the only case when (set == NULL). */ /* This should be the only case when (set == NULL). */
} }
else if (tag == RPMDBI_PACKAGES) { else if (tag == RPMDBI_PACKAGES) {
/* Special case #2: will fetch header instance. */ /* Special case #2: will fetch header instance. */
uint32_t hdrNum; uint32_t hdrNum;
assert(keylen == sizeof(hdrNum)); assert(keylen == sizeof(hdrNum));
memcpy(&hdrNum, keyp, sizeof(hdrNum)); memcpy(&hdrNum, keyp, sizeof(hdrNum));
/* The set has only one element, which is hdrNum. */ /* The set has only one element, which is hdrNum. */
set = xcalloc(1, sizeof(*set)); set = (dbiIndexSet) xcalloc(1, sizeof(*set));
set->count = 1; set->count = 1;
set->recs = xcalloc(1, sizeof(set->recs[0])); set->recs = (dbiIndexItem) xcalloc(1, sizeof(set->recs[0]));
set->recs[0].hdrNum = hdrNum; set->recs[0].hdrNum = hdrNum;
} }
else if (keyp == NULL) { else if (keyp == NULL) {
/* XXX Special case #3: empty iterator with rpmmiGrow() */ /* XXX Special case #3: empty iterator with rpmmiGrow() */
assert(keylen == 0); assert(keylen == 0);
} }
else if (usePatterns) { else if (usePatterns) {
/* XXX Special case #4: gather primary keys with patterns. */ /* XXX Special case #4: gather primary keys with patterns. */
rpmRC rc; rpmRC rc;
rc = dbiFindMatches(dbi, keyp, &set); rc = dbiFindMatches(dbi, (const char *)keyp, &set);
#if defined(RPM_VENDOR_MANDRIVA) #if defined(RPM_VENDOR_MANDRIVA)
/* /*
* Hack to workaround disttag/distepoch pattern matching issue to bu y some * Hack to workaround disttag/distepoch pattern matching issue to bu y some
* time to come up with better pattern fix.. * time to come up with better pattern fix..
* One size should fit all now.. ;) * One size should fit all now.. ;)
* *
* This patch will try match NVR first, then for all matches returne d, * This patch will try match NVR first, then for all matches returne d,
* it will match disttag, distepoch & arch individually. * it will match disttag, distepoch & arch individually.
*/ */
skipping to change at line 2559 skipping to change at line 2688
} }
else if (dbi && dbi->dbi_primary != NULL) { else if (dbi && dbi->dbi_primary != NULL) {
/* XXX Special case #5: secondary index associated w primary table. */ /* XXX Special case #5: secondary index associated w primary table. */
} }
else { else {
/* Common case: retrieve join keys. */ /* Common case: retrieve join keys. */
assert(0); assert(0);
} }
/*@-assignexpose@*/ /*@-assignexpose@*/
mi->mi_db = rpmdbLink(db, __FUNCTION__); mi->mi_db = (rpmdb) rpmdbLink(db, __FUNCTION__);
/*@=assignexpose@*/ /*@=assignexpose@*/
mi->mi_rpmtag = tag; mi->mi_rpmtag = tag;
mi->mi_dbc = NULL; mi->mi_dbc = NULL;
mi->mi_set = set; mi->mi_set = set;
mi->mi_setx = 0; mi->mi_setx = 0;
mi->mi_count = (set ? set->count : 0); mi->mi_count = (set ? set->count : 0);
mi->mi_primary = (dbi && dbi->dbi_primary mi->mi_primary = (dbi && dbi->dbi_primary
? xstrdup(dbi->dbi_primary) : NULL); ? xstrdup(dbi->dbi_primary) : NULL);
/* Coerce/swab integer keys. Save key ind keylen in the iterator. */ /* Coerce/swab integer keys. Save key ind keylen in the iterator. */
switch (tagType(tag) & 0xffff) { switch (tagType(tag) & 0xffff) {
case RPM_UINT8_TYPE: case RPM_UINT8_TYPE:
assert(keylen == sizeof(he->p.ui8p[0])); assert(keylen == sizeof(he->p.ui8p[0]));
mi->mi_keylen = sizeof(he->p.ui32p[0]); /* XXX coerce to uint32_t */ mi->mi_keylen = sizeof(he->p.ui32p[0]); /* XXX coerce to uint32_t */
mi->mi_keyp = he->p.ui32p = xmalloc(mi->mi_keylen); mi->mi_keyp = he->p.ui32p = (rpmuint32_t *) xmalloc(mi->mi_keylen);
he->p.ui32p[0] = 0; he->p.ui32p[0] = 0;
memcpy(&he->p.ui8p[3], keyp, keylen); memcpy(&he->p.ui8p[3], keyp, keylen);
break; break;
case RPM_UINT16_TYPE: case RPM_UINT16_TYPE:
assert(keylen == sizeof(he->p.ui16p[0])); assert(keylen == sizeof(he->p.ui16p[0]));
mi->mi_keylen = sizeof(he->p.ui32p[0]); /* XXX coerce to uint32_t */ mi->mi_keylen = sizeof(he->p.ui32p[0]); /* XXX coerce to uint32_t */
mi->mi_keyp = he->p.ui32p = xmalloc(mi->mi_keylen); mi->mi_keyp = he->p.ui32p = (rpmuint32_t *) xmalloc(mi->mi_keylen);
he->p.ui32p[0] = 0; he->p.ui32p[0] = 0;
memcpy(&he->p.ui16p[1], keyp, keylen); memcpy(&he->p.ui16p[1], keyp, keylen);
he->p.ui16p[1] = _hton_us(he->p.ui16p[1]); he->p.ui16p[1] = _hton_us(he->p.ui16p[1]);
break; break;
#if !defined(__LCLINT__) /* LCL: buggy */ #if !defined(__LCLINT__) /* LCL: buggy */
case RPM_UINT32_TYPE: case RPM_UINT32_TYPE:
assert(keylen == sizeof(he->p.ui32p[0])); assert(keylen == sizeof(he->p.ui32p[0]));
mi->mi_keylen = keylen; mi->mi_keylen = keylen;
/*@-mayaliasunique@*/ /*@-mayaliasunique@*/
mi->mi_keyp = memcpy((he->p.ui32p = xmalloc(keylen)), keyp, keylen); mi->mi_keyp = memcpy((he->p.ptr = xmalloc(keylen)), keyp, keylen);
/*@=mayaliasunique@*/ /*@=mayaliasunique@*/
he->p.ui32p[0] = _hton_ui(he->p.ui32p[0]); he->p.ui32p[0] = _hton_ui(he->p.ui32p[0]);
break; break;
case RPM_UINT64_TYPE: case RPM_UINT64_TYPE:
assert(keylen == sizeof(he->p.ui64p[0])); assert(keylen == sizeof(he->p.ui64p[0]));
mi->mi_keylen = keylen; mi->mi_keylen = keylen;
/*@-mayaliasunique@*/ /*@-mayaliasunique@*/
mi->mi_keyp = memcpy((he->p.ui64p = xmalloc(keylen)), keyp, keylen); mi->mi_keyp = memcpy((he->p.ptr = xmalloc(keylen)), keyp, keylen);
/*@=mayaliasunique@*/ /*@=mayaliasunique@*/
{ uint32_t _tmp = he->p.ui32p[0]; { uint32_t _tmp = he->p.ui32p[0];
he->p.ui32p[0] = _hton_ui(he->p.ui32p[1]); he->p.ui32p[0] = _hton_ui(he->p.ui32p[1]);
he->p.ui32p[1] = _hton_ui(_tmp); he->p.ui32p[1] = _hton_ui(_tmp);
} }
break; break;
#endif /* !defined(__LCLINT__) */ #endif /* !defined(__LCLINT__) */
case RPM_I18NSTRING_TYPE: /* XXX never occurs */ case RPM_I18NSTRING_TYPE: /* XXX never occurs */
#if !defined(SUPPORT_I18NSTRING_TYPE) #if !defined(SUPPORT_I18NSTRING_TYPE)
assert(0); assert(0);
#endif #endif
case RPM_BIN_TYPE: case RPM_BIN_TYPE:
case RPM_STRING_TYPE: case RPM_STRING_TYPE:
case RPM_STRING_ARRAY_TYPE: case RPM_STRING_ARRAY_TYPE:
default: default:
mi->mi_keylen = keylen; mi->mi_keylen = keylen;
if (keyp) if (keyp)
mi->mi_keyp = keylen > 0 mi->mi_keyp = (keylen > 0
? memcpy(xmalloc(keylen), keyp, keylen) : xstrdup(keyp) ; ? memcpy(xmalloc(keylen), (char *)keyp, keylen)
: xstrdup((char *)keyp));
else else
mi->mi_keyp = NULL; mi->mi_keyp = NULL;
break; break;
} }
he->p.ptr = NULL; he->p.ptr = NULL;
mi->mi_h = NULL; mi->mi_h = NULL;
mi->mi_sorted = 0; mi->mi_sorted = 0;
mi->mi_cflags = 0; mi->mi_cflags = 0;
mi->mi_modified = 0; mi->mi_modified = 0;
skipping to change at line 2645 skipping to change at line 2775
exit: exit:
return mi; return mi;
} }
/*@=dependenttrans =exposetrans =globstate @*/ /*@=dependenttrans =exposetrans =globstate @*/
/* XXX psm.c */ /* XXX psm.c */
int rpmdbRemove(rpmdb db, /*@unused@*/ int rid, uint32_t hdrNum, int rpmdbRemove(rpmdb db, /*@unused@*/ int rid, uint32_t hdrNum,
/*@unused@*/ rpmts ts) /*@unused@*/ rpmts ts)
{ {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
Header h = NULL; Header h = NULL;
sigset_t signalMask; sigset_t signalMask;
dbiIndex dbi; dbiIndex dbi;
size_t dbix; size_t dbix;
int rc = RPMRC_FAIL; /* XXX RPMRC */ int rc = RPMRC_FAIL; /* XXX RPMRC */
int xx; int xx;
if (db == NULL) if (db == NULL)
return RPMRC_OK; /* XXX RPMRC */ return RPMRC_OK; /* XXX RPMRC */
skipping to change at line 2755 skipping to change at line 2885
rc = RPMRC_OK; /* XXX RPMRC */ rc = RPMRC_OK; /* XXX RPMRC */
exit: exit:
(void) unblockSignals(db, &signalMask); (void) unblockSignals(db, &signalMask);
return rc; return rc;
} }
/* XXX install.c */ /* XXX install.c */
int rpmdbAdd(rpmdb db, int iid, Header h, /*@unused@*/ rpmts ts) int rpmdbAdd(rpmdb db, int iid, Header h, /*@unused@*/ rpmts ts)
{ {
HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he)); HE_t he = (HE_t) memset(alloca(sizeof(*he)), 0, sizeof(*he));
sigset_t signalMask; sigset_t signalMask;
dbiIndex dbi; dbiIndex dbi;
size_t dbix; size_t dbix;
uint32_t hdrNum = headerGetInstance(h); uint32_t hdrNum = headerGetInstance(h);
int rc = RPMRC_FAIL; /* XXX RPMRC */ int rc = RPMRC_FAIL; /* XXX RPMRC */
int xx; int xx;
if (db == NULL) if (db == NULL)
return RPMRC_OK; /* XXX RPMRC */ return RPMRC_OK; /* XXX RPMRC */
 End of changes. 52 change blocks. 
46 lines changed or deleted 177 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/