ssl,dtls: use ProtocolVersion from Server Hello
[metze/wireshark/wip.git] / epan / funnel.c
1 /*
2  *  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  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <epan/funnel.h>
30
31 typedef struct _funnel_menu_t {
32     const char *name;
33     register_stat_group_t group;
34     funnel_menu_callback callback;
35     gpointer callback_data;
36     gboolean retap;
37     struct _funnel_menu_t* next;
38 } funnel_menu_t;
39
40 /* XXX This assumes one main window and one capture file. */
41 static const funnel_ops_t* ops = NULL;
42 static funnel_menu_t* registered_menus = NULL;
43 static funnel_menu_t* added_menus = NULL;
44 static funnel_menu_t* removed_menus = NULL;
45 static gboolean menus_registered = FALSE;
46
47 const funnel_ops_t* funnel_get_funnel_ops(void) { return ops;  }
48 void funnel_set_funnel_ops(const funnel_ops_t* o) { ops = o; }
49
50 static void funnel_insert_menu (funnel_menu_t** menu_list, funnel_menu_t *menu)
51 {
52     if (!(*menu_list))  {
53         *menu_list = menu;
54     } else {
55         funnel_menu_t* c;
56         for (c = *menu_list; c->next; c = c->next);
57         c->next = menu;
58     }
59 }
60
61 static void funnel_remove_menu (funnel_menu_t ** menu_list, funnel_menu_t *menu)
62 {
63     funnel_menu_t *m = *menu_list, *p = NULL;
64
65     while (m) {
66         if (m->callback == menu->callback) {
67             if (p) {
68                 p->next = m->next;
69             } else {
70                 *menu_list = m->next;
71             }
72             g_free((char *)m->name);
73             g_free(m);
74             if (p) {
75                 m = p->next;
76             } else {
77                 m = *menu_list ? (*menu_list)->next : NULL;
78             }
79         } else {
80             p = m;
81             m = m->next;
82         }
83     }
84 }
85
86 static void funnel_clear_menu (funnel_menu_t** menu_list)
87 {
88     funnel_menu_t *m;
89
90     while (*menu_list) {
91         m = *menu_list;
92         *menu_list = m->next;
93         g_free((char *)m->name);
94         g_free(m);
95     }
96     *menu_list = NULL;
97 }
98
99 void funnel_register_menu(const char *name,
100                           register_stat_group_t group,
101                           funnel_menu_callback callback,
102                           gpointer callback_data,
103                           gboolean retap)
104 {
105     funnel_menu_t* m = (funnel_menu_t *)g_malloc(sizeof(funnel_menu_t));
106     m->name = g_strdup(name);
107     m->group = group;
108     m->callback = callback;
109     m->callback_data = callback_data;
110     m->retap = retap;
111     m->next = NULL;
112
113     funnel_insert_menu(&registered_menus, m);
114     if (menus_registered) {
115         funnel_menu_t* m_r = (funnel_menu_t *)g_memdup(m, sizeof *m);
116         m_r->name = g_strdup(name);
117         funnel_insert_menu(&added_menus, m_r);
118     }
119 }
120
121 void funnel_deregister_menus(funnel_menu_callback callback)
122 {
123     funnel_menu_t* m = (funnel_menu_t *)g_malloc0(sizeof(funnel_menu_t));
124     m->callback = callback;
125
126     funnel_remove_menu(&registered_menus, m);
127     funnel_insert_menu(&removed_menus, m);
128 }
129
130 void funnel_register_all_menus(funnel_registration_cb_t r_cb)
131 {
132     funnel_menu_t* c;
133     for (c = registered_menus; c; c = c->next) {
134         r_cb(c->name,c->group,c->callback,c->callback_data,c->retap);
135     }
136     menus_registered = TRUE;
137 }
138
139 void funnel_reload_menus(funnel_deregistration_cb_t d_cb,
140                          funnel_registration_cb_t r_cb)
141 {
142     funnel_menu_t* c;
143     for (c = removed_menus; c; c = c->next) {
144         d_cb(c->callback);
145     }
146     for (c = added_menus; c; c = c->next) {
147         r_cb(c->name,c->group,c->callback,c->callback_data,c->retap);
148     }
149
150     funnel_clear_menu(&removed_menus);
151     funnel_clear_menu(&added_menus);
152 }
153
154 /*
155  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
156  *
157  * Local variables:
158  * c-basic-offset: 4
159  * tab-width: 8
160  * indent-tabs-mode: nil
161  * End:
162  *
163  * vi: set shiftwidth=4 tabstop=8 expandtab:
164  * :indentSize=4:tabSize=8:noTabs=true:
165  */