summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-01-22 14:35:25 +0000
committerRichard Hughes <richard@hughsie.com>2015-01-22 14:38:06 +0000
commitc604ba0b93cab5b7cf8ae771d62d6d5c240a21bb (patch)
treed359922ab7954caa1e447c3aed75d9e89d4e8840
parent53c358dc289e06199b6e58a41be59b92aec2a37f (diff)
downloadappstream-glib-c604ba0b93cab5b7cf8ae771d62d6d5c240a21bb.tar.gz
Add support for <permission>
This is useful for bundles to define ahead of time, and to show in the software center before the application is installed.
-rw-r--r--libappstream-glib/as-app.c105
-rw-r--r--libappstream-glib/as-app.h8
-rw-r--r--libappstream-glib/as-self-test.c7
-rw-r--r--libappstream-glib/as-tag.c4
-rw-r--r--libappstream-glib/as-tag.gperf2
-rw-r--r--libappstream-glib/as-tag.h6
6 files changed, 127 insertions, 5 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 3e6d583..843ad0b 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
+ * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
@@ -69,6 +69,7 @@ struct _AsAppPrivate
GPtrArray *compulsory_for_desktops; /* of string */
GPtrArray *extends; /* of string */
GPtrArray *kudos; /* of string */
+ GPtrArray *permissions; /* of string */
GPtrArray *mimetypes; /* of string */
GPtrArray *pkgnames; /* of string */
GPtrArray *architectures; /* of string */
@@ -272,6 +273,7 @@ as_app_finalize (GObject *object)
g_ptr_array_unref (priv->compulsory_for_desktops);
g_ptr_array_unref (priv->extends);
g_ptr_array_unref (priv->kudos);
+ g_ptr_array_unref (priv->permissions);
g_ptr_array_unref (priv->mimetypes);
g_ptr_array_unref (priv->pkgnames);
g_ptr_array_unref (priv->architectures);
@@ -310,6 +312,7 @@ as_app_init (AsApp *app)
priv->keywords = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, (GDestroyNotify) g_ptr_array_unref);
priv->kudos = g_ptr_array_new_with_free_func (g_free);
+ priv->permissions = g_ptr_array_new_with_free_func (g_free);
priv->mimetypes = g_ptr_array_new_with_free_func (g_free);
priv->pkgnames = g_ptr_array_new_with_free_func (g_free);
priv->architectures = g_ptr_array_new_with_free_func (g_free);
@@ -491,6 +494,32 @@ as_app_get_compulsory_for_desktops (AsApp *app)
}
/**
+ * as_app_has_permission:
+ * @app: a #AsApp instance.
+ * @permission: a permission string, e.g. "Network"
+ *
+ * Searches the permission list for a specific item.
+ *
+ * Returns: %TRUE if the application has got the specified permission
+ *
+ * Since: 0.3.5
+ */
+gboolean
+as_app_has_permission (AsApp *app, const gchar *permission)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ const gchar *tmp;
+ guint i;
+
+ for (i = 0; i < priv->permissions->len; i++) {
+ tmp = g_ptr_array_index (priv->permissions, i);
+ if (g_strcmp0 (tmp, permission) == 0)
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/**
* as_app_get_keywords:
* @app: a #AsApp instance.
* @locale: the locale, or %NULL. e.g. "en_GB"
@@ -528,6 +557,23 @@ as_app_get_kudos (AsApp *app)
}
/**
+ * as_app_get_permissions:
+ * @app: a #AsApp instance.
+ *
+ * Gets any permissions the application has obtained.
+ *
+ * Returns: (element-type utf8) (transfer none): an array
+ *
+ * Since: 0.3.5
+ **/
+GPtrArray *
+as_app_get_permissions (AsApp *app)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+ return priv->permissions;
+}
+
+/**
* as_app_get_mimetypes:
* @app: a #AsApp instance.
*
@@ -1981,6 +2027,33 @@ as_app_add_kudo (AsApp *app, const gchar *kudo, gssize kudo_len)
}
/**
+ * as_app_add_permission:
+ * @app: a #AsApp instance.
+ * @permission: the permission.
+ * @permission_len: the size of @permission, or -1 if %NULL-terminated.
+ *
+ * Add a permission the application has obtained.
+ *
+ * Since: 0.3.5
+ **/
+void
+as_app_add_permission (AsApp *app, const gchar *permission, gssize permission_len)
+{
+ AsAppPrivate *priv = GET_PRIVATE (app);
+
+ /* handle untrusted */
+ if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_VALID_UTF8) > 0 &&
+ !as_app_validate_utf8 (permission, permission_len)) {
+ return;
+ }
+ if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_DUPLICATES) > 0 &&
+ as_app_array_find_string (priv->permissions, permission, permission_len)) {
+ return;
+ }
+ g_ptr_array_add (priv->permissions, as_strndup (permission, permission_len));
+}
+
+/**
* as_app_add_kudo_kind:
* @app: a #AsApp instance.
* @kudo_kind: the #AsKudoKind.
@@ -2564,6 +2637,12 @@ as_app_subsume_private (AsApp *app, AsApp *donor, AsAppSubsumeFlags flags)
as_app_add_kudo (app, tmp, -1);
}
+ /* permissions */
+ for (i = 0; i < priv->permissions->len; i++) {
+ tmp = g_ptr_array_index (priv->permissions, i);
+ as_app_add_permission (app, tmp, -1);
+ }
+
/* extends */
for (i = 0; i < priv->extends->len; i++) {
tmp = g_ptr_array_index (priv->extends, i);
@@ -3005,6 +3084,16 @@ as_app_node_insert (AsApp *app, GNode *parent, AsNodeContext *ctx)
}
}
+ /* <permissions> */
+ if (priv->permissions->len > 0 && api_version >= 0.8) {
+ g_ptr_array_sort (priv->permissions, as_app_ptr_array_sort_cb);
+ node_tmp = as_node_insert (node_app, "permissions", NULL, 0, NULL);
+ for (i = 0; i < priv->permissions->len; i++) {
+ tmp = g_ptr_array_index (priv->permissions, i);
+ as_node_insert (node_tmp, "permission", tmp, 0, NULL);
+ }
+ }
+
/* <vetos> */
if (priv->vetos->len > 0 && api_version >= 0.8) {
g_ptr_array_sort (priv->vetos, as_app_ptr_array_sort_cb);
@@ -3317,6 +3406,20 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags,
}
break;
+ /* <permissions> */
+ case AS_TAG_PERMISSIONS:
+ if (!(flags & AS_APP_PARSE_FLAG_APPEND_DATA))
+ g_ptr_array_set_size (priv->permissions, 0);
+ for (c = n->children; c != NULL; c = c->next) {
+ if (as_node_get_tag (c) != AS_TAG_PERMISSION)
+ continue;
+ taken = as_node_take_data (c);
+ if (taken == NULL)
+ continue;
+ g_ptr_array_add (priv->permissions, taken);
+ }
+ break;
+
/* <vetos> */
case AS_TAG_VETOS:
if (!(flags & AS_APP_PARSE_FLAG_APPEND_DATA))
diff --git a/libappstream-glib/as-app.h b/libappstream-glib/as-app.h
index 0dc0cb3..47ba797 100644
--- a/libappstream-glib/as-app.h
+++ b/libappstream-glib/as-app.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
+ * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
@@ -227,6 +227,7 @@ GPtrArray *as_app_get_extends (AsApp *app);
GPtrArray *as_app_get_keywords (AsApp *app,
const gchar *locale);
GPtrArray *as_app_get_kudos (AsApp *app);
+GPtrArray *as_app_get_permissions (AsApp *app);
GPtrArray *as_app_get_mimetypes (AsApp *app);
GPtrArray *as_app_get_pkgnames (AsApp *app);
GPtrArray *as_app_get_architectures (AsApp *app);
@@ -274,6 +275,8 @@ gboolean as_app_has_kudo (AsApp *app,
const gchar *kudo);
gboolean as_app_has_kudo_kind (AsApp *app,
AsKudoKind kudo);
+gboolean as_app_has_permission (AsApp *app,
+ const gchar *permission);
/* setters */
void as_app_set_id (AsApp *app,
@@ -339,6 +342,9 @@ void as_app_add_kudo (AsApp *app,
gssize kudo_len);
void as_app_add_kudo_kind (AsApp *app,
AsKudoKind kudo_kind);
+void as_app_add_permission (AsApp *app,
+ const gchar *permission,
+ gssize permission_len);
void as_app_add_mimetype (AsApp *app,
const gchar *mimetype,
gssize mimetype_len);
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index a653ad4..69eb0be 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
+ * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
@@ -855,6 +855,9 @@ as_test_app_func (void)
"<kudos>\n"
"<kudo>SearchProvider</kudo>\n"
"</kudos>\n"
+ "<permissions>\n"
+ "<permission>Network</permission>\n"
+ "</permissions>\n"
"<vetos>\n"
"<veto>Required AppData: ConsoleOnly</veto>\n"
"</vetos>\n"
@@ -923,12 +926,14 @@ as_test_app_func (void)
g_assert_cmpint (as_app_get_releases(app)->len, ==, 1);
g_assert_cmpint (as_app_get_provides(app)->len, ==, 3);
g_assert_cmpint (as_app_get_kudos(app)->len, ==, 1);
+ g_assert_cmpint (as_app_get_permissions(app)->len, ==, 1);
g_assert_cmpstr (as_app_get_metadata_item (app, "SomethingRandom"), ==, "");
g_assert_cmpint (as_app_get_language (app, "en_GB"), ==, 90);
g_assert_cmpint (as_app_get_language (app, "pl"), ==, 0);
g_assert_cmpint (as_app_get_language (app, "xx_XX"), ==, -1);
g_assert (as_app_has_kudo (app, "SearchProvider"));
g_assert (as_app_has_kudo_kind (app, AS_KUDO_KIND_SEARCH_PROVIDER));
+ g_assert (as_app_has_permission (app, "Network"));
g_assert (!as_app_has_kudo (app, "MagicValue"));
g_assert (!as_app_has_kudo_kind (app, AS_KUDO_KIND_USER_DOCS));
as_node_unref (root);
diff --git a/libappstream-glib/as-tag.c b/libappstream-glib/as-tag.c
index 9ed5d78..7f4f8f2 100644
--- a/libappstream-glib/as-tag.c
+++ b/libappstream-glib/as-tag.c
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
+ * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com>
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
@@ -186,6 +186,8 @@ as_tag_to_string (AsTag tag)
"vetos",
"veto",
"bundle",
+ "permissions",
+ "permission",
NULL };
if (tag > AS_TAG_LAST)
tag = AS_TAG_LAST;
diff --git a/libappstream-glib/as-tag.gperf b/libappstream-glib/as-tag.gperf
index 019d417..7b4b962 100644
--- a/libappstream-glib/as-tag.gperf
+++ b/libappstream-glib/as-tag.gperf
@@ -50,3 +50,5 @@ source_pkgname, AS_TAG_SOURCE_PKGNAME
vetos, AS_TAG_VETOS
veto, AS_TAG_VETO
bundle, AS_TAG_BUNDLE
+permissions, AS_TAG_PERMISSIONS
+permission, AS_TAG_PERMISSION
diff --git a/libappstream-glib/as-tag.h b/libappstream-glib/as-tag.h
index 45e3cbc..77857f8 100644
--- a/libappstream-glib/as-tag.h
+++ b/libappstream-glib/as-tag.h
@@ -1,6 +1,6 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
- * Copyright (C) 2014 Richard Hughes <richard@hughsie.com`
+ * Copyright (C) 2014-2015 Richard Hughes <richard@hughsie.com`
*
* Licensed under the GNU Lesser General Public License Version 2.1
*
@@ -73,6 +73,8 @@
* @AS_TAG_VETOS: `vetos`
* @AS_TAG_VETO: `veto`
* @AS_TAG_BUNDLE: `bundle`
+ * @AS_TAG_PERMISSIONS: `permissions`
+ * @AS_TAG_PERMISSION: `permission`
*
* The tag type.
**/
@@ -120,6 +122,8 @@ typedef enum {
AS_TAG_VETOS, /* Since: 0.3.0 */
AS_TAG_VETO, /* Since: 0.3.0 */
AS_TAG_BUNDLE, /* Since: 0.3.5 */
+ AS_TAG_PERMISSIONS, /* Since: 0.3.5 */
+ AS_TAG_PERMISSION, /* Since: 0.3.5 */
/*< private >*/
AS_TAG_LAST
} AsTag;