- 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);
- }
- }
- curl_easy_setopt ( curl, CURLOPT_USERAGENT, PACKAGE "/" VERSION " libcurl/7.15.4" );
- if ((cookie_file = get_cookie_file(FALSE)) != NULL)
- curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookie_file);
- res = curl_easy_perform ( curl );
- curl_easy_cleanup ( curl );
+ 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_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(options->check_file_server_time && 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, time_condition);