Starting migration to new SP library
[shibboleth/sp.git] / shibsp / SPConfig.cpp
1
2 /*
3  *  Copyright 2001-2006 Internet2
4  * 
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 /**
19  * SPConfig.cpp
20  * 
21  * Library configuration 
22  */
23
24 #include "internal.h"
25 #include "exceptions.h"
26 #include "SPConfig.h"
27
28 #include <log4cpp/Category.hh>
29 #include <saml/SAMLConfig.h>
30 #include <xmltooling/util/NDC.h>
31 #include <xmltooling/util/TemplateEngine.h>
32
33 using namespace shibsp;
34 using namespace opensaml;
35 using namespace xmltooling;
36 using namespace log4cpp;
37
38 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
39 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
40
41 namespace shibsp {
42    SPInternalConfig g_config;
43 }
44
45 SPConfig& SPConfig::getConfig()
46 {
47     return g_config;
48 }
49
50 SPInternalConfig& SPInternalConfig::getInternalConfig()
51 {
52     return g_config;
53 }
54
55 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
56 {
57     //delete m_serviceProvider;
58     m_serviceProvider = serviceProvider;
59 }
60
61 bool SPInternalConfig::init(const char* catalog_path)
62 {
63 #ifdef _DEBUG
64     NDC ndc("init");
65 #endif
66     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
67     log.debug("library initialization started");
68
69     const char* loglevel=getenv("SHIBSP_LOGGING");
70     if (!loglevel)
71         loglevel = SHIBSP_LOGGING;
72     XMLToolingConfig::getConfig().log_config(loglevel);
73
74     if (catalog_path)
75         XMLToolingConfig::getConfig().catalog_path = catalog_path;
76
77     if (!SAMLConfig::getConfig().init()) {
78         log.fatal("failed to initialize OpenSAML library");
79         return false;
80     }
81
82     XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
83     XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
84     
85     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
86     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
87
88     log.info("library initialization complete");
89     return true;
90 }
91
92 void SPInternalConfig::term()
93 {
94 #ifdef _DEBUG
95     NDC ndc("term");
96 #endif
97     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
98     log.info("shutting down the library");
99
100     //delete m_serviceProvider;
101     m_serviceProvider = NULL;
102
103     SAMLConfig::getConfig().term();
104     log.info("library shutdown complete");
105 }