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 | |
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>
-rw-r--r-- | capinfos.c | 3 | ||||
-rw-r--r-- | captype.c | 3 | ||||
-rw-r--r-- | editcap.c | 27 | ||||
-rw-r--r-- | file.c | 16 | ||||
-rw-r--r-- | reordercap.c | 7 | ||||
-rw-r--r-- | sharkd.c | 2 | ||||
-rw-r--r-- | tshark.c | 9 | ||||
-rw-r--r-- | ui/alert_box.c | 147 | ||||
-rw-r--r-- | ui/alert_box.h | 25 | ||||
-rw-r--r-- | ui/export_pdu_ui_utils.c | 5 | ||||
-rw-r--r-- | ui/failure_message.c | 168 | ||||
-rw-r--r-- | ui/failure_message.h | 53 | ||||
-rw-r--r-- | ui/gtk/file_import_dlg.c | 5 | ||||
-rw-r--r-- | ui/qt/import_text_dialog.cpp | 2 |
14 files changed, 269 insertions, 203 deletions
diff --git a/capinfos.c b/capinfos.c index 647b6cb093..f049864673 100644 --- a/capinfos.c +++ b/capinfos.c @@ -1725,8 +1725,7 @@ main(int argc, char *argv[]) wth = wtap_open_offline(argv[opt], WTAP_TYPE_AUTO, &err, &err_info, FALSE); if (!wth) { - cfile_open_failure_message("capinfos", argv[opt], err, err_info, FALSE, - WTAP_TYPE_AUTO); + cfile_open_failure_message("capinfos", argv[opt], err, err_info); overall_error_status = 2; /* remember that an error has occurred */ if (!continue_after_wtap_open_offline_failure) goto exit; @@ -219,8 +219,7 @@ main(int argc, char *argv[]) if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT) printf("%s: unknown\n", argv[i]); else { - cfile_open_failure_message("captype", argv[i], err, err_info, FALSE, - WTAP_TYPE_AUTO); + cfile_open_failure_message("captype", argv[i], err, err_info); overall_error_status = 2; /* remember that an error has occurred */ } } @@ -1351,8 +1351,8 @@ main(int argc, char *argv[]) wth = wtap_open_offline(argv[optind], WTAP_TYPE_AUTO, &read_err, &read_err_info, FALSE); if (!wth) { - cfile_open_failure_message("editap", argv[optind], read_err, - read_err_info, FALSE, WTAP_TYPE_AUTO); + cfile_open_failure_message("editcap", argv[optind], read_err, + read_err_info); ret = INVALID_FILE; goto clean_exit; } @@ -1423,9 +1423,8 @@ main(int argc, char *argv[]) shb_hdrs, idb_inf, nrb_hdrs, &write_err); if (pdh == NULL) { - cfile_open_failure_message("editcap", filename, - write_err, NULL, TRUE, - out_frame_type); + cfile_dump_open_failure_message("editcap", filename, + write_err, out_frame_type); ret = INVALID_FILE; goto clean_exit; } @@ -1465,9 +1464,9 @@ main(int argc, char *argv[]) shb_hdrs, idb_inf, nrb_hdrs, &write_err); if (pdh == NULL) { - cfile_open_failure_message("editcap", filename, - write_err, NULL, TRUE, - out_frame_type); + cfile_dump_open_failure_message("editcap", filename, + write_err, + out_frame_type); ret = INVALID_FILE; goto clean_exit; } @@ -1495,9 +1494,9 @@ main(int argc, char *argv[]) snaplen ? MIN(snaplen, wtap_snapshot_length(wth)) : wtap_snapshot_length(wth), shb_hdrs, idb_inf, nrb_hdrs, &write_err); if (pdh == NULL) { - cfile_open_failure_message("editcap", filename, - write_err, NULL, TRUE, - out_frame_type); + cfile_dump_open_failure_message("editcap", filename, + write_err, + out_frame_type); ret = INVALID_FILE; goto clean_exit; } @@ -1809,9 +1808,9 @@ main(int argc, char *argv[]) snaplen ? MIN(snaplen, wtap_snapshot_length(wth)): wtap_snapshot_length(wth), shb_hdrs, idb_inf, nrb_hdrs, &write_err); if (pdh == NULL) { - cfile_open_failure_message("editcap", filename, - write_err, NULL, TRUE, - out_frame_type); + cfile_dump_open_failure_message("editcap", filename, + write_err, + out_frame_type); ret = INVALID_FILE; goto clean_exit; } @@ -372,7 +372,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp return CF_OK; fail: - cfile_open_failure_alert_box(fname, *err, err_info, FALSE, 0); + cfile_open_failure_alert_box(fname, *err, err_info); return CF_ERROR; } @@ -1379,13 +1379,11 @@ cf_merge_files_to_tempfile(gpointer pd_window, char **out_filenamep, break; case MERGE_ERR_CANT_OPEN_INFILE: - cfile_open_failure_alert_box(in_filenames[err_fileno], err, err_info, - FALSE, 0); + cfile_open_failure_alert_box(in_filenames[err_fileno], err, err_info); break; case MERGE_ERR_CANT_OPEN_OUTFILE: - cfile_open_failure_alert_box(*out_filenamep, err, err_info, TRUE, - file_type); + cfile_dump_open_failure_alert_box(*out_filenamep, err, file_type); break; case MERGE_ERR_CANT_READ_INFILE: /* fall through */ @@ -4198,7 +4196,7 @@ rescan_file(capture_file *cf, const char *fname, gboolean is_tempfile) sense for now. */ 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); return CF_READ_ERROR; } @@ -4472,7 +4470,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, idb_inf = NULL; if (pdh == NULL) { - cfile_open_failure_alert_box(fname, err, NULL, TRUE, save_format); + cfile_dump_open_failure_alert_box(fname, err, save_format); goto fail; } @@ -4574,7 +4572,7 @@ cf_save_records(capture_file *cf, const char *fname, guint save_format, cf->open_type = WTAP_TYPE_AUTO; 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); cf_close(cf); } else { g_free(cf->filename); @@ -4704,7 +4702,7 @@ cf_export_specified_packets(capture_file *cf, const char *fname, idb_inf = NULL; if (pdh == NULL) { - cfile_open_failure_alert_box(fname, err, NULL, TRUE, save_format); + cfile_dump_open_failure_alert_box(fname, err, save_format); goto fail; } diff --git a/reordercap.c b/reordercap.c index a66f928fbc..ec7d4ce8ef 100644 --- a/reordercap.c +++ b/reordercap.c @@ -295,8 +295,7 @@ main(int argc, char *argv[]) open_routine reader to use, then the following needs to change. */ wth = wtap_open_offline(infile, WTAP_TYPE_AUTO, &err, &err_info, TRUE); if (wth == NULL) { - cfile_open_failure_message("reordercap", infile, err, err_info, - FALSE, WTAP_TYPE_AUTO); + cfile_open_failure_message("reordercap", infile, err, err_info); ret = OPEN_ERROR; goto clean_exit; } @@ -318,8 +317,8 @@ main(int argc, char *argv[]) idb_inf = NULL; if (pdh == NULL) { - cfile_open_failure_message("reordercap", outfile, err, err_info, TRUE, - wtap_file_type_subtype(wth)); + cfile_dump_open_failure_message("reordercap", outfile, err, + wtap_file_type_subtype(wth)); wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); ret = OUTPUT_FILE_ERROR; @@ -484,7 +484,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp return CF_OK; fail: - cfile_open_failure_message("sharkd", fname, *err, err_info, FALSE, cf->cd_t); + cfile_open_failure_message("sharkd", fname, *err, err_info); return CF_ERROR; } @@ -1910,8 +1910,8 @@ main(int argc, char *argv[]) comment = g_strdup_printf("Dump of PDUs from %s", cf_name); err = exp_pdu_open(&exp_pdu_tap_data, exp_fd, comment); if (err != 0) { - cfile_open_failure_message("TShark", exp_pdu_filename, err, NULL, - TRUE, WTAP_FILE_TYPE_SUBTYPE_PCAPNG); + cfile_dump_open_failure_message("TShark", exp_pdu_filename, err, + WTAP_FILE_TYPE_SUBTYPE_PCAPNG); g_free(comment); exit_status = INVALID_EXPORT; goto clean_exit; @@ -3021,8 +3021,7 @@ load_cap_file(capture_file *cf, char *save_file, int out_file_type, if (pdh == NULL) { /* We couldn't set up to write to the capture file. */ - cfile_open_failure_message("TShark", save_file, err, NULL, TRUE, - out_file_type); + cfile_dump_open_failure_message("TShark", save_file, err, out_file_type); goto out; } } else { @@ -3939,7 +3938,7 @@ cf_open(capture_file *cf, const char *fname, unsigned int type, gboolean is_temp return CF_OK; fail: - cfile_open_failure_message("TShark", fname, *err, err_info, FALSE, cf->cd_t); + cfile_open_failure_message("TShark", fname, *err, err_info); return CF_ERROR; } 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); } } diff --git a/ui/alert_box.h b/ui/alert_box.h index ee8d22cdbc..74d3261474 100644 --- a/ui/alert_box.h +++ b/ui/alert_box.h @@ -40,18 +40,23 @@ extern void vfailure_alert_box(const char *msg_format, va_list ap); extern void 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.. */ extern void cfile_open_failure_alert_box(const char *filename, int err, - gchar *err_info, gboolean for_writing, - int file_type_subtype); + gchar *err_info); + +/* + * 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. + */ +extern void cfile_dump_open_failure_alert_box(const char *filename, int err, + int file_type_subtype); /* * Alert box for a failed attempt to read from a capture file. diff --git a/ui/export_pdu_ui_utils.c b/ui/export_pdu_ui_utils.c index e16c1ff31d..352861e0ab 100644 --- a/ui/export_pdu_ui_utils.c +++ b/ui/export_pdu_ui_utils.c @@ -57,9 +57,8 @@ exp_pdu_file_open(exp_pdu_t *exp_pdu_tap_data) err = exp_pdu_open(exp_pdu_tap_data, import_file_fd, comment); if (err != 0) { g_free(comment); - cfile_open_failure_alert_box(capfile_name ? capfile_name : "temporary file", - err, NULL, TRUE, - WTAP_FILE_TYPE_SUBTYPE_PCAPNG); + cfile_dump_open_failure_alert_box(capfile_name ? capfile_name : "temporary file", + err, WTAP_FILE_TYPE_SUBTYPE_PCAPNG); goto end; } diff --git a/ui/failure_message.c b/ui/failure_message.c index 74c56ce5a2..5a6a0f3d43 100644 --- a/ui/failure_message.c +++ b/ui/failure_message.c @@ -63,27 +63,20 @@ output_file_description(const char *fname) } /* - * Error message 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). + * Error message for a failed attempt to open a capture file for reading. + * "progname" is the name of the program trying to open the file; + * "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. */ void cfile_open_failure_message(const char *progname, const char *filename, - int err, gchar *err_info, gboolean for_writing, - int file_type) + int err, gchar *err_info) { char *file_description; /* Get a string that describes what we're opening */ - if (for_writing) - file_description = output_file_description(filename); - else - file_description = input_file_description(filename); + file_description = input_file_description(filename); if (err < 0) { /* Wiretap error. */ @@ -95,19 +88,16 @@ cfile_open_failure_message(const char *progname, const char *filename, break; case WTAP_ERR_RANDOM_OPEN_PIPE: - /* Seen only when opening a capture file for reading. */ cmdarg_err("The %s is a pipe or FIFO; %s can't read pipe or FIFO files in two-pass mode.", file_description, progname); break; case WTAP_ERR_FILE_UNKNOWN_FORMAT: - /* Seen only when opening a capture file for reading. */ cmdarg_err("The %s isn't a capture file in a format %s understands.", file_description, progname); break; case WTAP_ERR_UNSUPPORTED: - /* Seen only when opening a capture file for reading. */ cmdarg_err("The %s contains record data that %s doesn't support.\n" "(%s)", file_description, progname, @@ -115,56 +105,97 @@ cfile_open_failure_message(const char *progname, const char *filename, g_free(err_info); break; + case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED: + cmdarg_err("The %s is a capture for a network type that %s doesn't support.", + file_description, progname); + break; + + case WTAP_ERR_BAD_FILE: + cmdarg_err("The %s appears to be damaged or corrupt.\n" + "(%s)", + file_description, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + case WTAP_ERR_CANT_OPEN: + cmdarg_err("The %s could not be opened for some unknown reason.", + file_description); + break; + + case WTAP_ERR_SHORT_READ: + cmdarg_err("The %s appears to have been cut short in the middle of a packet or other data.", + file_description); + break; + + case WTAP_ERR_DECOMPRESS: + cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt." + "(%s)", + file_description, + err_info != NULL ? err_info : "no information supplied"); + g_free(err_info); + break; + + default: + cmdarg_err("The %s could not be opened: %s.", + file_description, + wtap_strerror(err)); + break; + } + g_free(file_description); + } else + cmdarg_err(file_open_error_message(err, FALSE), filename); +} + +/* + * Error message for a failed attempt to open a capture file for writing. + * "progname" is the name of the program trying to open the file; + * "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. + */ +void +cfile_dump_open_failure_message(const char *progname, const char *filename, + int err, int file_type_subtype) +{ + char *file_description; + + /* Get a string that describes what we're opening */ + file_description = output_file_description(filename); + + if (err < 0) { + /* Wiretap error. */ + switch (err) { + + case WTAP_ERR_NOT_REGULAR_FILE: + cmdarg_err("The %s is a \"special file\" or socket or other non-regular file.", + file_description); + break; + case WTAP_ERR_CANT_WRITE_TO_PIPE: - /* Seen only when opening a capture file for writing. */ cmdarg_err("The %s is a pipe, and \"%s\" capture files can't be written to a pipe.", file_description, - wtap_file_type_subtype_short_string(file_type)); + wtap_file_type_subtype_short_string(file_type_subtype)); break; case WTAP_ERR_UNWRITABLE_FILE_TYPE: - /* Seen only when opening a capture file for writing. */ cmdarg_err("%s doesn't support writing capture files in that format.", progname); break; case WTAP_ERR_UNWRITABLE_ENCAP: - /* Seen only when opening a capture file for writing. */ cmdarg_err("The capture file being read can't be written as a \"%s\" file.", - wtap_file_type_subtype_short_string(file_type)); + wtap_file_type_subtype_short_string(file_type_subtype)); break; case WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED: - if (for_writing) { - cmdarg_err("The capture file being read can't be written as a \"%s\" file.", - wtap_file_type_subtype_short_string(file_type)); - } else { - cmdarg_err("The %s is a capture for a network type that %s doesn't support.", - file_description, progname); - } - break; - - case WTAP_ERR_BAD_FILE: - /* Seen only when opening a capture file for reading. */ - cmdarg_err("The %s appears to be damaged or corrupt.\n" - "(%s)", - file_description, - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); + cmdarg_err("The capture file being read can't be written as a \"%s\" file.", + wtap_file_type_subtype_short_string(file_type_subtype)); break; case WTAP_ERR_CANT_OPEN: - if (for_writing) { - cmdarg_err("The %s could not be created for some unknown reason.", - file_description); - } else { - cmdarg_err("The %s could not be opened for some unknown reason.", - file_description); - } - break; - - case WTAP_ERR_SHORT_READ: - cmdarg_err("The %s appears to have been cut short in the middle of a packet or other data.", + cmdarg_err("The %s could not be created for some unknown reason.", file_description); break; @@ -177,32 +208,23 @@ cfile_open_failure_message(const char *progname, const char *filename, cmdarg_err("This file type cannot be written as a compressed file."); break; - case WTAP_ERR_DECOMPRESS: - /* Seen only when opening a capture file for reading. */ - cmdarg_err("The %s cannot be decompressed; it may be damaged or corrupt." - "(%s)", - file_description, - err_info != NULL ? err_info : "no information supplied"); - g_free(err_info); - break; - default: - cmdarg_err("The %s could not be %s: %s.", + cmdarg_err("The %s could not be created: %s.", file_description, - for_writing ? "created" : "opened", wtap_strerror(err)); break; } g_free(file_description); } else - cmdarg_err(file_open_error_message(err, for_writing), filename); + cmdarg_err(file_open_error_message(err, TRUE), filename); } /* * Error message 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. + * "progname" is the name of the program trying to open the file; + * "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. */ void cfile_read_failure_message(const char *progname, const char *filename, @@ -254,12 +276,15 @@ cfile_read_failure_message(const char *progname, const char *filename, /* * Error message for a failed attempt to write to 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; "framenum" is the frame number of the record - * on which the error occurred; "file_type_subtype" is a - * WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file being - * written. + * "progname" is the name of the program trying to open the file; + * "in_filename" is the name of the file from which the record + * being written came; "out_filename" is the name of the file to + * which we're writing; "err" is assumed "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; + * "framenum" is the frame number of the record on which the error + * occurred; "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value + * for the type and subtype of file being written. */ void cfile_write_failure_message(const char *progname, const char *in_filename, @@ -354,7 +379,8 @@ cfile_write_failure_message(const char *progname, const char *in_filename, /* * Error message for a failed attempt to close a capture file. - * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value. + * "filename" is the name of the file being closed; "err" is assumed + * to be a UNIX-style errno or a WTAP_ERR_ value. * * When closing a capture file: * diff --git a/ui/failure_message.h b/ui/failure_message.h index 1f9c48732b..9749eb7178 100644 --- a/ui/failure_message.h +++ b/ui/failure_message.h @@ -29,25 +29,34 @@ extern "C" { #endif /* __cplusplus */ /* - * Error message 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). + * Error message for a failed attempt to open a capture file for input. + * "progname" is the name of the program trying to open the file; + * "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. */ extern void cfile_open_failure_message(const char *progname, const char *filename, int err, - gchar *err_info, gboolean for_writing, - int file_type); + gchar *err_info); + +/* + * Error message for a failed attempt to open a capture file for writing. + * "progname" is the name of the program trying to open the file; + * "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. + */ +extern void cfile_dump_open_failure_message(const char *progname, + const char *filename, int err, + int file_type_subtype); /* * Error message 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. + * "progname" is the name of the program trying to open the file; + * "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. */ extern void cfile_read_failure_message(const char *progname, const char *filename, int err, @@ -55,12 +64,15 @@ extern void cfile_read_failure_message(const char *progname, /* * Error message for a failed attempt to write to 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; "framenum" is the frame number of the record - * on which the error occurred; "file_type_subtype" is a - * WTAP_FILE_TYPE_SUBTYPE_ value for the type and subtype of file being - * written. + * "progname" is the name of the program trying to open the file; + * "in_filename" is the name of the file from which the record + * being written came; "out_filename" is the name of the file to + * which we're writing; "err" is assumed "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; + * "framenum" is the frame number of the record on which the error + * occurred; "file_type_subtype" is a WTAP_FILE_TYPE_SUBTYPE_ value + * for the type and subtype of file being written. */ extern void cfile_write_failure_message(const char *progname, const char *in_filename, @@ -71,7 +83,8 @@ extern void cfile_write_failure_message(const char *progname, /* * Error message for a failed attempt to close a capture file. - * "err" is assumed to be a UNIX-style errno or a WTAP_ERR_ value. + * "filename" is the name of the file being closed; "err" is assumed + * to be a UNIX-style errno or a WTAP_ERR_ value. * * When closing a capture file: * diff --git a/ui/gtk/file_import_dlg.c b/ui/gtk/file_import_dlg.c index f13c632181..0daefe5ad4 100644 --- a/ui/gtk/file_import_dlg.c +++ b/ui/gtk/file_import_dlg.c @@ -516,9 +516,8 @@ file_import_open(text_import_info_t *info) shb_hdrs, idb_inf, NULL, &err); capfile_name = g_strdup(tmpname); if (info->wdh == NULL) { - cfile_open_failure_alert_box(tmpname ? tmpname : "temporary file", - err, NULL, TRUE, - WTAP_FILE_TYPE_SUBTYPE_PCAPNG); + cfile_dump_open_failure_alert_box(tmpname ? tmpname : "temporary file", + err, WTAP_FILE_TYPE_SUBTYPE_PCAPNG); fclose(info->import_text_file); goto end; } diff --git a/ui/qt/import_text_dialog.cpp b/ui/qt/import_text_dialog.cpp index 39b13af75d..0c3ef3587f 100644 --- a/ui/qt/import_text_dialog.cpp +++ b/ui/qt/import_text_dialog.cpp @@ -134,7 +134,7 @@ void ImportTextDialog::convertTextFile() { capfile_name_.append(tmpname ? tmpname : "temporary file"); qDebug() << capfile_name_ << ":" << import_info_.wdh << import_info_.encapsulation << import_info_.max_frame_length; if (import_info_.wdh == NULL) { - cfile_open_failure_alert_box(capfile_name_.toUtf8().constData(), err, NULL, TRUE, WTAP_FILE_TYPE_SUBTYPE_PCAP); + cfile_dump_open_failure_alert_box(capfile_name_.toUtf8().constData(), err, WTAP_FILE_TYPE_SUBTYPE_PCAP); fclose(import_info_.import_text_file); setResult(QDialog::Rejected); return; |