From 3f6bee638bbf6ff8a2d68b9ba0727dafe6cf5bed Mon Sep 17 00:00:00 2001 From: Pavla Kratochvilova Date: Thu, 12 Nov 2020 08:50:28 +0100 Subject: [PATCH] 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. --- ext/repo_comps.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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: -- 2.47.2