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 : : *
47 : : * These are directly equivalent to the values in the `AsContentRatingValue`
48 : : * enumeration in libappstream.
49 : : *
50 : : * Since: 0.2.0
51 : : */
52 : : typedef enum
53 : : {
54 : : MCT_APP_FILTER_OARS_VALUE_UNKNOWN,
55 : : MCT_APP_FILTER_OARS_VALUE_NONE,
56 : : MCT_APP_FILTER_OARS_VALUE_MILD,
57 : : MCT_APP_FILTER_OARS_VALUE_MODERATE,
58 : : MCT_APP_FILTER_OARS_VALUE_INTENSE,
59 : : } MctAppFilterOarsValue;
60 : :
61 : : /**
62 : : * MctAppFilter:
63 : : *
64 : : * An opaque, immutable structure which contains a snapshot of the app filtering
65 : : * settings for a user at a given time.
66 : : *
67 : : * This includes a list of apps which are explicitly banned or allowed to be run
68 : : * by that user.
69 : : *
70 : : * Typically, app filter settings can only be changed by the administrator, and
71 : : * are read-only for non-administrative users. The precise policy is set using
72 : : * polkit.
73 : : *
74 : : * Since: 0.2.0
75 : : */
76 : : typedef struct _MctAppFilter MctAppFilter;
77 : : GType mct_app_filter_get_type (void);
78 : : #define MCT_TYPE_APP_FILTER mct_app_filter_get_type ()
79 : :
80 : : MctAppFilter *mct_app_filter_ref (MctAppFilter *filter);
81 : : void mct_app_filter_unref (MctAppFilter *filter);
82 : :
83 [ + + ]: 378 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctAppFilter, mct_app_filter_unref)
84 : :
85 : : uid_t mct_app_filter_get_user_id (MctAppFilter *filter);
86 : :
87 : : gboolean mct_app_filter_is_enabled (MctAppFilter *filter);
88 : :
89 : : gboolean mct_app_filter_is_path_allowed (MctAppFilter *filter,
90 : : const gchar *path);
91 : : gboolean mct_app_filter_is_flatpak_ref_allowed (MctAppFilter *filter,
92 : : const gchar *app_ref);
93 : : gboolean mct_app_filter_is_flatpak_app_allowed (MctAppFilter *filter,
94 : : const gchar *app_id);
95 : : gboolean mct_app_filter_is_appinfo_allowed (MctAppFilter *filter,
96 : : GAppInfo *app_info);
97 : : gboolean mct_app_filter_is_content_type_allowed (MctAppFilter *filter,
98 : : const gchar *content_type);
99 : :
100 : : const gchar **mct_app_filter_get_oars_sections (MctAppFilter *filter);
101 : : MctAppFilterOarsValue mct_app_filter_get_oars_value (MctAppFilter *filter,
102 : : const gchar *oars_section);
103 : :
104 : : gboolean mct_app_filter_is_user_installation_allowed (MctAppFilter *filter);
105 : : gboolean mct_app_filter_is_system_installation_allowed (MctAppFilter *filter);
106 : :
107 : : GVariant *mct_app_filter_serialize (MctAppFilter *filter);
108 : : MctAppFilter *mct_app_filter_deserialize (GVariant *variant,
109 : : uid_t user_id,
110 : : GError **error);
111 : :
112 : : gboolean mct_app_filter_equal (MctAppFilter *a,
113 : : MctAppFilter *b);
114 : :
115 : : /**
116 : : * MctAppFilterBuilder:
117 : : *
118 : : * A stack-allocated mutable structure used to build an
119 : : * [struct@Malcontent.AppFilter] instance.
120 : : *
121 : : * Use [method@Malcontent.AppFilterBuilder.init], various method
122 : : * calls to set properties of the app filter, and then
123 : : * [method@Malcontent.AppFilterBuilder.end], to construct an
124 : : * [struct@Malcontent.AppFilter].
125 : : *
126 : : * Since: 0.2.0
127 : : */
128 : : typedef struct
129 : : {
130 : : /*< private >*/
131 : : gpointer p0;
132 : : gpointer p1;
133 : : gboolean b0;
134 : : gboolean b1;
135 : : gpointer p2;
136 : : gpointer p3;
137 : : } MctAppFilterBuilder;
138 : :
139 : : GType mct_app_filter_builder_get_type (void);
140 : :
141 : : /**
142 : : * MCT_APP_FILTER_BUILDER_INIT:
143 : : *
144 : : * Initialise a stack-allocated [struct@Malcontent.AppFilterBuilder] instance at
145 : : * declaration time.
146 : : *
147 : : * This is typically used with `g_auto()`:
148 : : * ```c
149 : : * g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
150 : : * ```
151 : : *
152 : : * Since: 0.2.0
153 : : */
154 : : #define MCT_APP_FILTER_BUILDER_INIT() \
155 : : { \
156 : : g_ptr_array_new_with_free_func (g_free), \
157 : : g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL), \
158 : : TRUE, \
159 : : FALSE, \
160 : : /* padding: */ \
161 : : NULL, \
162 : : NULL \
163 : : }
164 : :
165 : : void mct_app_filter_builder_init (MctAppFilterBuilder *builder);
166 : : void mct_app_filter_builder_clear (MctAppFilterBuilder *builder);
167 : :
168 : 17 : G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (MctAppFilterBuilder,
169 : : mct_app_filter_builder_clear)
170 : :
171 : : MctAppFilterBuilder *mct_app_filter_builder_new (void);
172 : : MctAppFilterBuilder *mct_app_filter_builder_copy (MctAppFilterBuilder *builder);
173 : : void mct_app_filter_builder_free (MctAppFilterBuilder *builder);
174 : :
175 [ + + ]: 48 : G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctAppFilterBuilder, mct_app_filter_builder_free)
176 : :
177 : : MctAppFilter *mct_app_filter_builder_end (MctAppFilterBuilder *builder);
178 : :
179 : : void mct_app_filter_builder_blocklist_path (MctAppFilterBuilder *builder,
180 : : const gchar *path);
181 : : void mct_app_filter_builder_blocklist_flatpak_ref (MctAppFilterBuilder *builder,
182 : : const gchar *app_ref);
183 : : void mct_app_filter_builder_blocklist_content_type (MctAppFilterBuilder *builder,
184 : : const gchar *content_type);
185 : :
186 : : void mct_app_filter_builder_set_oars_value (MctAppFilterBuilder *builder,
187 : : const gchar *oars_section,
188 : : MctAppFilterOarsValue value);
189 : :
190 : : void mct_app_filter_builder_set_allow_user_installation (MctAppFilterBuilder *builder,
191 : : gboolean allow_user_installation);
192 : : void mct_app_filter_builder_set_allow_system_installation (MctAppFilterBuilder *builder,
193 : : gboolean allow_system_installation);
194 : :
195 : : #include <libmalcontent/manager.h>
196 : :
197 : : /* FIXME: Eventually deprecate these compatibility fallbacks. */
198 : : typedef MctManagerError MctAppFilterError;
199 : : #define MCT_APP_FILTER_ERROR_INVALID_USER MCT_MANAGER_ERROR_INVALID_USER
200 : : #define MCT_APP_FILTER_ERROR_PERMISSION_DENIED MCT_MANAGER_ERROR_PERMISSION_DENIED
201 : : #define MCT_APP_FILTER_ERROR_INVALID_DATA MCT_MANAGER_ERROR_INVALID_DATA
202 : : #define MCT_APP_FILTER_ERROR_DISABLED MCT_MANAGER_ERROR_DISABLED
203 : :
204 : : GQuark mct_app_filter_error_quark (void);
205 : : #define MCT_APP_FILTER_ERROR mct_app_filter_error_quark ()
206 : :
207 : : G_END_DECLS
|