]> git.street.me.uk Git - andy/viking.git/commitdiff
Add referer to DownloadOptions
authorGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sat, 23 Jun 2007 14:44:34 +0000 (14:44 +0000)
committerGuilhem Bonnefille <guilhem.bonnefille@gmail.com>
Sat, 23 Jun 2007 14:44:34 +0000 (14:44 +0000)
This allows to specify a referer per map source

14 files changed:
ChangeLog
src/curl_download.c
src/curl_download.h
src/download.c
src/download.h
src/expedia.c
src/google.c
src/googlemaps.c
src/googlesearch.c
src/http.c
src/http.h
src/khmaps.c
src/osm.c
src/terraserver.c

index f253a08278529d5eb220a285ebb0947120671614..15ccfb9cc6982ca73bb419701bd88fde2d59bbc0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2007-06-23
 Guilhem Bonnefille <guilhem.bonnefille@gmail.com>:
        * Minor change to avoid SEGFAULT on x86_64
+       * Add DownloadOptions type to specify referer per map source
 
 2007-06-19
 Quy Tonthat <qtonthat@gmail.com>:
index 3435e521f8f4ad1fa41546da002fa751dc1f86d5..210d64c5e43a9f1a4e73eb4112a5b1b9550ea925 100644 (file)
@@ -77,7 +77,7 @@ void curl_download_init()
   get_cookie_file(TRUE);
 }
 
-int curl_download_uri ( const char *uri, FILE *f )
+int curl_download_uri ( const char *uri, FILE *f, DownloadOptions *options )
 {
   CURL *curl;
   CURLcode res = CURLE_FAILED_INIT;
@@ -88,8 +88,8 @@ int curl_download_uri ( const char *uri, FILE *f )
     {
       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 (options != NULL && options->referer != NULL)
+        curl_easy_setopt ( curl, CURLOPT_REFERER, options->referer);
       curl_easy_setopt ( curl, CURLOPT_USERAGENT, "viking/0.1.3 libcurl/7.15.4" );
       if (cookie_file = get_cookie_file(FALSE))
         curl_easy_setopt(curl, CURLOPT_COOKIEFILE, cookie_file);
@@ -99,14 +99,14 @@ int curl_download_uri ( const char *uri, FILE *f )
   return(res);
 }
 
-int curl_download_get_url ( const char *hostname, const char *uri, FILE *f )
+int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadOptions *options )
 {
   int ret;
   gchar *full = NULL;
 
   /* Compose the full url */
   full = g_strdup_printf ( "http://%s%s", hostname, uri );
-  ret = curl_download_uri ( full, f );
+  ret = curl_download_uri ( full, f, options );
   g_free ( full );
   full = NULL;
 
index 8043b1d9bee23edbd25484cf97712da1a65627b1..8ad400384806a154038056d0ab14a09e94d89039 100644 (file)
 
 #include <stdio.h>
 
+#include "download.h"
+
 void curl_download_init ();
-int curl_download_get_url ( const char *hostname, const char *uri, FILE *f );
-int curl_download_uri ( const char *uri, FILE *f );
+int curl_download_get_url ( const char *hostname, const char *uri, FILE *f, DownloadOptions *options );
+int curl_download_uri ( const char *uri, FILE *f, DownloadOptions *options );
 
 #endif
index dea5b8231ac2576c0cd143c5c0b64442e703c050..fcaef0b5db1da8bee67c2cec9bfba69d90a1f274 100644 (file)
@@ -100,7 +100,7 @@ static int check_map_file(FILE* f)
   return(res);
 }
 
