# HG changeset patch # User Mark Doliner # Date 1246325948 0 # Node ID 3d92b968d49ff7bc34235b00905a6ab3a0037d77 # Parent f1385d46220521fbbc478bacba14f63cb9248a08 Use glib's base64 encode and decode functions if they're available. Our purple_base64_decode() implementation is horrendously ineffecient, by the way. It allocates memory inside a while loop while decoding. It should allocate memory ahead of time (the glib version does this). The glib version is here if anyone wants to steal it: http://git.gnome.org./cgit/glib/tree/glib/gbase64.c diff -r f1385d462205 -r 3d92b968d49f libpurple/util.c --- a/libpurple/util.c Mon Jun 29 13:40:18 2009 +0000 +++ b/libpurple/util.c Tue Jun 30 01:39:08 2009 +0000 @@ -219,6 +219,9 @@ gchar * purple_base64_encode(const guchar *data, gsize len) { +#if GLIB_CHECK_VERSION(2,12,0) + return g_base64_encode(data, len); +#else char *out, *rv; g_return_val_if_fail(data != NULL, NULL); @@ -253,11 +256,21 @@ *out = '\0'; return rv; +#endif /* GLIB < 2.12.0 */ } guchar * purple_base64_decode(const char *str, gsize *ret_len) { +#if GLIB_CHECK_VERSION(2,12,0) + /* + * We want to allow ret_len to be NULL for backward compatibility, + * but g_base64_decode() requires a valid length variable. So if + * ret_len is NULL then pass in a dummy variable. + */ + gsize unused; + return g_base64_decode(str, ret_len != NULL ? ret_len : &unused); +#else guchar *out = NULL; char tmp = 0; const char *c; @@ -319,6 +332,7 @@ *ret_len = len; return out; +#endif /* GLIB < 2.12.0 */ } /**************************************************************************