[vlc-devel] [PATCH 04/21] input/stream: stream-fragments: add helper to encode fragment
Filip Roséen
filip at atch.se
Sun Jul 31 22:42:13 CEST 2016
Given the specification of stream-fragments, we will need to be able
to url-encode entities N number of times in order to implement the
functionality outlined by the spec.
This commit adds "RecursiveEncode" which does just that; see the
associated documentation for more information.
---
src/input/stream.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/src/input/stream.c b/src/input/stream.c
index 0510adf..f39afab 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -37,6 +37,7 @@
#include <vlc_access.h>
#include <vlc_charset.h>
#include <vlc_interrupt.h>
+#include <vlc_url.h>
#include <libvlc.h>
#include "stream.h"
@@ -94,6 +95,20 @@ typedef struct stream_priv_t
static int EscapeFragment( char** out, char const* data );
/**
+ * \ingroup stream_fragments_internals
+ * \internal
+ *
+ * Function to url-encode the requested data \p level number of times.
+ *
+ * \param out on success, *out will refer to an allocated string with the
+ * result of the operation.
+ * \param data the data that is to be encoded.
+ * \param level the number of times it should be recursively url-encoded.
+ * \return VLS_SUCCESS on success, negative value on error
+ **/
+static int RecursiveEncode( char** out, char const* data, size_t level );
+
+/**
* Allocates a VLC stream object
*/
stream_t *vlc_stream_CommonNew(vlc_object_t *parent,
@@ -743,3 +758,20 @@ static int EscapeFragment( char** out, char const* data )
return VLC_SUCCESS;
}
+
+static int RecursiveEncode( char** out, char const* data, size_t level )
+{
+ char* encoded = strdup( data );
+
+ for( char* tmp; level && encoded; --level )
+ {
+ tmp = vlc_uri_encode( encoded );
+ free( encoded );
+ encoded = tmp;
+ }
+
+ if( likely( *out = encoded ) )
+ return VLC_SUCCESS;
+
+ return VLC_ENOMEM;
+}
--
2.9.2
More information about the vlc-devel
mailing list