1 /* packet_list_record.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "packet_list_record.h"
26 #include <epan/epan_dissect.h>
27 #include <epan/column-info.h>
28 #include <epan/column.h>
31 #include "color_filters.h"
32 #include "frame_tvbuff.h"
34 #include <QStringList>
36 QMap<int, int> cinfo_column_;
38 PacketListRecord::PacketListRecord(frame_data *frameData) :
40 // columnized_(false),
45 QVariant PacketListRecord::columnString(capture_file *cap_file, int column)
47 // packet_list_store.c:packet_list_get_value
50 if (!cap_file || column < 0 || column > cap_file->cinfo.num_cols) {
54 if (column >= col_text_.size() || col_text_[column].isNull() || !colorized_) {
55 dissect(cap_file, !colorized_);
58 return col_text_.value(column, QByteArray());
61 frame_data *PacketListRecord::frameData() {
65 void PacketListRecord::resetColumns(column_info *cinfo)
71 cinfo_column_.clear();
73 for (i = 0, j = 0; i < cinfo->num_cols; i++) {
74 if (!col_based_on_frame_data(cinfo, i)) {
81 void PacketListRecord::dissect(capture_file *cap_file, bool dissect_color)
83 // packet_list_store.c:packet_list_dissect_and_cache_record
85 column_info *cinfo = NULL;
86 gboolean create_proto_tree;
87 struct wtap_pkthdr phdr; /* Packet header */
88 Buffer buf; /* Packet data */
89 gboolean dissect_columns = col_text_.isEmpty();
95 memset(&phdr, 0, sizeof(struct wtap_pkthdr));
97 if (dissect_columns) {
98 cinfo = &cap_file->cinfo;
101 ws_buffer_init(&buf, 1500);
102 if (!cf_read_record_r(cap_file, fdata_, &phdr, &buf)) {
104 * Error reading the record.
106 * Don't set the color filter for now (we might want
107 * to colorize it in some fashion to warn that the
108 * row couldn't be filled in or colorized), and
109 * set the columns to placeholder values, except
110 * for the Info column, where we'll put in an
113 if (dissect_columns) {
114 col_fill_in_error(cinfo, fdata_, FALSE, FALSE /* fill_fd_columns */);
116 cacheColumnStrings(cinfo);
119 fdata_->color_filter = NULL;
122 ws_buffer_free(&buf);
123 return; /* error reading the record */
126 create_proto_tree = (dissect_color && color_filters_used()) ||
127 (dissect_columns && have_custom_cols(cinfo));
129 epan_dissect_init(&edt, cap_file->epan,
131 FALSE /* proto_tree_visible */);
134 color_filters_prime_edt(&edt);
136 col_custom_prime_edt(&edt, cinfo);
139 * XXX - need to catch an OutOfMemoryError exception and
140 * attempt to recover from it.
142 epan_dissect_run(&edt, cap_file->cd_t, &phdr, frame_tvbuff_new_buffer(fdata_, &buf), fdata_, cinfo);
145 fdata_->color_filter = color_filters_colorize_packet(&edt);
147 if (dissect_columns) {
148 /* "Stringify" non frame_data vals */
149 epan_dissect_fill_in_columns(&edt, FALSE, FALSE /* fill_fd_columns */);
150 cacheColumnStrings(cinfo);
157 epan_dissect_cleanup(&edt);
158 ws_buffer_free(&buf);
161 //#define MINIMIZE_STRING_COPYING 1
162 void PacketListRecord::cacheColumnStrings(column_info *cinfo)
164 // packet_list_store.c:packet_list_change_record(PacketList *packet_list, PacketListRecord *record, gint col, column_info *cinfo)
171 for (int column = 0; column < cinfo->num_cols; ++column) {
173 #ifdef MINIMIZE_STRING_COPYING
174 int text_col = cinfo_column_.value(column, -1);
176 /* Column based on frame_data or it already contains a value */
178 col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
179 col_text_.append(cinfo->col_data[column]);
183 switch (cinfo->col_fmt[column]) {
185 case COL_RES_SRC: /* COL_DEF_SRC is currently just like COL_RES_SRC */
189 case COL_UNRES_DL_SRC:
190 case COL_DEF_NET_SRC:
191 case COL_RES_NET_SRC:
192 case COL_UNRES_NET_SRC:
194 case COL_RES_DST: /* COL_DEF_DST is currently just like COL_RES_DST */
198 case COL_UNRES_DL_DST:
199 case COL_DEF_NET_DST:
200 case COL_RES_NET_DST:
201 case COL_UNRES_NET_DST:
206 case COL_8021Q_VLAN_ID:
209 if (cinfo->col_data[column] && cinfo->col_data[column] != cinfo->col_buf[column]) {
210 /* This is a constant string, so we don't have to copy it */
211 // XXX - ui/gtk/packet_list_store.c uses G_MAXUSHORT. We don't do proper UTF8
212 // truncation in either case.
213 int col_text_len = MIN(qstrlen(cinfo->col_data[column]) + 1, COL_MAX_INFO_LEN);
214 col_text_.append(QByteArray::fromRawData(cinfo->col_data[column], col_text_len));
217 /* !! FALL-THROUGH!! */
220 if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
221 /* Use the unresolved value in col_expr_val */
222 // XXX Use QContiguousCache?
223 col_text_.append(cinfo->col_expr.col_expr_val[column]);
225 col_text_.append(cinfo->col_data[column]);
229 #else // MINIMIZE_STRING_COPYING
230 // XXX Use QContiguousCache?
231 if (!get_column_resolved(column) && cinfo->col_expr.col_expr_val[column]) {
232 /* Use the unresolved value in col_expr_val */
233 col_text_.append(cinfo->col_expr.col_expr_val[column]);
235 int text_col = cinfo_column_.value(column, -1);
238 col_fill_in_frame_data(fdata_, cinfo, column, FALSE);
240 col_text_.append(cinfo->col_data[column]);
242 #endif // MINIMIZE_STRING_COPYING
252 * indent-tabs-mode: nil
255 * ex: set shiftwidth=4 tabstop=8 expandtab:
256 * :indentSize=4:tabSize=8:noTabs=true: