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>:
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;
{
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);
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;
#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
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;
/* 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))
/* 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 );
}
#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 */
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 };
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 };
#include "googlemaps.h"
-static DownloadOptions googlemaps_options = { 1 };
+static DownloadOptions googlemaps_options = { 1, "http://maps.google.com/" };
/* initialisation */
void googlemaps_init () {
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)
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;
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;
}
- 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 );
#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
#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 };
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 () {
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 };