Merge rpmdbIndexIteratorKey and rpmdbIndexIteratorKeySize into rpmdbIndexIteratorNext
authorFlorian Festi <ffesti@redhat.com>
Wed, 3 Nov 2010 09:58:41 +0000 (10:58 +0100)
committerFlorian Festi <ffesti@redhat.com>
Wed, 3 Nov 2010 11:17:02 +0000 (12:17 +0100)
lib/rpmdb.c
lib/rpmdb.h
python/rpmii-py.c

index e539ebb..63f9a2c 100644 (file)
@@ -2272,41 +2272,40 @@ rpmdbIndexIterator rpmdbIndexIteratorInit(rpmdb db, rpmDbiTag rpmtag)
     return ii;
 }
 
-int rpmdbIndexIteratorNext(rpmdbIndexIterator ii)
+int rpmdbIndexIteratorNext(rpmdbIndexIterator ii, const void ** key, size_t * keylen)
 {
     int rc, xx;
     DBT data;
 
     if (ii == NULL)
-       return 1;
+       return -1;
 
     if (ii->ii_dbc == NULL)
         xx = dbiCopen(ii->ii_dbi, &ii->ii_dbc, 0);
 
+    /* free old data */
+    ii->ii_set = dbiFreeIndexSet(ii->ii_set);
+
     memset(&data, 0, sizeof(data));
     rc = dbiGet(ii->ii_dbi, ii->ii_dbc, &ii->ii_key, &data, DB_NEXT);
 
-    if (rc != 0 && rc != DB_NOTFOUND) {
-        rpmlog(RPMLOG_ERR,
-               _("error(%d:%s) getting next key from %s index\n"),
-               rc, db_strerror(rc), rpmTagGetName(ii->ii_rpmtag));
-    }
-    ii->ii_set = dbiFreeIndexSet(ii->ii_set);
-    (void) dbt2set(ii->ii_dbi, &data, &ii->ii_set);
+    if (rc != 0) { 
+        *key = NULL;
+        *keylen = 0;
 
-    return rc;
-}
+        if (rc != DB_NOTFOUND) {
+            rpmlog(RPMLOG_ERR,
+                   _("error(%d:%s) getting next key from %s index\n"),
+                   rc, db_strerror(rc), rpmTagGetName(ii->ii_rpmtag));
+        }
+        return -1;
+    }
 
-const void * rpmdbIndexIteratorKey(rpmdbIndexIterator ii)
-{
-    if (ii == NULL) return NULL;
-    return ii->ii_key.data;
-}
+    (void) dbt2set(ii->ii_dbi, &data, &ii->ii_set);
+    *key = ii->ii_key.data;
+    *keylen = ii->ii_key.size;
 
-size_t rpmdbIndexIteratorKeySize(rpmdbIndexIterator ii)
-{
-    if (ii == NULL) return (size_t) 0;
-    return (size_t)(ii->ii_key.size);
+    return 0;
 }
 
 unsigned int rpmdbIndexIteratorNumPkgs(rpmdbIndexIterator ii)
index 4ea6420..a8479f5 100644 (file)
@@ -228,25 +228,14 @@ int rpmdbRebuild(const char * prefix, rpmts ts,
 rpmdbIndexIterator rpmdbIndexIteratorInit(rpmdb db, rpmDbiTag rpmtag);
 
 /** \ingroup rpmdb
- * Get the next key - must be called before getting the first key
+ * Get the next key - Warning! Keys are not zero terminated!
+ * Binary tags may even contain zero bytes
  * @param ii           index iterator
+ * @param key          adress to save the pointer to the key
+ * @param keylen       adress to save the length of the key to
  * @return             0 on success; != 0 on error or end of index
  */
-int rpmdbIndexIteratorNext(rpmdbIndexIterator ii);
-
-/** \ingroup rpmdb
- * Get current key
- * @param ii            index iterator
- * @return             pointer to key content. Keys are not zero terminated!
- */
-const void * rpmdbIndexIteratorKey(rpmdbIndexIterator ii);
-
-/** \ingroup rpmdb
- * Get length of key
- * @param ii            index iterator
- * @return             length of key
- */
-size_t rpmdbIndexIteratorKeySize(rpmdbIndexIterator ii);
+int rpmdbIndexIteratorNext(rpmdbIndexIterator ii, const void ** key, size_t * keylen);
 
 /** \ingroup rpmdb
  * Get number of entries for current key
index 5275a31..d40035c 100644 (file)
@@ -43,12 +43,13 @@ struct rpmiiObject_s {
 static PyObject *
 rpmii_iternext(rpmiiObject * s)
 {
-    if (s->ii == NULL || (rpmdbIndexIteratorNext(s->ii)) != 0) {
+    char * key;
+    size_t keylen;
+    if (s->ii == NULL || (rpmdbIndexIteratorNext(s->ii, (const void**)&key, &keylen)) != 0) {
        s->ii = rpmdbIndexIteratorFree(s->ii);
        return NULL;
     }
-    return PyString_FromStringAndSize(rpmdbIndexIteratorKey(s->ii),
-                                      rpmdbIndexIteratorKeySize(s->ii));
+    return PyString_FromStringAndSize(key, keylen);
 };
 
 static PyObject *