673082e1a81a771903490c7dedf71d4615e03b1e
[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  * $Id$
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 1998 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
27  */
28
29 #include "config.h"
30
31 #include <glib.h>
32 #include <wiretap/wtap.h>
33 #include <epan/proto.h>
34
35 #include <epan/funnel.h>
36 #include <stdio.h>
37 #include <epan/stat_cmd_args.h>
38
39
40 struct _funnel_text_window_t {
41     gchar* title;
42     GString* text;
43 };
44
45 static GPtrArray* text_windows = NULL;
46
47 static funnel_text_window_t* new_text_window(const gchar* title) {
48     funnel_text_window_t* tw = g_new(funnel_text_window_t,1);
49     tw->title = g_strdup(title);
50     tw->text = g_string_new("");
51     
52     if (!text_windows)
53         text_windows = g_ptr_array_new();
54     
55     g_ptr_array_add(text_windows,tw);
56     
57     return tw;
58 }
59
60 static void text_window_clear(funnel_text_window_t*  tw) {
61     g_string_free(tw->text,TRUE);
62     tw->text = g_string_new("");    
63 }
64
65 static void text_window_append(funnel_text_window_t*  tw, const char *text ) {
66     g_string_append(tw->text,text);
67 }
68
69 static void text_window_set_text(funnel_text_window_t*  tw, const char* text) {
70     g_string_free(tw->text,TRUE);
71     tw->text = g_string_new(text);
72 }
73
74 static void text_window_prepend(funnel_text_window_t*  tw, const char *text) {
75     g_string_prepend(tw->text,text);    
76 }
77
78 static const gchar* text_window_get_text(funnel_text_window_t*  tw) {
79     return tw->text->str;
80 }
81
82 /* XXX: finish this */
83 static void funnel_logger(const gchar *log_domain _U_,
84                           GLogLevelFlags log_level _U_,
85                           const gchar *message,
86                           gpointer user_data _U_) {
87     fputs(message,stderr);
88 }
89
90
91
92 static const funnel_ops_t funnel_ops = {
93     new_text_window,
94     text_window_set_text,
95     text_window_append,
96     text_window_prepend,
97     text_window_clear,
98     text_window_get_text,
99     NULL,
100     NULL,
101     NULL,
102     NULL,
103     /*...,*/
104     NULL,
105     funnel_logger,
106     NULL,
107     NULL,
108     NULL,
109     NULL,
110     NULL,
111     NULL,
112     NULL,
113     NULL,
114     NULL,
115     NULL,
116     NULL,
117     NULL,
118     NULL
119 };
120
121
122 void initialize_funnel_ops(void) {
123     funnel_set_funnel_ops(&funnel_ops);
124 }
125
126
127 void funnel_dump_all_text_windows(void) {
128     guint i;
129     
130     if (!text_windows) return;
131     
132     for ( i = 0 ; i < text_windows->len; i++) {
133         funnel_text_window_t*  tw = (funnel_text_window_t*)g_ptr_array_index(text_windows,i);
134         printf("\n========================== %s "
135                "==========================\n%s\n",tw->title,tw->text->str);
136         
137         g_ptr_array_remove_index(text_windows,i);
138         g_free(tw->title);
139         g_string_free(tw->text,TRUE);
140         g_free(tw);        
141     }
142 }
143
144 #if 0
145
146 GHashTable* menus = NULL;
147 typedef struct _menu_cb_t {
148     void (*callback)(gpointer);
149     void* callback_data;
150 } menu_cb_t;
151
152
153 static void  init_funnel_cmd(const char *opt_arg, void* data ) {
154     gchar** args = g_strsplit(opt_arg,",",0); 
155     gchar** arg;
156     menu_cb_t* mcb = data;
157     
158     for(arg = args; *arg ; arg++) {
159         g_strstrip(*arg);
160     }
161     
162     if (mcb->callback) {
163         mcb->callback(mcb->callback_data);
164     }
165     
166 }
167
168 static void register_menu_cb(const char *name,
169                              register_stat_group_t group _U_,
170                              void (*callback)(gpointer),
171                              gpointer callback_data,
172                              gboolean retap _U_) {
173     menu_cb_t* mcb = g_malloc(sizeof(menu_cb_t));
174     
175     mcb->callback = callback;
176     mcb->callback_data = callback_data;
177
178     if (!menus)
179         menus = g_hash_table_new(g_str_hash,g_str_equal);
180
181     g_hash_table_insert(menus,g_strdup(name),mcb);
182     
183     register_stat_cmd_arg(name,init_funnel_cmd,mcb);
184 }
185
186 void initialize_funnel_ops(void) {
187     funnel_set_funnel_ops(&funnel_ops);
188 }
189
190 #endif
191 void
192 register_tap_listener_gtkfunnel(void)
193 {
194 #if 0
195         /* #if 0 at least since Revision Rev 17396 */
196     funnel_register_all_menus(register_menu_cb);
197 #endif
198 }