aboutsummaryrefslogtreecommitdiffstats
path: root/ui/failure_message.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-03-15 11:29:43 -0700
committerGuy Harris <gharris@sonic.net>2021-03-15 12:17:59 -0700
commitc33e2f7b51f9e14f99f6b6d9018ac41b7e97d5a6 (patch)
tree4e02fee80e16cfd08afc9d555e4612399c72d69b /ui/failure_message.c
parent89ae76d3008719f6b797eb201794dfe0de294640 (diff)
Add more error-reporting routines that call through a function pointer.
Have routines to report capture-file errors, using libwireshark error codes and strings, that call through a pointer, so they can pop up dialogs in GUI apps, print a message to the standard error on command-line apps, and possibly do something different on server programs. Have init_report_message() take a pointer to structure containing those function pointers, rather than the function pointers themselves, as arguments. Make other API changes to make that work.
Diffstat (limited to 'ui/failure_message.c')
-rw-r--r--ui/failure_message.c80
1 files changed, 61 insertions, 19 deletions
diff --git a/ui/failure_message.c b/ui/failure_message.c
index f5660122e2..760e75124e 100644
--- a/ui/failure_message.c
+++ b/ui/failure_message.c
@@ -16,10 +16,59 @@
#include <wiretap/wtap.h>
#include <wsutil/filesystem.h>
+#include <wsutil/report_message.h>
#include <ui/cmdarg_err.h>
#include "ui/failure_message.h"
+/*
+ * Generic error message.
+ */
+void
+failure_message(const char *msg_format, va_list ap)
+{
+ vcmdarg_err(msg_format, ap);
+}
+
+/*
+ * Error message for a failed attempt to open or create a file
+ * other than a capture file.
+ * "filename" is the name of the file being opened; "err" is assumed
+ * to be a UNIX-style errno; "for_writing" is TRUE if we're opening
+ * the file for writing and FALSE if we're opening it for reading.
+ */
+void
+open_failure_message(const char *filename, int err, gboolean for_writing)
+{
+ cmdarg_err(file_open_error_message(err, for_writing), filename);
+}
+
+/*
+ * Error message for a failed attempt to read from a file other than
+ * a capture file.
+ * "filename" is the name of the file being read from; "err" is assumed
+ * to be a UNIX-style errno.
+ */
+void
+read_failure_message(const char *filename, int err)
+{
+ cmdarg_err("An error occurred while reading from the file \"%s\": %s.",
+ filename, g_strerror(err));
+}
+
+/*
+ * Error message for a failed attempt to write to a file other than
+ * a capture file.
+ * "filename" is the name of the file being written to; "err" is assumed
+ * to be a UNIX-style errno.
+ */
+void
+write_failure_message(const char *filename, int err)
+{
+ cmdarg_err("An error occurred while writing to the file \"%s\": %s.",
+ filename, g_strerror(err));
+}
+
static char *
input_file_description(const char *fname)
{
@@ -52,14 +101,12 @@ output_file_description(const char *fname)
/*
* 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)
+cfile_open_failure_message(const char *filename, int err, gchar *err_info)
{
if (err < 0) {
/*
@@ -77,25 +124,25 @@ cfile_open_failure_message(const char *progname, const char *filename,
case WTAP_ERR_RANDOM_OPEN_PIPE:
cmdarg_err("The %s is a pipe or FIFO; %s can't read pipe or FIFO files in two-pass mode.",
- file_description, progname);
+ file_description, get_friendly_program_name());
break;
case WTAP_ERR_FILE_UNKNOWN_FORMAT:
cmdarg_err("The %s isn't a capture file in a format %s understands.",
- file_description, progname);
+ file_description, get_friendly_program_name());
break;
case WTAP_ERR_UNSUPPORTED:
cmdarg_err("The %s contains record data that %s doesn't support.\n"
"(%s)",
- file_description, progname,
+ file_description, get_friendly_program_name(),
err_info != NULL ? err_info : "no information supplied");
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);
+ file_description, get_friendly_program_name());
break;
case WTAP_ERR_BAD_FILE:
@@ -153,7 +200,6 @@ cfile_open_failure_message(const char *progname, const char *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; "err_info" is assumed
* to be a string giving further information for some WTAP_ERR_ values;
@@ -161,8 +207,7 @@ cfile_open_failure_message(const char *progname, const char *filename,
* and subtype of file being opened.
*/
void
-cfile_dump_open_failure_message(const char *progname, const char *filename,
- int err, gchar *err_info,
+cfile_dump_open_failure_message(const char *filename, int err, gchar *err_info,
int file_type_subtype)
{
if (err < 0) {
@@ -187,7 +232,7 @@ cfile_dump_open_failure_message(const char *progname, const char *filename,
case WTAP_ERR_UNWRITABLE_FILE_TYPE:
cmdarg_err("%s doesn't support writing capture files in that format.",
- progname);
+ get_friendly_program_name());
break;
case WTAP_ERR_UNWRITABLE_ENCAP:
@@ -235,14 +280,12 @@ cfile_dump_open_failure_message(const char *progname, const char *filename,
/*
* Error message for a failed attempt to read from a capture file.
- * "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,
- int err, gchar *err_info)
+cfile_read_failure_message(const char *filename, int err, gchar *err_info)
{
char *file_string;
@@ -254,7 +297,7 @@ cfile_read_failure_message(const char *progname, const char *filename,
case WTAP_ERR_UNSUPPORTED:
cmdarg_err("The %s contains record data that %s doesn't support.\n"
"(%s)",
- file_string, progname,
+ file_string, get_friendly_program_name(),
err_info != NULL ? err_info : "no information supplied");
g_free(err_info);
break;
@@ -305,7 +348,6 @@ cfile_read_failure_message(const char *progname, const char *filename,
/*
* Error message for a failed attempt to write to a capture file.
- * "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
@@ -316,8 +358,8 @@ cfile_read_failure_message(const char *progname, const char *filename,
* for the type and subtype of file being written.
*/
void
-cfile_write_failure_message(const char *progname, const char *in_filename,
- const char *out_filename, int err, gchar *err_info,
+cfile_write_failure_message(const char *in_filename, const char *out_filename,
+ int err, gchar *err_info,
guint32 framenum, int file_type_subtype)
{
char *in_file_string;
@@ -368,7 +410,7 @@ cfile_write_failure_message(const char *progname, const char *in_filename,
* and report the frame number and file type/subtype.
*/
cmdarg_err("Frame%s is larger than %s supports in a \"%s\" file.",
- in_frame_string, progname,
+ in_frame_string, get_friendly_program_name(),
wtap_file_type_subtype_name(file_type_subtype));
break;