Add a routine to report write errors to the list of failure-reporting
[obnox/wireshark/wip.git] / epan / epan.c
1 /* epan.c
2  *
3  * $Id$
4  *
5  * Wireshark Protocol Analyzer Library
6  *
7  * Copyright (c) 2001 by Gerald Combs <gerald@wireshark.org>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #if (defined(HAVE_LIBGCRYPT) || defined(HAVE_LIBGNUTLS)) && defined(_WIN32)
29 #include <winposixtype.h>
30 #endif
31
32 #ifdef HAVE_LIBGCRYPT
33 #include <gcrypt.h>
34 #endif /* HAVE_LIBGCRYPT */
35
36 #ifdef HAVE_LIBGNUTLS
37 #include <gnutls/gnutls.h>
38 #endif /* HAVE_LIBGNUTLS */
39
40
41 #include <glib.h>
42 #include "epan.h"
43 #include "epan_dissect.h"
44 #include "report_err.h"
45
46 #include "conversation.h"
47 #include "circuit.h"
48 #include "except.h"
49 #include "packet.h"
50 #include "prefs.h"
51 #include "column-utils.h"
52 #include "tap.h"
53 #include "addr_resolv.h"
54 #include "oids.h"
55 #include "emem.h"
56 #include "expert.h"
57
58 #ifdef HAVE_LUA_5_1
59         int wslua_init(void*);
60 #endif
61
62 #ifdef HAVE_GEOIP
63 #include "geoip_db.h"
64 #endif
65
66 gchar*
67 epan_get_version(void) {
68   return VERSION;
69 }
70
71 void
72 epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_data),
73           void (*register_all_handoffs_func)(register_cb cb, gpointer client_data),
74           register_cb cb,
75           gpointer client_data,
76           void (*report_failure)(const char *, va_list),
77           void (*report_open_failure)(const char *, int, gboolean),
78           void (*report_read_failure)(const char *, int),
79           void (*report_write_failure)(const char *, int))
80 {
81         init_report_err(report_failure, report_open_failure,
82             report_read_failure, report_write_failure);
83
84         /* initialize memory allocation subsystem */
85         ep_init_chunk();
86         se_init_chunk();
87
88         /* initialize the GUID to name mapping table */
89         guids_init();
90
91         except_init();
92 #ifdef HAVE_LIBGNUTLS
93         gnutls_global_init();
94 #elif defined(HAVE_LIBGCRYPT)
95         gcry_check_version(NULL);
96 #endif
97         tvbuff_init();
98         tap_init();
99         prefs_init();
100         proto_init(register_all_protocols_func, register_all_handoffs_func,
101             cb, client_data);
102         packet_init();
103         dfilter_init();
104         final_registration_all_protocols();
105         host_name_lookup_init();
106         expert_init();
107         oids_init();
108 #ifdef HAVE_LUA_5_1
109         wslua_init(NULL);
110 #endif
111 #ifdef HAVE_GEOIP
112         geoip_db_init();
113 #endif
114
115 }
116
117 void
118 epan_cleanup(void)
119 {
120         se_free_all();
121         expert_cleanup();
122         dfilter_cleanup();
123         proto_cleanup();
124         prefs_cleanup();
125         packet_cleanup();
126         oid_resolv_cleanup();
127         tvbuff_cleanup();
128 #ifdef HAVE_LIBGNUTLS
129         gnutls_global_deinit();
130 #endif
131         except_deinit();
132         host_name_lookup_cleanup();
133 }
134
135 void
136 epan_conversation_init(void)
137 {
138         conversation_init();
139 }
140
141 void
142 epan_circuit_init(void)
143 {
144         circuit_init();
145 }
146
147 epan_dissect_t*
148 epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
149 {
150         epan_dissect_t  *edt;
151
152         edt = g_new(epan_dissect_t, 1);
153
154         if (create_proto_tree) {
155                 edt->tree = proto_tree_create_root();
156                 proto_tree_set_visible(edt->tree, proto_tree_visible);
157         }
158         else {
159                 edt->tree = NULL;
160         }
161
162         return edt;
163 }
164
165 void
166 epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
167         const guint8* data, frame_data *fd, column_info *cinfo)
168 {
169         /* free all memory allocated during previous packet */
170         ep_free_all();
171
172         dissect_packet(edt, pseudo_header, data, fd, cinfo);
173 }
174
175
176 void
177 epan_dissect_free(epan_dissect_t* edt)
178 {
179         /* Free the data sources list. */
180         free_data_sources(&edt->pi);
181
182         /* Free all tvb's created from this tvb, unless dissector
183          * wanted to store the pointer (in which case, the dissector
184          * would have incremented the usage count on that tvbuff_t*) */
185         tvb_free_chain(edt->tvb);
186
187         if (edt->tree) {
188                 proto_tree_free(edt->tree);
189         }
190
191         g_free(edt);
192 }
193
194 void
195 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
196 {
197         dfilter_prime_proto_tree(dfcode, edt->tree);
198 }
199
200 void
201 epan_dissect_fill_in_columns(epan_dissect_t *edt)
202 {
203     col_fill_in(&edt->pi);
204 }