More warining fixes: char -> const char
[obnox/wireshark/wip.git] / epan / epan.c
1 /* epan.h
2  *
3  * $Id$
4  *
5  * Ethereal Protocol Analyzer Library
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #include <glib.h>
13 #include "epan.h"
14 #include "epan_dissect.h"
15 #include "report_err.h"
16
17 #include "conversation.h"
18 #include "circuit.h"
19 #include "except.h"
20 #include "packet.h"
21 #include "column-utils.h"
22 #include "tap.h"
23 #include "addr_resolv.h"
24
25 static void (*report_failure_func)(const char *, va_list);
26 static void (*report_open_failure_func)(const char *, int, gboolean);
27 static void (*report_read_failure_func)(const char *, int);
28
29 /*
30  * XXX - this takes the plugin directory as an argument, because
31  * libethereal now has its own configure script and "config.h" file,
32  * which is what code in the "epan" directory includes, but we need
33  * to define PLUGIN_DIR in the top-level directory, as it's used by,
34  * for example, the Makefile for the Gryphon plugin, so it knows
35  * where to install the plugin.
36  *
37  * Eventually, we should probably have an "epan-configure" script
38  * (or "libethereal-configure", or whatever), along the lines of what
39  * GTK+ and GLib have, that can print, among other things, the directory
40  * into which plugins should be installed.  That way, only libethereal
41  * need know what directory that is; programs using it won't, *and*
42  * Makefiles for plugins can just use "epan-configure" to figure out
43  * where to install the plugins.
44  *
45  * (Would that *more* libraries had configure scripts like that, so
46  * that configure scripts didn't have to go through various contortions
47  * to figure out where the header files and libraries for various
48  * libraries are located.)
49  */
50 void
51 epan_init(const char *plugin_dir, void (*register_all_protocols)(void),
52           void (*register_all_handoffs)(void),
53           void (*report_failure)(const char *, va_list),
54           void (*report_open_failure)(const char *, int, gboolean),
55           void (*report_read_failure)(const char *, int))
56 {
57         report_failure_func = report_failure;
58         report_open_failure_func = report_open_failure;
59         report_read_failure_func = report_read_failure;
60         except_init();
61         tvbuff_init();
62         frame_data_init();
63         tap_init();
64         proto_init(plugin_dir,register_all_protocols,register_all_handoffs);
65         packet_init();
66         dfilter_init();
67         final_registration_all_protocols();
68         host_name_lookup_init();
69 }
70
71 void
72 epan_cleanup(void)
73 {
74         dfilter_cleanup();
75         proto_cleanup();
76         packet_cleanup();
77         frame_data_cleanup();
78         tvbuff_cleanup();
79         except_deinit();
80         host_name_lookup_cleanup();
81 }
82
83 void
84 epan_conversation_init(void)
85 {
86         conversation_init();
87 }
88
89 void
90 epan_circuit_init(void)
91 {
92         circuit_init();
93 }
94
95 /*
96  * Report a general error.
97  */
98 void
99 report_failure(const char *msg_format, ...)
100 {
101         va_list ap;
102
103         va_start(ap, msg_format);
104         (*report_failure_func)(msg_format, ap);
105         va_end(ap);
106 }
107
108 /*
109  * Report an error when trying to open or create a file.
110  * "err" is assumed to be an error code from Wiretap; positive values are
111  * UNIX-style errnos, so this can be used for open failures not from
112  * Wiretap as long as the failue code is just an errno.
113  */
114 void
115 report_open_failure(const char *filename, int err,
116     gboolean for_writing)
117 {
118         (*report_open_failure_func)(filename, err, for_writing);
119 }
120
121 /*
122  * Report an error when trying to read a file.
123  * "err" is assumed to be a UNIX-style errno.
124  */
125 void
126 report_read_failure(const char *filename, int err)
127 {
128         (*report_read_failure_func)(filename, err);
129 }
130
131 epan_dissect_t*
132 epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
133 {
134         epan_dissect_t  *edt;
135
136         edt = g_new(epan_dissect_t, 1);
137
138         if (create_proto_tree) {
139                 edt->tree = proto_tree_create_root();
140                 proto_tree_set_visible(edt->tree, proto_tree_visible);
141         }
142         else {
143                 edt->tree = NULL;
144         }
145
146         return edt;
147 }
148
149 void
150 epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
151         const guint8* data, frame_data *fd, column_info *cinfo)
152 {
153         dissect_packet(edt, pseudo_header, data, fd, cinfo);
154 }
155
156
157 void
158 epan_dissect_free(epan_dissect_t* edt)
159 {
160         /* Free the data sources list. */
161         free_data_sources(&edt->pi);
162
163         /* Free all tvb's created from this tvb, unless dissector
164          * wanted to store the pointer (in which case, the dissector
165          * would have incremented the usage count on that tvbuff_t*) */
166         tvb_free_chain(edt->tvb);
167
168         if (edt->tree) {
169                 proto_tree_free(edt->tree);
170         }
171
172         g_free(edt);
173 }
174
175 void
176 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
177 {
178         dfilter_prime_proto_tree(dfcode, edt->tree);
179 }
180
181 void
182 epan_dissect_fill_in_columns(epan_dissect_t *edt)
183 {
184     fill_in_columns(&edt->pi);
185 }