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