[vlc-devel] [PATCH 03/21] input/stream: stream-fragments: add helper to escape a fragment
Filip Roséen
filip at atch.se
Sun Jul 31 22:42:12 CEST 2016
Given the specification of stream-fragments, we will need to be able
to properly escape fragment data in order to implement the relevant
functionality.
This commit adds a helper function named EscapeFragment; the
associated documentation should provide deeper insight.
---
src/input/stream.c | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/src/input/stream.c b/src/input/stream.c
index a16c675..0510adf 100644
--- a/src/input/stream.c
+++ b/src/input/stream.c
@@ -80,6 +80,20 @@ typedef struct stream_priv_t
} stream_priv_t;
/**
+ * \ingroup stream_fragments_internals
+ * \internal
+ *
+ * The function will escape the passed data so that it does not conflict
+ * with the \ref stream_fragments specification.
+ *
+ * \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 escaped.
+ * \return VLC_SUCCESS on success, negative value on error
+ **/
+static int EscapeFragment( char** out, char const* data );
+
+/**
* Allocates a VLC stream object
*/
stream_t *vlc_stream_CommonNew(vlc_object_t *parent,
@@ -706,3 +720,26 @@ int vlc_stream_ReadDir( stream_t *s, input_item_node_t *p_node )
{
return s->pf_readdir( s, p_node );
}
+
+static int EscapeFragment( char** out, char const* data )
+{
+ size_t out_len = 0;
+
+ for( char const* src = data; *src; ++src )
+ out_len += ( *src == '#' ? 2 : 1 );
+
+ *out = malloc( out_len + 1 );
+
+ if( unlikely( !*out ) )
+ return VLC_ENOMEM;
+
+ (*out)[ out_len ] = '\0';
+
+ for( char* dst = *out; *data; )
+ {
+ if( ( *dst++ = *data++ ) == '#' )
+ *dst++ = '#';
+ }
+
+ return VLC_SUCCESS;
+}
--
2.9.2
More information about the vlc-devel
mailing list