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.
(backported from commit 01151ec332
)
This commit is contained in:
parent
6cbf30fa88
commit
7e0360206e
|
@ -30,46 +30,63 @@
|
|||
#include "tap_export_pdu.h"
|
||||
#include "export_pdu_ui_utils.h"
|
||||
|
||||
static void
|
||||
exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
|
||||
void
|
||||
do_export_pdu(const char *filter, const gchar *tap_name)
|
||||
{
|
||||
exp_pdu_t exp_pdu_tap_data;
|
||||
char *error;
|
||||
int import_file_fd;
|
||||
char *capfile_name, *comment;
|
||||
gboolean status;
|
||||
int err;
|
||||
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 */
|
||||
GError *err_tempfile = NULL;
|
||||
import_file_fd = create_tempfile(&capfile_name, "Wireshark_PDU_", NULL, &err_tempfile);
|
||||
if (import_file_fd < 0) {
|
||||
failure_alert_box("Temporary file could not be created: %s", err_tempfile->message);
|
||||
g_error_free(err_tempfile);
|
||||
goto end;
|
||||
g_free(capfile_name);
|
||||
return;
|
||||
}
|
||||
|
||||
comment = g_strdup_printf("Dump of PDUs from %s", cfile.filename);
|
||||
status = exp_pdu_open(exp_pdu_tap_data, import_file_fd, comment, &err,
|
||||
status = exp_pdu_open(&exp_pdu_tap_data, import_file_fd, comment, &err,
|
||||
&err_info);
|
||||
g_free(comment);
|
||||
if (!status) {
|
||||
cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file",
|
||||
err, err_info,
|
||||
WTAP_FILE_TYPE_SUBTYPE_PCAPNG);
|
||||
goto end;
|
||||
g_free(capfile_name);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Run the tap */
|
||||
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);
|
||||
/*
|
||||
* 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? */
|
||||
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 */
|
||||
goto end;
|
||||
g_free(capfile_name);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cf_read(&cfile, FALSE)) {
|
||||
|
@ -88,27 +105,9 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data)
|
|||
break;
|
||||
}
|
||||
|
||||
end:
|
||||
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
|
||||
*
|
||||
|
|
|
@ -19,9 +19,9 @@ extern "C" {
|
|||
|
||||
/**
|
||||
* 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
|
||||
|
|
|
@ -13,12 +13,9 @@
|
|||
#include "export_pdu_dialog.h"
|
||||
#include <ui_export_pdu_dialog.h>
|
||||
|
||||
#include <wiretap/pcap-encap.h>
|
||||
|
||||
#include <epan/tap.h>
|
||||
#include <epan/exported_pdu.h>
|
||||
|
||||
#include "ui/tap_export_pdu.h"
|
||||
#include "ui/export_pdu_ui_utils.h"
|
||||
|
||||
ExportPDUDialog::ExportPDUDialog(QWidget *parent) :
|
||||
|
@ -35,14 +32,10 @@ ExportPDUDialog::ExportPDUDialog(QWidget *parent) :
|
|||
}
|
||||
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& 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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue