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
#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"
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;
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)
/* 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");
- open_failure_alert_box(file_path, errno, TRUE);
- g_free(file_path);
+ open_failure_alert_box(map_data_filename, errno, TRUE);
fputs("lat\tlon\ttitle\tdescription\t\n", out_file);
fputs("lat\tlon\ttitle\tdescription\t\n", out_file);
/* 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 */
- /* 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_string_free(dst_file_path, TRUE);
+ return;
/* 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);
);
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);