mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-12 15:50:34 +01:00
libnm-core: drop nm_setting_lookup_type_by_quark()
nm_setting_lookup_type_by_quark() was only ever used in places that were still mistakenly assuming the old style of nm_connection_verify() errors, where the error message would contain only a property name and no further explanation. Fix those places to assume that the error will contain a real error message, and include both the setting name and the property name. Given that, there's no longer any need for nm_setting_lookup_type_by_quark(), so drop it.
This commit is contained in:
parent
63957e0ed2
commit
a7b1ee77db
8 changed files with 11 additions and 53 deletions
|
|
@ -46,13 +46,11 @@ typedef enum {
|
|||
|
||||
void _nm_register_setting (const char *name,
|
||||
const GType type,
|
||||
const guint32 priority,
|
||||
const GQuark error_quark);
|
||||
const guint32 priority);
|
||||
|
||||
#define _nm_register_setting(name, priority) \
|
||||
G_STMT_START { \
|
||||
_nm_register_setting (NM_SETTING_ ## name ## _SETTING_NAME "", g_define_type_id, priority, NM_SETTING_ ## name ## _ERROR); \
|
||||
g_type_ensure (NM_TYPE_SETTING_ ## name ## _ERROR); \
|
||||
_nm_register_setting (NM_SETTING_ ## name ## _SETTING_NAME "", g_define_type_id, priority); \
|
||||
} G_STMT_END
|
||||
|
||||
gboolean _nm_setting_is_base_type (NMSetting *setting);
|
||||
|
|
|
|||
|
|
@ -69,7 +69,6 @@ typedef struct {
|
|||
const char *name;
|
||||
GType type;
|
||||
guint32 priority;
|
||||
GQuark error_quark;
|
||||
} SettingInfo;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -127,7 +126,6 @@ _ensure_registered (void)
|
|||
* @name: the name of the #NMSetting object to register
|
||||
* @type: the #GType of the #NMSetting
|
||||
* @priority: the sort priority of the setting, see below
|
||||
* @error_quark: the setting's error quark
|
||||
*
|
||||
* INTERNAL ONLY: registers a setting's internal properties, like its priority
|
||||
* and its error quark type, with libnm.
|
||||
|
|
@ -158,22 +156,19 @@ _ensure_registered (void)
|
|||
void
|
||||
(_nm_register_setting) (const char *name,
|
||||
const GType type,
|
||||
const guint32 priority,
|
||||
const GQuark error_quark)
|
||||
const guint32 priority)
|
||||
{
|
||||
SettingInfo *info;
|
||||
|
||||
g_return_if_fail (name != NULL && *name);
|
||||
g_return_if_fail (type != G_TYPE_INVALID);
|
||||
g_return_if_fail (type != G_TYPE_NONE);
|
||||
g_return_if_fail (error_quark != 0);
|
||||
g_return_if_fail (priority <= 4);
|
||||
|
||||
_ensure_registered ();
|
||||
|
||||
if (G_LIKELY ((info = g_hash_table_lookup (registered_settings, name)))) {
|
||||
g_return_if_fail (info->type == type);
|
||||
g_return_if_fail (info->error_quark == error_quark);
|
||||
g_return_if_fail (info->priority == priority);
|
||||
g_return_if_fail (g_strcmp0 (info->name, name) == 0);
|
||||
return;
|
||||
|
|
@ -186,7 +181,6 @@ void
|
|||
info = g_slice_new0 (SettingInfo);
|
||||
info->type = type;
|
||||
info->priority = priority;
|
||||
info->error_quark = error_quark;
|
||||
info->name = name;
|
||||
g_hash_table_insert (registered_settings, (void *) info->name, info);
|
||||
g_hash_table_insert (registered_settings_by_type, &info->type, info);
|
||||
|
|
@ -260,32 +254,6 @@ nm_setting_lookup_type (const char *name)
|
|||
return info ? info->type : G_TYPE_INVALID;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_setting_lookup_type_by_quark:
|
||||
* @error_quark: a setting error quark
|
||||
*
|
||||
* Returns the #GType of the setting's class for a given setting error quark.
|
||||
* Useful for figuring out which setting a returned error is for.
|
||||
*
|
||||
* Returns: the #GType of the setting's class, or %G_TYPE_INVALID if
|
||||
* @error_quark is not recognized
|
||||
**/
|
||||
GType
|
||||
nm_setting_lookup_type_by_quark (GQuark error_quark)
|
||||
{
|
||||
SettingInfo *info;
|
||||
GHashTableIter iter;
|
||||
|
||||
_ensure_registered ();
|
||||
|
||||
g_hash_table_iter_init (&iter, registered_settings);
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &info)) {
|
||||
if (info->error_quark == error_quark)
|
||||
return info->type;
|
||||
}
|
||||
return G_TYPE_INVALID;
|
||||
}
|
||||
|
||||
gint
|
||||
_nm_setting_compare_priority (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -244,7 +244,6 @@ typedef void (*NMSettingValueIterFn) (NMSetting *setting,
|
|||
GType nm_setting_get_type (void);
|
||||
|
||||
GType nm_setting_lookup_type (const char *name);
|
||||
GType nm_setting_lookup_type_by_quark (GQuark error_quark);
|
||||
|
||||
NMSetting *nm_setting_duplicate (NMSetting *setting);
|
||||
|
||||
|
|
|
|||
|
|
@ -686,7 +686,6 @@ global:
|
|||
nm_setting_ip6_config_remove_route;
|
||||
nm_setting_ip6_config_remove_route_by_value;
|
||||
nm_setting_lookup_type;
|
||||
nm_setting_lookup_type_by_quark;
|
||||
nm_setting_olpc_mesh_error_get_type;
|
||||
nm_setting_olpc_mesh_error_quark;
|
||||
nm_setting_olpc_mesh_get_channel;
|
||||
|
|
|
|||
|
|
@ -491,9 +491,8 @@ impl_vpn_plugin_need_secrets (NMVpnPlugin *plugin,
|
|||
g_dbus_method_invocation_return_error (context,
|
||||
NM_VPN_PLUGIN_ERROR,
|
||||
NM_VPN_PLUGIN_ERROR_CONNECTION_INVALID,
|
||||
"The connection was invalid: '%s' / '%s' invalid: %d.",
|
||||
g_type_name (nm_setting_lookup_type_by_quark (error->domain)),
|
||||
error->message, error->code);
|
||||
"The connection was invalid: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -834,9 +834,8 @@ claim_connection (NMSettings *self,
|
|||
}
|
||||
|
||||
if (!nm_connection_normalize (NM_CONNECTION (connection), NULL, NULL, &error)) {
|
||||
nm_log_warn (LOGD_SETTINGS, "plugin provided invalid connection: '%s' / '%s' invalid: %d",
|
||||
g_type_name (nm_setting_lookup_type_by_quark (error->domain)),
|
||||
error->message, error->code);
|
||||
nm_log_warn (LOGD_SETTINGS, "plugin provided invalid connection: %s",
|
||||
error->message);
|
||||
g_error_free (error);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -197,11 +197,8 @@ update_connection_settings_commit_cb (NMSettingsConnection *orig, GError *error,
|
|||
* an error here.
|
||||
*/
|
||||
if (error) {
|
||||
nm_log_warn (LOGD_SETTINGS, "%s: '%s' / '%s' invalid: %d",
|
||||
__func__,
|
||||
error ? g_type_name (nm_setting_lookup_type_by_quark (error->domain)) : "(none)",
|
||||
(error && error->message) ? error->message : "(none)",
|
||||
error ? error->code : -1);
|
||||
nm_log_warn (LOGD_SETTINGS, "%s: connection invalid: %s",
|
||||
__func__, error->message);
|
||||
g_clear_error (&error);
|
||||
|
||||
nm_settings_connection_signal_remove (orig);
|
||||
|
|
|
|||
|
|
@ -1385,9 +1385,8 @@ nm_keyfile_plugin_connection_from_file (const char *filename, GError **error)
|
|||
/* Normalize and verify the connection */
|
||||
if (!nm_connection_normalize (connection, NULL, NULL, &verify_error)) {
|
||||
g_set_error (error, KEYFILE_PLUGIN_ERROR, 0,
|
||||
"invalid or missing connection property '%s/%s'",
|
||||
verify_error ? g_type_name (nm_setting_lookup_type_by_quark (verify_error->domain)) : "(unknown)",
|
||||
(verify_error && verify_error->message) ? verify_error->message : "(unknown)");
|
||||
"invalid connection: %s",
|
||||
verify_error->message);
|
||||
g_clear_error (&verify_error);
|
||||
g_object_unref (connection);
|
||||
connection = NULL;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue