root / qerror.c @ b5ec5ce0
History | View | Annotate | Download (8.6 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 "sysemu.h" |
16 | 9f9daf9a | Luiz Capitulino | #include "qemu-common.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 | e16a1812 | Markus Armbruster | .error_fmt = QERR_COMMAND_NOT_FOUND, |
45 | e16a1812 | Markus Armbruster | .desc = "The command %(name) has not been found",
|
46 | 4b9d4683 | Luiz Capitulino | }, |
47 | 4b9d4683 | Luiz Capitulino | { |
48 | 0df37c41 | Luiz Capitulino | .error_fmt = QERR_DEVICE_ENCRYPTED, |
49 | 0df37c41 | Luiz Capitulino | .desc = "The %(device) is encrypted",
|
50 | 0df37c41 | Luiz Capitulino | }, |
51 | 0df37c41 | Luiz Capitulino | { |
52 | b0868380 | Markus Armbruster | .error_fmt = QERR_DEVICE_LOCKED, |
53 | b0868380 | Markus Armbruster | .desc = "Device %(device) is locked",
|
54 | b0868380 | Markus Armbruster | }, |
55 | b0868380 | Markus Armbruster | { |
56 | e16a1812 | Markus Armbruster | .error_fmt = QERR_DEVICE_NOT_ACTIVE, |
57 | e16a1812 | Markus Armbruster | .desc = "The %(device) device has not been activated by the guest",
|
58 | e16a1812 | Markus Armbruster | }, |
59 | e16a1812 | Markus Armbruster | { |
60 | 357b6156 | Luiz Capitulino | .error_fmt = QERR_DEVICE_NOT_FOUND, |
61 | 357b6156 | Luiz Capitulino | .desc = "The %(device) device has not been found",
|
62 | 357b6156 | Luiz Capitulino | }, |
63 | 055f6122 | Luiz Capitulino | { |
64 | 5cfe0264 | Markus Armbruster | .error_fmt = QERR_DEVICE_NOT_REMOVABLE, |
65 | 5cfe0264 | Markus Armbruster | .desc = "Device %(device) is not removable",
|
66 | 5cfe0264 | Markus Armbruster | }, |
67 | 5cfe0264 | Markus Armbruster | { |
68 | c7c338c4 | Markus Armbruster | .error_fmt = QERR_FD_NOT_FOUND, |
69 | c7c338c4 | Markus Armbruster | .desc = "Failed to find file descriptor named %(name)",
|
70 | c7c338c4 | Markus Armbruster | }, |
71 | c7c338c4 | Markus Armbruster | { |
72 | 41471a23 | Markus Armbruster | .error_fmt = QERR_FD_NOT_SUPPLIED, |
73 | 41471a23 | Markus Armbruster | .desc = "No file descriptor supplied via SCM_RIGHTS",
|
74 | 41471a23 | Markus Armbruster | }, |
75 | 41471a23 | Markus Armbruster | { |
76 | 3da2c808 | Markus Armbruster | .error_fmt = QERR_OPEN_FILE_FAILED, |
77 | 3da2c808 | Markus Armbruster | .desc = "Could not open '%(filename)'",
|
78 | 3da2c808 | Markus Armbruster | }, |
79 | 3da2c808 | Markus Armbruster | { |
80 | 17901e75 | Markus Armbruster | .error_fmt = QERR_INVALID_BLOCK_FORMAT, |
81 | 17901e75 | 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 | 7a046f5f | 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 | e16a1812 | Markus Armbruster | .desc = "The entered password is invalid",
|
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 | 4b9d4683 | Luiz Capitulino | .desc = "Parameter %(name) is missing",
|
106 | 4b9d4683 | Luiz Capitulino | }, |
107 | 4b9d4683 | Luiz Capitulino | { |
108 | 4b9d4683 | Luiz Capitulino | .error_fmt = QERR_QMP_BAD_INPUT_OBJECT, |
109 | 4b9d4683 | Luiz Capitulino | .desc = "Bad QMP input object",
|
110 | 4b9d4683 | Luiz Capitulino | }, |
111 | 4b9d4683 | Luiz Capitulino | { |
112 | 7a84cb23 | Markus Armbruster | .error_fmt = QERR_SET_PASSWD_FAILED, |
113 | 7a84cb23 | Markus Armbruster | .desc = "Could not set password",
|
114 | 7a84cb23 | Markus Armbruster | }, |
115 | 7a84cb23 | Markus Armbruster | { |
116 | a488be27 | Markus Armbruster | .error_fmt = QERR_TOO_MANY_FILES, |
117 | a488be27 | Markus Armbruster | .desc = "Too many open files",
|
118 | a488be27 | Markus Armbruster | }, |
119 | a488be27 | Markus Armbruster | { |
120 | e16a1812 | Markus Armbruster | .error_fmt = QERR_UNDEFINED_ERROR, |
121 | e16a1812 | Markus Armbruster | .desc = "An undefined error has ocurred",
|
122 | 4b9d4683 | Luiz Capitulino | }, |
123 | a6906e31 | Markus Armbruster | { |
124 | a6906e31 | Markus Armbruster | .error_fmt = QERR_VNC_SERVER_FAILED, |
125 | a6906e31 | Markus Armbruster | .desc = "Could not start VNC server on %(target)",
|
126 | a6906e31 | Markus Armbruster | }, |
127 | 9f9daf9a | Luiz Capitulino | {} |
128 | 9f9daf9a | Luiz Capitulino | }; |
129 | 9f9daf9a | Luiz Capitulino | |
130 | 9f9daf9a | Luiz Capitulino | /**
|
131 | 9f9daf9a | Luiz Capitulino | * qerror_new(): Create a new QError
|
132 | 9f9daf9a | Luiz Capitulino | *
|
133 | 9f9daf9a | Luiz Capitulino | * Return strong reference.
|
134 | 9f9daf9a | Luiz Capitulino | */
|
135 | 9f9daf9a | Luiz Capitulino | QError *qerror_new(void)
|
136 | 9f9daf9a | Luiz Capitulino | { |
137 | 9f9daf9a | Luiz Capitulino | QError *qerr; |
138 | 9f9daf9a | Luiz Capitulino | |
139 | 9f9daf9a | Luiz Capitulino | qerr = qemu_mallocz(sizeof(*qerr));
|
140 | 9f9daf9a | Luiz Capitulino | QOBJECT_INIT(qerr, &qerror_type); |
141 | 9f9daf9a | Luiz Capitulino | |
142 | 9f9daf9a | Luiz Capitulino | return qerr;
|
143 | 9f9daf9a | Luiz Capitulino | } |
144 | 9f9daf9a | Luiz Capitulino | |
145 | 9f9daf9a | Luiz Capitulino | static void qerror_abort(const QError *qerr, const char *fmt, ...) |
146 | 9f9daf9a | Luiz Capitulino | { |
147 | 9f9daf9a | Luiz Capitulino | va_list ap; |
148 | 9f9daf9a | Luiz Capitulino | |
149 | 9f9daf9a | Luiz Capitulino | fprintf(stderr, "qerror: bad call in function '%s':\n", qerr->func);
|
150 | 9f9daf9a | Luiz Capitulino | fprintf(stderr, "qerror: -> ");
|
151 | 9f9daf9a | Luiz Capitulino | |
152 | 9f9daf9a | Luiz Capitulino | va_start(ap, fmt); |
153 | 9f9daf9a | Luiz Capitulino | vfprintf(stderr, fmt, ap); |
154 | 9f9daf9a | Luiz Capitulino | va_end(ap); |
155 | 9f9daf9a | Luiz Capitulino | |
156 | 9f9daf9a | Luiz Capitulino | fprintf(stderr, "\nqerror: call at %s:%d\n", qerr->file, qerr->linenr);
|
157 | 9f9daf9a | Luiz Capitulino | abort(); |
158 | 9f9daf9a | Luiz Capitulino | } |
159 | 9f9daf9a | Luiz Capitulino | |
160 | 9f9daf9a | Luiz Capitulino | static void qerror_set_data(QError *qerr, const char *fmt, va_list *va) |
161 | 9f9daf9a | Luiz Capitulino | { |
162 | 9f9daf9a | Luiz Capitulino | QObject *obj; |
163 | 9f9daf9a | Luiz Capitulino | |
164 | 9f9daf9a | Luiz Capitulino | obj = qobject_from_jsonv(fmt, va); |
165 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
166 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "invalid format '%s'", fmt);
|
167 | 9f9daf9a | Luiz Capitulino | } |
168 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QDICT) {
|
169 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "error format is not a QDict '%s'", fmt);
|
170 | 9f9daf9a | Luiz Capitulino | } |
171 | 9f9daf9a | Luiz Capitulino | |
172 | 9f9daf9a | Luiz Capitulino | qerr->error = qobject_to_qdict(obj); |
173 | 9f9daf9a | Luiz Capitulino | |
174 | 9f9daf9a | Luiz Capitulino | obj = qdict_get(qerr->error, "class");
|
175 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
176 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "missing 'class' key in '%s'", fmt);
|
177 | 9f9daf9a | Luiz Capitulino | } |
178 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QSTRING) {
|
179 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "'class' key value should be a QString");
|
180 | 9f9daf9a | Luiz Capitulino | } |
181 | 9f9daf9a | Luiz Capitulino | |
182 | 9f9daf9a | Luiz Capitulino | obj = qdict_get(qerr->error, "data");
|
183 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
184 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "missing 'data' key in '%s'", fmt);
|
185 | 9f9daf9a | Luiz Capitulino | } |
186 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QDICT) {
|
187 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "'data' key value should be a QDICT");
|
188 | 9f9daf9a | Luiz Capitulino | } |
189 | 9f9daf9a | Luiz Capitulino | } |
190 | 9f9daf9a | Luiz Capitulino | |
191 | 9f9daf9a | Luiz Capitulino | static void qerror_set_desc(QError *qerr, const char *fmt) |
192 | 9f9daf9a | Luiz Capitulino | { |
193 | 9f9daf9a | Luiz Capitulino | int i;
|
194 | 9f9daf9a | Luiz Capitulino | |
195 | 9f9daf9a | Luiz Capitulino | // FIXME: inefficient loop
|
196 | 9f9daf9a | Luiz Capitulino | |
197 | 9f9daf9a | Luiz Capitulino | for (i = 0; qerror_table[i].error_fmt; i++) { |
198 | 9f9daf9a | Luiz Capitulino | if (strcmp(qerror_table[i].error_fmt, fmt) == 0) { |
199 | 9f9daf9a | Luiz Capitulino | qerr->entry = &qerror_table[i]; |
200 | 9f9daf9a | Luiz Capitulino | return;
|
201 | 9f9daf9a | Luiz Capitulino | } |
202 | 9f9daf9a | Luiz Capitulino | } |
203 | 9f9daf9a | Luiz Capitulino | |
204 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "error format '%s' not found", fmt);
|
205 | 9f9daf9a | Luiz Capitulino | } |
206 | 9f9daf9a | Luiz Capitulino | |
207 | 9f9daf9a | Luiz Capitulino | /**
|
208 | 9f9daf9a | Luiz Capitulino | * qerror_from_info(): Create a new QError from error information
|
209 | 9f9daf9a | Luiz Capitulino | *
|
210 | 9f9daf9a | Luiz Capitulino | * The information consists of:
|
211 | 9f9daf9a | Luiz Capitulino | *
|
212 | 9f9daf9a | Luiz Capitulino | * - file the file name of where the error occurred
|
213 | 9f9daf9a | Luiz Capitulino | * - linenr the line number of where the error occurred
|
214 | 9f9daf9a | Luiz Capitulino | * - func the function name of where the error occurred
|
215 | 9f9daf9a | Luiz Capitulino | * - fmt JSON printf-like dictionary, there must exist keys 'class' and
|
216 | 9f9daf9a | Luiz Capitulino | * 'data'
|
217 | 9f9daf9a | Luiz Capitulino | * - va va_list of all arguments specified by fmt
|
218 | 9f9daf9a | Luiz Capitulino | *
|
219 | 9f9daf9a | Luiz Capitulino | * Return strong reference.
|
220 | 9f9daf9a | Luiz Capitulino | */
|
221 | 9f9daf9a | Luiz Capitulino | QError *qerror_from_info(const char *file, int linenr, const char *func, |
222 | 9f9daf9a | Luiz Capitulino | const char *fmt, va_list *va) |
223 | 9f9daf9a | Luiz Capitulino | { |
224 | 9f9daf9a | Luiz Capitulino | QError *qerr; |
225 | 9f9daf9a | Luiz Capitulino | |
226 | 9f9daf9a | Luiz Capitulino | qerr = qerror_new(); |
227 | 9f9daf9a | Luiz Capitulino | qerr->linenr = linenr; |
228 | 9f9daf9a | Luiz Capitulino | qerr->file = file; |
229 | 9f9daf9a | Luiz Capitulino | qerr->func = func; |
230 | 9f9daf9a | Luiz Capitulino | |
231 | 9f9daf9a | Luiz Capitulino | if (!fmt) {
|
232 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerr, "QDict not specified");
|
233 | 9f9daf9a | Luiz Capitulino | } |
234 | 9f9daf9a | Luiz Capitulino | |
235 | 9f9daf9a | Luiz Capitulino | qerror_set_data(qerr, fmt, va); |
236 | 9f9daf9a | Luiz Capitulino | qerror_set_desc(qerr, fmt); |
237 | 9f9daf9a | Luiz Capitulino | |
238 | 9f9daf9a | Luiz Capitulino | return qerr;
|
239 | 9f9daf9a | Luiz Capitulino | } |
240 | 9f9daf9a | Luiz Capitulino | |
241 | 9f9daf9a | Luiz Capitulino | static void parse_error(const QError *qerror, int c) |
242 | 9f9daf9a | Luiz Capitulino | { |
243 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerror, "expected '%c' in '%s'", c, qerror->entry->desc);
|
244 | 9f9daf9a | Luiz Capitulino | } |
245 | 9f9daf9a | Luiz Capitulino | |
246 | 9f9daf9a | Luiz Capitulino | static const char *append_field(QString *outstr, const QError *qerror, |
247 | 9f9daf9a | Luiz Capitulino | const char *start) |
248 | 9f9daf9a | Luiz Capitulino | { |
249 | 9f9daf9a | Luiz Capitulino | QObject *obj; |
250 | 9f9daf9a | Luiz Capitulino | QDict *qdict; |
251 | 9f9daf9a | Luiz Capitulino | QString *key_qs; |
252 | 9f9daf9a | Luiz Capitulino | const char *end, *key; |
253 | 9f9daf9a | Luiz Capitulino | |
254 | 9f9daf9a | Luiz Capitulino | if (*start != '%') |
255 | 9f9daf9a | Luiz Capitulino | parse_error(qerror, '%');
|
256 | 9f9daf9a | Luiz Capitulino | start++; |
257 | 9f9daf9a | Luiz Capitulino | if (*start != '(') |
258 | 9f9daf9a | Luiz Capitulino | parse_error(qerror, '(');
|
259 | 9f9daf9a | Luiz Capitulino | start++; |
260 | 9f9daf9a | Luiz Capitulino | |
261 | 9f9daf9a | Luiz Capitulino | end = strchr(start, ')');
|
262 | 9f9daf9a | Luiz Capitulino | if (!end)
|
263 | 9f9daf9a | Luiz Capitulino | parse_error(qerror, ')');
|
264 | 9f9daf9a | Luiz Capitulino | |
265 | 9f9daf9a | Luiz Capitulino | key_qs = qstring_from_substr(start, 0, end - start - 1); |
266 | 9f9daf9a | Luiz Capitulino | key = qstring_get_str(key_qs); |
267 | 9f9daf9a | Luiz Capitulino | |
268 | 9f9daf9a | Luiz Capitulino | qdict = qobject_to_qdict(qdict_get(qerror->error, "data"));
|
269 | 9f9daf9a | Luiz Capitulino | obj = qdict_get(qdict, key); |
270 | 9f9daf9a | Luiz Capitulino | if (!obj) {
|
271 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerror, "key '%s' not found in QDict", key);
|
272 | 9f9daf9a | Luiz Capitulino | } |
273 | 9f9daf9a | Luiz Capitulino | |
274 | 9f9daf9a | Luiz Capitulino | switch (qobject_type(obj)) {
|
275 | 9f9daf9a | Luiz Capitulino | case QTYPE_QSTRING:
|
276 | 9f9daf9a | Luiz Capitulino | qstring_append(outstr, qdict_get_str(qdict, key)); |
277 | 9f9daf9a | Luiz Capitulino | break;
|
278 | 9f9daf9a | Luiz Capitulino | case QTYPE_QINT:
|
279 | 9f9daf9a | Luiz Capitulino | qstring_append_int(outstr, qdict_get_int(qdict, key)); |
280 | 9f9daf9a | Luiz Capitulino | break;
|
281 | 9f9daf9a | Luiz Capitulino | default:
|
282 | 9f9daf9a | Luiz Capitulino | qerror_abort(qerror, "invalid type '%c'", qobject_type(obj));
|
283 | 9f9daf9a | Luiz Capitulino | } |
284 | 9f9daf9a | Luiz Capitulino | |
285 | 9f9daf9a | Luiz Capitulino | QDECREF(key_qs); |
286 | 9f9daf9a | Luiz Capitulino | return ++end;
|
287 | 9f9daf9a | Luiz Capitulino | } |
288 | 9f9daf9a | Luiz Capitulino | |
289 | 9f9daf9a | Luiz Capitulino | /**
|
290 | 77e595e7 | Markus Armbruster | * qerror_human(): Format QError data into human-readable string.
|
291 | 9f9daf9a | Luiz Capitulino | *
|
292 | 77e595e7 | Markus Armbruster | * Formats according to member 'desc' of the specified QError object.
|
293 | 9f9daf9a | Luiz Capitulino | */
|
294 | 77e595e7 | Markus Armbruster | QString *qerror_human(const QError *qerror)
|
295 | 9f9daf9a | Luiz Capitulino | { |
296 | 9f9daf9a | Luiz Capitulino | const char *p; |
297 | 9f9daf9a | Luiz Capitulino | QString *qstring; |
298 | 9f9daf9a | Luiz Capitulino | |
299 | 9f9daf9a | Luiz Capitulino | assert(qerror->entry != NULL);
|
300 | 9f9daf9a | Luiz Capitulino | |
301 | 9f9daf9a | Luiz Capitulino | qstring = qstring_new(); |
302 | 9f9daf9a | Luiz Capitulino | |
303 | 9f9daf9a | Luiz Capitulino | for (p = qerror->entry->desc; *p != '\0';) { |
304 | 9f9daf9a | Luiz Capitulino | if (*p != '%') { |
305 | 9f9daf9a | Luiz Capitulino | qstring_append_chr(qstring, *p++); |
306 | 9f9daf9a | Luiz Capitulino | } else if (*(p + 1) == '%') { |
307 | 9f9daf9a | Luiz Capitulino | qstring_append_chr(qstring, '%');
|
308 | 9f9daf9a | Luiz Capitulino | p += 2;
|
309 | 9f9daf9a | Luiz Capitulino | } else {
|
310 | 9f9daf9a | Luiz Capitulino | p = append_field(qstring, qerror, p); |
311 | 9f9daf9a | Luiz Capitulino | } |
312 | 9f9daf9a | Luiz Capitulino | } |
313 | 9f9daf9a | Luiz Capitulino | |
314 | 77e595e7 | Markus Armbruster | return qstring;
|
315 | 77e595e7 | Markus Armbruster | } |
316 | 77e595e7 | Markus Armbruster | |
317 | 77e595e7 | Markus Armbruster | /**
|
318 | 77e595e7 | Markus Armbruster | * qerror_print(): Print QError data
|
319 | 77e595e7 | Markus Armbruster | *
|
320 | 77e595e7 | Markus Armbruster | * This function will print the member 'desc' of the specified QError object,
|
321 | 77e595e7 | Markus Armbruster | * it uses qemu_error() for this, so that the output is routed to the right
|
322 | 77e595e7 | Markus Armbruster | * place (ie. stderr or Monitor's device).
|
323 | 77e595e7 | Markus Armbruster | */
|
324 | 77e595e7 | Markus Armbruster | void qerror_print(const QError *qerror) |
325 | 77e595e7 | Markus Armbruster | { |
326 | 77e595e7 | Markus Armbruster | QString *qstring = qerror_human(qerror); |
327 | 9f9daf9a | Luiz Capitulino | qemu_error("%s\n", qstring_get_str(qstring));
|
328 | 9f9daf9a | Luiz Capitulino | QDECREF(qstring); |
329 | 9f9daf9a | Luiz Capitulino | } |
330 | 9f9daf9a | Luiz Capitulino | |
331 | 9f9daf9a | Luiz Capitulino | /**
|
332 | 9f9daf9a | Luiz Capitulino | * qobject_to_qerror(): Convert a QObject into a QError
|
333 | 9f9daf9a | Luiz Capitulino | */
|
334 | 9f9daf9a | Luiz Capitulino | QError *qobject_to_qerror(const QObject *obj)
|
335 | 9f9daf9a | Luiz Capitulino | { |
336 | 9f9daf9a | Luiz Capitulino | if (qobject_type(obj) != QTYPE_QERROR) {
|
337 | 9f9daf9a | Luiz Capitulino | return NULL; |
338 | 9f9daf9a | Luiz Capitulino | } |
339 | 9f9daf9a | Luiz Capitulino | |
340 | 9f9daf9a | Luiz Capitulino | return container_of(obj, QError, base);
|
341 | 9f9daf9a | Luiz Capitulino | } |
342 | 9f9daf9a | Luiz Capitulino | |
343 | 9f9daf9a | Luiz Capitulino | /**
|
344 | 9f9daf9a | Luiz Capitulino | * qerror_destroy_obj(): Free all memory allocated by a QError
|
345 | 9f9daf9a | Luiz Capitulino | */
|
346 | 9f9daf9a | Luiz Capitulino | static void qerror_destroy_obj(QObject *obj) |
347 | 9f9daf9a | Luiz Capitulino | { |
348 | 9f9daf9a | Luiz Capitulino | QError *qerr; |
349 | 9f9daf9a | Luiz Capitulino | |
350 | 9f9daf9a | Luiz Capitulino | assert(obj != NULL);
|
351 | 9f9daf9a | Luiz Capitulino | qerr = qobject_to_qerror(obj); |
352 | 9f9daf9a | Luiz Capitulino | |
353 | 9f9daf9a | Luiz Capitulino | QDECREF(qerr->error); |
354 | 9f9daf9a | Luiz Capitulino | qemu_free(qerr); |
355 | 9f9daf9a | Luiz Capitulino | } |