summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2017-12-09 15:47:33 +0000
committerRichard Hughes <richard@hughsie.com>2017-12-09 15:48:30 +0000
commit12034745755ec289b698882d37feb1b67d73e5d3 (patch)
tree0dc5f80c56ed68191eaf1efdcf7510cb2111b24a
parentf060dbbd518295094fafe9cdcc662ae80bdfff90 (diff)
downloadappstream-glib-12034745755ec289b698882d37feb1b67d73e5d3.tar.gz
trivial: Check for duplicate content ratings sections with the same kind
-rw-r--r--libappstream-glib/as-app-private.h2
-rw-r--r--libappstream-glib/as-app-validate.c5
-rw-r--r--libappstream-glib/as-app.c12
3 files changed, 19 insertions, 0 deletions
diff --git a/libappstream-glib/as-app-private.h b/libappstream-glib/as-app-private.h
index a36fd7c..b9e0dd2 100644
--- a/libappstream-glib/as-app-private.h
+++ b/libappstream-glib/as-app-private.h
@@ -56,6 +56,7 @@ G_BEGIN_DECLS
* @AS_APP_PROBLEM_INVALID_KEYWORDS: One or more keywords was invalid
* @AS_APP_PROBLEM_DUPLICATE_RELEASE: More than one release with the same version
* @AS_APP_PROBLEM_DUPLICATE_SCREENSHOT: More than one screenshot with the same URL
+ * @AS_APP_PROBLEM_DUPLICATE_CONTENT_RATING: More than one content rating with the same kind
*
* The application problems detected when loading.
**/
@@ -80,6 +81,7 @@ typedef enum {
AS_APP_PROBLEM_INVALID_KEYWORDS = 1 << 16,
AS_APP_PROBLEM_DUPLICATE_RELEASE = 1 << 17,
AS_APP_PROBLEM_DUPLICATE_SCREENSHOT = 1 << 18,
+ AS_APP_PROBLEM_DUPLICATE_CONTENT_RATING = 1 << 19,
/*< private >*/
AS_APP_PROBLEM_LAST
} AsAppProblems;
diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c
index 21fa2a5..3c1f75d 100644
--- a/libappstream-glib/as-app-validate.c
+++ b/libappstream-glib/as-app-validate.c
@@ -1423,6 +1423,11 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error)
AS_PROBLEM_KIND_TAG_INVALID,
"<screenshot> content was duplicated");
}
+ if (problems & AS_APP_PROBLEM_DUPLICATE_CONTENT_RATING) {
+ ai_app_validate_add (helper,
+ AS_PROBLEM_KIND_TAG_INVALID,
+ "<content_rating> was duplicated");
+ }
/* check for things that have to exist */
if (as_app_get_id (app) == NULL) {
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 1027704..3c71167 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -3374,6 +3374,18 @@ void
as_app_add_content_rating (AsApp *app, AsContentRating *content_rating)
{
AsAppPrivate *priv = GET_PRIVATE (app);
+
+ /* handle untrusted */
+ if ((priv->trust_flags & AS_APP_TRUST_FLAG_CHECK_DUPLICATES) > 0) {
+ for (guint i = 0; i < priv->content_ratings->len; i++) {
+ AsContentRating *cr_tmp = g_ptr_array_index (priv->content_ratings, i);
+ if (g_strcmp0 (as_content_rating_get_kind (cr_tmp),
+ as_content_rating_get_kind (content_rating)) == 0) {
+ priv->problems |= AS_APP_PROBLEM_DUPLICATE_CONTENT_RATING;
+ return;
+ }
+ }
+ }
g_ptr_array_add (priv->content_ratings, g_object_ref (content_rating));
}