00001
00006 #include "system.h"
00007
00008 #include "rpmbuild.h"
00009 #include "debug.h"
00010
00011 int addReqProv( Spec spec, Header h, rpmTag tagN,
00012 const char * N, const char * EVR, rpmsenseFlags Flags,
00013 int index)
00014 {
00015 HGE_t hge = (HGE_t)headerGetEntryMinMemory;
00016 HFD_t hfd = headerFreeData;
00017 const char ** names;
00018 rpmTagType dnt;
00019 rpmTag nametag = 0;
00020 rpmTag versiontag = 0;
00021 rpmTag flagtag = 0;
00022 rpmTag indextag = 0;
00023 int len;
00024 rpmsenseFlags extra = RPMSENSE_ANY;
00025 int xx;
00026
00027 if (Flags & RPMSENSE_PROVIDES) {
00028 nametag = RPMTAG_PROVIDENAME;
00029 versiontag = RPMTAG_PROVIDEVERSION;
00030 flagtag = RPMTAG_PROVIDEFLAGS;
00031 extra = Flags & RPMSENSE_FIND_PROVIDES;
00032 } else if (Flags & RPMSENSE_OBSOLETES) {
00033 nametag = RPMTAG_OBSOLETENAME;
00034 versiontag = RPMTAG_OBSOLETEVERSION;
00035 flagtag = RPMTAG_OBSOLETEFLAGS;
00036 } else if (Flags & RPMSENSE_CONFLICTS) {
00037 nametag = RPMTAG_CONFLICTNAME;
00038 versiontag = RPMTAG_CONFLICTVERSION;
00039 flagtag = RPMTAG_CONFLICTFLAGS;
00040 } else if (Flags & RPMSENSE_PREREQ) {
00041 nametag = RPMTAG_REQUIRENAME;
00042 versiontag = RPMTAG_REQUIREVERSION;
00043 flagtag = RPMTAG_REQUIREFLAGS;
00044 extra = Flags & _ALL_REQUIRES_MASK;
00045 } else if (Flags & RPMSENSE_TRIGGER) {
00046 nametag = RPMTAG_TRIGGERNAME;
00047 versiontag = RPMTAG_TRIGGERVERSION;
00048 flagtag = RPMTAG_TRIGGERFLAGS;
00049 indextag = RPMTAG_TRIGGERINDEX;
00050 extra = Flags & RPMSENSE_TRIGGER;
00051 } else {
00052 nametag = RPMTAG_REQUIRENAME;
00053 versiontag = RPMTAG_REQUIREVERSION;
00054 flagtag = RPMTAG_REQUIREFLAGS;
00055 extra = Flags & _ALL_REQUIRES_MASK;
00056 }
00057
00058 Flags = (Flags & RPMSENSE_SENSEMASK) | extra;
00059
00060
00061 if (EVR == NULL)
00062 EVR = "";
00063
00064
00065
00066 if (hge(h, nametag, &dnt, (void **) &names, &len)) {
00067 const char ** versions = NULL;
00068 rpmTagType dvt = RPM_STRING_ARRAY_TYPE;
00069 int *flags = NULL;
00070 int *indexes = NULL;
00071 int duplicate = 0;
00072
00073 if (flagtag) {
00074 xx = hge(h, versiontag, &dvt, (void **) &versions, NULL);
00075 xx = hge(h, flagtag, NULL, (void **) &flags, NULL);
00076 }
00077 if (indextag)
00078 xx = hge(h, indextag, NULL, (void **) &indexes, NULL);
00079
00080
00081 while (len > 0) {
00082 len--;
00083 if (strcmp(names[len], N))
00084 continue;
00085 if (flagtag && versions != NULL &&
00086 (strcmp(versions[len], EVR) || flags[len] != Flags))
00087 continue;
00088 if (indextag && indexes != NULL && indexes[len] != index)
00089 continue;
00090
00091
00092 duplicate = 1;
00093
00094 break;
00095 }
00096
00097 names = hfd(names, dnt);
00098 versions = hfd(versions, dvt);
00099 if (duplicate)
00100 return 0;
00101 }
00102
00103
00104 xx = headerAddOrAppendEntry(h, nametag, RPM_STRING_ARRAY_TYPE, &N, 1);
00105 if (flagtag) {
00106 xx = headerAddOrAppendEntry(h, versiontag,
00107 RPM_STRING_ARRAY_TYPE, &EVR, 1);
00108 xx = headerAddOrAppendEntry(h, flagtag,
00109 RPM_INT32_TYPE, &Flags, 1);
00110 }
00111 if (indextag)
00112 xx = headerAddOrAppendEntry(h, indextag, RPM_INT32_TYPE, &index, 1);
00113
00114 return 0;
00115 }
00116
00117
00118 int rpmlibNeedsFeature(Header h, const char * feature, const char * featureEVR)
00119 {
00120 char * reqname = alloca(sizeof("rpmlib()") + strlen(feature));
00121
00122 (void) stpcpy( stpcpy( stpcpy(reqname, "rpmlib("), feature), ")");
00123
00124
00125 return addReqProv(NULL, h, RPMTAG_REQUIRENAME, reqname, featureEVR,
00126 RPMSENSE_RPMLIB|(RPMSENSE_LESS|RPMSENSE_EQUAL), 0);
00127 }
00128