rpm 5.2.1

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

- File List
- Globals

reqprov.c
Go to the documentation of this file.
1
6 #include "system.h"
7
8 #include <rpmio.h>
9 #include <rpmiotypes.h>
10 #define _RPMEVR_INTERNAL
11 #include "rpmbuild.h"
12 #include "debug.h"
13
14 int addReqProv(/*@unused@*/ Spec spec, Header h,
15 /*@unused@*/ rpmTag tagN,
16 const char * N, const char * EVR, rpmsenseFlags Flags,
17 rpmuint32_t index)
18 {
19 HE_t he = memset(alloca(sizeof(*he)), 0, sizeof(*he));
20 const char ** names;
21 rpmTag nametag = 0;
22 rpmTag versiontag = 0;
23 rpmTag flagtag = 0;
24 rpmTag indextag = 0;
25 int len;
26 rpmsenseFlags extra = RPMSENSE_ANY;
27 int xx;
28
29 if (Flags & RPMSENSE_PROVIDES) {
30 nametag = RPMTAG_PROVIDENAME;
31 versiontag = RPMTAG_PROVIDEVERSION;
32 flagtag = RPMTAG_PROVIDEFLAGS;
33 extra = Flags & RPMSENSE_FIND_PROVIDES;
34 } else if (Flags & RPMSENSE_OBSOLETES) {
35 nametag = RPMTAG_OBSOLETENAME;
36 versiontag = RPMTAG_OBSOLETEVERSION;
37 flagtag = RPMTAG_OBSOLETEFLAGS;
38 } else if (Flags & RPMSENSE_CONFLICTS) {
39 nametag = RPMTAG_CONFLICTNAME;
40 versiontag = RPMTAG_CONFLICTVERSION;
41 flagtag = RPMTAG_CONFLICTFLAGS;
42 } else if (Flags & RPMSENSE_TRIGGER) {
43 nametag = RPMTAG_TRIGGERNAME;
44 versiontag = RPMTAG_TRIGGERVERSION;
45 flagtag = RPMTAG_TRIGGERFLAGS;
46 indextag = RPMTAG_TRIGGERINDEX;
47 extra = Flags & RPMSENSE_TRIGGER;
48 } else {
49 nametag = RPMTAG_REQUIRENAME;
50 versiontag = RPMTAG_REQUIREVERSION;
51 flagtag = RPMTAG_REQUIREFLAGS;
52 extra = Flags & _ALL_REQUIRES_MASK;
53 }
54
55 Flags = (Flags & RPMSENSE_SENSEMASK) | extra;
56
57 if (EVR == NULL)
58 EVR = "";
59
60 /* Check for duplicate dependencies. */
61 he->tag = nametag;
62 xx = headerGet(h, he, 0);
63 names = he->p.argv;
64 len = he->c;
65 if (xx) {
66 const char ** versions = NULL;
67 rpmuint32_t * flags = NULL;
68 rpmuint32_t * indexes = NULL;
69 int duplicate = 0;
70
71 if (flagtag) {
72 he->tag = versiontag;
73 xx = headerGet(h, he, 0);
74 versions = he->p.argv;
75 he->tag = flagtag;
76 xx = headerGet(h, he, 0);
77 flags = he->p.ui32p;
78 }
79 if (indextag) {
80 he->tag = indextag;
81 xx = headerGet(h, he, 0);
82 indexes = he->p.ui32p;
83 }
84
85 while (len > 0) {
86 len--;
87 if (strcmp(names[len], N))
88 continue;
89 if (flagtag && versions != NULL &&
90 (strcmp(versions[len], EVR) || (rpmsenseFlags)flags[len] != Flags))
91 continue;
92 if (indextag && indexes != NULL && indexes[len] != index)
93 continue;
94
95 /* This is a duplicate dependency. */
96 duplicate = 1;
97
98 break;
99 }
100 /*@-usereleased@*/
101 names = _free(names);
102 versions = _free(versions);
103 flags = _free(flags);
104 indexes = _free(indexes);
105 /*@=usereleased@*/
106 if (duplicate)
107 return 0;
108 }
109
110 /* Add this dependency. */
111 he->tag = nametag;
112 he->t = RPM_STRING_ARRAY_TYPE;
113 he->p.argv = &N;
114 he->c = 1;
115 he->append = 1;
116 xx = headerPut(h, he, 0);
117 he->append = 0;
118
119 if (flagtag) {
120 he->tag = versiontag;
121 he->t = RPM_STRING_ARRAY_TYPE;
122 he->p.argv = &EVR;
123 he->c = 1;
124 he->append = 1;
125 xx = headerPut(h, he, 0);
126 he->append = 0;
127
128 he->tag = flagtag;
129 he->t = RPM_UINT32_TYPE;
130 he->p.ui32p = (rpmuint32_t *) &Flags;
131 he->c = 1;
132 he->append = 1;
133 xx = headerPut(h, he, 0);
134 he->append = 0;
135 }
136 if (indextag) {
137 he->tag = indextag;
138 he->t = RPM_UINT32_TYPE;
139 he->p.ui32p = &index;
140 he->c = 1;
141 he->append = 1;
142 xx = headerPut(h, he, 0);
143 he->append = 0;
144 }
145
146 return 0;
147 }
148
149 int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
150 {
151 char * reqname = alloca(sizeof("rpmlib()") + strlen(feature));
152
153 (void) stpcpy( stpcpy( stpcpy(reqname, "rpmlib("), feature), ")");
154
155 /* XXX 1st arg is unused */
156 return addReqProv(NULL, h, RPMTAG_REQUIRENAME, reqname, featureEVR,
157 RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL), 0);
158 }