rpm 5.3.12
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 
00124 #ifdef  DYING
00125 
00131 static int filecontextsTag(Header h, HE_t he)
00132         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00133         /*@modifies h, he,
00134                 rpmGlobalMacroContext, fileSystem, internalState @*/
00135 {
00136     he->t = RPM_STRING_ARRAY_TYPE;
00137     rpmfiBuildFContexts(h, &he->p.argv, &he->c);
00138     he->freeData = 1;
00139     return 0;
00140 }
00141 
00148 static int fscontextsTag(Header h, HE_t he)
00149         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00150         /*@modifies h, he,
00151                 rpmGlobalMacroContext, fileSystem, internalState @*/
00152 {
00153     he->t = RPM_STRING_ARRAY_TYPE;
00154     rpmfiBuildFSContexts(h, &he->p.argv, &he->c);
00155     he->freeData = 1;
00156     return 0;
00157 }
00158 
00165 static int recontextsTag(Header h, HE_t he)
00166         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00167         /*@modifies h, he,
00168                 rpmGlobalMacroContext, fileSystem, internalState @*/
00169 {
00170     he->t = RPM_STRING_ARRAY_TYPE;
00171     rpmfiBuildREContexts(h, &he->p.argv, &he->c);
00172     he->freeData = 1;
00173     return 0;
00174 }
00175 #endif
00176 
00183 static int fileprovideTag(Header h, HE_t he)
00184         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00185         /*@modifies h, he,
00186                 rpmGlobalMacroContext, fileSystem, internalState @*/
00187 {
00188     he->t = RPM_STRING_ARRAY_TYPE;
00189     rpmfiBuildFDeps(h, RPMTAG_PROVIDENAME, &he->p.argv, &he->c);
00190     he->freeData = 1;
00191     return 0;
00192 }
00193 
00200 static int filerequireTag(Header h, HE_t he)
00201         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00202         /*@modifies h, he,
00203                 rpmGlobalMacroContext, fileSystem, internalState @*/
00204 {
00205     he->t = RPM_STRING_ARRAY_TYPE;
00206     rpmfiBuildFDeps(h, RPMTAG_REQUIRENAME, &he->p.argv, &he->c);
00207     he->freeData = 1;
00208     return 0;
00209 }
00210 
00217 static int missingokTag(Header h, HE_t he)
00218         /*@globals rpmGlobalMacroContext, h_errno, fileSystem, internalState @*/
00219         /*@modifies h, he,
00220                 rpmGlobalMacroContext, fileSystem, internalState @*/
00221 {
00222     rpmds ds = rpmdsNew(h, RPMTAG_REQUIRENAME, 0);
00223     ARGV_t av = NULL;
00224     ARGV_t argv;
00225     int argc = 0;
00226     char * t;
00227     size_t nb = 0;
00228     int i;
00229 
00230     if (ds == NULL)
00231         return 1;
00232 
00233     /* Collect dependencies marked as hints. */
00234     ds = rpmdsInit(ds);
00235     if (ds != NULL)
00236     while (rpmdsNext(ds) >= 0) {
00237         int Flags = rpmdsFlags(ds);
00238         const char * DNEVR;
00239         if (!(Flags & RPMSENSE_MISSINGOK))
00240             continue;
00241         DNEVR = rpmdsDNEVR(ds);
00242         if (DNEVR == NULL)
00243             continue;
00244         nb += sizeof(*argv) + strlen(DNEVR+2) + 1;
00245         (void) argvAdd(&av, DNEVR+2);
00246         argc++;
00247     }
00248     nb += sizeof(*argv);        /* final argv NULL */
00249 
00250     /* Create contiguous header string array. */
00251     argv = (ARGV_t) xcalloc(nb, 1);
00252     t = (char *)(argv + argc);
00253     for (i = 0; i < argc; i++) {
00254         argv[i] = t;
00255         t = stpcpy(t, av[i]);
00256         *t++ = '\0';
00257     }
00258     av = argvFree(av);
00259     (void)rpmdsFree(ds);
00260     ds = NULL;
00261 
00262     he->t = RPM_STRING_ARRAY_TYPE;
00263     he->p.argv = argv;
00264     he->c = argc;
00265     he->freeData = 1;
00266     return 0;
00267 }
00268 
00269 /*@-type@*/ /* FIX: cast? */
00270 static struct headerSprintfExtension_s _rpmHeaderFormats[] = {
00271     { HEADER_EXT_TAG, "RPMTAG_ENHANCES",
00272         { .tagFunction = missingokTag } },
00273     { HEADER_EXT_TAG, "RPMTAG_FILECLASS",
00274         { .tagFunction = fileclassTag } },
00275 #ifdef  DYING
00276     { HEADER_EXT_TAG, "RPMTAG_FILECONTEXTS",
00277         { .tagFunction = filecontextsTag } },
00278 #endif
00279     { HEADER_EXT_TAG, "RPMTAG_FILEPROVIDE",
00280         { .tagFunction = fileprovideTag } },
00281     { HEADER_EXT_TAG, "RPMTAG_FILEREQUIRE",
00282         { .tagFunction = filerequireTag } },
00283 #ifdef  DYING
00284     { HEADER_EXT_TAG, "RPMTAG_FSCONTEXTS",
00285         { .tagFunction = fscontextsTag } },
00286 #endif
00287     { HEADER_EXT_TAG, "RPMTAG_FSNAMES", 
00288         { .tagFunction = fsnamesTag } },
00289     { HEADER_EXT_TAG, "RPMTAG_FSSIZES",
00290         { .tagFunction = fssizesTag } },
00291 #ifdef  DYING
00292     { HEADER_EXT_TAG, "RPMTAG_RECONTEXTS",
00293         { .tagFunction = recontextsTag } },
00294 #endif
00295     { HEADER_EXT_TAG, "RPMTAG_SUGGESTS",
00296         { .tagFunction = missingokTag } },
00297     { HEADER_EXT_MORE, NULL,            { (void *) &headerCompoundFormats } }
00298 } ;
00299 /*@=type@*/
00300 
00301 headerSprintfExtension rpmHeaderFormats = &_rpmHeaderFormats[0];