LCOV - code coverage report
Current view: top level - libmalcontent - app-filter.h (source / functions) Hit Total Coverage
Test: unnamed Lines: 3 3 100.0 %
Date: 2020-12-09 07:02:21 Functions: 5 5 100.0 %
Branches: 4 4 100.0 %

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

Generated by: LCOV version 1.14