aboutsummaryrefslogtreecommitdiffstats
path: root/ui/gtk
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2016-10-07 16:25:01 -0400
committerMichael Mann <mmann78@netscape.net>2016-10-08 02:44:53 +0000
commit268841f3e00b7cf0f16c81dd2b3b952172130b8b (patch)
tree359e01cf5eba83308760531888713fe0ff0bc10b /ui/gtk
parent11d3224142c0531879fb8e415daf9639a4eace66 (diff)
Combine Decode As and port preferences for tcp.port dissector table.
This patch introduces new APIs to allow dissectors to have a preference for a (TCP) port, but the underlying data is actually part of Decode As functionality. For now the APIs are intentionally separate from the regular APIs that register a dissector within a dissector table. It may be possible to eventually combine the two so that all dissectors that register with a dissector table have an opportunity to "automatically" have a preference to adjust the "table value" through the preferences dialog. The tcp.port dissector table was used as the guinea pig. This will eventually be expanded to other dissector tables as well (most notably UDP ports). Some dissectors that "shared" a TCP/UDP port preference were also converted. It also removed the need for some preference callback functions (mostly when the callback function was the proto_reg_handoff function) so there is cleanup around that. Dissectors that has a port preference whose default was 0 were switched to using the dissector_add_for_decode_as_with_preference API rather than dissector_add_uint_with_preference Also added comments for TCP ports used that aren't IANA registered. Change-Id: I99604f95d426ad345f4b494598d94178b886eb67 Reviewed-on: https://code.wireshark.org/review/17724 Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui/gtk')
-rw-r--r--ui/gtk/decode_as_dlg.c56
-rw-r--r--ui/gtk/main.c1
-rw-r--r--ui/gtk/prefs_dlg.c122
3 files changed, 171 insertions, 8 deletions
diff --git a/ui/gtk/decode_as_dlg.c b/ui/gtk/decode_as_dlg.c
index c38f686cd1..1d9d14780e 100644
--- a/ui/gtk/decode_as_dlg.c
+++ b/ui/gtk/decode_as_dlg.c
@@ -30,6 +30,8 @@
#include <epan/packet.h>
#include <epan/epan_dissect.h>
#include <epan/decode_as.h>
+#include <epan/prefs.h>
+#include <epan/prefs-int.h>
#include <epan/dissectors/packet-dcerpc.h>
#include "ui/decode_as_utils.h"
@@ -648,6 +650,7 @@ decode_simple (GtkWidget *notebook_pg)
gpointer ptr, value_ptr;
gint requested_index = 0;
gboolean add_reset_list = FALSE;
+ dissector_table_t sub_dissectors;
list = (GtkWidget *)g_object_get_data(G_OBJECT(notebook_pg), E_PAGE_LIST);
if (requested_action == E_DECODE_NO)
@@ -655,6 +658,7 @@ decode_simple (GtkWidget *notebook_pg)
entry = (decode_as_t *)g_object_get_data(G_OBJECT(notebook_pg), E_PAGE_DECODE_AS_DATA);
table_name = (gchar *)g_object_get_data(G_OBJECT(notebook_pg), E_PAGE_TABLE);
+ sub_dissectors = find_dissector_table(table_name);
/* (sub)dissector selection */
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(list));
@@ -678,13 +682,65 @@ decode_simple (GtkWidget *notebook_pg)
/* Apply values to dissector table (stored in entry) */
for (value_loop = 0; value_loop < entry->values[requested_index].num_values; value_loop++)
{
+ pref_t* pref_value;
+ dissector_handle_t temp_handle;
+ module_t *module;
+
guint8 saved_curr_layer_num = cfile.edt->pi.curr_layer_num;
cfile.edt->pi.curr_layer_num = (guint8)GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(notebook_pg), E_PAGE_CURR_LAYER_NUM));
value_ptr = entry->values[requested_index].build_values[value_loop](&cfile.edt->pi);
if (abbrev != NULL && strcmp(abbrev, "(default)") == 0) {
+ /* Find the handle currently associated with the value */
+ temp_handle = dissector_get_uint_handle(sub_dissectors, GPOINTER_TO_UINT(value_ptr));
+
add_reset_list = entry->reset_value(table_name, value_ptr);
+
+ /* For now, only numeric dissector tables can use preferences */
+ if (IS_FT_UINT(dissector_table_get_type(sub_dissectors))) {
+ if (temp_handle != NULL) {
+ module = prefs_find_module(proto_get_protocol_filter_name(dissector_handle_get_protocol_index(temp_handle)));
+ pref_value = prefs_find_preference(module, table_name);
+ if (pref_value != NULL) {
+ module->prefs_changed = TRUE;
+ switch(pref_value->type)
+ {
+ case PREF_DECODE_AS_UINT:
+ *pref_value->varp.uint = pref_value->default_val.uint;
+ break;
+ case PREF_DECODE_AS_RANGE:
+ range_remove_value(pref_value->varp.range, GPOINTER_TO_UINT(value_ptr));
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
} else {
add_reset_list = entry->change_value(table_name, value_ptr, &handle, abbrev);
+
+ /* For now, only numeric dissector tables can use preferences */
+ if (IS_FT_UINT(dissector_table_get_type(sub_dissectors))) {
+ module = prefs_find_module(proto_get_protocol_filter_name(dissector_handle_get_protocol_index(handle)));
+ pref_value = prefs_find_preference(module, table_name);
+ if (pref_value != NULL) {
+ module->prefs_changed = TRUE;
+ switch(pref_value->type)
+ {
+ case PREF_DECODE_AS_UINT:
+ /* This doesn't support multiple values for a dissector in Decode As because the
+ preference only supports a single value. This leads to a "last port for
+ dissector in Decode As wins" */
+ *pref_value->varp.uint = GPOINTER_TO_UINT(value_ptr);
+ break;
+ case PREF_DECODE_AS_RANGE:
+ range_add_value(pref_value->varp.range, GPOINTER_TO_UINT(value_ptr));
+ break;
+ default:
+ break;
+ }
+ }
+ }
}
cfile.edt->pi.curr_layer_num = saved_curr_layer_num;
diff --git a/ui/gtk/main.c b/ui/gtk/main.c
index 09ae47147a..6a43426072 100644
--- a/ui/gtk/main.c
+++ b/ui/gtk/main.c
@@ -62,6 +62,7 @@
#include <epan/column.h>
#include <epan/disabled_protos.h>
#include <epan/epan.h>
+#include <epan/decode_as.h>
#include <epan/proto.h>
#include <epan/epan_dissect.h>
#include <epan/dfilter/dfilter.h>
diff --git a/ui/gtk/prefs_dlg.c b/ui/gtk/prefs_dlg.c
index ba5b94c7b0..12ce7c3c37 100644
--- a/ui/gtk/prefs_dlg.c
+++ b/ui/gtk/prefs_dlg.c
@@ -31,6 +31,7 @@
#include <epan/prefs.h>
#include <epan/prefs-int.h>
#include <epan/epan_dissect.h>
+#include <epan/decode_as.h>
#include "ui/preference_utils.h"
@@ -158,6 +159,7 @@ pref_show(pref_t *pref, gpointer user_data)
switch (pref->type) {
case PREF_UINT:
+ case PREF_DECODE_AS_UINT:
/* XXX - there are no uint spinbuttons, so we can't use a spinbutton.
Even more annoyingly, even if there were, GLib doesn't define
G_MAXUINT - but I think ANSI C may define UINT_MAX, so we could
@@ -224,6 +226,7 @@ pref_show(pref_t *pref, gpointer user_data)
break;
case PREF_RANGE:
+ case PREF_DECODE_AS_RANGE:
{
char *range_str_p;
@@ -951,6 +954,7 @@ pref_check(pref_t *pref, gpointer user_data)
switch (pref->type) {
case PREF_UINT:
+ case PREF_DECODE_AS_UINT:
str_val = gtk_entry_get_text(GTK_ENTRY(pref->control));
errno = 0;
@@ -989,6 +993,7 @@ pref_check(pref_t *pref, gpointer user_data)
break;
case PREF_RANGE:
+ case PREF_DECODE_AS_RANGE:
str_val = gtk_entry_get_text(GTK_ENTRY(pref->control));
if (strlen(str_val) != 0) {
@@ -1039,12 +1044,38 @@ pref_fetch(pref_t *pref, gpointer user_data)
guint uval;
gboolean bval;
gint enumval;
- gboolean *pref_changed_p = (gboolean *)user_data;
+ dissector_table_t sub_dissectors;
+ dissector_handle_t handle;
+ module_t *module = (module_t *)user_data;
/* Fetch the value of the preference, and set the appropriate variable
to it. */
switch (pref->type) {
+ case PREF_DECODE_AS_UINT:
+ str_val = gtk_entry_get_text(GTK_ENTRY(pref->control));
+ uval = (guint)strtoul(str_val, &p, pref->info.base);
+#if 0
+ if (p == value || *p != '\0')
+ return PREFS_SET_SYNTAX_ERR; /* number was bad */
+#endif
+ if (*pref->varp.uint != uval) {
+ module->prefs_changed = TRUE;
+ if (*pref->varp.uint != pref->default_val.uint) {
+ dissector_reset_uint(pref->name, *pref->varp.uint);
+ }
+ *pref->varp.uint = uval;
+
+ sub_dissectors = find_dissector_table(pref->name);
+ if (sub_dissectors != NULL) {
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+ if (handle != NULL) {
+ dissector_change_uint(pref->name, *pref->varp.uint, handle);
+ }
+ }
+ }
+ break;
+
case PREF_UINT:
str_val = gtk_entry_get_text(GTK_ENTRY(pref->control));
uval = (guint)strtoul(str_val, &p, pref->info.base);
@@ -1053,7 +1084,7 @@ pref_fetch(pref_t *pref, gpointer user_data)
return PREFS_SET_SYNTAX_ERR; /* number was bad */
#endif
if (*pref->varp.uint != uval) {
- *pref_changed_p = TRUE;
+ module->prefs_changed = TRUE;
*pref->varp.uint = uval;
}
break;
@@ -1061,7 +1092,7 @@ pref_fetch(pref_t *pref, gpointer user_data)
case PREF_BOOL:
bval = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pref->control));
if (*pref->varp.boolp != bval) {
- *pref_changed_p = TRUE;
+ module->prefs_changed = TRUE;
*pref->varp.boolp = bval;
}
break;
@@ -1076,7 +1107,7 @@ pref_fetch(pref_t *pref, gpointer user_data)
}
if (*pref->varp.enump != enumval) {
- *pref_changed_p = TRUE;
+ module->prefs_changed = TRUE;
*pref->varp.enump = enumval;
}
break;
@@ -1085,12 +1116,68 @@ pref_fetch(pref_t *pref, gpointer user_data)
case PREF_FILENAME:
case PREF_DIRNAME:
str_val = gtk_entry_get_text(GTK_ENTRY(pref->control));
- prefs_set_string_like_value(pref, str_val, pref_changed_p);
+ prefs_set_string_like_value(pref, str_val, &module->prefs_changed);
break;
+ case PREF_DECODE_AS_RANGE:
+ {
+ range_t *newrange;
+
+ str_val = gtk_entry_get_text(GTK_ENTRY(pref->control));
+
+ if (range_convert_str_work(&newrange, str_val, pref->info.max_value, TRUE) != CVT_NO_ERROR) {
+#if 0
+ return PREFS_SET_SYNTAX_ERR; /* range was bad */
+#else
+ return 0; /* XXX - should fail */
+#endif
+ }
+
+ if (!ranges_are_equal(*pref->varp.range, newrange)) {
+ guint32 i, j;
+
+ g_free(*pref->varp.range);
+ *pref->varp.range = newrange;
+ module->prefs_changed = TRUE;
+
+ /* Name of preference is the dissector table */
+ sub_dissectors = find_dissector_table(pref->name);
+ if (sub_dissectors != NULL) {
+ handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+ if (handle != NULL) {
+ /* Delete all of the old values from the dissector table */
+ for (i = 0; i < (*pref->varp.range)->nranges; i++) {
+ for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
+ dissector_delete_uint(pref->name, j, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+ }
+
+ dissector_delete_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
+ }
+
+ /* Add new values to the dissector table */
+ for (i = 0; i < newrange->nranges; i++) {
+ for (j = newrange->ranges[i].low; j < newrange->ranges[i].high; j++) {
+ dissector_change_uint(pref->name, j, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+ }
+
+ dissector_change_uint(pref->name, newrange->ranges[i].high, handle);
+ decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(newrange->ranges[i].high), NULL, NULL);
+ }
+ }
+ }
+
+ } else {
+ g_free(newrange);
+ }
+
+ break;
+ }
case PREF_RANGE:
str_val = gtk_entry_get_text(GTK_ENTRY(pref->control));
- if (!prefs_set_range_value(pref, str_val, pref_changed_p))
+ if (!prefs_set_range_value(pref, str_val, &module->prefs_changed))
#if 0
return PREFS_SET_SYNTAX_ERR; /* range was bad */
#else
@@ -1127,7 +1214,7 @@ module_prefs_fetch(module_t *module, gpointer user_data)
/* For all preferences in this module, fetch its value from this
module's notebook page. Find out whether any of them changed. */
module->prefs_changed = FALSE; /* assume none of them changed */
- prefs_pref_foreach(module, pref_fetch, &module->prefs_changed);
+ prefs_pref_foreach(module, pref_fetch, module);
/* If any of them changed, indicate that we must redissect and refilter
the current capture (if we have one), as the preference change
@@ -1374,10 +1461,18 @@ static void prefs_copy(void) {
static void
overwrite_existing_prefs_cb(gpointer dialog _U_, gint btn, gpointer parent_w _U_)
{
+ gchar* err = NULL;
+
switch (btn) {
case(ESD_BTN_SAVE):
prefs_main_write();
prefs.unknown_prefs = FALSE;
+
+ if (save_decode_as_entries(&err) < 0)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err);
+ g_free(err);
+ }
break;
case(ESD_BTN_DONT_SAVE):
break;
@@ -1388,6 +1483,8 @@ overwrite_existing_prefs_cb(gpointer dialog _U_, gint btn, gpointer parent_w _U_
static void
prefs_main_save(gpointer parent_w)
{
+ gchar* err = NULL;
+
if (prefs.unknown_prefs) {
gpointer dialog;
const gchar *msg =
@@ -1408,6 +1505,12 @@ prefs_main_save(gpointer parent_w)
simple_dialog_set_cb(dialog, overwrite_existing_prefs_cb, parent_w);
} else {
prefs_main_write();
+
+ if (save_decode_as_entries(&err) < 0)
+ {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", err);
+ g_free(err);
+ }
}
}
@@ -1523,6 +1626,7 @@ static guint
module_prefs_revert(module_t *module, gpointer user_data)
{
gboolean *must_redissect_p = (gboolean *)user_data;
+ pref_unstash_data_t unstashed_data;
/* Ignore any preferences with their own interface */
if (!module->use_gui) {
@@ -1533,7 +1637,9 @@ module_prefs_revert(module_t *module, gpointer user_data)
it had when we popped up the Preferences dialog. Find out whether
this changes any of them. */
module->prefs_changed = FALSE; /* assume none of them changed */
- prefs_pref_foreach(module, pref_unstash, &module->prefs_changed);
+ unstashed_data.module = module;
+ unstashed_data.handle_decode_as = FALSE;
+ prefs_pref_foreach(module, pref_unstash, &unstashed_data);
/* If any of them changed, indicate that we must redissect and refilter
the current capture (if we have one), as the preference change