Bug 564728 Add function to decode base64 encoded data in place
authorMatthias Clasen <mclasen@redhat.com>
Tue, 13 Jan 2009 19:59:32 +0000 (19:59 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Tue, 13 Jan 2009 19:59:32 +0000 (19:59 +0000)
2009-01-13  Matthias Clasen  <mclasen@redhat.com>

        Bug 564728 Add function to decode base64 encoded data in place

        * glib/glib.symbols:
        * glib/gbase64.[hc] (g_base64_decode_inplace): New convenience
        API to decode in place, overwriting the input string. Patch by
        Sebastian Dröge.

svn path=/trunk/; revision=7807

ChangeLog
docs/reference/ChangeLog
docs/reference/glib/glib-sections.txt
docs/reference/glib/tmpl/base64.sgml
glib/gbase64.c
glib/gbase64.h
glib/glib.symbols

index c350ced7d3292778cfac9226c92c46d233fe5c5c..61e6532a3762daed0e36f4de8475da7e0ab0b5e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2009-01-13  Matthias Clasen  <mclasen@redhat.com>
+
+       Bug 564728 Add function to decode base64 encoded data in place
+
+       * glib/glib.symbols:
+       * glib/gbase64.[hc] (g_base64_decode_inplace): New convenience
+       API to decode in place, overwriting the input string. Patch by
+       Sebastian Dröge.
+
 2009-01-12  Matthias Clasen  <mclasen@redhat.com>
        
        * glib/gtestutils.c (g_strcmp0): Be more explicit about the NULL
index b2ba91a24648cecb72fbbb51dcffe546b6382e60..306a897300ffc79691d17307fa2e8875dd252116 100644 (file)
@@ -1,3 +1,8 @@
+2009-01-13  Matthias Clasen  <mclasen@redhat.com>
+
+       * glib/glib-sections.txt:
+       * glib/tmpl/base64.sgml: Mention g_base64_decode_inplace
+
 2009-01-05  Matthias Clasen  <mclasen@redhat.com>
 
        * === Released 2.19.4 ===
index 49a51bfb53e08f5ac29040b98fe0f90d6bb1cebb..e7e09ed691054218d75671a496b28b39604fec93 100644 (file)
@@ -2527,6 +2527,7 @@ g_base64_encode_close
 g_base64_encode
 g_base64_decode_step
 g_base64_decode
+g_base64_decode_inplace
 </SECTION>
 
 <SECTION>
index 787be6d3961db3401832caf53624597adf6c53d4..64aec5a28c9967283cde66a883ad57d5067afae2 100644 (file)
@@ -18,7 +18,8 @@ for email.
 GLib supports incremental encoding using g_base64_encode_step() and
 g_base64_encode_close(). Incremental decoding can be done with
 g_base64_decode_step(). To encode or decode data in one go, use 
-g_base64_encode() or g_base64_decode(). 
+g_base64_encode() or g_base64_decode(). To avoid memory allocation when
+decoding, you can use g_base64_decode_inplace().
 </para>
 
 <para>
index 437c4c983898b28cd56d4e83dd1767f79bb5e238..7f83c88df2563ade76feeae14c4012e557d47d35 100644 (file)
@@ -374,6 +374,39 @@ g_base64_decode (const gchar *text,
   
   return ret; 
 }
+/**
+ * g_base64_decode_inplace:
+ * @text: zero-terminated string with base64 text to decode
+ * @out_len: The length of the decoded data is written here
+ *
+ * Decode a sequence of Base-64 encoded text into binary data
+ * by overwriting the input data.
+ *
+ * Return value: The binary data that @text responds. This pointer
+ *               is the same as the input @text.
+ *
+ * Since: 2.20
+ */
+guchar *
+g_base64_decode_inplace (gchar *text,
+                         gsize *out_len)
+{
+  gint input_length, state = 0;
+  guint save = 0;
+  
+  g_return_val_if_fail (text != NULL, NULL);
+  g_return_val_if_fail (out_len != NULL, NULL);
+
+  input_length = strlen (text);
+
+  g_return_val_if_fail (input_length > 1, NULL);
+
+  *out_len = g_base64_decode_step (text, input_length, (guchar *) text, &state, &save);
+  
+  return text; 
+}
+
 
 #define __G_BASE64_C__
 #include "galiasdef.c"
index 63f08a4b735a650400b656412ab0de4c14ece718..2f7c49fdd90f68b81e8efabd22fe4a44ad8d96df 100644 (file)
@@ -48,6 +48,9 @@ gsize   g_base64_decode_step  (const gchar  *in,
                               guint        *save);
 guchar *g_base64_decode       (const gchar  *text,
                               gsize        *out_len) G_GNUC_MALLOC;
+guchar *g_base64_decode_inplace (gchar      *text,
+                                 gsize      *out_len);
+
 
 G_END_DECLS
 
index 0667062b7f77bc321806a8e49ac0552bc443d782..333164f541aa48fa5ca374cba8774b8837232f69 100644 (file)
@@ -111,6 +111,7 @@ g_base64_encode_close
 g_base64_encode G_GNUC_MALLOC
 g_base64_decode_step
 g_base64_decode G_GNUC_MALLOC
+g_base64_decode_inplace
 #endif
 #endif