+ 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);
+ }
+ }
+ }
+ curl_easy_setopt ( curl, CURLOPT_USERAGENT, curl_download_user_agent );
+ if ((cookie_file = get_cookie_file(FALSE)) != NULL)
+ curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookie_file);
+ res = curl_easy_perform ( curl );
+
+ if (res == 0) {
+ glong response;
+ curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response);
+ if (response == 304) { // 304 = Not Modified
+ res = CURL_DOWNLOAD_NO_NEWER_FILE;
+ } else if (response == 200 || // http: 200 = Ok
+ response == 226) { // ftp: 226 = sucess
+ gdouble size;
+ /* verify if curl sends us any data - this is a workaround on using CURLOPT_TIMECONDITION
+ when the server has a (incorrect) time earlier than the time on the file we already have */
+ curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &size);
+ if (size == 0)
+ res = CURL_DOWNLOAD_ERROR;
+ else
+ res = CURL_DOWNLOAD_NO_ERROR;
+ } else {
+ g_warning("%s: http response: %ld for uri %s\n", __FUNCTION__, response, uri);
+ res = CURL_DOWNLOAD_ERROR;
+ }
+ } else {
+ res = CURL_DOWNLOAD_ERROR;
+ }
+ if (!handle)
+ curl_easy_cleanup ( curl );
+ if (curl_send_headers) {
+ curl_slist_free_all(curl_send_headers);
+ curl_send_headers = NULL;
+ curl_easy_setopt ( curl, CURLOPT_HTTPHEADER , NULL);
+ }
+ return res;