]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Parse boolean values in comps xml 409/head
authorPavla Kratochvilova <pkratoch@redhat.com>
Thu, 12 Nov 2020 07:50:28 +0000 (08:50 +0100)
committerPavla Kratochvilova <pkratoch@redhat.com>
Wed, 18 Nov 2020 07:05:30 +0000 (08:05 +0100)
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

index 5943fd676542f0f20c1c070ffaf08de07828f4da..51b7f91cde5bcf851fcd74f32934fd534633e1d3 100644 (file)
@@ -16,6 +16,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
+#include <stdbool.h>
 
 #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: