- Update to Xerces-2.1 support
[shibboleth/cpp-sp.git] / shib-target / shib-target.cpp
1 /*
2  * shib-target.cpp -- General target initialization and finalization routines
3  *
4  * Created By:  Derek Atkins <derek@ihtfp.com>
5  *
6  * $Id$
7  */
8
9 #include "shib-target.h"
10
11 #include <log4cpp/Category.hh>
12
13 using namespace saml;
14 using namespace shibboleth;
15 using namespace shibtarget;
16 using namespace std;
17
18 /* shib-target.cpp */
19
20 static ShibTargetConfig* g_Config = NULL;
21
22 /* initialize and finalize the target library: return 0 on success, 1 on failure */
23 extern "C" int shib_target_initialize (const char* app_name, const char* inifile)
24 {
25   if (!app_name) {
26     cerr << "APPLICATION ERROR: No application supplied to shib_target_init\n";
27     return 1;
28   }
29
30   if (g_Config) {
31     log4cpp::Category& log = log4cpp::Category::getInstance("shibtarget.init");
32     log.error("shib_target_initialize: Already initialized");
33     return 1;
34   }
35
36   try {
37     g_Config = &(ShibTargetConfig::init(app_name, inifile));
38   } catch (runtime_error &e) {
39     return 1;
40   }
41
42   return 0;
43 }
44
45 extern "C" void shib_target_finalize (void)
46 {
47   if (!g_Config)
48     return;
49
50   g_Config->shutdown();
51   g_Config = NULL;
52 }