From 6cbb121f4dfe0bb34430c4262b64871a7dd16cfc Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 5 Feb 2014 14:55:13 +0000 Subject: [PATCH 2/7] mcd_keyfile_get_variant: add support for int16, uint16 If we're opportunistically migrating parameters according to CM-specified types, we need to cope with uint16 ('q') for port numbers. --- src/mcd-storage.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/mcd-storage.c b/src/mcd-storage.c index 481c3dc..90f6247 100644 --- a/src/mcd-storage.c +++ b/src/mcd-storage.c @@ -914,6 +914,29 @@ mcd_keyfile_get_variant (GKeyFile *keyfile, } break; + case G_VARIANT_CLASS_INT16: + { + GError *e = NULL; + gint v_int = g_key_file_get_integer (keyfile, group, + key, &e); + + if (e != NULL) + { + g_propagate_error (error, e); + } + else if (v_int < G_MININT16 || v_int > G_MAXINT16) + { + g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, + "integer %d out of range [%d,%d]", + v_int, G_MININT16, G_MAXINT16); + } + else + { + ret = g_variant_new_int16 (v_int); + } + } + break; + case G_VARIANT_CLASS_INT32: { GError *e = NULL; @@ -948,6 +971,28 @@ mcd_keyfile_get_variant (GKeyFile *keyfile, } break; + case G_VARIANT_CLASS_UINT16: + { + GError *e = NULL; + gint v_int = g_key_file_get_integer (keyfile, group, + key, &e); + + if (e != NULL) + { + g_propagate_error (error, e); + } + else if (v_int < 0 || (unsigned) v_int > G_MAXUINT16) + { + g_set_error (error, TP_ERROR, TP_ERROR_INVALID_ARGUMENT, + "integer %d out of range [0,%d]", v_int, G_MAXUINT16); + } + else + { + ret = g_variant_new_uint16 (v_int); + } + } + break; + case G_VARIANT_CLASS_UINT32: { GError *e = NULL; -- 1.9.rc1