[MPlayer-users] Streaming radio on Mplayer behind proxy with authentication

Prathmesh Prabhu callpraths at gmail.com
Tue Feb 16 01:37:29 CET 2010


15-Feb-2010

Hi,
I am trying to get radio streaming working behind a proxy that requires
authentication.
I tried to look for help on the net and came up with some ideas
(unfortunately don't remember the link) that I tried out.
Could someone please help me out on this / direct me to an existing
resource. My apologies if this mail is redundant.

Here's what I've done so far.

1. Added a Proxy-Authorization field to header (my own idea) With
Authorization field, proxy server refused connection.

 diff -Naur --speed-large-files mplayer-checkout-2010-02-13/stream/http.c
mymplayer/stream/http.c
--- mplayer-checkout-2010-02-13/stream/http.c    2010-02-13
10:45:02.000000000 +0530
+++ mymplayer/stream/http.c    2010-02-16 04:50:30.000000000 +0530
@@ -606,7 +606,7 @@

 int
 http_add_basic_authentication( HTTP_header_t *http_hdr, const char
*username, const char *password ) {
-    char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL;
+    char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL, *ref=NULL;
     int encoded_len, pass_len=0, out_len;
     int res = -1;
     if( http_hdr==NULL || username==NULL ) return -1;
@@ -646,6 +646,7 @@
     }

     sprintf( auth, "Authorization: Basic %s", b64_usr_pass);
+    sprintf( auth, "Proxy-Authorization: Basic %s", b64_usr_pass);
     http_set_field( http_hdr, auth );
     res = 0;

2. Found this on net, and this is where I began. Adds username and password
fields to the url passed on by mplayer

diff -Naur --speed-large-files mplayer-checkout-2010-02-13/stream/network.c
mymplayer/stream/network.c
--- mplayer-checkout-2010-02-13/stream/network.c    2010-02-13
10:45:02.000000000 +0530
+++ mymplayer/stream/network.c    2010-02-16 05:01:56.000000000 +0530
@@ -168,13 +168,28 @@

             mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: %s\n",
proxy_url->url );
             len = strlen( proxy_url->hostname ) + strlen( url->url ) +
20;    // 20 = http_proxy:// + port
+            if(proxy_url->username){
+                len += strlen(proxy_url->username) + 2;
+                if(proxy_url->password)
+                    len+=strlen(proxy_url->password);
+            }
             new_url = malloc( len+1 );
             if( new_url==NULL ) {
                 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
                 url_free(proxy_url);
                 return url_out;
             }
-            sprintf(new_url, "http_proxy://%s:%d/%s", proxy_url->hostname,
proxy_url->port, url->url );
+
+            //debug//
+            //char *ppp_dump = malloc(500);
+            //sprintf(ppp_dump,,
+           //mp_msg(MSGT_NETWORK, MSGL_FATAL, len_dump);
+
+            if(proxy_url->username){
+                sprintf(new_url, "http_proxy://%s:%s@%s:%d/%s",
proxy_url->username, proxy_url->password, proxy_url->hostname,
proxy_url->port, url->url );
+            }else{
+                sprintf(new_url, "http_proxy://%s:%d/%s",
proxy_url->hostname, proxy_url->port, url->url );
+            }
             tmp_url = url_new( new_url );
             if( tmp_url==NULL ) {
                 free( new_url );

3. My own idea: Add a refered field same as host (only did this because I
saw firefox do this on wireshark)

@@ -198,7 +213,7 @@
     int fd = -1;
     int ret;
     int proxy = 0;        // Boolean
-
+    char ref[256];
     http_hdr = http_new_header();

     if( !strcasecmp(url->protocol, "http_proxy") ) {
@@ -233,7 +248,12 @@

     if (network_cookies_enabled) cookies_set( http_hdr,
server_url->hostname, server_url->url );

-    http_set_field( http_hdr, "Connection: close");
+    if(proxy){
+        http_set_field( http_hdr, "Proxy-Connection: keep-alive");
+        snprintf(ref, 256, "Referer: %s:%u", server_url->hostname,
server_url->port);
+        http_set_field( http_hdr, ref);
+    }else
+        http_set_field( http_hdr, "Connection: close");
     http_add_basic_authentication( http_hdr, url->username, url->password
);
     if( http_build_request( http_hdr )==NULL ) {
         goto err_out;

At the end of this exercise, Mplayer successfully requests opening of a
stream from my proxy server and receives  200 OK with 233bytes of video
data, but it keeps repeating these steps and does not seem to move on
towards continuous streaming.
Since I do not understand how streaming works, I'm in the blue about what
I've done wrong.

Thanks in advance for any help.
-- 
Prathmesh


More information about the MPlayer-users mailing list