Imported Upstream version 2.1.dfsg1
[shibboleth/sp.git] / fastcgi / shibresponder.cpp
index f40a2e7..3582833 100644 (file)
@@ -1,6 +1,6 @@
 /*\r
  *  Copyright 2001-2007 Internet2\r
- * \r
+ *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
@@ -209,7 +209,7 @@ public:
     virtual void clearHeader(const char* rawname, const char* cginame) {\r
         throw runtime_error("clearHeader not implemented by FastCGI responder.");\r
     }\r
-  \r
+\r
     virtual void setHeader(const char* name, const char* value) {\r
         throw runtime_error("setHeader not implemented by FastCGI responder.");\r
     }\r
@@ -283,20 +283,9 @@ int main(void)
         exit(1);\r
     }\r
 \r
-    const char* config=getenv("SHIBSP_CONFIG");\r
-    if (!config)\r
-        config=SHIBSP_CONFIG;\r
-\r
     try {\r
-        DOMDocument* dummydoc=XMLToolingConfig::getConfig().getParser().newDocument();\r
-        XercesJanitor<DOMDocument> docjanitor(dummydoc);\r
-        DOMElement* dummy = dummydoc->createElementNS(NULL,path);\r
-        auto_ptr_XMLCh src(config);\r
-        dummy->setAttributeNS(NULL,path,src.get());\r
-        dummy->setAttributeNS(NULL,validate,xmlconstants::XML_ONE);\r
-\r
-        g_Config->setServiceProvider(g_Config->ServiceProviderManager.newPlugin(XML_SERVICE_PROVIDER,dummy));\r
-        g_Config->getServiceProvider()->init();\r
+        if (!g_Config->instantiate(NULL, true))\r
+            throw runtime_error("unknown error");\r
     }\r
     catch (exception& ex) {\r
         g_Config->term();\r
@@ -327,7 +316,7 @@ int main(void)
 \r
     FCGX_Init();\r
     FCGX_InitRequest(&request, 0, 0);\r
-    \r
+\r
     cout << "Shibboleth initialization complete. Starting request loop." << endl;\r
     while (FCGX_Accept_r(&request) == 0) {\r
         // Note that the default bufsize (0) will cause the use of iostream\r
@@ -350,17 +339,15 @@ int main(void)
         try {\r
             xmltooling::NDC ndc("FastCGI shibresponder");\r
             ShibTargetFCGI stf(&request, content, g_ServerScheme.c_str(), g_ServerName.c_str(), g_ServerPort);\r
-          \r
+\r
             pair<bool,long> res = stf.getServiceProvider().doHandler(stf);\r
             if (res.first) {\r
-#ifdef _DEBUG\r
-                cerr << "shib: doHandler handled the request" << endl;\r
-#endif\r
+                stf.log(SPRequest::SPDebug, "shib: doHandler handled the request");\r
                 switch(res.second) {\r
                     case SHIB_RETURN_OK:\r
                         print_ok();\r
                         break;\r
-              \r
+\r
                     case SHIB_RETURN_KO:\r
                         cerr << "shib: doHandler failed to handle the request" << endl;\r
                         print_error("<html><body>FastCGI Shibboleth responder should only be used for Shibboleth protocol requests.</body></html>");\r
@@ -369,7 +356,7 @@ int main(void)
                     case SHIB_RETURN_DONE:\r
                         // response already handled\r
                         break;\r
-              \r
+\r
                     default:\r
                         cerr << "shib: doHandler returned an unexpected result: " << res.second << endl;\r
                         print_error("<html><body>FastCGI Shibboleth responder returned an unexpected result.</body></html>");\r
@@ -379,8 +366,8 @@ int main(void)
             else {\r
                 cerr << "shib: doHandler failed to handle request." << endl;\r
                 print_error("<html><body>FastCGI Shibboleth responder failed to process request.</body></html>");\r
-            }          \r
-          \r
+            }\r
+\r
         }\r
         catch (exception& e) {\r
             cerr << "shib: FastCGI responder caught an exception: " << e.what() << endl;\r
@@ -403,6 +390,6 @@ int main(void)
 \r
     if (g_Config)\r
         g_Config->term();\r
\r
+\r
     return 0;\r
 }\r