1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
<chapter id="xmlsec-notes-init-shutdown">
<title>Initialization and shutdown.</title>
<para>XML Security Library initialization/shutdown
process includes initialization and shutdown of the
dependent libraries:
<itemizedlist>
<listitem><para>libxml library;</para></listitem>
<listitem><para>libxslt library;</para></listitem>
<listitem><para>crypto library (OpenSSL, GnuTLS, NSS, ...);</para></listitem>
<listitem><para>xmlsec library
(<link linkend="xmlSecInit">xmlSecInit</link>
and <link linkend="xmlSecShutdown">xmlSecShutdown</link>
functions);
</para></listitem>
<listitem><para>xmlsec-crypto library
(<link linkend="xmlSecCryptoDLLoadLibrary">xmlSecCryptoDLLoadLibrary</link>
to load xmlsec-crypto library dynamicaly if needed,
<link linkend="xmlSecCryptoInit">xmlSecCryptoInit</link>
and <link linkend="xmlSecCryptoShutdown">xmlSecCryptoShutdown</link>
functions);
</para></listitem>
</itemizedlist>
xmlsec-crypto library also provides a convinient functions
<link linkend="xmlSecAppCryptoInit">xmlSecAppCryptoInit</link>
and <link linkend="xmlSecAppCryptoShutdown">xmlSecAppCryptoShutdown</link>
to initialize the crypto library itself but application can do it
by itself.
</para>
<para>
<example>
<title>Initializing application.</title>
<programlisting><![CDATA[
/* Init libxml and libxslt libraries */
xmlInitParser();
LIBXML_TEST_VERSION
xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
xmlSubstituteEntitiesDefault(1);
#ifndef XMLSEC_NO_XSLT
xmlIndentTreeOutput = 1;
#endif /* XMLSEC_NO_XSLT */
/* Init xmlsec library */
if(xmlSecInit() < 0) {
fprintf(stderr, "Error: xmlsec initialization failed.\n");
return(-1);
}
/* Check loaded library version */
if(xmlSecCheckVersion() != 1) {
fprintf(stderr, "Error: loaded xmlsec library version is not compatible.\n");
return(-1);
}
/* Load default crypto engine if we are supporting dynamic
* loading for xmlsec-crypto libraries. Use the crypto library
* name ("openssl", "nss", etc.) to load corresponding
* xmlsec-crypto library.
*/
#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING
if(xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) < 0) {
fprintf(stderr, "Error: unable to load default xmlsec-crypto library. Make sure\n"
"that you have it installed and check shared libraries path\n"
"(LD_LIBRARY_PATH) envornment variable.\n");
return(-1);
}
#endif /* XMLSEC_CRYPTO_DYNAMIC_LOADING */
/* Init crypto library */
if(xmlSecCryptoAppInit(NULL) < 0) {
fprintf(stderr, "Error: crypto initialization failed.\n");
return(-1);
}
/* Init xmlsec-crypto library */
if(xmlSecCryptoInit() < 0) {
fprintf(stderr, "Error: xmlsec-crypto initialization failed.\n");
return(-1);
}
]]></programlisting>
</example>
</para>
<para>
<example>
<title>Shutting down application.</title>
<programlisting><![CDATA[
/* Shutdown xmlsec-crypto library */
xmlSecCryptoShutdown();
/* Shutdown crypto library */
xmlSecCryptoAppShutdown();
/* Shutdown xmlsec library */
xmlSecShutdown();
/* Shutdown libxslt/libxml */
#ifndef XMLSEC_NO_XSLT
xsltCleanupGlobals();
#endif /* XMLSEC_NO_XSLT */
xmlCleanupParser();
]]></programlisting>
</example>
</para>
</chapter>
|