Updated footer comment
[metaproxy-moved-to-github.git] / src / filter_frontend_net.cpp
index 22a3a9d..3839101 100644 (file)
@@ -1,7 +1,5 @@
-/* $Id: filter_frontend_net.cpp,v 1.26 2008-02-20 15:07:51 adam Exp $
-   Copyright (c) 2005-2008, Index Data.
-
-This file is part of Metaproxy.
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2008 Index Data
 
 Metaproxy is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free
@@ -14,10 +12,9 @@ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 for more details.
 
 You should have received a copy of the GNU General Public License
-along with Metaproxy; see the file LICENSE.  If not, write to the
-Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-02111-1307, USA.
- */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
 
 #include "config.hpp"
 
@@ -87,13 +84,13 @@ namespace metaproxy_1 {
     class ThreadPoolPackage : public mp::IThreadPoolMsg {
     public:
         ThreadPoolPackage(mp::Package *package, mp::ZAssocChild *ses) :
-            m_session(ses), m_package(package) { };
+            m_assoc_child(ses), m_package(package) { };
         ~ThreadPoolPackage();
         IThreadPoolMsg *handle();
         void result();
         
     private:
-        mp::ZAssocChild *m_session;
+        mp::ZAssocChild *m_assoc_child;
         mp::Package *m_package;
         
     };
@@ -126,14 +123,14 @@ mp::ThreadPoolPackage::~ThreadPoolPackage()
 
 void mp::ThreadPoolPackage::result()
 {
-    m_session->m_no_requests--;
+    m_assoc_child->m_no_requests--;
 
     yazpp_1::GDU *gdu = &m_package->response();
 
     if (gdu->get())
     {
        int len;
-       m_session->send_GDU(gdu->get(), &len);
+       m_assoc_child->send_GDU(gdu->get(), &len);
     }
     else if (!m_package->session().is_closed())
     {
@@ -150,14 +147,24 @@ void mp::ThreadPoolPackage::result()
                 z_gdu->u.z3950, Z_Close_systemProblem, 
                 "unhandled Z39.50 request");
 
-            m_session->send_Z_PDU(apdu_response, &len);
-            m_package->session().close();
+            m_assoc_child->send_Z_PDU(apdu_response, &len);
         }
+        else if (z_gdu && z_gdu->which == Z_GDU_HTTP_Request)
+        {
+            // For HTTP, respond with Server Error
+            int len;
+            mp::odr odr;
+            Z_GDU *zgdu_res 
+                = odr.create_HTTP_Response(m_package->session(), 
+                                           z_gdu->u.HTTP_Request, 500);
+            m_assoc_child->send_GDU(zgdu_res, &len);
+        }
+        m_package->session().close();
     }
 
-    if (m_session->m_no_requests == 0 && m_package->session().is_closed())
+    if (m_assoc_child->m_no_requests == 0 && m_package->session().is_closed())
     {
-        m_session->close();
+        m_assoc_child->close();
     }
     delete this;
 }
@@ -212,7 +219,8 @@ void mp::ZAssocChild::failNotify()
     // TODO: send Package to signal "close"
     if (m_session.is_closed())
     {
-        delete this;
+        if (m_no_requests == 0)
+            delete this;
        return;
     }
     m_no_requests++;
@@ -441,8 +449,9 @@ extern "C" {
 /*
  * Local variables:
  * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
  * indent-tabs-mode: nil
- * c-file-style: "stroustrup"
  * End:
  * vim: shiftwidth=4 tabstop=8 expandtab
  */
+