2 * Routines for code that can run in GUI and command-line environments to
3 * use to report errors and warnings to the user (e.g., I/O errors, or
4 * problems with preference settings) if the message should be shown as
5 * a GUI error in a GUI environment.
7 * The application using libwsutil will register error-reporting
8 * routines, and the routines defined here will call the registered
9 * routines. That way, these routines can be called by code that
10 * doesn't itself know whether to pop up a dialog or print something
11 * to the standard error.
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * SPDX-License-Identifier: GPL-2.0-or-later
21 #include "report_message.h"
23 static const char *friendly_program_name
;
24 static const struct report_message_routines
*routines
;
27 init_report_message(const char *friendly_program_name_arg
,
28 const struct report_message_routines
*routines_arg
)
30 friendly_program_name
= friendly_program_name_arg
;
31 routines
= routines_arg
;
35 * Report a general error.
38 report_failure(const char *msg_format
, ...)
42 va_start(ap
, msg_format
);
43 (*routines
->vreport_failure
)(msg_format
, ap
);
48 * Report a general warning.
51 report_warning(const char *msg_format
, ...)
55 va_start(ap
, msg_format
);
56 (*routines
->vreport_warning
)(msg_format
, ap
);
61 * Report an error when trying to open or create a file.
62 * "err" is assumed to be an error code from Wiretap; positive values are
63 * UNIX-style errnos, so this can be used for open failures not from
64 * Wiretap as long as the failure code is just an errno.
67 report_open_failure(const char *filename
, int err
,
70 (*routines
->report_open_failure
)(filename
, err
, for_writing
);
74 * Report an error when trying to read a file.
75 * "err" is assumed to be a UNIX-style errno.
78 report_read_failure(const char *filename
, int err
)
80 (*routines
->report_read_failure
)(filename
, err
);
84 * Report an error when trying to write a file.
85 * "err" is assumed to be a UNIX-style errno.
88 report_write_failure(const char *filename
, int err
)
90 (*routines
->report_write_failure
)(filename
, err
);
94 * Report an error when trying to rename a file.
95 * "err" is assumed to be a UNIX-style errno.
98 report_rename_failure(const char *old_filename
, const char *new_filename
,
101 (*routines
->report_rename_failure
)(old_filename
, new_filename
, err
);
105 * Report an error from opening a capture file for reading.
108 report_cfile_open_failure(const char *filename
, int err
, char *err_info
)
110 (*routines
->report_cfile_open_failure
)(filename
, err
, err_info
);
114 * Report an error from opening a capture file for writing.
117 report_cfile_dump_open_failure(const char *filename
,
118 int err
, char *err_info
, int file_type_subtype
)
120 (*routines
->report_cfile_dump_open_failure
)(filename
,
121 err
, err_info
, file_type_subtype
);
125 * Report an error from attempting to read from a capture file.
128 report_cfile_read_failure(const char *filename
, int err
, char *err_info
)
130 (*routines
->report_cfile_read_failure
)(filename
, err
, err_info
);
134 * Report an error from attempting to write to a capture file.
137 report_cfile_write_failure(const char *in_filename
, const char *out_filename
,
138 int err
, char *err_info
, uint64_t framenum
, int file_type_subtype
)
140 (*routines
->report_cfile_write_failure
)(in_filename
, out_filename
,
141 err
, err_info
, framenum
, file_type_subtype
);
145 * Report an error from closing a capture file open for writing.
148 report_cfile_close_failure(const char *filename
, int err
, char *err_info
)
150 (*routines
->report_cfile_close_failure
)(filename
, err
, err_info
);
154 * Return the "friendly" program name.
157 get_friendly_program_name(void)
159 return friendly_program_name
;
163 * Editor modelines - https://www.wireshark.org/tools/modelines.html
168 * indent-tabs-mode: t
171 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
172 * :indentSize=8:tabSize=8:noTabs=false: