TShark doesn't need column text attached to each frame; move col_text

and col_text_len from the frame_data structure to the PacketRecord
structure.

svn path=/trunk/; revision=36967
This commit is contained in:
Guy Harris 2011-05-03 01:19:55 +00:00
parent 11565cd070
commit b42fab3a61
6 changed files with 33 additions and 52 deletions

View File

@ -206,8 +206,6 @@ frame_data_init(frame_data *fdata, guint32 num,
fdata->flags.ref_time = 0;
fdata->flags.ignored = 0;
fdata->color_filter = NULL;
fdata->col_text_len = NULL;
fdata->col_text = NULL;
}
void

View File

@ -63,9 +63,6 @@ typedef struct _frame_data {
nstime_t rel_ts; /**< Relative timestamp (yes, it can be negative) */
nstime_t del_dis_ts; /**< Delta timestamp to previous displayed frame (yes, it can be negative) */
nstime_t del_cap_ts; /**< Delta timestamp to previous captured frame (yes, it can be negative) */
gchar **col_text; /**< The column text for some columns, see colum_utils */
guint *col_text_len; /**< The length of the column text strings in 'col_text' */
} frame_data;
/**

22
file.c
View File

@ -1151,16 +1151,6 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf,
return row;
}
/*
* Initialize the col_text and col_text_len arrays.
*/
static void
init_col_text(frame_data *fdata, gint num_cols)
{
fdata->col_text_len = se_alloc0(sizeof(*fdata->col_text_len) * num_cols);
fdata->col_text = se_alloc0(sizeof(*fdata->col_text) * num_cols);
}
/* read in a new packet */
/* returns the row of the new packet in the packet list or -1 if not displayed */
static int
@ -1181,12 +1171,6 @@ read_packet(capture_file *cf, dfilter_t *dfcode,
framenum = cf->count + 1;
frame_data_init(&fdlocal, framenum, phdr, offset, cum_bytes);
/* Note - if the packet doesn't pass the read filter, and is thus
not added to the capture_file's collection of packets, the
column text arrays aren't free; they're alocated with
se_alloc0(), so they eventually get freed when we close the
file. */
init_col_text(&fdlocal, cf->cinfo.num_cols);
passed = TRUE;
if (cf->rfcode) {
@ -1760,12 +1744,6 @@ rescan_packets(capture_file *cf, const char *action, const char *action_item,
* "init_dissection()"), and null out the GSList pointer. */
fdata->flags.visited = 0;
frame_data_cleanup(fdata);
/* cleanup_dissection() calls se_free_all();
* And after that fdata->col_text (which is allocated using se_alloc0())
* no longer points to valid memory.
*/
init_col_text(fdata, cf->cinfo.num_cols);
}
if (!cf_read_frame(cf, fdata))

View File

@ -1332,13 +1332,13 @@ show_cell_data_func(GtkTreeViewColumn *col _U_, GtkCellRenderer *renderer,
!record->colorized);
}
g_assert(fdata->col_text);
g_assert(record->col_text);
if (col_based_on_frame_data(&cfile.cinfo, col_num)) {
col_fill_in_frame_data(fdata, &cfile.cinfo, col_num, FALSE);
cell_text = cfile.cinfo.col_data[col_num];
}else
cell_text = fdata->col_text[col_num];
cell_text = record->col_text[col_num];
g_assert(cell_text);
@ -1655,7 +1655,7 @@ get_col_text_from_record( PacketListRecord *record, gint col_num, gchar** cell_t
col_fill_in_frame_data(record->fdata, &cfile.cinfo, col_id, FALSE);
*cell_text = g_strdup(cfile.cinfo.col_data[col_id]);
}else
*cell_text = g_strdup(record->fdata->col_text[col_id]);
*cell_text = g_strdup(record->col_text[col_id]);
return TRUE;
}

View File

