]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
mmap: Only use MAP_NOCACHE on platforms that support it.
[vlc] / modules / access / http.c
index f66ffb95216b80be3488c0b1634448ed0ff21e49..ac0d6fc9db26f825eb52d1347374d0f00a955bea 100644 (file)
@@ -43,6 +43,7 @@
 #include <vlc_url.h>
 #include <vlc_tls.h>
 #include <vlc_strings.h>
+#include <vlc_charset.h>
 #include <vlc_input.h>
 #include <vlc_md5.h>
 
@@ -92,7 +93,7 @@ static void Close( vlc_object_t * );
     "types of HTTP streams." )
 
 #define FORWARD_COOKIES_TEXT N_("Forward Cookies")
-#define FORWARD_COOKIES_LONGTEXT N_("Forward Cookies Across http redirections ")
+#define FORWARD_COOKIES_LONGTEXT N_("Forward Cookies across http redirections ")
 
 vlc_module_begin();
     set_description( N_("HTTP input") );
@@ -113,7 +114,7 @@ vlc_module_begin();
               RECONNECT_LONGTEXT, true );
     add_bool( "http-continuous", 0, NULL, CONTINUOUS_TEXT,
               CONTINUOUS_LONGTEXT, true );
-    add_bool( "http-forward-cookies", 0, NULL, FORWARD_COOKIES_TEXT,
+    add_bool( "http-forward-cookies", true, NULL, FORWARD_COOKIES_TEXT,
               FORWARD_COOKIES_LONGTEXT, true );
     add_obsolete_string("http-user");
     add_obsolete_string("http-pwd");
@@ -184,6 +185,7 @@ struct access_sys_t
     int64_t    i_chunk;
 
     int        i_icy_meta;
+    int64_t    i_icy_offset;
     char       *psz_icy_name;
     char       *psz_icy_genre;
     char       *psz_icy_title;
@@ -276,6 +278,7 @@ static int OpenWithCookies( vlc_object_t *p_this, vlc_array_t *cookies )
     p_sys->p_tls = NULL;
     p_sys->p_vs = NULL;
     p_sys->i_icy_meta = 0;
+    p_sys->i_icy_offset = 0;
     p_sys->psz_icy_name = NULL;
     p_sys->psz_icy_genre = NULL;
     p_sys->psz_icy_title = NULL;
@@ -437,6 +440,7 @@ connect:
         if( p_sys->url.psz_username && p_sys->url.psz_password &&
             p_sys->auth.psz_nonce && p_sys->auth.i_nonce == 0 )
         {
+            Disconnect( p_access );
             goto connect;
         }
         snprintf( psz_msg, 250,
@@ -454,6 +458,7 @@ connect:
             if( psz_password ) p_sys->url.psz_password = strdup( psz_password );
             free( psz_login );
             free( psz_password );
+            Disconnect( p_access );
             goto connect;
         }
         else
@@ -637,7 +642,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
     access_sys_t *p_sys = p_access->p_sys;
     int i_read;
 
-    if( p_sys->fd < 0 )
+    if( p_sys->fd == -1 )
     {
         p_access->info.b_eof = true;
         return 0;
@@ -697,10 +702,10 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
     }
 
 
-    if( p_sys->i_icy_meta > 0 && p_access->info.i_pos > 0 )
+    if( p_sys->i_icy_meta > 0 && p_access->info.i_pos-p_sys->i_icy_offset > 0 )
     {
         int64_t i_next = p_sys->i_icy_meta -
-                                    p_access->info.i_pos % p_sys->i_icy_meta;
+                                    (p_access->info.i_pos - p_sys->i_icy_offset ) % p_sys->i_icy_meta;
 
         if( i_next == p_sys->i_icy_meta )
         {
@@ -826,7 +831,7 @@ static int ReadICYMeta( access_t *p_access )
             strcmp( p_sys->psz_icy_title, &p[1] ) )
         {
             free( p_sys->psz_icy_title );
-            p_sys->psz_icy_title = strdup( &p[1] );
+            p_sys->psz_icy_title = EnsureUTF8( strdup( &p[1] ));
             p_access->info.i_update |= INPUT_UPDATE_META;
 
             msg_Dbg( p_access, "New Title=%s", p_sys->psz_icy_title );
@@ -1005,6 +1010,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
     p_sys->b_chunked = false;
     p_sys->i_chunk = 0;
     p_sys->i_icy_meta = 0;
+    p_sys->i_icy_offset = i_tell;
     p_sys->psz_icy_name = NULL;
     p_sys->psz_icy_genre = NULL;
     p_sys->psz_icy_title = NULL;
@@ -1015,8 +1021,8 @@ static int Connect( access_t *p_access, int64_t i_tell )
     p_access->info.i_pos  = i_tell;
     p_access->info.b_eof  = false;
 
-
     /* Open connection */
+    assert( p_sys->fd == -1 ); /* No open sockets (leaking fds is BAD) */
     p_sys->fd = net_ConnectTCP( p_access, srv.psz_host, srv.i_port );
     if( p_sys->fd == -1 )
     {
@@ -1109,7 +1115,6 @@ static int Request( access_t *p_access, int64_t i_tell )
     access_sys_t   *p_sys = p_access->p_sys;
     char           *psz ;
     v_socket_t     *pvs = p_sys->p_vs;
-    bool b_connection_close = false;
     p_sys->b_persist = false;
 
     p_sys->i_remaining = 0;
@@ -1411,7 +1416,7 @@ static int Request( access_t *p_access, int64_t i_tell )
         else if( !strcasecmp( psz, "Icy-Name" ) )
         {
             free( p_sys->psz_icy_name );
-            p_sys->psz_icy_name = strdup( p );
+            p_sys->psz_icy_name = EnsureUTF8( strdup( p ));
             msg_Dbg( p_access, "Icy-Name: %s", p_sys->psz_icy_name );
 
             p_sys->b_icecast = true; /* be on the safeside. set it here as well. */
@@ -1421,7 +1426,7 @@ static int Request( access_t *p_access, int64_t i_tell )
         else if( !strcasecmp( psz, "Icy-Genre" ) )
         {
             free( p_sys->psz_icy_genre );
-            p_sys->psz_icy_genre = strdup( p );
+            p_sys->psz_icy_genre = EnsureUTF8( strdup( p ));
             msg_Dbg( p_access, "Icy-Genre: %s", p_sys->psz_icy_genre );
         }
         else if( !strncasecmp( psz, "Icy-Notice", 10 ) )