From 2c35823bdf49692d1d1627110742c71de767a372 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 26 Jul 2007 14:33:01 +0000 Subject: [PATCH] API: gst_rtsp_base64_decode_ip() Original commit message from CVS: * docs/libs/gst-plugins-base-libs-sections.txt: * gst-libs/gst/rtsp/gstrtspbase64.c: (gst_rtsp_base64_decode_ip): * gst-libs/gst/rtsp/gstrtspbase64.h: API: gst_rtsp_base64_decode_ip() Added function to decode Base64 in-place. --- ChangeLog | 8 ++++ docs/libs/gst-plugins-base-libs-sections.txt | 1 + gst-libs/gst/rtsp/gstrtspbase64.c | 61 +++++++++++++++++++++++++++- gst-libs/gst/rtsp/gstrtspbase64.h | 3 +- 4 files changed, 71 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index d58d479..c969c80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-07-26 Wim Taymans + + * docs/libs/gst-plugins-base-libs-sections.txt: + * gst-libs/gst/rtsp/gstrtspbase64.c: (gst_rtsp_base64_decode_ip): + * gst-libs/gst/rtsp/gstrtspbase64.h: + API: gst_rtsp_base64_decode_ip() + Added function to decode Base64 in-place. + 2007-07-26 Jan Schmidt * tests/check/libs/.cvsignore: diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index 416ddf6..1bb5484 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -1007,6 +1007,7 @@ gst_rtsp_transport_free gstrtspbase64 gst/rtsp/gstrtspbase64.h gst_rtsp_base64_encode +gst_rtsp_base64_decode_ip
diff --git a/gst-libs/gst/rtsp/gstrtspbase64.c b/gst-libs/gst/rtsp/gstrtspbase64.c index 42f3f67..40fcdd8 100644 --- a/gst-libs/gst/rtsp/gstrtspbase64.c +++ b/gst-libs/gst/rtsp/gstrtspbase64.c @@ -19,7 +19,7 @@ /** * SECTION:gstrtspbase64 - * @short_description: Helper function to encode into Base64 + * @short_description: Helper functions to handle Base64 * * Last reviewed on 2007-07-24 (0.10.14) */ @@ -28,6 +28,8 @@ #include "config.h" #endif +#include + #include "gstrtspbase64.h" static char base64table[64] = { @@ -85,3 +87,60 @@ gst_rtsp_base64_encode (const gchar * data, gsize len) return result; } + +/** + * gst_rtsp_base64_decode_ip: + * @data: the base64 encoded data + * @len: location for output length or NULL + * + * Decode the base64 string pointed to by @data in-place. When @len is not #NULL + * it will contain the length of the decoded data. + */ +void +gst_rtsp_base64_decode_ip (gchar * data, gsize * len) +{ + char dtable[256]; + int i, j, k = 0, n = strlen (data); + + for (i = 0; i < 255; i++) + dtable[i] = 0x80; + for (i = 'A'; i <= 'Z'; i++) + dtable[i] = 0 + (i - 'A'); + for (i = 'a'; i <= 'z'; i++) + dtable[i] = 26 + (i - 'a'); + for (i = '0'; i <= '9'; i++) + dtable[i] = 52 + (i - '0'); + dtable['+'] = 62; + dtable['/'] = 63; + dtable['='] = 0; + + for (j = 0; j < n; j += 4) { + char a[4], b[4]; + + for (i = 0; i < 4; i++) { + int c = data[i + j]; + + if (dtable[c] & 0x80) { + if (len) + *len = 0; + return; + } + a[i] = (char) c; + b[i] = (char) dtable[c]; + } + data[k++] = (b[0] << 2) | (b[1] >> 4); + data[k++] = (b[1] << 4) | (b[2] >> 2); + data[k++] = (b[2] << 6) | b[3]; + i = a[2] == '=' ? 1 : (a[3] == '=' ? 2 : 3); + if (i < 3) { + data[k] = 0; + if (len) + *len = k; + return; + } + } + data[k] = 0; + if (len) + *len = k; + return; +} diff --git a/gst-libs/gst/rtsp/gstrtspbase64.h b/gst-libs/gst/rtsp/gstrtspbase64.h index 29804ea..0b50ab6 100644 --- a/gst-libs/gst/rtsp/gstrtspbase64.h +++ b/gst-libs/gst/rtsp/gstrtspbase64.h @@ -24,7 +24,8 @@ G_BEGIN_DECLS -gchar *gst_rtsp_base64_encode(const gchar *data, gsize len); +gchar *gst_rtsp_base64_encode (const gchar *data, gsize len); +void gst_rtsp_base64_decode_ip (gchar *data, gsize *len); G_END_DECLS -- 2.7.4