rpm  5.2.1
lib/formats.c
Go to the documentation of this file.
00001 
00005 #include "system.h"
00006 
00007 #include <rpmio.h>
00008 #include <rpmiotypes.h>         /* XXX fnpyKey */
00009 #include <rpmmacro.h>           /* XXX for %_i18ndomains */
00010 
00011 #define _RPMTAG_INTERNAL
00012 #include <rpmtag.h>
00013 #include <rpmtypes.h>
00014 
00015 #define _RPMEVR_INTERNAL
00016 #include <rpmds.h>
00017 #include <rpmfi.h>
00018 
00019 #include "legacy.h"
00020 #include "manifest.h"
00021 #include "argv.h"
00022 #include "fs.h"
00023 
00024 #include "debug.h"
00025 
00026 /*@access headerSprintfExtension @*/
00027 
00034 static int fsnamesTag( /*@unused@*/ Header h, HE_t he)
00035         /*@globals fileSystem, internalState @*/
00036         /*@modifies he, fileSystem, internalState @*/
00037 {
00038     const char ** list;
00039 
00040     if (rpmGetFilesystemList(&list, &he->c))
00041         return 1;
00042 
00043     he->t = RPM_STRING_ARRAY_TYPE;
00044     he->p.argv = list;
00045     he->freeData = 0;
00046 
00047     return 0;
00048 }
00049 
00056 static int fssizesTag(Header h, HE_t he)
00057         /*@globals rpmGlobalMacroContext, h_errno,
00058                 fileSystem, internalState @*/
00059         /*@modifies he, rpmGlobalMacroContext,
00060                 fileSystem, internalState @*/
00061 {
00062     rpmTagData fnames = { .ptr = NULL };
00063     rpmTagData fsizes = { .ptr = NULL };
00064     rpmTagData p;
00065     rpmuint64_t *usages;
00066     int numFiles;
00067     int rc = 1;         /* assume error */
00068     int xx, yy;
00069 
00070     p.ptr = he->p.ptr;
00071     he->tag = RPMTAG_FILESIZES;
00072     xx = headerGet(h, he, 0);
00073     fsizes.ptr = he->p.ptr;
00074     he->tag = RPMTAG_FILEPATHS;
00075     yy = headerGet(h, he, 0);
00076     fnames.ptr = he->p.ptr;
00077     numFiles = he->c;
00078     he->p.ptr = p.ptr;
00079     if (!xx || !yy) {
00080         numFiles = 0;
00081         fsizes.ui32p = _free(fsizes.ui32p);
00082         fnames.argv = _free(fnames.argv);
00083     }
00084 
00085     if (rpmGetFilesystemList(NULL, &he->c))
00086         goto exit;
00087 
00088     he->t = RPM_UINT64_TYPE;
00089     he->freeData = 1;
00090 
00091     if (fnames.ptr == NULL)
00092         usages = xcalloc(he->c, sizeof(*usages));
00093     else
00094     if (rpmGetFilesystemUsage(fnames.argv, fsizes.ui32p, numFiles, &usages, 0)) 
00095         goto exit;
00096 
00097     he->p.ui64p = usages;
00098     rc = 0;
00099 
00100 exit:
00101     fnames.ptr = _free(fnames.ptr);
00102     fsizes.ptr = _free(fsizes.ptr);
00103 
00104     return rc;
00105 }
00106 
00113 static int fileclassTag(Header h, HE_t he)
00114         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00115         /*@modifies h, he,
00116                 rpmGlobalMacroContext, fileSystem, internalState @*/
00117 {
00118     he->t = RPM_STRING_ARRAY_TYPE;
00119     rpmfiBuildFClasses(h, &he->p.argv, &he->c);
00120     he->freeData = 1;
00121     return 0;
00122 }
00123 
00130 static int filecontextsTag(Header h, HE_t he)
00131         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00132         /*@modifies h, he,
00133                 rpmGlobalMacroContext, fileSystem, internalState @*/
00134 {
00135     he->t = RPM_STRING_ARRAY_TYPE;
00136     rpmfiBuildFContexts(h, &he->p.argv, &he->c);
00137     he->freeData = 1;
00138     return 0;
00139 }
00140 
00147 static int fscontextsTag(Header h, HE_t he)
00148         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00149         /*@modifies h, he,
00150                 rpmGlobalMacroContext, fileSystem, internalState @*/
00151 {
00152     he->t = RPM_STRING_ARRAY_TYPE;
00153     rpmfiBuildFSContexts(h, &he->p.argv, &he->c);
00154     he->freeData = 1;
00155     return 0;
00156 }
00157 
00164 static int recontextsTag(Header h, HE_t he)
00165         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00166         /*@modifies h, he,
00167                 rpmGlobalMacroContext, fileSystem, internalState @*/
00168 {
00169     he->t = RPM_STRING_ARRAY_TYPE;
00170     rpmfiBuildREContexts(h, &he->p.argv, &he->c);
00171     he->freeData = 1;
00172     return 0;
00173 }
00174 
00181 static int fileprovideTag(Header h, HE_t he)
00182         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00183         /*@modifies h, he,
00184                 rpmGlobalMacroContext, fileSystem, internalState @*/
00185 {
00186     he->t = RPM_STRING_ARRAY_TYPE;
00187     rpmfiBuildFDeps(h, RPMTAG_PROVIDENAME, &he->p.argv, &he->c);
00188     he->freeData = 1;
00189     return 0;
00190 }
00191 
00198 static int filerequireTag(Header h, HE_t he)
00199         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00200         /*@modifies h, he,
00201                 rpmGlobalMacroContext, fileSystem, internalState @*/
00202 {
00203     he->t = RPM_STRING_ARRAY_TYPE;
00204     rpmfiBuildFDeps(h, RPMTAG_REQUIRENAME, &he->p.argv, &he->c);
00205     he->freeData = 1;
00206     return 0;
00207 }
00208 
00215 static int missingokTag(Header h, HE_t he)
00216         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00217         /*@modifies h, he,
00218                 rpmGlobalMacroContext, fileSystem, internalState @*/
00219 {
00220     rpmds ds = rpmdsNew(h, RPMTAG_REQUIRENAME, 0);
00221     ARGV_t av = NULL;
00222     ARGV_t argv;
00223     int argc = 0;
00224     char * t;
00225     size_t nb = 0;
00226     int i;
00227 
00228     if (ds == NULL)
00229         return 1;
00230 
00231     /* Collect dependencies marked as hints. */
00232     ds = rpmdsInit(ds);
00233     if (ds != NULL)
00234     while (rpmdsNext(ds) >= 0) {
00235         int Flags = rpmdsFlags(ds);
00236         const char * DNEVR;
00237         if (!(Flags & RPMSENSE_MISSINGOK))
00238             continue;
00239         DNEVR = rpmdsDNEVR(ds);
00240         if (DNEVR == NULL)
00241             continue;
00242         nb += sizeof(*argv) + strlen(DNEVR+2) + 1;
00243         (void) argvAdd(&av, DNEVR+2);
00244         argc++;
00245     }
00246     nb += sizeof(*argv);        /* final argv NULL */
00247 
00248     /* Create contiguous header string array. */
00249     argv = (ARGV_t) xcalloc(nb, 1);
00250     t = (char *)(argv + argc);
00251     for (i = 0; i < argc; i++) {
00252         argv[i] = t;
00253         t = stpcpy(t, av[i]);
00254         *t++ = '\0';
00255     }
00256     av = argvFree(av);
00257     (void)rpmdsFree(ds);
00258     ds = NULL;
00259 
00260     he->t = RPM_STRING_ARRAY_TYPE;
00261     he->p.argv = argv;
00262     he->c = argc;
00263     he->freeData = 1;
00264     return 0;
00265 }
00266 
00267 /*@-type@*/ /* FIX: cast? */
00268 static struct headerSprintfExtension_s _rpmHeaderFormats[] = {
00269     { HEADER_EXT_TAG, "RPMTAG_ENHANCES",
00270         { .tagFunction = missingokTag } },
00271     { HEADER_EXT_TAG, "RPMTAG_FILECLASS",
00272         { .tagFunction = fileclassTag } },
00273     { HEADER_EXT_TAG, "RPMTAG_FILECONTEXTS",
00274         { .tagFunction = filecontextsTag } },
00275     { HEADER_EXT_TAG, "RPMTAG_FILEPROVIDE",
00276         { .tagFunction = fileprovideTag } },
00277     { HEADER_EXT_TAG, "RPMTAG_FILEREQUIRE",
00278         { .tagFunction = filerequireTag } },
00279     { HEADER_EXT_TAG, "RPMTAG_FSCONTEXTS",
00280         { .tagFunction = fscontextsTag } },
00281     { HEADER_EXT_TAG, "RPMTAG_FSNAMES", 
00282         { .tagFunction = fsnamesTag } },
00283     { HEADER_EXT_TAG, "RPMTAG_FSSIZES",
00284         { .tagFunction = fssizesTag } },
00285     { HEADER_EXT_TAG, "RPMTAG_RECONTEXTS",
00286         { .tagFunction = recontextsTag } },
00287     { HEADER_EXT_TAG, "RPMTAG_SUGGESTS",
00288         { .tagFunction = missingokTag } },
00289     { HEADER_EXT_MORE, NULL,            { (void *) &headerCompoundFormats } }
00290 } ;
00291 /*@=type@*/
00292 
00293 headerSprintfExtension rpmHeaderFormats = &_rpmHeaderFormats[0];