diff options
author | Guy Harris <gharris@sonic.net> | 2021-03-14 06:51:36 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2021-03-14 06:51:36 -0700 |
commit | 01151ec332f6232cd7b86d1b9026e54decb88203 (patch) | |
tree | 302dd732190b8740bc4c6c057e1440f62b89cb2c /ui | |
parent | 006f0ab571b8848ead23068ff91f52fe6a3680cc (diff) |
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.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/export_pdu_ui_utils.c | 49 | ||||
-rw-r--r-- | ui/export_pdu_ui_utils.h | 4 | ||||
-rw-r--r-- | ui/qt/export_pdu_dialog.cpp | 9 |
3 files changed, 27 insertions, 35 deletions
diff --git a/ui/export_pdu_ui_utils.c b/ui/export_pdu_ui_utils.c index 39e9cdbd37..c9a7c1c878 100644 --- a/ui/export_pdu_ui_utils.c +++ b/ui/export_pdu_ui_utils.c @@ -30,9 +30,11 @@ #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; int file_type_subtype; char *capfile_name, *comment; @@ -40,39 +42,54 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data) 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; } /* Write a pcapng file... */ file_type_subtype = wtap_pcapng_file_type_subtype(); /* ...with this comment */ 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); g_free(comment); if (!status) { cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file", err, err_info, file_type_subtype); - 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)) { @@ -91,27 +108,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 * diff --git a/ui/export_pdu_ui_utils.h b/ui/export_pdu_ui_utils.h index 7b7310b9b1..5c72261ad3 100644 --- a/ui/export_pdu_ui_utils.h +++ b/ui/export_pdu_ui_utils.h @@ -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 diff --git a/ui/qt/export_pdu_dialog.cpp b/ui/qt/export_pdu_dialog.cpp index 227a3a6147..8595e9c33c 100644 --- a/ui/qt/export_pdu_dialog.cpp +++ b/ui/qt/export_pdu_dialog.cpp @@ -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() { |