Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / xmltooling / internal.h
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /*
22  *  internal.h - internally visible classes
23  */
24
25 #ifndef __xmltooling_internal_h__
26 #define __xmltooling_internal_h__
27
28 #ifdef WIN32
29 # define _CRT_SECURE_NO_DEPRECATE 1
30 # define _CRT_NONSTDC_NO_DEPRECATE 1
31 # define _SCL_SECURE_NO_WARNINGS 1
32 #endif
33
34 // Export public APIs.
35 #define XMLTOOLING_EXPORTS
36
37 // eventually we might be able to support autoconf via cygwin...
38 #if defined (_MSC_VER) || defined(__BORLANDC__)
39 # include "config_win32.h"
40 #else
41 # include "config.h"
42 #endif
43
44 #include "base.h"
45 #include "XMLToolingConfig.h"
46 #include "util/ParserPool.h"
47
48 #include <map>
49 #include <string>
50 #include <vector>
51
52 #ifndef XMLTOOLING_NO_XMLSEC
53     #include <xsec/framework/XSECProvider.hpp>
54 #endif
55
56 #define XMLTOOLING_LOGCAT "XMLTooling"
57
58 #define XMLTOOLING_ENTITY_EXPANSION_LIMIT 100
59
60 // Macros for path and directory separators.
61 #if defined __CYGWIN32__ && !defined __CYGWIN__
62    /* For backwards compatibility with Cygwin b19 and
63       earlier, we define __CYGWIN__ here, so that
64       we can rely on checking just for that macro. */
65 #  define __CYGWIN__  __CYGWIN32__
66 #endif
67
68 #if defined _WIN32 && !defined __CYGWIN__
69    /* Use Windows separators on all _WIN32 defining
70       environments, except Cygwin. */
71 #  define DIR_SEPARATOR_CHAR        '\\'
72 #  define DIR_SEPARATOR_STR         "\\"
73 #  define PATH_SEPARATOR_CHAR       ';'
74 #  define PATH_SEPARATOR_STR        ";"
75 #endif
76 #ifndef DIR_SEPARATOR_CHAR
77    /* Assume that not having this is an indicator that all
78       are missing. */
79 #  define DIR_SEPARATOR_CHAR        '/'
80 #  define DIR_SEPARATOR_STR         "/"
81 #  define PATH_SEPARATOR_CHAR       ':'
82 #  define PATH_SEPARATOR_STR        ":"
83 #endif /* !DIR_SEPARATOR_CHAR */
84
85 namespace xmltooling {
86     
87     /// @cond OFF
88     class XMLTOOL_DLLLOCAL XMLToolingInternalConfig : public XMLToolingConfig
89     {
90     public:
91         XMLToolingInternalConfig();
92         ~XMLToolingInternalConfig();
93
94         static XMLToolingInternalConfig& getInternalConfig();
95
96         // global per-process setup and shutdown of runtime
97         bool init();
98         void term();
99
100         // global mutex available to library applications
101         Lockable* lock();
102         void unlock();
103
104         // named mutexes to limit lock scope
105         Mutex& getNamedMutex(const char* name);
106
107         // configuration
108         bool load_library(const char* path, void* context=nullptr);
109         bool log_config(const char* config=nullptr);
110
111         // parser access
112         ParserPool& getParser() const {
113             return *m_parserPool;
114         }
115
116         ParserPool& getValidatingParser() const {
117             return *m_validatingPool;
118         }
119
120 #ifndef XMLTOOLING_NO_XMLSEC
121         XSECCryptoX509CRL* X509CRL() const;
122         std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const;
123         void registerXMLAlgorithm(
124             const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0, XMLSecurityAlgorithmType type=ALGTYPE_UNK
125             );
126         bool isXMLAlgorithmSupported(const XMLCh* xmlAlgorithm, XMLSecurityAlgorithmType type=ALGTYPE_UNK);
127         void registerXMLAlgorithms();
128
129         XSECProvider* m_xsecProvider;
130     private:
131         typedef std::map<XMLSecurityAlgorithmType, std::map< xstring,std::pair<std::string,unsigned int> > > algmap_t;
132         algmap_t m_algorithmMap;
133 #endif
134
135     private:
136         int m_initCount;
137         std::auto_ptr<Mutex> m_lock;
138         std::map<std::string,Mutex*> m_namedLocks;
139         std::vector<void*> m_libhandles;
140         ParserPool* m_parserPool;
141         ParserPool* m_validatingPool;
142     };
143     
144 #ifndef XMLTOOLING_NO_XMLSEC
145     void log_openssl();
146 #endif
147     
148     /// @endcond
149
150 };
151
152 #endif /* __xmltooling_internal_h__ */