From 9d176f10f7e84c046deab870e935f0b011143b6c Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 17 Sep 2014 19:56:27 +0100 Subject: [PATCH 5/5] tp_cm_param_filter_uint_nonzero: allow it to be used with guint16 --- telepathy-glib/base-protocol.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/telepathy-glib/base-protocol.c b/telepathy-glib/base-protocol.c index f98f758..01784b5 100644 --- a/telepathy-glib/base-protocol.c +++ b/telepathy-glib/base-protocol.c @@ -73,7 +73,7 @@ /** * tp_cm_param_filter_uint_nonzero: * @paramspec: The parameter specification for a guint parameter - * @value: (transfer full): A #GVariant containing a guint32 + * @value: (transfer full): A #GVariant containing a guint32 or guint16 * @user_data: unused * @error: Used to return an error if the guint is 0 * @@ -87,14 +87,34 @@ tp_cm_param_filter_uint_nonzero (const TpCMParamSpec *paramspec, gpointer user_data, GError **error) { - if (g_variant_get_uint32 (value) == 0) + switch (g_variant_classify (value)) { - g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, - "Account parameter '%s' may not be set to zero", - paramspec->name); - g_variant_unref (value); - return NULL; + case G_VARIANT_CLASS_UINT32: + if (g_variant_get_uint32 (value) == 0) + { + g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, + "Account parameter '%s' may not be set to zero", + paramspec->name); + g_variant_unref (value); + return NULL; + } + break; + + case G_VARIANT_CLASS_UINT16: + if (g_variant_get_uint32 (value) == 0) + { + g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, + "Account parameter '%s' may not be set to zero", + paramspec->name); + g_variant_unref (value); + return NULL; + } + break; + + default: + g_assert_not_reached (); } + return value; } -- 2.1.0