https://issues.shibboleth.net/jira/browse/CPPXT-70
[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 #endif
32
33 // Export public APIs.
34 #define XMLTOOLING_EXPORTS
35
36 // eventually we might be able to support autoconf via cygwin...
37 #if defined (_MSC_VER) || defined(__BORLANDC__)
38 # include "config_win32.h"
39 #else
40 # include "config.h"
41 #endif
42
43 #include "base.h"
44 #include "XMLToolingConfig.h"
45 #include "util/ParserPool.h"
46
47 #include <map>
48 #include <string>
49 #include <vector>
50
51 #ifndef XMLTOOLING_NO_XMLSEC
52     #include <xsec/framework/XSECProvider.hpp>
53 #endif
54
55 #define XMLTOOLING_LOGCAT "XMLTooling"
56
57 // Macros for path and directory separators.
58 #if defined __CYGWIN32__ && !defined __CYGWIN__
59    /* For backwards compatibility with Cygwin b19 and
60       earlier, we define __CYGWIN__ here, so that
61       we can rely on checking just for that macro. */
62 #  define __CYGWIN__  __CYGWIN32__
63 #endif
64
65 #if defined _WIN32 && !defined __CYGWIN__
66    /* Use Windows separators on all _WIN32 defining
67       environments, except Cygwin. */
68 #  define DIR_SEPARATOR_CHAR        '\\'
69 #  define DIR_SEPARATOR_STR         "\\"
70 #  define PATH_SEPARATOR_CHAR       ';'
71 #  define PATH_SEPARATOR_STR        ";"
72 #endif
73 #ifndef DIR_SEPARATOR_CHAR
74    /* Assume that not having this is an indicator that all
75       are missing. */
76 #  define DIR_SEPARATOR_CHAR        '/'
77 #  define DIR_SEPARATOR_STR         "/"
78 #  define PATH_SEPARATOR_CHAR       ':'
79 #  define PATH_SEPARATOR_STR        ":"
80 #endif /* !DIR_SEPARATOR_CHAR */
81
82 namespace xmltooling {
83     
84     /// @cond OFF
85     class XMLTOOL_DLLLOCAL XMLToolingInternalConfig : public XMLToolingConfig
86     {
87     public:
88         XMLToolingInternalConfig();
89         ~XMLToolingInternalConfig();
90
91         static XMLToolingInternalConfig& getInternalConfig();
92
93         // global per-process setup and shutdown of runtime
94         bool init();
95         void term();
96
97         // global mutex available to library applications
98         Lockable* lock();
99         void unlock();
100
101         // named mutexes to limit lock scope
102         Mutex& getNamedMutex(const char* name);
103
104         // configuration
105         bool load_library(const char* path, void* context=nullptr);
106         bool log_config(const char* config=nullptr);
107
108         // parser access
109         ParserPool& getParser() const {
110             return *m_parserPool;
111         }
112
113         ParserPool& getValidatingParser() const {
114             return *m_validatingPool;
115         }
116
117 #ifndef XMLTOOLING_NO_XMLSEC
118         XSECCryptoX509CRL* X509CRL() const;
119         std::pair<const char*,unsigned int> mapXMLAlgorithmToKeyAlgorithm(const XMLCh* xmlAlgorithm) const;
120         void registerXMLAlgorithm(
121             const XMLCh* xmlAlgorithm, const char* keyAlgorithm, unsigned int size=0, XMLSecurityAlgorithmType type=ALGTYPE_UNK
122             );
123         bool isXMLAlgorithmSupported(const XMLCh* xmlAlgorithm, XMLSecurityAlgorithmType type=ALGTYPE_UNK);
124         void registerXMLAlgorithms();
125
126         XSECProvider* m_xsecProvider;
127     private:
128         typedef std::map<XMLSecurityAlgorithmType, std::map< xstring,std::pair<std::string,unsigned int> > > algmap_t;
129         algmap_t m_algorithmMap;
130 #endif
131
132     private:
133         int m_initCount;
134         Mutex* m_lock;
135         std::map<std::string,Mutex*> m_namedLocks;
136         std::vector<void*> m_libhandles;
137         ParserPool* m_parserPool;
138         ParserPool* m_validatingPool;
139     };
140     
141 #ifndef XMLTOOLING_NO_XMLSEC
142     void log_openssl();
143 #endif
144     
145     /// @endcond
146
147 };
148
149 #endif /* __xmltooling_internal_h__ */