Migrated ShibTarget logic into ServiceProvider base.
[shibboleth/cpp-sp.git] / shibsp / util / TemplateParameters.cpp
1 /*
2  *  Copyright 2001-2006 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * TemplateParameters.cpp
19  * 
20  * Supplies xmltooling TemplateEngine with additional parameters from a PropertySet. 
21  */
22
23 #include "internal.h"
24 #include "util/TemplateParameters.h"
25
26 #include <ctime>
27
28 using namespace shibsp;
29 using namespace xmltooling;
30 using namespace std;
31
32 void TemplateParameters::setPropertySet(const PropertySet* props)
33 {
34     m_props = props;
35
36     // Create a timestamp.
37     time_t now = time(NULL);
38 #ifdef HAVE_CTIME_R
39     char timebuf[32];
40     m_map["now"] = ctime_r(&now,timebuf);
41 #else
42     m_map["now"] = ctime(&now);
43 #endif
44 }
45
46 const char* TemplateParameters::getParameter(const char* name) const
47 {
48     const char* pch = TemplateEngine::TemplateParameters::getParameter(name);
49     if (pch || !m_props)
50         return pch;
51     pair<bool,const char*> p = m_props->getString(name);
52     return p.first ? p.second : NULL;
53 }