libmalcontent: Move MctAppFilterError to MctManagerError

This isn’t an API break, as compatibility defines are in place; and the
error code values are the same, so it shouldn’t be an ABI break. The
string value of the error quark has changed, but nobody should be
comparing that against a value which hasn’t come out of libmalcontent,
so changing it should be OK.

This is along the same lines as the previous commit: we don’t need one
error domain per property of an `MctManager`, so reduce the potential
for future duplication by renaming it now.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
This commit is contained in:
Philip Withnall 2019-12-11 15:46:14 +00:00
parent acf2738d56
commit 300b5a624f
5 changed files with 76 additions and 57 deletions

View File

@ -33,7 +33,12 @@
#include "libmalcontent/app-filter-private.h" #include "libmalcontent/app-filter-private.h"
G_DEFINE_QUARK (MctAppFilterError, mct_app_filter_error) /* FIXME: Eventually deprecate these compatibility fallbacks. */
GQuark
mct_app_filter_error_quark (void)
{
return mct_manager_error_quark ();
}
/* struct _MctAppFilter is defined in app-filter-private.h */ /* struct _MctAppFilter is defined in app-filter-private.h */

View File

@ -29,31 +29,6 @@
G_BEGIN_DECLS G_BEGIN_DECLS
/**
* MctAppFilterError:
* @MCT_APP_FILTER_ERROR_INVALID_USER: Given user ID doesnt exist
* @MCT_APP_FILTER_ERROR_PERMISSION_DENIED: Not authorized to query the app
* filter for the given user
* @MCT_APP_FILTER_ERROR_INVALID_DATA: The data stored in the app filter for
* a user is inconsistent or invalid
* @MCT_APP_FILTER_ERROR_DISABLED: App filtering is disabled for all users (Since: 0.3.0)
*
* Errors relating to #MctAppFilter instances, which can be returned by
* mct_manager_get_app_filter_async() (for example).
*
* Since: 0.2.0
*/
typedef enum
{
MCT_APP_FILTER_ERROR_INVALID_USER,
MCT_APP_FILTER_ERROR_PERMISSION_DENIED,
MCT_APP_FILTER_ERROR_INVALID_DATA,
MCT_APP_FILTER_ERROR_DISABLED,
} MctAppFilterError;
GQuark mct_app_filter_error_quark (void);
#define MCT_APP_FILTER_ERROR mct_app_filter_error_quark ()
/** /**
* MctAppFilterOarsValue: * MctAppFilterOarsValue:
* @MCT_APP_FILTER_OARS_VALUE_UNKNOWN: Unknown value for the given * @MCT_APP_FILTER_OARS_VALUE_UNKNOWN: Unknown value for the given
@ -197,4 +172,16 @@ void mct_app_filter_builder_set_allow_user_installation (MctAppFilterBuilder *
void mct_app_filter_builder_set_allow_system_installation (MctAppFilterBuilder *builder, void mct_app_filter_builder_set_allow_system_installation (MctAppFilterBuilder *builder,
gboolean allow_system_installation); gboolean allow_system_installation);
#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 ()
G_END_DECLS G_END_DECLS

View File

@ -31,6 +31,9 @@
#include "libmalcontent/app-filter-private.h" #include "libmalcontent/app-filter-private.h"
G_DEFINE_QUARK (MctManagerError, mct_manager_error)
/** /**
* MctManager: * MctManager:
* *
@ -298,19 +301,19 @@ bus_remote_error_matches (const GError *error,
return g_str_equal (error_name, expected_error_name); return g_str_equal (error_name, expected_error_name);
} }
/* Convert a #GDBusError into a #MctAppFilterError. */ /* Convert a #GDBusError into a #MctManagerError. */
static GError * static GError *
bus_error_to_app_filter_error (const GError *bus_error, bus_error_to_manager_error (const GError *bus_error,
uid_t user_id) uid_t user_id)
{ {
if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED) || if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_ACCESS_DENIED) ||
bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.PermissionDenied")) bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.PermissionDenied"))
return g_error_new (MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED, return g_error_new (MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED,
_("Not allowed to query app filter data for user %u"), _("Not allowed to query app filter data for user %u"),
(guint) user_id); (guint) user_id);
else if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) || else if (g_error_matches (bus_error, G_DBUS_ERROR, G_DBUS_ERROR_UNKNOWN_METHOD) ||
bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.Failed")) bus_remote_error_matches (bus_error, "org.freedesktop.Accounts.Error.Failed"))
return g_error_new (MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_INVALID_USER, return g_error_new (MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_INVALID_USER,
_("User %u does not exist"), (guint) user_id); _("User %u does not exist"), (guint) user_id);
else else
return g_error_copy (bus_error); return g_error_copy (bus_error);
@ -346,8 +349,8 @@ accounts_find_user_by_id (GDBusConnection *connection,
&local_error); &local_error);
if (local_error != NULL) if (local_error != NULL)
{ {
g_autoptr(GError) app_filter_error = bus_error_to_app_filter_error (local_error, g_autoptr(GError) app_filter_error = bus_error_to_manager_error (local_error,
user_id); user_id);
g_propagate_error (error, g_steal_pointer (&app_filter_error)); g_propagate_error (error, g_steal_pointer (&app_filter_error));
return NULL; return NULL;
} }
@ -415,24 +418,23 @@ mct_manager_get_app_filter (MctManager *self,
&local_error); &local_error);
if (local_error != NULL) if (local_error != NULL)
{ {
g_autoptr(GError) app_filter_error = NULL; g_autoptr(GError) manager_error = NULL;
if (g_error_matches (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS)) if (g_error_matches (local_error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS))
{ {
/* o.fd.D.GetAll() will return InvalidArgs errors if /* o.fd.D.GetAll() will return InvalidArgs errors if
* accountsservice doesnt have the com.endlessm.ParentalControls.AppFilter * accountsservice doesnt have the com.endlessm.ParentalControls.AppFilter
* extension interface installed. */ * extension interface installed. */
app_filter_error = g_error_new_literal (MCT_APP_FILTER_ERROR, manager_error = g_error_new_literal (MCT_MANAGER_ERROR,
MCT_APP_FILTER_ERROR_DISABLED, MCT_MANAGER_ERROR_DISABLED,
_("App filtering is globally disabled")); _("App filtering is globally disabled"));
} }
else else
{ {
app_filter_error = bus_error_to_app_filter_error (local_error, manager_error = bus_error_to_manager_error (local_error, user_id);
user_id);
} }
g_propagate_error (error, g_steal_pointer (&app_filter_error)); g_propagate_error (error, g_steal_pointer (&manager_error));
return NULL; return NULL;
} }
@ -442,8 +444,8 @@ mct_manager_get_app_filter (MctManager *self,
if (!g_variant_lookup (properties, "AppFilter", "(b^as)", if (!g_variant_lookup (properties, "AppFilter", "(b^as)",
&is_whitelist, &app_list)) &is_whitelist, &app_list))
{ {
g_set_error (error, MCT_APP_FILTER_ERROR, g_set_error (error, MCT_MANAGER_ERROR,
MCT_APP_FILTER_ERROR_PERMISSION_DENIED, MCT_MANAGER_ERROR_PERMISSION_DENIED,
_("Not allowed to query app filter data for user %u"), _("Not allowed to query app filter data for user %u"),
(guint) user_id); (guint) user_id);
return NULL; return NULL;
@ -462,8 +464,8 @@ mct_manager_get_app_filter (MctManager *self,
if (!g_str_equal (content_rating_kind, "oars-1.0") && if (!g_str_equal (content_rating_kind, "oars-1.0") &&
!g_str_equal (content_rating_kind, "oars-1.1")) !g_str_equal (content_rating_kind, "oars-1.1"))
{ {
g_set_error (error, MCT_APP_FILTER_ERROR, g_set_error (error, MCT_MANAGER_ERROR,
MCT_APP_FILTER_ERROR_INVALID_DATA, MCT_MANAGER_ERROR_INVALID_DATA,
_("OARS filter for user %u has an unrecognized kind %s"), _("OARS filter for user %u has an unrecognized kind %s"),
(guint) user_id, content_rating_kind); (guint) user_id, content_rating_kind);
return NULL; return NULL;
@ -528,7 +530,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (GetAppFilterData, get_app_filter_data_free)
* Asynchronously get a snapshot of the app filter settings for the given * Asynchronously get a snapshot of the app filter settings for the given
* @user_id. * @user_id.
* *
* On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be * On failure, an #MctManagerError, a #GDBusError or a #GIOError will be
* returned. * returned.
* *
* Since: 0.3.0 * Since: 0.3.0
@ -676,7 +678,7 @@ mct_manager_set_app_filter (MctManager *self,
&local_error); &local_error);
if (local_error != NULL) if (local_error != NULL)
{ {
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); g_propagate_error (error, bus_error_to_manager_error (local_error, user_id));
return FALSE; return FALSE;
} }
@ -699,7 +701,7 @@ mct_manager_set_app_filter (MctManager *self,
&local_error); &local_error);
if (local_error != NULL) if (local_error != NULL)
{ {
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); g_propagate_error (error, bus_error_to_manager_error (local_error, user_id));
return FALSE; return FALSE;
} }
@ -722,7 +724,7 @@ mct_manager_set_app_filter (MctManager *self,
&local_error); &local_error);
if (local_error != NULL) if (local_error != NULL)
{ {
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); g_propagate_error (error, bus_error_to_manager_error (local_error, user_id));
return FALSE; return FALSE;
} }
@ -745,7 +747,7 @@ mct_manager_set_app_filter (MctManager *self,
&local_error); &local_error);
if (local_error != NULL) if (local_error != NULL)
{ {
g_propagate_error (error, bus_error_to_app_filter_error (local_error, user_id)); g_propagate_error (error, bus_error_to_manager_error (local_error, user_id));
return FALSE; return FALSE;
} }
@ -786,7 +788,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (SetAppFilterData, set_app_filter_data_free)
* Asynchronously set the app filter settings for the given @user_id to the * Asynchronously set the app filter settings for the given @user_id to the
* given @app_filter instance. This will set all fields of the app filter. * given @app_filter instance. This will set all fields of the app filter.
* *
* On failure, an #MctAppFilterError, a #GDBusError or a #GIOError will be * On failure, an #MctManagerError, a #GDBusError or a #GIOError will be
* returned. The users app filter settings will be left in an undefined state. * returned. The users app filter settings will be left in an undefined state.
* *
* Since: 0.3.0 * Since: 0.3.0

