- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# lib/formats.c

Go to the documentation of this file.

    00001
    00005 #include "system.h"
    00006
    00007 #include <rpmio.h>
    00008 #include <rpmcb.h>              /* XXX fnpyKey */
    00009 #include <rpmmacro.h>           /* XXX for %_i18ndomains */
    00010
    00011 #define _RPMTAG_INTERNAL
    00012 #include <rpmtag.h>
    00013 #include <rpmlib.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     uint64_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 assert(ds != NULL);
    00229     /* Collect dependencies marked as hints. */
    00230     ds = rpmdsInit(ds);
    00231     if (ds != NULL)
    00232     while (rpmdsNext(ds) >= 0) {
    00233         int Flags = rpmdsFlags(ds);
    00234         const char * DNEVR;
    00235         if (!(Flags & RPMSENSE_MISSINGOK))
    00236             continue;
    00237         DNEVR = rpmdsDNEVR(ds);
    00238         if (DNEVR == NULL)
    00239             continue;
    00240         nb += sizeof(*argv) + strlen(DNEVR+2) + 1;
    00241         (void) argvAdd(&av, DNEVR+2);
    00242         argc++;
    00243     }
    00244     nb += sizeof(*argv);        /* final argv NULL */
    00245
    00246     /* Create contiguous header string array. */
    00247     argv = (ARGV_t) xcalloc(nb, 1);
    00248     t = (char *)(argv + argc);
    00249     for (i = 0; i < argc; i++) {
    00250         argv[i] = t;
    00251         t = stpcpy(t, av[i]);
    00252         *t++ = '\0';
    00253     }
    00254     av = argvFree(av);
    00255     ds = rpmdsFree(ds);
    00256
    00257     /* XXX perhaps return "(none)" inband if no suggests/enhances <shrug>. */
    00258
    00259     he->t = RPM_STRING_ARRAY_TYPE;
    00260     he->p.argv = argv;
    00261     he->c = argc;
    00262     he->freeData = 1;
    00263     return 0;
    00264 }
    00265
    00266 /*@-type@*/ /* FIX: cast? */
    00267 static struct headerSprintfExtension_s _rpmHeaderFormats[] = {
    00268     { HEADER_EXT_TAG, "RPMTAG_ENHANCES",
    00269         { .tagFunction = missingokTag } },
    00270     { HEADER_EXT_TAG, "RPMTAG_FILECLASS",
    00271         { .tagFunction = fileclassTag } },
    00272     { HEADER_EXT_TAG, "RPMTAG_FILECONTEXTS",
    00273         { .tagFunction = filecontextsTag } },
    00274     { HEADER_EXT_TAG, "RPMTAG_FILEPROVIDE",
    00275         { .tagFunction = fileprovideTag } },
    00276     { HEADER_EXT_TAG, "RPMTAG_FILEREQUIRE",
    00277         { .tagFunction = filerequireTag } },
    00278     { HEADER_EXT_TAG, "RPMTAG_FSCONTEXTS",
    00279         { .tagFunction = fscontextsTag } },
    00280     { HEADER_EXT_TAG, "RPMTAG_FSNAMES",
    00281         { .tagFunction = fsnamesTag } },
    00282     { HEADER_EXT_TAG, "RPMTAG_FSSIZES",
    00283         { .tagFunction = fssizesTag } },
    00284     { HEADER_EXT_TAG, "RPMTAG_RECONTEXTS",
    00285         { .tagFunction = recontextsTag } },
    00286     { HEADER_EXT_TAG, "RPMTAG_SUGGESTS",
    00287         { .tagFunction = missingokTag } },
    00288     { HEADER_EXT_MORE, NULL,            { (void *) &headerCompoundFormats } }
    00289 } ;
    00290 /*@=type@*/
    00291
    00292 headerSprintfExtension rpmHeaderFormats = &_rpmHeaderFormats[0];