diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-04-19 14:43:11 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-04-19 21:43:47 +0000 |
commit | 4362e63dd54d8d35603d81fd2468cfe710b88f3e (patch) | |
tree | 8d670fa2ff4042858f08d1330ab54516d351f865 | |
parent | 26cc3f06a7541578ed216ab37e8c07683f2e9b3a (diff) |
Have a common "capture file close alert box" routine.
Take the code from cf_read() to pop up an alert box and put it into
libui, with the name cfile_read_failure_alert_box(). Use it in a couple
of places where we pop up such an error dialog.
While we're at it, get rid of the "err" argument to rescan_file();
nobody uses what it returns.
Change-Id: Iba7099b95de24309359d94eb96f606020e2ff2c3
Reviewed-on: https://code.wireshark.org/review/21232
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | file.c | 105 | ||||
-rw-r--r-- | ui/alert_box.c | 64 | ||||
-rw-r--r-- | ui/alert_box.h | 9 |
3 files changed, 82 insertions, 96 deletions
@@ -737,41 +737,7 @@ cf_read(capture_file *cf, gboolean reloading) /* Put up a message box noting that the read failed somewhere along the line. Don't throw out the stuff we managed to read, though, if any. */ - switch (err) { - - case WTAP_ERR_UNSUPPORTED: - simple_error_message_box( - "The capture file contains record data that Wireshark doesn't support.\n(%s)", - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - - case WTAP_ERR_SHORT_READ: - simple_error_message_box( - "The capture file appears to have been cut short" - " in the middle of a packet."); - break; - - case WTAP_ERR_BAD_FILE: - simple_error_message_box( - "The capture file appears to be damaged or corrupt.\n(%s)", - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - - case WTAP_ERR_DECOMPRESS: - simple_error_message_box( - "The compressed capture file appears to be damaged or corrupt.\n(%s)", - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - - default: - simple_error_message_box( - "An error occurred while reading the" - " capture file: %s.", wtap_strerror(err)); - break; - } + cfile_read_failure_alert_box(NULL, err, err_info); return CF_READ_ERROR; } else return CF_READ_OK; @@ -1531,7 +1497,6 @@ cf_read_record_r(capture_file *cf, const frame_data *fdata, { int err; gchar *err_info; - gchar *display_basename; #ifdef WANT_PACKET_EDITOR /* if fdata->file_off == -1 it means packet was edited, and we must find data inside edited_frames tree */ @@ -1551,23 +1516,7 @@ cf_read_record_r(capture_file *cf, const frame_data *fdata, #endif if (!wtap_seek_read(cf->wth, fdata->file_off, phdr, buf, &err, &err_info)) { - display_basename = g_filename_display_basename(cf->filename); - switch (err) { - - case WTAP_ERR_BAD_FILE: - simple_error_message_box("An error occurred while reading from the file \"%s\": %s.\n(%s)", - display_basename, wtap_strerror(err), - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - - default: - simple_error_message_box( - "An error occurred while reading from the file \"%s\": %s.", - display_basename, wtap_strerror(err)); - break; - } - g_free(display_basename); + cfile_read_failure_alert_box(cf->filename, err, err_info); return FALSE; } return TRUE; @@ -4282,9 +4231,10 @@ cf_has_unsaved_data(capture_file *cf) * Quick scan to find packet offsets. */ static cf_read_status_t -rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) +rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) { const struct wtap_pkthdr *phdr; + int err; gchar *err_info; gchar *name_ptr; gint64 data_offset; @@ -4307,9 +4257,9 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) format than the original, and the user is not given a choice of which reader to use (only which format to save it in), so doing this makes sense for now. */ - cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, err, &err_info, TRUE); + cf->wth = wtap_open_offline(fname, WTAP_TYPE_AUTO, &err, &err_info, TRUE); if (cf->wth == NULL) { - cfile_open_failure_alert_box(fname, *err, err_info, FALSE, 0); + cfile_open_failure_alert_box(fname, err, err_info, FALSE, 0); return CF_READ_ERROR; } @@ -4357,7 +4307,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) framenum = 0; phdr = wtap_phdr(cf->wth); - while ((wtap_read(cf->wth, err, &err_info, &data_offset))) { + while ((wtap_read(cf->wth, &err, &err_info, &data_offset))) { framenum++; fdata = frame_data_sequence_find(cf->frames, framenum); fdata->file_off = data_offset; @@ -4433,46 +4383,11 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile, int *err) return CF_READ_ABORTED; } - if (*err != 0) { + if (err != 0) { /* Put up a message box noting that the read failed somewhere along the line. Don't throw out the stuff we managed to read, though, if any. */ - switch (*err) { - - case WTAP_ERR_UNSUPPORTED: - simple_error_message_box( - "The capture file contains record data that Wireshark doesn't support.\n(%s)", - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - - case WTAP_ERR_SHORT_READ: - simple_error_message_box( - "The capture file appears to have been cut short" - " in the middle of a packet."); - break; - - case WTAP_ERR_BAD_FILE: - simple_error_message_box( - "The capture file appears to be damaged or corrupt.\n(%s)", - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - - case WTAP_ERR_DECOMPRESS: - simple_error_message_box( - "The compressed capture file appears to be damaged or corrupt.\n" - "(%s)", - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - - default: - simple_error_message_box( - "An error occurred while reading the" - " capture file: %s.", wtap_strerror(*err)); - break; - } + cfile_read_failure_alert_box(NULL, err, err_info); return CF_READ_ERROR; } else return CF_READ_OK; @@ -4752,7 +4667,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, /* rescan_file will cause us to try all open_routines, so reset cfile's open_type */ cf->open_type = WTAP_TYPE_AUTO; - if (rescan_file(cf, fname, FALSE, &err) != CF_READ_OK) { + if (rescan_file(cf, fname, FALSE) != CF_READ_OK) { /* The rescan failed; just close the file. Either a dialog was popped up for the failure, so the user knows what happened, or they stopped the diff --git a/ui/alert_box.c b/ui/alert_box.c index 26d2b49d8c..bdf71e20fa 100644 --- a/ui/alert_box.c +++ b/ui/alert_box.c @@ -25,7 +25,6 @@ #include <string.h> - #include <wiretap/wtap.h> #include <wsutil/filesystem.h> @@ -209,6 +208,69 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, } /* + * Alert box for a failed attempt to read from a capture file. + * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value; + * "err_info" is assumed to be a string giving further information for + * some WTAP_ERR_ values. + */ +void +cfile_read_failure_alert_box(const char *filename, int err, gchar *err_info) +{ + gchar *display_name; + + if (filename == NULL) + display_name = g_strdup("capture file"); + else { + gchar *display_basename; + + display_basename = g_filename_display_basename(filename); + display_name = g_strdup_printf("capture file %s", display_basename); + g_free(display_basename); + } + + switch (err) { + + case WTAP_ERR_UNSUPPORTED: + simple_error_message_box( + "The %s contains record data that Wireshark doesn't support.\n(%s)", + display_name, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + case WTAP_ERR_SHORT_READ: + simple_error_message_box( + "The %s appears to have been cut short in the middle of a packet.", + display_name); + break; + + case WTAP_ERR_BAD_FILE: + simple_error_message_box( + "The %s appears to be damaged or corrupt.\n(%s)", + display_name, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + case WTAP_ERR_DECOMPRESS: + simple_error_message_box( + "The compressed %s appears to be damaged or corrupt.\n(%s)", + display_name, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + default: + simple_error_message_box( + "An error occurred while reading the %s: %s.", + display_name, + wtap_strerror(err)); + break; + } + g_free(display_name); +} + +/* * Alert box for a failed attempt to close a capture file. * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value. * diff --git a/ui/alert_box.h b/ui/alert_box.h index bd19963279..1660749dc7 100644 --- a/ui/alert_box.h +++ b/ui/alert_box.h @@ -53,6 +53,15 @@ extern void cfile_open_failure_alert_box(const char *filename, int err, int file_type); /* + * Alert box for a failed attempt to read from a capture file. + * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value; + * "err_info" is assumed to be a string giving further information for + * some WTAP_ERR_ values. + */ +extern void cfile_read_failure_alert_box(const char *filename, int err, + gchar *err_info); + +/* * Alert box for a failed attempt to close a capture file. * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value. * |