<div dir="ltr">Thanks, Remi. Is there another better way of getting a user-configured passphrase to the srt module ?<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Mar 6, 2019 at 5:57 AM Rémi Denis-Courmont <<a href="mailto:remi@remlab.net">remi@remlab.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi,<br><br>Passing passwords in URLs is well-documented as a terrible idea. In VLC's case, the passphrase will show up in the OSD title, window title, logs, etc...<br><br><div class="gmail_quote">Le 5 mars 2019 23:42:14 GMT+02:00, Aaron Boxer <<a href="mailto:boxerab@gmail.com" target="_blank">boxerab@gmail.com</a>> a écrit :<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr"><div>Parse pass phrase and latency from url for incoming srt stream<br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">diff --git a/modules/access/srt.c b/modules/access/srt.c<br>index d8d8cbe659..55c0efc201 100644<br>--- a/modules/access/srt.c<br>+++ b/modules/access/srt.c<br>@@ -37,6 +37,9 @@<br> <br> #include <srt/srt.h><br> <br>+const char* SRT_PARAM_PASSPHRASE = "passphrase";<br>+const char* SRT_PARAM_LATENCY = "latency";<br>+<br> /* libsrt defines default packet size as 1316 internally<br> * so srt module takes same value. */<br> #define SRT_DEFAULT_CHUNK_SIZE 1316<br>@@ -70,6 +73,85 @@ typedef struct<br> int i_chunks; /* Number of chunks to allocate in the next read */<br> } stream_sys_t;<br> <br>+<br>+<br>+struct parsed_param {<br>+ char *key;<br>+ char *val;<br>+};<br>+<br>+static inline char *<br>+find(char *str, char find)<br>+{<br>+ str = strchr(str, find);<br>+ if (NULL == str) {<br>+ return NULL;<br>+ }<br>+ return str + 1;<br>+}<br>+<br>+static inline char *<br>+find_query(char *str)<br>+{<br>+ return find(str, '?');<br>+}<br>+<br>+/**<br>+ * Parse a query string into an array of key/value structs.<br>+ *<br>+ * The query string should be a null terminated string of parameters separated by<br>+ * a delimiter. Each parameter are checked for the equal sign character. If it<br>+ * appears in the parameter, it will be used as a null terminator and the part<br>+ * that comes after it will be the value of the parameter.<br>+ *<br>+ *<br>+ * param: query: the query string to parse. The string will be modified.<br>+ * param: delimiter: the character that separates the key/value pairs from each other.<br>+ * param: params: an array of parsed_param structs to hold the result.<br>+ * param: max_params: maximum number of parameters to parse.<br>+ *<br>+ * Return: the number of parsed items. -1 if there was an error.<br>+ */<br>+static int<br>+srt_url_parse_query(char *query, char delimiter, struct parsed_param *params, int max_params)<br>+{<br>+ int i = 0;<br>+<br>+ if (!query || *query == '\0')<br>+ {<br>+ return -1;<br>+ }<br>+ if (!params || max_params == 0)<br>+ {<br>+ return 0;<br>+ }<br>+<br>+ params[i++].key = query;<br>+ while (i < max_params && NULL != (query = strchr(query, delimiter)))<br>+ {<br>+ *query = '\0';<br>+ params[i].key = ++query;<br>+ params[i].val = NULL;<br>+<br>+ /* Go back and split previous param if one exists */<br>+ if (i > 0)<br>+ {<br>+ if ((params[i - 1].val = strchr(params[i - 1].key, '=')) != NULL)<br>+ {<br>+ *(params[i - 1].val)++ = '\0';<br>+ }<br>+ }<br>+ i++;<br>+ }<br>+ /* Go back and split last param */<br>+ if ((params[i - 1].val = strchr(params[i - 1].key, '=')) != NULL)<br>+ {<br>+ *(params[i - 1].val)++ = '\0';<br>+ }<br>+ return i;<br>+}<br>+<br>+<br> static void srt_wait_interrupted(void *p_data)<br> {<br> stream_t *p_stream = p_data;<br>@@ -115,9 +197,11 @@ static int Control(stream_t *p_stream, int i_query, va_list args)<br> <br> static bool srt_schedule_reconnect(stream_t *p_stream)<br> {<br>- int i_latency;<br>+ int i_latency=-1;<br> int stat;<br> char *psz_passphrase = NULL;<br>+ bool parsed_passphrase = false;<br>+ char *url = NULL;<br> <br> struct addrinfo hints = {<br> .ai_socktype = SOCK_DGRAM,<br>@@ -153,6 +237,38 @@ static bool srt_schedule_reconnect(stream_t *p_stream)<br> goto out;<br> }<br> <br>+ /* Parse URL parameters */<br>+ if (p_stream->psz_url && strlen(p_stream->psz_url) < 512)<br>+ {<br>+ char* query = NULL;<br>+ struct parsed_param params[32];<br>+ int num_params = 0;<br>+ int i=0;<br>+ size_t url_size = strlen(p_stream->psz_url)+1;<br>+<br>+ url = malloc(url_size);<br>+ url[url_size-1] = 0;<br>+ strcpy(url, p_stream->psz_url);<br>+ query = find_query(url);<br>+ if (query)<br>+ {<br>+ num_params = srt_url_parse_query(query,'&', params, sizeof(params)/sizeof(struct parsed_param) );<br>+ if (num_params > 0) {<br>+ for (i = 0; i < num_params; ++i)<br>+ {<br>+ if (strcmp(params[i].key, SRT_PARAM_PASSPHRASE) == 0)<br>+ {<br>+ psz_passphrase = params[i].val;<br>+ parsed_passphrase = true;<br>+ }<br>+ else if (strcmp(params[i].key, SRT_PARAM_LATENCY) == 0)<br>+ i_latency = atoi(params[i].val);<br>+ }<br>+ }<br>+ }<br>+ }<br>+<br>+<br> /* Make SRT non-blocking */<br> srt_setsockopt( p_sys->sock, 0, SRTO_SNDSYN,<br> &(bool) { false }, sizeof( bool ) );<br>@@ -168,11 +284,13 @@ static bool srt_schedule_reconnect(stream_t *p_stream)<br> &(int) { 0 }, sizeof( int ) );<br> <br> /* Set latency */<br>- i_latency = var_InheritInteger( p_stream, "latency" );<br>+ if (i_latency == -1)<br>+ i_latency = var_InheritInteger( p_stream, SRT_PARAM_LATENCY );<br> srt_setsockopt( p_sys->sock, 0, SRTO_TSBPDDELAY,<br> &i_latency, sizeof( int ) );<br> <br>- psz_passphrase = var_InheritString( p_stream, "passphrase" );<br>+ if (!psz_passphrase)<br>+ psz_passphrase = var_InheritString( p_stream, SRT_PARAM_PASSPHRASE );<br> if ( psz_passphrase != NULL && psz_passphrase[0] != '\0')<br> {<br> int i_key_length = var_InheritInteger( p_stream, "key-length" );<br>@@ -211,7 +329,11 @@ out:<br> }<br> <br> freeaddrinfo( res );<br>- free( psz_passphrase );<br>+ if (!parsed_passphrase)<br>+ {<br>+ free( psz_passphrase );<br>+ }<br>+ free(url);<br> <br> return !failed;<br> }<br>@@ -422,8 +544,8 @@ vlc_module_begin ()<br> N_("SRT chunk size (bytes)"), NULL, true )<br> add_integer( "poll-timeout", SRT_DEFAULT_POLL_TIMEOUT,<br> N_("Return poll wait after timeout milliseconds (-1 = infinite)"), NULL, true )<br>- add_integer( "latency", SRT_DEFAULT_LATENCY, N_("SRT latency (ms)"), NULL, true )<br>- add_password("passphrase", "", N_("Password for stream encryption"), NULL)<br>+ add_integer( SRT_PARAM_LATENCY, SRT_DEFAULT_LATENCY, N_("SRT latency (ms)"), NULL, true )<br>+ add_password(SRT_PARAM_PASSPHRASE, "", N_("Password for stream encryption"), NULL)<br> add_integer( "key-length", SRT_DEFAULT_KEY_LENGTH,<br> SRT_KEY_LENGTH_TEXT, SRT_KEY_LENGTH_TEXT, false )<br> change_integer_list( srt_key_lengths, srt_key_length_names )<br><br></div></div>
</blockquote></div><br>-- <br>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</div></blockquote></div>