7 #include <rpmfileutil.h>
10 static int reverse = -1;
14 static int IDTintcmp(const void * a, const void * b)
16 return ( reverse * (((IDT)a)->val.u32 - ((IDT)b)->val.u32) );
19 IDTX IDTXfree(IDTX idtx)
24 for (i = 0; i < idtx->nidt; i++) {
25 IDT idt = idtx->idt + i;
26 idt->h = headerFree(idt->h);
27 idt->key = _free(idt->key);
29 idtx->idt = _free(idtx->idt);
37 IDTX idtx = xcalloc(1, sizeof(*idtx));
39 idtx->size = sizeof(*((IDT)0));
43 IDTX IDTXgrow(IDTX idtx, int need)
45 if (need < 0) return NULL;
48 if (need == 0) return idtx;
50 if ((idtx->nidt + need) > idtx->alloced) {
52 idtx->alloced += idtx->delta;
55 idtx->idt = xrealloc(idtx->idt, (idtx->alloced * idtx->size) );
60 IDTX IDTXsort(IDTX idtx)
62 if (idtx != NULL && idtx->idt != NULL && idtx->nidt > 0)
63 qsort(idtx->idt, idtx->nidt, idtx->size, IDTintcmp);
67 IDTX IDTXload(rpmts ts, rpmTag tag)
70 rpmdbMatchIterator mi;
71 HGE_t hge = (HGE_t) headerGetEntry;
74 mi = rpmtsInitIterator(ts, tag, NULL, 0);
76 (void) rpmdbSetIteratorRE(mi, RPMTAG_NAME, RPMMIRE_DEFAULT, '!gpg-pubkey');
78 while ((h = rpmdbNextIterator(mi)) != NULL) {
79 rpmTagType type = RPM_NULL_TYPE;
84 if (!hge(h, tag, &type, (void **)&tidp, &count) || tidp == NULL)
87 if (type == RPM_INT32_TYPE && (*tidp == 0 || *tidp == -1))
90 idtx = IDTXgrow(idtx, 1);
93 if (idtx->idt == NULL)
97 idt = idtx->idt + idtx->nidt;
98 idt->h = headerLink(h);
100 idt->instance = rpmdbGetIteratorOffset(mi);
101 idt->val.u32 = *tidp;
105 mi = rpmdbFreeIterator(mi);
107 return IDTXsort(idtx);
110 IDTX IDTXglob(rpmts ts, const char * globstr, rpmTag tag)
113 HGE_t hge = (HGE_t) headerGetEntry;
117 const char ** av = NULL;
124 xx = rpmGlob(globstr, &ac, &av);
127 for (i = 0; i < ac; i++) {
132 fd = Fopen(av[i], "r.ufdio");
133 if (fd == NULL || Ferror(fd)) {
134 rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), av[i],
136 if (fd != NULL) (void) Fclose(fd);
140 rpmrc = rpmReadPackageFile(ts, fd, av[i], &h);
146 case RPMRC_NOTTRUSTED:
149 isSource = headerIsEntry(h, RPMTAG_SOURCEPACKAGE);
156 if (hge(h, tag, &type, (void **) &tidp, &count) && tidp != NULL) {
158 idtx = IDTXgrow(idtx, 1);
159 if (idtx == NULL || idtx->idt == NULL)
163 idt = idtx->idt + idtx->nidt;
164 idt->h = headerLink(h);
168 idt->val.u32 = *tidp;
176 for (i = 0; i < ac; i++)
177 av[i] = _free(av[i]);
178 av = _free(av); ac = 0;
180 return IDTXsort(idtx);