aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk/hostlist_table.c
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2012-04-05 22:10:53 +0000
committerGerald Combs <gerald@wireshark.org>2012-04-05 22:10:53 +0000
commit81334e311aa9d417cbdccda7e48978befc85eae6 (patch)
tree2cf360be85cb03cae2d40196dd41b36966bda639 /ui/gtk/hostlist_table.c
parentae62dc3bdbdda96a73ed5a289c8b579d6024b307 (diff)
Instead of loading our coordinates from a separate text file via
OpenLayers.Layer.Text, insert them into a JSON array and load them using OpenLayers.Layer.Vector + OpenLayers.Format.GeoJSON. This should fix the endpoint map feature on modern browsers. Switch OpenStreetMap to a simpler map from OSGeo. svn path=/trunk/; revision=41967
Diffstat (limited to 'ui/gtk/hostlist_table.c')
-rw-r--r--ui/gtk/hostlist_table.c108
1 files changed, 71 insertions, 37 deletions
diff --git a/ui/gtk/hostlist_table.c b/ui/gtk/hostlist_table.c
index ae691e9438..28ca7f1612 100644
--- a/ui/gtk/hostlist_table.c
+++ b/ui/gtk/hostlist_table.c
@@ -930,7 +930,7 @@ map_handle(GtkTreeModel *model, GtkTreePath *path _U_, GtkTreeIter *iter,
gpointer data)
{
map_t *map = (map_t *)data;
- gchar *table_entry;
+ gchar *table_entry, *esc_entry;
guint64 value;
/* Add the column values to the TSV data */
@@ -947,46 +947,66 @@ map_handle(GtkTreeModel *model, GtkTreePath *path _U_, GtkTreeIter *iter,
return FALSE;
}
- /* Latitude */
- gtk_tree_model_get(model, iter, map->col_lat, &table_entry, -1);
- fputs(table_entry, map->out_file);
- g_free(table_entry);
- fputs("\t", map->out_file);
+/*
+{
+ 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [-122.583889, 37.898889] },
+ 'properties': { 'title': 'host.example.com', 'description': 'AS: AS12345 Ewok Holdings, Inc.<br/>Country: US<br/>City: Muir Woods, CA<br/>Packets: 6<br/>Bytes: 980' }
+},
+ */
+
+ fputs("{\n", map->out_file);
+ fputs(" 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [", map->out_file);
/* Longitude */
gtk_tree_model_get(model, iter, map->col_lon, &table_entry, -1);
fputs(table_entry, map->out_file);
g_free(table_entry);
- fputs("\t", map->out_file);
+ fputs(", ", map->out_file);
+
+ /* Latitude */
+ gtk_tree_model_get(model, iter, map->col_lat, &table_entry, -1);
+ fputs(table_entry, map->out_file);
+ g_free(table_entry);
+ fputs("] },\n", map->out_file);
+
+ fputs(" 'properties': { 'title': '", map->out_file);
/* Title */
gtk_tree_model_get(model, iter, map->col_ip, &table_entry, -1);
- fputs(table_entry, map->out_file);
+ esc_entry = string_replace(table_entry, "'", "&#39;");
+ fputs(esc_entry, map->out_file);
g_free(table_entry);
- fputs("\t", map->out_file);
+ g_free(esc_entry);
+ fputs("', 'description': '", map->out_file);
/* Description */
if (map->col_as_num >= 0) {
gtk_tree_model_get(model, iter, map->col_as_num, &table_entry, -1);
fputs("AS: ", map->out_file);
- fputs(table_entry, map->out_file);
+ esc_entry = string_replace(table_entry, "'", "&#39;");
+ fputs(esc_entry, map->out_file);
g_free(table_entry);
+ g_free(esc_entry);
fputs("<br/>", map->out_file);
}
if (map->col_country >= 0) {
gtk_tree_model_get(model, iter, map->col_country, &table_entry, -1);
fputs("Country: ", map->out_file);
- fputs(table_entry, map->out_file);
+ esc_entry = string_replace(table_entry, "'", "&#39;");
+ fputs(esc_entry, map->out_file);
g_free(table_entry);
+ g_free(esc_entry);
fputs("<br/>", map->out_file);
}
if (map->col_country >= 0) {
gtk_tree_model_get(model, iter, map->col_city, &table_entry, -1);
fputs("City: ", map->out_file);
- fputs(table_entry, map->out_file);
+ esc_entry = string_replace(table_entry, "'", "&#39;");
+ fputs(esc_entry, map->out_file);
g_free(table_entry);
+ g_free(esc_entry);
fputs("<br/>", map->out_file);
}
@@ -994,29 +1014,32 @@ map_handle(GtkTreeModel *model, GtkTreePath *path _U_, GtkTreeIter *iter,
fprintf(map->out_file, "Packets: %" G_GINT64_MODIFIER "u<br/>", value);
gtk_tree_model_get(model, iter, map->col_bytes, &value, -1);
- fprintf(map->out_file, "Bytes: %" G_GINT64_MODIFIER "u\t", value);
+ fprintf(map->out_file, "Bytes: %" G_GINT64_MODIFIER "u", value);
/* XXX - we could add specific icons, e.g. depending on the amount of packets or bytes */
- fputs("\n", map->out_file); /* new row */
+ fputs("' }\n", map->out_file);
+ fputs("},\n", map->out_file); /* XXX - Trim the comma from the last item */
map->hosts_written = TRUE;
return FALSE;
}
+#define MAX_TPL_LINE_LEN 4096
static void
open_as_map_cb(GtkWindow *copy_bt, gpointer data _U_)
{
- guint32 i;
+ guint32 i;
gchar *file_uri;
gboolean uri_open;
- char *map_path, *map_data_filename;
- char *src_file_path;
- char *dst_file_path;
+ char *map_path, *map_filename;
+ char *tpl_filename;
+ char *tpl_line;
GList *columns, *list;
GtkTreeViewColumn *column;
GtkListStore *store;
map_t map;
+ FILE *tpl_file;
map.talkers =g_object_get_data(G_OBJECT(copy_bt), HOST_PTR_KEY);
if (!map.talkers)
@@ -1072,47 +1095,58 @@ open_as_map_cb(GtkWindow *copy_bt, gpointer data _U_)
return;
}
- /* open the TSV output file */
+ /* Create a location map HTML file from a template */
/* XXX - add error handling */
+ tpl_filename = get_datafile_path("ipmap.html");
+ tpl_file = ws_fopen(tpl_filename, "r");
+ if(tpl_file == NULL) {
+ open_failure_alert_box(tpl_filename, errno, FALSE);
+ g_free(tpl_filename);
+ return;
+ }
+ g_free(tpl_filename);
+
+ /* We should probably create a file with a temporary name and a .html extension instead */
if (! create_tempdir(&map_path, "Wireshark IP Map ")) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
"Could not create temporary directory\n%s",
map_path);
return;
}
- map_data_filename = g_strdup_printf("%s%cipmap.txt", map_path, G_DIR_SEPARATOR);
- map.out_file = ws_fopen(map_data_filename, "w");
+
+ map_filename = g_strdup_printf("%s%cipmap.html", map_path, G_DIR_SEPARATOR);
+ map.out_file = ws_fopen(map_filename, "w");
if(map.out_file == NULL) {
- open_failure_alert_box(map_data_filename, errno, TRUE);
+ open_failure_alert_box(map_filename, errno, TRUE);
+ g_free(map_filename);
+ fclose(tpl_file);
return;
}
- fputs("lat\tlon\ttitle\tdescription\t\n", map.out_file);
store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(map.talkers->table)));
- gtk_tree_model_foreach(GTK_TREE_MODEL(store), map_handle, &map);
+ tpl_line = g_malloc(MAX_TPL_LINE_LEN);
+ while (fgets(tpl_line, MAX_TPL_LINE_LEN, tpl_file) != NULL) {
+ fputs(tpl_line, map.out_file);
+ /* MUST match ipmap.html */
+ if (strstr(tpl_line, "// Start endpoint list")) {
+ gtk_tree_model_foreach(GTK_TREE_MODEL(store), map_handle, &map);
+ }
+ }
+ g_free(tpl_line);
+ fclose(tpl_file);
fclose(map.out_file);
if(!map.hosts_written) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No latitude/longitude data found");
+ g_free(map_filename);
return;
}
- /* copy ipmap.html to temp dir */
- src_file_path = get_datafile_path("ipmap.html");
- dst_file_path = g_strdup_printf("%s%cipmap.html", map_path, G_DIR_SEPARATOR);
-
- if (!copy_file_binary_mode(src_file_path, dst_file_path)) {
- g_free(src_file_path);
- g_free(dst_file_path);
- return;
- }
- g_free(src_file_path);
-
/* open the webbrowser */
- file_uri = filename2uri(dst_file_path);
- g_free(dst_file_path);
+ file_uri = filename2uri(map_filename);
+ g_free(map_filename);
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 your web browser", file_uri);