From: Pavla Kratochvilova Date: Thu, 12 Nov 2020 07:50:28 +0000 (+0100) Subject: Parse boolean values in comps xml X-Git-Tag: 0.7.17~2^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F409%2Fhead;p=thirdparty%2Flibsolv.git Parse boolean values in comps xml Before this change, the resulting value was true if the attribute was present, false otherwise. After this change, the resulting value is true if the attribute value is "true", false if "false" and default value otherwise. This is the same how libcomps parses the comps xml. --- diff --git a/ext/repo_comps.c b/ext/repo_comps.c index 5943fd67..51b7f91c 100644 --- a/ext/repo_comps.c +++ b/ext/repo_comps.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "pool.h" #include "repo.h" @@ -100,6 +101,21 @@ struct parsedata { }; +const bool COMPS_DEFAULT_USERVISIBLE = true; +const bool COMPS_DEFAULT_DEFAULT = false; + + +/* Return true if "true", false if "false", default_value otherwise */ +bool +parse_boolean(char *content, bool default_value) +{ + if (!strcmp(content, "true")) + return true; + if (!strcmp(content, "false")) + return false; + return default_value; +} + static void startElement(struct solv_xmlparser *xmlp, int state, const char *name, const char **atts) @@ -115,6 +131,10 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha s = pd->solvable = pool_id2solvable(pool, repo_add_solvable(pd->repo)); pd->handle = s - pool->solvables; pd->kind = state == STATE_GROUP ? "group" : "category"; + if (COMPS_DEFAULT_USERVISIBLE) + repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE); + if (COMPS_DEFAULT_DEFAULT) + repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT); break; case STATE_NAME: @@ -193,11 +213,17 @@ endElement(struct solv_xmlparser *xmlp, int state, char *content) break; case STATE_USERVISIBLE: - repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE); + if (parse_boolean(content, COMPS_DEFAULT_USERVISIBLE)) + repodata_set_void(pd->data, pd->handle, SOLVABLE_ISVISIBLE); + else + repodata_unset(pd->data, pd->handle, SOLVABLE_ISVISIBLE); break; case STATE_DEFAULT: - repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT); + if (parse_boolean(content, COMPS_DEFAULT_DEFAULT)) + repodata_set_void(pd->data, pd->handle, SOLVABLE_ISDEFAULT); + else + repodata_unset(pd->data, pd->handle, SOLVABLE_ISDEFAULT); break; case STATE_LANG_ONLY: