#include "system.h"
-#include "rpmbuild.h"
+#include <rpm/rpmtypes.h>
+#include <rpm/rpmbuild.h>
+#include <rpm/rpmlog.h>
+#include "debug.h"
+/**
+ */
static struct ReqComp {
- char *token;
- int sense;
-} ReqComparisons[] = {
+const char * token;
+ rpmsenseFlags sense;
+} const ReqComparisons[] = {
{ "<=", RPMSENSE_LESS | RPMSENSE_EQUAL},
{ "=<", RPMSENSE_LESS | RPMSENSE_EQUAL},
{ "<", RPMSENSE_LESS},
{ NULL, 0 },
};
-#define SKIPWHITE(_x) {while(*(_x) && (isspace(*_x) || *(_x) == ',')) (_x)++;}
-#define SKIPNONWHITE(_x){while(*(_x) &&!(isspace(*_x) || *(_x) == ',')) (_x)++;}
+#define SKIPWHITE(_x) {while(*(_x) && (risspace(*_x) || *(_x) == ',')) (_x)++;}
+#define SKIPNONWHITE(_x){while(*(_x) &&!(risspace(*_x) || *(_x) == ',')) (_x)++;}
-/** */
-int parseRCPOT(Spec spec, Package pkg, const char *field, int tag,
- int index, int tagflags)
+rpmRC parseRCPOT(rpmSpec spec, Package pkg, const char *field, rpmTag tagN,
+ int index, rpmsenseFlags tagflags)
{
const char *r, *re, *v, *ve;
- char *req, *version;
+ char * N, * EVR;
+ rpmsenseFlags Flags;
Header h;
- int flags;
- switch (tag) {
+ switch (tagN) {
case RPMTAG_PROVIDEFLAGS:
tagflags |= RPMSENSE_PROVIDES;
h = pkg->header;
h = spec->buildRestrictions;
break;
case RPMTAG_PREREQ:
- tagflags |= RPMSENSE_PREREQ;
+ /* XXX map legacy PreReq into Requires(pre,preun) */
+ tagflags |= (RPMSENSE_SCRIPT_PRE|RPMSENSE_SCRIPT_PREUN);
h = pkg->header;
break;
- case RPMTAG_BUILDPREREQ:
- tagflags |= RPMSENSE_PREREQ;
- h = spec->buildRestrictions;
+ case RPMTAG_TRIGGERPREIN:
+ tagflags |= RPMSENSE_TRIGGERPREIN;
+ h = pkg->header;
break;
case RPMTAG_TRIGGERIN:
tagflags |= RPMSENSE_TRIGGERIN;
tagflags |= RPMSENSE_TRIGGERUN;
h = pkg->header;
break;
+ case RPMTAG_BUILDPREREQ:
case RPMTAG_BUILDREQUIRES:
tagflags |= RPMSENSE_ANY;
h = spec->buildRestrictions;
break;
}
- for (r = field; *r; r = re) {
+ for (r = field; *r != '\0'; r = re) {
SKIPWHITE(r);
if (*r == '\0')
break;
- flags = (tagflags & ~RPMSENSE_SENSEMASK);
+ Flags = (tagflags & ~RPMSENSE_SENSEMASK);
- /* Tokens must begin with alphanumeric, _, or / */
- if (!(isalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
- rpmError(RPMERR_BADSPEC,
- _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s"),
+ /*
+ * Tokens must begin with alphanumeric, _, or /, but we don't know
+ * the spec's encoding so we only check what we can: plain ascii.
+ */
+ if (isascii(r[0]) && !(risalnum(r[0]) || r[0] == '_' || r[0] == '/')) {
+ rpmlog(RPMLOG_ERR,
+ _("line %d: Dependency tokens must begin with alpha-numeric, '_' or '/': %s\n"),
spec->lineNum, spec->line);
- return RPMERR_BADSPEC;
- }
-
- /* Don't permit file names as args for certain tags */
- switch (tag) {
- case RPMTAG_OBSOLETEFLAGS:
- case RPMTAG_CONFLICTFLAGS:
- case RPMTAG_BUILDCONFLICTS:
- if (r[0] == '/') {
- rpmError(RPMERR_BADSPEC,_("line %d: File name not permitted: %s"),
- spec->lineNum, spec->line);
- return RPMERR_BADSPEC;
- }
- break;
- default:
- break;
+ return RPMRC_FAIL;
}
re = r;
SKIPNONWHITE(re);
- req = xmalloc((re-r) + 1);
- strncpy(req, r, (re-r));
- req[re-r] = '\0';
+ N = xmalloc((re-r) + 1);
+ rstrlcpy(N, r, (re-r) + 1);
- /* Parse version */
+ /* Parse EVR */
v = re;
SKIPWHITE(v);
ve = v;
SKIPNONWHITE(ve);
- re = v; /* ==> next token (if no version found) starts here */
+ re = v; /* ==> next token (if no EVR found) starts here */
/* Check for possible logical operator */
if (ve > v) {
- struct ReqComp *rc;
+ const struct ReqComp *rc;
for (rc = ReqComparisons; rc->token != NULL; rc++) {
- if ((ve-v) != strlen(rc->token) || strncmp(v, rc->token, (ve-v)))
+ if ((ve-v) != strlen(rc->token) || !rstreqn(v, rc->token, (ve-v)))
continue;
if (r[0] == '/') {
- rpmError(RPMERR_BADSPEC,
- _("line %d: Versioned file name not permitted: %s"),
+ rpmlog(RPMLOG_ERR,
+ _("line %d: Versioned file name not permitted: %s\n"),
spec->lineNum, spec->line);
- return RPMERR_BADSPEC;
+ return RPMRC_FAIL;
}
- switch(tag) {
+ switch(tagN) {
case RPMTAG_BUILDPREREQ:
case RPMTAG_PREREQ:
case RPMTAG_PROVIDEFLAGS:
case RPMTAG_OBSOLETEFLAGS:
/* Add prereq on rpmlib that has versioned dependencies. */
- if (!rpmExpandNumeric("%{_noVersionedDependencies}"))
- rpmlibNeedsFeature(h, "VersionedDependencies", "3.0.3-1");
+ if (!rpmExpandNumeric("%{?_noVersionedDependencies}"))
+ (void) rpmlibNeedsFeature(h, "VersionedDependencies", "3.0.3-1");
break;
default:
break;
}
- flags |= rc->sense;
+ Flags |= rc->sense;
- /* now parse version */
+ /* now parse EVR */
v = ve;
SKIPWHITE(v);
ve = v;
}
}
- if (flags & RPMSENSE_SENSEMASK) {
+ if (Flags & RPMSENSE_SENSEMASK) {
if (*v == '\0' || ve == v) {
- rpmError(RPMERR_BADSPEC, _("line %d: Version required: %s"),
+ rpmlog(RPMLOG_ERR, _("line %d: Version required: %s\n"),
spec->lineNum, spec->line);
- return RPMERR_BADSPEC;
+ return RPMRC_FAIL;
}
- version = xmalloc((ve-v) + 1);
- strncpy(version, v, (ve-v));
- version[ve-v] = '\0';
- re = ve; /* ==> next token after version string starts here */
+ EVR = xmalloc((ve-v) + 1);
+ rstrlcpy(EVR, v, (ve-v) + 1);
+ if (rpmCharCheck(spec, EVR, ve-v, ".-_+:")) return RPMRC_FAIL;
+ re = ve; /* ==> next token after EVR string starts here */
} else
- version = NULL;
+ EVR = NULL;
- addReqProv(spec, h, flags, req, version, index);
+ (void) addReqProv(spec, h, tagN, N, EVR, Flags, index);
- if (req) free(req);
- if (version) free(version);
+ N = _free(N);
+ EVR = _free(EVR);
}
- return 0;
+ return RPMRC_OK;
}