summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ancell <robert.ancell@canonical.com>2016-03-04 11:38:10 +1300
committerRobert Ancell <robert.ancell@canonical.com>2016-03-04 11:38:17 +1300
commit924326edc3eb5df7d062212ed8f622f361cd0313 (patch)
tree39f52f32a709a65c90d002cea01c06602b5587cf
parent216216cb52afdbfb3fef43c2e4f23e5ca2cb1104 (diff)
downloadappstream-glib-924326edc3eb5df7d062212ed8f622f361cd0313.tar.gz
Implement DEP-11 MediaBaseUrl support
-rw-r--r--libappstream-glib/as-image.c12
-rw-r--r--libappstream-glib/as-node-private.h3
-rw-r--r--libappstream-glib/as-node.c31
-rw-r--r--libappstream-glib/as-store.c6
4 files changed, 49 insertions, 3 deletions
diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c
index 49a86c2..f59d13f 100644
--- a/libappstream-glib/as-image.c
+++ b/libappstream-glib/as-image.c
@@ -465,8 +465,16 @@ as_image_node_parse_dep11 (AsImage *im, GNode *node,
as_image_set_height (im, as_yaml_node_get_value_as_int (n));
else if (g_strcmp0 (tmp, "width") == 0)
as_image_set_width (im, as_yaml_node_get_value_as_int (n));
- else if (g_strcmp0 (tmp, "url") == 0)
- as_image_set_url (im, as_yaml_node_get_value (n));
+ else if (g_strcmp0 (tmp, "url") == 0) {
+ const gchar *media_base_url = as_node_context_get_media_base_url (ctx);
+ if (media_base_url != NULL) {
+ g_autofree gchar *url = NULL;
+ url = g_build_path ("/", media_base_url, as_yaml_node_get_value (n), NULL);
+ as_image_set_url (im, url);
+ } else {
+ as_image_set_url (im, as_yaml_node_get_value (n));
+ }
+ }
}
return TRUE;
}
diff --git a/libappstream-glib/as-node-private.h b/libappstream-glib/as-node-private.h
index 58cdb59..8a405b8 100644
--- a/libappstream-glib/as-node-private.h
+++ b/libappstream-glib/as-node-private.h
@@ -45,6 +45,9 @@ void as_node_context_set_output_trusted (AsNodeContext *ctx,
AsAppSourceKind as_node_context_get_output (AsNodeContext *ctx);
void as_node_context_set_output (AsNodeContext *ctx,
AsAppSourceKind output);
+const gchar *as_node_context_get_media_base_url (AsNodeContext *ctx);
+void as_node_context_set_media_base_url (AsNodeContext *ctx,
+ const gchar *url);
gchar *as_node_take_data (const GNode *node);
gchar *as_node_take_attribute (const GNode *node,
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c
index 340ee1e..bef6fbf 100644
--- a/libappstream-glib/as-node.c
+++ b/libappstream-glib/as-node.c
@@ -1930,6 +1930,7 @@ struct _AsNodeContext {
AsAppSourceKind output;
gdouble version;
gboolean output_trusted;
+ gchar *media_base_url;
};
/**
@@ -2075,3 +2076,33 @@ as_node_context_set_output (AsNodeContext *ctx, AsAppSourceKind output)
{
ctx->output = output;
}
+
+/**
+ * as_node_context_get_media_base_url: (skip)
+ * @ctx: a #AsNodeContext.
+ *
+ * Gets the base URL for media used when inserting nodes.
+ *
+ * Since: 0.5.11
+ **/
+const gchar *
+as_node_context_get_media_base_url (AsNodeContext *ctx)
+{
+ return ctx->media_base_url;
+}
+
+/**
+ * as_node_context_set_media_base_url: (skip)
+ * @ctx: a #AsNodeContext.
+ * @url: a URL
+ *
+ * Sets the base URL for media used when inserting nodes.
+ *
+ * Since: 0.5.11
+ **/
+void
+as_node_context_set_media_base_url (AsNodeContext *ctx, const gchar *url)
+{
+ g_free (ctx->media_base_url);
+ ctx->media_base_url = g_strdup (url);
+}
diff --git a/libappstream-glib/as-store.c b/libappstream-glib/as-store.c
index b83d93d..6c99536 100644
--- a/libappstream-glib/as-store.c
+++ b/libappstream-glib/as-store.c
@@ -1076,6 +1076,7 @@ as_store_load_yaml_file (AsStore *store,
return FALSE;
/* get header information */
+ ctx = as_node_context_new ();
for (n = root->children->children; n != NULL; n = n->next) {
tmp = as_yaml_node_get_key (n);
if (g_strcmp0 (tmp, "Origin") == 0) {
@@ -1087,6 +1088,10 @@ as_store_load_yaml_file (AsStore *store,
as_store_set_api_version (store, g_ascii_strtod (as_yaml_node_get_value (n), NULL));
continue;
}
+ if (g_strcmp0 (tmp, "MediaBaseUrl") == 0) {
+ as_node_context_set_media_base_url (ctx, as_yaml_node_get_value (n));
+ continue;
+ }
}
/* if we have an origin either from the YAML or _set_origin() */
@@ -1107,7 +1112,6 @@ as_store_load_yaml_file (AsStore *store,
tok = as_store_changed_inhibit (store);
/* parse applications */
- ctx = as_node_context_new ();
for (app_n = root->children->next; app_n != NULL; app_n = app_n->next) {
g_autoptr(AsApp) app = NULL;
if (app_n->children == NULL)