]> git.street.me.uk Git - andy/viking.git/blobdiff - src/curl_download.c
Fix crashing if attempting to Extend a Route via the Route Finder when the route...
[andy/viking.git] / src / curl_download.c
index 2ef4c5bb960da158bed6f2349331b88444d8520c..8b171f8af0ae3ca9ca8c2e433f10c6b96a0ff090 100644 (file)
@@ -27,6 +27,7 @@
 #endif
 
 #include <stdio.h>
+#include <string.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
@@ -129,6 +130,10 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, D
   if (vik_verbose)
     curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 );
   curl_easy_setopt ( curl, CURLOPT_NOSIGNAL, 1 ); // Yep, we're a multi-threaded program so don't let signals mess it up!
+  if ( options != NULL && options->user_pass ) {
+    curl_easy_setopt ( curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY );
+    curl_easy_setopt ( curl, CURLOPT_USERPWD, options->user_pass );
+  }
   curl_easy_setopt ( curl, CURLOPT_URL, uri );
   curl_easy_setopt ( curl, CURLOPT_WRITEDATA, f );
   curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func);
@@ -204,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;