diff options
author | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-07-15 14:58:33 +0100 |
---|---|---|
committer | Simon McVittie <simon.mcvittie@collabora.co.uk> | 2010-07-15 14:58:33 +0100 |
commit | 0a4a1594704253ffffa587a16a69b2a5674bc1a2 (patch) | |
tree | 5d6b4fe35282b3e0b81c19b631905e8be9c24011 /telepathy-glib/base-protocol.c | |
parent | 78d7eff35b01b1415e877de9841d00624623e2d4 (diff) | |
download | telepathy-glib-0a4a1594704253ffffa587a16a69b2a5674bc1a2.tar.gz |
Factor out tp_base_protocol_sanitize_parameters
Diffstat (limited to 'telepathy-glib/base-protocol.c')
-rw-r--r-- | telepathy-glib/base-protocol.c | 94 |
1 files changed, 56 insertions, 38 deletions
diff --git a/telepathy-glib/base-protocol.c b/telepathy-glib/base-protocol.c index a73342317..3b7a6a08c 100644 --- a/telepathy-glib/base-protocol.c +++ b/telepathy-glib/base-protocol.c @@ -875,51 +875,24 @@ _tp_cm_param_spec_coerce (const TpCMParamSpec *param_spec, g_assert_not_reached (); } -/** - * tp_base_protocol_new_connection: - * @self: a Protocol object - * @asv: (transfer none) (element-type utf8 GObject.Value): the parameters - * provided via D-Bus - * @error: used to return an error if %NULL is returned - * - * Create a new connection using the #TpBaseProtocolClass.get_parameters and - * #TpBaseProtocolClass.new_connection implementations provided by a subclass. - * This is used to implement the RequestConnection() D-Bus method. - * - * If the parameters in @asv do not fit the result of @get_parameters (unknown - * parameters are given, types are inappropriate, required parameters are - * not given, or a #TpCMParamSpec.filter fails), then this method raises an - * error and @new_connection is not called. - * - * Otherwise, @new_connection is called. Its @asv argument is a copy of the - * @asv given to this method, with default values for missing parameters - * filled in where available, and parameters' types converted to the #GType - * specified by #TpCMParamSpec.gtype. - * - * Returns: a new connection, or %NULL on error - */ -TpBaseConnection * -tp_base_protocol_new_connection (TpBaseProtocol *self, +static GHashTable * +tp_base_protocol_sanitize_parameters (TpBaseProtocol *self, GHashTable *asv, + gboolean allow_omissions, GError **error) { - TpBaseProtocolClass *cls = TP_BASE_PROTOCOL_GET_CLASS (self); GHashTable *combined; const TpCMParamSpec *parameters; guint i; - TpBaseConnection *conn = NULL; guint mandatory_flag; - g_return_val_if_fail (cls != NULL, NULL); - g_return_val_if_fail (cls->new_connection != NULL, NULL); - parameters = tp_base_protocol_get_parameters (self); combined = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) tp_g_value_slice_free); if (!_tp_cm_param_spec_check_all_allowed (parameters, asv, error)) - goto finally; + goto except; if (tp_asv_get_boolean (asv, "register", NULL)) { @@ -941,7 +914,7 @@ tp_base_protocol_new_connection (TpBaseProtocol *self, error); if (coerced == NULL) - goto finally; + goto except; if (G_UNLIKELY (G_VALUE_TYPE (coerced) != parameters[i].gtype)) { @@ -956,7 +929,7 @@ tp_base_protocol_new_connection (TpBaseProtocol *self, { DEBUG ("parameter %s rejected by filter function", name); tp_g_value_slice_free (coerced); - goto finally; + goto except; } } @@ -970,13 +943,14 @@ tp_base_protocol_new_connection (TpBaseProtocol *self, DEBUG ("using specified value for %s", name); g_hash_table_insert (combined, g_strdup (name), coerced); } - else if ((parameters[i].flags & mandatory_flag) != 0) + else if ((parameters[i].flags & mandatory_flag) != 0 && + !allow_omissions) { DEBUG ("missing mandatory account parameter %s", name); g_set_error (error, TP_ERRORS, TP_ERROR_INVALID_ARGUMENT, "missing mandatory account parameter %s", name); - goto finally; + goto except; } else if ((parameters[i].flags & TP_CONN_MGR_PARAM_FLAG_HAS_DEFAULT) != 0) { @@ -991,11 +965,55 @@ tp_base_protocol_new_connection (TpBaseProtocol *self, } } - conn = cls->new_connection (self, combined, error); + return combined; + +except: + g_hash_table_unref (combined); + return NULL; +} + +/** + * tp_base_protocol_new_connection: + * @self: a Protocol object + * @asv: (transfer none) (element-type utf8 GObject.Value): the parameters + * provided via D-Bus + * @error: used to return an error if %NULL is returned + * + * Create a new connection using the #TpBaseProtocolClass.get_parameters and + * #TpBaseProtocolClass.new_connection implementations provided by a subclass. + * This is used to implement the RequestConnection() D-Bus method. + * + * If the parameters in @asv do not fit the result of @get_parameters (unknown + * parameters are given, types are inappropriate, required parameters are + * not given, or a #TpCMParamSpec.filter fails), then this method raises an + * error and @new_connection is not called. + * + * Otherwise, @new_connection is called. Its @asv argument is a copy of the + * @asv given to this method, with default values for missing parameters + * filled in where available, and parameters' types converted to the #GType + * specified by #TpCMParamSpec.gtype. + * + * Returns: a new connection, or %NULL on error + */ +TpBaseConnection * +tp_base_protocol_new_connection (TpBaseProtocol *self, + GHashTable *asv, + GError **error) +{ + TpBaseProtocolClass *cls = TP_BASE_PROTOCOL_GET_CLASS (self); + GHashTable *combined; + TpBaseConnection *conn = NULL; + + g_return_val_if_fail (cls != NULL, NULL); + g_return_val_if_fail (cls->new_connection != NULL, NULL); + + combined = tp_base_protocol_sanitize_parameters (self, asv, FALSE, error); -finally: if (combined != NULL) - g_hash_table_unref (combined); + { + conn = cls->new_connection (self, combined, error); + g_hash_table_unref (combined); + } return conn; } |