• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

rpmdb/hdrNVR.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 #include <rpmio.h>
00007 #include <rpmmacro.h>
00008 
00009 #define _RPMTAG_INTERNAL
00010 #include "header_internal.h"            /* XXX hdrchkType(), hdrchkData() */
00011 
00012 #include "debug.h"
00013 
00018 /*@observer@*/ /*@unchecked@*/
00019 static struct tagMacro {
00020 /*@observer@*/ /*@null@*/
00021     const char *macroname;      
00022     rpmTag      tag;            
00023 } tagMacros[] = {
00024     { "name",           RPMTAG_NAME },
00025     { "version",        RPMTAG_VERSION },
00026     { "release",        RPMTAG_RELEASE },
00027     { "epoch",          RPMTAG_EPOCH },
00028     { "arch",           RPMTAG_ARCH },
00029     { "os",             RPMTAG_OS },
00030     { NULL, 0 }
00031 };
00032 
00033 /*@-globs -mods -incondefs@*/
00034 int headerMacrosLoad(Header h)
00035         /*@globals rpmGlobalMacroContext @*/
00036         /*@modifies rpmGlobalMacroContext @*/
00037 {
00038     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
00039     struct tagMacro * tagm;
00040     char numbuf[64];
00041     const char * val;
00042     uint64_t ival;
00043     int xx;
00044 
00045     numbuf[0] = '\0';
00046     /* XXX pre-expand %{buildroot} (if any) */
00047     {   const char *s = rpmExpand("%{?buildroot}", NULL);
00048         if (s && *s) 
00049             (void) addMacro(NULL, "..buildroot", NULL, s, -1);
00050         s = _free(s);
00051     }
00052     {   const char *s = rpmExpand("%{?_builddir}", NULL);
00053         if (s && *s) 
00054             (void) addMacro(NULL, ".._builddir", NULL, s, -1);
00055         s = _free(s);
00056     }
00057 
00058     for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
00059         he->tag = tagm->tag;
00060         xx = headerGet(h, he, 0);
00061         if (!xx)
00062             continue;
00063         val = NULL;
00064         ival = 0;
00065         switch (he->t) {
00066         case RPM_UINT8_TYPE:
00067             ival = he->p.ui8p[0];
00068             val = numbuf;
00069             /*@switchbreak@*/ break;
00070         case RPM_UINT16_TYPE:
00071             ival = he->p.ui16p[0];
00072             val = numbuf;
00073             /*@switchbreak@*/ break;
00074         case RPM_UINT32_TYPE:
00075             ival = he->p.ui32p[0];
00076             val = numbuf;
00077             /*@switchbreak@*/ break;
00078         case RPM_UINT64_TYPE:
00079             ival = he->p.ui64p[0];
00080             val = numbuf;
00081             /*@switchbreak@*/ break;
00082         case RPM_STRING_TYPE:
00083             val = he->p.str;
00084             /*@switchbreak@*/ break;
00085         case RPM_STRING_ARRAY_TYPE:
00086         case RPM_I18NSTRING_TYPE:
00087         case RPM_BIN_TYPE:
00088         default:
00089             /*@switchbreak@*/ break;
00090         }
00091         
00092         if (val) {
00093 /*@-duplicatequals@*/
00094             if (val == numbuf)
00095                 sprintf(numbuf, "%llu", (unsigned long long)ival);
00096 /*@=duplicatequals@*/
00097             addMacro(NULL, tagm->macroname, NULL, val, -1);
00098         }
00099         he->p.ptr = _free(he->p.ptr);
00100     }
00101     return 0;
00102 }
00103 /*@=globs =mods =incondefs@*/
00104 
00105 /*@-globs -mods -incondefs@*/
00106 int headerMacrosUnload(Header h)
00107         /*@globals rpmGlobalMacroContext @*/
00108         /*@modifies rpmGlobalMacroContext @*/
00109 {
00110     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
00111     struct tagMacro * tagm;
00112     int xx;
00113 
00114     for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
00115         he->tag = tagm->tag;
00116         xx = headerGet(h, he, 0);
00117         if (!xx)
00118             continue;
00119         switch (he->t) {
00120         case RPM_UINT32_TYPE:
00121             delMacro(NULL, tagm->macroname);
00122             /*@switchbreak@*/ break;
00123         case RPM_STRING_TYPE:
00124             delMacro(NULL, tagm->macroname);
00125             /*@switchbreak@*/ break;
00126         case RPM_STRING_ARRAY_TYPE:
00127         case RPM_I18NSTRING_TYPE:
00128         case RPM_BIN_TYPE:
00129         case RPM_UINT8_TYPE:
00130         case RPM_UINT16_TYPE:
00131         case RPM_UINT64_TYPE:
00132         default:
00133             /*@switchbreak@*/ break;
00134         }
00135         he->p.ptr = _free(he->p.ptr);
00136     }
00137 
00138     /* XXX restore previous %{buildroot} (if any) */
00139     {   const char *s = rpmExpand("%{?_builddir}", NULL);
00140         if (s && *s) 
00141             (void) delMacro(NULL, "_builddir");
00142         s = _free(s);
00143     }
00144     {   const char *s = rpmExpand("%{?buildroot}", NULL);
00145         if (s && *s) 
00146             (void) delMacro(NULL, "buildroot");
00147         s = _free(s);
00148     }
00149 
00150     return 0;
00151 }
00152 /*@=globs =mods =incondefs@*/
00153 
00154 int headerNEVRA(Header h, const char **np,
00155                 /*@unused@*/ const char **ep, const char **vp, const char **rp,
00156                 const char **ap)
00157 {
00158     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
00159 
00160 /*@-onlytrans@*/
00161     if (np) {
00162         he->tag = RPMTAG_NAME;
00163         if (headerGet(h, he, 0)
00164          && he->t == RPM_STRING_TYPE && he->c == 1)
00165             *np = xstrdup(he->p.str);
00166         else
00167             *np = NULL;
00168         he->p.ptr = _free(he->p.ptr);
00169     }
00170     if (vp) {
00171         he->tag = RPMTAG_VERSION;
00172         if (headerGet(h, he, 0)
00173          && he->t == RPM_STRING_TYPE && he->c == 1)
00174             *vp = xstrdup(he->p.str);
00175         else
00176             *vp = NULL;
00177         he->p.ptr = _free(he->p.ptr);
00178     }
00179     if (rp) {
00180         he->tag = RPMTAG_RELEASE;
00181         if (headerGet(h, he, 0)
00182          && he->t == RPM_STRING_TYPE && he->c == 1)
00183             *rp = xstrdup(he->p.str);
00184         else
00185             *rp = NULL;
00186         he->p.ptr = _free(he->p.ptr);
00187     }
00188     if (ap) {
00189 #if !defined(RPM_VENDOR_OPENPKG) /* no-architecture-expose */
00190         /* do not expose the architecture as this is too less
00191            information, as in OpenPKG the "platform" is described by the
00192            architecture+operating-system combination. But as the whole
00193            "platform" information is actually overkill, just revert to the
00194            RPM 4 behaviour and do not expose any such information at all. */
00195         he->tag = RPMTAG_ARCH;
00196 /*@-observertrans -readonlytrans@*/
00197         if (!headerIsEntry(h, he->tag))
00198             *ap = xstrdup("pubkey");
00199         else
00200         if (!headerIsEntry(h, RPMTAG_SOURCERPM))
00201             *ap = xstrdup("src");
00202 /*@=observertrans =readonlytrans@*/
00203         else
00204         if (headerGet(h, he, 0)
00205          && he->t == RPM_STRING_TYPE && he->c == 1)
00206             *ap = xstrdup(he->p.str);
00207         else
00208 #endif
00209             *ap = NULL;
00210         he->p.ptr = _free(he->p.ptr);
00211     }
00212 /*@=onlytrans@*/
00213     return 0;
00214 }
00215 
00216 uint32_t hGetColor(Header h)
00217 {
00218     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
00219     uint32_t hcolor = 0;
00220     int xx;
00221 
00222     he->tag = RPMTAG_FILECOLORS;
00223     xx = headerGet(h, he, 0);
00224     if (xx && he->p.ptr != NULL && he->c > 0) {
00225         unsigned i;
00226         for (i = 0; i < (unsigned) he->c; i++)
00227             hcolor |= he->p.ui32p[i];
00228     }
00229     he->p.ptr = _free(he->p.ptr);
00230     hcolor &= 0x0f;
00231 
00232     return hcolor;
00233 }
00234 
00235 void headerMergeLegacySigs(Header h, const Header sigh)
00236 {
00237     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
00238     HeaderIterator hi;
00239     int xx;
00240 
00241     if (h == NULL || sigh == NULL)
00242         return;
00243 
00244     for (hi = headerInit(sigh);
00245         headerNext(hi, he, 0);
00246         he->p.ptr = _free(he->p.ptr))
00247     {
00248         /* XXX Translate legacy signature tag values. */
00249         switch ((rpmSigTag)he->tag) {
00250         case RPMSIGTAG_SIZE:
00251             he->tag = RPMTAG_SIGSIZE;
00252             /*@switchbreak@*/ break;
00253         case RPMSIGTAG_MD5:
00254             he->tag = RPMTAG_SIGMD5;
00255             /*@switchbreak@*/ break;
00256         case RPMSIGTAG_PAYLOADSIZE:
00257             he->tag = RPMTAG_ARCHIVESIZE;
00258             /*@switchbreak@*/ break;
00259         case RPMSIGTAG_SHA1:
00260         case RPMSIGTAG_DSA:
00261         case RPMSIGTAG_RSA:
00262         default:
00263             /* Skip all unknown tags that are not in the signature tag range. */
00264             if (!(he->tag >= HEADER_SIGBASE && he->tag < HEADER_TAGBASE))
00265                 continue;
00266             /*@switchbreak@*/ break;
00267         }
00268 assert(he->p.ptr != NULL);
00269         if (!headerIsEntry(h, he->tag)) {
00270             if (hdrchkType(he->t))
00271                 continue;
00272             if (hdrchkData(he->c))
00273                 continue;
00274             switch(he->t) {
00275             default:
00276 assert(0);      /* XXX keep gcc quiet */
00277                 /*@switchbreak@*/ break;
00278             case RPM_UINT8_TYPE:
00279             case RPM_UINT16_TYPE:
00280             case RPM_UINT32_TYPE:
00281             case RPM_UINT64_TYPE:
00282                 if (he->c != 1)
00283                     continue;
00284                 /*@switchbreak@*/ break;
00285             case RPM_STRING_TYPE:
00286             case RPM_BIN_TYPE:
00287                 if (he->c >= 16*1024)
00288                     continue;
00289                 /*@switchbreak@*/ break;
00290             case RPM_STRING_ARRAY_TYPE:
00291             case RPM_I18NSTRING_TYPE:
00292                 continue;
00293                 /*@notreached@*/ /*@switchbreak@*/ break;
00294             }
00295             xx = headerPut(h, he, 0);
00296 assert(xx == 1);
00297         }
00298     }
00299     hi = headerFini(hi);
00300 }
00301 
00302 Header headerRegenSigHeader(const Header h, int noArchiveSize)
00303 {
00304     HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
00305     Header sigh = headerNew();
00306     HeaderIterator hi;
00307     int xx;
00308 
00309     for (hi = headerInit(h);
00310         headerNext(hi, he, 0);
00311         he->p.ptr = _free(he->p.ptr))
00312     {
00313         /* XXX Translate legacy signature tag values. */
00314         switch (he->tag) {
00315         case RPMTAG_SIGSIZE:
00316             he->tag = (rpmTag) RPMSIGTAG_SIZE;
00317             /*@switchbreak@*/ break;
00318         case RPMTAG_SIGMD5:
00319             he->tag = (rpmTag) RPMSIGTAG_MD5;
00320             /*@switchbreak@*/ break;
00321         case RPMTAG_ARCHIVESIZE:
00322             /* XXX rpm-4.1 and later has archive size in signature header. */
00323             if (noArchiveSize)
00324                 continue;
00325             he->tag = (rpmTag) RPMSIGTAG_PAYLOADSIZE;
00326             /*@switchbreak@*/ break;
00327         case RPMTAG_SHA1HEADER:
00328         case RPMTAG_DSAHEADER:
00329         case RPMTAG_RSAHEADER:
00330         default:
00331             /* Skip all unknown tags that are not in the signature tag range. */
00332             if (!(he->tag >= HEADER_SIGBASE && he->tag < HEADER_TAGBASE))
00333                 continue;
00334             /*@switchbreak@*/ break;
00335         }
00336 assert(he->p.ptr != NULL);
00337         if (!headerIsEntry(sigh, he->tag)) {
00338             xx = headerPut(sigh, he, 0);
00339 assert(xx == 1);
00340         }
00341     }
00342     hi = headerFini(hi);
00343     return sigh;
00344 }

Generated on Mon Nov 29 2010 05:18:46 for rpm by  doxygen 1.7.2