3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef ATAP_DATA_MODEL_H
11 #define ATAP_DATA_MODEL_H
16 #include <epan/conversation.h>
17 #include <epan/conversation_table.h>
19 #include <QAbstractListModel>
22 * @brief DataModel for tap user data
24 * This datamodel provides the management for all tap data for the conversation
25 * and endpoint dialogs. It predominantly is implemented to work with conversation
26 * tap data. The management of displaying and correctly presenting the information
27 * is done in the corresponding type classes
29 * @see EndpointDataModel
30 * @see ConversationDataModel
32 class ATapDataModel
: public QAbstractListModel
38 DISPLAY_FILTER
= Qt::UserRole
,
39 UNFORMATTED_DISPLAYDATA
,
57 DATAMODEL_CONVERSATION
,
64 * @brief Construct a new ATapDataModel object
66 * The tap will not be created automatically, but must be enabled by calling enableTap
68 * @param type an element of dataModelType. Either DATAMODEL_ENDPOINT or DATAMODEL_CONVERSATION are supported
70 * @param protoId the protocol id for which the tap is created
71 * @param filter a potential filter to be used for the tap
72 * @param parent the parent for the class
76 explicit ATapDataModel(dataModelType type
, int protoId
, QString filter
, QObject
*parent
= nullptr);
77 virtual ~ATapDataModel();
80 * @brief Number of rows under the given parent in this model, which
81 * is the total number of rows for the empty QModelIndex, and 0 for
82 * any valid parent index (as no row has children; this is a flat table.)
84 * @param parent index of parent, QModelIndex() for the root
85 * @return int the number of rows under the parent
87 int rowCount(const QModelIndex
&parent
= QModelIndex()) const;
89 virtual int columnCount(const QModelIndex
&parent
= QModelIndex()) const = 0;
90 virtual QVariant
headerData(int section
, Qt::Orientation orientation
= Qt::Horizontal
, int role
= Qt::DisplayRole
) const = 0;
91 virtual QVariant
data(const QModelIndex
&idx
, int role
= Qt::DisplayRole
) const = 0;
94 * @brief Returns the name for the tap being used
96 * @return QString the tap name, normally identical with the protocol name
101 * @brief The protocol id for the tap
103 * @return int the id given in the constructor
108 * @brief Set the filter string.
110 * A set filter can be reset by providing an empty string
112 * @param filter the filter for the tap
114 void setFilter(QString filter
);
117 * @brief Return a filter set for the model
119 * @return QString the filter string for the model
121 QString
filter() const;
124 * @brief Is the model set to resolve names in address and ports columns
126 * @return true yes, names will be resolved
127 * @return false no they won't
129 bool resolveNames() const;
132 * @brief Enable or disable if names should be resolved
134 * @param resolve true if names should be resolved
136 void setResolveNames(bool resolve
);
139 * @brief Does the model allow names to be resolved
141 * @return true yes, names may be resolved (set via setResolveNames)
142 * @return false no, they won't be resolved
144 * @see setResolveNames
147 bool allowsNameResolution() const;
150 * @brief Use absolute time for any column supporting it
152 * @param absolute true to use absolute time values
154 void useAbsoluteTime(bool absolute
);
157 * @brief Use nanosecond timestamps if requested
159 * @param nanoseconds use nanosecond timestamps if required and requested
161 void useNanosecondTimestamps(bool nanoseconds
);
164 * @brief Are ports hidden for this model
166 * @return true the ports are hidden
167 * @return false the ports are not hidden
169 bool portsAreHidden() const;
172 * @brief A total column is filled
174 * @return true if the column is filled
175 * @return false the column is empty
177 bool showTotalColumn() const;
180 * @brief Enable tapping in this model.
182 * This will register the tap listener with the corresponding packet function.
183 * @note if the tap has not been disabled, this method will do nothing
185 * @return true the tap has been enabled
186 * @return false the tap has not been enabled
191 * @brief Disable the tapping for this model
196 * @brief Return the model type
198 * @return dataModelType
200 dataModelType
modelType() const;
202 conv_hash_t
* hash();
205 * @brief Update the flags
207 void updateFlags(unsigned flag
);
209 #ifdef HAVE_MAXMINDDB
211 * @brief Does this model have geoip data available
213 * @return true it has
214 * @return false it has not
220 void tapListenerChanged(bool enable
);
224 static void tapReset(void *tapdata
);
225 static void tapDraw(void *tap_data
);
227 virtual tap_packet_cb
conversationPacketHandler();
230 void updateData(GArray
* data
);
241 double _minRelStartTime
;
242 double _maxRelStopTime
;
246 register_ct_t
* registerTable() const;
253 class EndpointDataModel
: public ATapDataModel
264 ENDP_COLUMN_PACKETS_TOTAL
,
265 ENDP_COLUMN_BYTES_TOTAL
,
267 ENDP_COLUMN_BYTES_AB
,
269 ENDP_COLUMN_BYTES_BA
,
271 ENDP_COLUMN_GEO_COUNTRY
= ENDP_NUM_COLUMNS
,
272 ENDP_COLUMN_GEO_CITY
,
273 ENDP_COLUMN_GEO_LATITUDE
,
274 ENDP_COLUMN_GEO_LONGITUDE
,
275 ENDP_COLUMN_GEO_AS_NUM
,
276 ENDP_COLUMN_GEO_AS_ORG
,
278 } endpoint_column_type_e
;
280 explicit EndpointDataModel(int protoId
, QString filter
, QObject
*parent
= nullptr);
282 int columnCount(const QModelIndex
&parent
= QModelIndex()) const;
283 QVariant
headerData(int section
, Qt::Orientation orientation
= Qt::Horizontal
, int role
= Qt::DisplayRole
) const;
284 QVariant
data(const QModelIndex
&idx
, int role
= Qt::DisplayRole
) const;
288 class ConversationDataModel
: public ATapDataModel
294 CONV_COLUMN_SRC_ADDR
,
295 CONV_COLUMN_SRC_PORT
,
296 CONV_COLUMN_DST_ADDR
,
297 CONV_COLUMN_DST_PORT
,
301 CONV_COLUMN_PACKETS_TOTAL
,
302 CONV_COLUMN_BYTES_TOTAL
,
304 CONV_COLUMN_BYTES_AB
,
306 CONV_COLUMN_BYTES_BA
,
308 CONV_COLUMN_DURATION
,
312 CONV_INDEX_COLUMN
= CONV_NUM_COLUMNS
313 } conversation_column_type_e
;
316 CONV_TCP_EXT_COLUMN_A
= CONV_INDEX_COLUMN
,
317 CONV_TCP_EXT_NUM_COLUMNS
,
318 CONV_TCP_EXT_INDEX_COLUMN
= CONV_TCP_EXT_NUM_COLUMNS
319 } conversation_tcp_ext_column_type_e
;
321 explicit ConversationDataModel(int protoId
, QString filter
, QObject
*parent
= nullptr);
323 int columnCount(const QModelIndex
&parent
= QModelIndex()) const;
324 QVariant
headerData(int section
, Qt::Orientation orientation
= Qt::Horizontal
, int role
= Qt::DisplayRole
) const;
325 QVariant
data(const QModelIndex
&idx
, int role
= Qt::DisplayRole
) const;
329 conv_item_t
* itemForRow(int row
);
332 * @brief Show the conversation id if available
334 * @return true a conversation id exists
335 * @return false none available
337 bool showConversationId(int row
= 0) const;
341 #endif // ATAP_DATA_MODEL_H