2018-09-28 10:11:11 +02:00
|
|
|
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
|
|
|
*
|
2019-06-13 02:34:43 +02:00
|
|
|
* Copyright © 2018-2019 Endless Mobile, Inc.
|
2018-09-28 10:11:11 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* - Philip Withnall <withnall@endlessm.com>
|
2019-06-13 02:34:43 +02:00
|
|
|
* - Andre Moreira Magalhaes <andre@endlessm.com>
|
2018-09-28 10:11:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <gio/gio.h>
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2018-10-09 12:24:25 +02:00
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
* MctAppFilterOarsValue:
|
|
|
|
* @MCT_APP_FILTER_OARS_VALUE_UNKNOWN: Unknown value for the given
|
2018-10-09 12:24:25 +02:00
|
|
|
* section.
|
2019-02-26 18:43:56 +01:00
|
|
|
* @MCT_APP_FILTER_OARS_VALUE_NONE: No rating for the given section.
|
|
|
|
* @MCT_APP_FILTER_OARS_VALUE_MILD: Mild rating for the given section.
|
|
|
|
* @MCT_APP_FILTER_OARS_VALUE_MODERATE: Moderate rating for the given
|
2018-10-09 12:24:25 +02:00
|
|
|
* section.
|
2019-02-26 18:43:56 +01:00
|
|
|
* @MCT_APP_FILTER_OARS_VALUE_INTENSE: Intense rating for the given
|
2018-10-09 12:24:25 +02:00
|
|
|
* section.
|
|
|
|
*
|
|
|
|
* Rating values of the intensity of a given section in an app or game.
|
|
|
|
* These are directly equivalent to the values in the #AsContentRatingValue
|
|
|
|
* enumeration in libappstream.
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
* Since: 0.2.0
|
2018-10-09 12:24:25 +02:00
|
|
|
*/
|
|
|
|
typedef enum
|
|
|
|
{
|
2019-02-26 18:43:56 +01:00
|
|
|
MCT_APP_FILTER_OARS_VALUE_UNKNOWN,
|
|
|
|
MCT_APP_FILTER_OARS_VALUE_NONE,
|
|
|
|
MCT_APP_FILTER_OARS_VALUE_MILD,
|
|
|
|
MCT_APP_FILTER_OARS_VALUE_MODERATE,
|
|
|
|
MCT_APP_FILTER_OARS_VALUE_INTENSE,
|
|
|
|
} MctAppFilterOarsValue;
|
2018-10-09 12:24:25 +02:00
|
|
|
|
2018-09-28 10:11:11 +02:00
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
* MctAppFilter:
|
2018-09-28 10:11:11 +02:00
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
* #MctAppFilter is an opaque, immutable structure which contains a snapshot of
|
2018-09-28 10:11:11 +02:00
|
|
|
* the app filtering settings for a user at a given time. This includes a list
|
|
|
|
* of apps which are explicitly banned or allowed to be run by that user.
|
|
|
|
*
|
|
|
|
* Typically, app filter settings can only be changed by the administrator, and
|
|
|
|
* are read-only for non-administrative users. The precise policy is set using
|
|
|
|
* polkit.
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
* Since: 0.2.0
|
2018-09-28 10:11:11 +02:00
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
typedef struct _MctAppFilter MctAppFilter;
|
|
|
|
GType mct_app_filter_get_type (void);
|
2020-01-28 14:56:00 +01:00
|
|
|
#define MCT_TYPE_APP_FILTER mct_app_filter_get_type ()
|
2018-09-28 10:11:11 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
MctAppFilter *mct_app_filter_ref (MctAppFilter *filter);
|
|
|
|
void mct_app_filter_unref (MctAppFilter *filter);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctAppFilter, mct_app_filter_unref)
|
2018-09-28 10:11:11 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
uid_t mct_app_filter_get_user_id (MctAppFilter *filter);
|
2020-03-20 15:56:36 +01:00
|
|
|
|
|
|
|
gboolean mct_app_filter_is_enabled (MctAppFilter *filter);
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
gboolean mct_app_filter_is_path_allowed (MctAppFilter *filter,
|
2018-10-12 06:59:04 +02:00
|
|
|
const gchar *path);
|
2019-02-26 18:43:56 +01:00
|
|
|
gboolean mct_app_filter_is_flatpak_ref_allowed (MctAppFilter *filter,
|
2018-11-08 18:54:22 +01:00
|
|
|
const gchar *app_ref);
|
2019-02-26 18:43:56 +01:00
|
|
|
gboolean mct_app_filter_is_flatpak_app_allowed (MctAppFilter *filter,
|
2018-11-14 16:17:18 +01:00
|
|
|
const gchar *app_id);
|
2019-02-26 18:43:56 +01:00
|
|
|
gboolean mct_app_filter_is_appinfo_allowed (MctAppFilter *filter,
|
2018-11-26 15:48:45 +01:00
|
|
|
GAppInfo *app_info);
|
2019-06-13 02:34:43 +02:00
|
|
|
gboolean mct_app_filter_is_content_type_allowed (MctAppFilter *filter,
|
|
|
|
const gchar *content_type);
|
2018-09-28 10:11:11 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
const gchar **mct_app_filter_get_oars_sections (MctAppFilter *filter);
|
|
|
|
MctAppFilterOarsValue mct_app_filter_get_oars_value (MctAppFilter *filter,
|
2018-11-08 18:20:11 +01:00
|
|
|
const gchar *oars_section);
|
2018-10-09 12:24:25 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
gboolean mct_app_filter_is_user_installation_allowed (MctAppFilter *filter);
|
|
|
|
gboolean mct_app_filter_is_system_installation_allowed (MctAppFilter *filter);
|
2018-11-13 12:30:19 +01:00
|
|
|
|
2020-03-16 13:13:35 +01:00
|
|
|
GVariant *mct_app_filter_serialize (MctAppFilter *filter);
|
|
|
|
MctAppFilter *mct_app_filter_deserialize (GVariant *variant,
|
|
|
|
uid_t user_id,
|
|
|
|
GError **error);
|
|
|
|
|
2020-11-02 16:21:04 +01:00
|
|
|
gboolean mct_app_filter_equal (MctAppFilter *a,
|
|
|
|
MctAppFilter *b);
|
|
|
|
|
2018-10-12 05:47:59 +02:00
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
* MctAppFilterBuilder:
|
2018-10-12 05:47:59 +02:00
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
* #MctAppFilterBuilder is a stack-allocated mutable structure used to build an
|
|
|
|
* #MctAppFilter instance. Use mct_app_filter_builder_init(), various method
|
2018-10-12 05:47:59 +02:00
|
|
|
* calls to set properties of the app filter, and then
|
2019-02-26 18:43:56 +01:00
|
|
|
* mct_app_filter_builder_end(), to construct an #MctAppFilter.
|
2018-10-12 05:47:59 +02:00
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/*< private >*/
|
|
|
|
gpointer p0;
|
|
|
|
gpointer p1;
|
2018-11-13 12:30:19 +01:00
|
|
|
gboolean b0;
|
2018-11-29 22:09:57 +01:00
|
|
|
gboolean b1;
|
2018-10-12 05:47:59 +02:00
|
|
|
gpointer p2;
|
|
|
|
gpointer p3;
|
2019-02-26 18:43:56 +01:00
|
|
|
} MctAppFilterBuilder;
|
2018-10-12 05:47:59 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
GType mct_app_filter_builder_get_type (void);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
|
|
|
/**
|
2019-02-26 18:43:56 +01:00
|
|
|
* MCT_APP_FILTER_BUILDER_INIT:
|
2018-10-12 05:47:59 +02:00
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
* Initialise a stack-allocated #MctAppFilterBuilder instance at declaration
|
2018-10-12 05:47:59 +02:00
|
|
|
* time.
|
|
|
|
*
|
|
|
|
* This is typically used with g_auto():
|
|
|
|
* |[
|
2019-02-26 18:43:56 +01:00
|
|
|
* g_auto(MctAppFilterBuilder) builder = MCT_APP_FILTER_BUILDER_INIT ();
|
2018-10-12 05:47:59 +02:00
|
|
|
* ]|
|
|
|
|
*
|
2019-02-26 18:43:56 +01:00
|
|
|
* Since: 0.2.0
|
2018-10-12 05:47:59 +02:00
|
|
|
*/
|
2019-02-26 18:43:56 +01:00
|
|
|
#define MCT_APP_FILTER_BUILDER_INIT() \
|
2018-10-12 05:47:59 +02:00
|
|
|
{ \
|
|
|
|
g_ptr_array_new_with_free_func (g_free), \
|
2018-11-13 12:30:19 +01:00
|
|
|
g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL), \
|
2018-11-29 22:09:57 +01:00
|
|
|
TRUE, \
|
2018-11-28 17:39:39 +01:00
|
|
|
FALSE, \
|
2019-05-15 15:31:02 +02:00
|
|
|
/* padding: */ \
|
|
|
|
NULL, \
|
|
|
|
NULL \
|
2018-10-12 05:47:59 +02:00
|
|
|
}
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
void mct_app_filter_builder_init (MctAppFilterBuilder *builder);
|
|
|
|
void mct_app_filter_builder_clear (MctAppFilterBuilder *builder);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC (MctAppFilterBuilder,
|
|
|
|
mct_app_filter_builder_clear)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
MctAppFilterBuilder *mct_app_filter_builder_new (void);
|
|
|
|
MctAppFilterBuilder *mct_app_filter_builder_copy (MctAppFilterBuilder *builder);
|
|
|
|
void mct_app_filter_builder_free (MctAppFilterBuilder *builder);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MctAppFilterBuilder, mct_app_filter_builder_free)
|
2018-10-12 05:47:59 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
MctAppFilter *mct_app_filter_builder_end (MctAppFilterBuilder *builder);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
2020-06-10 00:30:39 +02:00
|
|
|
void mct_app_filter_builder_blocklist_path (MctAppFilterBuilder *builder,
|
2018-10-12 06:59:04 +02:00
|
|
|
const gchar *path);
|
2020-06-10 00:30:39 +02:00
|
|
|
void mct_app_filter_builder_blocklist_flatpak_ref (MctAppFilterBuilder *builder,
|
2018-10-12 06:59:04 +02:00
|
|
|
const gchar *app_ref);
|
2020-06-10 00:30:39 +02:00
|
|
|
void mct_app_filter_builder_blocklist_content_type (MctAppFilterBuilder *builder,
|
2019-06-13 02:34:43 +02:00
|
|
|
const gchar *content_type);
|
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
void mct_app_filter_builder_set_oars_value (MctAppFilterBuilder *builder,
|
2018-10-12 06:59:04 +02:00
|
|
|
const gchar *oars_section,
|
2019-02-26 18:43:56 +01:00
|
|
|
MctAppFilterOarsValue value);
|
2018-10-12 05:47:59 +02:00
|
|
|
|
2019-02-26 18:43:56 +01:00
|
|
|
void mct_app_filter_builder_set_allow_user_installation (MctAppFilterBuilder *builder,
|
2018-11-29 22:09:57 +01:00
|
|
|
gboolean allow_user_installation);
|
2019-02-26 18:43:56 +01:00
|
|
|
void mct_app_filter_builder_set_allow_system_installation (MctAppFilterBuilder *builder,
|
2018-11-28 17:39:39 +01:00
|
|
|
gboolean allow_system_installation);
|
2018-11-13 12:30:19 +01:00
|
|
|
|
2019-12-11 16:46:14 +01:00
|
|
|
#include <libmalcontent/manager.h>
|
|
|
|
|
|
|
|
/* FIXME: Eventually deprecate these compatibility fallbacks. */
|
|
|
|
typedef MctManagerError MctAppFilterError;
|
|
|
|
#define MCT_APP_FILTER_ERROR_INVALID_USER MCT_MANAGER_ERROR_INVALID_USER
|
|
|
|
#define MCT_APP_FILTER_ERROR_PERMISSION_DENIED MCT_MANAGER_ERROR_PERMISSION_DENIED
|
|
|
|
#define MCT_APP_FILTER_ERROR_INVALID_DATA MCT_MANAGER_ERROR_INVALID_DATA
|
|
|
|
#define MCT_APP_FILTER_ERROR_DISABLED MCT_MANAGER_ERROR_DISABLED
|
|
|
|
|
|
|
|
GQuark mct_app_filter_error_quark (void);
|
|
|
|
#define MCT_APP_FILTER_ERROR mct_app_filter_error_quark ()
|
|
|
|
|
2018-09-28 10:11:11 +02:00
|
|
|
G_END_DECLS
|