X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/97634600d01c0ebeb23d61fdaf69836b7db9bb90..de2fc9aa9e8db8e0258c8328161c6b5eda176a0a:/src/google.c?ds=sidebyside diff --git a/src/google.c b/src/google.c index 203e67d2..9092d9e0 100644 --- a/src/google.c +++ b/src/google.c @@ -22,6 +22,7 @@ #include "config.h" #endif +#include #include #include #include @@ -45,7 +46,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 = { "http://maps.google.com/", 0 }; +static DownloadOptions google_options = { "http://maps.google.com/", 0, a_check_map_file }; 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 }; @@ -104,19 +105,21 @@ static gchar *parse_version_number(gchar *text) static const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_type) { static gboolean first = TRUE; - static char *vers[] = { "w2.60", "w2t.60", "20", "w2p.60" }; + static char *vers[] = { "w2.80", "w2t.80", "30", "w2p.81"}; FILE *tmp_file; int tmp_fd; gchar *tmpname; gchar *uri; VikCoord coord; + gchar coord_north_south[G_ASCII_DTOSTR_BUF_SIZE], coord_east_west[G_ASCII_DTOSTR_BUF_SIZE]; gchar *text, *pat, *beg; GMappedFile *mf; gsize len; gchar *gvers, *tvers, *kvers, *terrvers, *tmpvers; - static DownloadOptions dl_options = { "http://maps.google.com/", 0 }; - static const char *gvers_pat = "http://mt0.google.com/mt?n\\x3d404\\x26v\\x3d"; - static const char *kvers_pat = "http://kh0.google.com/kh?n\\x3d404\\x26v\\x3d"; + static DownloadOptions dl_options = { "http://maps.google.com/", 0, a_check_map_file }; + /* static const char *gvers_pat = "http://mt0.google.com/mt?v\\x3d"; */ + static const char *gvers_pat = "http://mt0.google.com/mt"; + static const char *kvers_pat = "http://khm0.google.com/kh?v\\x3d"; g_assert(google_type < TYPE_GOOGLE_NUM); @@ -127,26 +130,28 @@ static const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_ first = FALSE; gvers = tvers = kvers = terrvers = NULL; if ((tmp_fd = g_file_open_tmp ("vikgvers.XXXXXX", &tmpname, NULL)) == -1) { - g_critical(_("couldn't open temp file %s\n"), tmpname); + g_critical(_("couldn't open temp file %s"), tmpname); exit(1); } google_mapcoord_to_center_coord(mapcoord, &coord); - uri = g_strdup_printf("http://maps.google.com/maps?f=q&hl=en&q=%f,%f", coord.north_south, coord.east_west); + uri = g_strdup_printf("http://maps.google.com/maps?f=q&hl=en&q=%s,%s", + g_ascii_dtostr (coord_north_south, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) coord.north_south), + g_ascii_dtostr (coord_east_west, G_ASCII_DTOSTR_BUF_SIZE, (gdouble) coord.east_west)); tmp_file = fdopen(tmp_fd, "r+"); if (curl_download_uri(uri, tmp_file, &dl_options)) { /* error */ - g_warning(_("Failed downloading %s\n"), tmpname); + g_warning(_("Failed downloading %s"), tmpname); } else { if ((mf = g_mapped_file_new(tmpname, FALSE, NULL)) == NULL) { - g_critical(_("couldn't map temp file\n")); + g_critical(_("couldn't map temp file")); exit(1); } len = g_mapped_file_get_length(mf); text = g_mapped_file_get_contents(mf); if ((beg = g_strstr_len(text, len, "GLoadApi")) == NULL) { - g_warning(_("Failed fetching Google numbers (\"GLoadApi\" not found)\n")); + g_warning(_("Failed fetching Google numbers (\"GLoadApi\" not found)")); goto failed; } @@ -154,6 +159,11 @@ static const gchar *google_version_number(MapCoord *mapcoord, GoogleType google_ while (!gvers || !tvers ||!terrvers) { if ((pat = g_strstr_len(pat, &text[len] - pat, gvers_pat)) != NULL) { pat += strlen(gvers_pat); + if ((pat[0] != '/' && pat[0] != '?') || + pat[1] != 'v' || pat[2] != '\\' || + pat[3] != 'x' || pat[4] != '3' || pat[5] != 'd') + continue; + pat += 6; if ((tmpvers = parse_version_number(pat)) != NULL) { if (strstr(tmpvers, "t.")) tvers = tmpvers; @@ -193,6 +203,7 @@ failed: } fclose(tmp_file); + tmp_file = NULL; g_free(tmpname); g_free (uri); return (vers[google_type]); @@ -299,7 +310,7 @@ static int google_kh_download ( MapCoord *src, const gchar *dest_fn ) const gchar *vers_str = google_version_number(src, TYPE_GOOGLE_SAT); gchar *uri = g_strdup_printf ( "/kh?n=404&v=%s&t=%s", vers_str, khenc ); g_free ( khenc ); - res = a_http_download_get_url ( "kh.google.com", uri, dest_fn, &google_options ); + res = a_http_download_get_url ( "khm.google.com", uri, dest_fn, &google_options ); g_free ( uri ); return(res); }