Have editcap and capinfos loading the wiretap plugins.
[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 "column-utils.h"
51 #include "tap.h"
52 #include "addr_resolv.h"
53 #include "oid_resolv.h"
54 #include "emem.h"
55 #include "expert.h"
56
57 #ifdef HAVE_LUA_5_1
58         int wslua_init(void*);
59 #endif
60
61 gchar*
62 epan_get_version(void) {
63   return VERSION;
64 }
65
66 void
67 epan_init(void (*register_all_protocols)(register_cb cb, gpointer client_data),
68           void (*register_all_handoffs)(register_cb cb, gpointer client_data),
69           register_cb cb,
70           gpointer client_data,
71           void (*report_failure)(const char *, va_list),
72           void (*report_open_failure)(const char *, int, gboolean),
73           void (*report_read_failure)(const char *, int))
74 {
75         init_report_err(report_failure, report_open_failure, report_read_failure);
76
77         /* initialize memory allocation subsystem */
78         ep_init_chunk();
79         se_init_chunk();
80
81         /* initialize the GUID to name mapping table */
82         guids_init();
83
84         except_init();
85 #ifdef HAVE_LIBGNUTLS
86         gnutls_global_init();
87 #elif defined(HAVE_LIBGCRYPT)
88         gcry_check_version(NULL);
89 #endif
90         tvbuff_init();
91         oid_resolv_init();
92         tap_init();
93         proto_init(register_all_protocols, register_all_handoffs, cb, client_data);
94         packet_init();
95         dfilter_init();
96         final_registration_all_protocols();
97         host_name_lookup_init();
98         expert_init();
99 #ifdef HAVE_LUA_5_1
100         wslua_init(NULL);
101 #endif
102
103 }
104
105 void
106 epan_cleanup(void)
107 {
108         expert_cleanup();
109         dfilter_cleanup();
110         proto_cleanup();
111         packet_cleanup();
112         oid_resolv_cleanup();
113         tvbuff_cleanup();
114 #ifdef HAVE_LIBGNUTLS
115         gnutls_global_deinit();
116 #endif
117         except_deinit();
118         host_name_lookup_cleanup();
119 }
120
121 void
122 epan_conversation_init(void)
123 {
124         conversation_init();
125 }
126
127 void
128 epan_circuit_init(void)
129 {
130         circuit_init();
131 }
132
133 epan_dissect_t*
134 epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
135 {
136         epan_dissect_t  *edt;
137
138         edt = g_new(epan_dissect_t, 1);
139
140         if (create_proto_tree) {
141                 edt->tree = proto_tree_create_root();
142                 proto_tree_set_visible(edt->tree, proto_tree_visible);
143         }
144         else {
145                 edt->tree = NULL;
146         }
147
148         return edt;
149 }
150
151 void
152 epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
153         const guint8* data, frame_data *fd, column_info *cinfo)
154 {
155         /* free all memory allocated during previous packet */
156         ep_free_all();
157
158         dissect_packet(edt, pseudo_header, data, fd, cinfo);
159 }
160
161
162 void
163 epan_dissect_free(epan_dissect_t* edt)
164 {
165         /* Free the data sources list. */
166         free_data_sources(&edt->pi);
167
168         /* Free all tvb's created from this tvb, unless dissector
169          * wanted to store the pointer (in which case, the dissector
170          * would have incremented the usage count on that tvbuff_t*) */
171         tvb_free_chain(edt->tvb);
172
173         if (edt->tree) {
174                 proto_tree_free(edt->tree);
175         }
176
177         g_free(edt);
178 }
179
180 void
181 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
182 {
183         dfilter_prime_proto_tree(dfcode, edt->tree);
184 }
185
186 void
187 epan_dissect_fill_in_columns(epan_dissect_t *edt)
188 {
189     col_fill_in(&edt->pi);
190 }