aboutsummaryrefslogtreecommitdiffstats
path: root/epan/epan.c
blob: 20edfb4b42a22bf678bf0e7788eac7d58848979c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* epan.h
 *
 * $Id: epan.c,v 1.14 2001/12/16 22:16:13 guy Exp $
 *
 * Ethereal Protocol Analyzer Library
 *
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <glib.h>
#include <epan.h>

#include "conversation.h"
#include "dfilter/dfilter.h"
#include "except.h"
#include "packet.h"
#include "proto.h"
#include "tvbuff.h"

/*
 * XXX - this takes the plugin directory as an argument, because
 * libethereal now has its own configure script and "config.h" file,
 * which is what code in the "epan" directory includes, but we need
 * to define PLUGIN_DIR in the top-level directory, as it's used by,
 * for example, the Makefile for the Gryphon plugin, so it knows
 * where to install the plugin.
 *
 * Eventually, we should probably have an "epan-configure" script
 * (or "libethereal-configure", or whatever), along the lines of what
 * GTK+ and GLib have, that can print, among other things, the directory
 * into which plugins should be installed.  That way, only libethereal
 * need know what directory that is; programs using it won't, *and*
 * Makefiles for plugins can just use "epan-configure" to figure out
 * where to install the plugins.
 *
 * (Would that *more* libraries had configure scripts like that, so
 * that configure scripts didn't have to go through various contortions
 * to figure out where the header files and libraries for various
 * libraries are located.)
 */
void
epan_init(const char *plugin_dir, void (register_all_protocols)(void),
	  void (register_all_handoffs)(void))
{
	except_init();
	tvbuff_init();
	frame_data_init();
	proto_init(plugin_dir,register_all_protocols,register_all_handoffs);
	packet_init();
	dfilter_init();
}

void
epan_cleanup(void)
{
	dfilter_cleanup();
	proto_cleanup();
	packet_cleanup();
	frame_data_cleanup();
	tvbuff_cleanup();
	except_deinit();
}


void
epan_conversation_init(void)
{
	conversation_init();
}



epan_dissect_t*
epan_dissect_new(void* pseudo_header, const guint8* data, frame_data *fd,
		gboolean create_proto_tree, gboolean proto_tree_visible,
		column_info *cinfo)
{
	epan_dissect_t	*edt;

	edt = g_new(epan_dissect_t, 1);

	/* start with empty data source list */
	if ( fd->data_src)
                g_slist_free( fd->data_src);
        fd->data_src = 0;

	/*
	 * Set the global "proto_tree_is_visible" to control whether
	 * to fill in the text representation field in the protocol
	 * tree fields.
	 */
	proto_tree_is_visible = proto_tree_visible;
	if (create_proto_tree) {
		edt->tree = proto_tree_create_root();
	}
	else {
		edt->tree = NULL;
	}

	dissect_packet(edt, pseudo_header, data, fd, cinfo);

	proto_tree_is_visible = FALSE;

	return edt;
}


void
epan_dissect_free(epan_dissect_t* edt)
{
	/* Free all tvb's created from this tvb, unless dissector
	 * wanted to store the pointer (in which case, the dissector
	 * would have incremented the usage count on that tvbuff_t*) */
	tvb_free_chain(edt->tvb);

	if (edt->tree) {
		proto_tree_free(edt->tree);
	}

	g_free(edt);
}