2015-06-17 00:24:19 +00:00
|
|
|
/* protocol_preferences_menu.h
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
2018-02-07 11:26:45 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2015-06-17 00:24:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <epan/prefs.h>
|
|
|
|
#include <epan/prefs-int.h>
|
|
|
|
#include <epan/proto.h>
|
|
|
|
|
2021-08-30 20:02:17 +00:00
|
|
|
#include <cfile.h>
|
|
|
|
#include <ui/commandline.h>
|
2015-06-17 00:24:19 +00:00
|
|
|
#include <ui/preference_utils.h>
|
2015-10-04 17:10:29 +00:00
|
|
|
#include <wsutil/utf8_entities.h>
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
#include "protocol_preferences_menu.h"
|
|
|
|
|
2017-12-17 02:51:33 +00:00
|
|
|
#include <ui/qt/models/enabled_protocols_model.h>
|
2017-07-25 14:15:18 +00:00
|
|
|
#include <ui/qt/utils/qt_ui_utils.h>
|
2015-06-17 00:24:19 +00:00
|
|
|
#include "uat_dialog.h"
|
2022-02-01 03:30:09 +00:00
|
|
|
#include "main_application.h"
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2021-11-20 03:51:05 +00:00
|
|
|
#include <QActionGroup>
|
|
|
|
|
2015-06-17 00:24:19 +00:00
|
|
|
// To do:
|
|
|
|
// - Elide really long items?
|
2015-06-17 15:41:41 +00:00
|
|
|
// - Handle color prefs.
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
class BoolPreferenceAction : public QAction
|
|
|
|
{
|
|
|
|
public:
|
2018-05-26 12:07:06 +00:00
|
|
|
BoolPreferenceAction(pref_t *pref, QObject *parent=0) :
|
|
|
|
QAction(parent),
|
2015-06-17 15:41:41 +00:00
|
|
|
pref_(pref)
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
setText(prefs_get_title(pref_));
|
2015-06-17 15:41:41 +00:00
|
|
|
setCheckable(true);
|
2017-01-07 13:52:23 +00:00
|
|
|
setChecked(prefs_get_bool_value(pref_, pref_current));
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 04:39:55 +00:00
|
|
|
unsigned int setBoolValue() {
|
|
|
|
return prefs_set_bool_value(pref_, isChecked(), pref_current);
|
2015-06-17 15:41:41 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 20:02:17 +00:00
|
|
|
pref_t *getPref() { return pref_; }
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
};
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
class EnumPreferenceAction : public QAction
|
|
|
|
{
|
|
|
|
public:
|
2018-05-26 12:07:06 +00:00
|
|
|
EnumPreferenceAction(pref_t *pref, const char *title, int enumval, QActionGroup *ag, QObject *parent=0) :
|
|
|
|
QAction(parent),
|
2015-06-17 00:24:19 +00:00
|
|
|
pref_(pref),
|
|
|
|
enumval_(enumval)
|
|
|
|
{
|
|
|
|
setText(title);
|
|
|
|
setActionGroup(ag);
|
|
|
|
setCheckable(true);
|
|
|
|
}
|
|
|
|
|
2018-01-06 04:39:55 +00:00
|
|
|
unsigned int setEnumValue() {
|
2017-01-07 13:52:23 +00:00
|
|
|
return prefs_set_enum_value(pref_, enumval_, pref_current);
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 20:02:17 +00:00
|
|
|
pref_t *getPref() { return pref_; }
|
|
|
|
|
2015-06-17 00:24:19 +00:00
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
int enumval_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class UatPreferenceAction : public QAction
|
|
|
|
{
|
|
|
|
public:
|
2018-05-26 12:07:06 +00:00
|
|
|
UatPreferenceAction(pref_t *pref, QObject *parent=0) :
|
|
|
|
QAction(parent),
|
2015-06-17 00:24:19 +00:00
|
|
|
pref_(pref)
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
setText(QString("%1" UTF8_HORIZONTAL_ELLIPSIS).arg(prefs_get_title(pref_)));
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void showUatDialog() {
|
2019-09-29 09:39:40 +00:00
|
|
|
UatDialog *uat_dlg = new UatDialog(parentWidget(), prefs_get_uat_value(pref_));
|
2022-02-01 03:30:09 +00:00
|
|
|
connect(uat_dlg, SIGNAL(destroyed(QObject*)), mainApp, SLOT(flushAppSignals()));
|
2019-09-29 09:39:40 +00:00
|
|
|
uat_dlg->setWindowModality(Qt::ApplicationModal);
|
|
|
|
uat_dlg->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
uat_dlg->show();
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
|
2021-08-30 20:02:17 +00:00
|
|
|
pref_t *getPref() { return pref_; }
|
|
|
|
|
2015-06-17 00:24:19 +00:00
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
};
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
// Preference requires an external editor (PreferenceEditorFrame)
|
|
|
|
class EditorPreferenceAction : public QAction
|
2015-06-17 00:24:19 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-05-26 12:07:06 +00:00
|
|
|
EditorPreferenceAction(pref_t *pref, QObject *parent=0) :
|
|
|
|
QAction(parent),
|
2015-06-17 00:24:19 +00:00
|
|
|
pref_(pref)
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
QString title = prefs_get_title(pref_);
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2017-01-04 15:57:25 +00:00
|
|
|
title.append(QString(": %1" UTF8_HORIZONTAL_ELLIPSIS).arg(gchar_free_to_qstring(prefs_pref_to_str(pref_, pref_current))));
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
setText(title);
|
|
|
|
}
|
2015-06-17 15:41:41 +00:00
|
|
|
pref_t *pref() { return pref_; }
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
pref_t *pref_;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
// Preference callback
|
|
|
|
|
|
|
|
static guint
|
|
|
|
add_prefs_menu_item(pref_t *pref, gpointer menu_ptr)
|
|
|
|
{
|
|
|
|
ProtocolPreferencesMenu *pp_menu = static_cast<ProtocolPreferencesMenu *>(menu_ptr);
|
|
|
|
if (!pp_menu) return 1;
|
|
|
|
|
|
|
|
pp_menu->addMenuItem(pref);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ProtocolPreferencesMenu::ProtocolPreferencesMenu()
|
|
|
|
{
|
|
|
|
setTitle(tr("Protocol Preferences"));
|
|
|
|
setModule(NULL);
|
|
|
|
}
|
|
|
|
|
2020-07-02 08:20:14 +00:00
|
|
|
ProtocolPreferencesMenu::ProtocolPreferencesMenu(const QString &title, const QString &module_name, QWidget *parent) :
|
|
|
|
QMenu(title, parent)
|
|
|
|
{
|
|
|
|
setModule(module_name);
|
|
|
|
}
|
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
void ProtocolPreferencesMenu::setModule(const QString module_name)
|
2015-06-17 00:24:19 +00:00
|
|
|
{
|
|
|
|
QAction *action;
|
|
|
|
int proto_id = -1;
|
2015-07-27 23:17:44 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
if (!module_name.isEmpty()) {
|
|
|
|
proto_id = proto_get_id_by_filter_name(module_name.toUtf8().constData());
|
2015-07-27 23:17:44 +00:00
|
|
|
}
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
clear();
|
|
|
|
module_name_.clear();
|
|
|
|
module_ = NULL;
|
|
|
|
|
2015-07-27 23:17:44 +00:00
|
|
|
protocol_ = find_protocol_by_id(proto_id);
|
2015-07-31 23:52:37 +00:00
|
|
|
const QString long_name = proto_get_protocol_long_name(protocol_);
|
|
|
|
const QString short_name = proto_get_protocol_short_name(protocol_);
|
2017-12-07 16:15:30 +00:00
|
|
|
if (module_name.isEmpty() || proto_id < 0 || !protocol_) {
|
2015-06-17 00:24:19 +00:00
|
|
|
action = addAction(tr("No protocol preferences available"));
|
|
|
|
action->setDisabled(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-02 10:32:58 +00:00
|
|
|
QAction *disable_action = new QAction(tr("Disable %1").arg(short_name), this);
|
2015-07-27 23:17:44 +00:00
|
|
|
connect(disable_action, SIGNAL(triggered(bool)), this, SLOT(disableProtocolTriggered()));
|
2017-05-04 12:21:27 +00:00
|
|
|
disable_action->setDisabled(!proto_can_toggle_protocol(proto_id));
|
2015-07-27 23:17:44 +00:00
|
|
|
|
2017-12-07 16:15:30 +00:00
|
|
|
module_ = prefs_find_module(module_name.toUtf8().constData());
|
|
|
|
if (!module_ || !prefs_is_registered_protocol(module_name.toUtf8().constData())) {
|
2015-07-31 23:52:37 +00:00
|
|
|
action = addAction(tr("%1 has no preferences").arg(long_name));
|
2015-06-17 00:24:19 +00:00
|
|
|
action->setDisabled(true);
|
2015-07-27 23:17:44 +00:00
|
|
|
addSeparator();
|
|
|
|
addAction(disable_action);
|
2015-06-17 00:24:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_name_ = module_name;
|
|
|
|
|
2020-09-29 00:40:05 +00:00
|
|
|
action = addAction(tr("Open %1 preferences…").arg(long_name));
|
2022-02-02 21:45:15 +00:00
|
|
|
if (module_->use_gui) {
|
|
|
|
action->setData(QString(module_name));
|
|
|
|
connect(action, SIGNAL(triggered(bool)), this, SLOT(modulePreferencesTriggered()));
|
|
|
|
} else {
|
|
|
|
action->setDisabled(true);
|
|
|
|
}
|
2015-06-17 00:24:19 +00:00
|
|
|
addSeparator();
|
|
|
|
|
|
|
|
prefs_pref_foreach(module_, add_prefs_menu_item, this);
|
2015-07-27 23:17:44 +00:00
|
|
|
|
|
|
|
if (!actions().last()->isSeparator()) {
|
|
|
|
addSeparator();
|
|
|
|
}
|
|
|
|
addAction(disable_action);
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolPreferencesMenu::addMenuItem(preference *pref)
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
switch (prefs_get_type(pref)) {
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_BOOL:
|
|
|
|
{
|
2018-05-26 12:07:06 +00:00
|
|
|
BoolPreferenceAction *bpa = new BoolPreferenceAction(pref, this);
|
2015-06-17 15:41:41 +00:00
|
|
|
addAction(bpa);
|
|
|
|
connect(bpa, SIGNAL(triggered(bool)), this, SLOT(boolPreferenceTriggered()));
|
|
|
|
break;
|
|
|
|
}
|
2015-06-17 00:24:19 +00:00
|
|
|
case PREF_ENUM:
|
|
|
|
{
|
2017-01-07 13:52:23 +00:00
|
|
|
QMenu *enum_menu = addMenu(prefs_get_title(pref));
|
2018-03-01 12:45:55 +00:00
|
|
|
const enum_val_t *enum_valp = prefs_get_enumvals(pref);
|
|
|
|
if (enum_valp && enum_valp->name) {
|
|
|
|
QActionGroup *ag = new QActionGroup(this);
|
|
|
|
while (enum_valp->name) {
|
2018-05-26 12:07:06 +00:00
|
|
|
EnumPreferenceAction *epa = new EnumPreferenceAction(pref, enum_valp->description, enum_valp->value, ag, this);
|
2018-03-01 12:45:55 +00:00
|
|
|
if (prefs_get_enum_value(pref, pref_current) == enum_valp->value) {
|
|
|
|
epa->setChecked(true);
|
|
|
|
}
|
|
|
|
enum_menu->addAction(epa);
|
|
|
|
connect(epa, SIGNAL(triggered(bool)), this, SLOT(enumPreferenceTriggered()));
|
|
|
|
enum_valp++;
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_UINT:
|
|
|
|
case PREF_STRING:
|
2020-07-02 11:45:42 +00:00
|
|
|
case PREF_SAVE_FILENAME:
|
|
|
|
case PREF_OPEN_FILENAME:
|
|
|
|
case PREF_DIRNAME:
|
2015-06-17 15:41:41 +00:00
|
|
|
case PREF_RANGE:
|
2017-01-25 09:38:49 +00:00
|
|
|
case PREF_DECODE_AS_UINT:
|
|
|
|
case PREF_DECODE_AS_RANGE:
|
2021-12-30 16:03:15 +00:00
|
|
|
case PREF_PASSWORD:
|
2015-06-17 15:41:41 +00:00
|
|
|
{
|
2018-05-26 12:07:06 +00:00
|
|
|
EditorPreferenceAction *epa = new EditorPreferenceAction(pref, this);
|
2015-06-17 15:41:41 +00:00
|
|
|
addAction(epa);
|
|
|
|
connect(epa, SIGNAL(triggered(bool)), this, SLOT(editorPreferenceTriggered()));
|
|
|
|
break;
|
|
|
|
}
|
2015-06-17 00:24:19 +00:00
|
|
|
case PREF_UAT:
|
|
|
|
{
|
2018-05-26 12:07:06 +00:00
|
|
|
UatPreferenceAction *upa = new UatPreferenceAction(pref, this);
|
2015-06-17 00:24:19 +00:00
|
|
|
addAction(upa);
|
|
|
|
connect(upa, SIGNAL(triggered(bool)), this, SLOT(uatPreferenceTriggered()));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case PREF_CUSTOM:
|
|
|
|
case PREF_STATIC_TEXT:
|
|
|
|
case PREF_OBSOLETE:
|
|
|
|
break;
|
|
|
|
default:
|
2020-07-02 11:45:42 +00:00
|
|
|
// A type we currently don't handle. Just open the prefs dialog.
|
2017-01-07 13:52:23 +00:00
|
|
|
QString title = QString("%1" UTF8_HORIZONTAL_ELLIPSIS).arg(prefs_get_title(pref));
|
2015-06-17 15:41:41 +00:00
|
|
|
QAction *mpa = addAction(title);
|
|
|
|
connect(mpa, SIGNAL(triggered(bool)), this, SLOT(modulePreferencesTriggered()));
|
2015-06-17 00:24:19 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:17:44 +00:00
|
|
|
void ProtocolPreferencesMenu::disableProtocolTriggered()
|
|
|
|
{
|
2017-12-17 02:51:33 +00:00
|
|
|
EnabledProtocolsModel::disableProtocol(protocol_);
|
2015-07-27 23:17:44 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
void ProtocolPreferencesMenu::modulePreferencesTriggered()
|
2015-06-17 00:24:19 +00:00
|
|
|
{
|
|
|
|
if (!module_name_.isEmpty()) {
|
|
|
|
emit showProtocolPreferences(module_name_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 15:41:41 +00:00
|
|
|
void ProtocolPreferencesMenu::editorPreferenceTriggered()
|
|
|
|
{
|
|
|
|
EditorPreferenceAction *epa = static_cast<EditorPreferenceAction *>(QObject::sender());
|
|
|
|
if (!epa) return;
|
|
|
|
|
|
|
|
if (epa->pref() && module_) {
|
|
|
|
emit editProtocolPreference(epa->pref(), module_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 00:24:19 +00:00
|
|
|
void ProtocolPreferencesMenu::boolPreferenceTriggered()
|
|
|
|
{
|
2015-06-17 15:41:41 +00:00
|
|
|
BoolPreferenceAction *bpa = static_cast<BoolPreferenceAction *>(QObject::sender());
|
|
|
|
if (!bpa) return;
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2018-01-06 04:39:55 +00:00
|
|
|
module_->prefs_changed_flags |= bpa->setBoolValue();
|
2019-11-17 12:25:15 +00:00
|
|
|
unsigned int changed_flags = module_->prefs_changed_flags;
|
2015-06-17 00:24:19 +00:00
|
|
|
|
|
|
|
prefs_apply(module_);
|
2018-09-01 12:05:46 +00:00
|
|
|
prefs_main_write();
|
2021-08-30 20:02:17 +00:00
|
|
|
commandline_options_drop(module_->name, prefs_get_name(bpa->getPref()));
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2019-11-17 12:25:15 +00:00
|
|
|
if (changed_flags & PREF_EFFECT_FIELDS) {
|
2022-02-01 03:30:09 +00:00
|
|
|
mainApp->emitAppSignal(MainApplication::FieldsChanged);
|
2019-11-17 12:25:15 +00:00
|
|
|
}
|
2018-01-06 17:10:06 +00:00
|
|
|
/* Protocol preference changes almost always affect dissection,
|
|
|
|
so don't bother checking flags */
|
2022-02-01 03:30:09 +00:00
|
|
|
mainApp->emitAppSignal(MainApplication::PacketDissectionChanged);
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolPreferencesMenu::enumPreferenceTriggered()
|
|
|
|
{
|
|
|
|
EnumPreferenceAction *epa = static_cast<EnumPreferenceAction *>(QObject::sender());
|
|
|
|
if (!epa) return;
|
|
|
|
|
2018-01-06 04:39:55 +00:00
|
|
|
unsigned int changed_flags = epa->setEnumValue();
|
|
|
|
if (changed_flags) { // Changed
|
|
|
|
module_->prefs_changed_flags |= changed_flags;
|
2015-06-17 00:24:19 +00:00
|
|
|
prefs_apply(module_);
|
2018-09-01 12:05:46 +00:00
|
|
|
prefs_main_write();
|
2021-08-30 20:02:17 +00:00
|
|
|
commandline_options_drop(module_->name, prefs_get_name(epa->getPref()));
|
2015-06-17 00:24:19 +00:00
|
|
|
|
2019-11-17 12:25:15 +00:00
|
|
|
if (changed_flags & PREF_EFFECT_FIELDS) {
|
2022-02-01 03:30:09 +00:00
|
|
|
mainApp->emitAppSignal(MainApplication::FieldsChanged);
|
2019-11-17 12:25:15 +00:00
|
|
|
}
|
2018-01-06 17:10:06 +00:00
|
|
|
/* Protocol preference changes almost always affect dissection,
|
|
|
|
so don't bother checking flags */
|
2022-02-01 03:30:09 +00:00
|
|
|
mainApp->emitAppSignal(MainApplication::PacketDissectionChanged);
|
2015-06-17 00:24:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProtocolPreferencesMenu::uatPreferenceTriggered()
|
|
|
|
{
|
|
|
|
UatPreferenceAction *upa = static_cast<UatPreferenceAction *>(QObject::sender());
|
|
|
|
if (!upa) return;
|
|
|
|
|
|
|
|
upa->showUatDialog();
|
|
|
|
}
|