Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
violethaze74
appstream
Commits
b5fe2b28
Commit
b5fe2b28
authored
Jan 15, 2020
by
Matthias Klumpp
Browse files
Add function to test if a license string is for free software
parent
3b1a4c12
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/as-spdx.c
View file @
b5fe2b28
...
...
@@ -645,3 +645,58 @@ as_get_license_url (const gchar *license)
return
g_strdup_printf
(
"https://spdx.org/licenses/%s.html#page"
,
license_id
->
str
);
}
/**
* as_license_is_free_license:
* @license: The SPDX license string to test.
*
* Check if the given license is for free-as-in-freedom software.
* Currently, all licenses listed on the SPDX website are considered to
* be "free software" licenses.
*
* This definition may be tightened in future. In any case, this function does
* not give any legal advice. Please read the license texts to know more about
* the individual licenses.
*
* Returns: %TRUE if the license string contains only free-as-in-freedom licenses.
*/
gboolean
as_license_is_free_license
(
const
gchar
*
license
)
{
g_auto
(
GStrv
)
tokens
=
NULL
;
gboolean
is_free
;
/* assume we have a free software license, unless proven otherwise */
is_free
=
TRUE
;
tokens
=
as_spdx_license_tokenize
(
license
);
for
(
guint
i
=
0
;
tokens
[
i
]
!=
NULL
;
i
++
)
{
if
(
g_strcmp0
(
tokens
[
i
],
"&"
)
==
0
||
g_strcmp0
(
tokens
[
i
],
"+"
)
==
0
||
g_strcmp0
(
tokens
[
i
],
"|"
)
==
0
||
g_strcmp0
(
tokens
[
i
],
"^"
)
==
0
||
g_strcmp0
(
tokens
[
i
],
"("
)
==
0
||
g_strcmp0
(
tokens
[
i
],
")"
)
==
0
)
continue
;
if
(
g_str_has_prefix
(
tokens
[
i
],
"@LicenseRef"
))
{
/* we only consider license ref's to be free if they explicitly state so */
if
(
!
g_str_has_prefix
(
tokens
[
i
],
"@LicenseRef-free"
))
{
is_free
=
FALSE
;
break
;
}
}
else
if
(
g_str_has_prefix
(
tokens
[
i
],
"@NOASSERTION"
)
||
g_str_has_prefix
(
tokens
[
i
],
"@NONE"
))
{
/* no license info is fishy as well */
is_free
=
FALSE
;
break
;
}
if
(
tokens
[
i
][
0
]
!=
'@'
)
{
/* if token has no license-id prefix, consider the license to be non-free */
is_free
=
FALSE
;
break
;
}
}
return
is_free
;
}
src/as-spdx.h
View file @
b5fe2b28
...
...
@@ -39,6 +39,7 @@ gchar *as_spdx_license_detokenize (gchar **license_tokens);
gchar
*
as_license_to_spdx_id
(
const
gchar
*
license
);
gboolean
as_license_is_metadata_license
(
const
gchar
*
license
);
gboolean
as_license_is_free_license
(
const
gchar
*
license
);
gchar
*
as_get_license_url
(
const
gchar
*
license
);
...
...
tests/test-basics.c
View file @
b5fe2b28
...
...
@@ -344,6 +344,14 @@ test_spdx (void)
tmp
=
as_get_license_url
(
"LicenseRef-proprietary=https://example.com/mylicense.txt"
);
g_assert_cmpstr
(
tmp
,
==
,
"https://example.com/mylicense.txt"
);
g_free
(
tmp
);
/* licenses are free-as-in-freedom */
g_assert
(
as_license_is_free_license
(
"CC0"
));
g_assert
(
as_license_is_free_license
(
"GPL-2.0 AND FSFAP"
));
g_assert
(
as_license_is_free_license
(
"OFL-1.1 OR (GPL-3.0-or-later WITH Font-exception-2.0)"
));
g_assert
(
!
as_license_is_free_license
(
"NOASSERTION"
));
g_assert
(
!
as_license_is_free_license
(
"LicenseRef-proprietary=https://example.com/mylicense.txt"
));
g_assert
(
!
as_license_is_free_license
(
"MIT AND LicenseRef-proprietary=https://example.com/lic.txt"
));
}
/**
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment