Add header color tag extension, ie headerGetColor()
authorPanu Matilainen <pmatilai@redhat.com>
Wed, 2 Sep 2009 10:57:54 +0000 (13:57 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Wed, 2 Sep 2009 10:57:54 +0000 (13:57 +0300)
- use common numeric tag generation helper for header color
  and dbinstance tags

lib/rpmtag.h
lib/tagexts.c
tests/rpmgeneral.at

index 367724f..c2b6146 100644 (file)
@@ -289,6 +289,7 @@ typedef enum rpmTag_e {
     RPMTAG_NVR                 = 5014, /* s extension */
     RPMTAG_NEVR                        = 5015, /* s extension */
     RPMTAG_NEVRA               = 5016, /* s extension */
+    RPMTAG_HEADERCOLOR         = 5017, /* i extension */
 
     RPMTAG_FIRSTFREE_TAG       /*!< internal */
 } rpmTag;
index ba93b83..ec0b001 100644 (file)
@@ -629,18 +629,38 @@ static int longsigsizeTag(Header h, rpmtd td, headerGetFlags hgflags)
     return get64(h, td, RPMTAG_LONGSIGSIZE, RPMTAG_SIGSIZE);
 }
 
-static int dbinstanceTag(Header h, rpmtd td, headerGetFlags hgflags)
+static int numberTag(rpmtd td, uint32_t val)
 {
-    uint32_t *recno = xmalloc(sizeof(*recno));
+    uint32_t *tval = xmalloc(sizeof(*tval));
 
-    recno[0] = headerGetInstance(h);
+    tval[0] = val;
     td->type = RPM_INT32_TYPE;
     td->count = 1;
-    td->data = recno;
+    td->data = tval;
     td->flags = RPMTD_ALLOCED;
     return 1; /* this cannot fail */
 }
 
+static int dbinstanceTag(Header h, rpmtd td, headerGetFlags hgflags)
+{
+    return numberTag(td, headerGetInstance(h));
+}
+
+static int headercolorTag(Header h, rpmtd td, headerGetFlags hgflags)
+{
+    rpm_color_t *fcolor, hcolor = 0;
+    struct rpmtd_s fcolors;
+
+    headerGet(h, RPMTAG_FILECOLORS, &fcolors, HEADERGET_MINMEM);
+    while ((fcolor = rpmtdNextUint32(&fcolors)) != NULL) {
+       hcolor |= *fcolor;
+    }
+    rpmtdFreeData(&fcolors);
+    hcolor &= 0x0f;
+
+    return numberTag(td, hcolor);
+}
+
 typedef enum nevraFlags_e {
     NEVRA_NAME         = (1 << 0),
     NEVRA_EPOCH                = (1 << 1),
@@ -748,6 +768,7 @@ static const struct headerTagFunc_s rpmHeaderTagExtensions[] = {
     { RPMTAG_NEVR,             nevrTag },
     { RPMTAG_NVRA,             nvraTag },
     { RPMTAG_NEVRA,            nevraTag },
+    { RPMTAG_HEADERCOLOR,      headercolorTag },
     { 0,                       NULL }
 };
 
index b6f2e25..18b7324 100644 (file)
@@ -133,6 +133,7 @@ FSSIZES
 GIF
 GROUP
 HDRID
+HEADERCOLOR
 HEADERI18NTABLE
 HEADERIMAGE
 HEADERIMMUTABLE