@ -379,8 +379,8 @@ packet_list_get_value(GtkTreeModel *tree_model, GtkTreeIter *iter, gint column,
g_value_set_pointer(value, record);
break;
case G_TYPE_STRING:
g_return_if_fail(record->fdata->col_text);
g_value_set_string(value, record->fdata->col_text[column]);
g_return_if_fail(record->col_text);
g_value_set_string(value, record->col_text[column]);
break;
default:
g_warning (G_STRLOC ": Unsupported type (%s) retrieved.", g_type_name (value->g_type));
@ -631,6 +631,8 @@ packet_list_append_record(PacketList *packet_list, frame_data *fdata)
newrecord = se_alloc(sizeof(PacketListRecord));
newrecord->columnized = FALSE;
newrecord->colorized = FALSE;
newrecord->col_text_len = se_alloc0(sizeof(*newrecord->col_text_len) * cfile.cinfo.num_cols);
newrecord->col_text = se_alloc0(sizeof(*newrecord->col_text) * cfile.cinfo.num_cols);
newrecord->fdata = fdata;
newrecord->physical_pos = PACKET_LIST_RECORD_COUNT(packet_list->physical_rows);
@ -676,9 +678,9 @@ packet_list_change_record(PacketList *packet_list, guint row, gint col, column_i
g_assert(record->physical_pos == row);
g_assert((record->fdata->col_text != NULL)&&(record->fdata->col_text_len != NULL));
g_assert((record->col_text != NULL)&&(record->col_text_len != NULL));
if (record->fdata->col_text[col] != NULL)
if (record->col_text[col] != NULL)
/* TODO: Column already contains a value. Bail out */
return;
@ -710,8 +712,8 @@ packet_list_change_record(PacketList *packet_list, guint row, gint col, column_i
case COL_FREQ_CHAN:
if (cinfo->col_data[col] && cinfo->col_data[col] != cinfo->col_buf[col]) {
/* This is a constant string, so we don't have to copy it */
record->fdata->col_text[col] = (gchar *) cinfo->col_data[col];
record->fdata->col_text_len[col] = (guint) strlen(record->fdata->col_text[col]);
record->col_text[col] = (gchar *) cinfo->col_data[col];
record->col_text_len[col] = (guint) strlen(record->col_text[col]);
#ifdef NEW_PACKET_LIST_STATISTICS
++packet_list->const_strings;
#endif
@ -720,10 +722,10 @@ packet_list_change_record(PacketList *packet_list, guint row, gint col, column_i
/* !! FALL-THROUGH!! */
default:
record->fdata->col_text_len[col] = (guint) strlen(cinfo->col_data[col]);
record->col_text_len[col] = (guint) strlen(cinfo->col_data[col]);
if (!record->fdata->col_text_len[col]) {
record->fdata->col_text[col] = "";
if (!record->col_text_len[col]) {
record->col_text[col] = "";
#ifdef NEW_PACKET_LIST_STATISTICS
++packet_list->const_strings;
#endif
@ -738,7 +740,7 @@ packet_list_change_record(PacketList *packet_list, guint row, gint col, column_i
} else {
str = g_string_chunk_insert_const (packet_list->string_pool, (const gchar *)cinfo->col_data[col]);
}
record->fdata->col_text[col] = str;
record->col_text[col] = str;
break;
}
}
@ -956,8 +958,8 @@ packet_list_compare_custom(gint sort_id, PacketListRecord *a, PacketListRecord *
(hfi->type == FT_RELATIVE_TIME)))
{
/* Attempt to convert to numbers */
double num_a = atof(a->fdata->col_text[sort_id]);
double num_b = atof(b->fdata->col_text[sort_id]);
double num_a = atof(a->col_text[sort_id]);
double num_b = atof(b->col_text[sort_id]);
if (num_a < num_b)
return -1;
@ -967,25 +969,25 @@ packet_list_compare_custom(gint sort_id, PacketListRecord *a, PacketListRecord *
return frame_data_compare(a->fdata, b->fdata, COL_NUMBER);
}
return strcmp(a->fdata->col_text[sort_id], b->fdata->col_text[sort_id]);
return strcmp(a->col_text[sort_id], b->col_text[sort_id]);
}
static gint
_packet_list_compare_records(gint sort_id, PacketListRecord *a,
PacketListRecord *b)
{
g_assert(a->fdata->col_text);
g_assert(b->fdata->col_text);
g_assert(a->fdata->col_text[sort_id]);
g_assert(b->fdata->col_text[sort_id]);
g_assert(a->col_text);
g_assert(b->col_text);
g_assert(a->col_text[sort_id]);
g_assert(b->col_text[sort_id]);
if(a->fdata->col_text[sort_id] == b->fdata->col_text[sort_id])
if(a->col_text[sort_id] == b->col_text[sort_id])
return 0; /* no need to call strcmp() */
if (cfile.cinfo.col_fmt[sort_id] == COL_CUSTOM) {
return packet_list_compare_custom (sort_id, a, b);
}
return strcmp(a->fdata->col_text[sort_id], b->fdata->col_text[sort_id]);
return strcmp(a->col_text[sort_id], b->col_text[sort_id]);
}
static gint
@ -1331,9 +1333,9 @@ packet_list_get_widest_column_string(PacketList *packet_list, gint col)
for(vis_idx = 0; vis_idx < PACKET_LIST_RECORD_COUNT(packet_list->visible_rows); ++vis_idx) {
record = PACKET_LIST_RECORD_GET(packet_list->visible_rows, vis_idx);
if (record->fdata->col_text_len[col] > widest_column_len) {
widest_column_str = record->fdata->col_text[col];
widest_column_len = record->fdata->col_text_len[col];
if (record->col_text_len[col] > widest_column_len) {
widest_column_str = record->col_text[col];
widest_column_len = record->col_text_len[col];
}
}

View File

@ -61,6 +61,12 @@ struct _PacketListRecord
gboolean columnized;
/** Has this record been colorized? */
gboolean colorized;
/** The column text for some columns */
gchar **col_text;
/**< The length of the column text strings in 'col_text' */
guint *col_text_len;
frame_data *fdata;
/* admin stuff used by the custom list model */