]> git.sesse.net Git - vlc/blobdiff - modules/access/http.c
Separate string list and string list callback
[vlc] / modules / access / http.c
index d8e56a42637a184ad436126370aeb830f5289d1f..531b7f86cc2903da08f2f0085dd38e2fe04ab37f 100644 (file)
@@ -97,7 +97,10 @@ static void Close( vlc_object_t * );
 #define REFERER_LONGTEXT N_("Customize the HTTP referer, simulating a previous document")
 
 #define UA_TEXT N_("User Agent")
-#define UA_LONGTEXT N_("You can use a custom User agent or use a known one")
+#define UA_LONGTEXT N_("The name and version of the program will be " \
+    "provided to the HTTP server. They must be separated by a forward " \
+    "slash, e.g. FooBar/1.2.3. This option can only be specified per input " \
+    "item, not globally.")
 
 vlc_module_begin ()
     set_description( N_("HTTP input") )
@@ -110,6 +113,7 @@ vlc_module_begin ()
                 false )
     add_password( "http-proxy-pwd", NULL,
                   PROXY_PASS_TEXT, PROXY_PASS_LONGTEXT, false )
+    add_obsolete_bool( "http-use-IE-proxy" )
     add_string( "http-referrer", NULL, REFERER_TEXT, REFERER_LONGTEXT, false )
         change_safe()
     add_string( "http-user-agent", NULL, UA_TEXT, UA_LONGTEXT, false )
@@ -401,7 +405,7 @@ static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
             msg_Err(p_access, "Allocating memory for libproxy failed");
         }
     }
-#elif defined( WIN32 )
+#elif (0) // defined( WIN32 ) The parsing is not complete enough
     else
     {
         /* Try to get the proxy server address from Windows internet settings using registry. */
@@ -449,6 +453,7 @@ static int OpenWithCookies( vlc_object_t *p_this, const char *psz_access,
             }
             else
                 msg_Dbg( p_access, "HTTP proxy disabled (MSIE)" );
+            RegCloseKey( h_key );
         }
     }
 #else
@@ -745,35 +750,15 @@ static void Close( vlc_object_t *p_this )
     free( p_sys );
 }
 
-/*****************************************************************************
- * Read: Read up to i_len bytes from the http connection and place in
- * p_buffer. Return the actual number of bytes read
- *****************************************************************************/
-static int ReadICYMeta( access_t *p_access );
-static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
+/* Read data from the socket taking care of chunked transfer if needed */
+static int ReadData( access_t *p_access, int *pi_read,
+                     uint8_t *p_buffer, size_t i_len )
 {
     access_sys_t *p_sys = p_access->p_sys;
-    int i_read;
-
-    if( p_sys->fd == -1 )
-        goto fatal;
-
-    if( p_sys->b_has_size )
-    {
-        /* Remaining bytes in the file */
-        uint64_t remainder = p_access->info.i_size - p_access->info.i_pos;
-        if( remainder < i_len )
-            i_len = remainder;
-
-        /* Remaining bytes in the response */
-        if( p_sys->i_remaining < i_len )
-            i_len = p_sys->i_remaining;
-    }
-
     if( p_sys->b_chunked )
     {
         if( p_sys->i_chunk < 0 )
-            goto fatal;
+            return VLC_EGENERIC;
 
         if( p_sys->i_chunk <= 0 )
         {
@@ -783,7 +768,7 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
             {
                 /* fatal error - end of file */
                 msg_Dbg( p_access, "failed reading chunk-header line" );
-                goto fatal;
+                return VLC_EGENERIC;
             }
             p_sys->i_chunk = strtoll( psz, NULL, 16 );
             free( psz );
@@ -791,18 +776,58 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
             if( p_sys->i_chunk <= 0 )   /* eof */
             {
                 p_sys->i_chunk = -1;
-                goto fatal;
+                return VLC_EGENERIC;
             }
         }
 
         if( i_len > p_sys->i_chunk )
             i_len = p_sys->i_chunk;
     }
+    *pi_read = net_Read( p_access, p_sys->fd, p_sys->p_vs, p_buffer, i_len, false );
+    if( *pi_read <= 0 )
+        return VLC_SUCCESS;
+
+    if( p_sys->b_chunked )
+    {
+        p_sys->i_chunk -= *pi_read;
+        if( p_sys->i_chunk <= 0 )
+        {
+            /* read the empty line */
+            char *psz = net_Gets( p_access, p_sys->fd, p_sys->p_vs );
+            free( psz );
+        }
+    }
+    return VLC_SUCCESS;
+}
+
+/*****************************************************************************
+ * Read: Read up to i_len bytes from the http connection and place in
+ * p_buffer. Return the actual number of bytes read
+ *****************************************************************************/
+static int ReadICYMeta( access_t *p_access );
+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 == -1 )
+        goto fatal;
+
+    if( p_sys->b_has_size )
+    {
+        /* Remaining bytes in the file */
+        uint64_t remainder = p_access->info.i_size - p_access->info.i_pos;
+        if( remainder < i_len )
+            i_len = remainder;
 
+        /* Remaining bytes in the response */
+        if( p_sys->i_remaining < i_len )
+            i_len = p_sys->i_remaining;
+    }
     if( i_len == 0 )
         goto fatal;
 
