]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
leaks in case of http connection failure
[vlc] / modules / access / http.c
index 4d78ac021ecf4fbd1a434e1d9e61326169379cfd..4b24ad3dcc9759c5e6f949443e1fbc5ca1d2050e 100644 (file)
@@ -37,7 +37,7 @@
 
 #include <vlc_access.h>
 
-#include <vlc_interface.h>
+#include <vlc_dialog.h>
 #include <vlc_meta.h>
 #include <vlc_network.h>
 #include <vlc_url.h>
@@ -103,19 +103,20 @@ vlc_module_begin ()
     set_subcategory( SUBCAT_INPUT_ACCESS )
 
     add_string( "http-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT,
-                false );
+                false )
     add_password( "http-proxy-pwd", NULL, NULL,
-                  PROXY_PASS_TEXT, PROXY_PASS_LONGTEXT, false );
+                  PROXY_PASS_TEXT, PROXY_PASS_LONGTEXT, false )
     add_integer( "http-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL,
-                 CACHING_TEXT, CACHING_LONGTEXT, true );
+                 CACHING_TEXT, CACHING_LONGTEXT, true )
     add_string( "http-user-agent", COPYRIGHT_MESSAGE , NULL, AGENT_TEXT,
-                AGENT_LONGTEXT, true );
+                AGENT_LONGTEXT, true )
     add_bool( "http-reconnect", 0, NULL, RECONNECT_TEXT,
-              RECONNECT_LONGTEXT, true );
+              RECONNECT_LONGTEXT, true )
     add_bool( "http-continuous", 0, NULL, CONTINUOUS_TEXT,
-              CONTINUOUS_LONGTEXT, true );
+              CONTINUOUS_LONGTEXT, true )
+        change_safe()
     add_bool( "http-forward-cookies", true, NULL, FORWARD_COOKIES_TEXT,
-              FORWARD_COOKIES_LONGTEXT, true );
+              FORWARD_COOKIES_LONGTEXT, true )
     add_obsolete_string("http-user")
     add_obsolete_string("http-pwd")
     add_shortcut( "http" )
@@ -433,9 +434,7 @@ connect:
 
     if( p_sys->i_code == 401 )
     {
-        char *psz_login = NULL, *psz_password = NULL;
-        char psz_msg[250];
-        int i_ret;
+        char *psz_login, *psz_password;
         /* FIXME ? */
         if( p_sys->url.psz_username && p_sys->url.psz_password &&
             p_sys->auth.psz_nonce && p_sys->auth.i_nonce == 0 )
@@ -443,21 +442,18 @@ connect:
             Disconnect( p_access );
             goto connect;
         }
-        snprintf( psz_msg, 250,
-            _("Please enter a valid login name and a password for realm %s."),
-            p_sys->auth.psz_realm );
         msg_Dbg( p_access, "authentication failed for realm %s",
-            p_sys->auth.psz_realm );
-        i_ret = intf_UserLoginPassword( p_access, _("HTTP authentication"),
-                                        psz_msg, &psz_login, &psz_password );
-        if( i_ret == DIALOG_OK_YES )
+                 p_sys->auth.psz_realm );
+        dialog_Login( p_access, &psz_login, &psz_password,
+                      _("HTTP authentication"),
+             _("Please enter a valid login name and a password for realm %s."),
+                      p_sys->auth.psz_realm );
+        if( psz_login != NULL && psz_password != NULL )
         {
             msg_Dbg( p_access, "retrying with user=%s, pwd=%s",
                         psz_login, psz_password );
-            if( psz_login ) p_sys->url.psz_username = strdup( psz_login );
-            if( psz_password ) p_sys->url.psz_password = strdup( psz_password );
-            free( psz_login );
-            free( psz_password );
+            p_sys->url.psz_username = psz_login;
+            p_sys->url.psz_password = psz_password;
             Disconnect( p_access );
             goto connect;
         }
@@ -587,6 +583,18 @@ error:
     free( p_sys->psz_user_agent );
 
     Disconnect( p_access );
+
+    if( p_sys->cookies )
+    {
+        int i;
+        for( i = 0; i < vlc_array_count( p_sys->cookies ); i++ )
+            free(vlc_array_item_at_index( p_sys->cookies, i ));
+        vlc_array_destroy( p_sys->cookies );
+    }
+
+#ifdef HAVE_ZLIB_H
+    inflateEnd( &p_sys->inflate.stream );
+#endif
     free( p_sys );
     return VLC_EGENERIC;
 }
@@ -913,10 +921,9 @@ static int Seek( access_t *p_access, int64_t i_pos )
 static int Control( access_t *p_access, int i_query, va_list args )
 {
     access_sys_t *p_sys = p_access->p_sys;
-    bool   *pb_bool;
-    int          *pi_int;
-    int64_t      *pi_64;
-    vlc_meta_t   *p_meta;
+    bool       *pb_bool;
+    int64_t    *pi_64;
+    vlc_meta_t *p_meta;
 
     switch( i_query )
     {
@@ -941,11 +948,6 @@ static int Control( access_t *p_access, int i_query, va_list args )
             break;
 
         /* */
-        case ACCESS_GET_MTU:
-            pi_int = (int*)va_arg( args, int * );
-            *pi_int = 0;
-            break;
-
         case ACCESS_GET_PTS_DELAY:
             pi_64 = (int64_t*)va_arg( args, int64_t * );
             *pi_64 = (int64_t)var_GetInteger( p_access, "http-caching" ) * 1000;
@@ -1029,6 +1031,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
         msg_Err( p_access, "cannot connect to %s:%d", srv.psz_host, srv.i_port );
         return -1;
     }
+    setsockopt (p_sys->fd, SOL_SOCKET, SO_KEEPALIVE, &(int){ 1 }, sizeof (int));
 
     /* Initialize TLS/SSL session */
     if( p_sys->b_ssl == true )
@@ -1710,7 +1713,7 @@ static void AuthParseHeader( access_t *p_access, const char *psz_header,
         const char *psz_end = strchr( psz_header, ' ' );
         if( psz_end )
             msg_Warn( p_access, "Unknown authentication scheme: '%*s'",
-                      psz_end - psz_header, psz_header );
+                      (int)(psz_end - psz_header), psz_header );
         else
             msg_Warn( p_access, "Unknown authentication scheme: '%s'",
                       psz_header );