[MPlayer-cvslog] r35207 - in trunk/stream: http.c url.c url.h

reimar subversion at mplayerhq.hu
Fri Sep 21 20:57:00 CEST 2012


Author: reimar
Date: Fri Sep 21 20:57:00 2012
New Revision: 35207

Log:
Fix redirection for proxy URLs.

Should fix bug #2091.

Modified:
   trunk/stream/http.c
   trunk/stream/url.c
   trunk/stream/url.h

Modified: trunk/stream/http.c
==============================================================================
--- trunk/stream/http.c	Fri Sep 21 09:55:55 2012	(r35206)
+++ trunk/stream/http.c	Fri Sep 21 20:57:00 2012	(r35207)
@@ -826,18 +826,16 @@ static int http_streaming_start(stream_t
 				if( next_url!=NULL ) {
 					int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0;
 					stream->streaming_ctrl->url = url_redirect( &url, next_url );
-					if (!strcasecmp(url->protocol, "mms")) {
+					if (url_is_protocol(url, "mms")) {
 						res = STREAM_REDIRECTED;
 						goto err_out;
 					}
-					if (strcasecmp(url->protocol, "http")) {
+					if (!url_is_protocol(url, "http")) {
 						mp_msg(MSGT_NETWORK,MSGL_ERR,"Unsupported http %d redirect to %s protocol\n", http_hdr->status_code, url->protocol);
 						goto err_out;
 					}
-					if (is_ultravox)  {
-						free(url->protocol);
-						url->protocol = strdup("unsv");
-					}
+					if (is_ultravox)
+						url_set_protocol(url, "unsv");
 					redirect = 1;
 				}
 				break;

Modified: trunk/stream/url.c
==============================================================================
--- trunk/stream/url.c	Fri Sep 21 09:55:55 2012	(r35206)
+++ trunk/stream/url.c	Fri Sep 21 20:57:00 2012	(r35207)
@@ -35,25 +35,65 @@
 #define SIZE_MAX ((size_t)-1)
 #endif
 
+static int is_proxy(const URL_t *url) {
+  return !strcasecmp(url->protocol, "http_proxy") && url->file && strstr(url->file, "://");
+}
+
+int url_is_protocol(const URL_t *url, const char *proto) {
+  int proxy = is_proxy(url);
+  if (proxy) {
+    URL_t *tmp = url_new(url->file + 1);
+    int res = !strcasecmp(tmp->protocol, proto);
+    url_free(tmp);
+    return res;
+  }
+  return !strcasecmp(url->protocol, proto);
+}
+
+void url_set_protocol(URL_t *url, const char *proto) {
+  int proxy = is_proxy(url);
+  if (proxy) {
+    char *dst = url->file + 1;
+    int oldlen = strstr(dst, "://") - dst;
+    int newlen = strlen(proto);
+    if (newlen != oldlen) {
+      mp_msg(MSGT_NETWORK, MSGL_ERR, "Setting protocol not implemented!\n");
+      return;
+    }
+    memcpy(dst, proto, newlen);
+    return;
+  }
+  free(url->protocol);
+  url->protocol = strdup(proto);
+}
+
 URL_t *url_redirect(URL_t **url, const char *redir) {
   URL_t *u = *url;
+  int proxy = is_proxy(u);
+  const char *oldurl = proxy ? u->file + 1 : u->url;
+  const char *newurl = redir;
+  char *buffer = NULL;
   URL_t *res;
   if (!strchr(redir, '/') || *redir == '/') {
     char *tmp;
-    char *newurl = malloc(strlen(u->url) + strlen(redir) + 1);
-    strcpy(newurl, u->url);
+    newurl = buffer = malloc(strlen(oldurl) + strlen(redir) + 1);
+    strcpy(buffer, oldurl);
     if (*redir == '/') {
       redir++;
-      tmp = strstr(newurl, "://");
+      tmp = strstr(buffer, "://");
       if (tmp) tmp = strchr(tmp + 3, '/');
     } else
-      tmp = strrchr(newurl, '/');
+      tmp = strrchr(buffer, '/');
     if (tmp) tmp[1] = 0;
-    strcat(newurl, redir);
-    res = url_new(newurl);
-    free(newurl);
-  } else
-    res = url_new(redir);
+    strcat(buffer, redir);
+  }
+  if (proxy) {
+    char *tmp = get_http_proxy_url(u, newurl);
+    free(buffer);
+    newurl = buffer = tmp;
+  }
+  res = url_new(newurl);
+  free(buffer);
   url_free(u);
   *url = res;
   return res;

Modified: trunk/stream/url.h
==============================================================================
--- trunk/stream/url.h	Fri Sep 21 09:55:55 2012	(r35206)
+++ trunk/stream/url.h	Fri Sep 21 20:57:00 2012	(r35207)
@@ -36,6 +36,8 @@ typedef struct {
 	char *password;
 } URL_t;
 
+int url_is_protocol(const URL_t *url, const char *proto);
+void url_set_protocol(URL_t *url, const char *proto);
 URL_t *url_redirect(URL_t **url, const char *redir);
 
 char *get_http_proxy_url(const URL_t *proxy, const char *host_url);


More information about the MPlayer-cvslog mailing list