2011-09-08 09:35:10 +00:00
|
|
|
/* filter_expressions.c
|
|
|
|
* Submitted by Edwin Groothuis <wireshark@mavetju.org>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-08 16:59:17 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2011-09-08 09:35:10 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 01:48:30 +00:00
|
|
|
#include "config.h"
|
2011-09-08 09:35:10 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/prefs.h>
|
2017-06-22 15:34:48 +00:00
|
|
|
#include <epan/uat.h>
|
|
|
|
#include <epan/uat-int.h>
|
2011-09-08 09:35:10 +00:00
|
|
|
|
|
|
|
#include "epan/filter_expressions.h"
|
|
|
|
|
2017-06-22 15:34:48 +00:00
|
|
|
/* UAT variables */
|
|
|
|
static uat_t *display_filter_macro_uat = NULL;
|
|
|
|
static filter_expression_t *display_filter_macros = NULL;
|
|
|
|
static guint num_display_filter_macros = 0;
|
|
|
|
|
|
|
|
/* Field callbacks. */
|
|
|
|
UAT_BOOL_CB_DEF(display_filter_macro_uat, enabled, filter_expression_t)
|
|
|
|
UAT_CSTRING_CB_DEF(display_filter_macro_uat, label, filter_expression_t)
|
|
|
|
UAT_DISPLAY_FILTER_CB_DEF(display_filter_macro_uat, expression, filter_expression_t)
|
2017-06-25 15:48:46 +00:00
|
|
|
UAT_CSTRING_CB_DEF(display_filter_macro_uat, comment, filter_expression_t)
|
2011-09-08 09:35:10 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new filter_expression and add it to the end of the list
|
|
|
|
* of filter_expressions.
|
|
|
|
*/
|
2017-06-22 15:34:48 +00:00
|
|
|
filter_expression_t*
|
2011-09-08 09:35:10 +00:00
|
|
|
filter_expression_new(const gchar *label, const gchar *expr,
|
2017-06-25 15:48:46 +00:00
|
|
|
const gchar *comment, const gboolean enabled)
|
2011-09-08 09:35:10 +00:00
|
|
|
{
|
2017-06-22 15:34:48 +00:00
|
|
|
filter_expression_t expression;
|
2011-09-08 09:35:10 +00:00
|
|
|
|
2017-06-22 15:34:48 +00:00
|
|
|
//UAT does the allocation of memory before copying structure
|
|
|
|
memset(&expression, 0, sizeof(expression));
|
|
|
|
expression.label = g_strdup(label);
|
|
|
|
expression.expression = g_strdup(expr);
|
2017-06-25 15:48:46 +00:00
|
|
|
expression.comment = g_strdup(comment);
|
2017-06-22 15:34:48 +00:00
|
|
|
expression.enabled = enabled;
|
|
|
|
|
|
|
|
/* XXX - This is just returned to make GTK GUI work. */
|
|
|
|
return (filter_expression_t*)uat_add_record(display_filter_macro_uat, &expression, TRUE);
|
2011-09-08 09:35:10 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 15:34:48 +00:00
|
|
|
void filter_expression_iterate_expressions(wmem_foreach_func func, void* user_data)
|
2011-09-08 09:35:10 +00:00
|
|
|
{
|
2017-06-22 15:34:48 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; i < num_display_filter_macros; i++)
|
|
|
|
{
|
|
|
|
func(NULL, &display_filter_macros[i], user_data);
|
|
|
|
}
|
2011-09-08 09:35:10 +00:00
|
|
|
}
|
2014-10-10 14:41:10 +00:00
|
|
|
|
2017-06-22 15:34:48 +00:00
|
|
|
static void display_filter_free_cb(void*r) {
|
|
|
|
filter_expression_t* rec = (filter_expression_t*)r;
|
|
|
|
|
|
|
|
g_free(rec->label);
|
|
|
|
g_free(rec->expression);
|
2017-06-25 15:48:46 +00:00
|
|
|
g_free(rec->comment);
|
2017-06-22 15:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void* display_filter_copy_cb(void* n, const void* o, size_t siz _U_) {
|
|
|
|
filter_expression_t* new_record = (filter_expression_t*)n;
|
|
|
|
const filter_expression_t* old_record = (const filter_expression_t*)o;
|
|
|
|
|
|
|
|
new_record->button = old_record->button;
|
|
|
|
new_record->label = g_strdup(old_record->label);
|
|
|
|
new_record->expression = g_strdup(old_record->expression);
|
2017-06-25 15:48:46 +00:00
|
|
|
new_record->comment = g_strdup(old_record->comment);
|
2017-06-22 15:34:48 +00:00
|
|
|
|
|
|
|
new_record->enabled = old_record->enabled;
|
|
|
|
|
|
|
|
return new_record;
|
2015-02-20 21:44:27 +00:00
|
|
|
}
|
|
|
|
|
2017-06-22 15:34:48 +00:00
|
|
|
static uat_field_t display_filter_uat_flds[] = {
|
2017-07-09 19:51:03 +00:00
|
|
|
UAT_FLD_BOOL(display_filter_macro_uat, enabled, "Show in toolbar",
|
2017-06-22 15:34:48 +00:00
|
|
|
"Checked to add display filter button to toolbar"),
|
|
|
|
UAT_FLD_CSTRING(display_filter_macro_uat, label, "Button Label",
|
|
|
|
"Name of the display filter button"),
|
|
|
|
UAT_FLD_DISPLAY_FILTER(display_filter_macro_uat, expression, "Filter Expression",
|
|
|
|
"Filter expression to be applied by the button"),
|
2017-06-25 15:48:46 +00:00
|
|
|
UAT_FLD_CSTRING(display_filter_macro_uat, comment, "Comment",
|
|
|
|
"Comment describing filter expression"),
|
2017-06-22 15:34:48 +00:00
|
|
|
UAT_END_FIELDS
|
|
|
|
};
|
|
|
|
|
|
|
|
void filter_expression_register_uat(module_t* pref_module)
|
|
|
|
{
|
|
|
|
display_filter_macro_uat = uat_new("Display expressions",
|
|
|
|
sizeof(filter_expression_t), /* record size */
|
|
|
|
"dfilter_buttons", /* filename */
|
|
|
|
TRUE, /* from_profile */
|
|
|
|
&display_filter_macros, /* data_ptr */
|
|
|
|
&num_display_filter_macros, /* numitems_ptr */
|
|
|
|
0, /* Doesn't not explicitly effect dissection */
|
|
|
|
NULL, /* help */
|
|
|
|
display_filter_copy_cb, /* copy callback */
|
|
|
|
NULL, /* update callback */
|
|
|
|
display_filter_free_cb, /* free callback */
|
|
|
|
NULL, /* post update callback */
|
|
|
|
NULL, /* reset callback */
|
|
|
|
display_filter_uat_flds); /* UAT field definitions */
|
|
|
|
|
|
|
|
prefs_register_uat_preference(pref_module, "expressions",
|
|
|
|
"Display filter expressions",
|
|
|
|
"Macros for display filters",
|
|
|
|
display_filter_macro_uat);
|
|
|
|
}
|
2015-02-20 21:44:27 +00:00
|
|
|
|
|
|
|
|
2014-10-10 14:41:10 +00:00
|
|
|
/*
|
|
|
|
* Editor modelines - http://www.wireshark.org/tools/modelines.html
|
|
|
|
*
|
|
|
|
* Local variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: t
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* vi: set shiftwidth=8 tabstop=8 noexpandtab:
|
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|