carve out the (currently disabled) welcome page into it's own file to slightly reduce...
[obnox/wireshark/wip.git] / 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@gmail.com>
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
27  */
28
29
30 #include <epan/funnel.h>
31 #include <stdio.h>
32 #include <epan/stat_cmd_args.h>
33 #include <epan/ws_strsplit.h>
34
35
36 struct _funnel_text_window_t {
37     gchar* title;
38     GString* text;
39 };
40
41 static GPtrArray* text_windows = NULL;
42
43 static funnel_text_window_t* new_text_window(const gchar* title) {
44     funnel_text_window_t* tw = g_malloc(sizeof(funnel_text_window_t));
45     tw->title = g_strdup(title);
46     tw->text = g_string_new("");
47     
48     if (!text_windows)
49         text_windows = g_ptr_array_new();
50     
51     g_ptr_array_add(text_windows,tw);
52     
53     return tw;
54 }
55
56 static void text_window_clear(funnel_text_window_t*  tw) {
57     g_string_free(tw->text,TRUE);
58     tw->text = g_string_new("");    
59 }
60
61 static void text_window_append(funnel_text_window_t*  tw, const char *text ) {
62     g_string_append(tw->text,text);
63 }
64
65 static void text_window_set_text(funnel_text_window_t*  tw, const char* text) {
66     g_string_free(tw->text,TRUE);
67     tw->text = g_string_new(text);
68 }
69
70 static void text_window_prepend(funnel_text_window_t*  tw, const char *text) {
71     g_string_prepend(tw->text,text);    
72 }
73
74 static const gchar* text_window_get_text(funnel_text_window_t*  tw) {
75     return tw->text->str;
76 }
77
78 /* XXX: finish this */
79 static void funnel_logger(const gchar *log_domain _U_,
80                           GLogLevelFlags log_level _U_,
81                           const gchar *message,
82                           gpointer user_data _U_) {
83     fputs(message,stderr);
84 }
85
86
87
88 static const funnel_ops_t funnel_ops = {
89     new_text_window,
90     text_window_set_text,
91     text_window_append,
92     text_window_prepend,
93     text_window_clear,
94     text_window_get_text,
95     NULL,
96     NULL,
97     NULL,
98     NULL,
99     /*...,*/
100     NULL,
101     funnel_logger,
102     NULL,
103     NULL,
104     NULL,
105     NULL,
106     NULL,
107     NULL,
108         NULL,
109         NULL
110 };
111
112
113 void initialize_funnel_ops(void) {
114     funnel_set_funnel_ops(&funnel_ops);
115 }
116
117
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 = 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 *optarg, void* data ) {
145     gchar** args = g_strsplit(optarg,",",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_malloc(sizeof(menu_cb_t));
165     
166     mcb->callback = callback;
167     mcb->callback_data = callback_data;
168
169     if (!menus)
170         menus = g_hash_table_new(g_str_hash,g_str_equal);
171
172     g_hash_table_insert(menus,g_strdup(name),mcb);
173     
174     register_stat_cmd_arg(name,init_funnel_cmd,mcb);
175 }
176
177 void initialize_funnel_ops(void) {
178     funnel_set_funnel_ops(&funnel_ops);
179 }
180
181 #endif
182 void
183 register_tap_listener_gtkfunnel(void)
184 {
185 #if 0
186     funnel_register_all_menus(register_menu_cb);
187 #endif
188 }