summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-release.c
diff options
context:
space:
mode:
Diffstat (limited to 'libappstream-glib/as-release.c')
-rw-r--r--libappstream-glib/as-release.c91
1 files changed, 90 insertions, 1 deletions
diff --git a/libappstream-glib/as-release.c b/libappstream-glib/as-release.c
index e4d58c6..ef17ffe 100644
--- a/libappstream-glib/as-release.c
+++ b/libappstream-glib/as-release.c
@@ -33,7 +33,7 @@
* Releases can be automatically generated by parsing upstream ChangeLogs or
* .spec files, or can be populated using AppData files.
*
- * See also: #AsApp
+ * See also: #AsRelease
*/
#include "config.h"
@@ -57,6 +57,7 @@ typedef struct
AsRefString *version;
GHashTable *blobs; /* of AsRefString:GBytes */
GHashTable *descriptions;
+ GHashTable *urls; /* of AsRefString:AsRefString */
guint64 timestamp;
guint64 install_duration;
GPtrArray *locations; /* of AsRefString, lazy */
@@ -74,6 +75,7 @@ as_release_finalize (GObject *object)
AsReleasePrivate *priv = GET_PRIVATE (release);
g_free (priv->sizes);
+ g_hash_table_unref (priv->urls);
if (priv->version != NULL)
as_ref_string_unref (priv->version);
if (priv->blobs != NULL)
@@ -95,6 +97,9 @@ as_release_init (AsRelease *release)
priv->urgency = AS_URGENCY_KIND_UNKNOWN;
priv->kind = AS_RELEASE_KIND_UNKNOWN;
priv->state = AS_RELEASE_STATE_UNKNOWN;
+ priv->urls = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) as_ref_string_unref,
+ (GDestroyNotify) as_ref_string_unref);
}
static void
@@ -770,6 +775,67 @@ as_release_set_description (AsRelease *release,
}
/**
+ * as_release_get_urls:
+ * @release: a #AsRelease instance.
+ *
+ * Gets the URLs set for the application.
+ *
+ * Returns: (transfer none): hash table of URLs
+ *
+ * Since: 0.7.15
+ **/
+GHashTable *
+as_release_get_urls (AsRelease *release)
+{
+ AsReleasePrivate *priv = GET_PRIVATE (release);
+ return priv->urls;
+}
+
+/**
+ * as_release_get_url_item:
+ * @release: a #AsRelease instance.
+ * @url_kind: the URL kind, e.g. %AS_URL_KIND_HOMEPAGE.
+ *
+ * Gets a URL.
+ *
+ * Returns: string, or %NULL if unset
+ *
+ * Since: 0.7.15
+ **/
+const gchar *
+as_release_get_url_item (AsRelease *release, AsUrlKind url_kind)
+{
+ AsReleasePrivate *priv = GET_PRIVATE (release);
+ return g_hash_table_lookup (priv->urls,
+ as_url_kind_to_string (url_kind));
+}
+
+/**
+ * as_release_add_url:
+ * @release: a #AsRelease instance.
+ * @url_kind: the URL kind, e.g. %AS_URL_KIND_DETAILS
+ * @url: the full URL.
+ *
+ * Adds some URL data to the application.
+ *
+ * Since: 0.7.15
+ **/
+void
+as_release_add_url (AsRelease *release,
+ AsUrlKind url_kind,
+ const gchar *url)
+{
+ AsReleasePrivate *priv = GET_PRIVATE (release);
+ if (url == NULL) {
+ g_hash_table_remove (priv->urls, as_url_kind_to_string (url_kind));
+ } else {
+ g_hash_table_insert (priv->urls,
+ (AsRefString *) as_url_kind_to_string (url_kind),
+ as_ref_string_new (url));
+ }
+}
+
+/**
* as_release_node_insert: (skip)
* @release: a #AsRelease instance.
* @parent: the parent #GNode to use..
@@ -829,6 +895,8 @@ as_release_node_insert (AsRelease *release, GNode *parent, AsNodeContext *ctx)
checksum = g_ptr_array_index (priv->checksums, i);
as_checksum_node_insert (checksum, n, ctx);
}
+ if (priv->urls != NULL)
+ as_node_insert_hash (n, "url", "type", priv->urls, 0);
if (priv->descriptions != NULL) {
as_node_insert_localized (n, "description", priv->descriptions,
AS_NODE_INSERT_FLAG_PRE_ESCAPED |
@@ -897,6 +965,16 @@ as_release_node_parse (AsRelease *release, GNode *node,
if (tmp != NULL)
priv->install_duration = g_ascii_strtoull (tmp, NULL, 10);
+ /* <url> */
+ for (n = node->children; n != NULL; n = n->next) {
+ if (as_node_get_tag (n) != AS_TAG_URL)
+ continue;
+ tmp = as_node_get_attribute (n, "type");
+ as_release_add_url (release,
+ as_url_kind_from_string (tmp),
+ as_node_get_data (n));
+ }
+
/* get optional locations */
if (priv->locations != NULL)
g_ptr_array_set_size (priv->locations, 0);
@@ -1019,6 +1097,17 @@ as_release_node_parse_dep11 (AsRelease *release, GNode *node,
}
continue;
}
+ if (g_strcmp0 (tmp, "url") == 0) {
+ for (c = n->children; c != NULL; c = c->next) {
+ if (g_strcmp0 (as_yaml_node_get_key (c), "details") == 0) {
+ as_release_add_url (release,
+ AS_URL_KIND_DETAILS,
+ as_yaml_node_get_value (c));
+ continue;
+ }
+ }
+ continue;
+ }
}
return TRUE;
}