]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
rtmp: fixed description formatting and made default values more logical.
[vlc] / modules / access / http.c
index 79677814b866618d0363773ee38d64bd9e6b7a9c..fdcee422c41aaa4b5c3be971ad906af5d91efeb4 100644 (file)
@@ -95,6 +95,9 @@ static void Close( vlc_object_t * );
 #define FORWARD_COOKIES_TEXT N_("Forward Cookies")
 #define FORWARD_COOKIES_LONGTEXT N_("Forward Cookies across http redirections.")
 
+#define MAX_REDIRECT_TEXT N_("Max number of redirection")
+#define MAX_REDIRECT_LONGTEXT N_("Limit the number of redirection to follow.")
+
 vlc_module_begin ()
     set_description( N_("HTTP input") )
     set_capability( "access", 0 )
@@ -118,6 +121,8 @@ vlc_module_begin ()
         change_safe()
     add_bool( "http-forward-cookies", true, NULL, FORWARD_COOKIES_TEXT,
               FORWARD_COOKIES_LONGTEXT, true )
+    add_integer( "http-max-redirect", 5, NULL, MAX_REDIRECT_TEXT,
+                 MAX_REDIRECT_LONGTEXT, true )
     add_obsolete_string("http-user")
     add_obsolete_string("http-pwd")
     add_shortcut( "http" )
@@ -206,6 +211,7 @@ struct access_sys_t
 
 /* */
 static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
+                            int i_nb_redirect, int i_max_redirect,
                             vlc_array_t *cookies );
 
 /* */
@@ -240,7 +246,8 @@ static void AuthReset( http_auth_t *p_auth );
 static int Open( vlc_object_t *p_this )
 {
     access_t *p_access = (access_t*)p_this;
-    return OpenWithCookies( p_this, p_access->psz_access, NULL );
+    return OpenWithCookies( p_this, p_access->psz_access, 0,
+                var_CreateGetInteger( p_access, "http-max-redirect" ), NULL );
 }
 
 /**
@@ -248,15 +255,19 @@ static int Open( vlc_object_t *p_this )
  * @param p_this: the vlc object
  * @psz_access: the acces to use (http, https, ...) (this value must be used
  *              instead of p_access->psz_access)
+ * @i_nb_redirect: the number of redirection already done
+ * @i_max_redirect: limit to the number of redirection to follow
  * @cookies: the available cookies
  * @return vlc error codes
  */
 static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
+                            int i_nb_redirect, int i_max_redirect,
                             vlc_array_t *cookies )
 {
     access_t     *p_access = (access_t*)p_this;
     access_sys_t *p_sys;
     char         *psz, *p;
+
     /* Only forward an store cookies if the corresponding option is activated */
     bool   b_forward_cookies = var_CreateGetBool( p_access, "http-forward-cookies" );
     vlc_array_t * saved_cookies = b_forward_cookies ? (cookies ? cookies : vlc_array_new()) : NULL;
@@ -483,6 +494,15 @@ connect:
     {
         msg_Dbg( p_access, "redirection to %s", p_sys->psz_location );
 
+        /* Check the number of redirection already done */
+        if( i_nb_redirect >= i_max_redirect )
+        {
+            msg_Err( p_access, "Too many redirection: break potential infinite"
+                     "loop" );
+            goto error;
+        }
+
+
         /* Do not accept redirection outside of HTTP works */
         const char *psz_protocol;
         if( !strncmp( p_sys->psz_location, "http:", 5 ) )
@@ -515,7 +535,8 @@ connect:
         free( p_sys );
 
         /* Do new Open() run with new data */
-        return OpenWithCookies( p_this, psz_protocol, cookies );
+        return OpenWithCookies( p_this, psz_protocol, i_nb_redirect + 1,
+                                i_max_redirect, cookies );
     }
 
     if( p_sys->b_mms )
@@ -694,7 +715,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
 
         if( p_sys->i_chunk <= 0 )
         {
-            char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, p_sys->p_vs );
+            char *psz = net_Gets( p_access, p_sys->fd, p_sys->p_vs );
             /* read the chunk header */
             if( psz == NULL )
             {
@@ -757,7 +778,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
             if( p_sys->i_chunk <= 0 )
             {
                 /* read the empty line */
-                char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, p_sys->p_vs );
+                char *psz = net_Gets( p_access, p_sys->fd, p_sys->p_vs );
                 free( psz );
             }
         }
@@ -1082,7 +1103,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
                         p_sys->i_version,
                         p_sys->url.psz_host, p_sys->url.i_port);
 
-            psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
+            psz = net_Gets( p_access, p_sys->fd, NULL );
             if( psz == NULL )
             {
                 msg_Err( p_access, "cannot establish HTTP/TLS tunnel" );
@@ -1102,7 +1123,7 @@ static int Connect( access_t *p_access, int64_t i_tell )
 
             do
             {
-                psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, NULL );
+                psz = net_Gets( p_access, p_sys->fd, NULL );
                 if( psz == NULL )
                 {
                     msg_Err( p_access, "HTTP proxy connection failed" );
@@ -1243,7 +1264,7 @@ static int Request( access_t *p_access, int64_t i_tell )
     }
 
     /* Read Answer */
-    if( ( psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, pvs ) ) == NULL )
+    if( ( psz = net_Gets( p_access, p_sys->fd, pvs ) ) == NULL )
     {
         msg_Err( p_access, "failed to read answer" );
         goto error;
@@ -1291,7 +1312,7 @@ static int Request( access_t *p_access, int64_t i_tell )
 
     for( ;; )
     {
-        char *psz = net_Gets( VLC_OBJECT(p_access), p_sys->fd, pvs );
+        char *psz = net_Gets( p_access, p_sys->fd, pvs );
         char *p;
 
         if( psz == NULL )