[vlc-devel] [PATCH 05/21] input/stream: stream-fragments: add helper to prepare a fragment
Filip Roséen
filip at atch.se
Sun Jul 31 22:42:14 CEST 2016
Given the specification of stream-fragments, functionality must be
present to both escape and url-encode a fragment in order to properly
append it to an MRL.
This commit adds PrepareFragment, a helper-function that will do what
is previously described. See the associated documentation for more
information.
---
src/input/stream.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/src/input/stream.c b/src/input/stream.c
index f39afab..304dd33 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -109,6 +109,21 @@ static int EscapeFragment( char** out, char const* data );
static int RecursiveEncode( char** out, char const* data, size_t level );
/**
+ * \ingroup stream_fragments_internals
+ * \internal
+ *
+ * Function will prepare the passed payload so that it can be used within an MRL
+ * following the \ref stream_fragments specification.
+ *
+ * \param out on success, *out will refer to an allocated string with the result
+ * of the operation.
+ * \param payload the data to use
+ * \param level the zero-based index of the fragment
+ * \return VLC_SUCCESS on success, negative value on error
+ **/
+static int PrepareFragment( char** out, char const* payload, size_t level );
+
+/**
* Allocates a VLC stream object
*/
stream_t *vlc_stream_CommonNew(vlc_object_t *parent,
@@ -775,3 +790,36 @@ static int RecursiveEncode( char** out, char const* data, size_t level )
return VLC_ENOMEM;
}
+
+static int PrepareFragment( char** out, char const* payload, size_t level )
+{
+ char* hash = NULL;
+ char* data = NULL;
+ char* tmp;
+
+ if( EscapeFragment( &tmp, payload ) )
+ return VLC_EGENERIC;
+
+ if( RecursiveEncode( &hash, "#", level - 1 ) )
+ {
+ free( tmp );
+ return VLC_EGENERIC;
+ }
+
+ if( RecursiveEncode( &data, tmp, level ) )
+ {
+ free( hash );
+ free( tmp );
+ return VLC_EGENERIC;
+ }
+
+ free( tmp );
+
+ if( asprintf( out, "%s%s", hash, data ) == -1 )
+ return VLC_ENOMEM;
+
+ free( data );
+ free( hash );
+
+ return VLC_SUCCESS;
+}
--
2.9.2
More information about the vlc-devel
mailing list