]> git.sesse.net Git - vlc/blobdiff - modules/access_output/shout.c
Merge branch 'master' of git://git.videolan.org/vlc
[vlc] / modules / access_output / shout.c
index 1a8bad822b1ee9e74f82bde253adcfcee183d4be..00c1a405d24ea4bdec5c018ffb2d5cd473b7e805 100644 (file)
@@ -173,10 +173,10 @@ static int Open( vlc_object_t *p_this )
     char *psz_accessname;
     char *psz_parser;
     const char *psz_user;
-    const char *psz_pass;
-    const char *psz_host;
-    const char *psz_mount;
-    const char *psz_port;
+    char *psz_pass;
+    char *psz_host;
+    char *psz_mount;
+    char *psz_port;
     char *psz_name;
     char *psz_description;
     char *psz_genre;
@@ -196,21 +196,43 @@ static int Open( vlc_object_t *p_this )
         return VLC_ENOMEM;
 
     /* Parse connection data user:pwd@host:port/mountpoint */
-    psz_user = psz_parser;
-    while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
-    if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
-    psz_pass = psz_parser;
-    while( psz_parser[0] && psz_parser[0] != '@' ) psz_parser++;
-    if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
-    psz_host = psz_parser;
-    while( psz_parser[0] && psz_parser[0] != ':' ) psz_parser++;
-    if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
-    psz_port = psz_parser;
-    while( psz_parser[0] && psz_parser[0] != '/' ) psz_parser++;
-    if( psz_parser[0] ) { psz_parser[0] = 0; psz_parser++; }
-    psz_mount = psz_parser;
-
-    i_port = atoi( psz_port );
+    psz_host = strchr( psz_parser, '@' );
+    if( psz_host )
+    {
+        psz_user = psz_parser;
+        *(psz_host++) = '\0';
+    }
+    else
+        psz_user = "";
+
+    psz_pass = strchr( psz_user, ':' );
+    if( psz_pass )
+        *(psz_pass++) = '\0';
+    else
+        psz_pass = "";
+
+    psz_mount = strchr( psz_host, '/' );
+    if( psz_mount )
+        *(psz_mount++) = '\0';
+    else
+        psz_mount = "";
+
+    if( psz_host[0] == '[' )
+    {
+        psz_port = strstr( psz_host, "]:" );
+        if( psz_port )
+        {
+            *psz_port = '\0';
+            psz_port += 2;
+        }
+    }
+    else
+    {
+        psz_port = strchr( psz_host, ':' );
+        if( psz_port )
+            *(psz_port++) = '\0';
+    }
+    i_port = psz_port ? atoi( psz_port ) : 8000;
 
     p_sys = p_access->p_sys = malloc( sizeof( sout_access_out_sys_t ) );
     if( !p_sys )
@@ -264,9 +286,7 @@ static int Open( vlc_object_t *p_this )
     if( i_ret != SHOUTERR_SUCCESS )
     {
         msg_Err( p_access, "failed to set the shoutcast streaming format" );
-        free( p_access->p_sys );
-        free( psz_accessname );
-        return VLC_EGENERIC;
+        goto error;
     }
 
     /* Don't force bitrate to 0 but only use when specified. This will otherwise
@@ -275,13 +295,11 @@ static int Open( vlc_object_t *p_this )
     if( psz_val )
     {
         i_ret = shout_set_audio_info( p_shout, SHOUT_AI_BITRATE, psz_val );
+        free( psz_val );
         if( i_ret != SHOUTERR_SUCCESS )
         {
             msg_Err( p_access, "failed to set the information about the bitrate" );
-            free( psz_val );
-            free( p_access->p_sys );
-            free( psz_accessname );
-            return VLC_EGENERIC;
+            goto error;
         }
     }
     else
@@ -300,13 +318,11 @@ static int Open( vlc_object_t *p_this )
     if( psz_val )
     {
         i_ret = shout_set_audio_info( p_shout, SHOUT_AI_SAMPLERATE, psz_val );
+        free( psz_val );
         if( i_ret != SHOUTERR_SUCCESS )
         {
             msg_Err( p_access, "failed to set the information about the samplerate" );
-            free( psz_val );
-            free( p_access->p_sys );
-            free( psz_accessname );
-            return VLC_EGENERIC;
+            goto error;
         }
     }
 
@@ -314,13 +330,11 @@ static int Open( vlc_object_t *p_this )
     if( psz_val )
     {
         i_ret = shout_set_audio_info( p_shout, SHOUT_AI_CHANNELS, psz_val );
+        free( psz_val );
         if( i_ret != SHOUTERR_SUCCESS )
         {
             msg_Err( p_access, "failed to set the information about the number of channels" );
-            free( psz_val );
-            free( p_access->p_sys );
-            free( psz_accessname );
-            return VLC_EGENERIC;
+            goto error;
         }
     }
 
@@ -328,13 +342,11 @@ static int Open( vlc_object_t *p_this )
     if( psz_val )
     {
         i_ret = shout_set_audio_info( p_shout, SHOUT_AI_QUALITY, psz_val );
+        free( psz_val );
         if( i_ret != SHOUTERR_SUCCESS )
         {
             msg_Err( p_access, "failed to set the information about Ogg Vorbis quality" );
-            free( psz_val );
-            free( p_access->p_sys );
-            free( psz_accessname );
-            return VLC_EGENERIC;
+            goto error;
         }
     }
 
@@ -344,9 +356,7 @@ static int Open( vlc_object_t *p_this )
         if( i_ret != SHOUTERR_SUCCESS )
         {
             msg_Err( p_access, "failed to set the server status setting to public" );
-            free( p_access->p_sys );
-            free( psz_accessname );
-            return VLC_EGENERIC;
+            goto error;
         }
     }
 
@@ -367,9 +377,7 @@ static int Open( vlc_object_t *p_this )
         if( i_ret != SHOUTERR_SUCCESS )
         {
             msg_Err( p_access, "failed to set the protocol to 'icy'" );
-            free( p_access->p_sys );
-            free( psz_accessname );
-            return VLC_EGENERIC;
+            goto error;
         }
         i_ret = shout_open( p_shout );
         if( i_ret == SHOUTERR_SUCCESS )
@@ -393,9 +401,7 @@ static int Open( vlc_object_t *p_this )
             if( i_ret != SHOUTERR_SUCCESS )
             {
                 msg_Err( p_access, "failed to set the protocol to 'http'" );
-                free( p_access->p_sys );
-                free( psz_accessname );
-                return VLC_EGENERIC;
+                goto error;
             }
             i_ret = shout_open( p_shout );
             if( i_ret == SHOUTERR_SUCCESS )
@@ -439,6 +445,11 @@ static int Open( vlc_object_t *p_this )
     free( psz_accessname );
 
     return VLC_SUCCESS;
+
+error:
+    free( psz_accessname );
+    free( p_sys );
+    return VLC_EGENERIC;
 }
 
 /*****************************************************************************