aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/models/atap_data_model.h
blob: 63b92eded71262072bd583c28ded3aede70a9398 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/** @file
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef ATAP_DATA_MODEL_H
#define ATAP_DATA_MODEL_H

#include "config.h"

#include "glib.h"

#include <epan/tap.h>
#include <epan/conversation.h>
#include <epan/conversation_table.h>

#include <QAbstractListModel>

/**
 * @brief DataModel for tap user data
 *
 * This datamodel provides the management for all tap data for the conversation
 * and endpoint dialogs. It predominantly is implemented to work with conversation
 * tap data. The management of displaying and correctly presenting the information
 * is done in the corresponding type classes
 *
 * @see EndpointDataModel
 * @see ConversationDataModel
 */
class ATapDataModel : public QAbstractListModel
{
    Q_OBJECT
public:

    enum {
        DISPLAY_FILTER = Qt::UserRole,
        UNFORMATTED_DISPLAYDATA,
#ifdef HAVE_MAXMINDDB
        GEODATA_AVAILABLE,
        GEODATA_LOOKUPTABLE,
        GEODATA_ADDRESS,
#endif
        TIMELINE_DATA,
        ENDPOINT_DATATYPE,
        CONVERSATION_ID,
        ROW_IS_FILTERED,
        DATA_ADDRESS_TYPE,
        DATA_IPV4_INTEGER,
        DATA_IPV6_LIST,
    };

    typedef enum {
        DATAMODEL_ENDPOINT,
        DATAMODEL_CONVERSATION,
        DATAMODEL_UNKNOWN
    } dataModelType;

    /**
     * @brief Construct a new ATapDataModel object
     *
     * The tap will not be created automatically, but must be enabled by calling enableTap
     *
     * @param type an element of dataModelType. Either DATAMODEL_ENDPOINT or DATAMODEL_CONVERSATION are supported
     *   at this time
     * @param protoId the protocol id for which the tap is created
     * @param filter a potential filter to be used for the tap
     * @param parent the parent for the class
     *
     * @see enableTap
     */
    explicit ATapDataModel(dataModelType type, int protoId, QString filter, QObject *parent = nullptr);
    virtual ~ATapDataModel();

    /**
     * @brief Number of rows in this model
     *
     * @param idx not used
     * @return int the number of rows
     */
    int rowCount(const QModelIndex &idx = QModelIndex()) const;

    virtual int columnCount(const QModelIndex &parent = QModelIndex()) const = 0;
    virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const = 0;
    virtual QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const = 0;

    /**
     * @brief Returns the name for the tap being used
     *
     * @return QString the tap name, normally identical with the protocol name
     */
    QString tap() const;

    /**
     * @brief The protocol id for the tap
     *
     * @return int the id given in the constructor
     */
    int protoId() const;

    /**
     * @brief Set the filter string.
     *
     * A set filter can be reset by providing an empty string
     *
     * @param filter the filter for the tap
     */
    void setFilter(QString filter);

    /**
     * @brief Return a filter set for the model
     *
     * @return QString the filter string for the model
     */
    QString filter() const;

    /**
     * @brief Is the model set to resolve names in address and ports columns
     *
     * @return true yes, names will be resolved
     * @return false no they won't
     */
    bool resolveNames() const;

    /**
     * @brief Enable or disable if names should be resolved
     *
     * @param resolve true if names should be resolved
     */
    void setResolveNames(bool resolve);

    /**
     * @brief Does the model allow names to be resolved
     *
     * @return true yes, names may be resolved (set via setResolveNames)
     * @return false no, they won't be resolved
     *
     * @see setResolveNames
     * @see resolveNames
     */
    bool allowsNameResolution() const;

    /**
     * @brief Use absolute time for any column supporting it
     *
     * @param absolute true to use absolute time values
     */
    void useAbsoluteTime(bool absolute);

