Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

rpmdb/hdrNVR.c

Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 #include <rpmlib.h>
00007 #include <rpmmacro.h>
00008 #include "debug.h"
00009 
00014 /*@observer@*/ /*@unchecked@*/
00015 static struct tagMacro {
00016 /*@observer@*/ /*@null@*/
00017     const char *macroname;      
00018     rpmTag      tag;            
00019 } tagMacros[] = {
00020     { "name",           RPMTAG_NAME },
00021     { "version",        RPMTAG_VERSION },
00022     { "release",        RPMTAG_RELEASE },
00023     { "epoch",          RPMTAG_EPOCH },
00024     { "arch",           RPMTAG_ARCH },
00025     { "os",             RPMTAG_OS },
00026     { NULL, 0 }
00027 };
00028 
00029 int headerMacrosLoad(Header h)
00030 {
00031     struct tagMacro * tagm;
00032     union {
00033         const void * ptr;
00034 /*@unused@*/
00035         const char ** argv;
00036         const char * str;
00037         int_32 * i32p;
00038     } body;
00039     char numbuf[32];
00040     int_32 type;
00041     int xx;
00042 
00043     /* XXX pre-expand %{buildroot} (if any) */
00044     {   const char *s = rpmExpand("%{?buildroot}", NULL);
00045         if (s && *s) 
00046             (void) addMacro(NULL, "..buildroot", NULL, s, -1);
00047         s = _free(s);
00048     }
00049     {   const char *s = rpmExpand("%{?_builddir}", NULL);
00050         if (s && *s) 
00051             (void) addMacro(NULL, ".._builddir", NULL, s, -1);
00052         s = _free(s);
00053     }
00054 
00055     for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
00056         xx = headerGetEntryMinMemory(h, tagm->tag, &type, (hPTR_t *) &body.ptr, NULL);
00057         if (!xx)
00058             continue;
00059         switch (type) {
00060         case RPM_INT32_TYPE:
00061 /*@-boundsread@*/
00062             sprintf(numbuf, "%d", *body.i32p);
00063 /*@=boundsread@*/
00064             addMacro(NULL, tagm->macroname, NULL, numbuf, -1);
00065             /*@switchbreak@*/ break;
00066         case RPM_STRING_TYPE:
00067             addMacro(NULL, tagm->macroname, NULL, body.str, -1);
00068             /*@switchbreak@*/ break;
00069         case RPM_STRING_ARRAY_TYPE:
00070         case RPM_I18NSTRING_TYPE:
00071         case RPM_BIN_TYPE:
00072             body.ptr = headerFreeData(body.ptr, type);
00073             /*@fallthrough@*/
00074         case RPM_NULL_TYPE:
00075         case RPM_CHAR_TYPE:
00076         case RPM_INT8_TYPE:
00077         case RPM_INT16_TYPE:
00078         default:
00079             /*@switchbreak@*/ break;
00080         }
00081     }
00082     return 0;
00083 }
00084 int headerMacrosUnload(Header h)
00085 {
00086     struct tagMacro * tagm;
00087     union {
00088         const void * ptr;
00089 /*@unused@*/
00090         const char ** argv;
00091         const char * str;
00092         int_32 * i32p;
00093     } body;
00094     int_32 type;
00095     int xx;
00096 
00097     for (tagm = tagMacros; tagm->macroname != NULL; tagm++) {
00098         xx = headerGetEntryMinMemory(h, tagm->tag, &type, (hPTR_t *) &body.ptr, NULL);
00099         if (!xx)
00100             continue;
00101         switch (type) {
00102         case RPM_INT32_TYPE:
00103             delMacro(NULL, tagm->macroname);
00104             /*@switchbreak@*/ break;
00105         case RPM_STRING_TYPE:
00106             delMacro(NULL, tagm->macroname);
00107             /*@switchbreak@*/ break;
00108         case RPM_STRING_ARRAY_TYPE:
00109         case RPM_I18NSTRING_TYPE:
00110         case RPM_BIN_TYPE:
00111             body.ptr = headerFreeData(body.ptr, type);
00112             /*@fallthrough@*/
00113         case RPM_NULL_TYPE:
00114         case RPM_CHAR_TYPE:
00115         case RPM_INT8_TYPE:
00116         case RPM_INT16_TYPE:
00117         default:
00118             /*@switchbreak@*/ break;
00119         }
00120     }
00121 
00122     /* XXX restore previous %{buildroot} (if any) */
00123     {   const char *s = rpmExpand("%{?_builddir}", NULL);
00124         if (s && *s) 
00125             (void) delMacro(NULL, "_builddir");
00126         s = _free(s);
00127     }
00128     {   const char *s = rpmExpand("%{?buildroot}", NULL);
00129         if (s && *s) 
00130             (void) delMacro(NULL, "buildroot");
00131         s = _free(s);
00132     }
00133 
00134     return 0;
00135 }
00136 
00137 int headerNVR(Header h, const char **np, const char **vp, const char **rp)
00138 {
00139     int type;
00140     int count;
00141 
00142 /*@-boundswrite@*/
00143     if (np) {
00144         if (!(headerGetEntry(h, RPMTAG_NAME, &type, (void **) np, &count)
00145             && type == RPM_STRING_TYPE && count == 1))
00146                 *np = NULL;
00147     }
00148     if (vp) {
00149         if (!(headerGetEntry(h, RPMTAG_VERSION, &type, (void **) vp, &count)
00150             && type == RPM_STRING_TYPE && count == 1))
00151                 *vp = NULL;
00152     }
00153     if (rp) {
00154         if (!(headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) rp, &count)
00155             && type == RPM_STRING_TYPE && count == 1))
00156                 *rp = NULL;
00157     }
00158 /*@=boundswrite@*/
00159     return 0;
00160 }
00161 
00162 int headerNEVRA(Header h, const char **np,
00163                 /*@unused@*/ const char **ep, const char **vp, const char **rp,
00164                 const char **ap)
00165 {
00166     int type;
00167     int count;
00168 
00169 /*@-boundswrite@*/
00170     if (np) {
00171         if (!(headerGetEntry(h, RPMTAG_NAME, &type, (void **) np, &count)
00172             && type == RPM_STRING_TYPE && count == 1))
00173                 *np = NULL;
00174     }
00175     if (vp) {
00176         if (!(headerGetEntry(h, RPMTAG_VERSION, &type, (void **) vp, &count)
00177             && type == RPM_STRING_TYPE && count == 1))
00178                 *vp = NULL;
00179     }
00180     if (rp) {
00181         if (!(headerGetEntry(h, RPMTAG_RELEASE, &type, (void **) rp, &count)
00182             && type == RPM_STRING_TYPE && count == 1))
00183                 *rp = NULL;
00184     }
00185     if (ap) {
00186         if (!(headerGetEntry(h, RPMTAG_ARCH, &type, (void **) ap, &count)
00187             && type == RPM_STRING_TYPE && count == 1))
00188                 *ap = NULL;
00189     }
00190 /*@=boundswrite@*/
00191     return 0;
00192 }
00193 
00194 char * hGetNEVR(Header h, const char ** np)
00195 {
00196     const char * n, * v, * r;
00197     char * NVR, * t;
00198 
00199     (void) headerNVR(h, &n, &v, &r);
00200     NVR = t = xcalloc(1, strlen(n) + strlen(v) + strlen(r) + sizeof("--"));
00201 /*@-boundswrite@*/
00202     t = stpcpy(t, n);
00203     t = stpcpy(t, "-");
00204     t = stpcpy(t, v);
00205     t = stpcpy(t, "-");
00206     t = stpcpy(t, r);
00207     if (np)
00208         *np = n;
00209 /*@=boundswrite@*/
00210     return NVR;
00211 }
00212 
00213 char * hGetNEVRA(Header h, const char ** np)
00214 {
00215     const char * n, * v, * r, * a;
00216     char * NVRA, * t;
00217 
00218     (void) headerNVR(h, &n, &v, &r);
00219     /* XXX pubkeys have no arch. */
00220 /*@-branchstate@*/
00221     a = NULL;
00222     if (!headerGetEntry(h, RPMTAG_ARCH, NULL, &a, NULL) || a == NULL)
00223         a = "pubkey";
00224 /*@=branchstate@*/
00225     NVRA = t = xcalloc(1, strlen(n) + strlen(v) + strlen(r) + strlen(a) + sizeof("--."));
00226 /*@-boundswrite@*/
00227     t = stpcpy(t, n);
00228     t = stpcpy(t, "-");
00229     t = stpcpy(t, v);
00230     t = stpcpy(t, "-");
00231     t = stpcpy(t, r);
00232     t = stpcpy(t, ".");
00233     t = stpcpy(t, a);
00234     if (np)
00235         *np = n;
00236 /*@=boundswrite@*/
00237     return NVRA;
00238 }
00239 
00240 uint_32 hGetColor(Header h)
00241 {
00242     HGE_t hge = (HGE_t)headerGetEntryMinMemory;
00243     uint_32 hcolor = 0;
00244     uint_32 * fcolors;
00245     int_32 ncolors;
00246     int i;
00247 
00248     fcolors = NULL;
00249     ncolors = 0;
00250     if (hge(h, RPMTAG_FILECOLORS, NULL, &fcolors, &ncolors)
00251      && fcolors != NULL && ncolors > 0)
00252     {
00253 /*@-boundsread@*/
00254         for (i = 0; i < ncolors; i++)
00255             hcolor |= fcolors[i];
00256 /*@=boundsread@*/
00257     }
00258     hcolor &= 0x0f;
00259 
00260     return hcolor;
00261 }

Generated on Wed Dec 28 00:13:33 2016 for rpm by  doxygen 1.4.4