Use a unique data file name for our OpenStreetMap data. Print an error
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 14 Jun 2009 22:19:08 +0000 (22:19 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 14 Jun 2009 22:19:08 +0000 (22:19 +0000)
if we don't have data for any hosts. Fixes bug 3530.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@28728 f5534014-38df-0310-8fa8-9805f1628bb7

gtk/hostlist_table.c
ipmap.html

index 0082994b74a1aa5f6dd8646de615a11c75c09e59..1e732d8c49347a13599c78c2e4af884c914a5900 100644 (file)
@@ -51,6 +51,7 @@
 #include "../globals.h"
 #include "../color.h"
 #include "../alert_box.h"
 #include "../globals.h"
 #include "../color.h"
 #include "../alert_box.h"
+#include "../tempfile.h"
 
 #include "gtk/hostlist_table.h"
 #include "gtk/filter_utils.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;
     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;
     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)
 
     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 */
 
     /* 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) {
     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;
     }
         return;
     }
-    g_free(file_path);
 
     fputs("lat\tlon\ttitle\tdescription\t\n", out_file);
 
 
     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 */
         /* 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);
 
     }
 
     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(src_file_path);
-        g_free(dst_file_path);
+        g_string_free(dst_file_path, TRUE);
+        return;
     }
     }
+    g_free(src_file_path);
 
     /* open the webbrowser */
 
     /* 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);
     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);
index c9bae85b4692a09cbc14850186d49f108c0d8e90..e3e6eb7b761429a7f3999f7ee1c3df6ff2c6159d 100644 (file)
             );
 
             map.addLayer(new OpenLayers.Layer.OSM.Mapnik("Mapnik"));
             );
 
             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", {
             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);
 
             var lonlat = (new OpenLayers.LonLat(0.0, 0.0));
             lonlat.transform(map.displayProjection, map.projection);