diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-02-11 20:25:06 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-15 14:15:04 +0100 |
commit | 71c3c8d8e55af4b78ad99285f32ee28b6fe87aa0 (patch) | |
tree | 5a7b42174122d82a126fe296e092eb5970ab55d1 | |
parent | 591e6413698897fecbb6b96e98004462f6e0e88a (diff) |
libmm-common: use the new key/value parser in the common bearer properties builder
-rw-r--r-- | libmm-common/mm-common-bearer-properties.c | 71 |
1 files changed, 28 insertions, 43 deletions
diff --git a/libmm-common/mm-common-bearer-properties.c b/libmm-common/mm-common-bearer-properties.c index 50ddb570..b771d5b4 100644 --- a/libmm-common/mm-common-bearer-properties.c +++ b/libmm-common/mm-common-bearer-properties.c @@ -256,58 +256,43 @@ mm_common_bearer_properties_consume_string (MMCommonBearerProperties *self, return TRUE; } +typedef struct { + MMCommonBearerProperties *properties; + GError *error; +} ParseKeyValueContext; + +static gboolean +key_value_foreach (const gchar *key, + const gchar *value, + ParseKeyValueContext *ctx) +{ + return mm_common_bearer_properties_consume_string (ctx->properties, + key, + value, + &ctx->error); +} + MMCommonBearerProperties * mm_common_bearer_properties_new_from_string (const gchar *str, GError **error) { - GError *inner_error = NULL; - MMCommonBearerProperties *properties; - gchar **words; - gchar *key; - gchar *value; - guint i; - - properties = mm_common_bearer_properties_new (); - - /* Expecting input as: - * key1=string,key2=true,key3=false... - * */ + ParseKeyValueContext ctx; - words = g_strsplit_set (str, ",= ", -1); - if (!words) - return properties; - - i = 0; - key = words[i]; - while (key) { - value = words[++i]; - - if (!value) { - inner_error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_INVALID_ARGS, - "Invalid properties string, no value for key '%s'", - key); - break; - } - - if (!mm_common_bearer_properties_consume_string (properties, - key, - value, - &inner_error)) - break; - - key = words[++i]; - } + ctx.error = NULL; + ctx.properties = mm_common_bearer_properties_new (); + mm_common_parse_key_value_string (str, + &ctx.error, + (MMParseKeyValueForeachFn)key_value_foreach, + &ctx); /* If error, destroy the object */ - if (inner_error) { - g_propagate_error (error, inner_error); - g_object_unref (properties); - properties = NULL; + if (ctx.error) { + g_propagate_error (error, ctx.error); + g_object_unref (ctx.properties); + ctx.properties = NULL; } - g_strfreev (words); - return properties; + return ctx.properties; } /*****************************************************************************/ |