[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[virt-tools-list] [libosinfo PATCHv3 6/9] loader: Read media language information



Getting language information can either be supplied through a
series of <l10n-language> tag set on the <media> element or through
a regex that will be applied on the media volume ID.
The former should be all that is needed for most Linux distros while
the latter will be useful to get the language of Windows images.
---
 data/schemas/libosinfo.rng | 19 +++++++++++++++++++
 osinfo/osinfo_loader.c     | 31 +++++++++++++++++++++++++++----
 osinfo/osinfo_media.h      |  2 ++
 3 files changed, 48 insertions(+), 4 deletions(-)

diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index 4094710..533ef1f 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -281,6 +281,9 @@
             <text/>
           </element>
         </optional>
+        <zeroOrMore>
+          <ref name='media-lang'/>
+        </zeroOrMore>
       </interleave>
     </element>
   </define>
@@ -328,6 +331,22 @@
     </element>
   </define>
 
+  <define name='media-lang'>
+    <element name='l10n-language'>
+      <optional>
+        <attribute name="regex">
+          <ref name='bool'/>
+        </attribute>
+      </optional>
+      <optional>
+        <attribute name="l10n-language-map">
+          <ref name='url'/>
+        </attribute>
+      </optional>
+      <text/>
+    </element>
+  </define>
+
   <define name='treeinfo'>
     <element name='treeinfo'>
       <interleave>
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 25385a0..f293d45 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -857,12 +857,35 @@ static OsinfoMedia *osinfo_loader_media (OsinfoLoader *loader,
              strcmp((const gchar *)nodes[i]->name,
                     OSINFO_MEDIA_PROP_PUBLISHER_ID) != 0 &&
              strcmp((const gchar *)nodes[i]->name,
-                    OSINFO_MEDIA_PROP_APPLICATION_ID) != 0))
+                    OSINFO_MEDIA_PROP_APPLICATION_ID) != 0 &&
+             strcmp((const gchar *)nodes[i]->name,
+                    OSINFO_MEDIA_PROP_LANG) != 0))
             continue;
 
-        osinfo_entity_set_param(OSINFO_ENTITY(media),
-                                (const gchar *)nodes[i]->name,
-                                (const gchar *)nodes[i]->children->content);
+        if (strcmp((const gchar *)nodes[i]->name,
+                   OSINFO_MEDIA_PROP_LANG) == 0) {
+            gchar *regex = (gchar *)xmlGetProp(nodes[i], BAD_CAST "regex");
+            if (g_strcmp0(regex, "true") == 0) {
+                gchar *datamap;
+                osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                        OSINFO_MEDIA_PROP_LANG_REGEX,
+                                        (const gchar *)nodes[i]->children->content);
+                datamap = (gchar *)xmlGetProp(nodes[i], BAD_CAST OSINFO_MEDIA_PROP_LANG_MAP);
+                if (datamap != NULL)
+                    osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                            OSINFO_MEDIA_PROP_LANG_MAP,
+                                            datamap);
+            } else {
+                osinfo_entity_add_param(OSINFO_ENTITY(media),
+                                        OSINFO_MEDIA_PROP_LANG,
+                                        (const gchar *)nodes[i]->children->content);
+            }
+            xmlFree(regex);
+        } else {
+            osinfo_entity_set_param(OSINFO_ENTITY(media),
+                                    (const gchar *)nodes[i]->name,
+                                    (const gchar *)nodes[i]->children->content);
+        }
     }
 
     g_free(nodes);
diff --git a/osinfo/osinfo_media.h b/osinfo/osinfo_media.h
index 8c8d649..f365e2b 100644
--- a/osinfo/osinfo_media.h
+++ b/osinfo/osinfo_media.h
@@ -82,6 +82,8 @@ typedef struct _OsinfoMediaPrivate OsinfoMediaPrivate;
 #define OSINFO_MEDIA_PROP_INSTALLER      "installer"
 #define OSINFO_MEDIA_PROP_INSTALLER_REBOOTS "installer-reboots"
 #define OSINFO_MEDIA_PROP_LANG           "l10n-language"
+#define OSINFO_MEDIA_PROP_LANG_REGEX     "l10n-language-regex"
+#define OSINFO_MEDIA_PROP_LANG_MAP       "l10n-language-map"
 
 /* object */
 struct _OsinfoMedia
-- 
1.8.0.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]