[gnome-software] Try to work out if an application is free software
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] Try to work out if an application is free software
- Date: Wed, 9 Dec 2015 16:29:14 +0000 (UTC)
commit f5ae21816b29365a6815533427bd38ada0f07cdf
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 9 11:06:18 2015 +0000
Try to work out if an application is free software
The way we're doing this is checking that all parts of the license string are
SPDX tokens. This isn't ideal as there is a mismatch between common distros
like Fedora and SPDX, but it's what SUSE and Debian are doing (and AppStream!)
and seems to be a good distro-neutral way of doing this.
src/gs-app.c | 41 +++++++++++++++++++++++++++++++++++++++++
src/gs-app.h | 1 +
2 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index cbfbaba..49453b8 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -102,6 +102,7 @@ struct _GsApp
gboolean to_be_installed;
gboolean provenance;
AsBundle *bundle;
+ gboolean licence_is_free;
};
enum {
@@ -1285,6 +1286,36 @@ gs_app_get_licence (GsApp *app)
}
/**
+ * gs_app_get_licence_is_free:
+ */
+gboolean
+gs_app_get_licence_is_free (GsApp *app)
+{
+ g_return_val_if_fail (GS_IS_APP (app), FALSE);
+ return app->licence_is_free;
+}
+
+/**
+ * gs_app_get_licence_token_is_nonfree:
+ */
+static gboolean
+gs_app_get_licence_token_is_nonfree (const gchar *token)
+{
+ /* grammar */
+ if (g_strcmp0 (token, "(") == 0)
+ return FALSE;
+ if (g_strcmp0 (token, ")") == 0)
+ return FALSE;
+
+ /* a token, but still nonfree */
+ if (g_strcmp0 (token, "@LicenseRef-proprietary") == 0)
+ return TRUE;
+
+ /* if it has a prefix, assume it is free */
+ return token[0] != '@';
+}
+
+/**
* gs_app_set_licence:
*/
void
@@ -1301,6 +1332,9 @@ gs_app_set_licence (GsApp *app, const gchar *licence, GsAppQuality quality)
g_return_if_fail (GS_IS_APP (app));
+ /* assume free software until we find an unmatched SPDX token */
+ app->licence_is_free = TRUE;
+
/* tokenize the license string and URLify any SPDX IDs */
urld = g_string_sized_new (strlen (licence) + 1);
tokens = as_utils_spdx_license_tokenize (licence);
@@ -1324,6 +1358,13 @@ gs_app_set_licence (GsApp *app, const gchar *licence, GsAppQuality quality)
continue;
}
+ /* do the best we can */
+ if (gs_app_get_licence_token_is_nonfree (tokens[i])) {
+ g_debug ("nonfree licence from %s: '%s'",
+ gs_app_get_id (app), tokens[i]);
+ app->licence_is_free = FALSE;
+ }
+
/* legacy literal text */
if (g_str_has_prefix (tokens[i], "#")) {
g_string_append (urld, tokens[i] + 1);
diff --git a/src/gs-app.h b/src/gs-app.h
index e281533..233809d 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -166,6 +166,7 @@ void gs_app_set_url (GsApp *app,
AsUrlKind kind,
const gchar *url);
const gchar *gs_app_get_licence (GsApp *app);
+gboolean gs_app_get_licence_is_free (GsApp *app);
void gs_app_set_licence (GsApp *app,
const gchar *licence,
GsAppQuality quality);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]