2 * XML Security Library (http://www.aleksey.com/xmlsec).
6 * This is free software; see Copyright file in the source
7 * distribution for preciese wording.
9 * Copyright (C) 2002-2003 Aleksey Sanin <aleksey@aleksey.com>
16 #include <libxml/tree.h>
18 #include <xmlsec/xmlsec.h>
19 #include <xmlsec/xmltree.h>
20 #include <xmlsec/keys.h>
21 #include <xmlsec/transforms.h>
22 #include <xmlsec/app.h>
23 #include <xmlsec/io.h>
24 #include <xmlsec/xkms.h>
25 #include <xmlsec/errors.h>
30 * Initializes XML Security Library. The depended libraries
31 * (LibXML and LibXSLT) must be initialized before.
33 * Returns: 0 on success or a negative value otherwise.
40 #ifndef XMLSEC_NO_CRYPTO_DYNAMIC_LOADING
41 if(xmlSecCryptoDLInit() < 0) {
42 xmlSecError(XMLSEC_ERRORS_HERE,
45 XMLSEC_ERRORS_R_XMLSEC_FAILED,
46 XMLSEC_ERRORS_NO_MESSAGE);
49 #endif /* XMLSEC_NO_CRYPTO_DYNAMIC_LOADING */
51 if(xmlSecKeyDataIdsInit() < 0) {
52 xmlSecError(XMLSEC_ERRORS_HERE,
54 "xmlSecKeyDataIdsInit",
55 XMLSEC_ERRORS_R_XMLSEC_FAILED,
56 XMLSEC_ERRORS_NO_MESSAGE);
60 if(xmlSecTransformIdsInit() < 0) {
61 xmlSecError(XMLSEC_ERRORS_HERE,
63 "xmlSecTransformIdsInit",
64 XMLSEC_ERRORS_R_XMLSEC_FAILED,
65 XMLSEC_ERRORS_NO_MESSAGE);
69 #ifndef XMLSEC_NO_XKMS
70 if(xmlSecXkmsRespondWithIdsInit() < 0) {
71 xmlSecError(XMLSEC_ERRORS_HERE,
73 "xmlSecXkmsRespondWithIdsInit",
74 XMLSEC_ERRORS_R_XMLSEC_FAILED,
75 XMLSEC_ERRORS_NO_MESSAGE);
78 if(xmlSecXkmsServerRequestIdsInit() < 0) {
79 xmlSecError(XMLSEC_ERRORS_HERE,
81 "xmlSecXkmsServerRequestIdsInit",
82 XMLSEC_ERRORS_R_XMLSEC_FAILED,
83 XMLSEC_ERRORS_NO_MESSAGE);
86 #endif /* XMLSEC_NO_XKMS */
88 /* we use rand() function to generate id attributes */
96 * Clean ups the XML Security Library.
98 * Returns: 0 on success or a negative value otherwise.
101 xmlSecShutdown(void) {
104 #ifndef XMLSEC_NO_XKMS
105 xmlSecXkmsServerRequestIdsShutdown();
106 xmlSecXkmsRespondWithIdsShutdown();
107 #endif /* XMLSEC_NO_XKMS */
109 xmlSecTransformIdsShutdown();
110 xmlSecKeyDataIdsShutdown();
112 #ifndef XMLSEC_NO_CRYPTO_DYNAMIC_LOADING
113 if(xmlSecCryptoDLShutdown() < 0) {
114 xmlSecError(XMLSEC_ERRORS_HERE,
116 "xmlSecCryptoDLShutdown",
117 XMLSEC_ERRORS_R_XMLSEC_FAILED,
118 XMLSEC_ERRORS_NO_MESSAGE);
121 #endif /* XMLSEC_NO_CRYPTO_DYNAMIC_LOADING */
124 xmlSecErrorsShutdown();
129 * xmlSecCheckVersionExt:
130 * @major: the major version number.
131 * @minor: the minor version number.
132 * @subminor: the subminor version number.
133 * @mode: the version check mode.
135 * Checks if the loaded version of xmlsec library could be used.
137 * Returns: 1 if the loaded xmlsec library version is OK to use
138 * 0 if it is not or a negative value if an error occurs.
141 xmlSecCheckVersionExt(int major, int minor, int subminor, xmlSecCheckVersionMode mode) {
142 /* we always want to have a match for major version number */
143 if(major != XMLSEC_VERSION_MAJOR) {
144 xmlSecError(XMLSEC_ERRORS_HERE,
147 XMLSEC_ERRORS_R_XMLSEC_FAILED,
148 "expected major version=%d;real major version=%d",
149 XMLSEC_VERSION_MAJOR, major);
154 case xmlSecCheckVersionExactMatch:
155 if((minor != XMLSEC_VERSION_MINOR) || (subminor != XMLSEC_VERSION_SUBMINOR)) {
156 xmlSecError(XMLSEC_ERRORS_HERE,
159 XMLSEC_ERRORS_R_XMLSEC_FAILED,
160 "mode=exact;expected minor version=%d;real minor version=%d;expected subminor version=%d;real subminor version=%d",
161 XMLSEC_VERSION_MINOR, minor,
162 XMLSEC_VERSION_SUBMINOR, subminor);
166 case xmlSecCheckVersionABICompatible:
167 if((minor < XMLSEC_VERSION_MINOR) ||
168 ((minor == XMLSEC_VERSION_MINOR) &&
169 (subminor < XMLSEC_VERSION_SUBMINOR))) {
170 xmlSecError(XMLSEC_ERRORS_HERE,
173 XMLSEC_ERRORS_R_XMLSEC_FAILED,
174 "mode=abi compatible;expected minor version=%d;real minor version=%d;expected subminor version=%d;real subminor version=%d",
175 XMLSEC_VERSION_MINOR, minor,
176 XMLSEC_VERSION_SUBMINOR, subminor);