- curl = curl_easy_init ();
- if ( curl )
- {
- curl_easy_setopt ( curl, CURLOPT_URL, uri );
- curl_easy_setopt ( curl, CURLOPT_FILE, f );
- if (options != NULL) {
- if(options->referer != NULL)
- curl_easy_setopt ( curl, CURLOPT_REFERER, options->referer);
- if(options->follow_location != 0) {
- curl_easy_setopt ( curl, CURLOPT_FOLLOWLOCATION, 1);
- curl_easy_setopt ( curl, CURLOPT_MAXREDIRS, options->follow_location);
+ g_debug("%s: uri=%s", __PRETTY_FUNCTION__, uri);
+
+ curl = handle ? handle : curl_easy_init ();
+ if ( !curl ) {
+ return DOWNLOAD_ERROR;
+ }
+ 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!
+ curl_easy_setopt ( curl, CURLOPT_URL, uri );
+ curl_easy_setopt ( curl, CURLOPT_WRITEDATA, f );
+ curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func);
+ curl_easy_setopt ( curl, CURLOPT_NOPROGRESS, 0 );
+ curl_easy_setopt ( curl, CURLOPT_PROGRESSDATA, NULL );
+ curl_easy_setopt ( curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func);
+ if (options != NULL) {
+ if(options->referer != NULL)
+ curl_easy_setopt ( curl, CURLOPT_REFERER, options->referer);
+ if(options->follow_location != 0) {
+ curl_easy_setopt ( curl, CURLOPT_FOLLOWLOCATION, 1);
+ curl_easy_setopt ( curl, CURLOPT_MAXREDIRS, options->follow_location);
+ }
+ if (file_options != NULL) {
+ if(options->check_file_server_time && file_options->time_condition != 0) {
+ /* if file exists, check against server if file is recent enough */
+ curl_easy_setopt ( curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
+ curl_easy_setopt ( curl, CURLOPT_TIMEVALUE, file_options->time_condition);
+ }
+ if (options->use_etag) {
+ if (file_options->etag != NULL) {
+ /* add an header on the HTTP request */
+ char str[60];
+ g_snprintf(str, 60, "If-None-Match: %s", file_options->etag);
+ curl_send_headers = curl_slist_append(curl_send_headers, str);
+ curl_easy_setopt ( curl, CURLOPT_HTTPHEADER , curl_send_headers);