/src/wireshark/wsutil/report_message.c
Line | Count | Source |
1 | | /* report_message.c |
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. |
6 | | * |
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. |
12 | | * |
13 | | * Wireshark - Network traffic analyzer |
14 | | * By Gerald Combs <gerald@wireshark.org> |
15 | | * Copyright 1998 Gerald Combs |
16 | | * |
17 | | * SPDX-License-Identifier: GPL-2.0-or-later |
18 | | */ |
19 | | #include "config.h" |
20 | | |
21 | | #include "report_message.h" |
22 | | |
23 | | static const char *friendly_program_name; |
24 | | static const struct report_message_routines *routines; |
25 | | |
26 | | void |
27 | | init_report_message(const char *friendly_program_name_arg, |
28 | | const struct report_message_routines *routines_arg) |
29 | 14 | { |
30 | 14 | friendly_program_name = friendly_program_name_arg; |
31 | 14 | routines = routines_arg; |
32 | 14 | } |
33 | | |
34 | | /* |
35 | | * Report a general error. |
36 | | */ |
37 | | void |
38 | | report_failure(const char *msg_format, ...) |
39 | 2 | { |
40 | 2 | va_list ap; |
41 | | |
42 | 2 | va_start(ap, msg_format); |
43 | 2 | (*routines->vreport_failure)(msg_format, ap); |
44 | 2 | va_end(ap); |
45 | 2 | } |
46 | | |
47 | | /* |
48 | | * Report a general warning. |
49 | | */ |
50 | | void |
51 | | report_warning(const char *msg_format, ...) |
52 | 0 | { |
53 | 0 | va_list ap; |
54 | |
|
55 | 0 | va_start(ap, msg_format); |
56 | 0 | (*routines->vreport_warning)(msg_format, ap); |
57 | 0 | va_end(ap); |
58 | 0 | } |
59 | | |
60 | | /* |
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. |
65 | | */ |
66 | | void |
67 | | report_open_failure(const char *filename, int err, |
68 | | bool for_writing) |
69 | 0 | { |
70 | 0 | (*routines->report_open_failure)(filename, err, for_writing); |
71 | 0 | } |
72 | | |
73 | | /* |
74 | | * Report an error when trying to read a file. |
75 | | * "err" is assumed to be a UNIX-style errno. |
76 | | */ |
77 | | void |
78 | | report_read_failure(const char *filename, int err) |
79 | 0 | { |
80 | 0 | (*routines->report_read_failure)(filename, err); |
81 | 0 | } |
82 | | |
83 | | /* |
84 | | * Report an error when trying to write a file. |
85 | | * "err" is assumed to be a UNIX-style errno. |
86 | | */ |
87 | | void |
88 | | report_write_failure(const char *filename, int err) |
89 | 0 | { |
90 | 0 | (*routines->report_write_failure)(filename, err); |
91 | 0 | } |
92 | | |
93 | | /* |
94 | | * Report an error when trying to rename a file. |
95 | | * "err" is assumed to be a UNIX-style errno. |
96 | | */ |
97 | | void |
98 | | report_rename_failure(const char *old_filename, const char *new_filename, |
99 | | int err) |
100 | 0 | { |
101 | 0 | (*routines->report_rename_failure)(old_filename, new_filename, err); |
102 | 0 | } |
103 | | |
104 | | /* |
105 | | * Report an error from opening a capture file for reading. |
106 | | */ |
107 | | void |
108 | | report_cfile_open_failure(const char *filename, int err, char *err_info) |
109 | 0 | { |
110 | 0 | (*routines->report_cfile_open_failure)(filename, err, err_info); |
111 | 0 | } |
112 | | |
113 | | /* |
114 | | * Report an error from opening a capture file for writing. |
115 | | */ |
116 | | void |
117 | | report_cfile_dump_open_failure(const char *filename, |
118 | | int err, char *err_info, int file_type_subtype) |
119 | 0 | { |
120 | 0 | (*routines->report_cfile_dump_open_failure)(filename, |
121 | 0 | err, err_info, file_type_subtype); |
122 | 0 | } |
123 | | |
124 | | /* |
125 | | * Report an error from attempting to read from a capture file. |
126 | | */ |
127 | | void |
128 | | report_cfile_read_failure(const char *filename, int err, char *err_info) |
129 | 0 | { |
130 | 0 | (*routines->report_cfile_read_failure)(filename, err, err_info); |
131 | 0 | } |
132 | | |
133 | | /* |
134 | | * Report an error from attempting to write to a capture file. |
135 | | */ |
136 | | void |
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) |
139 | 0 | { |
140 | 0 | (*routines->report_cfile_write_failure)(in_filename, out_filename, |
141 | 0 | err, err_info, framenum, file_type_subtype); |
142 | 0 | } |
143 | | |
144 | | /* |
145 | | * Report an error from closing a capture file open for writing. |
146 | | */ |
147 | | void |
148 | | report_cfile_close_failure(const char *filename, int err, char *err_info) |
149 | 0 | { |
150 | 0 | (*routines->report_cfile_close_failure)(filename, err, err_info); |
151 | 0 | } |
152 | | |
153 | | /* |
154 | | * Return the "friendly" program name. |
155 | | */ |
156 | | const char * |
157 | | get_friendly_program_name(void) |
158 | 0 | { |
159 | 0 | return friendly_program_name; |
160 | 0 | } |
161 | | |
162 | | /* |
163 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
164 | | * |
165 | | * Local variables: |
166 | | * c-basic-offset: 8 |
167 | | * tab-width: 8 |
168 | | * indent-tabs-mode: t |
169 | | * End: |
170 | | * |
171 | | * vi: set shiftwidth=8 tabstop=8 noexpandtab: |
172 | | * :indentSize=8:tabSize=8:noTabs=false: |
173 | | */ |