forked from osmocom/wireshark
Clean up "Export PDUs to File" code.
Combine exp_pdu_file_open() is called only by do_export_pdu(); just combine them into one routine. Get rid of the exp_pdu_t * argument to do_export_pdu(); instead, have the exp_pdu_t structure be a local variable in that routine. There's no need to initialize exp_pdu_data.pkt_encap in ExportPDUDialog::on_buttonBox_accepted() - do_export_pdu() already does so. The return value of do_export_pdu() isn't used; don't return anything.
This commit is contained in:
parent
006f0ab571
commit
01151ec332
|
@ -30,9 +30,11 @@
|
||||||
#include "tap_export_pdu.h"
|
#include "tap_export_pdu.h"
|
||||||
#include "export_pdu_ui_utils.h"
|
#include "export_pdu_ui_utils.h"
|
||||||
|
|
||||||
static void
|
void
|
||||||
exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
|
do_export_pdu(const char *filter, const gchar *tap_name)
|
||||||
{
|
{
|
||||||
|
exp_pdu_t exp_pdu_tap_data;
|
||||||
|
char *error;
|
||||||
int import_file_fd;
|
int import_file_fd;
|
||||||
int file_type_subtype;
|
int file_type_subtype;
|
||||||
char *capfile_name, *comment;
|
char *capfile_name, *comment;
|
||||||
|
@ -40,39 +42,54 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
|
||||||
int err;
|
int err;
|
||||||
gchar *err_info;
|
gchar *err_info;
|
||||||
|
|
||||||
|
error = exp_pdu_pre_open(tap_name, filter, &exp_pdu_tap_data);
|
||||||
|
if (error) {
|
||||||
|
/* Error. We failed to attach to the tap. Clean up */
|
||||||
|
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error);
|
||||||
|
g_free(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Choose a random name for the temporary import buffer */
|
/* Choose a random name for the temporary import buffer */
|
||||||
GError *err_tempfile = NULL;
|
GError *err_tempfile = NULL;
|
||||||
import_file_fd = create_tempfile(&capfile_name, "Wireshark_PDU_", NULL, &err_tempfile);
|
import_file_fd = create_tempfile(&capfile_name, "Wireshark_PDU_", NULL, &err_tempfile);
|
||||||
if (import_file_fd < 0) {
|
if (import_file_fd < 0) {
|
||||||
failure_alert_box("Temporary file could not be created: %s", err_tempfile->message);
|
failure_alert_box("Temporary file could not be created: %s", err_tempfile->message);
|
||||||
g_error_free(err_tempfile);
|
g_error_free(err_tempfile);
|
||||||
goto end;
|
g_free(capfile_name);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a pcapng file... */
|
/* Write a pcapng file... */
|
||||||
file_type_subtype = wtap_pcapng_file_type_subtype();
|
file_type_subtype = wtap_pcapng_file_type_subtype();
|
||||||
/* ...with this comment */
|
/* ...with this comment */
|
||||||
comment = g_strdup_printf("Dump of PDUs from %s", cfile.filename);
|
comment = g_strdup_printf("Dump of PDUs from %s", cfile.filename);
|
||||||
status = exp_pdu_open(exp_pdu_tap_data, file_type_subtype, import_file_fd,
|
status = exp_pdu_open(&exp_pdu_tap_data, file_type_subtype, import_file_fd,
|
||||||
comment, &err, &err_info);
|
comment, &err, &err_info);
|
||||||
g_free(comment);
|
g_free(comment);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file",
|
cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file",
|
||||||
err, err_info, file_type_subtype);
|
err, err_info, file_type_subtype);
|
||||||
goto end;
|
g_free(capfile_name);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run the tap */
|
/* Run the tap */
|
||||||
cf_retap_packets(&cfile);
|
cf_retap_packets(&cfile);
|
||||||
|
|
||||||
if (!exp_pdu_close(exp_pdu_tap_data, &err, &err_info)) {
|
if (!exp_pdu_close(&exp_pdu_tap_data, &err, &err_info)) {
|
||||||
cfile_close_failure_alert_box(capfile_name, err, err_info);
|
cfile_close_failure_alert_box(capfile_name, err, err_info);
|
||||||
|
/*
|
||||||
|
* XXX - remove the temporary file and don't open it as
|
||||||
|
* the current capture?
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX: should this use the open_routine type in the cfile instead of WTAP_TYPE_AUTO? */
|
/* XXX: should this use the open_routine type in the cfile instead of WTAP_TYPE_AUTO? */
|
||||||
if (cf_open(&cfile, capfile_name, WTAP_TYPE_AUTO, TRUE /* temporary file */, &err) != CF_OK) {
|
if (cf_open(&cfile, capfile_name, WTAP_TYPE_AUTO, TRUE /* temporary file */, &err) != CF_OK) {
|
||||||
/* cf_open() has put up a dialog box for the error */
|
/* cf_open() has put up a dialog box for the error */
|
||||||
goto end;
|
g_free(capfile_name);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cf_read(&cfile, FALSE)) {
|
switch (cf_read(&cfile, FALSE)) {
|
||||||
|
@ -91,27 +108,9 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
end:
|
|
||||||
g_free(capfile_name);
|
g_free(capfile_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
do_export_pdu(const char *filter, const gchar *tap_name, exp_pdu_t *exp_pdu_tap_data)
|
|
||||||
{
|
|
||||||
char *error;
|
|
||||||
error = exp_pdu_pre_open(tap_name, filter, exp_pdu_tap_data);
|
|
||||||
if (error) {
|
|
||||||
/* Error. We failed to attach to the tap. Clean up */
|
|
||||||
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "%s", error);
|
|
||||||
g_free(error);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
exp_pdu_file_open(exp_pdu_tap_data);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Editor modelines
|
* Editor modelines
|
||||||
*
|
*
|
||||||
|
|
|
@ -19,9 +19,9 @@ extern "C" {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filters the current opened capture file into a temporary file. On success,
|
* Filters the current opened capture file into a temporary file. On success,
|
||||||
* TRUE is returned and the filtered file is opened into the UI.
|
* the filtered file is opened into the UI.
|
||||||
*/
|
*/
|
||||||
gboolean do_export_pdu(const char *filter, const gchar *tap_name, exp_pdu_t *data);
|
void do_export_pdu(const char *filter, const gchar *tap_name);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -13,12 +13,9 @@
|
||||||
#include "export_pdu_dialog.h"
|
#include "export_pdu_dialog.h"
|
||||||
#include <ui_export_pdu_dialog.h>
|
#include <ui_export_pdu_dialog.h>
|
||||||
|
|
||||||
#include <wiretap/pcap-encap.h>
|
|
||||||
|
|
||||||
#include <epan/tap.h>
|
#include <epan/tap.h>
|
||||||
#include <epan/exported_pdu.h>
|
#include <epan/exported_pdu.h>
|
||||||
|
|
||||||
#include "ui/tap_export_pdu.h"
|
|
||||||
#include "ui/export_pdu_ui_utils.h"
|
#include "ui/export_pdu_ui_utils.h"
|
||||||
|
|
||||||
ExportPDUDialog::ExportPDUDialog(QWidget *parent) :
|
ExportPDUDialog::ExportPDUDialog(QWidget *parent) :
|
||||||
|
@ -35,14 +32,10 @@ ExportPDUDialog::ExportPDUDialog(QWidget *parent) :
|
||||||
}
|
}
|
||||||
void ExportPDUDialog::on_buttonBox_accepted()
|
void ExportPDUDialog::on_buttonBox_accepted()
|
||||||
{
|
{
|
||||||
exp_pdu_t exp_pdu_data;
|
|
||||||
|
|
||||||
exp_pdu_data.pkt_encap = wtap_wtap_encap_to_pcap_encap(WTAP_ENCAP_WIRESHARK_UPPER_PDU);
|
|
||||||
|
|
||||||
const QByteArray& filter = ui->displayFilterLineEdit->text().toUtf8();
|
const QByteArray& filter = ui->displayFilterLineEdit->text().toUtf8();
|
||||||
const QByteArray& tap_name = ui->comboBox->currentText().toUtf8();
|
const QByteArray& tap_name = ui->comboBox->currentText().toUtf8();
|
||||||
|
|
||||||
do_export_pdu(filter.constData(), tap_name.constData(), &exp_pdu_data);
|
do_export_pdu(filter.constData(), tap_name.constData());
|
||||||
}
|
}
|
||||||
ExportPDUDialog::~ExportPDUDialog()
|
ExportPDUDialog::~ExportPDUDialog()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue