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