summaryrefslogtreecommitdiff
path: root/gst-libs/gst/rtsp/gstrtspbase64.c
blob: 9aca1e05a30bbe8640eda48c986bc7ce1f4c7053 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* GStreamer
 * Copyright (C) <2007> Mike Smith <msmith@xiph.org>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

/**
 * SECTION:gstrtspbase64
 * @short_description: Helper functions to handle Base64
 *
 * Last reviewed on 2007-07-24 (0.10.14)
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <string.h>

#include "gstrtspbase64.h"

/**
 * gst_rtsp_base64_encode:
 * @data: the binary data to encode
 * @len: the length of @data
 *
 * Encode a sequence of binary data into its Base-64 stringified representation.
 *
 * Deprecated: Use g_base64_encode()
 *
 * Returns: a newly allocated, zero-terminated Base-64 encoded string
 * representing @data.
 */
/* This isn't efficient, but it doesn't need to be */
#ifndef GST_REMOVE_DEPRECATED
gchar *
gst_rtsp_base64_encode (const gchar * data, gsize len)
{
  return g_base64_encode ((const guchar *) data, len);
}
#endif

/**
 * 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.
 */
/* FIXME: Deprecate this once we depend on GLib 2.20 and
 * use g_base64_decode_inplace then.
 */
void
gst_rtsp_base64_decode_ip (gchar * data, gsize * len)
{
  gint input_length, output_length, state = 0;
  guint save = 0;

  g_return_if_fail (data != NULL);

  input_length = strlen (data);

  g_return_if_fail (input_length > 1);

  output_length =
      g_base64_decode_step (data, input_length, (guchar *) data, &state, &save);

  if (len)
    *len = output_length;
}