Interim fix to handle HTTP codes.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 1 Apr 2005 16:54:34 +0000 (16:54 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 1 Apr 2005 16:54:34 +0000 (16:54 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@1472 cb58f699-b61c-0410-a6fe-9272a202ed29

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

index d98a066..0e947fa 100644 (file)
@@ -318,10 +318,9 @@ public:
         return string("");
     if (strcasecmp(auth_type, "shibboleth")) {
       if (!strcasecmp(auth_type, "basic") && m_dc->bBasicHijack == 1) {
-       core_dir_config* conf= (core_dir_config*)
-         ap_get_module_config(m_req->per_dir_config,
+        core_dir_config* conf= (core_dir_config*)ap_get_module_config(m_req->per_dir_config,
                               ap_find_linked_module("http_core.c"));
-       auth_type = conf->ap_auth_type = "shibboleth";
+        auth_type = conf->ap_auth_type = "shibboleth";
       }
     }
     return string(auth_type);
@@ -360,22 +359,22 @@ public:
       const char* w = ap_getword_white(m_req->pool, &t);
       rline->tokens.push_back(w);
       while (*t) {
-       w = ap_getword_conf(m_req->pool, &t);
-       rline->tokens.push_back(w);
+        w = ap_getword_conf(m_req->pool, &t);
+        rline->tokens.push_back(w);
       }
       ht->elements.push_back(rline);
     }
     return ht;
   }
-  virtual HTGroupTable* getGroupTable(string &user) {
+  virtual HTGroupTable* getGroupTable(stringuser) {
     if (m_dc->szAuthGrpFile && !user.empty()) {
       ap_log_rerror(APLOG_MARK,APLOG_DEBUG|APLOG_NOERRNO,SH_AP_R(m_req),
                    "getGroupTable() using groups file: %s\n",
                    m_dc->szAuthGrpFile);
       try {
-       HTGroupTableApache *gt = new HTGroupTableApache(m_req, user.c_str(),
+        HTGroupTableApache *gt = new HTGroupTableApache(m_req, user.c_str(),
                                                        m_dc->szAuthGrpFile);
-       return gt;
+        return gt;
       } catch (...) { }
     }
     return NULL;
@@ -383,9 +382,9 @@ public:
 
   virtual void* sendPage(
     const string& msg,
-    const string& content_type,
-       const saml::Iterator<header_t>& headers=EMPTY(header_t),
-    int code=200
+    int code=200,
+    const string& content_type="text/html",
+       const Iterator<header_t>& headers=EMPTY(header_t)
     ) {
     m_req->content_type = ap_psprintf(m_req->pool, content_type.c_str());
     while (headers.hasNext()) {
@@ -394,7 +393,7 @@ public:
     }
     ap_send_http_header(m_req);
     ap_rprintf(m_req, msg.c_str());
-    return (void*)DONE;
+    return (void*)((code==200) ? DONE : code);
   }
   virtual void* sendRedirect(const string& url) {
     ap_table_set(m_req->headers_out, "Location", url.c_str());
index 4a49748..4a56df8 100644 (file)
@@ -445,16 +445,24 @@ public:
   virtual string getRemoteUser(void) {
     return getHeader(string("remote-user"));
   }
-  virtual void* sendPage(const string& msg, const string& content_type,
-      const Iterator<header_t>& headers=EMPTY(header_t), int code=200) {
+  virtual void* sendPage(
+    const string& msg,
+    int code=200,
+    const string& content_type="text/html",
+    const Iterator<header_t>& headers=EMPTY(header_t)) {
     string hdr = string ("Connection: close\r\nContent-type: ") + content_type + "\r\n";
     while (headers.hasNext()) {
         const header_t& h=headers.next();
         hdr += h.first + ": " + h.second + "\r\n";
     }
     hdr += "\r\n";
-    // XXX Need to handle "code"
-    m_pfc->ServerSupportFunction(m_pfc, SF_REQ_SEND_RESPONSE_HEADER, "200 OK", (DWORD)hdr.c_str(), 0);
+    const char* codestr="200 OK";
+    switch (code) {
+        case 403:   codestr="403 Forbidden"; break;
+        case 404:   codestr="404 Not Found"; break;
+        case 500:   codestr="500 Server Error"; break;
+    }
+    m_pfc->ServerSupportFunction(m_pfc, SF_REQ_SEND_RESPONSE_HEADER, (void*)codestr, (DWORD)hdr.c_str(), 0);
     DWORD resplen = msg.size();
     m_pfc->WriteClient(m_pfc, (LPVOID)msg.c_str(), &resplen, 0);
     return (void*)SF_STATUS_REQ_FINISHED;
@@ -1112,16 +1120,23 @@ public:
     else
       return string(reinterpret_cast<char*>(m_lpECB->lpbData),m_lpECB->cbAvailable);
   }
-  virtual void* sendPage(const string &msg, const string& content_type,
-                        const Iterator<header_t>& headers=EMPTY(header_t), int code=200) {
+  virtual void* sendPage(
+    const string &msg,
+    int code=200,
+    const string& content_type="text/html",
+    const Iterator<header_t>& headers=EMPTY(header_t)) {
     string hdr = string ("Connection: close\r\nContent-type: ") + content_type + "\r\n";
     for (int k = 0; k < headers.size(); k++) {
       hdr += headers[k].first + ": " + headers[k].second + "\r\n";
     }
     hdr += "\r\n";
-    // XXX Need to handle "code"
-    m_lpECB->ServerSupportFunction(m_lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER,
-                                  "200 OK", 0, (LPDWORD)hdr.c_str());
+    const char* codestr="200 OK";
+    switch (code) {
+        case 403:   codestr="403 Forbidden"; break;
+        case 404:   codestr="404 Not Found"; break;
+        case 500:   codestr="500 Server Error"; break;
+    }
+    m_lpECB->ServerSupportFunction(m_lpECB->ConnID, HSE_REQ_SEND_RESPONSE_HEADER, (void*)codestr, 0, (LPDWORD)hdr.c_str());
     DWORD resplen = msg.size();
     m_lpECB->WriteClient(m_lpECB->ConnID, (LPVOID)msg.c_str(), &resplen, HSE_IO_SYNC);
     return (void*)HSE_STATUS_SUCCESS;
index 492bacb..4387a11 100644 (file)
@@ -401,11 +401,11 @@ namespace shibtarget {
     // If there are no headers supplied assume the content-type == text/html
     typedef std::pair<std::string, std::string> header_t;
     virtual void* sendPage(
-                          const std::string& msg,
-                          const std::string& content_type = "text/html",
-                          const saml::Iterator<header_t>& headers = EMPTY(header_t),
-                          int code = 200
-                          )=0;
+        const std::string& msg,
+        int code = 200,
+        const std::string& content_type = "text/html",
+        const saml::Iterator<header_t>& headers = EMPTY(header_t)
+        )=0;
     void* sendPage(const char *msg) {
       std::string m = msg;
       return sendPage(m);