forked from osmocom/wireshark
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>
This commit is contained in:
parent
e312d07367
commit
9a1a5fd22a
|
@ -40,6 +40,7 @@ since version 3.2.0:
|
|||
* Dissector based on Protobuf can register itself to a new 'protobuf_field' dissector table,
|
||||
which is keyed with the full names of fields, for further parsing fields of BYETS or STRING type.
|
||||
* Wireshark is able to decode, play and save iLBC payload on platforms where iLBC library (https://github.com/TimothyGu/libilbc) is available.
|
||||
* Decode As entries can now be copied from other profiles using a button in the dialog.
|
||||
|
||||
// === Removed Features and Support
|
||||
|
||||
|
|
|
@ -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 ¤t = ui->decodeAsTreeView->currentIndex();
|
||||
|
|
|
@ -51,6 +51,7 @@ public slots:
|
|||
void modelRowsReset();
|
||||
|
||||
private slots:
|
||||
void copyFromProfile(QString filename);
|
||||
void on_decodeAsTreeView_currentItemChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
|
||||
void on_newToolButton_clicked();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_;
|
||||
|
|
Loading…
Reference in New Issue