    /**
     * @brief Use nanosecond timestamps if requested
     *
     * @param nanoseconds use nanosecond timestamps if required and requested
     */
    void useNanosecondTimestamps(bool nanoseconds);

    /**
     * @brief Are ports hidden for this model
     *
     * @return true the ports are hidden
     * @return false the ports are not hidden
     */
    bool portsAreHidden() const;

    /**
     * @brief Enable tapping in this model.
     *
     * This will register the tap listener with the corresponding packet function.
     * @note if the tap has not been disabled, this method will do nothing
     *
     * @return true the tap has been enabled
     * @return false the tap has not been enabled
     */
    bool enableTap();

    /**
     * @brief Disable the tapping for this model
     */
    void disableTap();

    /**
     * @brief Return the model type
     *
     * @return dataModelType
     */
    dataModelType modelType() const;

#ifdef HAVE_MAXMINDDB
    /**
     * @brief Does this model have geoip data available
     *
     * @return true it has
     * @return false it has not
     */
    bool hasGeoIPData();
#endif

signals:
    void tapListenerChanged(bool enable);

protected:

    static void tapReset(void *tapdata);
    static void tapDraw(void *tap_data);

    virtual tap_packet_cb conversationPacketHandler();

    conv_hash_t * hash();

    void resetData();
    void updateData(GArray * data);

    dataModelType _type;
    GArray * storage_;
    QString _filter;

    bool _absoluteTime;
    bool _nanoseconds;
    bool _resolveNames;
    bool _disableTap;

    double _minRelStartTime;
    double _maxRelStopTime;

    register_ct_t* registerTable() const;

    bool showTotalColumn() const;

private:
    int _protoId;

    conv_hash_t hash_;
};

class EndpointDataModel : public ATapDataModel
{
    Q_OBJECT
public:

    typedef enum
    {
        ENDP_COLUMN_ADDR,
        ENDP_COLUMN_PORT,
        ENDP_COLUMN_PACKETS,
        ENDP_COLUMN_BYTES,
        ENDP_COLUMN_PKT_AB,
        ENDP_COLUMN_BYTES_AB,
        ENDP_COLUMN_PKT_BA,
        ENDP_COLUMN_BYTES_BA,
        ENDP_NUM_COLUMNS,
        ENDP_COLUMN_GEO_COUNTRY = ENDP_NUM_COLUMNS,
        ENDP_COLUMN_GEO_CITY,
        ENDP_COLUMN_GEO_AS_NUM,
        ENDP_COLUMN_GEO_AS_ORG,
        ENDP_NUM_GEO_COLUMNS
    } endpoint_column_type_e;

    explicit EndpointDataModel(int protoId, QString filter, QObject *parent = nullptr);

    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const;

};

class ConversationDataModel : public ATapDataModel
{
    Q_OBJECT
public:

    typedef enum {
        CONV_COLUMN_SRC_ADDR,
        CONV_COLUMN_SRC_PORT,
        CONV_COLUMN_DST_ADDR,
        CONV_COLUMN_DST_PORT,
        CONV_COLUMN_PACKETS,
        CONV_COLUMN_BYTES,
        CONV_COLUMN_PKT_AB,
        CONV_COLUMN_BYTES_AB,
        CONV_COLUMN_PKT_BA,
        CONV_COLUMN_BYTES_BA,
        CONV_COLUMN_START,
        CONV_COLUMN_DURATION,
        CONV_COLUMN_BPS_AB,
        CONV_COLUMN_BPS_BA,
        CONV_NUM_COLUMNS,
        CONV_INDEX_COLUMN = CONV_NUM_COLUMNS
    } conversation_column_type_e;

    explicit ConversationDataModel(int protoId, QString filter, QObject *parent = nullptr);

    int columnCount(const QModelIndex &parent = QModelIndex()) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    QVariant data(const QModelIndex &idx, int role = Qt::DisplayRole) const;

    void doDataUpdate();

    conv_item_t * itemForRow(int row);

};

#endif // ATAP_DATA_MODEL_H