summaryrefslogtreecommitdiff
path: root/lib/rpmdb.c
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2008-05-28 07:52:19 +0300
committerPanu Matilainen <pmatilai@redhat.com>2008-05-28 09:45:34 +0300
commit1f32f4aa7773e247f55cb05e9b86f4d3e5009d02 (patch)
treea217d63b9765ce1f83177676c4593680978aa1c9 /lib/rpmdb.c
parente4f021461d22880794c69e2974173ad03f640d5e (diff)
downloadrpm-1f32f4aa7773e247f55cb05e9b86f4d3e5009d02.tar.gz
Convert rpmdbAdd() to new headerGet() + friends
Diffstat (limited to 'lib/rpmdb.c')
-rw-r--r--lib/rpmdb.c118
1 files changed, 50 insertions, 68 deletions
diff --git a/lib/rpmdb.c b/lib/rpmdb.c
index f2c2c784e..bf945dd4b 100644
--- a/lib/rpmdb.c
+++ b/lib/rpmdb.c
@@ -2597,8 +2597,6 @@ int rpmdbAdd(rpmdb db, int iid, Header h,
DBC * dbcursor = NULL;
DBT key;
DBT data;
- HGE_t hge = (HGE_t)headerGetEntryMinMemory;
- HFD_t hfd = headerFreeData;
sigset_t signalMask;
dbiIndex dbi;
int dbix;
@@ -2699,18 +2697,13 @@ int rpmdbAdd(rpmdb db, int iid, Header h,
if (dbiTags.tags != NULL)
for (dbix = 0; dbix < dbiTags.max; dbix++) {
- const char *av[1];
- const char **rpmvals = NULL;
- rpmTagType rpmtype = 0;
- rpm_count_t rpmcnt = 0;
rpmTag rpmtag;
- rpm_flag_t * requireFlags;
rpmRC rpmrc;
- int i, j;
+ int j;
+ struct rpmtd_s tagdata, reqflags;
rpmrc = RPMRC_NOTFOUND;
dbi = NULL;
- requireFlags = NULL;
rpmtag = dbiTags.tags[dbix];
/* Filter out temporary databases */
@@ -2758,66 +2751,55 @@ int rpmdbAdd(rpmdb db, int iid, Header h,
continue;
break;
case RPMTAG_REQUIRENAME:
- xx = hge(h, rpmtag, &rpmtype, (rpm_data_t *)&rpmvals, &rpmcnt);
- xx = hge(h, RPMTAG_REQUIREFLAGS, NULL, (rpm_data_t *)&requireFlags, NULL);
+ headerGet(h, rpmtag, &tagdata, HEADERGET_MINMEM);
+ headerGet(h, RPMTAG_REQUIREFLAGS, &reqflags, HEADERGET_MINMEM);
break;
default:
- xx = hge(h, rpmtag, &rpmtype, (rpm_data_t *)&rpmvals, &rpmcnt);
+ headerGet(h, rpmtag, &tagdata, HEADERGET_MINMEM);
break;
}
- if (rpmcnt == 0) {
+ if (rpmtdCount(&tagdata) == 0) {
if (rpmtag != RPMTAG_GROUP)
continue;
/* XXX preserve legacy behavior */
- rpmtype = RPM_STRING_TYPE;
- rpmvals = (const char **) "Unknown";
- rpmcnt = 1;
+ tagdata.type = RPM_STRING_TYPE;
+ tagdata.data = (const char **) "Unknown";
+ tagdata.count = 1;
}
dbi = dbiOpen(db, rpmtag, 0);
if (dbi != NULL) {
- int printed;
+ int printed = 0;
- if (rpmtype == RPM_STRING_TYPE) {
- /* XXX force uniform headerGetEntry return */
- av[0] = (const char *) rpmvals;
- rpmvals = av;
- rpmcnt = 1;
- }
-
- printed = 0;
xx = dbiCopen(dbi, dbi->dbi_txnid, &dbcursor, DB_WRITECURSOR);
- for (i = 0; i < rpmcnt; i++) {
+ while (rpmtdNext(&tagdata) >= 0) {
dbiIndexSet set;
- int stringvalued;
+ int stringvalued, i;
uint8_t bin[32];
- uint8_t * t;
+ const char *str = NULL;
/*
* Include the tagNum in all indices. rpm-3.0.4 and earlier
* included the tagNum only for files.
*/
- rec->tagNum = i;
+ i = rec->tagNum = rpmtdGetIndex(&tagdata);
switch (dbi->dbi_rpmtag) {
- case RPMTAG_PUBKEYS:
- break;
- case RPMTAG_FILEMD5S:
- /* Filter out empty MD5 strings. */
- if (!(rpmvals[i] && *rpmvals[i] != '\0'))
- continue;
- break;
- case RPMTAG_REQUIRENAME:
+ case RPMTAG_REQUIRENAME: {
/* Filter out install prerequisites. */
- if (requireFlags && isInstallPreReq(requireFlags[i]))
+ rpm_flag_t *rflag = rpmtdNextUint32(&reqflags);
+ if (rflag && isInstallPreReq(*rflag))
continue;
break;
+ }
case RPMTAG_TRIGGERNAME:
- if (i) { /* don't add duplicates */
+ if (i > 0) { /* don't add duplicates */
+ const char **tnames = tagdata.data;
+ const char *str = rpmtdGetString(&tagdata);
for (j = 0; j < i; j++) {
- if (!strcmp(rpmvals[i], rpmvals[j]))
+ if (!strcmp(str, tnames[j]))
break;
}
if (j < i)
@@ -2830,66 +2812,69 @@ int rpmdbAdd(rpmdb db, int iid, Header h,
/* Identify value pointer and length. */
stringvalued = 0;
- switch (rpmtype) {
+ switch (rpmtdType(&tagdata)) {
case RPM_CHAR_TYPE:
case RPM_INT8_TYPE:
- key.size = sizeof(int8_t);
- key.data = rpmvals + i;
+ key.size = sizeof(uint8_t);
+ key.data = rpmtdGetChar(&tagdata);
break;
case RPM_INT16_TYPE:
- key.size = sizeof(int16_t);
- key.data = rpmvals + i;
+ key.size = sizeof(uint16_t);
+ key.data = rpmtdGetUint16(&tagdata);
break;
case RPM_INT32_TYPE:
- key.size = sizeof(int32_t);
- key.data = rpmvals + i;
+ key.size = sizeof(uint32_t);
+ key.data = rpmtdGetUint32(&tagdata);
break;
case RPM_BIN_TYPE:
- key.size = rpmcnt;
- key.data = rpmvals;
- rpmcnt = 1; /* XXX break out of loop. */
+ key.size = tagdata.count;
+ key.data = tagdata.data;
break;
case RPM_STRING_TYPE:
case RPM_I18NSTRING_TYPE:
- rpmcnt = 1; /* XXX break out of loop. */
case RPM_STRING_ARRAY_TYPE:
+ str = rpmtdGetString(&tagdata);
/* Convert from hex to binary. */
if (dbi->dbi_rpmtag == RPMTAG_FILEMD5S) {
- const char * s;
+ uint8_t * t = bin;
+ /* Filter out empty MD5 strings. */
+ if (!(str && *str != '\0'))
+ continue;
- s = rpmvals[i];
- t = bin;
- for (j = 0; j < 16; j++, t++, s += 2)
- *t = (rnibble(s[0]) << 4) | rnibble(s[1]);
+ for (j = 0; j < 16; j++, t++, str += 2)
+ *t = (rnibble(str[0]) << 4) | rnibble(str[1]);
key.data = bin;
key.size = 16;
break;
- }
- /* Extract the pubkey id from the base64 blob. */
- if (dbi->dbi_rpmtag == RPMTAG_PUBKEYS) {
- int nbin = pgpExtractPubkeyFingerprint(rpmvals[i], bin);
+ } else if (dbi->dbi_rpmtag == RPMTAG_PUBKEYS) {
+ /* Extract the pubkey id from the base64 blob. */
+ int nbin = pgpExtractPubkeyFingerprint(str, bin);
if (nbin <= 0)
continue;
key.data = bin;
key.size = nbin;
break;
+ } else {
+ /* fallthrough */;
}
default:
- key.data = (void *) rpmvals[i];
- key.size = strlen(rpmvals[i]);
+ str = rpmtdGetString(&tagdata);
+ key.data = str;
+ key.size = strlen(str);
stringvalued = 1;
break;
}
if (!printed) {
- if (rpmcnt == 1 && stringvalued) {
+ rpm_count_t c = rpmtdCount(&tagdata);
+ if (c == 1 && stringvalued) {
rpmlog(RPMLOG_DEBUG,
"adding \"%s\" to %s index.\n",
(char *)key.data, rpmTagGetName(dbi->dbi_rpmtag));
} else {
rpmlog(RPMLOG_DEBUG,
"adding %d entries to %s index.\n",
- rpmcnt, rpmTagGetName(dbi->dbi_rpmtag));
+ c, rpmTagGetName(dbi->dbi_rpmtag));
}
printed++;
}
@@ -2945,10 +2930,7 @@ int rpmdbAdd(rpmdb db, int iid, Header h,
xx = dbiSync(dbi, 0);
}
- if (rpmtype != RPM_BIN_TYPE) /* XXX WTFO? HACK ALERT */
- rpmvals = hfd(rpmvals, rpmtype);
- rpmtype = 0;
- rpmcnt = 0;
+ rpmtdFreeData(&tagdata);
}
rec = _free(rec);