changeset 32884:0d95f044c589

Use mp_asprintf in make_noauth_url and make_http_proxy_url.
author cboesch
date Sat, 26 Feb 2011 11:57:18 +0000
parents fa04e96e6177
children 34fb7af52b82
files stream/network.c stream/url.c stream/url.h
diffstat 3 files changed, 17 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/stream/network.c	Sat Feb 26 11:55:02 2011 +0000
+++ b/stream/network.c	Sat Feb 26 11:57:18 2011 +0000
@@ -143,7 +143,6 @@
 		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 @@
 #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 );
--- a/stream/url.c	Sat Feb 26 11:55:02 2011 +0000
+++ b/stream/url.c	Sat Feb 26 11:57:18 2011 +0000
@@ -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 @@
   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 @@
 		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;
--- a/stream/url.h	Sat Feb 26 11:55:02 2011 +0000
+++ b/stream/url.h	Sat Feb 26 11:57:18 2011 +0000
@@ -38,7 +38,7 @@
 
 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);