Work on filter log. Added support for init-options logging. Category
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 20 Jun 2006 22:29:38 +0000 (22:29 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 20 Jun 2006 22:29:38 +0000 (22:29 +0000)
"session", "apdu", may be specified in log config (to cover both
request and response respectively).

etc/config-shared1.xml
etc/config.xsd
src/filter_log.cpp

index 5ae3d49..a7d6223 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<!-- $Id: config-shared1.xml,v 1.1 2006-06-19 13:27:49 adam Exp $ -->
+<!-- $Id: config-shared1.xml,v 1.2 2006-06-20 22:29:38 adam Exp $ -->
 <yp2 xmlns="http://indexdata.dk/yp2/config/1">
   <start route="start"/>
   <filters>
   <routes>  
     <route id="start">
       <filter refid="frontend"/>
-      <filter type="log"/>
-      <filter type="session_shared"/>
+      <filter type="log">
+       <message>F</message>
+       <category init-options="true" apdu="false"/>
+      </filter>
+      <filter type="session_shared"/> 
+      <filter type="log">
+       <message>B</message>
+       <category init-options="true" apdu="false"/>
+      </filter>
       <filter refid="backend"/>
     </route>
   </routes>
index e915697..1e4fd0d 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- $Id: config.xsd,v 1.18 2006-06-19 13:27:49 adam Exp $ -->
+<!-- $Id: config.xsd,v 1.19 2006-06-20 22:29:38 adam Exp $ -->
 <!--
        This Schema prescribes the format of YP2 configuration files.
        Invoke it like this:
            <xs:complexType>
             <xs:attribute name="request-session" type="xs:boolean"/>
             <xs:attribute name="response-session" type="xs:boolean"/>
+            <xs:attribute name="session" type="xs:boolean"/>
             <xs:attribute name="request-apdu" type="xs:boolean"/>
             <xs:attribute name="response-apdu" type="xs:boolean"/>
+            <xs:attribute name="apdu" type="xs:boolean"/>
+            <xs:attribute name="init-options" type="xs:boolean"/>
            </xs:complexType>
          </xs:element>
         </xs:sequence>
index fc457bb..ec34a73 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_log.cpp,v 1.19 2006-06-19 13:08:00 adam Exp $
+/* $Id: filter_log.cpp,v 1.20 2006-06-20 22:29:39 adam Exp $
    Copyright (c) 2005-2006, Index Data.
 
    See the LICENSE file for details
@@ -42,6 +42,7 @@ namespace metaproxy_1 {
             bool m_res_apdu;
             bool m_req_session;
             bool m_res_session;
+            bool m_init_options;
         };
         // Only used during configure stage (no threading)
         static std::list<LFilePtr> filter_log_files;
@@ -54,6 +55,7 @@ yf::Log::Rep::Rep()
     m_res_apdu = true;
     m_req_session = true;
     m_res_session = true;
+    m_init_options = false;
 }
 
 yf::Log::Log(const std::string &x) : m_p(new Rep)
@@ -73,6 +75,12 @@ void stream_write(ODR o, void *handle, int type, const char *buf, int len)
     lfile->out.write(buf, len);
 }
 
+void option_write(const char *name, void *handle)
+{
+    yf::Log::LFile *lfile = (yf::Log::LFile*) handle;
+    lfile->out << " " << name;
+}
+
 void yf::Log::process(mp::Package &package) const
 {
     Z_GDU *gdu;
@@ -93,6 +101,20 @@ void yf::Log::process(mp::Package &package) const
                              << (package.session().is_closed() ? "yes" : "no")
                              << "\n";
         }
+        if (m_p->m_init_options)
+        {
+            gdu = package.request().get();
+            if (gdu && gdu->which == Z_GDU_Z3950 &&
+                gdu->u.z3950->which == Z_APDU_initRequest)
+            {
+                m_p->m_file->out << receive_time << " " << m_p->m_msg;
+                m_p->m_file->out << " init options:";
+                yaz_init_opt_decode(gdu->u.z3950->u.initRequest->options,
+                                    option_write, m_p->m_file.get());
+                m_p->m_file->out << "\n";
+            }
+        }
+
         if (m_p->m_req_apdu)
         {
             gdu = package.request().get();
@@ -127,6 +149,19 @@ void yf::Log::process(mp::Package &package) const
                              << "duration=" << duration      
                              << "\n";
         }
+        if (m_p->m_init_options)
+        {
+            gdu = package.response().get();
+            if (gdu && gdu->which == Z_GDU_Z3950 &&
+                gdu->u.z3950->which == Z_APDU_initResponse)
+            {
+                m_p->m_file->out << receive_time << " " << m_p->m_msg;
+                m_p->m_file->out << " init options:";
+                yaz_init_opt_decode(gdu->u.z3950->u.initResponse->options,
+                                    option_write, m_p->m_file.get());
+                m_p->m_file->out << "\n";
+            }
+        }
         if (m_p->m_res_apdu)
         {
             gdu = package.response().get();
@@ -184,6 +219,11 @@ void yf::Log::configure(const xmlNode *ptr)
                     m_p->m_req_apdu = mp::xml::get_bool(attr->children, true);
                 else if (!strcmp((const char *) attr->name, "response-apdu"))
                     m_p->m_res_apdu = mp::xml::get_bool(attr->children, true);
+                else if (!strcmp((const char *) attr->name, "apdu"))
+                {
+                    m_p->m_req_apdu = mp::xml::get_bool(attr->children, true);
+                    m_p->m_res_apdu = m_p->m_req_apdu;
+                }
                 else if (!strcmp((const char *) attr->name,
                                  "request-session"))
                     m_p->m_req_session = 
@@ -192,6 +232,17 @@ void yf::Log::configure(const xmlNode *ptr)
                                  "response-session"))
                     m_p->m_res_session = 
                         mp::xml::get_bool(attr->children, true);
+                else if (!strcmp((const char *) attr->name,
+                                 "session"))
+                {
+                    m_p->m_req_session = 
+                        mp::xml::get_bool(attr->children, true);
+                    m_p->m_res_session = m_p->m_req_session;
+                }
+                else if (!strcmp((const char *) attr->name, 
+                                 "init-options"))
+                    m_p->m_init_options = 
+                        mp::xml::get_bool(attr->children, true);
                 else
                     throw mp::filter::FilterException(
                         "Bad attribute " + std::string((const char *)