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