2015-01-13 21:00:59 +00:00
|
|
|
/* sctp_chunk_statistics_dialog.cpp
|
2013-12-13 11:29:11 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-12-13 07:25:30 +00:00
|
|
|
#include "sctp_chunk_statistics_dialog.h"
|
2015-06-25 16:17:03 +00:00
|
|
|
#include <ui_sctp_chunk_statistics_dialog.h>
|
2013-12-13 07:25:30 +00:00
|
|
|
#include "uat_dialog.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
SCTPChunkStatisticsDialog::SCTPChunkStatisticsDialog(QWidget *parent, sctp_assoc_info_t *assoc, capture_file *cf) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::SCTPChunkStatisticsDialog),
|
|
|
|
selected_assoc(assoc),
|
|
|
|
cap_file_(cf)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-11-17 07:51:12 +00:00
|
|
|
Qt::WindowFlags flags = Qt::Window | Qt::WindowSystemMenuHint
|
|
|
|
| Qt::WindowMinimizeButtonHint
|
|
|
|
| Qt::WindowMaximizeButtonHint
|
|
|
|
| Qt::WindowCloseButtonHint;
|
|
|
|
this->setWindowFlags(flags);
|
2013-12-13 10:56:14 +00:00
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
|
|
|
ui->tableWidget->verticalHeader()->setClickable(true);
|
|
|
|
ui->tableWidget->verticalHeader()->setMovable(true);
|
|
|
|
#else
|
2013-12-13 07:25:30 +00:00
|
|
|
ui->tableWidget->verticalHeader()->setSectionsClickable(true);
|
|
|
|
ui->tableWidget->verticalHeader()->setSectionsMovable(true);
|
2013-12-13 10:56:14 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-13 07:25:30 +00:00
|
|
|
|
|
|
|
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
ui->tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
|
|
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
|
|
|
ui->tableWidget->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
#else
|
|
|
|
ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
|
|
|
#endif
|
|
|
|
|
2013-12-17 10:22:00 +00:00
|
|
|
this->setWindowTitle(QString(tr("SCTP Chunk Statistics: %1 Port1 %2 Port2 %3")).arg(cf_get_display_name(cap_file_)).arg(selected_assoc->port1).arg(selected_assoc->port2));
|
2013-12-18 08:04:01 +00:00
|
|
|
// connect(ui->tableWidget->verticalHeader(), SIGNAL(sectionMoved(int,int,int)), this, SLOT(on_sectionMoved(int, int, int)));
|
2013-12-13 07:25:30 +00:00
|
|
|
|
|
|
|
ctx_menu_.addAction(ui->actionHideChunkType);
|
|
|
|
ctx_menu_.addAction(ui->actionChunkTypePreferences);
|
|
|
|
ctx_menu_.addAction(ui->actionShowAllChunkTypes);
|
|
|
|
initializeChunkMap();
|
|
|
|
fillTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
SCTPChunkStatisticsDialog::~SCTPChunkStatisticsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCTPChunkStatisticsDialog::initializeChunkMap()
|
|
|
|
{
|
|
|
|
struct chunkTypes temp;
|
|
|
|
gchar buf[16];
|
|
|
|
|
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
temp.id = i;
|
|
|
|
temp.row = i;
|
2015-08-25 13:16:29 +00:00
|
|
|
g_snprintf(buf, sizeof buf, "%d", i);
|
|
|
|
g_strlcpy(temp.name, val_to_str_const(i, chunk_type_values, "NA"), sizeof temp.name);
|
2013-12-13 07:25:30 +00:00
|
|
|
if (strcmp(temp.name, "NA") == 0) {
|
|
|
|
temp.hide = 1;
|
2015-08-25 13:16:29 +00:00
|
|
|
g_strlcpy(temp.name, buf, sizeof temp.name);
|
2013-12-13 07:25:30 +00:00
|
|
|
} else {
|
|
|
|
temp.hide = 0;
|
|
|
|
}
|
|
|
|
chunks.insert(i, temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCTPChunkStatisticsDialog::fillTable(bool all)
|
|
|
|
{
|
2015-11-25 16:20:11 +00:00
|
|
|
FILE* fp = NULL;
|
2013-12-13 07:25:30 +00:00
|
|
|
|
|
|
|
pref_t *pref = prefs_find_preference(prefs_find_module("sctp"),"statistics_chunk_types");
|
|
|
|
uat_t *uat = pref->varp.uat;
|
|
|
|
gchar* fname = uat_get_actual_filename(uat,TRUE);
|
|
|
|
bool init = false;
|
|
|
|
|
2016-01-23 12:18:30 +00:00
|
|
|
if (!fname) {
|
2013-12-13 07:25:30 +00:00
|
|
|
init = true;
|
|
|
|
} else {
|
|
|
|
fp = ws_fopen(fname,"r");
|
|
|
|
|
|
|
|
if (!fp && errno == ENOENT) {
|
|
|
|
init = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_free (fname);
|
|
|
|
|
|
|
|
if (init || all) {
|
|
|
|
int j = 0;
|
2013-12-18 08:04:01 +00:00
|
|
|
|
2013-12-13 07:25:30 +00:00
|
|
|
for (int i = 0; i < chunks.size(); i++) {
|
|
|
|
if (!chunks.value(i).hide) {
|
|
|
|
ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
|
|
|
|
ui->tableWidget->setVerticalHeaderItem(j, new QTableWidgetItem(QString("%1").arg(chunks.value(i).name)));
|
|
|
|
ui->tableWidget->setItem(j,0, new QTableWidgetItem(QString("%1").arg(selected_assoc->chunk_count[chunks.value(i).id])));
|
|
|
|
ui->tableWidget->setItem(j,1, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep1_chunk_count[chunks.value(i).id])));
|
|
|
|
ui->tableWidget->setItem(j,2, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep2_chunk_count[chunks.value(i).id])));
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < chunks.size(); i++) {
|
|
|
|
if (chunks.value(i).hide) {
|
|
|
|
ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
|
2013-12-17 08:56:47 +00:00
|
|
|
ui->tableWidget->setVerticalHeaderItem(j, new QTableWidgetItem(QString("%1").arg(chunks.value(i).name)));
|
2013-12-13 07:25:30 +00:00
|
|
|
ui->tableWidget->setItem(j,0, new QTableWidgetItem(QString("%1").arg(selected_assoc->chunk_count[chunks.value(i).id])));
|
|
|
|
ui->tableWidget->setItem(j,1, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep1_chunk_count[chunks.value(i).id])));
|
2013-12-17 08:56:47 +00:00
|
|
|
ui->tableWidget->setItem(j,2, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep2_chunk_count[chunks.value(i).id])));
|
2013-12-13 07:25:30 +00:00
|
|
|
ui->tableWidget->hideRow(j);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2013-12-17 08:56:47 +00:00
|
|
|
char line[100];
|
2013-12-13 07:25:30 +00:00
|
|
|
char *token, id[5];
|
|
|
|
int i = 0, j = 0;
|
|
|
|
struct chunkTypes temp;
|
|
|
|
|
2014-09-07 09:15:45 +00:00
|
|
|
while (fgets(line, (int)sizeof line, fp)) {
|
2013-12-18 08:04:01 +00:00
|
|
|
if (line[0] == '#')
|
|
|
|
continue;
|
2013-12-13 07:25:30 +00:00
|
|
|
token = strtok(line, ",");
|
|
|
|
/* Get rid of the quotation marks */
|
|
|
|
QString ch = QString(token).mid(1, (int)strlen(token)-2);
|
2015-08-25 13:16:29 +00:00
|
|
|
g_strlcpy(id, qPrintable(ch), sizeof id);
|
2013-12-13 07:25:30 +00:00
|
|
|
temp.id = atoi(id);
|
2015-08-25 13:16:29 +00:00
|
|
|
temp.hide = 0;
|
|
|
|
temp.name[0] = '\0';
|
2013-12-13 07:25:30 +00:00
|
|
|
while(token != NULL) {
|
|
|
|
token = strtok(NULL, ",");
|
|
|
|
if (token) {
|
|
|
|
if ((strstr(token, "Hide"))) {
|
|
|
|
temp.hide = 1;
|
|
|
|
} else if ((strstr(token, "Show"))) {
|
|
|
|
temp.hide = 0;
|
|
|
|
} else {
|
|
|
|
QString ch = QString(token).mid(1, (int)strlen(token)-2);
|
2015-08-25 13:16:29 +00:00
|
|
|
g_strlcpy(temp.name, qPrintable(ch), sizeof temp.name);
|
2013-12-13 07:25:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!temp.hide) {
|
|
|
|
ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
|
|
|
|
ui->tableWidget->setVerticalHeaderItem(j, new QTableWidgetItem(QString("%1").arg(temp.name)));
|
|
|
|
ui->tableWidget->setItem(j,0, new QTableWidgetItem(QString("%1").arg(selected_assoc->chunk_count[temp.id])));
|
|
|
|
ui->tableWidget->setItem(j,1, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep1_chunk_count[temp.id])));
|
|
|
|
ui->tableWidget->setItem(j,2, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep2_chunk_count[temp.id])));
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
chunks.insert(i, temp);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
j = ui->tableWidget->rowCount();
|
|
|
|
for (int i = 0; i < chunks.size(); i++) {
|
|
|
|
if (chunks.value(i).hide) {
|
|
|
|
ui->tableWidget->setRowCount(ui->tableWidget->rowCount()+1);
|
2013-12-17 08:56:47 +00:00
|
|
|
ui->tableWidget->setVerticalHeaderItem(j, new QTableWidgetItem(QString("%1").arg(chunks.value(i).name)));
|
2013-12-13 07:25:30 +00:00
|
|
|
ui->tableWidget->setItem(j,0, new QTableWidgetItem(QString("%1").arg(selected_assoc->chunk_count[chunks.value(i).id])));
|
|
|
|
ui->tableWidget->setItem(j,1, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep1_chunk_count[chunks.value(i).id])));
|
2013-12-17 08:56:47 +00:00
|
|
|
ui->tableWidget->setItem(j,2, new QTableWidgetItem(QString("%1").arg(selected_assoc->ep2_chunk_count[chunks.value(i).id])));
|
2013-12-13 07:25:30 +00:00
|
|
|
ui->tableWidget->hideRow(j);
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-25 16:20:11 +00:00
|
|
|
if (fp)
|
|
|
|
fclose(fp);
|
2013-12-13 07:25:30 +00:00
|
|
|
}
|
|
|
|
|
2016-01-23 12:18:30 +00:00
|
|
|
void SCTPChunkStatisticsDialog::contextMenuEvent(QContextMenuEvent * event)
|
2013-12-13 07:25:30 +00:00
|
|
|
{
|
|
|
|
selected_point = event->pos();
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->itemAt(selected_point.x(), selected_point.y()-60);
|
|
|
|
if (item) {
|
|
|
|
ctx_menu_.exec(event->globalPos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SCTPChunkStatisticsDialog::on_pushButton_clicked()
|
|
|
|
{
|
|
|
|
FILE* fp;
|
|
|
|
|
|
|
|
pref_t *pref = prefs_find_preference(prefs_find_module("sctp"),"statistics_chunk_types");
|
|
|
|
|
|
|
|
uat_t *uat = pref->varp.uat;
|
|
|
|
|
|
|
|
gchar* fname = uat_get_actual_filename(uat,TRUE);
|
|
|
|
|
2016-01-23 12:18:30 +00:00
|
|
|
if (!fname) {
|
2013-12-13 07:25:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
fp = ws_fopen(fname,"w");
|
|
|
|
|
|
|
|
if (!fp && errno == ENOENT) {
|
|
|
|
gchar *pf_dir_path = NULL;
|
|
|
|
if (create_persconffile_dir(&pf_dir_path) != 0) {
|
|
|
|
g_free (pf_dir_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fp = ws_fopen(fname,"w");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (fname);
|
|
|
|
|
|
|
|
fprintf(fp,"# This file is automatically generated, DO NOT MODIFY.\n");
|
|
|
|
char str[40];
|
2015-12-03 12:47:33 +00:00
|
|
|
struct chunkTypes tempChunk;
|
2013-12-13 07:25:30 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < chunks.size(); i++) {
|
2015-12-03 12:47:33 +00:00
|
|
|
tempChunk = chunks.value(i);
|
|
|
|
g_snprintf(str, sizeof str, "\"%d\",\"%s\",\"%s\"\n", tempChunk.id, tempChunk.name, tempChunk.hide==0?"Show":"Hide");
|
2013-12-13 07:25:30 +00:00
|
|
|
fputs(str, fp);
|
|
|
|
void *rec = g_malloc0(uat->record_size);
|
|
|
|
uat_add_record(uat, rec, TRUE);
|
|
|
|
if (uat->free_cb) {
|
|
|
|
uat->free_cb(rec);
|
|
|
|
}
|
|
|
|
g_free(rec);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
2013-12-18 08:04:01 +00:00
|
|
|
/*void SCTPChunkStatisticsDialog::on_sectionMoved(int logicalIndex, int oldVisualIndex, int newVisualIndex)
|
2013-12-13 07:25:30 +00:00
|
|
|
{
|
2013-12-18 08:04:01 +00:00
|
|
|
}*/
|
2013-12-13 07:25:30 +00:00
|
|
|
|
|
|
|
void SCTPChunkStatisticsDialog::on_actionHideChunkType_triggered()
|
|
|
|
{
|
|
|
|
int row;
|
|
|
|
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->itemAt(selected_point.x(), selected_point.y()-60);
|
|
|
|
if (item) {
|
|
|
|
row = item->row();
|
|
|
|
ui->tableWidget->hideRow(row);
|
|
|
|
QTableWidgetItem *item = ui->tableWidget->verticalHeaderItem(row);
|
|
|
|
QMap<int, struct chunkTypes>::iterator iter;
|
|
|
|
for (iter = chunks.begin(); iter != chunks.end(); ++iter) {
|
|
|
|
if (strcmp(iter.value().name, item->text().toUtf8().constData()) == 0) {
|
|
|
|
iter.value().hide = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCTPChunkStatisticsDialog::on_actionChunkTypePreferences_triggered()
|
|
|
|
{
|
2015-01-10 00:50:09 +00:00
|
|
|
gchar* err = NULL;
|
2013-12-13 07:25:30 +00:00
|
|
|
|
|
|
|
pref_t *pref = prefs_find_preference(prefs_find_module("sctp"),"statistics_chunk_types");
|
|
|
|
uat_t *uat = pref->varp.uat;
|
|
|
|
uat_clear(uat);
|
|
|
|
|
2015-01-13 21:00:59 +00:00
|
|
|
if (!uat_load(pref->varp.uat, &err)) {
|
|
|
|
/* XXX - report this through the GUI */
|
2013-12-13 07:25:30 +00:00
|
|
|
printf("Error loading table '%s': %s",pref->varp.uat->name,err);
|
2015-01-10 00:50:09 +00:00
|
|
|
g_free(err);
|
2013-12-13 07:25:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
UatDialog *uatdialog = new UatDialog(this, pref->varp.uat);
|
|
|
|
uatdialog->exec();
|
2015-08-26 18:24:29 +00:00
|
|
|
// Emitting PacketDissectionChanged directly from a QDialog can cause
|
|
|
|
// problems on OS X.
|
|
|
|
wsApp->flushAppSignals();
|
|
|
|
|
2013-12-13 07:25:30 +00:00
|
|
|
ui->tableWidget->clear();
|
|
|
|
ui->tableWidget->setRowCount(0);
|
2013-12-17 10:22:00 +00:00
|
|
|
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(QString(tr("Association"))));
|
|
|
|
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(QString(tr("Endpoint 1"))));
|
|
|
|
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(QString(tr("Endpoint 2"))));
|
2013-12-13 07:25:30 +00:00
|
|
|
fillTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SCTPChunkStatisticsDialog::on_actionShowAllChunkTypes_triggered()
|
|
|
|
{
|
|
|
|
ui->tableWidget->clear();
|
|
|
|
ui->tableWidget->setRowCount(0);
|
2013-12-17 10:22:00 +00:00
|
|
|
ui->tableWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(QString(tr("Association"))));
|
|
|
|
ui->tableWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(QString(tr("Endpoint 1"))));
|
|
|
|
ui->tableWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(QString(tr("Endpoint 2"))));
|
2013-12-13 07:25:30 +00:00
|
|
|
initializeChunkMap();
|
|
|
|
fillTable(true);
|
|
|
|
}
|
2013-12-13 11:29:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* tab-width: 8
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
* End:
|
|
|
|
*
|
|
|
|
* ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
|
|
* :indentSize=4:tabSize=8:noTabs=true:
|
|
|
|
*/
|