[balsa] Use g_uri_* functions instead of custom code



commit 4e4d3c3733a94f440acee765ded43f1514e7d192
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Fri Apr 14 21:28:17 2017 -0400

    Use g_uri_* functions instead of custom code
    
        * libbalsa/misc.h: define libbalsa_urlencode and libbalsa_decode
          to use g_uri_escape_string and g_uri_unescape_string, instead of
          declaring the custom functions;
        * libbalsa/misc.c: remove the custom functions.

 ChangeLog       |    7 ++++++
 libbalsa/misc.c |   56 -------------------------------------------------------
 libbalsa/misc.h |    4 +-
 3 files changed, 9 insertions(+), 58 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ca9c073..c20cad4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2017-04-14  Peter Bloomfield  <pbloomfield bellsouth net>
 
+       * libbalsa/misc.h: define libbalsa_urlencode and libbalsa_decode
+         to use g_uri_escape_string and g_uri_unescape_string, instead of
+         declaring the custom functions;
+       * libbalsa/misc.c: remove the custom functions.
+
+2017-04-14  Peter Bloomfield  <pbloomfield bellsouth net>
+
        * libbalsa/mailbox_pop3.c (notify_progress),
          (libbalsa_mailbox_pop3_check): cast gsize to unsigned long, to
          print portably with %lu.
diff --git a/libbalsa/misc.c b/libbalsa/misc.c
index 7f9ea7d..997b22a 100644
--- a/libbalsa/misc.c
+++ b/libbalsa/misc.c
@@ -129,62 +129,6 @@ libbalsa_get_domainname(void)
     return NULL;
 }
 
-/* libbalsa_urlencode: 
- * Taken from PHP's urlencode()
- */
-gchar*
-libbalsa_urlencode(const gchar* str)
-{
-    static const unsigned char hexchars[] = "0123456789ABCDEF";
-    gchar *retval = NULL;
-    gchar *x = NULL;
-    
-    g_return_val_if_fail(str != NULL, NULL);
-    
-    retval = malloc(strlen(str) * 3 + 1);
-    
-    for (x = retval; *str != '\0'; str++, x++) {
-       *x = *str;
-       if (*x == ' ') {
-           *x = '+';
-       } else if (!isalnum(*x) && strchr("_-.", *x) == NULL) {
-           /* Allow only alnum chars and '_', '-', '.'; escape the rest */
-           *x++ = '%';
-           *x++ = hexchars[(*str >> 4) & 0x0F];
-           *x = hexchars[(*str) & 0x0F];
-       }
-    }
-    
-    *x = '\0';
-    return retval;
-}
-
-gchar *
-libbalsa_urldecode(const gchar * str)
-{
-    gchar *retval;
-    gchar *x;
-
-    retval = g_new(char, strlen(str)+1);
-
-    for (x = retval; *str != '\0'; str++, x++) {
-       *x = *str;
-       if (*x == '+')
-           *x = ' ';
-       else if (*x == '%') {
-           if (!*++str || !g_ascii_isxdigit(*str))
-               break;
-           *x = g_ascii_xdigit_value(*str);
-           if (!*++str || !g_ascii_isxdigit(*str))
-               break;
-           *x = *x << 4 | g_ascii_xdigit_value(*str);
-       }
-    }
-
-    *x = '\0';
-    return retval;
-}
-
 /* readfile allocates enough space for the ending '\0' characeter as well.
    returns the number of read characters.
 */
diff --git a/libbalsa/misc.h b/libbalsa/misc.h
index fc4d6fb..755bcf7 100644
--- a/libbalsa/misc.h
+++ b/libbalsa/misc.h
@@ -96,8 +96,8 @@ size_t libbalsa_readfile_nostat(FILE * fp, char **buf);
 
 gchar *libbalsa_get_hostname(void);
 gchar *libbalsa_get_domainname(void);
-gchar *libbalsa_urlencode(const gchar* str);
-gchar *libbalsa_urldecode(const gchar * str);
+#define libbalsa_urlencode(str) (g_uri_escape_string((str), NULL, FALSE))
+#define libbalsa_urldecode(str) (g_uri_unescape_string((str), NULL))
 
 gboolean libbalsa_find_word(const gchar * word, const gchar * str);
 void libbalsa_wrap_string(gchar * str, int width);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]