From: Marcel Holtmann Date: Wed, 1 Apr 2009 01:33:09 +0000 (-0700) Subject: Add helper function to encode D-Bus object paths X-Git-Tag: 0.16~121 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17112569b2227e443126d34dfac86e40c648ecab;p=platform%2Fupstream%2Fconnman.git Add helper function to encode D-Bus object paths --- diff --git a/include/dbus.h b/include/dbus.h index 77766c72..277e69a8 100644 --- a/include/dbus.h +++ b/include/dbus.h @@ -52,6 +52,8 @@ extern void connman_dbus_dict_append_array(DBusMessageIter *dict, extern void connman_dbus_dict_append_variant(DBusMessageIter *dict, const char *key, int type, void *val); +extern char *connman_dbus_encode_string(const char *value); + #ifdef __cplusplus } #endif diff --git a/src/dbus.c b/src/dbus.c index 062cc7ab..daa2239c 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -23,8 +23,36 @@ #include #endif +#include + #include "connman.h" +char *connman_dbus_encode_string(const char *value) +{ + GString *str; + unsigned int i, size; + + if (value == NULL) + return NULL; + + size = strlen(value); + + str = g_string_new(NULL); + if (str == NULL) + return NULL; + + for (i = 0; i < size; i++) { + const char tmp = value[i]; + if ((tmp < '0' || tmp > '9') && (tmp < 'A' || tmp > 'Z') && + (tmp < 'a' || tmp > 'z')) + g_string_append_printf(str, "_%02x", tmp); + else + str = g_string_append_c(str, tmp); + } + + return g_string_free(str, FALSE); +} + void connman_dbus_property_append_variant(DBusMessageIter *iter, const char *key, int type, void *val) {