1 /*
2  * XML Security Library (http://www.aleksey.com/xmlsec).
3  *
4  * Internal header only used during the compilation,
5  *
6  * This is free software; see Copyright file in the source
7  * distribution for preciese wording.
8  *
9  * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
10  */
11 
12 #ifndef __XMLSEC_ERROR_HELPERS_H__
13 #define __XMLSEC_ERROR_HELPERS_H__
14 
15 #ifndef XMLSEC_PRIVATE
16 #error "private.h file contains private xmlsec definitions and should not be used outside xmlsec or xmlsec-$crypto libraries"
17 #endif /* XMLSEC_PRIVATE */
18 
19 #include <errno.h>
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24 
25 /**********************************************************************
26  *
27  * Error handling macros.
28  *
29  **********************************************************************/
30 
31 /**
32  * xmlSecInternalError:
33  * @errorFunction:      the failed function name.
34  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
35  *
36  * Macro. The XMLSec library macro for reporting internal XMLSec errors.
37  */
38 #define xmlSecInternalError(errorFunction, errorObject) \
39         xmlSecError(XMLSEC_ERRORS_HERE,                     \
40                     (const char*)(errorObject),             \
41                     (errorFunction),                        \
42                     XMLSEC_ERRORS_R_XMLSEC_FAILED,          \
43                     XMLSEC_ERRORS_NO_MESSAGE                \
44         )
45 
46 /**
47  * xmlSecInternalError2:
48  * @errorFunction:      the failed function name.
49  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
50  * @msg:                the extra message.
51  * @param:              the extra message param.
52  *
53  * Macro. The XMLSec library macro for reporting internal XMLSec errors.
54  */
55 #define xmlSecInternalError2(errorFunction, errorObject, msg, param) \
56         xmlSecError(XMLSEC_ERRORS_HERE,                     \
57                     (const char*)(errorObject),             \
58                     (errorFunction),                        \
59                     XMLSEC_ERRORS_R_XMLSEC_FAILED,          \
60                     (msg), (param)                          \
61         )
62 
63 /**
64  * xmlSecInternalError3:
65  * @errorFunction:      the failed function name.
66  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
67  * @msg:                the extra message.
68  * @param1:             the extra message param1.
69  * @param2:             the extra message param2.
70  *
71  * Macro. The XMLSec library macro for reporting internal XMLSec errors.
72  */
73 #define xmlSecInternalError3(errorFunction, errorObject, msg, param1, param2) \
74         xmlSecError(XMLSEC_ERRORS_HERE,                     \
75                     (const char*)(errorObject),             \
76                     (errorFunction),                        \
77                     XMLSEC_ERRORS_R_XMLSEC_FAILED,          \
78                     (msg), (param1), (param2)               \
79         )
80 
81 /**
82  * xmlSecInternalError4:
83  * @errorFunction:      the failed function name.
84  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
85  * @msg:                the extra message.
86  * @param1:             the extra message param1.
87  * @param2:             the extra message param2.
88  * @param3:             the extra message param3.
89  *
90  * Macro. The XMLSec library macro for reporting internal XMLSec errors.
91  */
92 #define xmlSecInternalError4(errorFunction, errorObject, msg, param1, param2, param3) \
93         xmlSecError(XMLSEC_ERRORS_HERE,                     \
94                     (const char*)(errorObject),             \
95                     (errorFunction),                        \
96                     XMLSEC_ERRORS_R_XMLSEC_FAILED,          \
97                     (msg), (param1), (param2), (param3)     \
98         )
99 
100 /**
101  * xmlSecMallocError:
102  * @allocSize:          the failed allocation size.
103  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
104  *
105  * Macro. The XMLSec library macro for reporting xmlMalloc() errors.
106  */
107 #define xmlSecMallocError(allocSize, errorObject) \
108         xmlSecError(XMLSEC_ERRORS_HERE,                     \
109                     (const char*)(errorObject),             \
110                     "xmlMalloc",                            \
111                     XMLSEC_ERRORS_R_MALLOC_FAILED,          \
112                     "size=%lu", (unsigned long)(allocSize)  \
113         )
114 
115 /**
116  * xmlSecStrdupError:
117  * @str:                the failed string.
118  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
119  *
120  * Macro. The XMLSec library macro for reporting xmlStrdup() errors.
121  */
122 #define xmlSecStrdupError(str, errorObject) \
123         xmlSecError(XMLSEC_ERRORS_HERE,                     \
124                     (const char*)(errorObject),             \
125                     "xmlStrdup",                            \
126                     XMLSEC_ERRORS_R_STRDUP_FAILED,          \
127                     "size=%lu", (unsigned long)xmlStrlen(str) \
128         )
129 
130 /**
131  * xmlSecXmlError:
132  * @errorFunction:      the failed function.
133  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
134  *
135  * Macro. The XMLSec library macro for reporting generic XML errors.
136  */
137 #define xmlSecXmlError(errorFunction, errorObject) \
138     {                                                 \
139         xmlErrorPtr error = xmlGetLastError();        \
140         int code = (error != NULL) ? error->code : 0; \
141         const char* message = (error != NULL) ? error->message : NULL; \
142         xmlSecError(XMLSEC_ERRORS_HERE,               \
143                    (const char*)(errorObject),        \
144                    (errorFunction),                   \
145                    XMLSEC_ERRORS_R_XML_FAILED,        \
146                    "xml error: %lu: %s",              \
147                    (unsigned long)code,               \
148                    xmlSecErrorsSafeString(message)    \
149         );                                            \
150     }
151 
152 /**
153  * xmlSecXmlError2:
154  * @errorFunction:      the failed function.
155  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
156  * @msg:                the extra message.
157  * @param:              the extra message param.
158  *
159  * Macro. The XMLSec library macro for reporting generic XML errors.
160  */
161 #define xmlSecXmlError2(errorFunction, errorObject, msg, param) \
162     {                                                 \
163         xmlErrorPtr error = xmlGetLastError();        \
164         int code = (error != NULL) ? error->code : 0; \
165         const char* message = (error != NULL) ? error->message : NULL; \
166         xmlSecError(XMLSEC_ERRORS_HERE,               \
167                    (const char*)(errorObject),        \
168                    (errorFunction),                   \
169                    XMLSEC_ERRORS_R_XML_FAILED,        \
170                    msg "; xml error: %lu: %s",        \
171                    (param),                           \
172                    (unsigned long)code,               \
173                    xmlSecErrorsSafeString(message)    \
174         );                                            \
175     }
176 
177 /**
178  * xmlSecXmlParserError:
179  * @errorFunction:      the failed function.
180  * @ctxt:               the parser context.
181  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
182  *
183  * Macro. The XMLSec library macro for reporting XML parser errors.
184  */
185 #define xmlSecXmlParserError(errorFunction, ctxt, errorObject) \
186     {                                                 \
187         xmlErrorPtr error = xmlCtxtGetLastError(ctxt);\
188         int code = (error != NULL) ? error->code : 0; \
189         const char* message = (error != NULL) ? error->message : NULL; \
190         xmlSecError(XMLSEC_ERRORS_HERE,               \
191                    (const char*)(errorObject),        \
192                    (errorFunction),                   \
193                    XMLSEC_ERRORS_R_XML_FAILED,        \
194                    "xml error: %lu: %s",              \
195                    (unsigned long)code,               \
196                    xmlSecErrorsSafeString(message)    \
197         );                                            \
198     }
199 
200 /**
201  * xmlSecXmlParserError2:
202  * @errorFunction:      the failed function.
203  * @ctxt:               the parser context.
204  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
205  * @msg:                the extra message.
206  * @param:              the extra message param.
207  *
208  * Macro. The XMLSec library macro for reporting XML parser errors.
209  */
210 #define xmlSecXmlParserError2(errorFunction, ctxt, errorObject, msg, param) \
211     {                                                 \
212         xmlErrorPtr error = xmlCtxtGetLastError(ctxt);\
213         int code = (error != NULL) ? error->code : 0; \
214         const char* message = (error != NULL) ? error->message : NULL; \
215         xmlSecError(XMLSEC_ERRORS_HERE,               \
216                    (const char*)(errorObject),        \
217                    (errorFunction),                   \
218                    XMLSEC_ERRORS_R_XML_FAILED,        \
219                    msg "; xml error: %lu: %s",        \
220                    (param),                           \
221                    (unsigned long)code,               \
222                    xmlSecErrorsSafeString(message)    \
223         );                                            \
224     }
225 
226 /**
227  * xmlSecXsltError:
228  * @errorFunction:      the failed function.
229  * @ctxt:               the parser context.
230  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
231  *
232  * Macro. The XMLSec library macro for reporting XSLT errors.
233  */
234 #define xmlSecXsltError(errorFunction, ctxt, errorObject) \
235     {                                                 \
236         xmlErrorPtr error = xmlGetLastError();        \
237         int code = (error != NULL) ? error->code : 0; \
238         const char* message = (error != NULL) ? error->message : NULL; \
239         xmlSecError(XMLSEC_ERRORS_HERE,               \
240                    (const char*)(errorObject),        \
241                    (errorFunction),                   \
242                    XMLSEC_ERRORS_R_XSLT_FAILED,       \
243                    "xslt error: %lu: %s",             \
244                    (unsigned long)code,               \
245                    xmlSecErrorsSafeString(message)    \
246         );                                            \
247     }
248 
249 /**
250  * xmlSecIOError:
251  * @errorFunction:      the failed function.
252  * @name:               the filename, function name, uri, etc.
253  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
254  *
255  * Macro. The XMLSec library macro for reporting IO errors.
256  */
257 #define xmlSecIOError(errorFunction, name, errorObject) \
258     {                                                 \
259         xmlSecError(XMLSEC_ERRORS_HERE,               \
260                    (const char*)(errorObject),        \
261                    (errorFunction),                   \
262                    XMLSEC_ERRORS_R_IO_FAILED,         \
263                    "name=\"%s\"; errno=%d",           \
264                    xmlSecErrorsSafeString(name),      \
265                    errno                              \
266         );                                            \
267     }
268 
269 /**
270  * xmlSecNotImplementedError:
271  * @details:           the additional details.
272  *
273  * Macro. The XMLSec library macro for reporting "not implemented" errors.
274  */
275 #define xmlSecNotImplementedError(details) \
276         xmlSecError(XMLSEC_ERRORS_HERE,                     \
277                     NULL,                                   \
278                     NULL,                                   \
279                     XMLSEC_ERRORS_R_NOT_IMPLEMENTED,        \
280                     "details=%s",                           \
281                     xmlSecErrorsSafeString(details)         \
282         )
283 /**
284  * xmlSecInvalidSizeError:
285  * @name:               the name of the variable, parameter, etc.
286  * @actual:             the actual value.
287  * @expected:           the expected value.
288  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
289  *
290  * Macro. The XMLSec library macro for reporting "invalid size" errors when
291  * we expect exact match.
292  */
293 #define xmlSecInvalidSizeError(name, actual, expected, errorObject) \
294         xmlSecError(XMLSEC_ERRORS_HERE,                     \
295                     (const char*)(errorObject),             \
296                     NULL,                                   \
297                     XMLSEC_ERRORS_R_INVALID_SIZE,           \
298                     "invalid size for '%s': actual=%lu is not equal to expected=%lu", \
299                     xmlSecErrorsSafeString(name),           \
300                     (unsigned long)(actual),                \
301                     (unsigned long)(expected)               \
302         )
303 
304 /**
305  * xmlSecInvalidSizeLessThanError:
306  * @name:               the name of the variable, parameter, etc.
307  * @actual:             the actual value.
308  * @expected:           the expected value.
309  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
310  *
311  * Macro. The XMLSec library macro for reporting "invalid size" errors when
312  * we expect at least the expected size.
313  */
314 #define xmlSecInvalidSizeLessThanError(name, actual, expected, errorObject) \
315         xmlSecError(XMLSEC_ERRORS_HERE,                     \
316                     (const char*)(errorObject),             \
317                     NULL,                                   \
318                     XMLSEC_ERRORS_R_INVALID_SIZE,           \
319                     "invalid size for '%s': actual=%lu is less than expected=%lu", \
320                     xmlSecErrorsSafeString(name),           \
321                     (unsigned long)(actual),                \
322                     (unsigned long)(expected)               \
323         )
324 
325 /**
326  * xmlSecInvalidSizeMoreThanError:
327  * @name:               the name of the variable, parameter, etc.
328  * @actual:             the actual value.
329  * @expected:           the expected value.
330  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
331  *
332  * Macro. The XMLSec library macro for reporting "invalid size" errors when
333  * we expect at most the expected size.
334  */
335 #define xmlSecInvalidSizeMoreThanError(name, actual, expected, errorObject) \
336         xmlSecError(XMLSEC_ERRORS_HERE,                     \
337                     (const char*)(errorObject),             \
338                     NULL,                                   \
339                     XMLSEC_ERRORS_R_NOT_IMPLEMENTED,        \
340                     "invalid size for '%s': actual=%lu is more than expected=%lu", \
341                     xmlSecErrorsSafeString(name),           \
342                     (unsigned long)(actual),                \
343                     (unsigned long)(expected)               \
344         )
345 
346 /**
347  * xmlSecInvalidSizeNotMultipleOfError:
348  * @name:               the name of the variable, parameter, etc.
349  * @actual:             the actual value.
350  * @divider:            the expected divider.
351  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
352  *
353  * Macro. The XMLSec library macro for reporting "invalid size" errors when
354  * we expect the size to be a multiple of the divider.
355  */
356 #define xmlSecInvalidSizeNotMultipleOfError(name, actual, divider, errorObject) \
357         xmlSecError(XMLSEC_ERRORS_HERE,                     \
358                     (const char*)(errorObject),             \
359                     NULL,                                   \
360                     XMLSEC_ERRORS_R_NOT_IMPLEMENTED,        \
361                     "invalid size for '%s': actual=%lu is not a multiple of %lu", \
362                     xmlSecErrorsSafeString(name),           \
363                     (unsigned long)(actual),                \
364                     (unsigned long)(divider)               \
365         )
366 
367 /**
368  * xmlSecInvalidSizeOtherError:
369  * @msg:                the message about the error.
370  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
371  *
372  * Macro. The XMLSec library macro for reporting "invalid size" errors when
373  * we expect exact match.
374  */
375 #define xmlSecInvalidSizeOtherError(msg, errorObject) \
376         xmlSecError(XMLSEC_ERRORS_HERE,                     \
377                     (const char*)(errorObject),             \
378                     NULL,                                   \
379                     XMLSEC_ERRORS_R_INVALID_SIZE,           \
380                     "invalid size: %s",                     \
381                     xmlSecErrorsSafeString(msg)             \
382         )
383 
384 /**
385  * xmlSecInvalidDataError:
386  * @msg:                the msg with explanation.
387  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
388  *
389  * Macro. The XMLSec library macro for reporting "invalid data" errors.
390  */
391 #define xmlSecInvalidDataError(msg, errorObject) \
392         xmlSecError(XMLSEC_ERRORS_HERE,                     \
393                     (const char*)(errorObject),             \
394                     NULL,                                   \
395                     XMLSEC_ERRORS_R_INVALID_DATA,           \
396                     "%s",                                   \
397                     xmlSecErrorsSafeString(msg)             \
398         )
399 
400 /**
401  * xmlSecInvalidStringDataError:
402  * @name:               the name of the variable, parameter, etc.
403  * @actual:             the actual value as a string.
404  * @expected:           the expected value(s) as a string.
405  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
406  *
407  * Macro. The XMLSec library macro for reporting "invalid data" errors for string.
408  */
409 #define xmlSecInvalidStringDataError(name, actual, expected, errorObject) \
410         xmlSecError(XMLSEC_ERRORS_HERE,                     \
411                     (const char*)(errorObject),             \
412                     NULL,                                   \
413                     XMLSEC_ERRORS_R_INVALID_DATA,           \
414                     "invalid data for '%s': actual='%s' and expected %s", \
415                     xmlSecErrorsSafeString(name),           \
416                     xmlSecErrorsSafeString(actual),         \
417                     (expected)                              \
418         )
419 
420 /**
421  * xmlSecInvalidIntegerDataError:
422  * @name:               the name of the variable, parameter, etc.
423  * @actual:             the actual value as an integer.
424  * @expected:           the expected value(s) as a string.
425  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
426  *
427  * Macro. The XMLSec library macro for reporting "invalid data" errors for integers.
428  */
429 #define xmlSecInvalidIntegerDataError(name, actual, expected, errorObject) \
430         xmlSecError(XMLSEC_ERRORS_HERE,                     \
431                     (const char*)(errorObject),             \
432                     NULL,                                   \
433                     XMLSEC_ERRORS_R_INVALID_DATA,           \
434                     "invalid data for '%s': actual=%ld and expected %s", \
435                     xmlSecErrorsSafeString(name),           \
436                     (unsigned long)(actual),                \
437                     (expected)                              \
438         )
439 
440 /**
441  * xmlSecInvalidIntegerDataError2:
442  * @name1:              the name of the first variable, parameter, etc.
443  * @actual1:            the actual first value as an integer.
444  * @name2:              the name of the second variable, parameter, etc.
445  * @actual2:            the actual second value as an integer.
446  * @expected:           the expected value(s) as a string.
447  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
448  *
449  * Macro. The XMLSec library macro for reporting "invalid data" errors for integers.
450  */
451 #define xmlSecInvalidIntegerDataError2(name1, actual1, name2, actual2, expected, errorObject) \
452         xmlSecError(XMLSEC_ERRORS_HERE,                     \
453                     (const char*)(errorObject),             \
454                     NULL,                                   \
455                     XMLSEC_ERRORS_R_INVALID_DATA,           \
456                     "invalid data: actual value '%s'=%ld, actual value '%s'=%ld and expected %s", \
457                     xmlSecErrorsSafeString(name1),          \
458                     (unsigned long)(actual1),               \
459                     xmlSecErrorsSafeString(name2),          \
460                     (unsigned long)(actual2),               \
461                     (expected)                              \
462         )
463 
464 /**
465  * xmlSecInvalidTypeError:
466  * @msg:                the msg with explanation.
467  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
468  *
469  * Macro. The XMLSec library macro for reporting "invalid type" errors.
470  */
471 #define xmlSecInvalidTypeError(msg, errorObject) \
472         xmlSecError(XMLSEC_ERRORS_HERE,                     \
473                     (const char*)(errorObject),             \
474                     NULL,                                   \
475                     XMLSEC_ERRORS_R_INVALID_TYPE,           \
476                     "%s",                                   \
477                     xmlSecErrorsSafeString(msg)             \
478         )
479 
480 /**
481  * xmlSecInvalidStringTypeError:
482  * @name:               the name of the variable, parameter, etc.
483  * @actual:             the actual value as a string.
484  * @expected:           the expected value(s) as a string.
485  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
486  *
487  * Macro. The XMLSec library macro for reporting "invalid type" errors for string.
488  */
489 #define xmlSecInvalidStringTypeError(name, actual, expected, errorObject) \
490         xmlSecError(XMLSEC_ERRORS_HERE,                     \
491                     (const char*)(errorObject),             \
492                     NULL,                                   \
493                     XMLSEC_ERRORS_R_INVALID_TYPE,           \
494                     "invalid type for '%s': actual='%s' and expected %s", \
495                     xmlSecErrorsSafeString(name),           \
496                     xmlSecErrorsSafeString(actual),         \
497                     (expected)                              \
498         )
499 
500 /**
501  * xmlSecInvalidIntegerTypeError:
502  * @name:               the name of the variable, parameter, etc.
503  * @actual:             the actual value as an integer.
504  * @expected:           the expected value(s) as a string.
505  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
506  *
507  * Macro. The XMLSec library macro for reporting "invalid type" errors for integers.
508  */
509 #define xmlSecInvalidIntegerTypeError(name, actual, expected, errorObject) \
510         xmlSecError(XMLSEC_ERRORS_HERE,                     \
511                     (const char*)(errorObject),             \
512                     NULL,                                   \
513                     XMLSEC_ERRORS_R_INVALID_TYPE,           \
514                     "invalid type for '%s': actual=%ld and expected %s", \
515                     xmlSecErrorsSafeString(name),           \
516                     (unsigned long)(actual),                \
517                     (expected)                              \
518         )
519 
520 /**
521  * xmlSecInvalidIntegerTypeError2:
522  * @name1:              the name of the first variable, parameter, etc.
523  * @actual1:            the actual first value as an integer.
524  * @name2:              the name of the second variable, parameter, etc.
525  * @actual2:            the actual second value as an integer.
526  * @expected:           the expected value(s) as a string.
527  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
528  *
529  * Macro. The XMLSec library macro for reporting "invalid type" errors for integers.
530  */
531 #define xmlSecInvalidIntegerTypeError2(name1, actual1, name2, actual2, expected, errorObject) \
532         xmlSecError(XMLSEC_ERRORS_HERE,                     \
533                     (const char*)(errorObject),             \
534                     NULL,                                   \
535                     XMLSEC_ERRORS_R_INVALID_TYPE,           \
536                     "invalid type: actual value '%s'=%ld, actual value '%s'=%ld and expected %s", \
537                     xmlSecErrorsSafeString(name1),          \
538                     (unsigned long)(actual1),               \
539                     xmlSecErrorsSafeString(name2),          \
540                     (unsigned long)(actual2),               \
541                     (expected)                              \
542         )
543 
544 /**
545  * xmlSecInvalidNodeError:
546  * @actualNode:         the actual node.
547  * @expectedNodeName:   the expected node name.
548  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
549  *
550  * Macro. The XMLSec library macro for reporting an invalid node errors.
551  */
552 #define xmlSecInvalidNodeError(actualNode, expectedNodeName, errorObject) \
553     {                                                 \
554         const char* actualNodeName = xmlSecNodeGetName(actualNode); \
555         xmlSecError(XMLSEC_ERRORS_HERE,               \
556                    (const char*)(errorObject),        \
557                    NULL,                              \
558                    XMLSEC_ERRORS_R_INVALID_NODE,      \
559                    "actual=%s; expected=%s",          \
560                    xmlSecErrorsSafeString(actualNodeName),  \
561                    xmlSecErrorsSafeString(expectedNodeName) \
562         );                                            \
563     }
564 
565 /**
566  * xmlSecInvalidNodeContentError:
567  * @node:               the node.
568  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
569  * @reason:             the reason why node content is invalid.
570  *
571  * Macro. The XMLSec library macro for reporting an invalid node content errors.
572  */
573 #define xmlSecInvalidNodeContentError(node, errorObject, reason) \
574     {                                                 \
575         const char* nName = xmlSecNodeGetName(node);  \
576         xmlSecError(XMLSEC_ERRORS_HERE,               \
577                    (const char*)(errorObject),        \
578                    NULL,                              \
579                    XMLSEC_ERRORS_R_INVALID_NODE_CONTENT, \
580                    "node=%s; reason=%s",              \
581                    xmlSecErrorsSafeString(nName),     \
582                    xmlSecErrorsSafeString(reason)     \
583         );                                            \
584     }
585 
586 /**
587  * xmlSecInvalidNodeAttributeError:
588  * @node:               the node.
589  * @attrName:           the attribute name.
590  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
591  * @reason:             the reason why node content is invalid.
592  *
593  * Macro. The XMLSec library macro for reporting an invalid node attribute errors.
594  */
595 #define xmlSecInvalidNodeAttributeError(node, attrName, errorObject, reason) \
596     {                                                 \
597         const char* nName = xmlSecNodeGetName(node);  \
598         xmlSecError(XMLSEC_ERRORS_HERE,               \
599                    (const char*)(errorObject),        \
600                    NULL,                              \
601                    XMLSEC_ERRORS_R_INVALID_NODE_ATTRIBUTE, \
602                    "node=%s; attribute=%s; reason=%s",\
603                    xmlSecErrorsSafeString(nName),     \
604                    xmlSecErrorsSafeString(attrName),  \
605                    xmlSecErrorsSafeString(reason)     \
606         );                                            \
607     }
608 
609 /**
610  * xmlSecNodeAlreadyPresentError:
611  * @parent:             the parent node.
612  * @nodeName:           the node name.
613  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
614  *
615  * Macro. The XMLSec library macro for reporting node already present errors.
616  */
617 #define xmlSecNodeAlreadyPresentError(parent, nodeName, errorObject) \
618     {                                                 \
619         const char* pName = xmlSecNodeGetName(parent);\
620         xmlSecError(XMLSEC_ERRORS_HERE,               \
621                    (const char*)(errorObject),        \
622                    NULL,                              \
623                    XMLSEC_ERRORS_R_NODE_ALREADY_PRESENT, \
624                    "parent=%s; node=%s",              \
625                    xmlSecErrorsSafeString(pName),     \
626                    xmlSecErrorsSafeString(nodeName)   \
627         );                                            \
628     }
629 
630 /**
631  * xmlSecUnexpectedNodeError:
632  * @node:               the node.
633  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
634  *
635  * Macro. The XMLSec library macro for reporting an invalid node errors.
636  */
637 #define xmlSecUnexpectedNodeError(node, errorObject) \
638     {                                                 \
639         const char* nName = xmlSecNodeGetName(node);  \
640         xmlSecError(XMLSEC_ERRORS_HERE,               \
641                    (const char*)(errorObject),        \
642                    NULL,                              \
643                    XMLSEC_ERRORS_R_UNEXPECTED_NODE,   \
644                    "node=%s",                         \
645                    xmlSecErrorsSafeString(nName)      \
646         );                                            \
647     }
648 
649 /**
650  * xmlSecNodeNotFoundError:
651  * @errorFunction:      the failed function.
652  * @startNode:          the search start node.
653  * @targetNodeName:     the expected child node name.
654  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
655  *
656  * Macro. The XMLSec library macro for reporting node not found errors.
657  */
658 #define xmlSecNodeNotFoundError(errorFunction, startNode, targetNodeName, errorObject) \
659     {                                                 \
660         const char* startNodeName = xmlSecNodeGetName(startNode); \
661         xmlSecError(XMLSEC_ERRORS_HERE,               \
662                    (const char*)(errorObject),        \
663                    (errorFunction),                   \
664                    XMLSEC_ERRORS_R_NODE_NOT_FOUND,    \
665                    "startNode=%s; target=%s",         \
666                    xmlSecErrorsSafeString(startNodeName), \
667                    xmlSecErrorsSafeString(targetNodeName) \
668         );                                            \
669     }
670 
671 /**
672  * xmlSecInvalidTransfromError:
673  * @transform:          the transform.
674  *
675  * Macro. The XMLSec library macro for reporting an invalid transform errors.
676  */
677 #define xmlSecInvalidTransfromError(transform) \
678     {                                                 \
679         xmlSecError(XMLSEC_ERRORS_HERE,               \
680                    (const char*)xmlSecTransformGetName(transform), \
681                    NULL,                              \
682                    XMLSEC_ERRORS_R_INVALID_TRANSFORM, \
683                    XMLSEC_ERRORS_NO_MESSAGE           \
684         );                                            \
685     }
686 
687 /**
688  * xmlSecInvalidTransfromError2:
689  * @transform:          the transform.
690  * @msg:                the extra message.
691  * @param:              the extra message param.
692  *
693  *
694  * Macro. The XMLSec library macro for reporting an invalid transform errors.
695  */
696 #define xmlSecInvalidTransfromError2(transform, msg, param) \
697     {                                                 \
698         xmlSecError(XMLSEC_ERRORS_HERE,               \
699                    (const char*)xmlSecTransformGetName(transform), \
700                    NULL,                              \
701                    XMLSEC_ERRORS_R_INVALID_TRANSFORM, \
702                    (msg), (param)                     \
703         );                                            \
704     }
705 
706 /**
707  * xmlSecInvalidTransfromStatusError:
708  * @transform:          the transform.
709  *
710  * Macro. The XMLSec library macro for reporting an invalid transform status errors.
711  */
712 #define xmlSecInvalidTransfromStatusError(transform) \
713     {                                                 \
714         xmlSecError(XMLSEC_ERRORS_HERE,               \
715                    (const char*)xmlSecTransformGetName(transform), \
716                    NULL,                              \
717                    XMLSEC_ERRORS_R_INVALID_STATUS,    \
718                    "transformStatus=%d",              \
719                    (int)((transform)->status)         \
720         );                                            \
721     }
722 
723 /**
724  * xmlSecInvalidTransfromStatusError2:
725  * @transform:          the transform.
726  * @msg:                the extra message.
727  *
728  * Macro. The XMLSec library macro for reporting an invalid transform status errors.
729  */
730 #define xmlSecInvalidTransfromStatusError2(transform, msg) \
731     {                                                 \
732         xmlSecError(XMLSEC_ERRORS_HERE,               \
733                    (const char*)xmlSecTransformGetName(transform), \
734                    NULL,                              \
735                    XMLSEC_ERRORS_R_INVALID_STATUS,    \
736                    "transformStatus=%ld, msg=%s",     \
737                    (long int)((transform)->status),   \
738                    msg                                \
739         );                                            \
740     }
741 
742 /**
743  * xmlSecInvalidKeyDataSizeError:
744  * @name:               the name of the variable, parameter, etc.
745  * @actual:             the actual value.
746  * @expected:           the expected value(s).
747  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
748  *
749  * Macro. The XMLSec library macro for reporting "invalid keydata size" errors.
750  */
751 #define xmlSecInvalidKeyDataSizeError(actual, expected, errorObject) \
752         xmlSecError(XMLSEC_ERRORS_HERE,                     \
753                     (const char*)(errorObject),             \
754                     NULL,                                   \
755                     XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE,  \
756                     "invalid key data size: actual=%ld and expected=%ld", \
757                     (unsigned long)(actual),                \
758                     (unsigned long)(expected)               \
759         )
760 
761 /**
762  * xmlSecInvalidZeroKeyDataSizeError:
763  * @name:               the name of the variable, parameter, etc.
764  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
765  *
766  * Macro. The XMLSec library macro for reporting "invalid keydata size" errors.
767  */
768 #define xmlSecInvalidZeroKeyDataSizeError(errorObject) \
769         xmlSecError(XMLSEC_ERRORS_HERE,                     \
770                     (const char*)(errorObject),             \
771                     NULL,                                   \
772                     XMLSEC_ERRORS_R_INVALID_KEY_DATA_SIZE,  \
773                     "invalid zero key data size"            \
774         )
775 
776 
777 /**
778  * xmlSecOtherError:
779  * @code:               the error code.
780  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
781  * @details:            the error message.
782  *
783  * Macro. The XMLSec library macro for reporting other XMLSec errors.
784  */
785 #define xmlSecOtherError(code, errorObject, details) \
786         xmlSecError(XMLSEC_ERRORS_HERE,                     \
787                     (const char*)(errorObject),             \
788                     NULL,                                   \
789                     (code),                                 \
790                     "details=%s",                           \
791                     xmlSecErrorsSafeString(details)         \
792         )
793 
794 /**
795  * xmlSecOtherError2:
796  * @code:               the error code.
797  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
798  * @msg:                the extra message.
799  * @param:              the extra message param.
800  *
801  * Macro. The XMLSec library macro for reporting other XMLSec errors.
802  */
803 #define xmlSecOtherError2(code, errorObject, msg, param) \
804         xmlSecError(XMLSEC_ERRORS_HERE,                     \
805                     (const char*)(errorObject),             \
806                     NULL,                                   \
807                     (code),                                 \
808                     (msg), (param)                          \
809         )
810 
811 /**
812  * xmlSecOtherError3:
813  * @code:               the error code.
814  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
815  * @msg:                the extra message.
816  * @param1:             the extra message param.
817  * @param2:             the extra message param.
818  *
819  * Macro. The XMLSec library macro for reporting other XMLSec errors.
820  */
821 #define xmlSecOtherError3(code, errorObject, msg, param1, param2) \
822         xmlSecError(XMLSEC_ERRORS_HERE,                     \
823                     (const char*)(errorObject),             \
824                     NULL,                                   \
825                     (code),                                 \
826                     (msg), (param1), (param2)               \
827         )
828 
829 /**
830  * xmlSecOtherError4:
831  * @code:               the error code.
832  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
833  * @msg:                the extra message.
834  * @param1:             the extra message param.
835  * @param2:             the extra message param.
836  * @param3:             the extra message param.
837  *
838  * Macro. The XMLSec library macro for reporting other XMLSec errors.
839  */
840 #define xmlSecOtherError4(code, errorObject, msg, param1, param2, param3) \
841         xmlSecError(XMLSEC_ERRORS_HERE,                     \
842                     (const char*)(errorObject),             \
843                     NULL,                                   \
844                     (code),                                 \
845                     (msg), (param1), (param2), (param3)     \
846         )
847 
848 /**
849  * xmlSecOtherError5:
850  * @code:               the error code.
851  * @errorObject:        the error specific error object (e.g. transform, key data, etc).
852  * @msg:                the extra message.
853  * @param1:             the extra message param.
854  * @param2:             the extra message param.
855  * @param3:             the extra message param.
856  * @param4:             the extra message param.
857  *
858  * Macro. The XMLSec library macro for reporting other XMLSec errors.
859  */
860 #define xmlSecOtherError5(code, errorObject, msg, param1, param2, param3, param4) \
861         xmlSecError(XMLSEC_ERRORS_HERE,                     \
862                     (const char*)(errorObject),             \
863                     NULL,                                   \
864                     (code),                                 \
865                     (msg), (param1), (param2), (param3), (param4) \
866         )
867 
868 #ifdef __cplusplus
869 }
870 #endif /* __cplusplus */
871 
872 #endif /* __XMLSEC_ERROR_HELPERS_H__ */
873