[virt-tools-list] [libosinfo 3/3] API to retrieve checksum for driver files

Zeeshan Ali (Khattak) zeeshanak at gnome.org
Wed Dec 12 01:21:30 UTC 2012


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

Keeping this API agnostic of MD5 so that we can later switch to another
hashing alogirthm without breaking the API.
---
 osinfo/libosinfo.syms         |  4 ++++
 osinfo/osinfo_device_driver.c | 24 ++++++++++++++++++++++++
 osinfo/osinfo_device_driver.h |  3 +++
 3 files changed, 31 insertions(+)

diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 82f6f95..4218b53 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -372,6 +372,10 @@ LIBOSINFO_0.2.2 {
 	osinfo_os_add_device_driver;
 } LIBOSINFO_0.2.1;
 
+LIBOSINFO_0.2.3 {
+	osinfo_device_driver_get_file_checksum;
+} LIBOSINFO_0.2.2;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo_device_driver.c b/osinfo/osinfo_device_driver.c
index 6b81170..c78b974 100644
--- a/osinfo/osinfo_device_driver.c
+++ b/osinfo/osinfo_device_driver.c
@@ -142,6 +142,30 @@ GList *osinfo_device_driver_get_files(OsinfoDeviceDriver *driver)
 }
 
 /**
+ * osinfo_device_driver_get_file_checksum:
+ * @driver: a #OsinfoDeviceDriver instance
+ * @file: The name of the driver file for which checksum is requested
+ * @checksum_type: (out) (allow-none): place-holder to return type of the
+ *                                     checksum into, or NULL
+ *
+ * Retrieves the expected checksum for the given driver file @file.
+ *
+ * Returns: The file checksum
+ */
+const gchar *osinfo_device_driver_get_file_checksum(OsinfoDeviceDriver *driver,
+                                                    const gchar *file,
+                                                    GChecksumType *checksum_type)
+{
+    g_return_val_if_fail(OSINFO_IS_DEVICE_DRIVER(driver), NULL);
+    g_return_val_if_fail(file != NULL, NULL);
+
+    if (checksum_type != NULL)
+        *checksum_type = G_CHECKSUM_MD5;
+
+    return g_hash_table_lookup(driver->priv->checksums, file);
+}
+
+/**
  * osinfo_device_driver_get_pre_installable:
  * @driver: a #OsinfoDeviceDriver instance
  *
diff --git a/osinfo/osinfo_device_driver.h b/osinfo/osinfo_device_driver.h
index c894fe8..aa571c6 100644
--- a/osinfo/osinfo_device_driver.h
+++ b/osinfo/osinfo_device_driver.h
@@ -83,6 +83,9 @@ const gchar *osinfo_device_driver_get_location(OsinfoDeviceDriver *driver);
 gboolean osinfo_device_driver_get_pre_installable(OsinfoDeviceDriver *driver);
 GList *osinfo_device_driver_get_files(OsinfoDeviceDriver *driver);
 OsinfoDeviceList *osinfo_device_driver_get_devices(OsinfoDeviceDriver *driver);
+const gchar *osinfo_device_driver_get_file_checksum(OsinfoDeviceDriver *driver,
+                                                    const gchar *file,
+                                                    GChecksumType *checksum_type);
 
 #endif /* __OSINFO_DEVICE_DRIVER_H__ */
 /*
-- 
1.8.0.1




More information about the virt-tools-list mailing list