Return NULL sock name if config not loaded.
[shibboleth/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 namespace {
21   ShibTargetConfig* g_Config = NULL;
22 };
23
24 /* initialize and finalize the target library: return 0 on success, 1 on failure */
25 extern "C" int shib_target_initialize (const char* app_name, const char* inifile)
26 {
27   if (!app_name) {
28     cerr << "APPLICATION ERROR: No application supplied to shib_target_init\n";
29     return 1;
30   }
31
32   if (g_Config) {
33     log4cpp::Category& log = log4cpp::Category::getInstance("shibtarget.init");
34     log.error("shib_target_initialize: Already initialized");
35     return 1;
36   }
37
38   // pre-init the configuration..
39   ShibTargetConfig::preinit();
40
41   try {
42     g_Config = &(ShibTargetConfig::init(app_name, inifile));
43   } catch (runtime_error &e) {
44     fprintf(stderr,"shib_target_initialize failed: %s\n",e.what());
45     return 1;
46   }
47
48   return 0;
49 }
50
51 extern "C" void shib_target_finalize (void)
52 {
53   if (!g_Config)
54     return;
55
56   g_Config->shutdown();
57   g_Config = NULL;
58 }
59
60 extern "C" ShibSockName shib_target_sockname(void)
61 {
62     return (g_Config ? g_Config->m_SocketName : (ShibSockName)0);
63 }