HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / ui / cli / tap-funnel.c
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 void register_tap_listener_funnel(void);
24
25 struct _funnel_text_window_t {
26     gchar *title;
27     GString *text;
28 };
29
30 static GPtrArray *text_windows = NULL;
31
32 static funnel_text_window_t *new_text_window(const gchar *title) {
33     funnel_text_window_t *tw = g_new(funnel_text_window_t, 1);
34     tw->title = g_strdup(title);
35     tw->text = g_string_new("");
36
37     if (!text_windows)
38         text_windows = g_ptr_array_new();
39
40     g_ptr_array_add(text_windows, tw);
41
42     return tw;
43 }
44
45 static void text_window_clear(funnel_text_window_t *tw) {
46     g_string_free(tw->text, TRUE);
47     tw->text = g_string_new("");
48 }
49
50 static void text_window_append(funnel_text_window_t *tw, const char *text ) {
51     g_string_append(tw->text, text);
52 }
53
54 static void text_window_set_text(funnel_text_window_t *tw, const char *text) {
55     g_string_free(tw->text, TRUE);
56     tw->text = g_string_new(text);
57 }
58
59 static void text_window_prepend(funnel_text_window_t *tw, const char *text) {
60     g_string_prepend(tw->text, text);
61 }
62
63 static const gchar *text_window_get_text(funnel_text_window_t *tw) {
64     return tw->text->str;
65 }
66
67 /* XXX: finish this */
68 static void funnel_logger(const gchar *log_domain _U_,
69                           GLogLevelFlags log_level _U_,
70                           const gchar *message,
71                           gpointer user_data _U_) {
72     fputs(message, stderr);
73 }
74
75
76
77 static const funnel_ops_t funnel_ops = {
78     NULL,
79     new_text_window,
80     text_window_set_text,
81     text_window_append,
82     text_window_prepend,
83     text_window_clear,
84     text_window_get_text,
85     NULL,
86     NULL,
87     NULL,
88     NULL,
89     /*...,*/
90     NULL,
91     NULL,
92     funnel_logger,
93     NULL,
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 };
108
109
110 void initialize_funnel_ops(void) {
111     funnel_set_funnel_ops(&funnel_ops);
112 }
113
114
115 void funnel_dump_all_text_windows(void) {
116     guint i;
117
118     if (!text_windows) return;
119
120     for ( i = 0 ; i < text_windows->len; i++) {
121         funnel_text_window_t *tw = (funnel_text_window_t *)g_ptr_array_index(text_windows, i);
122         printf("\n========================== %s "
123                "==========================\n%s\n", tw->title, tw->text->str);
124
125         g_ptr_array_remove_index(text_windows, i);
126         g_free(tw->title);
127         g_string_free(tw->text, TRUE);
128         g_free(tw);
129     }
130 }
131
132 #if 0
133
134 GHashTable *menus = NULL;
135 typedef struct _menu_cb_t {
136     void (*callback)(gpointer);
137     void *callback_data;
138 } menu_cb_t;
139
140
141 static void  init_funnel_cmd(const char *opt_arg, void *data ) {
142     gchar **args = g_strsplit(opt_arg, ",", 0);
143     gchar **arg;
144     menu_cb_t *mcb = data;
145
146     for (arg = args; *arg ; arg++) {
147         g_strstrip(*arg);
148     }
149
150     if (mcb->callback) {
151         mcb->callback(mcb->callback_data);
152     }
153
154 }
155
156 static void register_menu_cb(const char *name,
157                              register_stat_group_t group _U_,
158                              void (*callback)(gpointer),
159                              gpointer callback_data,
160                              gboolean retap _U_) {
161     menu_cb_t *mcb = g_malloc(sizeof(menu_cb_t));
162     stat_tap_ui ui_info;
163
164     mcb->callback = callback;
165     mcb->callback_data = callback_data;
166
167     if (!menus)
168         menus = g_hash_table_new(g_str_hash, g_str_equal);
169
170     g_hash_table_insert(menus, g_strdup(name), mcb);
171
172     ui_info.group = REGISTER_STAT_GROUP_GENERIC;
173     ui_info.title = NULL;
174     ui_info.cli_string = name;
175     ui_info.tap_init_cb = init_funnel_cmd;
176     ui_info.nparams = 0;
177     ui_info.params = NULL;
178     register_stat_tap_ui(&ui_info, mcb);
179 }
180
181 void initialize_funnel_ops(void) {
182     funnel_set_funnel_ops(&funnel_ops);
183 }
184
185 #endif
186 void
187 register_tap_listener_funnel(void)
188 {
189 #if 0
190     /* #if 0 at least since Revision Rev 17396 */
191     funnel_register_all_menus(register_menu_cb);
192 #endif
193 }
194
195 /*
196  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
197  *
198  * Local variables:
199  * c-basic-offset: 4
200  * tab-width: 8
201  * indent-tabs-mode: nil
202  * End:
203  *
204  * vi: set shiftwidth=4 tabstop=8 expandtab:
205  * :indentSize=4:tabSize=8:noTabs=true:
206  */