Branch data Line data Source code
1 : : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 : : *
3 : : * Copyright © 2018-2019 Endless Mobile, Inc.
4 : : *
5 : : * SPDX-License-Identifier: LGPL-2.1-or-later
6 : : *
7 : : * This library is free software; you can redistribute it and/or
8 : : * modify it under the terms of the GNU Lesser General Public
9 : : * License as published by the Free Software Foundation; either
10 : : * version 2.1 of the License, or (at your option) any later version.
11 : : *
12 : : * This library is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : * Lesser General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU Lesser General Public
18 : : * License along with this library; if not, write to the Free Software
19 : : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 : : *
21 : : * Authors:
22 : : * - Philip Withnall <withnall@endlessm.com>
23 : : * - Andre Moreira Magalhaes <andre@endlessm.com>
24 : : */
25 : :
26 : : #pragma once
27 : :
28 : : #include <gio/gio.h>
29 : : #include <glib.h>
30 : : #include <glib-object.h>
31 : :
32 : : G_BEGIN_DECLS
33 : :
34 : : /**
35 : : * MctAppFilterOarsValue:
36 : : * @MCT_APP_FILTER_OARS_VALUE_UNKNOWN: Unknown value for the given
37 : : * section.
38 : : * @MCT_APP_FILTER_OARS_VALUE_NONE: No rating for the given section.
39 : : * @MCT_APP_FILTER_OARS_VALUE_MILD: Mild rating for the given section.
40 : : * @MCT_APP_FILTER_OARS_VALUE_MODERATE: Moderate rating for the given
41 : : * section.
42 : : * @MCT_APP_FILTER_OARS_VALUE_INTENSE: Intense rating for the given
43 : : * section.
44 : : *
45 : : * Rating values of the intensity of a given section in an app or game.
46 : : * These are directly equivalent to the values in the #AsContentRatingValue
47 : : * enumeration in libappstream.
48 : : *
49 : : * Since: 0.2.0
50 : : */
51 : : typedef enum
52 : : {
53 : : MCT_APP_FILTER_OARS_VALUE_UNKNOWN,
54 : : MCT_APP_FILTER_OARS_VALUE_NONE,
55 : : MCT_APP_FILTER_OARS_VALUE_MILD,
56 : : MCT_APP_FILTER_OARS_VALUE_MODERATE,
57 : : MCT_APP_FILTER_OARS_VALUE_INTENSE,
58 : : } MctAppFilterOarsValue;
59 : :
60 : : /**
61 : : * MctAppFilter:
62 : : *
63 : : * #MctAppFilter is an opaque, immutable structure which contains a snapshot of
64 : : * the app filtering settings for a user at a given time. This includes a list
65 : : * of apps which are explicitly banned or allowed to be run by that user.
66 : : *
67 : : * Typically, app filter settings can only be changed by the administrator, and
68 : : * are read-only for non-administrative users. The precise policy is set using
69 : : * polkit.
70 : : *
71 : : * Since: 0.2.0
72 : : */
73 : : typedef struct _MctAppFilter MctAppFilter;
74 : : GType mct_app_filter_get_type (void);
75 : : #define MCT_TYPE_APP_FILTER mct_app_filter_get_type ()
76 : :
77 : : MctAppFilter *mct_app_filter_ref (MctAppFilter *filter);
78 : : void mct_app_filter_unref (MctAppFilter *filter);
79 : :
80 [ + + ]: 378 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctAppFilter, mct_app_filter_unref)
81 : :
82 : : uid_t mct_app_filter_get_user_id (MctAppFilter *filter);
83 : :
84 : : gboolean mct_app_filter_is_enabled (MctAppFilter *filter);
85 : :
86 : : gboolean mct_app_filter_is_path_allowed (MctAppFilter *filter,
87 : : const gchar *path);
88 : : gboolean mct_app_filter_is_flatpak_ref_allowed (MctAppFilter *filter,
89 : : const gchar *app_ref);
90 : : gboolean mct_app_filter_is_flatpak_app_allowed (MctAppFilter *filter,
91 : : const gchar *app_id);
92 : : gboolean mct_app_filter_is_appinfo_allowed (MctAppFilter *filter,
93 : : GAppInfo *app_info);
94 : : gboolean mct_app_filter_is_content_type_allowed (MctAppFilter *filter,
95 : : const gchar *content_type);
96 : :
97 : : const gchar **mct_app_filter_get_oars_sections (MctAppFilter *filter);
98 : : MctAppFilterOarsValue mct_app_filter_get_oars_value (MctAppFilter *filter,
99 : : const gchar *oars_section);
100 : :
101 : : gboolean mct_app_filter_is_user_installation_allowed (MctAppFilter *filter);
102 : : gboolean mct_app_filter_is_system_installation_allowed (MctAppFilter *filter);
103 : :
104 : : GVariant *mct_app_filter_serialize (MctAppFilter *filter);
105 : : MctAppFilter *mct_app_filter_deserialize (GVariant *variant,
106 : : uid_t user_id,
107 : : GError **error);
108 : :
109 : : gboolean mct_app_filter_equal (MctAppFilter *a,
110 : : MctAppFilter *b);
111 : :
112 : : /**
113 : : * MctAppFilterBuilder:
114 : : *
115 : : * #MctAppFilterBuilder is a stack-allocated mutable structure used to build an
116 : : * #MctAppFilter instance. Use mct_app_filter_builder_init(), various method
117 : : * calls to set properties of the app filter, and then
118 : : * mct_app_filter_builder_end(), to construct an #MctAppFilter.
119 : : *
120 : : * Since: 0.2.0
121 : : */
122 : : typedef struct
123 : : {
124 : : /*< private >*/
125 : : gpointer p0;
126 : : gpointer p1;
127 : : gboolean b0;
128 : : gboolean b1;
129 : : gpointer p2;
130 : : gpointer p3;
131 : : } MctAppFilterBuilder;
132 : :
133 : : GType mct_app_filter_builder_get_type (void);
134 : :
135 : : /**
136 : : * MCT_APP_FILTER_BUILDER_INIT:
137 : : *
138 : : * Initialise a stack-allocated #MctAppFilterBuilder instance at declaration
139 : : * time.
140 : : *
141 : : * This is typically used with g_auto():
142 : : * |[
143 : : * g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
144 : : * ]|
145 : : *
146 : : * Since: 0.2.0
147 : : */
148 : : #define MCT_APP_FILTER_BUILDER_INIT() \
149 : : { \
150 : : g_ptr_array_new_with_free_func (g_free), \
151 : : g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL), \
152 : : TRUE, \
153 : : FALSE, \
154 : : /* padding: */ \
155 : : NULL, \
156 : : NULL \
157 : : }
158 : :
159 : : void mct_app_filter_builder_init (MctAppFilterBuilder *builder);
160 : : void mct_app_filter_builder_clear (MctAppFilterBuilder *builder);
161 : :
162 : 17 : G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (MctAppFilterBuilder,
163 : : mct_app_filter_builder_clear)
164 : :
165 : : MctAppFilterBuilder *mct_app_filter_builder_new (void);
166 : : MctAppFilterBuilder *mct_app_filter_builder_copy (MctAppFilterBuilder *builder);
167 : : void mct_app_filter_builder_free (MctAppFilterBuilder *builder);
168 : :
169 [ + + ]: 48 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctAppFilterBuilder, mct_app_filter_builder_free)
170 : :
171 : : MctAppFilter *mct_app_filter_builder_end (MctAppFilterBuilder *builder);
172 : :
173 : : void mct_app_filter_builder_blocklist_path (MctAppFilterBuilder *builder,
174 : : const gchar *path);
175 : : void mct_app_filter_builder_blocklist_flatpak_ref (MctAppFilterBuilder *builder,
176 : : const gchar *app_ref);
177 : : void mct_app_filter_builder_blocklist_content_type (MctAppFilterBuilder *builder,
178 : : const gchar *content_type);
179 : :
180 : : void mct_app_filter_builder_set_oars_value (MctAppFilterBuilder *builder,
181 : : const gchar *oars_section,
182 : : MctAppFilterOarsValue value);
183 : :
184 : : void mct_app_filter_builder_set_allow_user_installation (MctAppFilterBuilder *builder,
185 : : gboolean allow_user_installation);
186 : : void mct_app_filter_builder_set_allow_system_installation (MctAppFilterBuilder *builder,
187 : : gboolean allow_system_installation);
188 : :
189 : : #include <libmalcontent/manager.h>
190 : :
191 : : /* FIXME: Eventually deprecate these compatibility fallbacks. */
192 : : typedef MctManagerError MctAppFilterError;
193 : : #define MCT_APP_FILTER_ERROR_INVALID_USER MCT_MANAGER_ERROR_INVALID_USER
194 : : #define MCT_APP_FILTER_ERROR_PERMISSION_DENIED MCT_MANAGER_ERROR_PERMISSION_DENIED
195 : : #define MCT_APP_FILTER_ERROR_INVALID_DATA MCT_MANAGER_ERROR_INVALID_DATA
196 : : #define MCT_APP_FILTER_ERROR_DISABLED MCT_MANAGER_ERROR_DISABLED
197 : :
198 : : GQuark mct_app_filter_error_quark (void);
199 : : #define MCT_APP_FILTER_ERROR mct_app_filter_error_quark ()
200 : :
201 : : G_END_DECLS
|