From Lars Roland: Move timestamp_type into libethereal and provide accessor
[obnox/wireshark/wip.git] / epan / epan.c
1 /* epan.h
2  *
3  * $Id: epan.c,v 1.23 2003/05/04 18:50:53 gerald Exp $
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
16 #include "conversation.h"
17 #include "circuit.h"
18 #include "except.h"
19 #include "packet.h"
20 #include "column-utils.h"
21 #include "../tap.h"
22 #include "resolv.h"
23
24 /*
25  * XXX - this takes the plugin directory as an argument, because
26  * libethereal now has its own configure script and "config.h" file,
27  * which is what code in the "epan" directory includes, but we need
28  * to define PLUGIN_DIR in the top-level directory, as it's used by,
29  * for example, the Makefile for the Gryphon plugin, so it knows
30  * where to install the plugin.
31  *
32  * Eventually, we should probably have an "epan-configure" script
33  * (or "libethereal-configure", or whatever), along the lines of what
34  * GTK+ and GLib have, that can print, among other things, the directory
35  * into which plugins should be installed.  That way, only libethereal
36  * need know what directory that is; programs using it won't, *and*
37  * Makefiles for plugins can just use "epan-configure" to figure out
38  * where to install the plugins.
39  *
40  * (Would that *more* libraries had configure scripts like that, so
41  * that configure scripts didn't have to go through various contortions
42  * to figure out where the header files and libraries for various
43  * libraries are located.)
44  */
45 void
46 epan_init(const char *plugin_dir, void (register_all_protocols)(void),
47           void (register_all_handoffs)(void))
48 {
49         except_init();
50         tvbuff_init();
51         frame_data_init();
52         tap_init();
53         proto_init(plugin_dir,register_all_protocols,register_all_handoffs);
54         packet_init();
55         dfilter_init();
56         final_registration_all_protocols();
57         host_name_lookup_init();
58 }
59
60 void
61 epan_cleanup(void)
62 {
63         dfilter_cleanup();
64         proto_cleanup();
65         packet_cleanup();
66         frame_data_cleanup();
67         tvbuff_cleanup();
68         except_deinit();
69         host_name_lookup_cleanup();
70 }
71
72 void
73 epan_conversation_init(void)
74 {
75         conversation_init();
76 }
77
78 void
79 epan_circuit_init(void)
80 {
81         circuit_init();
82 }
83
84 epan_dissect_t*
85 epan_dissect_new(gboolean create_proto_tree, gboolean proto_tree_visible)
86 {
87         epan_dissect_t  *edt;
88
89         edt = g_new(epan_dissect_t, 1);
90
91         if (create_proto_tree) {
92                 edt->tree = proto_tree_create_root();
93                 proto_tree_set_visible(edt->tree, proto_tree_visible);
94         }
95         else {
96                 edt->tree = NULL;
97         }
98
99         return edt;
100 }
101
102 void
103 epan_dissect_run(epan_dissect_t *edt, void* pseudo_header,
104         const guint8* data, frame_data *fd, column_info *cinfo)
105 {
106         dissect_packet(edt, pseudo_header, data, fd, cinfo);
107 }
108
109
110 void
111 epan_dissect_free(epan_dissect_t* edt)
112 {
113         /* Free the data sources list. */
114         free_data_sources(&edt->pi);
115
116         /* Free all tvb's created from this tvb, unless dissector
117          * wanted to store the pointer (in which case, the dissector
118          * would have incremented the usage count on that tvbuff_t*) */
119         tvb_free_chain(edt->tvb);
120
121         if (edt->tree) {
122                 proto_tree_free(edt->tree);
123         }
124
125         g_free(edt);
126 }
127
128 void
129 epan_dissect_prime_dfilter(epan_dissect_t *edt, const dfilter_t* dfcode)
130 {
131         dfilter_prime_proto_tree(dfcode, edt->tree);
132 }
133
134 void
135 epan_dissect_fill_in_columns(epan_dissect_t *edt)
136 {
137     fill_in_columns(&edt->pi);
138 }