From 1aefc7ebc9c119aea3377e3ae35282ea23f43494 Mon Sep 17 00:00:00 2001 From: Guilhem Bonnefille Date: Mon, 20 May 2013 22:48:09 +0200 Subject: [PATCH] Allow to use full URL as download parameter --- src/curl_download.c | 16 +++++++++++++--- src/vikwebtool_datasource.c | 6 +----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/curl_download.c b/src/curl_download.c index cbaa4031..8b171f8a 100644 --- a/src/curl_download.c +++ b/src/curl_download.c @@ -27,6 +27,7 @@ #endif #include +#include #ifdef HAVE_UNISTD_H #include @@ -208,10 +209,19 @@ int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, Down int ret; gchar *full = NULL; - /* Compose the full url */ - full = g_strdup_printf ( "%s://%s%s", (ftp?"ftp":"http"), hostname, uri ); + if ( strstr ( hostname, "://" ) != NULL ) + /* Already full url */ + full = (gchar *) hostname; + else if ( strstr ( uri, "://" ) != NULL ) + /* Already full url */ + full = (gchar *) uri; + else + /* Compose the full url */ + full = g_strdup_printf ( "%s://%s%s", (ftp?"ftp":"http"), hostname, uri ); ret = curl_download_uri ( full, f, options, file_options, handle ); - g_free ( full ); + /* Free newly allocated memory, but do not free uri */ + if ( hostname != full && uri != full ) + g_free ( full ); full = NULL; return ret; diff --git a/src/vikwebtool_datasource.c b/src/vikwebtool_datasource.c index 04eb8988..f2661d35 100644 --- a/src/vikwebtool_datasource.c +++ b/src/vikwebtool_datasource.c @@ -142,11 +142,7 @@ static void datasource_get_cmd_string ( gpointer user_data, gchar **cmd, gchar * gchar *url = vik_webtool_get_url ( vwd, data->vw ); g_debug ("%s: %s", __FUNCTION__, url ); - // if url starts with 'http://' then only the copy the part after it - as the download code always inserts it! - if ( !strncmp(url, "http://", 7 ) ) - *cmd = g_strndup ( &url[7], strlen (url) ); - else - *cmd = g_strdup ( url ); + *cmd = g_strdup ( url ); // Only use first section of the file_type string // One can't use values like 'kml -x transform,rte=wpt' in order to do fancy things -- 2.39.5