[vlc-devel] [PATCH 3/4] access/udp.c: use vlc_UrlParse()
Jean-Paul Saman
jpsaman at videolan.org
Thu Oct 27 15:42:26 CEST 2016
---
modules/access/udp.c | 59 +++++++++++-----------------------------------------
1 file changed, 12 insertions(+), 47 deletions(-)
diff --git a/modules/access/udp.c b/modules/access/udp.c
index ced4f8e..c156ae7 100644
--- a/modules/access/udp.c
+++ b/modules/access/udp.c
@@ -42,6 +42,7 @@
#include <vlc_access.h>
#include <vlc_network.h>
#include <vlc_block.h>
+#include <vlc_url.h>
#include <vlc_interrupt.h>
#ifdef HAVE_POLL
# include <poll.h>
@@ -106,59 +107,23 @@ static int Open( vlc_object_t *p_this )
/* Set up p_access */
ACCESS_SET_CALLBACKS( NULL, BlockUDP, Control, NULL );
- char *psz_name = strdup( p_access->psz_location );
- char *psz_parser;
- const char *psz_server_addr, *psz_bind_addr = "";
- int i_bind_port = 1234, i_server_port = 0;
-
- if( unlikely(psz_name == NULL) )
- goto error;
-
- /* Parse psz_name syntax :
+ /* Parse p_access->psz_location syntax :
* [serveraddr[:serverport]][@[bindaddr]:[bindport]] */
- psz_parser = strchr( psz_name, '@' );
- if( psz_parser != NULL )
- {
- /* Found bind address and/or bind port */
- *psz_parser++ = '\0';
- psz_bind_addr = psz_parser;
-
- if( psz_bind_addr[0] == '[' )
- /* skips bracket'd IPv6 address */
- psz_parser = strchr( psz_parser, ']' );
-
- if( psz_parser != NULL )
- {
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser != NULL )
- {
- *psz_parser++ = '\0';
- i_bind_port = atoi( psz_parser );
- }
- }
- }
+ vlc_url_t url;
+ int res = vlc_UrlParse(&url, p_access->psz_location);
+ if( unlikely(res < 0) )
+ goto error;
- psz_server_addr = psz_name;
- psz_parser = ( psz_server_addr[0] == '[' )
- ? strchr( psz_name, ']' ) /* skips bracket'd IPv6 address */
- : psz_name;
-
- if( psz_parser != NULL )
- {
- psz_parser = strchr( psz_parser, ':' );
- if( psz_parser != NULL )
- {
- *psz_parser++ = '\0';
- i_server_port = atoi( psz_parser );
- }
- }
+ int i_bind_port = url.i_bind_port > 0 ? url.i_bind_port : 1234;
+ const char *psz_bind_addr = url.psz_bind_host ? url.psz_bind_host : "";
msg_Dbg( p_access, "opening server=%s:%d local=%s:%d",
- psz_server_addr, i_server_port, psz_bind_addr, i_bind_port );
+ url.psz_host, url.i_port, psz_bind_addr, i_bind_port );
sys->fd = net_OpenDgram( p_access, psz_bind_addr, i_bind_port,
- psz_server_addr, i_server_port, IPPROTO_UDP );
- free( psz_name );
+ url.psz_host, url.i_port, IPPROTO_UDP );
+ vlc_UrlClean(&url);
+
if( sys->fd == -1 )
{
msg_Err( p_access, "cannot open socket" );
--
2.7.4
More information about the vlc-devel
mailing list