aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorStig Bjørlykke <stig@bjorlykke.org>2020-06-30 10:28:30 +0200
committerStig Bjørlykke <stig@bjorlykke.org>2020-07-02 06:13:27 +0000
commit9a1a5fd22a9fa9c62595ff06020a0ae22a7aa33d (patch)
tree6e193dd22971c56d991f2cd0750f5968438826de /ui
parente312d073677232e63d3603d6e990b263da87ceef (diff)
Qt: Add copy from another profile for Decode As
Add a new button to the Decode As dialog to copy entries from another profile. Change-Id: Ia04edd063bd2eba14b2b14acfd53b03111646f7e Reviewed-on: https://code.wireshark.org/review/37616 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot Reviewed-by: Stig Bjørlykke <stig@bjorlykke.org>
Diffstat (limited to 'ui')
-rw-r--r--ui/qt/decode_as_dialog.cpp18
-rw-r--r--ui/qt/decode_as_dialog.h1
-rw-r--r--ui/qt/models/decode_as_model.cpp77
-rw-r--r--ui/qt/models/decode_as_model.h4
4 files changed, 99 insertions, 1 deletions
diff --git a/ui/qt/decode_as_dialog.cpp b/ui/qt/decode_as_dialog.cpp
index 6f1dea907d..ef91d5ffd8 100644
--- a/ui/qt/decode_as_dialog.cpp
+++ b/ui/qt/decode_as_dialog.cpp
@@ -18,6 +18,7 @@
#include "wsutil/filesystem.h"
#include <wsutil/utf8_entities.h>
+#include <ui/qt/widgets/copy_from_profile_button.h>
#include <ui/qt/utils/qt_ui_utils.h>
#include "wireshark_application.h"
@@ -72,6 +73,10 @@ DecodeAsDialog::DecodeAsDialog(QWidget *parent, capture_file *cf, bool create_ne
ui->pathLabel->setEnabled(true);
}
+ CopyFromProfileButton *copy_button = new CopyFromProfileButton(this, DECODE_AS_ENTRIES_FILE_NAME);
+ ui->buttonBox->addButton(copy_button, QDialogButtonBox::ActionRole);
+ connect(copy_button, &CopyFromProfileButton::copyProfile, this, &DecodeAsDialog::copyFromProfile);
+
fillTable();
connect(model_, SIGNAL(modelReset()), this, SLOT(modelRowsReset()));
@@ -130,6 +135,19 @@ void DecodeAsDialog::on_decodeAsTreeView_currentItemChanged(const QModelIndex &c
}
}
+void DecodeAsDialog::copyFromProfile(QString filename)
+{
+ const gchar *err = NULL;
+
+ if (!model_->copyFromProfile(filename, &err)) {
+ simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Error while loading %s: %s", filename.toUtf8().constData(), err);
+ }
+
+ resizeColumns();
+
+ ui->clearToolButton->setEnabled(model_->rowCount() > 0);
+}
+
void DecodeAsDialog::addRecord(bool copy_from_current)
{
const QModelIndex &current = ui->decodeAsTreeView->currentIndex();
diff --git a/ui/qt/decode_as_dialog.h b/ui/qt/decode_as_dialog.h
index 222b956a00..37f8065631 100644
--- a/ui/qt/decode_as_dialog.h
+++ b/ui/qt/decode_as_dialog.h
@@ -51,6 +51,7 @@ public slots:
void modelRowsReset();
private slots:
+ void copyFromProfile(QString filename);
void on_decodeAsTreeView_currentItemChanged(const QModelIndex &current, const QModelIndex &previous);
void on_newToolButton_clicked();
diff --git a/ui/qt/models/decode_as_model.cpp b/ui/qt/models/decode_as_model.cpp
index 8ffdc42d00..f525e3567a 100644
--- a/ui/qt/models/decode_as_model.cpp
+++ b/ui/qt/models/decode_as_model.cpp
@@ -8,6 +8,8 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
+#include <errno.h>
+
#include "decode_as_model.h"
#include <epan/to_str.h>
#include <epan/decode_as.h>
@@ -18,6 +20,7 @@
#include <epan/dissectors/packet-dcerpc.h>
#include <ui/qt/utils/qt_ui_utils.h>
+#include <wsutil/file_util.h>
#include <QVector>
@@ -426,6 +429,80 @@ bool DecodeAsModel::copyRow(int dst_row, int src_row)
return true;
}
+prefs_set_pref_e DecodeAsModel::readDecodeAsEntry(gchar *key, const gchar *value, void *private_data, gboolean)
+{
+ DecodeAsModel *model = (DecodeAsModel*)private_data;
+ if (model == NULL)
+ return PREFS_SET_OK;
+
+ if (strcmp(key, DECODE_AS_ENTRY) != 0) {
+ return PREFS_SET_NO_SUCH_PREF;
+ }
+
+ /* Parse into table, selector, initial, current */
+ gchar **values = g_strsplit_set(value, ",", 4);
+ DecodeAsItem *item = new DecodeAsItem();
+
+ dissector_table_t dissector_table = find_dissector_table(values[0]);
+
+ QString tableName(values[0]);
+ bool tableNameFound = false;
+ // Get the table values from the Decode As list because they are persistent
+ for (GList *cur = decode_as_list; cur; cur = cur->next) {
+ decode_as_t *entry = (decode_as_t *) cur->data;
+ if (tableName.compare(entry->table_name) == 0) {
+ item->tableName_ = entry->table_name;
+ item->tableUIName_ = get_dissector_table_ui_name(entry->table_name);
+ tableNameFound = true;
+ break;
+ }
+ }
+
+ if (!tableNameFound || !dissector_table) {
+ delete item;
+ g_strfreev(values);
+ return PREFS_SET_SYNTAX_ERR;
+ }
+
+ QString selector(values[1]);
+ ftenum_t selector_type = get_dissector_table_selector_type(item->tableName_);
+
+ if (IS_FT_STRING(selector_type)) {
+ item->selectorString_ = selector;
+ } else if (IS_FT_UINT(selector_type)) {
+ item->selectorUint_ = selector.toUInt(Q_NULLPTR, 0);
+ }
+
+ item->default_proto_ = values[2];
+ item->dissector_handle_ = dissector_table_get_dissector_handle(dissector_table, values[3]);
+ if (item->dissector_handle_) {
+ item->current_proto_ = values[3];
+ }
+
+ model->decode_as_items_ << item;
+ g_strfreev(values);
+
+ return PREFS_SET_OK;
+}
+
+bool DecodeAsModel::copyFromProfile(QString filename, const gchar **err)
+{
+ FILE *fp = ws_fopen(filename.toUtf8().constData(), "r");
+
+ if (fp == NULL) {
+ *err = g_strerror(errno);
+ return false;
+ }
+
+ beginInsertRows(QModelIndex(), rowCount(), rowCount());
+ read_prefs_file(filename.toUtf8().constData(), fp, readDecodeAsEntry, this);
+ endInsertRows();
+
+ fclose(fp);
+
+ return true;
+}
+
QString DecodeAsModel::entryString(const gchar *table_name, gconstpointer value)
{
QString entry_str;
diff --git a/ui/qt/models/decode_as_model.h b/ui/qt/models/decode_as_model.h
index 61b0aec059..de735ecb3b 100644
--- a/ui/qt/models/decode_as_model.h
+++ b/ui/qt/models/decode_as_model.h
@@ -74,6 +74,7 @@ public:
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
void clearAll();
bool copyRow(int dst_row, int src_row);
+ bool copyFromProfile(QString filename, const gchar **err);
static QString entryString(const gchar *table_name, gconstpointer value);
@@ -85,7 +86,8 @@ protected:
static void buildDceRpcChangedList(gpointer data, gpointer user_data);
static void gatherChangedEntries(const gchar *table_name, ftenum_t selector_type,
gpointer key, gpointer value, gpointer user_data);
-
+ static prefs_set_pref_e readDecodeAsEntry(gchar *key, const gchar *value,
+ void *user_data, gboolean return_range_errors);
private:
capture_file *cap_file_;