#define NODES_PER_LEVEL (1<<LOG2_NODES_PER_LEVEL)
typedef struct _capture_file {
+ epan_t *epan;
file_state state; /* Current state of capture file */
gchar *filename; /* Name of capture file */
gchar *source; /* Temp file source, e.g. "Pipe from elsewhere" */
#include "epan_dissect.h"
#include "wsutil/report_err.h"
+#include "epan-int.h"
#include "conversation.h"
#include "circuit.h"
#include "except.h"
wmem_cleanup();
}
+epan_t *
+epan_new(void)
+{
+ epan_t *session = g_slice_new(epan_t);
+
+ /* XXX, it should take session as param */
+ init_dissection();
+
+ return session;
+}
+
+void
+epan_free(epan_t *session)
+{
+ /* XXX, it should take session as param */
+ cleanup_dissection();
+
+ g_slice_free(epan_t, session);
+}
+
void
epan_conversation_init(void)
{
}
epan_dissect_t*
-epan_dissect_init(epan_dissect_t *edt, const gboolean create_proto_tree, const gboolean proto_tree_visible)
+epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
{
g_assert(edt);
+ edt->session = session;
edt->pi.pool = wmem_allocator_new(WMEM_ALLOCATOR_SIMPLE);
if (create_proto_tree) {
}
epan_dissect_t*
-epan_dissect_new(const gboolean create_proto_tree, const gboolean proto_tree_visible)
+epan_dissect_new(epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible)
{
epan_dissect_t *edt;
edt = g_new0(epan_dissect_t, 1);
- return epan_dissect_init(edt, create_proto_tree, proto_tree_visible);
+ return epan_dissect_init(edt, session, create_proto_tree, proto_tree_visible);
}
void
* some protocols cannot be decoded without knowledge of previous packets.
* This inter-packet "state" is stored in the epan_t.
*/
-/* XXX - NOTE: epan_t, epan_new and epan_free are currently unused! */
typedef struct epan_session epan_t;
-epan_t*
-epan_new(void);
+WS_DLL_PUBLIC epan_t *epan_new(void);
-void
-epan_free(epan_t*);
+WS_DLL_PUBLIC void epan_free(epan_t *session);
WS_DLL_PUBLIC const gchar*
epan_get_version(void);
/** initialize an existing single packet dissection */
WS_DLL_PUBLIC
epan_dissect_t*
-epan_dissect_init(epan_dissect_t *edt, const gboolean create_proto_tree, const gboolean proto_tree_visible);
+epan_dissect_init(epan_dissect_t *edt, epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible);
/** get a new single packet dissection
* should be freed using epan_dissect_free() after packet dissection completed
*/
WS_DLL_PUBLIC
epan_dissect_t*
-epan_dissect_new(const gboolean create_proto_tree, const gboolean proto_tree_visible);
+epan_dissect_new(epan_t *session, const gboolean create_proto_tree, const gboolean proto_tree_visible);
/** Indicate whether we should fake protocols or not */
WS_DLL_PUBLIC
* to addresses in your byte array.
*/
struct _epan_dissect_t {
+ struct epan_session *session;
tvbuff_t *tvb;
proto_tree *tree;
packet_info pi;
WS_DLL_PUBLIC void register_init_routine(void (*func)(void));
/* Initialize all data structures used for dissection. */
-WS_DLL_PUBLIC void init_dissection(void);
+void init_dissection(void);
/* Free data structures allocated for dissection. */
-WS_DLL_PUBLIC void cleanup_dissection(void);
+void cleanup_dissection(void);
/* Allow protocols to register a "cleanup" routine to be
* run after the initial sequential run through the packets.
the packets, so we know how much we'll ultimately need. */
buffer_init(&cf->buf, 1500);
- /* Cleanup all data structures used for dissection. */
- cleanup_dissection();
- /* Initialize all data structures used for dissection. */
- init_dissection();
+ /* Create new epan session for dissection. */
+ epan_free(cf->epan);
+ cf->epan = epan_new();
/* We're about to start reading the file. */
cf->state = FILE_READ_IN_PROGRESS;
/* close things, if not already closed before */
color_filters_cleanup();
cf_reset_state(cf);
- cleanup_dissection();
+ epan_free(cf->epan);
+ cf->epan = NULL;
cf_callback_invoke(cf_cb_file_closed, cf);
}
prev_cap = fdata;
/* Dissect the frame. */
- epan_dissect_init(&edt, create_proto_tree, FALSE);
+ epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
if (dfcode != NULL) {
epan_dissect_prime_dfilter(&edt, dfcode);
passed = TRUE;
if (cf->rfcode) {
epan_dissect_t edt;
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, cf->rfcode);
epan_dissect_run(&edt, phdr, frame_tvbuff_new(&fdlocal, buf), &fdlocal, NULL);
passed = dfilter_apply_edt(cf->rfcode, &edt);
want to dissect those before their time. */
cf->redissecting = TRUE;
- /* Cleanup all data structures used for dissection. */
- cleanup_dissection();
- /* Initialize all data structures used for dissection. */
- init_dissection();
+ /* 'reset' dissection session */
+ epan_free(cf->epan);
+ cf->epan = epan_new();
/* We need to redissect the packets so we have to discard our old
* packet list store. */
retap_callback_args_t *args = (retap_callback_args_t *)argsp;
epan_dissect_t edt;
- epan_dissect_init(&edt, args->construct_protocol_tree, FALSE);
+ epan_dissect_init(&edt, cf->epan, args->construct_protocol_tree, FALSE);
epan_dissect_run_with_taps(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, args->cinfo);
epan_dissect_cleanup(&edt);
XXX - do we need it if we're just printing the hex data? */
proto_tree_needed =
args->print_args->print_dissections != print_dissections_none || args->print_args->print_hex || have_custom_cols(&cf->cinfo);
- epan_dissect_init(&edt, proto_tree_needed, proto_tree_needed);
+ epan_dissect_init(&edt, cf->epan, proto_tree_needed, proto_tree_needed);
/* Fill in the column information if we're printing the summary
information. */
epan_dissect_t edt;
/* Create the protocol tree, but don't fill in the column information. */
- epan_dissect_init(&edt, TRUE, TRUE);
+ epan_dissect_init(&edt, cf->epan, TRUE, TRUE);
epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
/* Write out the information in that tree. */
/* Fill in the column information, only create the protocol tree
if having custom columns. */
proto_tree_needed = have_custom_cols(&cf->cinfo);
- epan_dissect_init(&edt, proto_tree_needed, proto_tree_needed);
+ epan_dissect_init(&edt, cf->epan, proto_tree_needed, proto_tree_needed);
col_custom_prime_edt(&edt, &cf->cinfo);
epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
epan_dissect_fill_in_columns(&edt, FALSE, TRUE);
/* Fill in the column information, only create the protocol tree
if having custom columns. */
proto_tree_needed = have_custom_cols(&cf->cinfo);
- epan_dissect_init(&edt, proto_tree_needed, proto_tree_needed);
+ epan_dissect_init(&edt, cf->epan, proto_tree_needed, proto_tree_needed);
col_custom_prime_edt(&edt, &cf->cinfo);
epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, &cf->cinfo);
epan_dissect_fill_in_columns(&edt, FALSE, TRUE);
}
static gboolean
-write_carrays_packet(capture_file *cf _U_, frame_data *fdata,
+write_carrays_packet(capture_file *cf, frame_data *fdata,
struct wtap_pkthdr *phdr,
const guint8 *pd, void *argsp)
{
FILE *fh = (FILE *)argsp;
epan_dissect_t edt;
- epan_dissect_init(&edt, TRUE, TRUE);
+ epan_dissect_init(&edt, cf->epan, TRUE, TRUE);
epan_dissect_run(&edt, phdr, frame_tvbuff_new(fdata, pd), fdata, NULL);
proto_tree_write_carrays(fdata->num, fh, &edt);
epan_dissect_cleanup(&edt);
}
/* Construct the protocol tree, including the displayed text */
- epan_dissect_init(&edt, TRUE, TRUE);
+ epan_dissect_init(&edt, cf->epan, TRUE, TRUE);
/* We don't need the column information */
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
}
/* Don't bother constructing the protocol tree */
- epan_dissect_init(&edt, FALSE, FALSE);
+ epan_dissect_init(&edt, cf->epan, FALSE, FALSE);
/* Get the column information */
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata,
&cf->cinfo);
return MR_ERROR;
}
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED;
old_edt = cf->edt;
/* Create the logical protocol tree. */
/* We don't need the columns here. */
- cf->edt = epan_dissect_new(TRUE, TRUE);
+ cf->edt = epan_dissect_new(cf->epan, TRUE, TRUE);
tap_build_interesting(cf->edt);
epan_dissect_run(cf->edt, &cf->phdr, frame_tvbuff_new_buffer(cf->current_frame, &cf->buf),
return FALSE; /* failure */
/* Dissect the frame tree not visible */
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cfile.epan, TRUE, FALSE);
/* Don't fake protocols. We need them for the protocol hierarchy */
epan_dissect_fake_protocols(&edt, FALSE);
epan_dissect_run(&edt, &phdr, frame_tvbuff_new_buffer(frame, &buf), frame, cinfo);
/* The protocol tree will be "visible", i.e., printed, only if we're
printing packet details, which is true if we're in verbose mode ("verbose"
is true). */
- epan_dissect_init(&edt, create_proto_tree, FALSE);
+ epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
/* If we're running a read filter, prime the epan_dissect_t with that
filter. */
/* The open succeeded. Fill in the information for this file. */
- /* Cleanup all data structures used for dissection. */
- cleanup_dissection();
- /* Initialize all data structures used for dissection. */
- init_dissection();
+ /* Create new epan session for dissection. */
+ epan_free(cf->epan);
+ cf->epan = epan_new();
cf->wth = NULL;
cf->f_datalen = 0; /* not used, but set it anyway */
relinquish_special_privs_perm();
print_current_user();
- /* Cleanup all data structures used for dissection. */
- cleanup_dissection();
- /* Initialize all data structures used for dissection. */
- init_dissection();
+ /* Create new dissection section. */
+ epan_free(cfile.epan);
+ cfile.epan = epan_new();
#ifdef _WIN32
/* Catch a CTRL+C event and, if we get it, clean up and exit. */
/* We're not going to display the protocol tree on this pass,
so it's not going to be "visible". */
- epan_dissect_init(&edt, create_proto_tree, FALSE);
+ epan_dissect_init(&edt, cf->epan, create_proto_tree, FALSE);
/* If we're running a read filter, prime the epan_dissect_t with that
filter. */
printing packet details, which is true if we're printing stuff
("print_packet_info" is true) and we're in verbose mode
("packet_details" is true). */
- epan_dissect_init(&edt, create_proto_tree, print_packet_info && print_details);
+ epan_dissect_init(&edt, cf->epan, create_proto_tree, print_packet_info && print_details);
/* If we're running a display filter, prime the epan_dissect_t with that
filter. */
printing packet details, which is true if we're printing stuff
("print_packet_info" is true) and we're in verbose mode
("packet_details" is true). */
- epan_dissect_init(&edt, create_proto_tree, print_packet_info && print_details);
+ epan_dissect_init(&edt, cf->epan, create_proto_tree, print_packet_info && print_details);
/* If we're running a filter, prime the epan_dissect_t with that
filter. */
/* The open succeeded. Fill in the information for this file. */
- /* Cleanup all data structures used for dissection. */
- cleanup_dissection();
- /* Initialize all data structures used for dissection. */
- init_dissection();
+ /* Create new epan session for dissection. */
+ epan_free(cf->epan);
+ cf->epan = epan_new();
cf->wth = wth;
cf->f_datalen = 0; /* not used, but set it anyway */
/* dissect the current frame */
if (!cf_read_frame(cf, fdata))
return; /* error reading the frame */
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf),
fdata, NULL);
if (!cf_read_frame (&cfile, fdata))
return NULL; /* error reading the frame */
- epan_dissect_init(&edt, FALSE, FALSE);
+ epan_dissect_init(&edt, cfile.epan, FALSE, FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
epan_dissect_run(&edt, &cfile.phdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
if (!cf_read_frame(&cfile, fdata))
return NULL; /* error reading the frame */
/* proto tree, visible. We need a proto tree if there's custom columns */
- epan_dissect_init(&edt, have_custom_cols(&cfile.cinfo), FALSE);
+ epan_dissect_init(&edt, cfile.epan, have_custom_cols(&cfile.cinfo), FALSE);
col_custom_prime_edt(&edt, &cfile.cinfo);
epan_dissect_run(&edt, &cfile.phdr, frame_tvbuff_new_buffer(fdata, &cfile.buf),
create_proto_tree = (dissect_color && color_filters_used()) ||
(dissect_columns && have_custom_cols(cinfo));
- epan_dissect_init(&edt,
+ epan_dissect_init(&edt, cfile.epan,
create_proto_tree,
FALSE /* proto_tree_visible */);
/* Data structure holding information about a packet-detail window. */
struct PacketWinData {
+ epan_t *epan;
frame_data *frame; /* The frame being displayed */
struct wtap_pkthdr phdr; /* Packet header */
guint8 *pd; /* Packet data */
/* XXX, can be optimized? */
proto_tree_draw(NULL, DataPtr->tree_view);
epan_dissect_cleanup(&(DataPtr->edt));
- epan_dissect_init(&(DataPtr->edt), TRUE, TRUE);
+ epan_dissect_init(&(DataPtr->edt), DataPtr->epan, TRUE, TRUE);
epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, frame_tvbuff_new(DataPtr->frame, DataPtr->pd), DataPtr->frame, NULL);
add_byte_views(&(DataPtr->edt), DataPtr->tree_view, DataPtr->bv_nb_ptr);
proto_tree_draw(DataPtr->edt.tree, DataPtr->tree_view);
}
/* redisect */
- epan_dissect_init(&edt, TRUE, TRUE);
+ epan_dissect_init(&edt, DataPtr->epan, TRUE, TRUE);
/* Makes any sense?
if (old_finfo->hfinfo)
proto_tree_prime_hfid(edt.tree, old_finfo->hfinfo->id);
proto_tree_draw(NULL, DataPtr->tree_view);
epan_dissect_cleanup(&(DataPtr->edt));
- epan_dissect_init(&(DataPtr->edt), TRUE, TRUE);
+ epan_dissect_init(&(DataPtr->edt), DataPtr->epan, TRUE, TRUE);
epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, frame_tvbuff_new(DataPtr->frame, DataPtr->pd), DataPtr->frame, NULL);
add_byte_views(&(DataPtr->edt), DataPtr->tree_view, DataPtr->bv_nb_ptr);
proto_tree_draw(DataPtr->edt.tree, DataPtr->tree_view);
/* Allocate data structure to represent this window. */
DataPtr = (struct PacketWinData *) g_malloc(sizeof(struct PacketWinData));
+ /* XXX, protect cfile.epan from closing (ref counting?) */
+ DataPtr->epan = cfile.epan;
DataPtr->frame = fd;
DataPtr->phdr = cfile.phdr;
DataPtr->pd = (guint8 *)g_malloc(DataPtr->frame->cap_len);
memcpy(DataPtr->pd, buffer_start_ptr(&cfile.buf), DataPtr->frame->cap_len);
- epan_dissect_init(&(DataPtr->edt), TRUE, TRUE);
+ epan_dissect_init(&(DataPtr->edt), DataPtr->epan, TRUE, TRUE);
epan_dissect_run(&(DataPtr->edt), &DataPtr->phdr, frame_tvbuff_new(DataPtr->frame, DataPtr->pd),
DataPtr->frame, &cfile.cinfo);
epan_dissect_fill_in_columns(&(DataPtr->edt), FALSE, TRUE);
exit(1);
}
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run_with_taps(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_cleanup(&edt);
/* dissect the current frame */
if (!cf_read_frame(cf, fdata))
return; /* error reading the frame */
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
if (!cf_read_frame(cf, fdata))
return; /* error reading the frame */
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
frame_matched = dfilter_apply_edt(sfcode, &edt);
exit(1);
}
- epan_dissect_init(&edt, TRUE, FALSE);
+ epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_dfilter(&edt, sfcode);
epan_dissect_run_with_taps(&edt, &cf->phdr, frame_tvbuff_new_buffer(fdata, &cf->buf), fdata, NULL);
epan_dissect_cleanup(&edt);
if (!cf_read_frame(cap_file_, fdata))
return filter; /* error reading the frame */
/* proto tree, visible. We need a proto tree if there's custom columns */
- epan_dissect_init(&edt, have_custom_cols(&cap_file_->cinfo), FALSE);
+ epan_dissect_init(&edt, cap_file_->epan, have_custom_cols(&cap_file_->cinfo), FALSE);
col_custom_prime_edt(&edt, &cap_file_->cinfo);
epan_dissect_run(&edt, &cap_file_->phdr, frame_tvbuff_new_buffer(fdata, &cap_file_->buf), fdata, &cap_file_->cinfo);
create_proto_tree = (color_filters_used() && enable_color_) ||
(have_custom_cols(cinfo) && dissect_columns);
- epan_dissect_init(&edt,
+ epan_dissect_init(&edt, cap_file_->epan,
create_proto_tree,
FALSE /* proto_tree_visible */);