Add headerPut() for adding data to headers through tag container
authorPanu Matilainen <pmatilai@redhat.com>
Tue, 13 May 2008 09:32:25 +0000 (12:32 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Tue, 13 May 2008 09:32:25 +0000 (12:32 +0300)
- tag container isn't that big a win on add/append operations as it is on
  retrieval, just use the existing headerAddEntry() family to do the
  actual work
- headerPut() is a nice and short name, lifted from rpm5.org, API might
  differ
- flags to control operation, just whether append is permitted or not for now

lib/header.c
lib/header.h

index 58af0f8..b951328 100644 (file)
@@ -1581,6 +1581,19 @@ int headerAddOrAppendEntry(Header h, rpmTag tag, rpmTagType type,
        : headerAddEntry(h, tag, type, p, c));
 }
 
+int headerPut(Header h, rpmtd td, int flags)
+{
+    int rc;
+    
+    assert(td != NULL);
+    if (flags & HEADERPUT_APPEND) {
+       rc = headerAddOrAppendEntry(h, td->tag, td->type, td->data, td->count);
+    } else {
+       rc = headerAddEntry(h, td->tag, td->type, td->data, td->count);
+    }
+    return rc;
+}
+
 int headerAddI18NString(Header h, rpmTag tag, const char * string,
                const char * lang)
 {
index 494ec94..0c63218 100644 (file)
@@ -325,6 +325,20 @@ int headerGetEntryMinMemory(Header h, rpmTag tag,
                        rpm_data_t * p, 
                        rpm_count_t * c);
 
+enum headerPutFlags_e {
+    HEADERPUT_DEFAULT  = 0,
+    HEADERPUT_APPEND   = (1 << 0),
+};
+/** \ingroup header
+ * Add or append tag to header.
+ *
+ * @param h            header
+ * @param td           tag data container
+ * @param flags                flags to control operation
+ * @return             1 on success, 0 on failure
+ */
+int headerPut(Header h, rpmtd td, int flags);
+
 /** \ingroup header
  * Add tag to header.
  * Duplicate tags are okay, but only defined for iteration (with the