aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2019-04-05 00:23:35 -0700
committerGuy Harris <guy@alum.mit.edu>2019-04-05 08:15:40 +0000
commit9445403f9558901dc54c88754ff21795ea1803f3 (patch)
treea5e826dcb7275201015395e84558eed0032b043c /file.c
parent053cf161734b243f836bed2870c5ea44382e2f52 (diff)
Get rid of the per-capture_file wtap_rec and Buffer.
Most code that reads from a capture_file already has its own wtap_rec and Buffer; change the remaining ones to do so as well. Change-Id: I9b7c136642bbb375848c37ebe23c9cdeffe830c3 Reviewed-on: https://code.wireshark.org/review/32732 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'file.c')
-rw-r--r--file.c165
1 files changed, 91 insertions, 74 deletions
diff --git a/file.c b/file.c
index 1f4b893fb0..1c4995f0cf 100644
--- a/file.c
+++ b/file.c
@@ -81,29 +81,30 @@ typedef enum {
MR_MATCHED,
MR_ERROR
} match_result;
+typedef match_result (*ws_match_function)(capture_file *, frame_data *,
+ wtap_rec *, Buffer *, void *);
static match_result match_protocol_tree(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static void match_subtree_text(proto_node *node, gpointer data);
static match_result match_summary_line(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_narrow_and_wide(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_narrow(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_wide(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_binary(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_regex(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_dfilter(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_marked(capture_file *cf, frame_data *fdata,
- void *criterion);
+ wtap_rec *, Buffer *, void *criterion);
static match_result match_time_reference(capture_file *cf, frame_data *fdata,
- void *criterion);
-static gboolean find_packet(capture_file *cf,
- match_result (*match_function)(capture_file *, frame_data *, void *),
+ wtap_rec *, Buffer *, void *criterion);
+static gboolean find_packet(capture_file *cf, ws_match_function match_function,
void *criterion, search_direction dir);
static void cf_rename_failure_alert_box(const char *filename, int err);
@@ -262,13 +263,6 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp
and fill in the information for this file. */
cf_close(cf);
- /* Initialize the record metadata. */
- wtap_rec_init(&cf->rec);
-
- /* XXX - we really want to initialize this after we've read all
- the packets, so we know how much we'll ultimately need. */
- ws_buffer_init(&cf->buf, 1500);
-
/* We're about to start reading the file. */
cf->state = FILE_READ_IN_PROGRESS;
@@ -385,12 +379,6 @@ cf_close(capture_file *cf)
/* no open_routine type */
cf->open_type = WTAP_TYPE_AUTO;
- /* Clean up the record metadata. */
- wtap_rec_cleanup(&cf->rec);
-
- /* Free up the packet buffer. */
- ws_buffer_free(&cf->buf);
-
dfilter_free(cf->rfcode);
cf->rfcode = NULL;
if (cf->provider.frames != NULL) {
@@ -1578,8 +1566,8 @@ cf_redissect_packets(capture_file *cf)
}
gboolean
-cf_read_record_r(capture_file *cf, const frame_data *fdata,
- wtap_rec *rec, Buffer *buf)
+cf_read_record(capture_file *cf, const frame_data *fdata,
+ wtap_rec *rec, Buffer *buf)
{
int err;
gchar *err_info;
@@ -1591,12 +1579,6 @@ cf_read_record_r(capture_file *cf, const frame_data *fdata,
return TRUE;
}
-gboolean
-cf_read_record(capture_file *cf, frame_data *fdata)
-{
- return cf_read_record_r(cf, fdata, &cf->rec, &cf->buf);
-}
-
/* Rescan the list of packets, reconstructing the CList.
"action" describes why we're doing this; it's used in the progress
@@ -1615,6 +1597,8 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
/* Rescan packets new packet list */
guint32 framenum;
frame_data *fdata;
+ wtap_rec rec;
+ Buffer buf;
progdlg_t *progbar = NULL;
GTimer *prog_timer = g_timer_new();
int count;
@@ -1639,6 +1623,9 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
g_assert(!cf->read_lock);
cf->read_lock = TRUE;
+ wtap_rec_init(&rec);
+ ws_buffer_init(&buf, 1500);
+
/* Compile the current display filter.
* We assume this will not fail since cf->dfilter is only set in
* cf_filter IFF the filter was valid.
@@ -1843,7 +1830,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
/* Frame dependencies from the previous dissection/filtering are no longer valid. */
fdata->dependent_of_displayed = 0;
- if (!cf_read_record(cf, fdata))
+ if (!cf_read_record(cf, fdata, &rec, &buf))
break; /* error reading the frame */
/* If the previous frame is displayed, and we haven't yet seen the
@@ -1855,7 +1842,7 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
}
add_packet_to_packet_list(fdata, cf, &edt, dfcode,
- cinfo, &cf->rec, &cf->buf,
+ cinfo, &rec, &buf,
add_to_packet_list);
/* If this frame is displayed, and this is the first frame we've
@@ -1989,6 +1976,8 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item, gb
redissect = redissect || queued_rescan_type == RESCAN_REDISSECT;
rescan_packets(cf, "Reprocessing", "all packets", redissect);
}
+ wtap_rec_cleanup(&rec);
+ ws_buffer_free(&buf);
}
@@ -2183,7 +2172,7 @@ process_specified_records(capture_file *cf, packet_range_t *range,
}
/* Get the packet */
- if (!cf_read_record_r(cf, fdata, &rec, &buf)) {
+ if (!cf_read_record(cf, fdata, &rec, &buf)) {
/* Attempt to get the packet failed. */
ret = PSP_FAILED;
break;
@@ -3064,13 +3053,14 @@ cf_find_string_protocol_tree(capture_file *cf, proto_tree *tree, match_data *md
}
static match_result
-match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion)
+match_protocol_tree(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion)
{
match_data *mdata = (match_data *)criterion;
epan_dissect_t edt;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
@@ -3078,8 +3068,8 @@ match_protocol_tree(capture_file *cf, frame_data *fdata, void *criterion)
/* Construct the protocol tree, including the displayed text */
epan_dissect_init(&edt, cf->epan, TRUE, TRUE);
/* We don't need the column information */
- epan_dissect_run(&edt, cf->cd_t, &cf->rec,
- frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf),
+ epan_dissect_run(&edt, cf->cd_t, rec,
+ frame_tvbuff_new_buffer(&cf->provider, fdata, buf),
fdata, NULL);
/* Iterate through all the nodes, seeing if they have text that matches. */
@@ -3169,7 +3159,8 @@ cf_find_packet_summary_line(capture_file *cf, const char *string,
}
static match_result
-match_summary_line(capture_file *cf, frame_data *fdata, void *criterion)
+match_summary_line(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion)
{
match_data *mdata = (match_data *)criterion;
const gchar *string = mdata->string;
@@ -3184,7 +3175,7 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion)
size_t c_match = 0;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
@@ -3192,8 +3183,8 @@ match_summary_line(capture_file *cf, frame_data *fdata, void *criterion)
/* Don't bother constructing the protocol tree */
epan_dissect_init(&edt, cf->epan, FALSE, FALSE);
/* Get the column information */
- epan_dissect_run(&edt, cf->cd_t, &cf->rec,
- frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf),
+ epan_dissect_run(&edt, cf->cd_t, rec,
+ frame_tvbuff_new_buffer(&cf->provider, fdata, buf),
fdata, &cf->cinfo);
/* Find the Info column */
@@ -3280,7 +3271,8 @@ cf_find_packet_data(capture_file *cf, const guint8 *string, size_t string_size,
}
static match_result
-match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion)
+match_narrow_and_wide(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion)
{
cbs_t *info = (cbs_t *)criterion;
const guint8 *ascii_text = info->data;
@@ -3293,14 +3285,14 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion)
size_t c_match = 0;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
- pd = ws_buffer_start_ptr(&cf->buf);
+ pd = ws_buffer_start_ptr(buf);
i = 0;
while (i < buf_len) {
c_char = pd[i];
@@ -3329,12 +3321,13 @@ match_narrow_and_wide(capture_file *cf, frame_data *fdata, void *criterion)
}
static match_result
-match_narrow(capture_file *cf, frame_data *fdata, void *criterion)
+match_narrow(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion)
{
- guint8 *pd;
cbs_t *info = (cbs_t *)criterion;
const guint8 *ascii_text = info->data;
size_t textlen = info->data_len;
+ guint8 *pd;
match_result result;
guint32 buf_len;
guint32 i;
@@ -3342,14 +3335,14 @@ match_narrow(capture_file *cf, frame_data *fdata, void *criterion)
size_t c_match = 0;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
- pd = ws_buffer_start_ptr(&cf->buf);
+ pd = ws_buffer_start_ptr(buf);
i = 0;
while (i < buf_len) {
c_char = pd[i];
@@ -3377,7 +3370,8 @@ match_narrow(capture_file *cf, frame_data *fdata, void *criterion)
}
static match_result
-match_wide(capture_file *cf, frame_data *fdata, void *criterion)
+match_wide(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion)
{
cbs_t *info = (cbs_t *)criterion;
const guint8 *ascii_text = info->data;
@@ -3390,14 +3384,14 @@ match_wide(capture_file *cf, frame_data *fdata, void *criterion)
size_t c_match = 0;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
- pd = ws_buffer_start_ptr(&cf->buf);
+ pd = ws_buffer_start_ptr(buf);
i = 0;
while (i < buf_len) {
c_char = pd[i];
@@ -3425,7 +3419,8 @@ match_wide(capture_file *cf, frame_data *fdata, void *criterion)
}
static match_result
-match_binary(capture_file *cf, frame_data *fdata, void *criterion)
+match_binary(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion)
{
cbs_t *info = (cbs_t *)criterion;
const guint8 *binary_data = info->data;
@@ -3437,14 +3432,14 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion)
size_t c_match = 0;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
result = MR_NOTMATCHED;
buf_len = fdata->cap_len;
- pd = ws_buffer_start_ptr(&cf->buf);
+ pd = ws_buffer_start_ptr(buf);
i = 0;
while (i < buf_len) {
if (pd[i] == binary_data[c_match]) {
@@ -3468,18 +3463,19 @@ match_binary(capture_file *cf, frame_data *fdata, void *criterion)
}
static match_result
-match_regex(capture_file *cf, frame_data *fdata, void *criterion _U_)
+match_regex(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion _U_)
{
match_result result = MR_NOTMATCHED;
GMatchInfo *match_info = NULL;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
- if (g_regex_match_full(cf->regex, (const gchar *)ws_buffer_start_ptr(&cf->buf), fdata->cap_len,
+ if (g_regex_match_full(cf->regex, (const gchar *)ws_buffer_start_ptr(buf), fdata->cap_len,
0, (GRegexMatchFlags) 0, &match_info, NULL))
{
gint start_pos = 0, end_pos = 0;
@@ -3525,22 +3521,23 @@ cf_find_packet_dfilter_string(capture_file *cf, const char *filter,
}
static match_result
-match_dfilter(capture_file *cf, frame_data *fdata, void *criterion)
+match_dfilter(capture_file *cf, frame_data *fdata,
+ wtap_rec *rec, Buffer *buf, void *criterion)
{
dfilter_t *sfcode = (dfilter_t *)criterion;
epan_dissect_t edt;
match_result result;
/* Load the frame's data. */
- if (!cf_read_record(cf, fdata)) {
+ if (!cf_read_record(cf, fdata, rec, buf)) {
/* Attempt to get the packet failed. */
return MR_ERROR;
}
epan_dissect_init(&edt, cf->epan, TRUE, FALSE);
epan_dissect_prime_with_dfilter(&edt, sfcode);
- epan_dissect_run(&edt, cf->cd_t, &cf->rec,
- frame_tvbuff_new_buffer(&cf->provider, fdata, &cf->buf),
+ epan_dissect_run(&edt, cf->cd_t, rec,
+ frame_tvbuff_new_buffer(&cf->provider, fdata, buf),
fdata, NULL);
result = dfilter_apply_edt(sfcode, &edt) ? MR_MATCHED : MR_NOTMATCHED;
epan_dissect_cleanup(&edt);
@@ -3554,7 +3551,8 @@ cf_find_packet_marked(capture_file *cf, search_direction dir)
}
static match_result
-match_marked(capture_file *cf _U_, frame_data *fdata, void *criterion _U_)
+match_marked(capture_file *cf _U_, frame_data *fdata, wtap_rec *rec _U_,
+ Buffer *buf _U_, void *criterion _U_)
{
return fdata->marked ? MR_MATCHED : MR_NOTMATCHED;
}
@@ -3566,20 +3564,22 @@ cf_find_packet_time_reference(capture_file *cf, search_direction dir)
}
static match_result
-match_time_reference(capture_file *cf _U_, frame_data *fdata, void *criterion _U_)
+match_time_reference(capture_file *cf _U_, frame_data *fdata, wtap_rec *rec _U_,
+ Buffer *buf _U_, void *criterion _U_)
{
return fdata->ref_time ? MR_MATCHED : MR_NOTMATCHED;
}
static gboolean
-find_packet(capture_file *cf,
- match_result (*match_function)(capture_file *, frame_data *, void *),
+find_packet(capture_file *cf, ws_match_function match_function,
void *criterion, search_direction dir)
{
frame_data *start_fd;
guint32 framenum;
guint32 prev_framenum;
frame_data *fdata;
+ wtap_rec rec;
+ Buffer buf;
frame_data *new_fd = NULL;
progdlg_t *progbar = NULL;
GTimer *prog_timer = g_timer_new();
@@ -3591,6 +3591,9 @@ find_packet(capture_file *cf,
const char *title;
match_result result;
+ wtap_rec_init(&rec);
+ ws_buffer_init(&buf, 1500);
+
start_fd = cf->current_frame;
if (start_fd != NULL) {
prev_framenum = start_fd->num;
@@ -3691,7 +3694,7 @@ find_packet(capture_file *cf,
/* Is this packet in the display? */
if (fdata && fdata->passed_dfilter) {
/* Yes. Does it match the search criterion? */
- result = (*match_function)(cf, fdata, criterion);
+ result = (*match_function)(cf, fdata, &rec, &buf, criterion);
if (result == MR_ERROR) {
/* Error; our caller has reported the error. Go back to the frame
where we started. */
@@ -3731,11 +3734,18 @@ find_packet(capture_file *cf,
simple_message_box(ESD_TYPE_INFO, NULL,
"The capture file is probably not fully dissected.",
"End of capture exceeded.");
+ wtap_rec_cleanup(&rec);
+ ws_buffer_free(&buf);
return FALSE;
}
+ wtap_rec_cleanup(&rec);
+ ws_buffer_free(&buf);
return TRUE; /* success */
- } else
+ } else {
+ wtap_rec_cleanup(&rec);
+ ws_buffer_free(&buf);
return FALSE; /* failure */
+ }
}
gboolean
@@ -3803,6 +3813,8 @@ cf_select_packet(capture_file *cf, int row)
{
epan_dissect_t *old_edt;
frame_data *fdata;
+ wtap_rec rec;
+ Buffer buf;
/* Get the frame data struct pointer for this frame */
fdata = packet_list_get_row_data(row);
@@ -3811,8 +3823,11 @@ cf_select_packet(capture_file *cf, int row)
return;
}
+ wtap_rec_init(&rec);
+ ws_buffer_init(&buf, 1500);
+
/* Get the data in that frame. */
- if (!cf_read_record (cf, fdata)) {
+ if (!cf_read_record (cf, fdata, &rec, &buf)) {
return;
}
@@ -3826,8 +3841,8 @@ cf_select_packet(capture_file *cf, int row)
cf->edt = epan_dissect_new(cf->epan, TRUE, TRUE);
tap_build_interesting(cf->edt);
- epan_dissect_run(cf->edt, cf->cd_t, &cf->rec,
- frame_tvbuff_new_buffer(&cf->provider, cf->current_frame, &cf->buf),
+ epan_dissect_run(cf->edt, cf->cd_t, &rec,
+ frame_tvbuff_new_buffer(&cf->provider, cf->current_frame, &buf),
cf->current_frame, NULL);
dfilter_macro_build_ftv_cache(cf->edt->tree);
@@ -3835,6 +3850,8 @@ cf_select_packet(capture_file *cf, int row)
if (old_edt != NULL)
epan_dissect_free(old_edt);
+ wtap_rec_cleanup(&rec);
+ ws_buffer_free(&buf);
}
/* Unselect the selected packet, if any. */
@@ -3980,7 +3997,7 @@ cf_get_packet_comment(capture_file *cf, const frame_data *fd)
wtap_rec_init(&rec);
ws_buffer_init(&buf, 1500);
- if (!cf_read_record_r(cf, fd, &rec, &buf))
+ if (!cf_read_record(cf, fd, &rec, &buf))
{ /* XXX, what we can do here? */ }
/* rec.opt_comment is owned by the record, copy it before it is gone. */