View File

@ -25,7 +25,6 @@
#include <gio/gio.h> #include <gio/gio.h>
#include <glib.h> #include <glib.h>
#include <glib-object.h> #include <glib-object.h>
#include <libmalcontent/app-filter.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -73,6 +72,32 @@ typedef MctManagerSetValueFlags MctSetAppFilterFlags;
#define MCT_SET_APP_FILTER_FLAGS_NONE MCT_MANAGER_SET_VALUE_FLAGS_NONE #define MCT_SET_APP_FILTER_FLAGS_NONE MCT_MANAGER_SET_VALUE_FLAGS_NONE
#define MCT_SET_APP_FILTER_FLAGS_INTERACTIVE MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE #define MCT_SET_APP_FILTER_FLAGS_INTERACTIVE MCT_MANAGER_SET_VALUE_FLAGS_INTERACTIVE
/**
* MctManagerError:
* @MCT_MANAGER_ERROR_INVALID_USER: Given user ID doesnt exist
* @MCT_MANAGER_ERROR_PERMISSION_DENIED: Not authorized to query properties of
* the given user
* @MCT_MANAGER_ERROR_INVALID_DATA: The data stored in a property of the given
* user is inconsistent or invalid
* @MCT_MANAGER_ERROR_DISABLED: Parental controls are disabled for all users
*
* Errors relating to get/set operations on an #MctManager instance.
*
* Since: 0.5.0
*/
typedef enum
{
MCT_MANAGER_ERROR_INVALID_USER,
MCT_MANAGER_ERROR_PERMISSION_DENIED,
MCT_MANAGER_ERROR_INVALID_DATA,
MCT_MANAGER_ERROR_DISABLED,
} MctManagerError;
GQuark mct_manager_error_quark (void);
#define MCT_MANAGER_ERROR mct_manager_error_quark ()
#include <libmalcontent/app-filter.h>
#define MCT_TYPE_MANAGER mct_manager_get_type () #define MCT_TYPE_MANAGER mct_manager_get_type ()
G_DECLARE_FINAL_TYPE (MctManager, mct_manager, MCT, MANAGER, GObject) G_DECLARE_FINAL_TYPE (MctManager, mct_manager, MCT, MANAGER, GObject)

