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

[virt-tools-list] [libosinfo 1/3] Every driver file in DB must provide MD5 checksum



From: "Zeeshan Ali (Khattak)" <zeeshanak gnome org>

---
 data/schemas/libosinfo.rng            |  9 +++++++++
 osinfo/osinfo_device_driver.c         | 18 ++++++++++++++++++
 osinfo/osinfo_device_driver_private.h |  3 +++
 osinfo/osinfo_loader.c                | 11 ++++++++---
 4 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/data/schemas/libosinfo.rng b/data/schemas/libosinfo.rng
index 51b0c20..819790a 100644
--- a/data/schemas/libosinfo.rng
+++ b/data/schemas/libosinfo.rng
@@ -415,6 +415,9 @@
       </optional>
       <zeroOrMore>
         <element name='file'>
+          <attribute name="md5">
+            <ref name='md5'/>
+          </attribute>
           <text/>
         </element>
       </zeroOrMore>
@@ -636,4 +639,10 @@
       <param name="pattern">dos|unix</param>
     </data>
   </define>
+
+  <define name='md5'>
+    <data type="string">
+      <param name="pattern">[0-9a-fA-F]{32}</param>
+    </data>
+  </define>
 </grammar>
diff --git a/osinfo/osinfo_device_driver.c b/osinfo/osinfo_device_driver.c
index 9a7e5e2..6b81170 100644
--- a/osinfo/osinfo_device_driver.c
+++ b/osinfo/osinfo_device_driver.c
@@ -50,6 +50,8 @@ G_DEFINE_TYPE (OsinfoDeviceDriver, osinfo_device_driver, OSINFO_TYPE_ENTITY);
 struct _OsinfoDeviceDriverPrivate
 {
     OsinfoDeviceList *devices;
+
+    GHashTable *checksums;
 };
 
 static void
@@ -58,6 +60,7 @@ osinfo_device_driver_finalize (GObject *object)
     OsinfoDeviceDriver *driver = OSINFO_DEVICE_DRIVER (object);
 
     g_object_unref(driver->priv->devices);
+    g_hash_table_unref(driver->priv->checksums);
 
     /* Chain up to the parent class */
     G_OBJECT_CLASS (osinfo_device_driver_parent_class)->finalize (object);
@@ -80,6 +83,8 @@ osinfo_device_driver_init (OsinfoDeviceDriver *driver)
     driver->priv = priv = OSINFO_DEVICE_DRIVER_GET_PRIVATE(driver);
 
     priv->devices = osinfo_devicelist_new ();
+    driver->priv->checksums = g_hash_table_new_full(g_str_hash, g_str_equal,
+                                                    g_free, g_free);
 }
 
 OsinfoDeviceDriver *osinfo_device_driver_new(const gchar *id)
@@ -172,6 +177,19 @@ void osinfo_device_driver_add_device(OsinfoDeviceDriver *driver,
                     OSINFO_ENTITY(device));
 }
 
+void osinfo_device_driver_add_file(OsinfoDeviceDriver *driver,
+                                   const gchar *name,
+                                   const gchar *checksum)
+{
+    g_hash_table_replace(driver->priv->checksums,
+                         g_strdup(name),
+                         g_strdup(checksum));
+
+    osinfo_entity_add_param(OSINFO_ENTITY(driver),
+                            OSINFO_DEVICE_DRIVER_PROP_FILE,
+                            name);
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/osinfo/osinfo_device_driver_private.h b/osinfo/osinfo_device_driver_private.h
index d49ffa1..6e54c61 100644
--- a/osinfo/osinfo_device_driver_private.h
+++ b/osinfo/osinfo_device_driver_private.h
@@ -29,6 +29,9 @@
 OsinfoDeviceDriver *osinfo_device_driver_new(const gchar *id);
 void osinfo_device_driver_add_device(OsinfoDeviceDriver *driver,
                                      OsinfoDevice *device);
+void osinfo_device_driver_add_file(OsinfoDeviceDriver *driver,
+                                   const gchar *name,
+                                   const gchar *checksum);
 
 #endif /* __OSINFO_DEVICE_DRIVER_PRIVATE_H__ */
 
diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
index 18325f6..f230395 100644
--- a/osinfo/osinfo_loader.c
+++ b/osinfo/osinfo_loader.c
@@ -971,9 +971,14 @@ static OsinfoDeviceDriver *osinfo_loader_driver(OsinfoLoader *loader,
             nodes[i]->children->type == XML_TEXT_NODE &&
             (strcmp((const gchar *)nodes[i]->name,
                     OSINFO_DEVICE_DRIVER_PROP_FILE) == 0)) {
-            osinfo_entity_add_param(OSINFO_ENTITY(driver),
-                                    (const gchar *)nodes[i]->name,
-                                    (const gchar *)nodes[i]->children->content);
+            xmlChar *checksum = xmlGetProp(nodes[i], BAD_CAST "md5");
+            if (checksum == NULL)
+                continue; // Checksum is a must!
+
+            osinfo_device_driver_add_file(driver,
+                                          (const gchar *)nodes[i]->children->content,
+                                          (const gchar *)checksum);
+            xmlFree(checksum);
         } else if (strcmp((const gchar *)nodes[i]->name,
                           OSINFO_DEVICE_DRIVER_PROP_DEVICE) == 0) {
             xmlChar *device_id = xmlGetProp(nodes[i], BAD_CAST "id");
-- 
1.8.0.1


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