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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
/* related_packet_delegate.cpp
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <ui/qt/models/related_packet_delegate.h>
#include "packet_list_record.h"
#include <ui/qt/main_application.h>
#include <ui/qt/utils/color_utils.h>
#include <ui/qt/main_window.h>
#include <QApplication>
#include <QPainter>
typedef enum {
CT_NONE, // Not within the selected conversation.
CT_STARTING, // First packet in a conversation.
CT_CONTINUING, // Part of the selected conversation.
CT_BYPASSING, // *Not* part of the selected conversation.
CT_ENDING, // Last packet in a conversation.
CT_NUM_TYPES,
} ct_conversation_trace_type_t;
// To do:
// - Add other frame types and symbols. If `tshark -G fields | grep FT_FRAMENUM`
// is any indication, we should add "reassembly" and "reassembly error"
// fields.
// - Don't add *too* many frame types and symbols. The goal is context, not
// clutter.
// - Add tooltips. It looks like this needs to be done in ::helpEvent
// or PacketListModel::data.
// - Add "Go -> Next Related" and "Go -> Previous Related"?
// - Apply as filter?
RelatedPacketDelegate::RelatedPacketDelegate(QWidget *parent) :
QStyledItemDelegate(parent),
conv_(NULL),
current_frame_(0)
{
clear();
}
void RelatedPacketDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
/* This prevents the drawing of related objects, if multiple lines are being selected */
if (mainApp && mainApp->mainWindow())
{
MainWindow * mw = qobject_cast<MainWindow *>(mainApp->mainWindow());
if (mw && mw->hasSelection())
{
QStyledItemDelegate::paint(painter, option, index);
return;
}
}
QStyleOptionViewItem option_vi = option;
QStyledItemDelegate::initStyleOption(&option_vi, index);
int em_w = option_vi.fontMetrics.height();
int en_w = (em_w + 1) / 2;
int line_w = (option_vi.fontMetrics.lineWidth());
option_vi.features |= QStyleOptionViewItem::HasDecoration;
option_vi.decorationSize.setHeight(1);
option_vi.decorationSize.setWidth(em_w);
QStyledItemDelegate::paint(painter, option_vi, index);
guint32 setup_frame = 0, last_frame = 0;
if (conv_) {
setup_frame = (int) conv_->setup_frame;
last_frame = (int) conv_->last_frame;
}
const frame_data *fd;
PacketListRecord *record = static_cast<PacketListRecord*>(index.internalPointer());
if (!record || (fd = record->frameData()) == NULL) {
return;
}
ct_conversation_trace_type_t conversation_trace_type = CT_NONE;
ft_framenum_type_t related_frame_type =
related_frames_.contains(fd->num) ? related_frames_[fd->num] : FT_FRAMENUM_NUM_TYPES;
if (setup_frame > 0 && last_frame > 0 && setup_frame != last_frame) {
if (fd->num == setup_frame) {
conversation_trace_type = CT_STARTING;
} else if (fd->num > setup_frame && fd->num < last_frame) {
conversation_trace_type =
conv_->conv_index == record->conversation() ? CT_CONTINUING : CT_BYPASSING;
} else if (fd->num == last_frame) {
conversation_trace_type = CT_ENDING;
}
}
painter->save();
if (QApplication::style()->objectName().contains("vista")) {
// QWindowsVistaStyle::drawControl does this internally. Unfortunately there
// doesn't appear to be a more general way to do this.
option_vi.palette.setColor(QPalette::All, QPalette::HighlightedText, option_vi.palette.color(QPalette::Active, QPalette::Text));
}
QPalette::ColorGroup cg = option_vi.state & QStyle::State_Enabled
? QPalette::Normal : QPalette::Disabled;
QColor fg;
if (cg == QPalette::Normal && !(option_vi.state & QStyle::State_Active))
cg = QPalette::Inactive;
#if !defined(Q_OS_WIN)
if (option_vi.state & QStyle::State_MouseOver) {
fg = QApplication::palette().text().color();
} else
#endif
if (option_vi.state & QStyle::State_Selected) {
fg = option_vi.palette.color(cg, QPalette::HighlightedText);
} else {
fg = option_vi.palette.color(cg, QPalette::Text);
}
fg = ColorUtils::alphaBlend(fg, option_vi.palette.color(cg, QPalette::Base), 0.5);
QPen line_pen(fg);
line_pen.setWidth(line_w);
line_pen.setJoinStyle(Qt::RoundJoin);
painter->setPen(line_pen);
painter->translate(option_vi.rect.x(), option_vi.rect.y());
painter->translate(en_w + 0.5, 0.5);
painter->setRenderHint(QPainter::Antialiasing, true);
int height = option_vi.rect.height();
// Uncomment to make the boundary visible.
// painter->save();
// painter->setPen(Qt::darkRed);
// painter->drawRect(QRectF(0.5, 0.5, en_w - 1, height - 1));
// painter->restore();
// The current decorations are based on what looked good and were easy
// to code.
// It might be useful to have a JACKPOT_MODE define that shows each
// decoration in sequence in order to make it easier to create
// screenshots for the User's Guide.
// Vertical line. Lower and upper half for the start and end of the
// conversation respectively, solid for conversation member, dashed
// for other packets in the start-end range.
switch (conversation_trace_type) {
case CT_STARTING:
{
QPoint start_line[] = {
QPoint(en_w - 1, height / 2),
QPoint(0, height / 2),
QPoint(0, height)
};
painter->drawPolyline(start_line, 3);
break;
}
case CT_CONTINUING:
case CT_BYPASSING:
{
painter->save();
if (conversation_trace_type == CT_BYPASSING) {
// Dashed line as we bypass packets not part of the conv.
QPen other_pen(line_pen);
other_pen.setStyle(Qt::DashLine);
painter->setPen(other_pen);
}
// analysis overriding mark (three horizontal lines)
if(fd->tcp_snd_manual_analysis) {
int wbound = (en_w - 1) / 2;
painter->drawLine(-wbound, 1, wbound, 1);
painter->drawLine(-wbound, height / 2, wbound, height / 2);
painter->drawLine(-wbound, height - 2, wbound, height - 2);
}
painter->drawLine(0, 0, 0, height);
painter->restore();
break;
}
case CT_ENDING:
{
QPoint end_line[] = {
QPoint(en_w - 1, height / 2),
QPoint(0, height / 2),
QPoint(0, 0)
};
painter->drawPolyline(end_line, 3);
/* analysis overriding on the last packet of the conversation,
* we mark it with an additional horizontal line only.
* See issue 10725 for example.
*/
// analysis overriding mark (three horizontal lines)
if(fd->tcp_snd_manual_analysis) {
int wbound = (en_w - 1) / 2;
painter->drawLine(-wbound, 1, wbound, 1);
painter->drawLine(-wbound, height / 2, wbound, height / 2);
}
break;
}
default:
break;
}
// Related packet indicator. Rightward arrow for requests, leftward
// arrow for responses, circle for others.
// XXX These are comically oversized when we have multi-line rows.
if (related_frame_type != FT_FRAMENUM_NUM_TYPES) {
painter->setBrush(fg);
switch (related_frame_type) {
// Request and response arrows are moved forward one pixel in order to
// maximize white space between the heads and the conversation line.
case FT_FRAMENUM_REQUEST:
{
int hh = height / 2;
QPoint tail(2 - en_w, hh);
QPoint head(en_w, hh);
drawArrow(painter, tail, head, hh / 2);
break;
}
case FT_FRAMENUM_RESPONSE:
{
int hh = height / 2;
QPoint tail(en_w - 1, hh);
QPoint head(1 - en_w, hh);
drawArrow(painter, tail, head, hh / 2);
break;
}
case FT_FRAMENUM_ACK:
{
QRect bbox (2 - en_w, height / 3, em_w - 2, height / 2);
drawCheckMark(painter, bbox);
break;
}
case FT_FRAMENUM_DUP_ACK:
{
QRect bbox (2 - en_w, (height / 3) - (line_w * 2), em_w - 2, height / 2);
drawCheckMark(painter, bbox);
bbox.moveTop(bbox.top() + (line_w * 3));
drawCheckMark(painter, bbox);
break;
}
case FT_FRAMENUM_RETRANS_PREV:
{
int hh = height / 2;
QPoint tail(2 - en_w, hh);
QPoint head(en_w, hh);
drawChevrons(painter, tail, head, hh / 2);
break;
}
case FT_FRAMENUM_RETRANS_NEXT:
{
int hh = height / 2;
QPoint tail(en_w - 1, hh);
QPoint head(1 - en_w, hh);
drawChevrons(painter, tail, head, hh / 2);
break;
}
case FT_FRAMENUM_NONE:
default:
painter->drawEllipse(QPointF(0.0, option_vi.rect.height() / 2), 2, 2);
}
}
painter->restore();
}
QSize RelatedPacketDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
/* This prevents the sizeHint for the delegate, if multiple lines are being selected */
if (mainApp && mainApp->mainWindow())
{
MainWindow * mw = qobject_cast<MainWindow *>(mainApp->mainWindow());
if (mw && mw->selectedRows().count() > 1)
return QStyledItemDelegate::sizeHint(option, index);
}
return QSize(option.fontMetrics.height() + QStyledItemDelegate::sizeHint(option, index).width(),
QStyledItemDelegate::sizeHint(option, index).height());
}
void RelatedPacketDelegate::drawArrow(QPainter *painter, const QPoint tail, const QPoint head, int head_size) const
{
int x_mul = head.x() > tail.x() ? -1 : 1;
QPoint head_points[] = {
head,
QPoint(head.x() + (head_size * x_mul), head.y() + (head_size / 2)),
QPoint(head.x() + (head_size * x_mul), head.y() - (head_size / 2)),
};
painter->drawLine(tail.x(), tail.y(), head.x() + (head_size * x_mul), head.y());
painter->drawPolygon(head_points, 3);
}
void RelatedPacketDelegate::drawChevrons(QPainter *painter, const QPoint tail, const QPoint head, int head_size) const
{
int x_mul = head.x() > tail.x() ? -1 : 1;
QPoint head_points1[] = {
head,
QPoint(head.x() + (head_size * x_mul), head.y() + (head_size / 2)),
QPoint(head.x() + (head_size * x_mul), head.y() - (head_size / 2)),
};
QPoint head2(head.x() + (head_size * x_mul), head.y());
QPoint head_points2[] = {
head2,
QPoint(head2.x() + (head_size * x_mul), head2.y() + (head_size / 2)),
QPoint(head2.x() + (head_size * x_mul), head2.y() - (head_size / 2)),
};
painter->drawPolygon(head_points1, 3);
painter->drawPolygon(head_points2, 3);
}
void RelatedPacketDelegate::drawCheckMark(QPainter *painter, const QRect bbox) const
{
QPoint cm_points[] = {
QPoint(bbox.x(), bbox.y() + (bbox.height() / 2)),
QPoint(bbox.x() + (bbox.width() / 4), bbox.y() + (bbox.height() * 3 / 4)),
bbox.topRight()
};
painter->drawPolyline(cm_points, 3);
}
void RelatedPacketDelegate::clear()
{
related_frames_.clear();
current_frame_ = 0;
conv_ = NULL;
}
void RelatedPacketDelegate::setCurrentFrame(guint32 current_frame)
{
current_frame_ = current_frame;
foreach (ft_framenum_type_t framenum_type, related_frames_) {
addRelatedFrame(-1, framenum_type); /* No need to check if this element belongs to the hash... */
}
}
void RelatedPacketDelegate::addRelatedFrame(int frame_num, ft_framenum_type_t framenum_type)
{
if (frame_num != -1 && !related_frames_.contains(frame_num))
related_frames_[frame_num] = framenum_type;
// Last match wins. Last match might not make sense, however.
if (current_frame_ > 0) {
switch (framenum_type) {
case FT_FRAMENUM_REQUEST:
related_frames_[current_frame_] = FT_FRAMENUM_RESPONSE;
break;
case FT_FRAMENUM_RESPONSE:
related_frames_[current_frame_] = FT_FRAMENUM_REQUEST;
break;
default:
break;
}
}
}
void RelatedPacketDelegate::setConversation(conversation *conv)
{
conv_ = conv;
}
|