-    if( p_sys->i_icy_meta > 0 && p_access->info.i_pos-p_sys->i_icy_offset > 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_offset ) % p_sys->i_icy_meta;
@@ -816,22 +841,10 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
             i_len = i_next;
     }
 
-    i_read = net_Read( p_access, p_sys->fd, p_sys->p_vs, p_buffer, i_len, false );
+    if( ReadData( p_access, &i_read, p_buffer, i_len ) )
+        goto fatal;
 
-    if( i_read > 0 )
-    {
-        if( p_sys->b_chunked )
-        {
-            p_sys->i_chunk -= i_read;
-            if( p_sys->i_chunk <= 0 )
-            {
-                /* read the empty line */
-                char *psz = net_Gets( p_access, p_sys->fd, p_sys->p_vs );
-                free( psz );
-            }
-        }
-    }
-    else
+    if( i_read <= 0 )
     {
         /*
          * I very much doubt that this will work.
@@ -897,24 +910,24 @@ static int ReadICYMeta( access_t *p_access )
     int i_read;
 
     /* Read meta data length */
-    i_read = net_Read( p_access, p_sys->fd, p_sys->p_vs, &buffer, 1,
-                       true );
-    if( i_read <= 0 )
+    if( ReadData( p_access, &i_read, &buffer, 1 ) )
         return VLC_EGENERIC;
-    if( buffer == 0 )
-        return VLC_SUCCESS;
-
-    i_read = buffer << 4;
-    /* msg_Dbg( p_access, "ICY meta size=%u", i_read); */
+    if( i_read != 1 )
+        return VLC_EGENERIC;
+    const int i_size = buffer << 4;
+    /* msg_Dbg( p_access, "ICY meta size=%u", i_size); */
 
-    psz_meta = malloc( i_read + 1 );
-    if( net_Read( p_access, p_sys->fd, p_sys->p_vs,
-                  (uint8_t *)psz_meta, i_read, true ) != i_read )
+    psz_meta = malloc( i_size + 1 );
+    for( i_read = 0; i_read < i_size; )
     {
-        free( psz_meta );
-        return VLC_EGENERIC;
+        int i_tmp;
+        if( ReadData( p_access, &i_tmp, (uint8_t *)&psz_meta[i_read], i_size - i_read ) || i_tmp <= 0 )
+        {
+            free( psz_meta );
+            return VLC_EGENERIC;
+        }
+        i_read += i_tmp;
     }
-
     psz_meta[i_read] = '\0'; /* Just in case */
 
     /* msg_Dbg( p_access, "icy-meta=%s", psz_meta ); */
@@ -1230,53 +1243,30 @@ static int Request( access_t *p_access, uint64_t i_tell )
     p_sys->b_persist = false;
 
     p_sys->i_remaining = 0;
-    if( p_sys->b_proxy )
-    {
-        if( p_sys->url.psz_path )
-        {
-            net_Printf( p_access, p_sys->fd, NULL,
-                        "GET http://%s:%d%s HTTP/1.%d\r\n",
-                        p_sys->url.psz_host, p_sys->url.i_port,
-                        p_sys->url.psz_path, p_sys->i_version );
-        }
-        else
-        {
-            net_Printf( p_access, p_sys->fd, NULL,
-                        "GET http://%s:%d/ HTTP/1.%d\r\n",
-                        p_sys->url.psz_host, p_sys->url.i_port,
-                        p_sys->i_version );
-        }
-    }
+
+    const char *psz_path = p_sys->url.psz_path;
+    if( !psz_path || !*psz_path )
+        psz_path = "/";
+    if( p_sys->b_proxy && pvs == NULL )
+        net_Printf( p_access, p_sys->fd, NULL,
+                    "GET http://%s:%d HTTP/1.%d\r\n",
+                    p_sys->url.psz_host, p_sys->url.i_port, p_sys->i_version );
     else
-    {
-        const char *psz_path = p_sys->url.psz_path;
-        if( !psz_path || !*psz_path )
-        {
-            psz_path = "/";
-        }
-        if( p_sys->url.i_port != (pvs ? 443 : 80) )
-        {
-            net_Printf( p_access, p_sys->fd, pvs,
-                        "GET %s HTTP/1.%d\r\nHost: %s:%d\r\n",
-                        psz_path, p_sys->i_version, p_sys->url.psz_host,
-                        p_sys->url.i_port );
-        }
-        else
-        {
-            net_Printf( p_access, p_sys->fd, pvs,
-                        "GET %s HTTP/1.%d\r\nHost: %s\r\n",
-                        psz_path, p_sys->i_version, p_sys->url.psz_host );
-        }
-    }
+        net_Printf( p_access, p_sys->fd, pvs, "GET %s HTTP/1.%d\r\n",
+                    psz_path, p_sys->i_version );
+    if( p_sys->url.i_port != (pvs ? 443 : 80) )
+        net_Printf( p_access, p_sys->fd, pvs, "Host: %s:%d\r\n",
+                    p_sys->url.psz_host, p_sys->url.i_port );
+    else
+        net_Printf( p_access, p_sys->fd, pvs, "Host: %s\r\n",
+                    p_sys->url.psz_host );
     /* User Agent */
-    net_Printf( p_access, p_sys->fd, pvs,
-                "User-Agent: %s\r\n",
+    net_Printf( p_access, p_sys->fd, pvs, "User-Agent: %s\r\n",
                 p_sys->psz_user_agent );
     /* Referrer */
     if (p_sys->psz_referrer)
     {
-        net_Printf( p_access, p_sys->fd, pvs,
-                    "Referer: %s\r\n",
+        net_Printf( p_access, p_sys->fd, pvs, "Referer: %s\r\n",
                     p_sys->psz_referrer);
     }
     /* Offset */
@@ -1732,8 +1722,10 @@ static void cookie_append( vlc_array_t * cookies, char * cookie )
 
         assert( current_cookie_name );
 
-        bool is_domain_matching = ( cookie_domain && current_cookie_domain &&
-                                         !strcmp( cookie_domain, current_cookie_domain ) );
+        bool is_domain_matching = (
+                      ( !cookie_domain && !current_cookie_domain ) ||
+                      ( cookie_domain && current_cookie_domain &&
+                        !strcmp( cookie_domain, current_cookie_domain ) ) );
 
         if( is_domain_matching && !strcmp( cookie_name, current_cookie_name )  )
         {