Support for new CGI data handling methods.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Mon, 2 Jan 2006 04:28:07 +0000 (04:28 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Mon, 2 Jan 2006 04:28:07 +0000 (04:28 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@1901 cb58f699-b61c-0410-a6fe-9272a202ed29

apache/mod_apache.cpp
isapi_shib/isapi_shib.cpp
nsapi_shib/nsapi_shib.cpp

index 568d4ea..cb6a274 100644 (file)
 #undef _XOPEN_SOURCE    // causes gethostname conflict in unistd.h
 #endif
 
+#ifdef WIN32
+# define _CRT_NONSTDC_NO_DEPRECATE 1
+# define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+
 // SAML Runtime
 #include <saml/saml.h>
 #include <shib/shib.h>
 #include <shib-target/shib-target.h>
 #include <xercesc/util/regx/RegularExpression.hpp>
 
+#ifdef WIN32
+# include <winsock.h>
+#endif
+
 #undef _XPG4_2
 
 // Apache specific header files
@@ -205,8 +214,15 @@ extern "C" const char* shib_ap_set_file_slot(cmd_parms* parms,
 
 class ShibTargetApache : public ShibTarget
 {
+  mutable string m_body;
+  mutable bool m_gotBody;
+
 public:
-  ShibTargetApache(request_rec* req) {
+  request_rec* m_req;
+  shib_dir_config* m_dc;
+  shib_server_config* m_sc;
+
+  ShibTargetApache(request_rec* req) : m_gotBody(false) {
     m_sc = (shib_server_config*)ap_get_module_config(req->server->module_config, &mod_shib);
     m_dc = (shib_dir_config*)ap_get_module_config(req->per_dir_config, &mod_shib);
 
@@ -222,7 +238,7 @@ public:
 
     m_req = req;
   }
-  ~ShibTargetApache() { }
+  ~ShibTargetApache() {}
 
   virtual void log(ShibLogLevel level, const string &msg) {
     ShibTarget::log(level,msg);
@@ -244,27 +260,28 @@ public:
     char* val = ap_psprintf(m_req->pool, "%s=%s", name.c_str(), value.c_str());
     ap_table_addn(m_req->err_headers_out, "Set-Cookie", val);
   }
-  virtual string getArgs(void) { return string(m_req->args ? m_req->args : ""); }
-  virtual string getPostData(void) {
+  virtual const char* getQueryString() const { return m_req->args; }
+  virtual const char* getRequestBody() const {
+    if (m_gotBody)
+        return m_body.c_str();
     // Read the posted data
     if (ap_setup_client_block(m_req, REQUEST_CHUNKED_ERROR))
-        throw FatalProfileException("Apache function (setup_client_block) failed while reading profile submission.");
+        throw SAMLException("Apache function (setup_client_block) failed while reading POST request body.");
     if (!ap_should_client_block(m_req))
-        throw FatalProfileException("Apache function (should_client_block) failed while reading profile submission.");
+        throw SAMLException("Apache function (should_client_block) failed while reading POST request body.");
     if (m_req->remaining > 1024*1024)
-        throw FatalProfileException("Blocked too-large a submission to profile endpoint.");
-    string cgistr;
+        throw SAMLException("Blocked POST request body larger than size limit.");
+    m_gotBody=true;
     char buff[HUGE_STRING_LEN];
-    ap_hard_timeout("[mod_shib] getPostData", m_req);
+    ap_hard_timeout("[mod_shib] getRequestBody", m_req);
     memset(buff, 0, sizeof(buff));
     while (ap_get_client_block(m_req, buff, sizeof(buff)-1) > 0) {
       ap_reset_timeout(m_req);
-      cgistr += buff;
+      m_body += buff;
       memset(buff, 0, sizeof(buff));
     }
     ap_kill_timeout(m_req);
-
-    return cgistr;
+    return m_body.c_str();
   }
   virtual void clearHeader(const string &name) {
     ap_table_unset(m_req->headers_in, name.c_str());
@@ -303,10 +320,6 @@ public:
   }
   virtual void* returnDecline(void) { return (void*)DECLINED; }
   virtual void* returnOK(void) { return (void*)OK; }
-
-  request_rec* m_req;
-  shib_dir_config* m_dc;
-  shib_server_config* m_sc;
 };
 
 /********************************************************************************/
@@ -889,11 +902,12 @@ extern "C" void shib_child_init(apr_pool_t* p, server_rec* s)
     try {
         g_Config=&ShibTargetConfig::getConfig();
         g_Config->setFeatures(
+            ShibTargetConfig::Caching |
             ShibTargetConfig::Listener |
             ShibTargetConfig::Metadata |
             ShibTargetConfig::AAP |
             ShibTargetConfig::RequestMapper |
-            ShibTargetConfig::LocalExtensions |
+            ShibTargetConfig::InProcess |
             ShibTargetConfig::Logging
             );
         if (!g_Config->init(g_szSchemaDir)) {
index 07f05e5..102be44 100644 (file)
@@ -22,6 +22,9 @@
 
 #include "config_win32.h"
 
+#define _CRT_NONSTDC_NO_DEPRECATE 1
+#define _CRT_SECURE_NO_DEPRECATE 1
+
 // SAML Runtime
 #include <saml/saml.h>
 #include <shib/shib.h>
@@ -154,10 +157,11 @@ extern "C" BOOL WINAPI GetFilterVersion(PHTTP_FILTER_VERSION pVer)
         g_Config=&ShibTargetConfig::getConfig();
         g_Config->setFeatures(
             ShibTargetConfig::Listener |
+            ShibTargetConfig::Caching |
             ShibTargetConfig::Metadata |
             ShibTargetConfig::AAP |
             ShibTargetConfig::RequestMapper |
-            ShibTargetConfig::LocalExtensions |
+            ShibTargetConfig::InProcess |
             ShibTargetConfig::Logging
             );
         if (!g_Config->init(schemadir)) {
@@ -462,8 +466,8 @@ public:
     // Set the cookie for later.  Use it during the redirect.
     m_cookie += "Set-Cookie: " + name + "=" + value + "\r\n";
   }
-  virtual string getArgs(void) { throw runtime_error("getArgs not implemented"); }
-  virtual string getPostData(void) { throw runtime_error("getPostData not implemented"); }
+  virtual const char* getQueryString() const { throw runtime_error("getQueryString not implemented"); }
+  virtual const char* getRequestBody() const { throw runtime_error("getRequestBody not implemented"); }
 };
 
 DWORD WriteClientError(PHTTP_FILTER_CONTEXT pfc, const char* msg)
@@ -571,9 +575,11 @@ class ShibTargetIsapiE : public ShibTarget
 {
   LPEXTENSION_CONTROL_BLOCK m_lpECB;
   string m_cookie;
+  mutable string m_body;
+  mutable bool m_gotBody;
   
 public:
-  ShibTargetIsapiE(LPEXTENSION_CONTROL_BLOCK lpECB, const site_t& site) {
+  ShibTargetIsapiE(LPEXTENSION_CONTROL_BLOCK lpECB, const site_t& site) : m_gotBody(false) {
     dynabuf ssl(5);
     GetServerVariable(lpECB,"HTTPS",ssl,5);
     bool SSL=(ssl=="on" || ssl=="ON");
@@ -666,28 +672,32 @@ public:
     // Set the cookie for later.  Use it during the redirect.
     m_cookie += "Set-Cookie: " + name + "=" + value + "\r\n";
   }
-  virtual string getArgs(void) {
-    return string(m_lpECB->lpszQueryString ? m_lpECB->lpszQueryString : "");
+  virtual const char* getQueryString() const {
+    return m_lpECB->lpszQueryString;
   }
-  virtual string getPostData(void) {
+  virtual const char* getRequestBody() const {
+    if (m_gotBody)
+        return m_body.c_str();
     if (m_lpECB->cbTotalBytes > 1024*1024) // 1MB?
-      throw FatalProfileException("Blocked too-large a submission to profile endpoint.");
+      throw SAMLException("Size of POST request body exceeded limit.");
     else if (m_lpECB->cbTotalBytes != m_lpECB->cbAvailable) {
-      string cgistr;
+      m_gotBody=true;
       char buf[8192];
       DWORD datalen=m_lpECB->cbTotalBytes;
       while (datalen) {
         DWORD buflen=8192;
         BOOL ret = m_lpECB->ReadClient(m_lpECB->ConnID, buf, &buflen);
         if (!ret || !buflen)
-          throw FatalProfileException("Error reading profile submission from browser.");
-        cgistr.append(buf, buflen);
+          throw SAMLException("Error reading POST request body from browser.");
+        m_body.append(buf, buflen);
         datalen-=buflen;
       }
-      return cgistr;
     }
-    else
-      return string(reinterpret_cast<char*>(m_lpECB->lpbData),m_lpECB->cbAvailable);
+    else {
+        m_gotBody=true;
+        m_body.assign(reinterpret_cast<char*>(m_lpECB->lpbData),m_lpECB->cbAvailable);
+    }
+    return m_body.c_str();
   }
   virtual void* sendPage(
     const string &msg,
index 1a9e027..985dfcf 100644 (file)
    12/13/04
 */
 
-#include "config_win32.h"
+#if defined (_MSC_VER) || defined(__BORLANDC__)
+# include "config_win32.h"
+#else
+# include "config.h"
+#endif
+
+#ifdef WIN32
+# define _CRT_NONSTDC_NO_DEPRECATE 1
+# define _CRT_SECURE_NO_DEPRECATE 1
+#endif
+
 
 // SAML Runtime
 #include <saml/saml.h>