|
1 /** |
|
2 * XML Security Library (http://www.aleksey.com/xmlsec). |
|
3 * |
|
4 * Error codes and error reporting functions. |
|
5 * |
|
6 * This is free software; see Copyright file in the source |
|
7 * distribution for preciese wording. |
|
8 * |
|
9 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com> |
|
10 * Portion Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. |
|
11 */ |
|
12 #ifndef __XMLSEC_ERRORS_H__ |
|
13 #define __XMLSEC_ERRORS_H__ |
|
14 |
|
15 #ifdef __cplusplus |
|
16 extern "C" { |
|
17 #endif /* __cplusplus */ |
|
18 |
|
19 #include "xmlsec_config.h" |
|
20 |
|
21 /*************************************************************** |
|
22 * |
|
23 * Error codes |
|
24 * |
|
25 **************************************************************/ |
|
26 /** |
|
27 * XMLSEC_ERRORS_R_XMLSEC_FAILED: |
|
28 * |
|
29 * An XMLSec function failed (error subject is the failed function). |
|
30 */ |
|
31 #define XMLSEC_ERRORS_R_XMLSEC_FAILED 1 |
|
32 |
|
33 /** |
|
34 * XMLSEC_ERRORS_R_MALLOC_FAILED: |
|
35 * |
|
36 * Failed to allocate memory error. |
|
37 */ |
|
38 #define XMLSEC_ERRORS_R_MALLOC_FAILED 2 |
|
39 |
|
40 /** |
|
41 * XMLSEC_ERRORS_R_STRDUP_FAILED: |
|
42 * |
|
43 * Failed to duplicate string error. |
|
44 */ |
|
45 #define XMLSEC_ERRORS_R_STRDUP_FAILED 3 |
|
46 |
|
47 /** |
|
48 * XMLSEC_ERRORS_R_CRYPTO_FAILED: |
|
49 * |
|
50 * Crypto (OpenSSL) function failed (error subject is the failed function). |
|
51 */ |
|
52 #define XMLSEC_ERRORS_R_CRYPTO_FAILED 4 |
|
53 |
|
54 /** |
|
55 * XMLSEC_ERRORS_R_XML_FAILED: |
|
56 * |
|
57 * LibXML function failed (error subject is the failed function). |
|
58 */ |
|
59 #define XMLSEC_ERRORS_R_XML_FAILED 5 |
|
60 |
|
61 /** |
|
62 * XMLSEC_ERRORS_R_XSLT_FAILED: |
|
63 * |
|
64 * LibXSLT function failed (error subject is the failed function). |
|
65 */ |
|
66 #define XMLSEC_ERRORS_R_XSLT_FAILED 6 |
|
67 |
|
68 /** |
|
69 * XMLSEC_ERRORS_R_IO_FAILED: |
|
70 * |
|
71 * IO operation failed. |
|
72 */ |
|
73 #define XMLSEC_ERRORS_R_IO_FAILED 7 |
|
74 |
|
75 /** |
|
76 * XMLSEC_ERRORS_R_DISABLED: |
|
77 * |
|
78 * The feature is disabled during compilation. |
|
79 * Check './configure --help' for details on how to |
|
80 * enable it. |
|
81 */ |
|
82 #define XMLSEC_ERRORS_R_DISABLED 8 |
|
83 |
|
84 /** |
|
85 * XMLSEC_ERRORS_R_NOT_IMPLEMENTED: |
|
86 * |
|
87 * Feature is not implemented. |
|
88 */ |
|
89 #define XMLSEC_ERRORS_R_NOT_IMPLEMENTED 9 |
|
90 |
|
91 /** |
|
92 * XMLSEC_ERRORS_R_INVALID_SIZE: |
|
93 * |
|
94 * Invalid size. |
|
95 */ |
|
96 #define XMLSEC_ERRORS_R_INVALID_SIZE 11 |
|
97 |
|
98 /** |
|
99 * XMLSEC_ERRORS_R_INVALID_DATA: |
|
100 * |
|
101 * Invalid data. |
|
102 */ |
|
103 #define XMLSEC_ERRORS_R_INVALID_DATA 12 |
|
104 |
|
105 /** |
|
106 * XMLSEC_ERRORS_R_INVALID_RESULT: |
|
107 * |
|
108 * Invalid result. |
|
109 */ |
|
110 #define XMLSEC_ERRORS_R_INVALID_RESULT 13 |
|
111 |
|
112 /** |
|
113 * XMLSEC_ERRORS_R_INVALID_TYPE: |
|
114 * |
|
115 * Invalid type. |
|
116 */ |
|
117 #define XMLSEC_ERRORS_R_INVALID_TYPE 14 |
|
118 |
|
119 /** |
|
120 * XMLSEC_ERRORS_R_INVALID_OPERATION: |
|
121 * |
|
122 * Invalid operation. |
|
123 */ |
|
124 #define XMLSEC_ERRORS_R_INVALID_OPERATION 15 |
|
125 |
|
126 /** |
|
127 * XMLSEC_ERRORS_R_INVALID_STATUS: |
|
128 * |
|
129 * Invalid status. |
|
130 */ |
|
131 #define XMLSEC_ERRORS_R_INVALID_STATUS 16 |
|
132 |
|
133 /** |
|
134 * XMLSEC_ERRORS_R_INVALID_FORMAT: |
|
135 * |
|
136 * Invalid format. |
|
137 */ |
|
138 #define XMLSEC_ERRORS_R_INVALID_FORMAT 17 |
|
139 |
|
140 /** |
|
141 * XMLSEC_ERRORS_R_DATA_NOT_MATCH: |
|
142 * |
|
143 * The data do not match our expectation. |
|
144 */ |
|
145 #define XMLSEC_ERRORS_R_DATA_NOT_MATCH 18 |
|
146 |
|
147 /** |
|
148 * XMLSEC_ERRORS_R_INVALID_NODE: |
|
149 * |
|
150 * Invalid node (error subject is the node name). |
|
151 */ |
|
152 #define XMLSEC_ERRORS_R_INVALID_NODE 21 |
|
153 |
|
154 /** |
|
155 * XMLSEC_ERRORS_R_INVALID_NODE_CONTENT: |
|
156 * |
|
157 * Invalid node content (error subject is the node name). |
|
158 */ |
|
159 #define XMLSEC_ERRORS_R_INVALID_NODE_CONTENT 22 |
|
160 |
|
161 /** |
|
162 * XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE: |
|
163 * |
|
164 * Invalid node attribute (error subject is the node name). |
|
165 */ |
|
166 #define XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE 23 |
|
167 |
|
168 /** |
|
169 * XMLSEC_ERRORS_R_MISSING_NODE_ATTRIBUTE: |
|
170 * |
|
171 * Missing node attribute (error subject is the node name). |
|
172 */ |
|
173 #define XMLSEC_ERRORS_R_MISSING_NODE_ATTRIBUTE 25 |
|
174 |
|
175 /** |
|
176 * XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT: |
|
177 * |
|
178 * Node already present, |
|
179 */ |
|
180 #define XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT 26 |
|
181 |
|
182 /** |
|
183 * XMLSEC_ERRORS_R_UNEXPECTED_NODE: |
|
184 * |
|
185 * Unexpected node (error subject is the node name). |
|
186 */ |
|
187 #define XMLSEC_ERRORS_R_UNEXPECTED_NODE 27 |
|
188 |
|
189 /** |
|
190 * XMLSEC_ERRORS_R_NODE_NOT_FOUND: |
|
191 * |
|
192 * Node not found (error subject is the required node name). |
|
193 */ |
|
194 #define XMLSEC_ERRORS_R_NODE_NOT_FOUND 28 |
|
195 |
|
196 /** |
|
197 * XMLSEC_ERRORS_R_INVALID_TRANSFORM: |
|
198 * |
|
199 * This transform is invlaid here. |
|
200 */ |
|
201 #define XMLSEC_ERRORS_R_INVALID_TRANSFORM 31 |
|
202 |
|
203 /** |
|
204 * XMLSEC_ERRORS_R_INVALID_TRANSFORM_KEY: |
|
205 * |
|
206 * Key is invalid for this transform. |
|
207 */ |
|
208 #define XMLSEC_ERRORS_R_INVALID_TRANSFORM_KEY 32 |
|
209 |
|
210 /** |
|
211 * XMLSEC_ERRORS_R_INVALID_URI_TYPE: |
|
212 * |
|
213 * Invalid URI type. |
|
214 */ |
|
215 #define XMLSEC_ERRORS_R_INVALID_URI_TYPE 33 |
|
216 |
|
217 /** |
|
218 * XMLSEC_ERRORS_R_TRANSFORM_SAME_DOCUMENT_REQUIRED: |
|
219 * |
|
220 * The transform requires the input document to be the same as context. |
|
221 */ |
|
222 #define XMLSEC_ERRORS_R_TRANSFORM_SAME_DOCUMENT_REQUIRED 34 |
|
223 |
|
224 /** |
|
225 * XMLSEC_ERRORS_R_TRANSFORM_DISABLED: |
|
226 * |
|
227 * The transform is disabled. |
|
228 */ |
|
229 #define XMLSEC_ERRORS_R_TRANSFORM_DISABLED 35 |
|
230 |
|
231 /** |
|
232 * XMLSEC_ERRORS_R_INVALID_KEY_DATA: |
|
233 * |
|
234 * Key data is invalid. |
|
235 */ |
|
236 #define XMLSEC_ERRORS_R_INVALID_KEY_DATA 41 |
|
237 |
|
238 /** |
|
239 * XMLSEC_ERRORS_R_KEY_DATA_NOT_FOUND: |
|
240 * |
|
241 * Data is not found (error subject is the data name). |
|
242 */ |
|
243 #define XMLSEC_ERRORS_R_KEY_DATA_NOT_FOUND 42 |
|
244 |
|
245 /** |
|
246 * XMLSEC_ERRORS_R_KEY_DATA_ALREADY_EXIST: |
|
247 * |
|
248 * The key data is already exist. |
|
249 */ |
|
250 #define XMLSEC_ERRORS_R_KEY_DATA_ALREADY_EXIST 43 |
|
251 |
|
252 /** |
|
253 * XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE: |
|
254 * |
|
255 * Invalid key size. |
|
256 */ |
|
257 #define XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE 44 |
|
258 |
|
259 /** |
|
260 * XMLSEC_ERRORS_R_KEY_NOT_FOUND: |
|
261 * |
|
262 * Key not found. |
|
263 */ |
|
264 #define XMLSEC_ERRORS_R_KEY_NOT_FOUND 45 |
|
265 |
|
266 /** |
|
267 * XMLSEC_ERRORS_R_KEYDATA_DISABLED: |
|
268 * |
|
269 * The key data type disabled. |
|
270 */ |
|
271 #define XMLSEC_ERRORS_R_KEYDATA_DISABLED 46 |
|
272 |
|
273 /** |
|
274 * XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL: |
|
275 * |
|
276 * Max allowed retrievals level reached. |
|
277 */ |
|
278 #define XMLSEC_ERRORS_R_MAX_RETRIEVALS_LEVEL 51 |
|
279 |
|
280 /** |
|
281 * XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH: |
|
282 * |
|
283 * The retrieved key data type does not match the one specified |
|
284 * in the <dsig:RetrievalMethod/> node. |
|
285 */ |
|
286 #define XMLSEC_ERRORS_R_MAX_RETRIEVAL_TYPE_MISMATCH 52 |
|
287 |
|
288 /** |
|
289 * XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL: |
|
290 * |
|
291 * Max EncryptedKey level reached. |
|
292 */ |
|
293 #define XMLSEC_ERRORS_R_MAX_ENCKEY_LEVEL 61 |
|
294 |
|
295 /** |
|
296 * XMLSEC_ERRORS_R_CERT_VERIFY_FAILED: |
|
297 * |
|
298 * Certificate verification failed. |
|
299 */ |
|
300 #define XMLSEC_ERRORS_R_CERT_VERIFY_FAILED 71 |
|
301 |
|
302 /** |
|
303 * XMLSEC_ERRORS_R_CERT_NOT_FOUND: |
|
304 * |
|
305 * Requested certificate is not found. |
|
306 */ |
|
307 #define XMLSEC_ERRORS_R_CERT_NOT_FOUND 72 |
|
308 |
|
309 /** |
|
310 * XMLSEC_ERRORS_R_CERT_REVOKED: |
|
311 * |
|
312 * The certificate is revoked. |
|
313 */ |
|
314 #define XMLSEC_ERRORS_R_CERT_REVOKED 73 |
|
315 |
|
316 /** |
|
317 * XMLSEC_ERRORS_R_CERT_ISSUER_FAILED: |
|
318 * |
|
319 * Failed to get certificate issuer. |
|
320 */ |
|
321 #define XMLSEC_ERRORS_R_CERT_ISSUER_FAILED 74 |
|
322 |
|
323 /** |
|
324 * XMLSEC_ERRORS_R_CERT_NOT_YET_VALID: |
|
325 * |
|
326 * "Not valid before" verification failed. |
|
327 */ |
|
328 #define XMLSEC_ERRORS_R_CERT_NOT_YET_VALID 75 |
|
329 |
|
330 /** |
|
331 * XMLSEC_ERRORS_R_CERT_HAS_EXPIRED: |
|
332 * |
|
333 * "Not valid after" verification failed. |
|
334 */ |
|
335 #define XMLSEC_ERRORS_R_CERT_HAS_EXPIRED 76 |
|
336 |
|
337 /** |
|
338 * XMLSEC_ERRORS_R_DSIG_NO_REFERENCES: |
|
339 * |
|
340 * The <dsig:Reference> nodes not found. |
|
341 */ |
|
342 #define XMLSEC_ERRORS_R_DSIG_NO_REFERENCES 81 |
|
343 |
|
344 /** |
|
345 * XMLSEC_ERRORS_R_DSIG_INVALID_REFERENCE: |
|
346 * |
|
347 * The <dsig:Reference> validation failed. |
|
348 */ |
|
349 #define XMLSEC_ERRORS_R_DSIG_INVALID_REFERENCE 82 |
|
350 |
|
351 /** |
|
352 * XMLSEC_ERRORS_R_ASSERTION: |
|
353 * |
|
354 * Invalid assertion. |
|
355 */ |
|
356 #define XMLSEC_ERRORS_R_ASSERTION 100 |
|
357 |
|
358 /** |
|
359 * XMLSEC_ERRORS_MAX_NUMBER: |
|
360 * |
|
361 * The maximum xmlsec errors number. |
|
362 */ |
|
363 #define XMLSEC_ERRORS_MAX_NUMBER 256 |
|
364 |
|
365 |
|
366 |
|
367 /******************************************************************* |
|
368 * |
|
369 * Error functions |
|
370 * |
|
371 *******************************************************************/ |
|
372 /** |
|
373 * xmlSecErrorsCallback: |
|
374 * @file: the error location file name (__FILE__ macro). |
|
375 * @line: the error location line number (__LINE__ macro). |
|
376 * @func: the error location function name (__FUNCTION__ macro). |
|
377 * @errorObject: the error specific error object |
|
378 * @errorSubject: the error specific error subject. |
|
379 * @reason: the error code. |
|
380 * @msg: the additional error message. |
|
381 * |
|
382 * The errors reporting callback function. |
|
383 */ |
|
384 typedef void (*xmlSecErrorsCallback) (const char* file, |
|
385 int line, |
|
386 const char* func, |
|
387 const char* errorObject, |
|
388 const char* errorSubject, |
|
389 int reason, |
|
390 const char* msg); |
|
391 |
|
392 |
|
393 XMLSEC_EXPORT void xmlSecErrorsInit (void); |
|
394 XMLSEC_EXPORT void xmlSecErrorsShutdown (void); |
|
395 XMLSEC_EXPORT void xmlSecErrorsSetCallback (xmlSecErrorsCallback callback); |
|
396 XMLSEC_EXPORT void xmlSecErrorsDefaultCallback (const char* file, |
|
397 int line, |
|
398 const char* func, |
|
399 const char* errorObject, |
|
400 const char* errorSubject, |
|
401 int reason, |
|
402 const char* msg); |
|
403 XMLSEC_EXPORT void xmlSecErrorsDefaultCallbackEnableOutput |
|
404 (int enabled); |
|
405 |
|
406 XMLSEC_EXPORT int xmlSecErrorsGetCode (xmlSecSize pos); |
|
407 XMLSEC_EXPORT const char* xmlSecErrorsGetMsg (xmlSecSize pos); |
|
408 |
|
409 |
|
410 |
|
411 /* __FUNCTION__ is defined for MSC compiler < MS VS .NET 2003 */ |
|
412 #if defined(_MSC_VER) && (_MSC_VER >= 1300) |
|
413 #define __XMLSEC_FUNCTION__ __FUNCTION__ |
|
414 #endif /* _MSC_VER */ |
|
415 |
|
416 /* fallback for __FUNCTION__ */ |
|
417 #if !defined(__XMLSEC_FUNCTION__) |
|
418 #define __XMLSEC_FUNCTION__ "" |
|
419 #endif /*!defined(__XMLSEC_FUNCTION__) */ |
|
420 |
|
421 /** |
|
422 * XMLSEC_ERRORS_HERE: |
|
423 * |
|
424 * The macro that specifies the location (file, line and function) |
|
425 * for the xmlSecError() function. |
|
426 */ |
|
427 #define XMLSEC_ERRORS_HERE __FILE__,__LINE__,__XMLSEC_FUNCTION__ |
|
428 #ifdef __GNUC__ |
|
429 #define XMLSEC_ERRORS_PRINTF_ATTRIBUTE __attribute__ ((format (printf, 7, 8))) |
|
430 #else /* __GNUC__ */ |
|
431 #define XMLSEC_ERRORS_PRINTF_ATTRIBUTE |
|
432 #endif /* __GNUC__ */ |
|
433 |
|
434 /** |
|
435 * xmlSecErrorsSafeString: |
|
436 * @str: the string. |
|
437 * |
|
438 * Macro. Returns @str if it is not NULL or pointer to "NULL" otherwise. |
|
439 */ |
|
440 #define xmlSecErrorsSafeString(str) \ |
|
441 (((str) != NULL) ? ((char*)(str)) : (char*)"NULL") |
|
442 |
|
443 /** |
|
444 * XMLSEC_ERRORS_NO_MESSAGE: |
|
445 * |
|
446 * Empty error message " ". |
|
447 */ |
|
448 #define XMLSEC_ERRORS_NO_MESSAGE " " |
|
449 |
|
450 |
|
451 XMLSEC_EXPORT void xmlSecError (const char* file, |
|
452 int line, |
|
453 const char* func, |
|
454 const char* errorObject, |
|
455 const char* errorSubject, |
|
456 int reason, |
|
457 const char* msg, ...) XMLSEC_ERRORS_PRINTF_ATTRIBUTE; |
|
458 |
|
459 |
|
460 |
|
461 /********************************************************************** |
|
462 * |
|
463 * Assertions |
|
464 * |
|
465 **********************************************************************/ |
|
466 /** |
|
467 * xmlSecAssert: |
|
468 * @p: the expression. |
|
469 * |
|
470 * Macro. Verifies that @p is true and calls return() otherwise. |
|
471 */ |
|
472 #define xmlSecAssert( p ) \ |
|
473 if(!( p ) ) { \ |
|
474 xmlSecError(XMLSEC_ERRORS_HERE, \ |
|
475 NULL, \ |
|
476 #p, \ |
|
477 XMLSEC_ERRORS_R_ASSERTION, \ |
|
478 XMLSEC_ERRORS_NO_MESSAGE); \ |
|
479 return; \ |
|
480 } |
|
481 |
|
482 /** |
|
483 * xmlSecAssert2: |
|
484 * @p: the expression. |
|
485 * @ret: the return value. |
|
486 * |
|
487 * Macro. Verifies that @p is true and calls return(@ret) otherwise. |
|
488 */ |
|
489 #define xmlSecAssert2( p, ret ) \ |
|
490 if(!( p ) ) { \ |
|
491 xmlSecError(XMLSEC_ERRORS_HERE, \ |
|
492 NULL, \ |
|
493 #p, \ |
|
494 XMLSEC_ERRORS_R_ASSERTION, \ |
|
495 XMLSEC_ERRORS_NO_MESSAGE); \ |
|
496 return(ret); \ |
|
497 } |
|
498 |
|
499 |
|
500 |
|
501 #ifdef __cplusplus |
|
502 } |
|
503 #endif /* __cplusplus */ |
|
504 |
|
505 #endif /* __XMLSEC_ERRORS_H__ */ |
|
506 |
|
507 |