Get rid of local_eo_save_entry().

Have eo_save_entry() use the report_ routines to report errors, so they
pop up a dialog in Wireshark and print an error message in command-line
programs such as TShark.  Use it instead of local_eo_save_entry().

Change-Id: I689fd880ff2a31486372374560129ee9d9692b1e
Reviewed-on: https://code.wireshark.org/review/31294
Petri-Dish: Guy Harris <guy@alum.mit.edu>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2019-01-01 11:50:57 -08:00
parent bfe81ab390
commit bac10e5869
2 changed files with 5 additions and 58 deletions

View File

@ -26,58 +26,6 @@
#include <ui/export_object_ui.h>
#include "tap-exportobject.h"
/* XXX - This is effectively a copy of eo_save_entry with the "GUI alerts"
* removed to accomodate tshark
*/
static gboolean
local_eo_save_entry(const gchar *save_as_filename, export_object_entry_t *entry)
{
int to_fd;
gint64 bytes_left;
int bytes_to_write;
ssize_t bytes_written;
guint8 *ptr;
to_fd = ws_open(save_as_filename, O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0644);
if(to_fd == -1) { /* An error occurred */
return FALSE;
}
/*
* The third argument to _write() on Windows is an unsigned int,
* so, on Windows, that's the size of the third argument to
* ws_write().
*
* The third argument to write() on UN*X is a size_t, although
* the return value is an ssize_t, so one probably shouldn't
* write more than the max value of an ssize_t.
*
* In either case, there's no guarantee that a gint64 such as
* payload_len can be passed to ws_write(), so we write in
* chunks of, at most 2^31 bytes.
*/
ptr = entry->payload_data;
bytes_left = entry->payload_len;
while (bytes_left != 0) {
if (bytes_left > 0x40000000)
bytes_to_write = 0x40000000;
else
bytes_to_write = (int)bytes_left;
bytes_written = ws_write(to_fd, ptr, bytes_to_write);
if(bytes_written <= 0) {
ws_close(to_fd);
return FALSE;
}
bytes_left -= bytes_written;
ptr += bytes_written;
}
if (ws_close(to_fd) < 0) {
return FALSE;
}
return TRUE;
}
typedef struct _export_object_list_gui_t {
GSList *entries;
register_eo_t* eo;
@ -193,7 +141,7 @@ eo_draw(void *tapdata)
g_string_free(safe_filename, TRUE);
} while (g_file_test(save_as_fullpath, G_FILE_TEST_EXISTS) && ++count < 1000);
count = 0;
if (!local_eo_save_entry(save_as_fullpath, entry))
if (!eo_save_entry(save_as_fullpath, entry, TRUE))
all_saved = FALSE;
g_free(save_as_fullpath);
save_as_fullpath = NULL;

View File

@ -23,8 +23,7 @@
#include <wiretap/wtap.h>
#include <wsutil/file_util.h>
#include <ui/alert_box.h>
#include <wsutil/report_message.h>
#include "export_object_ui.h"
@ -42,7 +41,7 @@ eo_save_entry(const gchar *save_as_filename, export_object_entry_t *entry, gbool
O_BINARY, 0644);
if(to_fd == -1) { /* An error occurred */
if (show_err)
open_failure_alert_box(save_as_filename, errno, TRUE);
report_open_failure(save_as_filename, errno, TRUE);
return FALSE;
}
@ -73,7 +72,7 @@ eo_save_entry(const gchar *save_as_filename, export_object_entry_t *entry, gbool
else
err = WTAP_ERR_SHORT_WRITE;
if (show_err)
write_failure_alert_box(save_as_filename, err);
report_write_failure(save_as_filename, err);
ws_close(to_fd);
return FALSE;
}
@ -82,7 +81,7 @@ eo_save_entry(const gchar *save_as_filename, export_object_entry_t *entry, gbool
}
if (ws_close(to_fd) < 0) {
if (show_err)
write_failure_alert_box(save_as_filename, errno);
report_write_failure(save_as_filename, errno);
return FALSE;
}