From ce3d46b20c917c6ce71d877af6318aef6921cd2d Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sun, 14 Jun 2009 22:19:08 +0000 Subject: Use a unique data file name for our OpenStreetMap data. Print an error if we don't have data for any hosts. Fixes bug 3530. svn path=/trunk/; revision=28728 --- gtk/hostlist_table.c | 58 ++++++++++++++++++++++++++++++++-------------------- ipmap.html | 6 +++++- 2 files changed, 41 insertions(+), 23 deletions(-) diff --git a/gtk/hostlist_table.c b/gtk/hostlist_table.c index 0082994b74..1e732d8c49 100644 --- a/gtk/hostlist_table.c +++ b/gtk/hostlist_table.c @@ -51,6 +51,7 @@ #include "../globals.h" #include "../color.h" #include "../alert_box.h" +#include "../tempfile.h" #include "gtk/hostlist_table.h" #include "gtk/filter_utils.h" @@ -591,10 +592,15 @@ open_as_map_cb(GtkWindow *copy_bt, gpointer data _U_) guint32 i; gchar *table_entry; gint32 col_lat, col_lon, col_country, col_city, col_as_num, col_ip, col_packets, col_bytes; - char *file_path; FILE *out_file; gchar *file_uri; gboolean uri_open; + char map_data_filename[128+1]; + int temp_fd; + char *src_file_path; + char *temp_path; + GString *dst_file_path; + gboolean hosts_written = FALSE; hostlist_table *hosts=g_object_get_data(G_OBJECT(copy_bt), HOST_PTR_KEY); if (!hosts) @@ -638,14 +644,18 @@ open_as_map_cb(GtkWindow *copy_bt, gpointer data _U_) /* open the TSV output file */ /* XXX - add error handling */ - file_path = get_tempfile_path("ipmap.txt"); - out_file = ws_fopen(file_path, "w+b"); + temp_fd = create_tempfile(map_data_filename, sizeof map_data_filename, "ipmap_"); + if(temp_fd == -1) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + "Could not create temporary file %s: %s", + map_data_filename, strerror(errno)); + return; + } + out_file = fdopen(temp_fd, "w"); if(out_file == NULL) { - open_failure_alert_box(file_path, errno, TRUE); - g_free(file_path); + open_failure_alert_box(map_data_filename, errno, TRUE); return; } - g_free(file_path); fputs("lat\tlon\ttitle\tdescription\t\n", out_file); @@ -705,31 +715,35 @@ open_as_map_cb(GtkWindow *copy_bt, gpointer data _U_) /* XXX - we could add specific icons, e.g. depending on the amount of packets or bytes */ fputs("\n", out_file); /* new row */ + hosts_written = TRUE; } fclose(out_file); - /* copy ipmap.html to temp dir */ - { - char * src_file_path; - char * dst_file_path; - - src_file_path = get_datafile_path("ipmap.html"); - dst_file_path = get_tempfile_path("ipmap.html"); + if(!hosts_written) { + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No latitude/longitude data found"); + return; + } - if (!copy_file_binary_mode(src_file_path, dst_file_path)) { - g_free(src_file_path); - g_free(dst_file_path); - return; - } + /* copy ipmap.html to temp dir */ + temp_path = g_strdup(map_data_filename); + get_dirname(temp_path); + src_file_path = get_datafile_path("ipmap.html"); + dst_file_path = g_string_new(""); + g_string_printf(dst_file_path, "%s%cipmap.html", temp_path, G_DIR_SEPARATOR); + g_free(temp_path); + + if (!copy_file_binary_mode(src_file_path, dst_file_path->str)) { g_free(src_file_path); - g_free(dst_file_path); + g_string_free(dst_file_path, TRUE); + return; } + g_free(src_file_path); /* open the webbrowser */ - file_path = get_tempfile_path("ipmap.html"); - file_uri = filename2uri(file_path); - g_free(file_path); + g_string_append_printf(dst_file_path, "#%s", get_basename(map_data_filename)); + file_uri = filename2uri(dst_file_path->str); + g_string_free(dst_file_path, TRUE); uri_open = browser_open_url (file_uri); if(!uri_open) { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't open the file: \"%s\" in the webbrowser", file_uri); diff --git a/ipmap.html b/ipmap.html index c9bae85b46..e3e6eb7b76 100644 --- a/ipmap.html +++ b/ipmap.html @@ -26,8 +26,12 @@ ); map.addLayer(new OpenLayers.Layer.OSM.Mapnik("Mapnik")); + map_file = "ipmap.txt"; + if (document.location.hash.length > 1) { + map_file = document.location.hash.substr(1); + } map.addLayer(new OpenLayers.Layer.Text("IP Locations", { - location: "ipmap.txt", projection: new OpenLayers.Projection("EPSG:4326")} ) ); + location: map_file, projection: new OpenLayers.Projection("EPSG:4326")} ) ); var lonlat = (new OpenLayers.LonLat(0.0, 0.0)); lonlat.transform(map.displayProjection, map.projection); -- cgit v1.2.1