]> git.street.me.uk Git - andy/viking.git/commitdiff
Move time_condition to scruct DownloadFileOptions - this is to add the etag value
authorJocelyn Jaubert <jocelyn.jaubert@gmail.com>
Sun, 21 Feb 2010 13:21:06 +0000 (14:21 +0100)
committerJocelyn Jaubert <jocelyn.jaubert@gmail.com>
Sun, 18 Jul 2010 17:32:45 +0000 (19:32 +0200)
src/curl_download.c
src/curl_download.h
src/download.c
src/download.h

index 871209f119cd843633d43f76f92fe9c63cc103e0..7d803a3ed64624b4631adac2b17d47265a8dad52 100644 (file)
@@ -121,7 +121,7 @@ void curl_download_init()
   curl_download_user_agent = g_strdup_printf ("%s/%s %s", PACKAGE, VERSION, curl_version());
 }
 
-int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, time_t time_condition, void *handle )
+int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, DownloadFileOptions *file_options, void *handle )
 {
   CURL *curl;
   CURLcode res = CURLE_FAILED_INIT;
@@ -148,10 +148,12 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, t
       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);
+    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);
+      }
     }
   }
   curl_easy_setopt ( curl, CURLOPT_USERAGENT, curl_download_user_agent );
@@ -174,7 +176,7 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, t
       else
         res = DOWNLOAD_NO_ERROR;
     } else {
-      g_warning("%s: http response: %ld for uri %s (time_condition = %ld)\n", __FUNCTION__, response, uri, time_condition);
+      g_warning("%s: http response: %ld for uri %s (time_condition = %ld)\n", __FUNCTION__, response, uri, file_options->time_condition);
       res = DOWNLOAD_ERROR;
     }
   } else {
@@ -185,14 +187,14 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, t
   return res;
 }
 
-int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadMapOptions *options, gboolean ftp, time_t time_condition, void *handle )
+int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadMapOptions *options, gboolean ftp, DownloadFileOptions *file_options, void *handle )
 {
   int ret;
   gchar *full = NULL;
 
   /* Compose the full url */
   full = g_strdup_printf ( "%s://%s%s", (ftp?"ftp":"http"), hostname, uri );
-  ret = curl_download_uri ( full, f, options, time_condition, handle );
+  ret = curl_download_uri ( full, f, options, file_options, handle );
   g_free ( full );
   full = NULL;
 
index 16505459c79c2c89e26113ef2a0eb6971fc20f8d..67e73965a3e1b245742766f35a223da9ed1f3ec8 100644 (file)
@@ -27,8 +27,8 @@
 #include "download.h"
 
 void curl_download_init ();
-int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadMapOptions *options, gboolean ftp, time_t time_condition, void *handle );
-int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, time_t time_condition, void *handle );
+int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadMapOptions *options, gboolean ftp, DownloadFileOptions *file_options, void *handle );
+int curl_download_uri ( const char *uri, FILE *f, DownloadMapOptions *options, DownloadFileOptions *file_options, void *handle );
 void * curl_download_handle_init ();
 void curl_download_handle_cleanup ( void * handle );
 
index 8536eaee02cc5baf72291b7f89b3904ce2085a20..957ba324eeceda2d3c40f8b5d54b9991c49bbc4f 100644 (file)
@@ -147,7 +147,7 @@ static int download( const char *hostname, const char *uri, const char *fn, Down
   int ret;
   gchar *tmpfilename;
   gboolean failure = FALSE;
-  time_t time_condition = 0;
+  DownloadFileOptions file_options = {0};
 
   /* Check file */
   if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == TRUE )
@@ -157,8 +157,8 @@ static int download( const char *hostname, const char *uri, const char *fn, Down
       /* Get the modified time of this file */
       struct stat buf;
       g_stat ( fn, &buf );
-      time_condition = buf.st_mtime;
-      if ( (time(NULL) - time_condition) < tile_age )
+      file_options.time_condition = buf.st_mtime;
+      if ( (time(NULL) - file_options.time_condition) < tile_age )
                                /* File cache is too recent, so return */
                                return -3;
     } else {
@@ -186,7 +186,7 @@ static int download( const char *hostname, const char *uri, const char *fn, Down
   }
 
   /* Call the backend function */
-  ret = curl_download_get_url ( hostname, uri, f, options, ftp, time_condition, handle );
+  ret = curl_download_get_url ( hostname, uri, f, options, ftp, &file_options, handle );
 
   if (ret != DOWNLOAD_NO_ERROR && ret != DOWNLOAD_NO_NEWER_FILE) {
     g_debug("%s: download failed: curl_download_get_url=%d", __FUNCTION__, ret);
index 4c9027c1bf814a618f62e7b7b32848eeecd0c5f9..810da554dce891d7aca61e01018b3d579f9b07e0 100644 (file)
@@ -56,6 +56,14 @@ typedef struct {
 
 } DownloadMapOptions;
 
+typedef struct {
+  /**
+   * Time sent to server on header If-Modified-Since
+   */
+  time_t time_condition;
+
+} DownloadFileOptions;
+
 void a_download_init(void);
 
 /* TODO: convert to Glib */