[MPlayer-cvslog] r32971 - in trunk/stream: network.c url.c url.h

cboesch subversion at mplayerhq.hu
Sat Feb 26 12:57:18 CET 2011


Author: cboesch
Date: Sat Feb 26 12:57:18 2011
New Revision: 32971

Log:
Use mp_asprintf in make_noauth_url and make_http_proxy_url.

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

Modified: trunk/stream/network.c
==============================================================================
--- trunk/stream/network.c	Sat Feb 26 12:55:02 2011	(r32970)
+++ trunk/stream/network.c	Sat Feb 26 12:57:18 2011	(r32971)
@@ -143,7 +143,6 @@ check4proxies( URL_t *url ) {
 		proxy = getenv("http_proxy");
 		if( proxy!=NULL ) {
 			// We got a proxy, build the URL to use it
-			int len;
 			char *new_url;
 			URL_t *tmp_url;
 			URL_t *proxy_url = url_new( proxy );
@@ -164,14 +163,12 @@ check4proxies( URL_t *url ) {
 #endif
 
 			mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: %s\n", proxy_url->url );
-			len = make_http_proxy_url(proxy_url, url->url, NULL, 0) + 1;
-			new_url = malloc(len);
+			new_url = get_http_proxy_url(proxy_url, url->url);
 			if( new_url==NULL ) {
 				mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
 				url_free(proxy_url);
 				return url_out;
 			}
-			make_http_proxy_url(proxy_url, url->url, new_url, len);
 			tmp_url = url_new( new_url );
 			if( tmp_url==NULL ) {
 				free( new_url );

Modified: trunk/stream/url.c
==============================================================================
--- trunk/stream/url.c	Sat Feb 26 12:55:02 2011	(r32970)
+++ trunk/stream/url.c	Sat Feb 26 12:57:18 2011	(r32971)
@@ -28,6 +28,7 @@
 
 #include "url.h"
 #include "mp_msg.h"
+#include "mp_strings.h"
 #include "help_mp.h"
 
 #ifndef SIZE_MAX
@@ -58,32 +59,31 @@ URL_t *url_redirect(URL_t **url, const c
   return res;
 }
 
-static int make_noauth_url(URL_t *url, char *dst, int dst_size)
+static char *get_noauth_url(URL_t *url)
 {
     if (url->port)
-        return snprintf(dst, dst_size, "%s://%s:%d%s", url->protocol,
-                        url->hostname, url->port, url->file);
+        return mp_asprintf("%s://%s:%d%s",
+                           url->protocol, url->hostname, url->port, url->file);
     else
-        return snprintf(dst, dst_size, "%s://%s%s", url->protocol,
-                        url->hostname, url->file);
+        return mp_asprintf("%s://%s%s",
+                           url->protocol, url->hostname, url->file);
 }
 
-int make_http_proxy_url(URL_t *proxy, const char *host_url, char *dst,
-                        int dst_size)
+char *get_http_proxy_url(URL_t *proxy, const char *host_url)
 {
     if (proxy->username)
-        return snprintf(dst, dst_size, "http_proxy://%s:%s@%s:%d/%s",
-                        proxy->username,
-                        proxy->password ? proxy->password : "",
-                        proxy->hostname, proxy->port, host_url);
+        return mp_asprintf("http_proxy://%s:%s@%s:%d/%s",
+                           proxy->username,
+                           proxy->password ? proxy->password : "",
+                           proxy->hostname, proxy->port, host_url);
     else
-        return snprintf(dst, dst_size, "http_proxy://%s:%d/%s",
-                        proxy->hostname, proxy->port, host_url);
+        return mp_asprintf("http_proxy://%s:%d/%s",
+                           proxy->hostname, proxy->port, host_url);
 }
 
 URL_t*
 url_new(const char* url) {
-	int pos1, pos2,v6addr = 0, noauth_len;
+	int pos1, pos2,v6addr = 0;
 	URL_t* Curl = NULL;
         char *escfilename=NULL;
 	char *ptr1=NULL, *ptr2=NULL, *ptr3=NULL, *ptr4=NULL;
@@ -252,16 +252,11 @@ url_new(const char* url) {
 		strcpy(Curl->file, "/");
 	}
 
-	noauth_len = make_noauth_url(Curl, NULL, 0);
-	if (noauth_len > 0) {
-		noauth_len++;
-		Curl->noauth_url = malloc(noauth_len);
+	Curl->noauth_url = get_noauth_url(Curl);
 		if (!Curl->noauth_url) {
 			mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MemAllocFailed);
 			goto err_out;
 		}
-		make_noauth_url(Curl, Curl->noauth_url, noauth_len);
-	}
 
         free(escfilename);
 	return Curl;

Modified: trunk/stream/url.h
==============================================================================
--- trunk/stream/url.h	Sat Feb 26 12:55:02 2011	(r32970)
+++ trunk/stream/url.h	Sat Feb 26 12:57:18 2011	(r32971)
@@ -38,7 +38,7 @@ typedef struct {
 
 URL_t *url_redirect(URL_t **url, const char *redir);
 
-int make_http_proxy_url(URL_t *proxy, const char *host_url, char *dst, int dst_size);
+char *get_http_proxy_url(URL_t *proxy, const char *host_url);
 
 URL_t* url_new(const char* url);
 void   url_free(URL_t* url);


More information about the MPlayer-cvslog mailing list