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