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