added logging support for init, search , present, scan and close
authorMarc Cromme <marc@indexdata.dk>
Wed, 30 Aug 2006 08:35:47 +0000 (08:35 +0000)
committerMarc Cromme <marc@indexdata.dk>
Wed, 30 Aug 2006 08:35:47 +0000 (08:35 +0000)
src/filter_log.cpp
src/gduutil.cpp

index 95f6600..2acf956 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_log.cpp,v 1.23 2006-08-29 10:06:31 marc Exp $
+/* $Id: filter_log.cpp,v 1.24 2006-08-30 08:35:47 marc Exp $
    Copyright (c) 2005-2006, Index Data.
 
    See the LICENSE file for details
@@ -98,10 +98,10 @@ void yf::Log::process(mp::Package &package) const
         = boost::posix_time::microsec_clock::local_time();
 
 
-    std::ostringstream msg_request;
-    std::ostringstream msg_request_2;
-    std::ostringstream msg_response;
-    std::ostringstream msg_response_2;
+    //std::ostringstream msg_request;
+    //std::ostringstream msg_request_2;
+    //std::ostringstream msg_response;
+    //std::ostringstream msg_response_2;
 
     // scope for locking Ostream 
     { 
@@ -115,8 +115,8 @@ void yf::Log::process(mp::Package &package) const
             {
                 m_p->m_file->out
                     << m_p->m_msg_config << " "
-                    << package.session().id() << " "
                     << receive_time << " "
+                    << package << " "
                     << "00:00:00.000000" << " " 
                     << *gdu
                     << "\n";
@@ -179,9 +179,9 @@ void yf::Log::process(mp::Package &package) const
             {
                 m_p->m_file->out
                     << m_p->m_msg_config << " "
-                    << package.session().id() << " "
                     << send_time << " "
-                    << duration  << " "
+                    << package << " "
+                    << duration << " "
                     << *gdu
                     << "\n";
             }   
index 1f455ae..7dcd712 100644 (file)
@@ -1,8 +1,8 @@
-/* $Id: gduutil.cpp,v 1.1 2006-08-29 10:06:31 marc Exp $
+/* $Id: gduutil.cpp,v 1.2 2006-08-30 08:35:47 marc Exp $
    Copyright (c) 2005-2006, Index Data.
 
    See the LICENSE file for details
- */
+*/
 
 #include "gduutil.hpp"
 
