Extended MLP to support arbitrary tag subbing from XML config
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Thu, 15 Apr 2004 04:12:39 +0000 (04:12 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Thu, 15 Apr 2004 04:12:39 +0000 (04:12 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@1001 cb58f699-b61c-0410-a6fe-9272a202ed29

apache/mod_apache.cpp
isapi_shib/isapi_shib.cpp
shib-target/shib-mlp.cpp
shib-target/shib-target.h

index 6044dd8..d0d85ae 100644 (file)
@@ -115,7 +115,7 @@ static int shib_error_page(request_rec* r, const IApplication* app, const char*
         if (p.first) {
             ifstream infile(p.second);
             if (!infile.fail()) {
-                const char* res = mlp.run(infile);
+                const char* res = mlp.run(infile,props);
                 if (res) {
                     r->content_type = ap_psprintf(r->pool, "text/html");
                     ap_send_http_header(r);
@@ -234,7 +234,7 @@ extern "C" int shib_check_user(request_rec* r)
 
     // Make sure this session is still valid.
     RPCError* status = NULL;
-    ShibMLP markupProcessor(application);
+    ShibMLP markupProcessor;
     markupProcessor.insert("requestURL", targeturl);
 
     try {
@@ -513,7 +513,7 @@ int shib_handler(request_rec* r, const IApplication* application, const IPropert
         return SERVER_ERROR;
     }
 
-    ShibMLP markupProcessor(application);
+    ShibMLP markupProcessor;
     markupProcessor.insert("requestURL", targeturl);
 
     // Process SHIRE request
@@ -917,7 +917,7 @@ extern "C" int shib_auth_checker(request_rec* r)
         return HTTP_FORBIDDEN;
     }
 
-    ShibMLP markupProcessor(application);
+    ShibMLP markupProcessor;
     markupProcessor.insert("requestURL", ap_construct_url(r->pool,r->unparsed_uri,r));
     return shib_error_page(r, application, "access", markupProcessor);
 }
index 29e2401..e9ad319 100644 (file)
@@ -377,7 +377,7 @@ DWORD WriteClientError(PHTTP_FILTER_CONTEXT pfc, const IApplication* app, const
         if (p.first) {
             ifstream infile(p.second);
             if (!infile.fail()) {
-                const char* res = mlp.run(infile);
+                const char* res = mlp.run(infile,props);
                 if (res) {
                     static const char* ctype="Content-Type: text/html\r\n";
                     pfc->AddResponseHeaders(pfc,const_cast<char*>(ctype),0);
@@ -476,7 +476,7 @@ extern "C" DWORD WINAPI HttpFilterProc(PHTTP_FILTER_CONTEXT pfc, DWORD notificat
 
         // Make sure this session is still valid.
         RPCError* status = NULL;
-        ShibMLP markupProcessor(application);
+        ShibMLP markupProcessor;
         markupProcessor.insert("requestURL", targeturl);
     
         dynabuf abuf(16);
@@ -750,7 +750,7 @@ DWORD WriteClientError(LPEXTENSION_CONTROL_BLOCK lpECB, const IApplication* app,
         if (p.first) {
             ifstream infile(p.second);
             if (!infile.fail()) {
-                const char* res = mlp.run(infile);
+                const char* res = mlp.run(infile,props);
                 if (res) {
                     static const char* ctype="Content-Type: text/html\r\n";
                     lpECB->ServerSupportFunction(lpECB->ConnID,HSE_REQ_SEND_RESPONSE_HEADER,"200 OK",0,(LPDWORD)ctype);
@@ -880,7 +880,7 @@ extern "C" DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
         // Process the post.
         string cookie;
         RPCError* status=NULL;
-        ShibMLP markupProcessor(application);
+        ShibMLP markupProcessor;
         markupProcessor.insert("requestURL", targeturl.c_str());
         try {
             status = shire.sessionCreate(elements.first,buf,cookie);
@@ -935,7 +935,7 @@ extern "C" DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
     }
     catch (ShibTargetException &e) {
         if (application) {
-            ShibMLP markupProcessor(application);
+            ShibMLP markupProcessor;
             markupProcessor.insert("requestURL", targeturl.c_str());
             markupProcessor.insert("errorType", "Session Creation Service Error");
             markupProcessor.insert("errorText", e.what());
@@ -946,7 +946,7 @@ extern "C" DWORD WINAPI HttpExtensionProc(LPEXTENSION_CONTROL_BLOCK lpECB)
 #ifndef _DEBUG
     catch (...) {
         if (application) {
-            ShibMLP markupProcessor(application);
+            ShibMLP markupProcessor;
             markupProcessor.insert("requestURL", targeturl.c_str());
             markupProcessor.insert("errorType", "Session Creation Service Error");
             markupProcessor.insert("errorText", "Unexpected Exception");
index fa25550..650e1d3 100644 (file)
@@ -91,26 +91,13 @@ static void trimspace (string& s)
   s = s.substr(start, end - start + 1);
 }
 
-ShibMLP::ShibMLP (const IApplication* app)
+ShibMLP::ShibMLP()
 {
   m_priv = new ShibMLPPriv ();
 
   // Create a timestamp
   time_t now = time(NULL);
   insert("now", ctime(&now));
-  
-  // Insert any available information.
-  if (app) {
-      const IPropertySet* props=app->getPropertySet("Errors");
-      if (props) {
-        pair<bool,const char*> p=props->getString("supportContact");
-        if (p.first)
-            insert("supportContact",p.second);
-        p=props->getString("logoLocation");
-        if (p.first)
-            insert("logoLocation",p.second);
-      }
-  }
 }
 
 ShibMLP::~ShibMLP ()
@@ -118,7 +105,7 @@ ShibMLP::~ShibMLP ()
   delete m_priv;
 }
 
-const char* ShibMLP::run (const string& is)
+const char* ShibMLP::run(const string& is, const IPropertySet* props)
 {
   const char* line = is.c_str();
   const char* lastpos = line;
@@ -156,16 +143,23 @@ const char* ShibMLP::run (const string& is)
       m_priv->log->debug("found key: \"%s\"", key.c_str());
 
       map<string,string>::const_iterator i=m_map.find(key);
-      if (i == m_map.end()) {
-        static string s1 = "<!-- Unknown SHIBMLP key: ";
-        static string s2 = "/>";
-        m_generated += s1 + key + s2;
-        m_priv->log->debug("key unknown");
-      }
-      else {
+      if (i != m_map.end()) {
         m_generated += i->second;
         m_priv->log->debug("key maps to \"%s\"", i->second.c_str());
       }
+      else {
+        pair<bool,const char*> p=props ? props->getString(key.c_str()) : pair<bool,const char*>(false,NULL);
+        if (p.first) {
+            m_generated += p.second;
+            m_priv->log->debug("property maps to \"%s\"", p.second);
+        }
+        else {
+            static string s1 = "<!-- Unknown SHIBMLP key: ";
+            static string s2 = "/>";
+            m_generated += s1 + key + s2;
+            m_priv->log->debug("key unknown");
+        }
+      }
 
       lastpos = thispos + 2;   // strlen("/>")
     }
@@ -175,7 +169,7 @@ const char* ShibMLP::run (const string& is)
   return m_generated.c_str();
 }
 
-const char* ShibMLP::run (istream& is)
+const char* ShibMLP::run(istream& is, const IPropertySet* props)
 {
   static string eol = "\r\n";
   string str, line;
@@ -185,7 +179,7 @@ const char* ShibMLP::run (istream& is)
   while (getline(is, line))
     str += line + eol;
 
-  return run(str);
+  return run(str,props);
 }
 
 void ShibMLP::insert (RPCError& e)
index d862f42..3c87285 100644 (file)
@@ -310,7 +310,7 @@ namespace shibtarget {
     class ShibMLPPriv;
     class SHIBTARGET_EXPORTS ShibMLP {
     public:
-        ShibMLP(const IApplication* app=NULL);
+        ShibMLP();
         ~ShibMLP();
 
         void insert (const std::string& key, const std::string& value);
@@ -330,11 +330,11 @@ namespace shibtarget {
 
         void clear () { m_map.clear(); }
 
-        const char* run (std::istream& s);
-        const char* run (const std::string& input);
-        const char* run (const char* input) {
+        const char* run (std::istream& s, const IPropertySet* props=NULL);
+        const char* run (const std::string& input, const IPropertySet* props=NULL);
+        const char* run (const char* input, const IPropertySet* props=NULL) {
             std::string i = input;
-            return run(i);
+            return run(i,props);
         }
 
     private: