Moved remoting layer to new 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 "ListenerService.h"
27 #include "SPConfig.h"
28
29 #include <log4cpp/Category.hh>
30 #include <saml/SAMLConfig.h>
31 #include <xmltooling/util/NDC.h>
32 #include <xmltooling/util/TemplateEngine.h>
33
34 using namespace shibsp;
35 using namespace opensaml;
36 using namespace xmltooling;
37 using namespace log4cpp;
38
39 DECL_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
40 DECL_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
41
42 namespace shibsp {
43    SPInternalConfig g_config;
44 }
45
46 SPConfig& SPConfig::getConfig()
47 {
48     return g_config;
49 }
50
51 SPInternalConfig& SPInternalConfig::getInternalConfig()
52 {
53     return g_config;
54 }
55
56 void SPConfig::setServiceProvider(ServiceProvider* serviceProvider)
57 {
58     //delete m_serviceProvider;
59     m_serviceProvider = serviceProvider;
60 }
61
62 bool SPInternalConfig::init(const char* catalog_path)
63 {
64 #ifdef _DEBUG
65     NDC ndc("init");
66 #endif
67     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
68     log.debug("library initialization started");
69
70     const char* loglevel=getenv("SHIBSP_LOGGING");
71     if (!loglevel)
72         loglevel = SHIBSP_LOGGING;
73     XMLToolingConfig::getConfig().log_config(loglevel);
74
75     if (catalog_path)
76         XMLToolingConfig::getConfig().catalog_path = catalog_path;
77
78     if (!SAMLConfig::getConfig().init()) {
79         log.fatal("failed to initialize OpenSAML library");
80         return false;
81     }
82
83     XMLToolingConfig::getConfig().setTemplateEngine(new TemplateEngine());
84     XMLToolingConfig::getConfig().getTemplateEngine()->setTagPrefix("shibmlp");
85     
86     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ConfigurationException,shibsp);
87     REGISTER_XMLTOOLING_EXCEPTION_FACTORY(ListenerException,shibsp);
88     
89     registerListenerServices();
90
91     log.info("library initialization complete");
92     return true;
93 }
94
95 void SPInternalConfig::term()
96 {
97 #ifdef _DEBUG
98     NDC ndc("term");
99 #endif
100     Category& log=Category::getInstance(SHIBSP_LOGCAT".Config");
101     log.info("shutting down the library");
102
103     //delete m_serviceProvider;
104     m_serviceProvider = NULL;
105     
106     ListenerServiceManager.deregisterFactories();
107
108     SAMLConfig::getConfig().term();
109     log.info("library shutdown complete");
110 }