@@ -34,41 +34,44 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
     switch(zapdu.which) {
 
     case Z_APDU_initRequest:
-        os << "initRequest" << " "
-            << "OK" << " ";
+        os << "initRequest" << " ";
                         
         {
             Z_InitRequest *ir 
                 = zapdu.u.initRequest;
-            os 
-                << (ir->implementationId) << " "
+
+            Z_IdAuthentication *a = ir->idAuthentication;
+            if (a && a->which == Z_IdAuthentication_idPass )
+                os << a->u.idPass->userId 
+                   << ":" << a->u.idPass->groupId << " ";
+            else
+                os << "-:-" << " ";
+
+
+            os << (ir->implementationId) << " "
                 //<< ir->referenceId << " "
-                << (ir->implementationName) << " "
-                << (ir->implementationVersion) << " ";
+               << (ir->implementationName) << " "
+               << (ir->implementationVersion) << " ";
+        }
+        break;
+    case Z_APDU_initResponse:
+        os << "initResponse" << " ";
+        {
+            Z_InitResponse *ir 
+                = zapdu.u.initResponse;
+            if (*(ir->result))
+                os << "OK" << " "
+                   << (ir->implementationId) << " "
+                    //<< ir->referenceId << " "
+                   << (ir->implementationName) << " "
+                   << (ir->implementationVersion) << " ";
+            else
+                os << "DIAG" << " ";
         }
         break;
-                    case Z_APDU_initResponse:
-                        os<< "initResponse" << " ";
-                        {
-                            Z_InitResponse *ir 
-                                = zapdu.u.initResponse;
-                            if (*(ir->result))
-                                os 
-                                    << "OK" << " "
-                                    << (ir->implementationId) << " "
-                                    //<< ir->referenceId << " "
-                                    << (ir->implementationName) << " "
-                                    << (ir->implementationVersion) << " ";
-                            else
-                                os 
-                                    << "ERROR" << " "
-                                    << "- - -" << " ";
-
-                         }
-                        break;
     case Z_APDU_searchRequest:
         os << "searchRequest" << " "
-            << "OK" << " ";
+           << "--" << " ";
         { 
             Z_SearchRequest *sr 
                 = zapdu.u.searchRequest;
@@ -77,9 +80,9 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
             {
                 os << sr->databaseNames[i];
                 if (i+1 ==  sr->num_databaseNames)
-                    os<< " ";
+                    os << " ";
                 else
-                    os<< "+";
+                    os << "+";
             }
                          
             WRBUF wr = wrbuf_alloc();
@@ -88,29 +91,24 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
             wrbuf_free(wr, 1);
         }
         break;
-                    case Z_APDU_searchResponse:
-                        os<< "searchResponse" << " ";
-                        {
-                            Z_SearchResponse *sr 
-                                = zapdu.u.searchResponse;
-                            if (*(sr->searchStatus))
-                                os 
-                                    << "OK" << " "
-                                    << *(sr->resultCount) << " "
-                                    //<< sr->referenceId << " "
-                                    << *(sr->numberOfRecordsReturned) << " "
-                                    << *(sr->nextResultSetPosition) << " ";
-                            else
-                                os 
-                                    << "ERROR" << " "
-                                    << "- - -" << " ";
-
-                         }
-                        //os<< wrbuf_buf(wr) << " ";
-                        break;
+    case Z_APDU_searchResponse:
+        os << "searchResponse" << " ";
+        {
+            Z_SearchResponse *sr 
+                = zapdu.u.searchResponse;
+            if (*(sr->searchStatus))
+                os << "OK" << " "
+                   << *(sr->resultCount) << " "
+                    //<< sr->referenceId << " "
+                   << *(sr->numberOfRecordsReturned) << " "
+                   << *(sr->nextResultSetPosition) << " ";
+            else
+                os << "DIAG" << " ";
+        }
+        break;
     case Z_APDU_presentRequest:
         os << "presentRequest" << " "
-            << "OK" << " "; 
+           << "--" << " "; 
         {
             Z_PresentRequest *pr = zapdu.u.presentRequest;
             os << pr->resultSetId << " "
@@ -119,97 +117,180 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
                << *(pr->numberOfRecordsRequested) << " ";
         }
         break;
-                   case Z_APDU_presentResponse:
-                        os<< "presentResponse" << " ";
-                        {
-                            Z_PresentResponse *pr 
-                                = zapdu.u.presentResponse;
-                            if (!*(pr->presentStatus))
-                                os 
-                                    << "OK" << " "
-                                    << "-" << " "
-                                    //<< pr->referenceId << " "
-                                    << *(pr->numberOfRecordsReturned) << " "
-                                    << *(pr->nextResultSetPosition) << " ";
-                            else
-                                os 
-                                    << "ERROR" << " "
-                                    << "-" << " "
-                                    //<< pr->referenceId << " "
-                                    << *(pr->numberOfRecordsReturned) << " "
-                                    << *(pr->nextResultSetPosition) << " ";
-                                    //<< "- - -" << " ";
-                         }
-                        break;
+    case Z_APDU_presentResponse:
+        os << "presentResponse" << " ";
+        {
+            Z_PresentResponse *pr 
+                = zapdu.u.presentResponse;
+            if (!*(pr->presentStatus))
+                os << "OK" << " "
+                   << "-" << " "
+                    //<< pr->referenceId << " "
+                   << *(pr->numberOfRecordsReturned) << " "
+                   << *(pr->nextResultSetPosition) << " ";
+            else
+                os << "DIAG" << " "
+                   << "-" << " "
+                    //<< pr->referenceId << " "
+                   << *(pr->numberOfRecordsReturned) << " "
+                   << *(pr->nextResultSetPosition) << " ";
+        }
+        break;
     case Z_APDU_deleteResultSetRequest:
-        os << "deleteResultSetRequest" << " "
-           << "OK" << " ";
+        os << "deleteResultSetRequest" << " ";
+        break;
+    case Z_APDU_deleteResultSetResponse:
+        os << "deleteResultSetResponse" << " ";
         break;
-                     case Z_APDU_deleteResultSetResponse:
-                        os << "deleteResultSetResponse" << " ";
-                        break;
     case Z_APDU_accessControlRequest:
-        os << "accessControlRequest" << " "
-           << "OK" << " "; 
-        break;
-                     case Z_APDU_accessControlResponse:
-                        os << "accessControlResponse" << " ";
-                        break;
-   case Z_APDU_resourceControlRequest:
-        os << "resourceControlRequest" << " "
-            << "OK" << " ";
-        break;
-                    case Z_APDU_resourceControlResponse:
-                        os << "resourceControlResponse" << " ";
-                        break;
+        os << "accessControlRequest" << " ";
+        break;
+    case Z_APDU_accessControlResponse:
+        os << "accessControlResponse" << " ";
+        break;
+    case Z_APDU_resourceControlRequest:
+        os << "resourceControlRequest" << " ";
+        break;
+    case Z_APDU_resourceControlResponse:
+        os << "resourceControlResponse" << " ";
+        break;
     case Z_APDU_triggerResourceControlRequest:
-        os << "triggerResourceControlRequest" << " "
-            << "OK" << " ";
+        os << "triggerResourceControlRequest" << " ";
         break;
     case Z_APDU_resourceReportRequest:
-        os << "resourceReportRequest" << " "
-            << "OK" << " ";
+        os << "resourceReportRequest" << " ";
         break;
-                    case Z_APDU_resourceReportResponse:
-                        os << "resourceReportResponse" << " ";
-                        break;
-     case Z_APDU_scanRequest:
+    case Z_APDU_resourceReportResponse:
+        os << "resourceReportResponse" << " ";
+        break;
+    case Z_APDU_scanRequest:
         os << "scanRequest" << " "
-            << "OK" << " ";
+           << "--" << " ";
+        { 
+            Z_ScanRequest *sr 
+                = zapdu.u.scanRequest;
+                            
+            for (int i = 0; i < sr->num_databaseNames; i++)
+            {
+                os << sr->databaseNames[i];
+                if (i+1 ==  sr->num_databaseNames)
+                    os << " ";
+                else
+                    os << "+";
+            }
+
+            os << *(sr->numberOfTermsRequested) << " "
+               << *(sr->preferredPositionInResponse) << " "
+               << *(sr->stepSize) << " ";
+                         
+            WRBUF wr = wrbuf_alloc();
+            yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, VAL_NONE);
+            os << wrbuf_buf(wr) << " ";
+            wrbuf_free(wr, 1);
+        }
+        break;
+    case Z_APDU_scanResponse:
+        os << "scanResponse" << " ";
+        {
+            Z_ScanResponse *sr 
+                = zapdu.u.scanResponse;
+            if (*(sr->scanStatus))
+                os << "OK" << " "
+                   << *(sr->scanStatus) << " "
+                   << *(sr->numberOfEntriesReturned) << " "
+                    //<< sr->referenceId << " "
+                   << *(sr->positionOfTerm) << " "
+                   << *(sr->stepSize) << " ";
+            else
+                os << "DIAG" << " "
+                   << *(sr->scanStatus) << " "
+                   << *(sr->numberOfEntriesReturned) << " "
+                    //<< sr->referenceId << " "
+                   << *(sr->positionOfTerm) << " "
+                   << *(sr->stepSize) << " ";
+        }
         break;