View File

@ -809,7 +809,7 @@ test_app_filter_bus_get_error_invalid_user (BusFixture *fixture,
&local_error); &local_error);
g_assert_error (local_error, g_assert_error (local_error,
MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_INVALID_USER); MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_INVALID_USER);
g_assert_null (app_filter); g_assert_null (app_filter);
} }
@ -866,7 +866,7 @@ test_app_filter_bus_get_error_permission_denied (BusFixture *fixture,
&local_error); &local_error);
g_assert_error (local_error, g_assert_error (local_error,
MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED); MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED);
g_assert_null (app_filter); g_assert_null (app_filter);
} }
@ -924,7 +924,7 @@ test_app_filter_bus_get_error_permission_denied_missing (BusFixture *fixture,
&local_error); &local_error);
g_assert_error (local_error, g_assert_error (local_error,
MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED); MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED);
g_assert_null (app_filter); g_assert_null (app_filter);
} }
@ -1027,7 +1027,7 @@ test_app_filter_bus_get_error_disabled (BusFixture *fixture,
&local_error); &local_error);
g_assert_error (local_error, g_assert_error (local_error,
MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_DISABLED); MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_DISABLED);
g_assert_null (app_filter); g_assert_null (app_filter);
} }
@ -1249,7 +1249,7 @@ test_app_filter_bus_set_error_invalid_user (BusFixture *fixture,
&local_error); &local_error);
g_assert_error (local_error, g_assert_error (local_error,
MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_INVALID_USER); MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_INVALID_USER);
g_assert_false (success); g_assert_false (success);
} }
@ -1286,7 +1286,7 @@ test_app_filter_bus_set_error_permission_denied (BusFixture *fixture,
&local_error); &local_error);
g_assert_error (local_error, g_assert_error (local_error,
MCT_APP_FILTER_ERROR, MCT_APP_FILTER_ERROR_PERMISSION_DENIED); MCT_MANAGER_ERROR, MCT_MANAGER_ERROR_PERMISSION_DENIED);
g_assert_false (success); g_assert_false (success);
} }