aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrbroker <rstbroker@gmail.com>2020-06-18 19:43:20 +0100
committerAnders Broman <a.broman58@gmail.com>2020-06-25 08:02:27 +0000
commit1f75d7b3b9fa5d489d0d4816fe7dd491d5a617d7 (patch)
tree39377641720d441b86b17c697ee09e4322d8ef07
parentc7f74a94fb96be83a9d098f59c3d157ea0e5aec4 (diff)
wslua: Add ability to query current temporary color filter text
The LUA API provides the "set_color_filter_slot" function, but without a corresponding "get_" function, it's very hard for two LUA dissectors to co-exist without one overwriting any color filters set by the other. It also looks like the documentation comment for "set_color_filter_slot" had an off-by-one error, which I've corrected as I was adding almost identical documentation for the new API. Change-Id: Ic54d23be555ec12e1830bbe6f84a1b04d04fd4f0 Reviewed-on: https://code.wireshark.org/review/37511 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--debian/libwireshark0.symbols1
-rw-r--r--epan/color_filters.c23
-rw-r--r--epan/color_filters.h8
-rw-r--r--epan/funnel.h3
-rw-r--r--epan/wslua/wslua_gui.c64
-rw-r--r--ui/cli/tap-funnel.c1
-rw-r--r--ui/qt/funnel_statistics.cpp6
7 files changed, 94 insertions, 12 deletions
diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols
index c1eead9326..600a6711c4 100644
--- a/debian/libwireshark0.symbols
+++ b/debian/libwireshark0.symbols
@@ -137,6 +137,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
color_filters_clone@Base 2.1.0
color_filters_colorize_packet@Base 2.1.0
color_filters_export@Base 2.1.0
+ color_filters_get_tmp@Base 3.3.0
color_filters_import@Base 2.1.0
color_filters_init@Base 2.1.0
color_filters_prime_edt@Base 2.1.0
diff --git a/epan/color_filters.c b/epan/color_filters.c
index cb5586529c..8dfd8c2e32 100644
--- a/epan/color_filters.c
+++ b/epan/color_filters.c
@@ -119,6 +119,29 @@ color_filters_find_by_name_cb(gconstpointer arg1, gconstpointer arg2)
return strcmp(colorf->filter_name, name);
}
+/* Get the filter of a temporary color filter */
+gchar*
+color_filters_get_tmp(guint8 filt_nr)
+{
+ gchar* name = NULL;
+ gchar* filter = NULL;
+ GSList* cfl;
+ color_filter_t* colorf;
+ /* Only perform a lookup if the supplied filter number is in the expected range */
+ if (filt_nr < 1 || filt_nr > 10)
+ return NULL;
+
+ name = g_strdup_printf("%s%02d", CONVERSATION_COLOR_PREFIX, filt_nr);
+ cfl = g_slist_find_custom(color_filter_list, name, color_filters_find_by_name_cb);
+ colorf = (color_filter_t*)cfl->data;
+
+ if (!colorf->disabled)
+ filter = g_strdup(colorf->filter_text);
+
+ g_free(name);
+
+ return filter;
+}
/* Set the filter off a temporary colorfilters and enable it */
gboolean
diff --git a/epan/color_filters.h b/epan/color_filters.h
index 092de7af68..873b85508f 100644
--- a/epan/color_filters.h
+++ b/epan/color_filters.h
@@ -70,6 +70,14 @@ WS_DLL_PUBLIC gboolean color_filters_used(void);
*/
WS_DLL_PUBLIC gboolean tmp_color_filters_used(void);
+/** Get the filter string of a temporary color filter
+ *
+ * @param filt_nr a number 1-10 pointing to a temporary color
+ * @return the current filter string which is assigned to the specified slot, or NULL if not available.
+ */
+WS_DLL_PUBLIC gchar*
+color_filters_get_tmp(guint8 filt_nr);
+
/** Set the filter string of a temporary color filter
*
* @param filt_nr a number 1-10 pointing to a temporary color
diff --git a/epan/funnel.h b/epan/funnel.h
index 534a5baa8c..0953b9f6f6 100644
--- a/epan/funnel.h
+++ b/epan/funnel.h
@@ -80,7 +80,8 @@ typedef struct _funnel_ops_t {
const gchar * (*get_filter)(funnel_ops_id_t *ops_id);
void (*set_filter)(funnel_ops_id_t *ops_id, const char* filter);
- void (*set_color_filter_slot)(guint8 flit_nr, const gchar* filter);
+ gchar * (*get_color_filter_slot)(guint8 filt_nr);
+ void (*set_color_filter_slot)(guint8 filt_nr, const gchar* filter);
gboolean (*open_file)(funnel_ops_id_t *ops_id, const char* fname, const char* filter, char** error);
void (*reload_packets)(funnel_ops_id_t *ops_id);
void (*reload_lua_plugins)(funnel_ops_id_t *ops_id);
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c
index fd6f5ff96e..17d72070c2 100644
--- a/epan/wslua/wslua_gui.c
+++ b/epan/wslua/wslua_gui.c
@@ -929,13 +929,55 @@ WSLUA_FUNCTION wslua_set_filter(lua_State* L) { /* Set the main filter text. */
return 0;
}
+WSLUA_FUNCTION wslua_get_color_filter_slot(lua_State* L) { /*
+ Gets the current https://wiki.wireshark.org/ColoringRules[packet coloring rule] (by index) for the
+ current session. Wireshark reserves 10 slots for these coloring rules. Requires a GUI.
+*/
+#define WSLUA_ARG_get_color_filter_slot_ROW 1 /*
+ The index (1-10) of the desired color filter value in the temporary coloring rules list.
+
+ .Default background colors
+ [cols="3",options="header"]
+ |===
+ |Index |RGB (hex) |Color
+ |1 |ffc0c0 |{set:cellbgcolor:#ffc0c0} pink 1
+ |2 |ffc0ff |{set:cellbgcolor:#ffc0ff} pink 2
+ |3 |e0c0e0 |{set:cellbgcolor:#e0c0e0} purple 1
+ |4 |c0c0ff |{set:cellbgcolor:#c0c0ff} purple 2
+ |5 |c0e0e0 |{set:cellbgcolor:#c0e0e0} green 1
+ |6 |c0ffff |{set:cellbgcolor:#c0ffff} green 2
+ |7 |c0ffc0 |{set:cellbgcolor:#c0ffc0} green 3
+ |8 |ffffc0 |{set:cellbgcolor:#ffffc0} yellow 1
+ |9 |e0e0c0 |{set:cellbgcolor:#e0e0c0} yellow 2
+ |10 |e0e0e0 |{set:cellbgcolor:#e0e0e0} gray
+ |===
+ */
+ guint8 row = (guint8)luaL_checkinteger(L, WSLUA_ARG_get_color_filter_slot_ROW);
+ gchar* filter_str = NULL;
+
+ if (!ops->get_color_filter_slot) {
+ WSLUA_ERROR(get_color_filter_slot, "GUI not available");
+ return 0;
+ }
+
+ filter_str = ops->get_color_filter_slot(row);
+ if (filter_str == NULL) {
+ lua_pushnil(L);
+ } else {
+ lua_pushstring(L, filter_str);
+ g_free(filter_str);
+ }
+
+ return 1;
+}
+
WSLUA_FUNCTION wslua_set_color_filter_slot(lua_State* L) { /*
Sets a https://wiki.wireshark.org/ColoringRules[packet coloring rule] (by index) for the current session.
Wireshark reserves 10 slots for these coloring rules.
Requires a GUI.
*/
#define WSLUA_ARG_set_color_filter_slot_ROW 1 /*
- The index (0-9) of the desired color in the temporary coloring rules list.
+ The index (1-10) of the desired color in the temporary coloring rules list.
The default foreground is black and the default backgrounds are listed below.
// XXX We need get the colors working, e.g. by adding them to a stylesheet.
@@ -943,16 +985,16 @@ WSLUA_FUNCTION wslua_set_color_filter_slot(lua_State* L) { /*
[cols="3",options="header"]
|===
|Index |RGB (hex) |Color
- |0 |ffc0c0 |{set:cellbgcolor:#ffc0c0} pink 1
- |1 |ffc0ff |{set:cellbgcolor:#ffc0ff} pink 2
- |2 |e0c0e0 |{set:cellbgcolor:#e0c0e0} purple 1
- |3 |c0c0ff |{set:cellbgcolor:#c0c0ff} purple 2
- |4 |c0e0e0 |{set:cellbgcolor:#c0e0e0} green 1
- |5 |c0ffff |{set:cellbgcolor:#c0ffff} green 2
- |6 |c0ffc0 |{set:cellbgcolor:#c0ffc0} green 3
- |7 |ffffc0 |{set:cellbgcolor:#ffffc0} yellow 1
- |8 |e0e0c0 |{set:cellbgcolor:#e0e0c0} yellow 2
- |9 |e0e0e0 |{set:cellbgcolor:#e0e0e0} gray
+ |1 |ffc0c0 |{set:cellbgcolor:#ffc0c0} pink 1
+ |2 |ffc0ff |{set:cellbgcolor:#ffc0ff} pink 2
+ |3 |e0c0e0 |{set:cellbgcolor:#e0c0e0} purple 1
+ |4 |c0c0ff |{set:cellbgcolor:#c0c0ff} purple 2
+ |5 |c0e0e0 |{set:cellbgcolor:#c0e0e0} green 1
+ |6 |c0ffff |{set:cellbgcolor:#c0ffff} green 2
+ |7 |c0ffc0 |{set:cellbgcolor:#c0ffc0} green 3
+ |8 |ffffc0 |{set:cellbgcolor:#ffffc0} yellow 1
+ |9 |e0e0c0 |{set:cellbgcolor:#e0e0c0} yellow 2
+ |10 |e0e0e0 |{set:cellbgcolor:#e0e0e0} gray
|===
The color list can be set from the command line using two unofficial preferences: `gui.colorized_frame.bg` and `gui.colorized_frame.fg`, which require 10 hex RGB codes (6 hex digits each), e.g.
diff --git a/ui/cli/tap-funnel.c b/ui/cli/tap-funnel.c
index 0b24096f8c..0171abaa8b 100644
--- a/ui/cli/tap-funnel.c
+++ b/ui/cli/tap-funnel.c
@@ -103,6 +103,7 @@ static const funnel_ops_t funnel_ops = {
NULL,
NULL,
NULL,
+ NULL,
NULL
};
diff --git a/ui/qt/funnel_statistics.cpp b/ui/qt/funnel_statistics.cpp
index cc9dbc0156..c7f67e600a 100644
--- a/ui/qt/funnel_statistics.cpp
+++ b/ui/qt/funnel_statistics.cpp
@@ -42,6 +42,7 @@ static void funnel_statistics_retap_packets(funnel_ops_id_t *ops_id);
static void funnel_statistics_copy_to_clipboard(GString *text);
static const gchar *funnel_statistics_get_filter(funnel_ops_id_t *ops_id);
static void funnel_statistics_set_filter(funnel_ops_id_t *ops_id, const char* filter_string);
+static gchar* funnel_statistics_get_color_filter_slot(guint8 filter_num);
static void funnel_statistics_set_color_filter_slot(guint8 filter_num, const gchar* filter_string);
static gboolean funnel_statistics_open_file(funnel_ops_id_t *ops_id, const char* fname, const char* filter, char**);
static void funnel_statistics_reload_packets(funnel_ops_id_t *ops_id);
@@ -130,6 +131,7 @@ FunnelStatistics::FunnelStatistics(QObject *parent, CaptureFile &cf) :
funnel_ops_->copy_to_clipboard = funnel_statistics_copy_to_clipboard;
funnel_ops_->get_filter = funnel_statistics_get_filter;
funnel_ops_->set_filter = funnel_statistics_set_filter;
+ funnel_ops_->get_color_filter_slot = funnel_statistics_get_color_filter_slot;
funnel_ops_->set_color_filter_slot = funnel_statistics_set_color_filter_slot;
funnel_ops_->open_file = funnel_statistics_open_file;
funnel_ops_->reload_packets = funnel_statistics_reload_packets;
@@ -241,6 +243,10 @@ void funnel_statistics_set_filter(funnel_ops_id_t *ops_id, const char* filter_st
ops_id->funnel_statistics->emitSetDisplayFilter(filter_string);
}
+gchar* funnel_statistics_get_color_filter_slot(guint8 filter_num) {
+ return color_filters_get_tmp(filter_num);
+}
+
void funnel_statistics_set_color_filter_slot(guint8 filter_num, const gchar* filter_string) {
gchar *err_msg = nullptr;
if (!color_filters_set_tmp(filter_num, filter_string, FALSE, &err_msg)) {