- curl = curl_easy_init ();
- if ( curl )
- {
- curl_easy_setopt ( curl, CURLOPT_URL, uri );
- curl_easy_setopt ( curl, CURLOPT_FILE, f );
- if (strstr(uri, ".google.com"))
- curl_easy_setopt ( curl, CURLOPT_REFERER, "http://maps.google.com/");
- if (cookie_file = get_cookie_file(FALSE))
- 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 CURL_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!
+ 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);
+ 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);
+ }
+ /* store the new etag from the server in an option value */
+ curl_easy_setopt ( curl, CURLOPT_WRITEHEADER, &(file_options->new_etag));
+ curl_easy_setopt ( curl, CURLOPT_HEADERFUNCTION, curl_get_etag_func);
+ }