headerlist.c: getXMLPackageNFV: support for complex requirements like "(name >= ver1 with name < ver2)"

This commit is contained in:
Silvan Calarco 2021-03-20 14:05:02 +01:00
parent 367ba2bf22
commit 2370dd1cd0

View File

@ -793,15 +793,15 @@ xmlNode* findXMLPackageByName(xmlNode *root_node, char* name) {
int XMLFlagToInt(char *flag) { int XMLFlagToInt(char *flag) {
if (!flag) if (!flag)
return RPMSENSE_ANY; return RPMSENSE_ANY;
else if (!strcmp(flag, "EQ")) else if (!strcmp(flag, "EQ") || !strcmp(flag, "="))
return RPMSENSE_EQUAL; return RPMSENSE_EQUAL;
else if (!strcmp(flag, "LT")) else if (!strcmp(flag, "LT") || !strcmp(flag, "<"))
return RPMSENSE_LESS; return RPMSENSE_LESS;
else if (!strcmp(flag, "LE")) else if (!strcmp(flag, "LE") || !strcmp(flag, "<="))
return RPMSENSE_EQUAL | RPMSENSE_LESS; return RPMSENSE_EQUAL | RPMSENSE_LESS;
else if (!strcmp(flag, "GT")) else if (!strcmp(flag, "GT") || !strcmp(flag, ">"))
return RPMSENSE_GREATER; return RPMSENSE_GREATER;
else if (!strcmp(flag, "GE")) else if (!strcmp(flag, "GE") || !strcmp(flag, ">="))
return RPMSENSE_EQUAL | RPMSENSE_GREATER; return RPMSENSE_EQUAL | RPMSENSE_GREATER;
return RPMSENSE_ANY; return RPMSENSE_ANY;
} }
@ -868,7 +868,7 @@ void getXMLPackageChangelog(xmlNode *parent,
void getXMLPackageNFV(xmlNode *parent, char ***name, void getXMLPackageNFV(xmlNode *parent, char ***name,
uint_32 **flags, char ***version, int *count) { uint_32 **flags, char ***version, int *count) {
char buf[PATH_MAX]; char *n, buf[PATH_MAX];
*count = xmlChildElementCount(parent); *count = xmlChildElementCount(parent);
if (*count == 0) { if (*count == 0) {
@ -889,26 +889,64 @@ void getXMLPackageNFV(xmlNode *parent, char ***name,
*count); *count);
return; return;
} }
(*name)[i] = (char*)findXMLAttributeByName(entry, "name"); n = (char*)findXMLAttributeByName(entry, "name");
(*flags)[i] = XMLFlagToInt( if (n[0] != '(') {
(char*)findXMLAttributeByName(entry, "flags")); (*name)[i] = n;
buf[0] = '\0'; (*flags)[i] = XMLFlagToInt(
if ((*flags)[i] != RPMSENSE_ANY) { (char*)findXMLAttributeByName(entry, "flags"));
char *epoch = (char*)findXMLAttributeByName(entry, "epoch"); buf[0] = '\0';
char *ver = (char*)findXMLAttributeByName(entry, "ver"); if ((*flags)[i] != RPMSENSE_ANY) {
char *rel = (char*)findXMLAttributeByName(entry, "rel"); char *epoch = (char*)findXMLAttributeByName(entry, "epoch");
if (epoch && ver && rel) { char *ver = (char*)findXMLAttributeByName(entry, "ver");
snprintf(buf, PATH_MAX,"%s:%s-%s", epoch, ver, rel); char *rel = (char*)findXMLAttributeByName(entry, "rel");
free(epoch); if (epoch && ver && rel) {
free(ver); snprintf(buf, PATH_MAX,"%s:%s-%s", epoch, ver, rel);
free(rel); free(epoch);
} else if (epoch && ver) { free(ver);
snprintf(buf, PATH_MAX,"%s:%s", epoch, ver); free(rel);
free(epoch); } else if (epoch && ver) {
free(ver); snprintf(buf, PATH_MAX,"%s:%s", epoch, ver);
} free(epoch);
free(ver);
}
}
(*version)[i] = strdup(buf);
} else {
// Complex requirement like "(name >= ver1 with name < ver2)"
char n1[PATH_MAX], rel1[PATH_MAX], v1[PATH_MAX],
n2[PATH_MAX], rel2[PATH_MAX], v2[PATH_MAX], comp[PATH_MAX];
int ret = sscanf(n,"%*1c%s %s %s %s %s %s %s%*1c", n1, rel1, v1,
comp, n2, rel2, v2);
if (ret == 7 && !strncmp(comp,"with",4)) {
free(n);
// Extend arrays
(*count)++;
char **newname = malloc(sizeof(char*) * *count);
uint_32 *newflags = malloc(sizeof(uint_32) * *count);
char **newversion = malloc(sizeof(char*) * *count);
memcpy(newname, *name, sizeof(name));
memcpy(newflags, *flags, sizeof(flags));
memcpy(newversion, *version, sizeof(version));
free(*name);
free(*flags);
free(*version);
*name = newname;
*flags = newflags;
*version = newversion;
(*name)[i] = strdup(n1);
(*flags)[i] = XMLFlagToInt(rel1);
(*version)[i] = strdup(v1);
i++;
(*name)[i] = strdup(n2);
(*flags)[i] = XMLFlagToInt(rel2);
(*version)[i] = strdup(v2);
} else {
logmsg(LOG_WARNING,"getXMLPackageNFV: don't know how to process '%s'; ignoring", n);
(*name)[i] = n;
(*flags)[i] = RPMSENSE_ANY;
(*version)[i] = NULL;
}
} }
(*version)[i] = strdup(buf);
i++; i++;
} }
} }