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