-                    case Z_APDU_scanResponse:
-                        os << "scanResponse" << " ";
-                        break;
     case Z_APDU_sortRequest:
-        os << "sortRequest" << " "
-            << "OK" << " ";
+        os << "sortRequest" << " ";
+        break;
+    case Z_APDU_sortResponse:
+        os << "sortResponse" << " ";
         break;
-                    case Z_APDU_sortResponse:
-                        os << "sortResponse" << " ";
-                        break;
     case Z_APDU_segmentRequest:
-        os << "segmentRequest" << " "
-            << "OK" << " ";
+        os << "segmentRequest" << " ";
         break;
     case Z_APDU_extendedServicesRequest:
-        os << "extendedServicesRequest" << " "
-            << "OK" << " ";
+        os << "extendedServicesRequest" << " ";
+//         { 
+//             Z_ExtendedServicesRequest *er 
+//                 = zapdu.u.extendedServicesRequest;
+
+//             os << er->packageName << " "
+//                << er->userId << " "
+//                << er->description << " ";
+//         }
+        break;
+    case Z_APDU_extendedServicesResponse:
+        os << "extendedServicesResponse" << " ";
+//         { 
+//             Z_ExtendedServicesResponse *er 
+//                 = zapdu.u.extendedServicesResponse;
+
+//             os << *(er->operationStatus) << " "
+//                << er->num_diagnostics << " ";
+//         }
         break;
-                    case Z_APDU_extendedServicesResponse:
-                        os << "extendedServicesResponse" << " ";
-                        break;
     case Z_APDU_close:
-        os  << "close" << " "
-            << "OK" << " ";
+        os  << "close" << " ";
+        { 
+            Z_Close  *c 
+                = zapdu.u.close;
+
+            os << *(c->closeReason) << " ";
+            switch (*(c->closeReason)) {
+            case Z_Close_finished:
+                os << "finished" << " ";
+                break;
+            case Z_Close_shutdown:
+                os << "shutdown" << " ";
+                break;
+            case Z_Close_systemProblem:
+                os << "systemProblem" << " ";
+                break;
+            case Z_Close_costLimit:
+                os << "costLimit" << " ";
+                break;
+            case Z_Close_resources:
+                os << "resources" << " ";
+                break;
+            case Z_Close_securityViolation:
+                os << "securityViolation" << " ";
+                break;
+            case Z_Close_protocolError:
+                os << "protocolError" << " ";
+                break;
+            case Z_Close_lackOfActivity:
+                os << "" << " ";
+                break;
+            case Z_Close_peerAbort:
+                os << "peerAbort" << " ";
+                break;
+            case Z_Close_unspecified:
+                os << "unspecified" << " ";
+                break;
+            default:
+                os << "unknown" << " ";
+                break;
+            }
+        }
         break;
     case Z_APDU_duplicateDetectionRequest:
-        os << "duplicateDetectionRequest" << " "
-           << "OK" << " ";
+        os << "duplicateDetectionRequest" << " ";
+        break;
+    case Z_APDU_duplicateDetectionResponse:
+        os << "duplicateDetectionResponse" << " ";
         break;
-                    case Z_APDU_duplicateDetectionResponse:
-                        os << "duplicateDetectionResponse" << " ";
-                        break;
-     default: 
+    default: 
         os << "Z_APDU "
            << "UNKNOWN" << " ";
     }