diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-04-20 11:23:51 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-04-20 18:24:20 +0000 |
commit | 9e9d284d9157a8b79964015be868f4e8c43274c3 (patch) | |
tree | bad43c0cd5b46eb04fd25ed9a5cf6f598d731391 /ui/alert_box.c | |
parent | d09ef614598cf6b714059f39191f09af5701bc93 (diff) |
Have separate routines for open-for-reading and open-for-writing errors.
Expand comments while we're at it.
Change-Id: I6dcc791eab1c9e323a9572f3d54720d223bdd64b
Reviewed-on: https://code.wireshark.org/review/21252
Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ui/alert_box.c')
-rw-r--r-- | ui/alert_box.c | 147 |
1 files changed, 89 insertions, 58 deletions
diff --git a/ui/alert_box.c b/ui/alert_box.c index 9701654c83..8f870269e9 100644 --- a/ui/alert_box.c +++ b/ui/alert_box.c @@ -58,14 +58,10 @@ vwarning_alert_box(const char *msg_format, va_list ap) } /* - * Alert box for a failed attempt to open or create 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; "for_writing" is TRUE if the file is being - * opened for writing and FALSE if it's being opened for reading; - * "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value for the type - * and subtype of file being opened for writing (it's ignored for - * opening-for-reading errors). + * Alert box for a failed attempt to open a capture file for reading. + * "filename" is the name of the file being opened; "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.. * * XXX - add explanatory secondary text for at least some of the errors; * various HIGs suggest that you should, for example, suggest that the @@ -74,8 +70,7 @@ vwarning_alert_box(const char *msg_format, va_list ap) * typical Wireshark user is, but.... */ void -cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, - gboolean for_writing, int file_type_subtype) +cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info) { gchar *display_basename; @@ -91,7 +86,6 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, break; case WTAP_ERR_RANDOM_OPEN_PIPE: - /* Seen only when opening a capture file for reading. */ simple_error_message_box( "The file \"%s\" is a pipe or FIFO; Wireshark can't read pipe or FIFO files.\n" "To capture from a pipe or FIFO use wireshark -i -", @@ -99,14 +93,12 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, break; case WTAP_ERR_FILE_UNKNOWN_FORMAT: - /* Seen only when opening a capture file for reading. */ simple_error_message_box( "The file \"%s\" isn't a capture file in a format Wireshark understands.", display_basename); break; case WTAP_ERR_UNSUPPORTED: - /* Seen only when opening a capture file for reading. */ simple_error_message_box( "The file \"%s\" contains record data that Wireshark doesn't support.\n" "(%s)", @@ -115,8 +107,87 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, g_free(err_info); break; + case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED: + simple_error_message_box( + "The file \"%s\" is a capture for a network type that Wireshark doesn't support.", + display_basename); + break; + + case WTAP_ERR_BAD_FILE: + simple_error_message_box( + "The file \"%s\" appears to be damaged or corrupt.\n" + "(%s)", + display_basename, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + case WTAP_ERR_CANT_OPEN: + simple_error_message_box( + "The file \"%s\" could not be opened for some unknown reason.", + display_basename); + break; + + case WTAP_ERR_SHORT_READ: + simple_error_message_box( + "The file \"%s\" appears to have been cut short" + " in the middle of a packet or other data.", + display_basename); + break; + + case WTAP_ERR_DECOMPRESS: + simple_error_message_box( + "The file \"%s\" cannot be decompressed; it may be damaged or corrupt.\n" + "(%s)", display_basename, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + default: + simple_error_message_box( + "The file \"%s\" could not be opened: %s.", + display_basename, + wtap_strerror(err)); + break; + } + g_free(display_basename); + } else { + /* OS error. */ + open_failure_alert_box(filename, err, FALSE); + } +} + +/* + * Alert box for a failed attempt to open a capture file for writing. + * "filename" is the name of the file being opened; "err" is assumed + * to be a UNIX-style errno or a WTAP_ERR_ value; "file_type_subtype" + * is a WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file + * being opened. + * + * XXX - add explanatory secondary text for at least some of the errors; + * various HIGs suggest that you should, for example, suggest that the + * user remove files if the file system is full. Perhaps that's because + * they're providing guidelines for people less sophisticated than the + * typical Wireshark user is, but.... + */ +void +cfile_dump_open_failure_alert_box(const char *filename, int err, + int file_type_subtype) +{ + gchar *display_basename; + + if (err < 0) { + /* Wiretap error. */ + display_basename = g_filename_display_basename(filename); + switch (err) { + + case WTAP_ERR_NOT_REGULAR_FILE: + simple_error_message_box( + "The file \"%s\" is a \"special file\" or socket or other non-regular file.", + display_basename); + break; + case WTAP_ERR_CANT_WRITE_TO_PIPE: - /* Seen only when opening a capture file for writing. */ simple_error_message_box( "The file \"%s\" is a pipe, and %s capture files can't be " "written to a pipe.", @@ -124,53 +195,22 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, break; case WTAP_ERR_UNWRITABLE_FILE_TYPE: - /* Seen only when opening a capture file for writing. */ simple_error_message_box( "Wireshark doesn't support writing capture files in that format."); break; case WTAP_ERR_UNWRITABLE_ENCAP: - /* Seen only when opening a capture file for writing. */ simple_error_message_box("Wireshark can't save this capture in that format."); break; case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED: - if (for_writing) { - simple_error_message_box( - "Wireshark can't save this capture in that format."); - } else { - simple_error_message_box( - "The file \"%s\" is a capture for a network type that Wireshark doesn't support.", - display_basename); - } - break; - - case WTAP_ERR_BAD_FILE: - /* Seen only when opening a capture file for reading. */ simple_error_message_box( - "The file \"%s\" appears to be damaged or corrupt.\n" - "(%s)", - display_basename, - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); + "Wireshark can't save this capture in that format."); break; case WTAP_ERR_CANT_OPEN: - if (for_writing) { - simple_error_message_box( - "The file \"%s\" could not be created for some unknown reason.", - display_basename); - } else { - simple_error_message_box( - "The file \"%s\" could not be opened for some unknown reason.", - display_basename); - } - break; - - case WTAP_ERR_SHORT_READ: simple_error_message_box( - "The file \"%s\" appears to have been cut short" - " in the middle of a packet or other data.", + "The file \"%s\" could not be created for some unknown reason.", display_basename); break; @@ -185,26 +225,17 @@ cfile_open_failure_alert_box(const char *filename, int err, gchar *err_info, "This file type cannot be written as a compressed file."); break; - case WTAP_ERR_DECOMPRESS: - simple_error_message_box( - "The file \"%s\" cannot be decompressed; it may be damaged or corrupt.\n" - "(%s)", display_basename, - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - default: simple_error_message_box( - "The file \"%s\" could not be %s: %s.", + "The file \"%s\" could not be created: %s.", display_basename, - for_writing ? "created" : "opened", wtap_strerror(err)); break; } g_free(display_basename); } else { /* OS error. */ - open_failure_alert_box(filename, err, for_writing); + open_failure_alert_box(filename, err, TRUE); } } |