root / qerror.c @ 7bbd8237
History | View | Annotate | Download (9.4 kB)
1 | 9f9daf9a | Luiz Capitulino | /*
|
---|---|---|---|
2 | 9f9daf9a | Luiz Capitulino | * QError: QEMU Error data-type.
|
3 | 9f9daf9a | Luiz Capitulino | *
|
4 | 9f9daf9a | Luiz Capitulino | * Copyright (C) 2009 Red Hat Inc.
|
5 | 9f9daf9a | Luiz Capitulino | *
|
6 | 9f9daf9a | Luiz Capitulino | * Authors:
|
7 | 9f9daf9a | Luiz Capitulino | * Luiz Capitulino <lcapitulino@redhat.com>
|
8 | 9f9daf9a | Luiz Capitulino | *
|
9 | 9f9daf9a | Luiz Capitulino | * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
10 | 9f9daf9a | Luiz Capitulino | * See the COPYING.LIB file in the top-level directory.
|
11 | 9f9daf9a | Luiz Capitulino | */
|
12 | 9f9daf9a | Luiz Capitulino | #include "qjson.h" |
13 | 9f9daf9a | Luiz Capitulino | #include "qerror.h" |
14 | 9f9daf9a | Luiz Capitulino | #include "qstring.h" |
15 | 9f9daf9a | Luiz Capitulino | #include "qemu-common.h" |
16 | 2f792016 | Markus Armbruster | #include "qemu-error.h" |
17 | 9f9daf9a | Luiz Capitulino | |
18 | 9f9daf9a | Luiz Capitulino | static void qerror_destroy_obj(QObject *obj); |
19 | 9f9daf9a | Luiz Capitulino | |
20 | 9f9daf9a | Luiz Capitulino | static const QType qerror_type = { |
21 | 9f9daf9a | Luiz Capitulino | .code = QTYPE_QERROR, |
22 | 9f9daf9a | Luiz Capitulino | .destroy = qerror_destroy_obj, |
23 | 9f9daf9a | Luiz Capitulino | }; |
24 | 9f9daf9a | Luiz Capitulino | |
25 | 9f9daf9a | Luiz Capitulino | /**
|
26 | 9f9daf9a | Luiz Capitulino | * The 'desc' parameter is a printf-like string, the format of the format
|
27 | 9f9daf9a | Luiz Capitulino | * string is:
|
28 | 9f9daf9a | Luiz Capitulino | *
|
29 | 9f9daf9a | Luiz Capitulino | * %(KEY)
|
30 | 9f9daf9a | Luiz Capitulino | *
|
31 | 9f9daf9a | Luiz Capitulino | * Where KEY is a QDict key, which has to be passed to qerror_from_info().
|
32 | 9f9daf9a | Luiz Capitulino | *
|
33 | 9f9daf9a | Luiz Capitulino | * Example:
|
34 | 9f9daf9a | Luiz Capitulino | *
|
35 | 9f9daf9a | Luiz Capitulino | * "foo error on device: %(device) slot: %(slot_nr)"
|
36 | 9f9daf9a | Luiz Capitulino | *
|
37 | 9f9daf9a | Luiz Capitulino | * A single percent sign can be printed if followed by a second one,
|
38 | 9f9daf9a | Luiz Capitulino | * for example:
|
39 | 9f9daf9a | Luiz Capitulino | *
|
40 | 9f9daf9a | Luiz Capitulino | * "running out of foo: %(foo)%%"
|
41 | 9f9daf9a | Luiz Capitulino | */
|
42 | d05ac8fa | Blue Swirl | static const QErrorStringTable qerror_table[] = { |
43 | 357b6156 | Luiz Capitulino | { |
44 | 7bbd8237 | Markus Armbruster | .error_fmt = QERR_BUS_NOT_FOUND, |
45 | 7bbd8237 | Markus Armbruster | .desc = "Bus '%(bus)' not found",
|
46 | 7bbd8237 | Markus Armbruster | }, |
47 | 7bbd8237 | Markus Armbruster | { |
48 | e16a1812 | Markus Armbruster | .error_fmt = QERR_COMMAND_NOT_FOUND, |
49 | e16a1812 | Markus Armbruster | .desc = "The command %(name) has not been found",
|
50 | 4b9d4683 | Luiz Capitulino | }, |
51 | 4b9d4683 | Luiz Capitulino | { |
52 | 0df37c41 | Luiz Capitulino | .error_fmt = QERR_DEVICE_ENCRYPTED, |
53 | fc5469d8 | Markus Armbruster | .desc = "Device '%(device)' is encrypted",
|
54 | 0df37c41 | Luiz Capitulino | }, |
55 | 0df37c41 | Luiz Capitulino | { |
56 | b0868380 | Markus Armbruster | .error_fmt = QERR_DEVICE_LOCKED, |
57 | fc5469d8 | Markus Armbruster | .desc = "Device '%(device)' is locked",
|
58 | b0868380 | Markus Armbruster | }, |
59 | b0868380 | Markus Armbruster | { |
60 | e16a1812 | Markus Armbruster | .error_fmt = QERR_DEVICE_NOT_ACTIVE, |
61 | fc5469d8 | Markus Armbruster | .desc = "Device '%(device)' has not been activated by the guest",
|
62 | e16a1812 | Markus Armbruster | }, |
63 | e16a1812 | Markus Armbruster | { |
64 | 357b6156 | Luiz Capitulino | .error_fmt = QERR_DEVICE_NOT_FOUND, |
65 | fc5469d8 | Markus Armbruster | .desc = "Device '%(device)' not found",
|
66 | 357b6156 | Luiz Capitulino | }, |
67 | 055f6122 | Luiz Capitulino | { |
68 | 5cfe0264 | Markus Armbruster | .error_fmt = QERR_DEVICE_NOT_REMOVABLE, |
69 | fc5469d8 | Markus Armbruster | .desc = "Device '%(device)' is not removable",
|
70 | 5cfe0264 | Markus Armbruster | }, |
71 | 5cfe0264 | Markus Armbruster | { |
72 | c7c338c4 | Markus Armbruster | .error_fmt = QERR_FD_NOT_FOUND, |
73 | fc5469d8 | Markus Armbruster | .desc = "File descriptor named '%(name)' not found",
|
74 | c7c338c4 | Markus Armbruster | }, |
75 | c7c338c4 | Markus Armbruster | { |
76 | 41471a23 | Markus Armbruster | .error_fmt = QERR_FD_NOT_SUPPLIED, |
77 | 41471a23 | Markus Armbruster | .desc = "No file descriptor supplied via SCM_RIGHTS",
|
78 | 41471a23 | Markus Armbruster | }, |
79 | 41471a23 | Markus Armbruster | { |
80 | 17901e75 | Markus Armbruster | .error_fmt = QERR_INVALID_BLOCK_FORMAT, |
81 | fc5469d8 | Markus Armbruster | .desc = "Invalid block format '%(name)'",
|
82 | 17901e75 | Markus Armbruster | }, |
83 | 17901e75 | Markus Armbruster | { |
84 | 7a046f5f | Markus Armbruster | .error_fmt = QERR_INVALID_PARAMETER, |
85 | fc5469d8 | Markus Armbruster | .desc = "Invalid parameter '%(name)'",
|
86 | 7a046f5f | Markus Armbruster | }, |
87 | 7a046f5f | Markus Armbruster | { |
88 | e16a1812 | Markus Armbruster | .error_fmt = QERR_INVALID_PARAMETER_TYPE, |
89 | e16a1812 | Markus Armbruster | .desc = "Invalid parameter type, expected: %(expected)",
|
90 | 055f6122 | Luiz Capitulino | }, |
91 | 82a60711 | Luiz Capitulino | { |
92 | e16a1812 | Markus Armbruster | .error_fmt = QERR_INVALID_PASSWORD, |
93 | fc5469d8 | Markus Armbruster | .desc = "Password incorrect",
|
94 | 4b9d4683 | Luiz Capitulino | }, |
95 | 4b9d4683 | Luiz Capitulino | { |
96 | e16a1812 | Markus Armbruster | .error_fmt = QERR_JSON_PARSING, |
97 | e16a1812 | Markus Armbruster | .desc = "Invalid JSON syntax",
|
98 | f6d855c5 | Luiz Capitulino | }, |
99 | f6d855c5 | Luiz Capitulino | { |
100 | 82a60711 | Luiz Capitulino | .error_fmt = QERR_KVM_MISSING_CAP, |
101 | 82a60711 | Luiz Capitulino | .desc = "Using KVM without %(capability), %(feature) unavailable",
|
102 | 82a60711 | Luiz Capitulino | }, |
103 | 4b9d4683 | Luiz Capitulino | { |
104 | 4b9d4683 | Luiz Capitulino | .error_fmt = QERR_MISSING_PARAMETER, |
105 | fc5469d8 | Markus Armbruster | .desc = "Parameter '%(name)' is missing",
|
106 | fc5469d8 | Markus Armbruster | }, |
107 | fc5469d8 | Markus Armbruster | { |
108 | fc5469d8 | Markus Armbruster | .error_fmt = QERR_OPEN_FILE_FAILED, |
109 | fc5469d8 | Markus Armbruster | .desc = "Could not open '%(filename)'",
|
110 | 4b9d4683 | Luiz Capitulino | }, |
111 | 4b9d4683 | Luiz Capitulino | { |
112 | c58a35f8 | Markus Armbruster | .error_fmt = QERR_PROPERTY_NOT_FOUND, |
113 | c58a35f8 | Markus Armbruster | .desc = "Property '%(device).%(property)' not found",
|
114 | c58a35f8 | Markus Armbruster | }, |
115 | c58a35f8 | Markus Armbruster | { |
116 | 06b4a703 | Markus Armbruster | .error_fmt = QERR_PROPERTY_VALUE_BAD, |
117 | 06b4a703 | Markus Armbruster | .desc = "Property '%(device).%(property)' doesn't take value '%(value)'",
|
118 | 06b4a703 | Markus Armbruster | }, |
119 | 06b4a703 | Markus Armbruster | { |
120 | 9c5eff95 | Markus Armbruster | .error_fmt = QERR_PROPERTY_VALUE_IN_USE, |
121 | 9c5eff95 | Markus Armbruster | .desc = "Property '%(device).%(property)' can't take value '%(value)', it's in use",
|
122 | 9c5eff95 | Markus Armbruster | }, |
123 | 9c5eff95 | Markus Armbruster | { |
124 | 84745d68 | Markus Armbruster | .error_fmt = QERR_PROPERTY_VALUE_NOT_FOUND, |
125 | 84745d68 | Markus Armbruster | .desc = "Property '%(device).%(property)' can't find value '%(value)'",
|
126 | 84745d68 | Markus Armbruster | }, |
127 | 84745d68 | Markus Armbruster | { |
128 | 4b9d4683 | Luiz Capitulino | .error_fmt = QERR_QMP_BAD_INPUT_OBJECT, |
129 | 4b9d4683 | Luiz Capitulino | .desc = "Bad QMP input object",
|
130 | 4b9d4683 | Luiz Capitulino | }, |
131 | 4b9d4683 | Luiz Capitulino | { |
132 | 7a84cb23 | Markus Armbruster | .error_fmt = QERR_SET_PASSWD_FAILED, |
133 | 7a84cb23 | Markus Armbruster | .desc = "Could not set password",
|
134 | 7a84cb23 | Markus Armbruster | }, |
135 | 7a84cb23 | Markus Armbruster | { |
136 | a488be27 | Markus Armbruster | .error_fmt = QERR_TOO_MANY_FILES, |
137 | a488be27 | Markus Armbruster | .desc = "Too many open files",
|
138 | a488be27 | Markus Armbruster | }, |
139 | a488be27 | Markus Armbruster | { |
140 | e16a1812 | Markus Armbruster | .error_fmt = QERR_UNDEFINED_ERROR, |
141 | e16a1812 | Markus Armbruster | .desc = "An undefined error has ocurred",
|
142 | 4b9d4683 | Luiz Capitulino | }, |
143 | a6906e31 | Markus Armbruster | { |
144 | a6906e31 | Markus Armbruster | .error_fmt = QERR_VNC_SERVER_FAILED, |
145 | a6906e31 | Markus Armbruster | .desc = "Could not start VNC server on %(target)",
|
146 | a6906e31 | Markus Armbruster | }, |
147 | 9f9daf9a | Luiz Capitulino | {} |
148 | 9f9daf9a | Luiz Capitulino | }; |
149 | 9f9daf9a | Luiz Capitulino | |
150 | 9f9daf9a | Luiz Capitulino | /**
|
151 | 9f9daf9a | Luiz Capitulino | * qerror_new(): Create a new QError
|
152 | 9f9daf9a | Luiz Capitulino | *
|
153 | 9f9daf9a | Luiz Capitulino | * Return strong reference.
|
154 | 9f9daf9a | Luiz Capitulino | */
|
155 | 9f9daf9a | Luiz Capitulino | QError *qerror_new(void)
|
156 | 9f9daf9a | Luiz Capitulino | { |
157 | 9f9daf9a | Luiz Capitulino | QError *qerr; |
158 | 9f9daf9a | Luiz Capitulino | |
159 | 9f9daf9a | Luiz Capitulino | qerr = qemu_mallocz(sizeof(*qerr));
|
160 | 9f9daf9a | Luiz Capitulino | QOBJECT_INIT(qerr, &qerror_type); |
161 | 9f9daf9a | Luiz Capitulino | |
162 | 9f9daf9a | Luiz Capitulino | return qerr;
|
163 | 9f9daf9a | Luiz Capitulino | } |
164 | 9f9daf9a | Luiz Capitulino | |
165 | 9f9daf9a | Luiz Capitulino | static void qerror_abort(const QError *qerr, const char *fmt, ...) |
166 | 9f9daf9a | Luiz Capitulino | { |
167 | 9f9daf9a | Luiz Capitulino | va_list ap; |
168 | 9f9daf9a | Luiz Capitulino | |
169 | 9f9daf9a | Luiz Capitulino | fprintf(stderr, "qerror: bad call in function '%s':\n", qerr->func);
|
170 | 9f9daf9a | Luiz Capitulino | fprintf(stderr, "qerror: -> ");
|
171 | 9f9daf9a | Luiz Capitulino | |
172 | 9f9daf9a | Luiz Capitulino | va_start(ap, fmt); |
173 | 9f9daf9a | Luiz Capitulino | vfprintf(stderr, fmt, ap); |
174 | 9f9daf9a | Luiz Capitulino | va_end(ap); |
175 | 9f9daf9a | Luiz Capitulino | |
176 | 9f9daf9a | Luiz Capitulino | fprintf(stderr, "\nqerror: call at %s:%d\n", qerr->file, qerr->linenr);
|
177 | 9f9daf9a | Luiz Capitulino | abort(); |
178 | 9f9daf9a | Luiz Capitulino | } |
179 | 9f9daf9a | Luiz Capitulino | |
180 | 9f9daf9a | Luiz Capitulino | static void qerror_set_data(QError *qerr, const char *fmt, va_list *va) |
181 | 9f9daf9a | Luiz Capitulino | { |
182 | 9f9daf9a | Luiz Capitulino | QObject *obj; |
183 | 9f9daf9a | Luiz Capitulino | |
184 | 9f9daf9a | Luiz Capitulino | obj = qobject_from_jsonv(fmt, va); |
185 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
186 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "invalid format '%s'", fmt);
|
187 | 9f9daf9a | Luiz Capitulino | } |
188 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QDICT) {
|
189 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
|
190 | 9f9daf9a | Luiz Capitulino | } |
191 | 9f9daf9a | Luiz Capitulino | |
192 | 9f9daf9a | Luiz Capitulino | qerr->error = qobject_to_qdict(obj); |
193 | 9f9daf9a | Luiz Capitulino | |
194 | 9f9daf9a | Luiz Capitulino | obj = qdict_get(qerr->error, "class");
|
195 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
196 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
|
197 | 9f9daf9a | Luiz Capitulino | } |
198 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QSTRING) {
|
199 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "'class' key value should be a QString");
|
200 | 9f9daf9a | Luiz Capitulino | } |
201 | 9f9daf9a | Luiz Capitulino | |
202 | 9f9daf9a | Luiz Capitulino | obj = qdict_get(qerr->error, "data");
|
203 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
204 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
|
205 | 9f9daf9a | Luiz Capitulino | } |
206 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QDICT) {
|
207 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "'data' key value should be a QDICT");
|
208 | 9f9daf9a | Luiz Capitulino | } |
209 | 9f9daf9a | Luiz Capitulino | } |
210 | 9f9daf9a | Luiz Capitulino | |
211 | 9f9daf9a | Luiz Capitulino | static void qerror_set_desc(QError *qerr, const char *fmt) |
212 | 9f9daf9a | Luiz Capitulino | { |
213 | 9f9daf9a | Luiz Capitulino | int i;
|
214 | 9f9daf9a | Luiz Capitulino | |
215 | 9f9daf9a | Luiz Capitulino | // FIXME: inefficient loop
|
216 | 9f9daf9a | Luiz Capitulino | |
217 | 9f9daf9a | Luiz Capitulino | for (i = 0; qerror_table[i].error_fmt; i++) { |
218 | 9f9daf9a | Luiz Capitulino | if (strcmp(qerror_table[i].error_fmt, fmt) == 0) { |
219 | 9f9daf9a | Luiz Capitulino | qerr->entry = &qerror_table[i]; |
220 | 9f9daf9a | Luiz Capitulino | return;
|
221 | 9f9daf9a | Luiz Capitulino | } |
222 | 9f9daf9a | Luiz Capitulino | } |
223 | 9f9daf9a | Luiz Capitulino | |
224 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "error format '%s' not found", fmt);
|
225 | 9f9daf9a | Luiz Capitulino | } |
226 | 9f9daf9a | Luiz Capitulino | |
227 | 9f9daf9a | Luiz Capitulino | /**
|
228 | 9f9daf9a | Luiz Capitulino | * qerror_from_info(): Create a new QError from error information
|
229 | 9f9daf9a | Luiz Capitulino | *
|
230 | 9f9daf9a | Luiz Capitulino | * The information consists of:
|
231 | 9f9daf9a | Luiz Capitulino | *
|
232 | 9f9daf9a | Luiz Capitulino | * - file the file name of where the error occurred
|
233 | 9f9daf9a | Luiz Capitulino | * - linenr the line number of where the error occurred
|
234 | 9f9daf9a | Luiz Capitulino | * - func the function name of where the error occurred
|
235 | 9f9daf9a | Luiz Capitulino | * - fmt JSON printf-like dictionary, there must exist keys 'class' and
|
236 | 9f9daf9a | Luiz Capitulino | * 'data'
|
237 | 9f9daf9a | Luiz Capitulino | * - va va_list of all arguments specified by fmt
|
238 | 9f9daf9a | Luiz Capitulino | *
|
239 | 9f9daf9a | Luiz Capitulino | * Return strong reference.
|
240 | 9f9daf9a | Luiz Capitulino | */
|
241 | 9f9daf9a | Luiz Capitulino | QError *qerror_from_info(const char *file, int linenr, const char *func, |
242 | 9f9daf9a | Luiz Capitulino | const char *fmt, va_list *va) |
243 | 9f9daf9a | Luiz Capitulino | { |
244 | 9f9daf9a | Luiz Capitulino | QError *qerr; |
245 | 9f9daf9a | Luiz Capitulino | |
246 | 9f9daf9a | Luiz Capitulino | qerr = qerror_new(); |
247 | 827b0813 | Markus Armbruster | loc_save(&qerr->loc); |
248 | 9f9daf9a | Luiz Capitulino | qerr->linenr = linenr; |
249 | 9f9daf9a | Luiz Capitulino | qerr->file = file; |
250 | 9f9daf9a | Luiz Capitulino | qerr->func = func; |
251 | 9f9daf9a | Luiz Capitulino | |
252 | 9f9daf9a | Luiz Capitulino | if (!fmt) {
|
253 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "QDict not specified");
|
254 | 9f9daf9a | Luiz Capitulino | } |
255 | 9f9daf9a | Luiz Capitulino | |
256 | 9f9daf9a | Luiz Capitulino | qerror_set_data(qerr, fmt, va); |
257 | 9f9daf9a | Luiz Capitulino | qerror_set_desc(qerr, fmt); |
258 | 9f9daf9a | Luiz Capitulino | |
259 | 9f9daf9a | Luiz Capitulino | return qerr;
|
260 | 9f9daf9a | Luiz Capitulino | } |
261 | 9f9daf9a | Luiz Capitulino | |
262 | 9f9daf9a | Luiz Capitulino | static void parse_error(const QError *qerror, int c) |
263 | 9f9daf9a | Luiz Capitulino | { |
264 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerror, "expected '%c' in '%s'", c, qerror->entry->desc);
|
265 | 9f9daf9a | Luiz Capitulino | } |
266 | 9f9daf9a | Luiz Capitulino | |
267 | 9f9daf9a | Luiz Capitulino | static const char *append_field(QString *outstr, const QError *qerror, |
268 | 9f9daf9a | Luiz Capitulino | const char *start) |
269 | 9f9daf9a | Luiz Capitulino | { |
270 | 9f9daf9a | Luiz Capitulino | QObject *obj; |
271 | 9f9daf9a | Luiz Capitulino | QDict *qdict; |
272 | 9f9daf9a | Luiz Capitulino | QString *key_qs; |
273 | 9f9daf9a | Luiz Capitulino | const char *end, *key; |
274 | 9f9daf9a | Luiz Capitulino | |
275 | 9f9daf9a | Luiz Capitulino | if (*start != '%') |
276 | 9f9daf9a | Luiz Capitulino | parse_error(qerror, '%');
|
277 | 9f9daf9a | Luiz Capitulino | start++; |
278 | 9f9daf9a | Luiz Capitulino | if (*start != '(') |
279 | 9f9daf9a | Luiz Capitulino | parse_error(qerror, '(');
|
280 | 9f9daf9a | Luiz Capitulino | start++; |
281 | 9f9daf9a | Luiz Capitulino | |
282 | 9f9daf9a | Luiz Capitulino | end = strchr(start, ')');
|
283 | 9f9daf9a | Luiz Capitulino | if (!end)
|
284 | 9f9daf9a | Luiz Capitulino | parse_error(qerror, ')');
|
285 | 9f9daf9a | Luiz Capitulino | |
286 | 9f9daf9a | Luiz Capitulino | key_qs = qstring_from_substr(start, 0, end - start - 1); |
287 | 9f9daf9a | Luiz Capitulino | key = qstring_get_str(key_qs); |
288 | 9f9daf9a | Luiz Capitulino | |
289 | 9f9daf9a | Luiz Capitulino | qdict = qobject_to_qdict(qdict_get(qerror->error, "data"));
|
290 | 9f9daf9a | Luiz Capitulino | obj = qdict_get(qdict, key); |
291 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
292 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerror, "key '%s' not found in QDict", key);
|
293 | 9f9daf9a | Luiz Capitulino | } |
294 | 9f9daf9a | Luiz Capitulino | |
295 | 9f9daf9a | Luiz Capitulino | switch (qobject_type(obj)) {
|
296 | 9f9daf9a | Luiz Capitulino | case QTYPE_QSTRING:
|
297 | 9f9daf9a | Luiz Capitulino | qstring_append(outstr, qdict_get_str(qdict, key)); |
298 | 9f9daf9a | Luiz Capitulino | break;
|
299 | 9f9daf9a | Luiz Capitulino | case QTYPE_QINT:
|
300 | 9f9daf9a | Luiz Capitulino | qstring_append_int(outstr, qdict_get_int(qdict, key)); |
301 | 9f9daf9a | Luiz Capitulino | break;
|
302 | 9f9daf9a | Luiz Capitulino | default:
|
303 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerror, "invalid type '%c'", qobject_type(obj));
|
304 | 9f9daf9a | Luiz Capitulino | } |
305 | 9f9daf9a | Luiz Capitulino | |
306 | 9f9daf9a | Luiz Capitulino | QDECREF(key_qs); |
307 | 9f9daf9a | Luiz Capitulino | return ++end;
|
308 | 9f9daf9a | Luiz Capitulino | } |
309 | 9f9daf9a | Luiz Capitulino | |
310 | 9f9daf9a | Luiz Capitulino | /**
|
311 | 77e595e7 | Markus Armbruster | * qerror_human(): Format QError data into human-readable string.
|
312 | 9f9daf9a | Luiz Capitulino | *
|
313 | 77e595e7 | Markus Armbruster | * Formats according to member 'desc' of the specified QError object.
|
314 | 9f9daf9a | Luiz Capitulino | */
|
315 | 77e595e7 | Markus Armbruster | QString *qerror_human(const QError *qerror)
|
316 | 9f9daf9a | Luiz Capitulino | { |
317 | 9f9daf9a | Luiz Capitulino | const char *p; |
318 | 9f9daf9a | Luiz Capitulino | QString *qstring; |
319 | 9f9daf9a | Luiz Capitulino | |
320 | 9f9daf9a | Luiz Capitulino | assert(qerror->entry != NULL);
|
321 | 9f9daf9a | Luiz Capitulino | |
322 | 9f9daf9a | Luiz Capitulino | qstring = qstring_new(); |
323 | 9f9daf9a | Luiz Capitulino | |
324 | 9f9daf9a | Luiz Capitulino | for (p = qerror->entry->desc; *p != '\0';) { |
325 | 9f9daf9a | Luiz Capitulino | if (*p != '%') { |
326 | 9f9daf9a | Luiz Capitulino | qstring_append_chr(qstring, *p++); |
327 | 9f9daf9a | Luiz Capitulino | } else if (*(p + 1) == '%') { |
328 | 9f9daf9a | Luiz Capitulino | qstring_append_chr(qstring, '%');
|
329 | 9f9daf9a | Luiz Capitulino | p += 2;
|
330 | 9f9daf9a | Luiz Capitulino | } else {
|
331 | 9f9daf9a | Luiz Capitulino | p = append_field(qstring, qerror, p); |
332 | 9f9daf9a | Luiz Capitulino | } |
333 | 9f9daf9a | Luiz Capitulino | } |
334 | 9f9daf9a | Luiz Capitulino | |
335 | 77e595e7 | Markus Armbruster | return qstring;
|
336 | 77e595e7 | Markus Armbruster | } |
337 | 77e595e7 | Markus Armbruster | |
338 | 77e595e7 | Markus Armbruster | /**
|
339 | 77e595e7 | Markus Armbruster | * qerror_print(): Print QError data
|
340 | 77e595e7 | Markus Armbruster | *
|
341 | 77e595e7 | Markus Armbruster | * This function will print the member 'desc' of the specified QError object,
|
342 | 1ecda02b | Markus Armbruster | * it uses error_report() for this, so that the output is routed to the right
|
343 | 77e595e7 | Markus Armbruster | * place (ie. stderr or Monitor's device).
|
344 | 77e595e7 | Markus Armbruster | */
|
345 | 827b0813 | Markus Armbruster | void qerror_print(QError *qerror)
|
346 | 77e595e7 | Markus Armbruster | { |
347 | 77e595e7 | Markus Armbruster | QString *qstring = qerror_human(qerror); |
348 | 827b0813 | Markus Armbruster | loc_push_restore(&qerror->loc); |
349 | 1ecda02b | Markus Armbruster | error_report("%s", qstring_get_str(qstring));
|
350 | 827b0813 | Markus Armbruster | loc_pop(&qerror->loc); |
351 | 9f9daf9a | Luiz Capitulino | QDECREF(qstring); |
352 | 9f9daf9a | Luiz Capitulino | } |
353 | 9f9daf9a | Luiz Capitulino | |
354 | 9f9daf9a | Luiz Capitulino | /**
|
355 | 9f9daf9a | Luiz Capitulino | * qobject_to_qerror(): Convert a QObject into a QError
|
356 | 9f9daf9a | Luiz Capitulino | */
|
357 | 9f9daf9a | Luiz Capitulino | QError *qobject_to_qerror(const QObject *obj)
|
358 | 9f9daf9a | Luiz Capitulino | { |
359 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QERROR) {
|
360 | 9f9daf9a | Luiz Capitulino | return NULL; |
361 | 9f9daf9a | Luiz Capitulino | } |
362 | 9f9daf9a | Luiz Capitulino | |
363 | 9f9daf9a | Luiz Capitulino | return container_of(obj, QError, base);
|
364 | 9f9daf9a | Luiz Capitulino | } |
365 | 9f9daf9a | Luiz Capitulino | |
366 | 9f9daf9a | Luiz Capitulino | /**
|
367 | 9f9daf9a | Luiz Capitulino | * qerror_destroy_obj(): Free all memory allocated by a QError
|
368 | 9f9daf9a | Luiz Capitulino | */
|
369 | 9f9daf9a | Luiz Capitulino | static void qerror_destroy_obj(QObject *obj) |
370 | 9f9daf9a | Luiz Capitulino | { |
371 | 9f9daf9a | Luiz Capitulino | QError *qerr; |
372 | 9f9daf9a | Luiz Capitulino | |
373 | 9f9daf9a | Luiz Capitulino | assert(obj != NULL);
|
374 | 9f9daf9a | Luiz Capitulino | qerr = qobject_to_qerror(obj); |
375 | 9f9daf9a | Luiz Capitulino | |
376 | 9f9daf9a | Luiz Capitulino | QDECREF(qerr->error); |
377 | 9f9daf9a | Luiz Capitulino | qemu_free(qerr); |
378 | 9f9daf9a | Luiz Capitulino | } |