[gnome-software/wip/hughsie/fwupd] Get the firmware information for local .cab files
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software/wip/hughsie/fwupd] Get the firmware information for local .cab files
- Date: Wed, 11 Mar 2015 14:07:17 +0000 (UTC)
commit fe47665eeecb051d9f4eca17400fabc38f03fb91
Author: Richard Hughes <richard hughsie com>
Date: Wed Mar 11 12:48:02 2015 +0000
Get the firmware information for local .cab files
src/gnome-software-local-file.desktop.in | 2 +-
src/plugins/gs-plugin-fwupd.c | 160 ++++++++++++++++++++++++++++++
2 files changed, 161 insertions(+), 1 deletions(-)
---
diff --git a/src/gnome-software-local-file.desktop.in b/src/gnome-software-local-file.desktop.in
index 049c855..b77386c 100644
--- a/src/gnome-software-local-file.desktop.in
+++ b/src/gnome-software-local-file.desktop.in
@@ -8,4 +8,4 @@ Type=Application
Icon=system-software-install
StartupNotify=true
NoDisplay=true
-MimeType=application/x-rpm;application/x-redhat-package-manager;application/x-deb;application/x-app-package;
+MimeType=application/x-rpm;application/x-redhat-package-manager;application/x-deb;application/x-app-package;application/vnd.ms-cab-compressed;
diff --git a/src/plugins/gs-plugin-fwupd.c b/src/plugins/gs-plugin-fwupd.c
index ccce30c..ccf81e9 100644
--- a/src/plugins/gs-plugin-fwupd.c
+++ b/src/plugins/gs-plugin-fwupd.c
@@ -496,3 +496,163 @@ gs_plugin_app_upgrade (GsPlugin *plugin,
return TRUE;
}
+
+/**
+ * gs_plugin_fwupd_content_type_matches:
+ */
+static gboolean
+gs_plugin_fwupd_content_type_matches (const gchar *filename,
+ gboolean *matches,
+ GCancellable *cancellable,
+ GError **error)
+{
+ const gchar *tmp;
+ guint i;
+ _cleanup_object_unref_ GFile *file = NULL;
+ _cleanup_object_unref_ GFileInfo *info = NULL;
+ const gchar *mimetypes[] = {
+ "application/vnd.ms-cab-compressed",
+ NULL };
+
+ /* get content type */
+ file = g_file_new_for_path (filename);
+ info = g_file_query_info (file,
+ G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ cancellable,
+ error);
+ if (info == NULL)
+ return FALSE;
+ tmp = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+
+ /* match any */
+ *matches = FALSE;
+ for (i = 0; mimetypes[i] != NULL; i++) {
+ if (g_strcmp0 (tmp, mimetypes[i]) == 0) {
+ *matches = TRUE;
+ break;
+ }
+ }
+ return TRUE;
+}
+
+#include <string.h>
+
+/**
+ * gs_plugin_filename_to_app:
+ */
+gboolean
+gs_plugin_filename_to_app (GsPlugin *plugin,
+ GList **list,
+ const gchar *filename,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gboolean supported;
+ _cleanup_object_unref_ GsApp *app = NULL;
+
+ /* does this match any of the mimetypes we support */
+ if (!gs_plugin_fwupd_content_type_matches (filename,
+ &supported,
+ cancellable,
+ error))
+ return FALSE;
+ if (!supported)
+ return TRUE;
+
+{
+ GVariant *body;
+ GVariant *val;
+ GVariant *variant;
+ const gchar *key;
+// const gchar *type;
+ gint fd;
+ gint retval;
+// guint i;
+ _cleanup_object_unref_ GDBusConnection *conn = NULL;
+ _cleanup_object_unref_ GDBusMessage *message = NULL;
+ _cleanup_object_unref_ GDBusMessage *request = NULL;
+ _cleanup_object_unref_ GUnixFDList *fd_list = NULL;
+ _cleanup_variant_iter_free_ GVariantIter *iter = NULL;
+
+ /* get request */
+ conn = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
+ if (conn == NULL)
+ return FALSE;
+
+ /* open file */
+ fd = open (filename, O_RDONLY);
+ if (fd < 0) {
+ g_set_error (error,
+ GS_PLUGIN_ERROR,
+ GS_PLUGIN_ERROR_FAILED,
+ "failed to open %s",
+ filename);
+ return FALSE;
+ }
+
+ /* set out of band file descriptor */
+ fd_list = g_unix_fd_list_new ();
+ retval = g_unix_fd_list_append (fd_list, fd, NULL);
+ g_assert (retval != -1);
+ request = g_dbus_message_new_method_call (FWUPD_DBUS_SERVICE,
+ FWUPD_DBUS_PATH,
+ FWUPD_DBUS_INTERFACE,
+ "GetDetails");
+ g_dbus_message_set_unix_fd_list (request, fd_list);
+
+ /* g_unix_fd_list_append did a dup() already */
+ close (fd);
+
+ /* send message */
+ body = g_variant_new ("(h)", fd > -1 ? 0 : -1);
+ g_dbus_message_set_body (request, body);
+ message = g_dbus_connection_send_message_with_reply_sync (conn,
+ request,
+ G_DBUS_SEND_MESSAGE_FLAGS_NONE,
+ -1,
+ NULL,
+ NULL,
+ error);
+ if (message == NULL) {
+ g_dbus_error_strip_remote_error (*error);
+ return FALSE;
+ }
+ if (g_dbus_message_to_gerror (message, error)) {
+ g_dbus_error_strip_remote_error (*error);
+ return FALSE;
+ }
+
+ /* get results */
+ app = gs_app_new (NULL);
+ gs_app_set_management_plugin (app, "fwupd");
+ gs_app_set_kind (app, GS_APP_KIND_PACKAGE);
+ gs_app_set_state (app, AS_APP_STATE_AVAILABLE_LOCAL);
+// gs_app_set_description (app, GS_APP_QUALITY_LOWEST, "FIXME"); //FIXME
+// gs_app_add_source (app, "XXX"); //FIXME
+// gs_app_add_source_id (app, "YYY"); //FIXME
+// gs_app_set_url (app, AS_URL_KIND_HOMEPAGE, "http://fixme.com"); //FIXME
+// gs_app_set_size (app, 999);
+// gs_app_set_licence (app, "NONFREE");
+ val = g_dbus_message_get_body (message);
+ g_variant_get (val, "(a{sv})", &iter);
+ while (g_variant_iter_next (iter, "{&sv}", &key, &variant)) {
+ if (g_strcmp0 (key, "Version") == 0) {
+ gs_app_set_version (app, g_variant_get_string (variant, NULL));
+ } else if (g_strcmp0 (key, "Vendor") == 0) {
+ gs_app_set_origin (app, g_variant_get_string (variant, NULL));
+ } else if (g_strcmp0 (key, "Name") == 0) {
+ gs_app_set_name (app, GS_APP_QUALITY_NORMAL,
+ g_variant_get_string (variant, NULL));
+ } else if (g_strcmp0 (key, "Summary") == 0) {
+ gs_app_set_summary (app, GS_APP_QUALITY_NORMAL,
+ g_variant_get_string (variant, NULL));
+ }
+ g_variant_unref (variant);
+ }
+
+}
+
+ gs_plugin_add_app (list, app);
+ return TRUE;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]