-static int download( const char *hostname, const char *uri, const char *fn, int sendhostname)
+static int download( const char *hostname, const char *uri, const char *fn, DownloadOptions *options)
 {
   FILE *f;
   int ret;
@@ -142,9 +142,9 @@ static int download( const char *hostname, const char *uri, const char *fn, int
 
   /* Call the backend function */
 #ifdef HAVE_LIBCURL
-  ret = curl_download_get_url ( hostname, uri, f );
+  ret = curl_download_get_url ( hostname, uri, f, options );
 #else
-  ret = http_download_get_url ( hostname, uri, f, 0, sendhostname );
+  ret = http_download_get_url ( hostname, uri, f, 0, options );
 #endif
 
   if (ret == -1 || ret == 1 || ret == -2 || check_map_file(f))
@@ -168,7 +168,5 @@ static int download( const char *hostname, const char *uri, const char *fn, int
 /* only reason for the "wrapper" is so we can do redirects. */
 int a_http_download_get_url ( const char *hostname, const char *uri, const char *fn, DownloadOptions *opt )
 {
-  int sendhostname = 0;
-  if (opt != NULL) sendhostname = opt->sendhostname;
-  return download ( hostname, uri, fn, sendhostname );
+  return download ( hostname, uri, fn, opt );
 }
index 5439a4ce4124750df3afc5019182beac765db068..d31776ae63c15aa249455b6ed694926e6bcdadc5 100644 (file)
 #define _VIKING_DOWNLOAD_H
 
 typedef struct {
+  /**
+   * Indicates if we should send hostname on the GET request.
+   * (see http.c)
+   */
   int sendhostname;
+  /**
+   * The REFERER string to use.
+   * Could be NULL.
+   */
+  gchar *referer;
 } DownloadOptions;
 
 /* TODO: convert to Glib */
index bc7b60864f9fb1596be853a9ee5c1dab33747a6b..cd0dfa9db8bc5976739e64263053906f0ef36ccb 100644 (file)
@@ -37,7 +37,7 @@ static gboolean expedia_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom,
 static void expedia_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest );
 static int expedia_download ( MapCoord *src, const gchar *dest_fn );
 
-static DownloadOptions expedia_options = { 0 };
+static DownloadOptions expedia_options = { 0, NULL };
 
 void expedia_init() {
   VikMapsLayer_MapType map_type = { 5, 0, 0, VIK_VIEWPORT_DRAWMODE_EXPEDIA, expedia_coord_to_mapcoord, expedia_mapcoord_to_center_coord, expedia_download };
index 62a480b6ffe3aa7f553cdb5c60dc69ab1b747d47..4034ecccd5adc2bd27946082adda0d4fb53c6689 100644 (file)
@@ -40,7 +40,7 @@ static int google_kh_download ( MapCoord *src, const gchar *dest_fn );
 static void google_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest );
 static gboolean google_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest );
 
-static DownloadOptions google_options = { 1 };
+static DownloadOptions google_options = { 1, "http://maps.google.com/" };
 
 void google_init () {
   VikMapsLayer_MapType google_1 = { 7, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_download };
index df8ff6298842f11e723b37727ea16c768a823309..87795fdf9d1aacc0afd526a900d3896294ce6899 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "googlemaps.h"
 
-static DownloadOptions googlemaps_options = { 1 };
+static DownloadOptions googlemaps_options = { 1, "http://maps.google.com/" };
 
 /* initialisation */
 void googlemaps_init () {
index a2c45be35b7db689081e4952b799b5d920acaab0..8037663c633a6d0b5cda980ca155b07b64d4de24 100644 (file)
@@ -34,6 +34,8 @@ static gchar *last_search_str = NULL;
 static VikCoord *last_coord = NULL;
 static gchar *last_successful_search_str = NULL;
 
+static DownloadOptions googlesearch_options = { 0, "http://maps.google.com/" };
+
 gchar * a_googlesearch_get_search_string_for_this_place(VikWindow *vw)
 {
   if (!last_coord)
@@ -206,7 +208,7 @@ static int google_search_get_coord(VikWindow *vw, VikViewport *vvp, gchar *srch_
   uri = g_strdup_printf(GOOGLE_SEARCH_URL_FMT, escaped_srch_str);
 
   /* TODO: curl may not be available */
-  if (curl_download_uri(uri, tmp_file)) {  /* error */
+  if (curl_download_uri(uri, tmp_file, &googlesearch_options)) {  /* error */
     fprintf(stderr, "DEBUG: %s() download error\n", __PRETTY_FUNCTION__);
     fclose(tmp_file);
     ret = -1;
index b8e0dab54531083ce9d2daf65175fbde78bd4203..6bbde741009ff6c772b9460b27cb77c038a1debc 100644 (file)
@@ -88,7 +88,7 @@ int http_get_line(int sock, char *buf, int len)
   return 1;
 }
 
-int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int already_redirected, int sendhostname )
+int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int already_redirected, DownloadOptions *options )
 {
   static char input_buffer[1024];
   int sock;
@@ -108,7 +108,7 @@ int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int
   }
 
 
-  if ( sendhostname ) {
+  if ( options != NULL && options->sendhostname ) {
     send ( sock, "GET http://", 11, 0);
     send ( sock, hostname, strlen(hostname), 0 );
     send ( sock, uri, strlen ( uri ), 0 );
index 04f5f74372232d81e718abad5e83beaceae1d48f..d9aac4ab8578c35774726333f9db504588e1df1f 100644 (file)
@@ -24,6 +24,8 @@
 
 #include <stdio.h>
 
-int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int already_redirected, int sendhostname );
+#include "download.h"
+
+int http_download_get_url ( const char *hostname, const char *uri, FILE *f, int already_redirected, DownloadOptions *options );
 
 #endif
index bed9da85e7bbb4965a2b2613d2177cd07099afa6..5921c98761ab26f4cab631bc6d0e39d29a011c2e 100644 (file)
@@ -31,7 +31,7 @@
 
 #include "khmaps.h"
 
-static DownloadOptions khmaps_options = { 1 };
+static DownloadOptions khmaps_options = { 1, NULL };
 
 void khmaps_init () {
   VikMapsLayer_MapType map_type = { 8, 256, 256, VIK_VIEWPORT_DRAWMODE_KH, khmaps_coord_to_mapcoord, khmaps_mapcoord_to_center_coord, khmaps_download };
index b49ec948b48734cc475577e3bd7ddceb44c7a968..5fd04697511ad7162013db4e64469e31b226f05c 100644 (file)
--- a/src/osm.c
+++ b/src/osm.c
@@ -38,7 +38,7 @@ static int osm_maplint_download ( MapCoord *src, const gchar *dest_fn );
 static int osm_mapnik_download ( MapCoord *src, const gchar *dest_fn );
 static int osm_osmarender_download ( MapCoord *src, const gchar *dest_fn );
 
-static DownloadOptions osm_options = { 1 };
+static DownloadOptions osm_options = { 1, NULL };
 
 /* initialisation */
 void osm_init () {
index 4499dbfd6e7c5fcfbedeec783c58b8f1b5bac1b3..68c77b8fa43042a46c4581f607bc735a13c1388f 100644 (file)
@@ -41,7 +41,7 @@ static int terraserver_urban_download ( MapCoord *src, const gchar *dest_fn );
 
 static void terraserver_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest );
 
-static DownloadOptions terraserver_options = { 0 };
+static DownloadOptions terraserver_options = { 0, NULL };
 
 void terraserver_init () {
   VikMapsLayer_MapType map_type_1 = { 2, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_topo_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_topo_download };