update epan/dissectors/pidl/drsuapi/drsuapi.idl from samba
[wireshark-sm.git] / epan / filter_expressions.c
bloba9406c555419733469b7179e3d2be51e2b4d9824
1 /* filter_expressions.c
2 * Submitted by Edwin Groothuis <wireshark@mavetju.org>
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
11 #include "config.h"
13 #include <glib.h>
15 #include <epan/prefs.h>
16 #include <epan/uat.h>
17 #include <epan/uat-int.h>
19 #include "epan/filter_expressions.h"
21 /* UAT variables */
22 static uat_t *display_filter_macro_uat;
23 static filter_expression_t *display_filter_macros;
24 static unsigned num_display_filter_macros;
26 /* Field callbacks. */
27 UAT_BOOL_CB_DEF(display_filter_macro_uat, enabled, filter_expression_t)
28 UAT_CSTRING_CB_DEF(display_filter_macro_uat, label, filter_expression_t)
29 UAT_DISPLAY_FILTER_CB_DEF(display_filter_macro_uat, expression, filter_expression_t)
30 UAT_CSTRING_CB_DEF(display_filter_macro_uat, comment, filter_expression_t)
33 * Create a new filter_expression and add it to the end of the list
34 * of filter_expressions.
36 filter_expression_t*
37 filter_expression_new(const char *label, const char *expr,
38 const char *comment, const bool enabled)
40 filter_expression_t expression;
42 // UAT allocates its own memory and then deep-copies this structure in.
43 memset(&expression, 0, sizeof(expression));
44 expression.label = (char *)label;
45 expression.expression = (char *)expr;
46 expression.comment = (char *)comment;
47 expression.enabled = enabled;
49 /* XXX - This is just returned to make GTK GUI work. */
50 return (filter_expression_t*)uat_add_record(display_filter_macro_uat, &expression, true);
53 void filter_expression_iterate_expressions(wmem_foreach_func func, void* user_data)
55 unsigned i;
57 for (i = 0; i < num_display_filter_macros; i++)
59 func(NULL, &display_filter_macros[i], user_data);
63 static void display_filter_free_cb(void*r) {
64 filter_expression_t* rec = (filter_expression_t*)r;
66 g_free(rec->label);
67 g_free(rec->expression);
68 g_free(rec->comment);
71 static void* display_filter_copy_cb(void* n, const void* o, size_t siz _U_) {
72 filter_expression_t* new_record = (filter_expression_t*)n;
73 const filter_expression_t* old_record = (const filter_expression_t*)o;
75 new_record->label = g_strdup(old_record->label);
76 new_record->expression = g_strdup(old_record->expression);
77 new_record->comment = g_strdup(old_record->comment);
79 new_record->enabled = old_record->enabled;
81 return new_record;
84 static uat_field_t display_filter_uat_flds[] = {
85 UAT_FLD_BOOL(display_filter_macro_uat, enabled, "Show in toolbar",
86 "Checked to add display filter button to toolbar"),
87 UAT_FLD_CSTRING(display_filter_macro_uat, label, "Button Label",
88 "Name of the display filter button"),
89 UAT_FLD_DISPLAY_FILTER(display_filter_macro_uat, expression, "Filter Expression",
90 "Filter expression to be applied by the button"),
91 UAT_FLD_CSTRING(display_filter_macro_uat, comment, "Comment",
92 "Comment describing filter expression"),
93 UAT_END_FIELDS
96 void filter_expression_register_uat(module_t* pref_module)
98 display_filter_macro_uat = uat_new("Display expressions",
99 sizeof(filter_expression_t), /* record size */
100 "dfilter_buttons", /* filename */
101 true, /* from_profile */
102 &display_filter_macros, /* data_ptr */
103 &num_display_filter_macros, /* numitems_ptr */
104 0, /* Doesn't not explicitly effect dissection */
105 NULL, /* help */
106 display_filter_copy_cb, /* copy callback */
107 NULL, /* update callback */
108 display_filter_free_cb, /* free callback */
109 NULL, /* post update callback */
110 NULL, /* reset callback */
111 display_filter_uat_flds); /* UAT field definitions */
113 prefs_register_uat_preference(pref_module, "expressions",
114 "Display filter expressions",
115 "Macros for display filters",
116 display_filter_macro_uat);
121 * Editor modelines - https://www.wireshark.org/tools/modelines.html
123 * Local variables:
124 * c-basic-offset: 8
125 * tab-width: 8
126 * indent-tabs-mode: t
127 * End:
129 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
130 * :indentSize=8:tabSize=8:noTabs=false: