1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2  *
3  * Copyright (C) 2014 Richard Hughes <richard@hughsie.com>
4  *
5  * SPDX-License-Identifier: LGPL-2.1+
6  */
7 
8 #pragma once
9 
10 #if !defined (__APPSTREAM_GLIB_H_INSIDE__) && !defined (AS_COMPILATION)
11 #error "Only <appstream-glib.h> can be included directly."
12 #endif
13 
14 #include <glib.h>
15 
16 #include "as-app.h"
17 #include "as-bundle.h"
18 
19 G_BEGIN_DECLS
20 
21 /**
22  * AsUtilsError:
23  * @AS_UTILS_ERROR_FAILED:			Generic failure
24  * @AS_UTILS_ERROR_INVALID_TYPE:		Invalid type
25  *
26  * The error type.
27  **/
28 typedef enum {
29 	AS_UTILS_ERROR_FAILED,
30 	AS_UTILS_ERROR_INVALID_TYPE,
31 	/*< private >*/
32 	AS_UTILS_ERROR_LAST
33 } AsUtilsError;
34 
35 #define	AS_UTILS_ERROR				as_utils_error_quark ()
36 
37 /**
38  * AsUtilsFindIconFlag:
39  * @AS_UTILS_FIND_ICON_NONE:			No flags set
40  * @AS_UTILS_FIND_ICON_HI_DPI:			Prefer a HiDPI icon
41  *
42  * The flags used when finding icons.
43  **/
44 typedef enum {
45 	AS_UTILS_FIND_ICON_NONE			= 0,
46 	AS_UTILS_FIND_ICON_HI_DPI		= 1 << 0,
47 	/*< private >*/
48 	AS_UTILS_FIND_ICON_LAST
49 } AsUtilsFindIconFlag;
50 
51 /**
52  * AsUtilsLocation:
53  * @AS_UTILS_LOCATION_SHARED:			Installed by the vendor, shared
54  * @AS_UTILS_LOCATION_CACHE:			Installed as metadata, shared
55  * @AS_UTILS_LOCATION_USER:			Installed by the user
56  *
57  * The flags used when installing and removing metadata files.
58  **/
59 typedef enum {
60 	AS_UTILS_LOCATION_SHARED,
61 	AS_UTILS_LOCATION_CACHE,
62 	AS_UTILS_LOCATION_USER,
63 	/*< private >*/
64 	AS_UTILS_LOCATION_LAST
65 } AsUtilsLocation;
66 
67 /**
68  * AsVersionParseFlag:
69  * @AS_VERSION_PARSE_FLAG_NONE:			No flags set
70  * @AS_VERSION_PARSE_FLAG_USE_TRIPLET:		Use Microsoft-style version numbers
71  * @AS_VERSION_PARSE_FLAG_USE_BCD:		Use binary coded decimal notation
72  *
73  * The flags used when parsing version numbers.
74  **/
75 typedef enum {
76 	AS_VERSION_PARSE_FLAG_NONE		= 0,
77 	AS_VERSION_PARSE_FLAG_USE_TRIPLET	= 1 << 0,
78 	AS_VERSION_PARSE_FLAG_USE_BCD		= 1 << 1,	/* Since: 0.7.3 */
79 	/*< private >*/
80 	AS_VERSION_PARSE_FLAG_LAST
81 } AsVersionParseFlag;
82 
83 /**
84  * AsVersionCompareFlag:
85  * @AS_VERSION_COMPARE_FLAG_NONE:		No flags set
86  * @AS_VERSION_COMPARE_FLAG_USE_HEURISTICS:	Use a heuristic to parse version numbers
87  *
88  * The flags used when comparing version numbers.
89  **/
90 typedef enum {
91 	AS_VERSION_COMPARE_FLAG_NONE		= 0,
92 	AS_VERSION_COMPARE_FLAG_USE_HEURISTICS	= 1 << 0,
93 	/*< private >*/
94 	AS_VERSION_COMPARE_FLAG_LAST
95 } AsVersionCompareFlag;
96 
97 /**
98  * AsUniqueIdMatchFlags:
99  * @AS_UNIQUE_ID_MATCH_FLAG_NONE:		No flags set
100  * @AS_UNIQUE_ID_MATCH_FLAG_SCOPE:		Scope, e.g. a #AsAppScope
101  * @AS_UNIQUE_ID_MATCH_FLAG_BUNDLE_KIND:	Bundle kind, e.g. a #AsBundleKind
102  * @AS_UNIQUE_ID_MATCH_FLAG_ORIGIN:		Origin
103  * @AS_UNIQUE_ID_MATCH_FLAG_KIND:		Component kind, e.g. a #AsAppKind
104  * @AS_UNIQUE_ID_MATCH_FLAG_ID:			Component AppStream ID
105  * @AS_UNIQUE_ID_MATCH_FLAG_BRANCH:		Branch
106  *
107  * The flags used when matching unique IDs.
108  **/
109 typedef enum {
110 	AS_UNIQUE_ID_MATCH_FLAG_NONE		= 0,
111 	AS_UNIQUE_ID_MATCH_FLAG_SCOPE		= 1 << 0,
112 	AS_UNIQUE_ID_MATCH_FLAG_BUNDLE_KIND	= 1 << 1,	/* Since: 0.7.8 */
113 	AS_UNIQUE_ID_MATCH_FLAG_ORIGIN		= 1 << 2,	/* Since: 0.7.8 */
114 	AS_UNIQUE_ID_MATCH_FLAG_KIND		= 1 << 3,	/* Since: 0.7.8 */
115 	AS_UNIQUE_ID_MATCH_FLAG_ID		= 1 << 4,	/* Since: 0.7.8 */
116 	AS_UNIQUE_ID_MATCH_FLAG_BRANCH		= 1 << 5,	/* Since: 0.7.8 */
117 	/*< private >*/
118 	AS_UNIQUE_ID_MATCH_FLAG_LAST
119 } AsUniqueIdMatchFlags;
120 
121 GQuark		 as_utils_error_quark		(void);
122 gboolean	 as_utils_is_stock_icon_name	(const gchar	*name);
123 gboolean	 as_utils_is_spdx_license_id	(const gchar	*license_id);
124 gboolean	 as_utils_is_spdx_license	(const gchar	*license);
125 gboolean	 as_utils_is_environment_id	(const gchar	*environment_id);
126 gboolean	 as_utils_is_category_id	(const gchar	*category_id);
127 
128 G_DEPRECATED
129 gboolean	 as_utils_is_blacklisted_id	(const gchar	*desktop_id);
130 
131 gchar		**as_utils_spdx_license_tokenize (const gchar	*license);
132 gchar		*as_utils_spdx_license_detokenize (gchar	**license_tokens);
133 gchar		*as_utils_license_to_spdx	(const gchar	*license);
134 gchar		*as_utils_find_icon_filename	(const gchar	*destdir,
135 						 const gchar	*search,
136 						 GError		**error);
137 gchar		*as_utils_find_icon_filename_full (const gchar	*destdir,
138 						 const gchar	*search,
139 						 AsUtilsFindIconFlag flags,
140 						 GError		**error);
141 gboolean	 as_utils_install_filename	(AsUtilsLocation location,
142 						 const gchar	*filename,
143 						 const gchar	*origin,
144 						 const gchar	*destdir,
145 						 GError		**error);
146 gboolean	 as_utils_search_token_valid	(const gchar	*token);
147 gchar		**as_utils_search_tokenize	(const gchar	*search);
148 gint		 as_utils_vercmp_full		(const gchar	*version_a,
149 						 const gchar	*version_b,
150 						 AsVersionCompareFlag flags);
151 gint		 as_utils_vercmp		(const gchar	*version_a,
152 						 const gchar	*version_b);
153 gboolean	 as_utils_guid_is_valid		(const gchar	*guid);
154 gchar		*as_utils_guid_from_string	(const gchar	*str);
155 gchar		*as_utils_guid_from_data	(const gchar	*namespace_id,
156 						 const guint8	*data,
157 						 gsize		 data_len,
158 						 GError		**error);
159 gchar		*as_utils_version_from_uint32	(guint32	 val,
160 						 AsVersionParseFlag flags);
161 gchar		*as_utils_version_from_uint16	(guint16	 val,
162 						 AsVersionParseFlag flags);
163 gchar		*as_utils_version_parse		(const gchar	*version);
164 guint		 as_utils_string_replace	(GString	*string,
165 						 const gchar	*search,
166 						 const gchar	*replace);
167 gchar		*as_utils_unique_id_build	(AsAppScope	 scope,
168 						 AsBundleKind	 bundle_kind,
169 						 const gchar	*origin,
170 						 AsAppKind	 kind,
171 						 const gchar	*id,
172 						 const gchar	*branch);
173 gboolean	 as_utils_unique_id_equal	(const gchar	*unique_id1,
174 						 const gchar	*unique_id2);
175 gboolean	 as_utils_unique_id_match	(const gchar	*unique_id1,
176 						 const gchar	*unique_id2,
177 						 AsUniqueIdMatchFlags match_flags);
178 gboolean	 as_utils_unique_id_valid	(const gchar	*unique_id);
179 guint		 as_utils_unique_id_hash	(const gchar	*unique_id);
180 gchar		*as_utils_appstream_id_build	(const gchar	*str);
181 gboolean	 as_utils_appstream_id_valid	(const gchar	*str);
182 
183 G_END_DECLS
184