1 /*
2 * tap-funnel.c
3 *
4 * EPAN's GUI mini-API
5 *
6 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
7 *
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 */
14
15 #include "config.h"
16
17
18 #include <epan/funnel.h>
19 #include <stdio.h>
20
21 #include "ws_attributes.h"
22
23 #include <wsutil/wslog.h>
24
25 void register_tap_listener_funnel(void);
26
27 struct _funnel_text_window_t {
28 gchar *title;
29 GString *text;
30 };
31
32 static GPtrArray *text_windows = NULL;
33
new_text_window(const gchar * title)34 static funnel_text_window_t *new_text_window(const gchar *title) {
35 funnel_text_window_t *tw = g_new(funnel_text_window_t, 1);
36 tw->title = g_strdup(title);
37 tw->text = g_string_new("");
38
39 if (!text_windows)
40 text_windows = g_ptr_array_new();
41
42 g_ptr_array_add(text_windows, tw);
43
44 return tw;
45 }
46
text_window_clear(funnel_text_window_t * tw)47 static void text_window_clear(funnel_text_window_t *tw) {
48 g_string_free(tw->text, TRUE);
49 tw->text = g_string_new("");
50 }
51
text_window_append(funnel_text_window_t * tw,const char * text)52 static void text_window_append(funnel_text_window_t *tw, const char *text ) {
53 g_string_append(tw->text, text);
54 }
55
text_window_set_text(funnel_text_window_t * tw,const char * text)56 static void text_window_set_text(funnel_text_window_t *tw, const char *text) {
57 g_string_free(tw->text, TRUE);
58 tw->text = g_string_new(text);
59 }
60
text_window_prepend(funnel_text_window_t * tw,const char * text)61 static void text_window_prepend(funnel_text_window_t *tw, const char *text) {
62 g_string_prepend(tw->text, text);
63 }
64
text_window_get_text(funnel_text_window_t * tw)65 static const gchar *text_window_get_text(funnel_text_window_t *tw) {
66 return tw->text->str;
67 }
68
funnel_logger(const gchar * log_domain,enum ws_log_level log_level,const gchar * message,gpointer user_data _U_)69 static void funnel_logger(const gchar *log_domain,
70 enum ws_log_level log_level,
71 const gchar *message,
72 gpointer user_data _U_) {
73 ws_log(log_domain, log_level, "%s", message);
74 }
75
76
77
78 static const funnel_ops_t funnel_ops = {
79 NULL,
80 new_text_window,
81 text_window_set_text,
82 text_window_append,
83 text_window_prepend,
84 text_window_clear,
85 text_window_get_text,
86 NULL,
87 NULL,
88 NULL,
89 NULL,
90 /*...,*/
91 NULL,
92 NULL,
93 funnel_logger,
94 NULL,
95 NULL,
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 NULL,
105 NULL,
106 NULL,
107 NULL,
108 NULL,
109 NULL
110 };
111
112
initialize_funnel_ops(void)113 void initialize_funnel_ops(void) {
114 funnel_set_funnel_ops(&funnel_ops);
115 }
116
117
funnel_dump_all_text_windows(void)118 void funnel_dump_all_text_windows(void) {
119 guint i;
120
121 if (!text_windows) return;
122
123 for ( i = 0 ; i < text_windows->len; i++) {
124 funnel_text_window_t *tw = (funnel_text_window_t *)g_ptr_array_index(text_windows, i);
125 printf("\n========================== %s "
126 "==========================\n%s\n", tw->title, tw->text->str);
127
128 g_ptr_array_remove_index(text_windows, i);
129 g_free(tw->title);
130 g_string_free(tw->text, TRUE);
131 g_free(tw);
132 }
133 }
134
135 #if 0
136
137 GHashTable *menus = NULL;
138 typedef struct _menu_cb_t {
139 void (*callback)(gpointer);
140 void *callback_data;
141 } menu_cb_t;
142
143
144 static void init_funnel_cmd(const char *opt_arg, void *data ) {
145 gchar **args = g_strsplit(opt_arg, ",", 0);
146 gchar **arg;
147 menu_cb_t *mcb = data;
148
149 for (arg = args; *arg ; arg++) {
150 g_strstrip(*arg);
151 }
152
153 if (mcb->callback) {
154 mcb->callback(mcb->callback_data);
155 }
156
157 }
158
159 static void register_menu_cb(const char *name,
160 register_stat_group_t group _U_,
161 void (*callback)(gpointer),
162 gpointer callback_data,
163 gboolean retap _U_) {
164 menu_cb_t* mcb = g_new(menu_cb_t, 1);
165 stat_tap_ui ui_info;
166
167 mcb->callback = callback;
168 mcb->callback_data = callback_data;
169
170 if (!menus)
171 menus = g_hash_table_new(g_str_hash, g_str_equal);
172
173 g_hash_table_insert(menus, g_strdup(name), mcb);
174
175 ui_info.group = REGISTER_STAT_GROUP_GENERIC;
176 ui_info.title = NULL;
177 ui_info.cli_string = name;
178 ui_info.tap_init_cb = init_funnel_cmd;
179 ui_info.nparams = 0;
180 ui_info.params = NULL;
181 register_stat_tap_ui(&ui_info, mcb);
182 }
183
184 void initialize_funnel_ops(void) {
185 funnel_set_funnel_ops(&funnel_ops);
186 }
187
188 #endif
189 void
register_tap_listener_funnel(void)190 register_tap_listener_funnel(void)
191 {
192 #if 0
193 /* #if 0 at least since Revision Rev 17396 */
194 funnel_register_all_menus(register_menu_cb);
195 #endif
196 }
197