summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-02-26 12:17:05 +0000
committerRichard Hughes <richard@hughsie.com>2016-02-26 12:17:05 +0000
commit2f6f9baf7c7f71db4568590d7bc4711143a1d2df (patch)
tree555ce7cb40bdfa1ede34e0bb3813bc3c53b2a94c
parentbe68554e8b1d78e24c92c46a20c76a96848d3d9a (diff)
downloadappstream-glib-2f6f9baf7c7f71db4568590d7bc4711143a1d2df.tar.gz
Support loading XML files using as_store_from_bytes()
-rw-r--r--libappstream-glib/as-store.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index eb77e59..7c55816 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -1387,16 +1387,40 @@ as_store_from_bytes (AsStore *store,
GCancellable *cancellable,
GError **error)
{
+ g_autofree gchar *content_type = NULL;
+ gconstpointer data;
+ gsize size;
+
+ /* find content type */
+ data = g_bytes_get_data (bytes, &size);
+ content_type = g_content_type_guess (NULL, data, size, NULL);
+
+ /* is an AppStream file */
+ if (g_strcmp0 (content_type, "application/xml") == 0) {
+ g_autofree gchar *tmp = g_strndup (data, size);
+ return as_store_from_xml (store, tmp, NULL, error);
+ }
+
+ /* is firmware */
+ if (g_strcmp0 (content_type, "application/vnd.ms-cab-compressed") == 0) {
#ifdef HAVE_GCAB
- /* lets assume this is a .cab file for now */
- return as_store_cab_from_bytes (store, bytes, cancellable, error);
+ return as_store_cab_from_bytes (store, bytes, cancellable, error);
#else
+ g_set_error (error,
+ AS_STORE_ERROR,
+ AS_STORE_ERROR_FAILED,
+ "no firmware support, compiled with --disable-firmware");
+ return FALSE;
+#endif
+ }
+
+ /* not sure what to do */
g_set_error (error,
AS_STORE_ERROR,
AS_STORE_ERROR_FAILED,
- "no firmware support, compiled with --disable-firmware");
+ "cannot load store of type %s",
+ content_type);
return FALSE;
-#endif
}
/**