diff options
author | Guy Harris <gharris@sonic.net> | 2021-03-15 11:29:43 -0700 |
---|---|---|
committer | Guy Harris <gharris@sonic.net> | 2021-03-15 12:17:59 -0700 |
commit | c33e2f7b51f9e14f99f6b6d9018ac41b7e97d5a6 (patch) | |
tree | 4e02fee80e16cfd08afc9d555e4612399c72d69b /tfshark.c | |
parent | 89ae76d3008719f6b797eb201794dfe0de294640 (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 'tfshark.c')
-rw-r--r-- | tfshark.c | 65 |
1 files changed, 20 insertions, 45 deletions
@@ -63,6 +63,7 @@ #include "ui/util.h" #include "ui/decode_as_utils.h" #include "ui/dissect_opts.h" +#include "ui/failure_message.h" #include <epan/epan_dissect.h> #include <epan/tap.h> #include <epan/stat_tap_ui.h> @@ -134,12 +135,8 @@ static gboolean write_finale(void); static const char *cf_open_error_message(int err, gchar *err_info, gboolean for_writing, int file_type); -static void failure_warning_message(const char *msg_format, va_list ap); -static void open_failure_message(const char *filename, int err, - gboolean for_writing); -static void read_failure_message(const char *filename, int err); -static void write_failure_message(const char *filename, int err); -static void failure_message_cont(const char *msg_format, va_list ap); +static void tfshark_cmdarg_err(const char *msg_format, va_list ap); +static void tfshark_cmdarg_err_cont(const char *msg_format, va_list ap); static GHashTable *output_only_tables = NULL; @@ -353,6 +350,18 @@ main(int argc, char *argv[]) #define OPTSTRING "+2C:d:e:E:hK:lo:O:qQr:R:S:t:T:u:vVxX:Y:z:" static const char optstring[] = OPTSTRING; + static const struct report_message_routines tfshark_report_routines = { + failure_message, + failure_message, + open_failure_message, + read_failure_message, + write_failure_message, + cfile_open_failure_message, + cfile_dump_open_failure_message, + cfile_read_failure_message, + cfile_write_failure_message, + cfile_close_failure_message + }; /* * Set the C-language locale to the native environment and set the @@ -364,7 +373,7 @@ main(int argc, char *argv[]) setlocale(LC_ALL, ""); #endif - cmdarg_err_init(failure_warning_message, failure_message_cont); + cmdarg_err_init(tfshark_cmdarg_err, tfshark_cmdarg_err_cont); #ifdef _WIN32 create_app_running_mutex(); @@ -471,9 +480,7 @@ main(int argc, char *argv[]) (GLogLevelFlags)log_flags, tfshark_log_handler, NULL /* user_data */); - init_report_message(failure_warning_message, failure_warning_message, - open_failure_message, read_failure_message, - write_failure_message); + init_report_message("tfshark", &tfshark_report_routines); timestamp_set_type(TS_RELATIVE); timestamp_set_precision(TS_PREC_AUTO); @@ -2236,11 +2243,10 @@ cf_open_error_message(int err, gchar *err_info _U_, gboolean for_writing, } /* - * General errors and warnings are reported with an console message - * in TFShark. + * Report an error in command-line arguments. */ static void -failure_warning_message(const char *msg_format, va_list ap) +tfshark_cmdarg_err(const char *msg_format, va_list ap) { fprintf(stderr, "tfshark: "); vfprintf(stderr, msg_format, ap); @@ -2248,41 +2254,10 @@ failure_warning_message(const char *msg_format, va_list ap) } /* - * Open/create errors are reported with an console message in TFShark. - */ -static void -open_failure_message(const char *filename, int err, gboolean for_writing) -{ - fprintf(stderr, "tfshark: "); - fprintf(stderr, file_open_error_message(err, for_writing), filename); - fprintf(stderr, "\n"); -} - -/* - * Read errors are reported with an console message in TFShark. - */ -static 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)); -} - -/* - * Write errors are reported with an console message in TFShark. - */ -static 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)); -} - -/* * Report additional information for an error in command-line arguments. */ static void -failure_message_cont(const char *msg_format, va_list ap) +tfshark_cmdarg_err_cont(const char *msg_format, va_list ap) { vfprintf(stderr, msg_format, ap); fprintf(stderr, "\n"); |