From 4b93eeb1110f4830af058626685fb55ac293ecda Mon Sep 17 00:00:00 2001 From: Jakub Adam Date: Tue, 29 Mar 2011 21:57:25 +0200 Subject: [PATCH] utils: move sipmsg_uri_unescape() to sipe-utils.h --- src/core/sipe-utils.c | 43 +++++++++++++++++++++++++++++++++++++++++++ src/core/sipe-utils.h | 9 +++++++++ src/core/sipmsg.c | 42 ++---------------------------------------- 3 files changed, 54 insertions(+), 40 deletions(-) diff --git a/src/core/sipe-utils.c b/src/core/sipe-utils.c index c27ca22d..2bef3edf 100644 --- a/src/core/sipe-utils.c +++ b/src/core/sipe-utils.c @@ -563,6 +563,49 @@ gchar *sipe_utils_subscription_key(const gchar *event, return key; } +gchar * +sipe_utils_uri_unescape(const gchar *string) +{ + gchar *unescaped; + gchar *tmp; + + if (!string) + return NULL; + +#if GLIB_CHECK_VERSION(2,16,0) + unescaped = g_uri_unescape_string(string, NULL); +#else + // based on libpurple/util.c:purple_url_decode() + { + GString *buf = g_string_new(NULL); + size_t len = strlen(string); + char hex[3]; + + hex[2] = '\0'; + + while (len--) { + gchar c = *string++; + + if ((len >= 2) && (c == '%')) { + strncpy(hex, string, 2); + c = strtol(hex, NULL, 16); + + string += 2; + len -= 2; + } + + g_string_append_c(buf, c); + } + + unescaped = g_string_free(buf, FALSE); + } +#endif + if (unescaped && !g_utf8_validate(unescaped, -1, (const gchar **)&tmp)) + *tmp = '\0'; + + return unescaped; +} + /* Local Variables: mode: c diff --git a/src/core/sipe-utils.h b/src/core/sipe-utils.h index 887a37cf..ba055001 100644 --- a/src/core/sipe-utils.h +++ b/src/core/sipe-utils.h @@ -446,3 +446,12 @@ gchar *sipe_utils_presence_key(const gchar *uri); */ gchar *sipe_utils_subscription_key(const gchar *event, const gchar *uri); + +/** + * Decodes a URI into a plain string. + * + * @param string the string to translate. + * + * @return the resulting string. Must be g_free()'d after use. + */ +gchar *sipe_utils_uri_unescape(const gchar *string); diff --git a/src/core/sipmsg.c b/src/core/sipmsg.c index b42e73cd..b3d4701d 100644 --- a/src/core/sipmsg.c +++ b/src/core/sipmsg.c @@ -672,44 +672,6 @@ sipmsg_get_ms_diagnostics_reason(struct sipmsg *msg) #define MSG_LEN 2048 #define BUF_LEN MSG_LEN -static -gchar *sipmsg_uri_unescape(const gchar *string) -{ - gchar *unescaped, *tmp; - - if (!string) return(NULL); - -#if GLIB_CHECK_VERSION(2,16,0) - unescaped = g_uri_unescape_string(string, NULL); -#else - /* loosely based on libpurple/util.c:purple_url_decode() */ - { - gsize i = 0; - gsize len = strlen(string); - - unescaped = g_malloc(len + 1); - while (len-- > 0) { - gchar c = *string++; - if ((len >= 2) && (c == '%')) { - char hex[3]; - strncpy(hex, string, 2); - hex[2] = '\0'; - c = strtol(hex, NULL, 16); - string += 2; - len -= 2; - } - unescaped[i++] = c; - } - unescaped[i] = '\0'; - } -#endif - - if (!g_utf8_validate(unescaped, -1, (const gchar **)&tmp)) - *tmp = '\0'; - - return(unescaped); -} - void msn_parse_format(const char *mime, char **pre_ret, char **post_ret) { @@ -811,7 +773,7 @@ msn_parse_format(const char *mime, char **pre_ret, char **post_ret) } } - cur = sipmsg_uri_unescape(pre->str); + cur = sipe_utils_uri_unescape(pre->str); g_string_free(pre, TRUE); if (pre_ret != NULL) @@ -819,7 +781,7 @@ msn_parse_format(const char *mime, char **pre_ret, char **post_ret) else g_free(cur); - cur = sipmsg_uri_unescape(post->str); + cur = sipe_utils_uri_unescape(post->str); g_string_free(post, TRUE); if (post_ret != NULL) -- 2.11.4.GIT