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