]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
avcodec: fix end-of-stream handling (fixes #8792) and factor code
[vlc] / modules / access / http.c
index fb5319f410ca8fa0793f28468b5ba5123f76cb6a..583cf4a1258448a9a207a314c9a7ad0c3701b7cc 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * http.c: HTTP input module
  *****************************************************************************
- * Copyright (C) 2001-2008 the VideoLAN team
+ * Copyright (C) 2001-2008 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
@@ -9,19 +9,19 @@
  *          RĂ©mi Denis-Courmont <rem # videolan.org>
  *          Antoine Cellerier <dionoea at videolan dot org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /*****************************************************************************
 #include <assert.h>
 #include <limits.h>
 
-#ifdef HAVE_LIBPROXY
-#    include <proxy.h>
-#endif
-
-#ifdef WIN32
-#   include <windows.h>
-#endif
-
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
@@ -367,117 +359,33 @@ static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
 
     /* Check proxy */
     psz = var_InheritString( p_access, "http-proxy" );
-    if( psz )
-    {
-        p_sys->b_proxy = true;
-        vlc_UrlParse( &p_sys->proxy, psz, 0 );
-        free( psz );
-    }
-#ifdef HAVE_LIBPROXY
-    else
+    if( psz == NULL )
     {
-        pxProxyFactory *pf = px_proxy_factory_new();
-        if (pf)
-        {
-            char *buf;
-            int i;
-            i=asprintf(&buf, "%s://%s", psz_access, p_access->psz_location);
-            if (i >= 0)
-            {
-                msg_Dbg(p_access, "asking libproxy about url '%s'", buf);
-                char **proxies = px_proxy_factory_get_proxies(pf, buf);
-                if (proxies[0])
-                {
-                    msg_Dbg(p_access, "libproxy suggest to use '%s'", proxies[0]);
-                    if(strcmp(proxies[0],"direct://") != 0)
-                    {
-                        p_sys->b_proxy = true;
-                        vlc_UrlParse( &p_sys->proxy, proxies[0], 0);
-                    }
-                }
-                for(i=0;proxies[i];i++) free(proxies[i]);
-                free(proxies);
-                free(buf);
-            }
-            px_proxy_factory_free(pf);
-        }
-        else
+        char *url;
+
+        if (likely(asprintf(&url, "%s://%s", psz_access,
+                            p_access->psz_location) != -1))
         {
-            msg_Err(p_access, "Allocating memory for libproxy failed");
+            msg_Dbg(p_access, "querying proxy for %s", url);
+            psz = vlc_getProxyUrl(url);
+            free(url);
         }
-    }
-#elif (0) // defined( WIN32 ) The parsing is not complete enough
-    else
-    {
-        /* Try to get the proxy server address from Windows internet settings using registry. */
-        HKEY h_key;
-        /* Open the key */
-        if( RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft"
-                          "\\Windows\\CurrentVersion\\Internet Settings",
-                          0, KEY_READ, &h_key ) == ERROR_SUCCESS )
-        {
-            DWORD len = sizeof( DWORD );
-            BYTE proxyEnable;
 
-            /* Get the proxy enable value */
-            if( RegQueryValueEx( h_key, "ProxyEnable", NULL, NULL,
-                                 &proxyEnable, &len ) == ERROR_SUCCESS
-             && proxyEnable )
-            {
-                /* Proxy is enabled */
-                /* Get the proxy URL :
-                   Proxy server value in the registry can be something like "address:port"
-                   or "ftp=address1:port1;http=address2:port2 ..." depending of the
-                   confirguration. */
-                unsigned char key[256];
-
-                len = sizeof( key );
-                if( RegQueryValueEx( h_key, "ProxyServer", NULL, NULL,
-                                     key, &len ) == ERROR_SUCCESS )
-                {
-                    /* FIXME: This is lame. The string should be tokenized. */
-#warning FIXME.
-                    char *psz_proxy = strstr( (char *)key, "http=" );
-                    if( psz_proxy != NULL )
-                    {
-                        psz_proxy += 5;
-                        char *end = strchr( psz_proxy, ';' );
-                        if( end != NULL )
-                            *end = '\0';
-                    }
-                    else
-                        psz_proxy = (char *)key;
-                    /* Set proxy enable for this connection. */
-                    p_sys->b_proxy = true;
-                    vlc_UrlParse( &p_sys->proxy, psz_proxy, 0 );
-                }
-            }
-            else
-                msg_Dbg( p_access, "HTTP proxy disabled (MSIE)" );
-            RegCloseKey( h_key );
-        }
+        if (psz != NULL)
+            msg_Dbg(p_access, "proxy: %s", psz);
+        else
+            msg_Dbg(p_access, "no proxy");
     }
-#else
-    else
+    if( psz != NULL )
     {
-        psz = getenv( "http_proxy" );
-        if( psz )
-        {
-            p_sys->b_proxy = true;
-            vlc_UrlParse( &p_sys->proxy, psz, 0 );
-        }
-    }
-#endif
+        p_sys->b_proxy = true;
+        vlc_UrlParse( &p_sys->proxy, psz, 0 );
+        free( psz );
 
-    if( psz ) /* No, this is NOT a use-after-free error */
-    {
         psz = var_InheritString( p_access, "http-proxy-pwd" );
         if( psz )
             p_sys->proxy.psz_password = p_sys->psz_proxy_passbuf = psz;
-    }
 
-    if( p_sys->b_proxy )
-    {
         if( p_sys->proxy.psz_host == NULL || *p_sys->proxy.psz_host == '\0' )
         {
             msg_Warn( p_access, "invalid proxy host" );
@@ -530,6 +438,11 @@ connect:
 
     if( p_sys->i_code == 401 )
     {
+        if( p_sys->auth.psz_realm == NULL )
+        {
+            msg_Err( p_access, "authentication failed without realm" );
+            goto error;
+        }
         char *psz_login, *psz_password;
         /* FIXME ? */
         if( p_sys->url.psz_username && p_sys->url.psz_password &&
@@ -999,7 +912,8 @@ static ssize_t ReadCompressed( access_t *p_access, uint8_t *p_buffer,
         p_sys->inflate.stream.next_out = p_buffer;
 
         i_ret = inflate( &p_sys->inflate.stream, Z_SYNC_FLUSH );
-        msg_Warn( p_access, "inflate return value: %d, %s", i_ret, p_sys->inflate.stream.msg );
+        if ( i_ret != Z_OK && i_ret != Z_STREAM_END )
+            msg_Warn( p_access, "inflate return value: %d, %s", i_ret, p_sys->inflate.stream.msg );
 
         return i_len - p_sys->inflate.stream.avail_out;
     }
@@ -1273,9 +1187,6 @@ static int Request( access_t *p_access, uint64_t i_tell )
         net_Printf( p_access, p_sys->fd, pvs, "Referer: %s\r\n",
                     p_sys->psz_referrer);
     }
-#ifdef HAVE_ZLIB_H
-    net_Printf( p_access, p_sys->fd, pvs, "Accept-Encoding: gzip, deflate\r\n" );
-#endif
     /* Offset */
     if( p_sys->i_version == 1 && ! p_sys->b_continuous )
     {