summaryrefslogtreecommitdiffstats
path: root/ui/qt/funnel_statistics.h
blob: 65b36ab8914d02197579064092f12529a92d4858 (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
/** @file
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#ifndef FUNNELSTATISTICS_H
#define FUNNELSTATISTICS_H

#include <QObject>
#include <QAction>
#include <QSet>
#include <QPointer>

#include <epan/funnel.h>
#include "io_console_dialog.h"
#include "capture_file.h"
#include <ui/qt/filter_action.h>

struct _funnel_ops_t;
struct progdlg;

/**
 * Signature of function that can be called from a custom packet menu entry
 */
typedef void (* funnel_packet_menu_callback)(gpointer, GPtrArray*);

class FunnelStatistics : public QObject
{
    Q_OBJECT
public:
    explicit FunnelStatistics(QObject *parent, CaptureFile &cf);
    ~FunnelStatistics();
    void retapPackets();
    struct progdlg *progressDialogNew(const gchar *task_title, const gchar *item_title, gboolean terminate_is_stop, gboolean *stop_flag);
    const char *displayFilter();
    void emitSetDisplayFilter(const QString filter);
    void reloadPackets();
    void redissectPackets();
    void reloadLuaPlugins();
    void emitApplyDisplayFilter();
    void emitOpenCaptureFile(QString cf_path, QString filter);
    static const QString &actionName() { return action_name_; }

signals:
    void openCaptureFile(QString cf_path, QString filter);
    void setDisplayFilter(QString filter, FilterAction::Action action, FilterAction::ActionType filterType);

public slots:
    void funnelActionTriggered();
    void displayFilterTextChanged(const QString &filter);

private:
    static const QString action_name_;
    struct _funnel_ops_t *funnel_ops_;
    struct _funnel_ops_id_t *funnel_ops_id_;

    CaptureFile &capture_file_;
    QByteArray display_filter_;
    QString prepared_filter_;
};

class FunnelAction : public QAction
{
    Q_OBJECT
public:
    FunnelAction(QObject *parent = nullptr);
    FunnelAction(QString title, funnel_menu_callback callback, gpointer callback_data, gboolean retap, QObject *parent);
    FunnelAction(QString title, funnel_packet_menu_callback callback, gpointer callback_data, gboolean retap, const char *packet_required_fields, QObject *parent);
    ~FunnelAction();
    funnel_menu_callback callback() const;
    QString title() const;
    virtual void triggerCallback();
    void setPacketCallback(funnel_packet_menu_callback packet_callback);
    void setPacketData(GPtrArray* finfos);
    void addToMenu(QMenu * ctx_menu, QHash<QString, QMenu *> &menuTextToMenus);
    void setPacketRequiredFields(const char *required_fields_str);
    const QSet<QString> getPacketRequiredFields();
    bool retap();
    QString getPacketSubmenus();

public slots:
    void triggerPacketCallback();

private:
    QString title_;
    QString packetSubmenu_;
    funnel_menu_callback callback_;
    gpointer callback_data_;
    gboolean retap_;
    funnel_packet_menu_callback packetCallback_;
    GPtrArray* packetData_;
    QSet<QString> packetRequiredFields_;
};

class FunnelConsoleAction : public FunnelAction
{
    Q_OBJECT
public:
    FunnelConsoleAction(QString name, funnel_console_eval_cb_t eval_cb,
                        funnel_console_open_cb_t open_cb,
                        funnel_console_close_cb_t close_cb,
                        void *callback_data, QObject *parent);
    ~FunnelConsoleAction();
    virtual void triggerCallback();

private:
    QString title_;
    funnel_console_eval_cb_t eval_cb_;
    funnel_console_open_cb_t open_cb_;
    funnel_console_close_cb_t close_cb_;
    void *callback_data_;
    QPointer<IOConsoleDialog> dialog_;
};

extern "C" {
    void funnel_statistics_reload_menus(void);
    void funnel_statistics_load_packet_menus(void);
    void funnel_statistics_load_console_menus(void);
    gboolean funnel_statistics_packet_menus_modified(void);
} // extern "C"

#endif // FUNNELSTATISTICS_H