factoring SRU helper utilities into seperate files
authorMarc Cromme <marc@indexdata.dk>
Tue, 26 Sep 2006 13:15:33 +0000 (13:15 +0000)
committerMarc Cromme <marc@indexdata.dk>
Tue, 26 Sep 2006 13:15:33 +0000 (13:15 +0000)
src/filter_sru_to_z3950.cpp
src/gduutil.cpp
src/gduutil.hpp
src/sru_util.cpp [new file with mode: 0644]
src/sru_util.hpp [new file with mode: 0644]

index 68a086b..2d7bcb9 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: filter_sru_to_z3950.cpp,v 1.13 2006-09-26 11:37:08 marc Exp $
+/* $Id: filter_sru_to_z3950.cpp,v 1.14 2006-09-26 13:15:33 marc Exp $
    Copyright (c) 2005-2006, Index Data.
 
    See the LICENSE file for details
@@ -9,6 +9,7 @@
 #include "package.hpp"
 #include "util.hpp"
 #include "gduutil.hpp"
+#include "sru_util.hpp"
 #include "filter_sru_to_z3950.hpp"
 
 #include <yaz/zgdu.h>
index 5b48e6e..373918f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gduutil.cpp,v 1.12 2006-09-22 14:13:03 marc Exp $
+/* $Id: gduutil.cpp,v 1.13 2006-09-26 13:15:33 marc Exp $
    Copyright (c) 2005-2006, Index Data.
 
    See the LICENSE file for details
@@ -557,189 +557,6 @@ std::ostream& std::operator<<(std::ostream& os,  Z_APDU& zapdu)
 }
 
 
-std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) 
-{
-    os << "SRU";
-    
-    switch(srw_pdu.which) {
-    case  Z_SRW_searchRetrieve_request:
-        os << " " << "searchRetrieveRequest";
-        {
-            Z_SRW_searchRetrieveRequest *sr = srw_pdu.u.request;
-            if (sr)
-            {
-                if (sr->database)
-                    os << " " << (sr->database);
-                else
-                    os << " -";
-                if (sr->startRecord)
-                    os << " " << *(sr->startRecord);
-                else
-                    os << " -";
-                if (sr->maximumRecords)
-                    os << " " << *(sr->maximumRecords);
-                else
-                    os << " -";
-                if (sr->recordPacking)
-                    os << " " << (sr->recordPacking);
-                else
-                    os << " -";
-
-                if (sr->recordSchema)
-                    os << " " << (sr->recordSchema);
-                else
-                    os << " -";
-                
-                switch (sr->query_type){
-                case Z_SRW_query_type_cql:
-                    os << " CQL";
-                    if (sr->query.cql)
-                        os << " " << sr->query.cql;
-                    break;
-                case Z_SRW_query_type_xcql:
-                    os << " XCQL";
-                    break;
-                case Z_SRW_query_type_pqf:
-                    os << " PQF";
-                    if (sr->query.pqf)
-                        os << " " << sr->query.pqf;
-                    break;
-                }
-            }
-        }
-        break;
-    case  Z_SRW_searchRetrieve_response:
-        os << " " << "searchRetrieveResponse";
-        {
-            Z_SRW_searchRetrieveResponse *sr = srw_pdu.u.response;
-            if (sr)
-            {
-                if (! (sr->num_diagnostics))
-                {
-                    os << " OK";
-                    if (sr->numberOfRecords)
-                        os << " " << *(sr->numberOfRecords);
-                    else
-                        os << " -";
-                    //if (sr->num_records)
-                    os << " " << (sr->num_records);
-                    //else
-                    //os << " -";
-                    if (sr->nextRecordPosition)
-                        os << " " << *(sr->nextRecordPosition);
-                    else
-                        os << " -";
-                } 
-                else
-                {
-                    os << " DIAG";
-                    if (sr->diagnostics && sr->diagnostics->uri)
-                        os << " " << (sr->diagnostics->uri);
-                    else
-                        os << " -";
-                    if (sr->diagnostics && sr->diagnostics->message)
-                        os << " " << (sr->diagnostics->message);
-                    else
-                        os << " -";
-                    if (sr->diagnostics && sr->diagnostics->details)
-                        os << " " << (sr->diagnostics->details);
-                    else
-                        os << " -";
-                }
-                
-                    
-            }
-        }
-        break;
-    case  Z_SRW_explain_request:
-        os << " " << "explainRequest";
-        break;
-    case  Z_SRW_explain_response:
-        os << " " << "explainResponse";
-        break;
-    case  Z_SRW_scan_request:
-        os << " " << "scanRequest";
-        break;
-    case  Z_SRW_scan_response:
-        os << " " << "scanResponse";
-        break;
-    case  Z_SRW_update_request:
-        os << " " << "updateRequest";
-        break;
-    case  Z_SRW_update_response:
-        os << " " << "updateResponse";
-        break;
-    default: 
-        os << " " << "UNKNOWN";    
-    }
-
-    return os;    
-}
-
-    
-//         {
-//             Z_InitRequest *ir 
-//                 = zapdu.u.initRequest;
-
-//             Z_IdAuthentication *a = ir->idAuthentication;
-//             if (a && a->which == Z_IdAuthentication_idPass )
-//                 os << a->u.idPass->userId << " ";
-//             //<< ":" << a->u.idPass->groupId << " ";
-//             else
-//                 os << "-" << " ";
-
-//             std::list<std::string> vhosts;
-//             mp::util::get_vhost_otherinfo(ir->otherInfo, vhosts);
-//             if (vhosts.size()){
-//                 copy(vhosts.begin(), vhosts.end(), 
-//                      ostream_iterator<string>(os, " "));
-//             }
-//                 else
-//                     os << "-" << " " ;
-
-//             os << (ir->implementationId) << " "
-//                 //<< ir->referenceId << " "
-//                << (ir->implementationName) << " "
-//                << (ir->implementationVersion);
-//         }
-//         break;
-//     case Z_APDU_initResponse:
-//         os << " " << "initResponse" << " ";
-//         {
-//             Z_InitResponse *ir 
-//                 = zapdu.u.initResponse;
-//             if (ir->result && *(ir->result))
-//                 os << "OK" << " "
-//                    << (ir->implementationId) << " "
-//                     //<< ir->referenceId << " "
-//                    << (ir->implementationName) << " "
-//                    << (ir->implementationVersion) << " ";
-//             else
-//                 os << "DIAG";
-//         }
-//         break;
-//     case Z_APDU_searchRequest:
-//         os << " " << "searchRequest" << " ";
-//         { 
-//             Z_SearchRequest *sr 
-//                 = zapdu.u.searchRequest;
-                            
-//             for (int i = 0; i < sr->num_databaseNames; i++)
-//             {
-//                 os << sr->databaseNames[i];
-//                 if (i+1 ==  sr->num_databaseNames)
-//                     os << " ";
-//                 else
-//                     os << "+";
-//             }
-                         
-//             WRBUF wr = wrbuf_alloc();
-//             yaz_query_to_wrbuf(wr, sr->query);
-//             os << wrbuf_buf(wr);
-//             wrbuf_free(wr, 1);
-//         }
-//         break;
-
 
 
 /*
index f097ca6..d79f510 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gduutil.hpp,v 1.3 2006-09-19 13:50:17 marc Exp $
+/* $Id: gduutil.hpp,v 1.4 2006-09-26 13:15:33 marc Exp $
    Copyright (c) 2005-2006, Index Data.
 
    See the LICENSE file for details
@@ -9,7 +9,7 @@
 
 #include <yaz/zgdu.h>
 #include <yaz/z-core.h>
-#include <yaz/srw.h>
+//#include <yaz/srw.h>
 
 #include <iosfwd>
 
@@ -17,7 +17,6 @@ namespace std
 {
     std::ostream& operator<<(std::ostream& os, Z_GDU& zgdu);
     std::ostream& operator<<(std::ostream& os, Z_APDU& zapdu); 
-    std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu); 
     std::ostream& operator<<(std::ostream& os, Z_HTTP_Request& httpreq);
     std::ostream& operator<<(std::ostream& os, Z_HTTP_Response& httpres);
     std::ostream& operator<<(std::ostream& os, Z_Records & rs);
diff --git a/src/sru_util.cpp b/src/sru_util.cpp
new file mode 100644 (file)
index 0000000..c84c918
--- /dev/null
@@ -0,0 +1,150 @@
+/* $Id: sru_util.cpp,v 1.1 2006-09-26 13:15:33 marc Exp $
+   Copyright (c) 2005-2006, Index Data.
+
+   See the LICENSE file for details
+*/
+
+#include "sru_util.hpp"
+//#include "util.hpp"
+
+//#include <yaz/wrbuf.h>
+//#include <yaz/querytowrbuf.h>
+
+#include <iostream>
+//#include <list>
+
+namespace mp = metaproxy_1;
+
+// Doxygen doesn't like mp::gdu, so we use this instead
+namespace mp_sru = metaproxy_1::sru;
+
+
+std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu) 
+{
+    os << "SRU";
+    
+    switch(srw_pdu.which) {
+    case  Z_SRW_searchRetrieve_request:
+        os << " " << "searchRetrieveRequest";
+        {
+            Z_SRW_searchRetrieveRequest *sr = srw_pdu.u.request;
+            if (sr)
+            {
+                if (sr->database)
+                    os << " " << (sr->database);
+                else
+                    os << " -";
+                if (sr->startRecord)
+                    os << " " << *(sr->startRecord);
+                else
+                    os << " -";
+                if (sr->maximumRecords)
+                    os << " " << *(sr->maximumRecords);
+                else
+                    os << " -";
+                if (sr->recordPacking)
+                    os << " " << (sr->recordPacking);
+                else
+                    os << " -";
+
+                if (sr->recordSchema)
+                    os << " " << (sr->recordSchema);
+                else
+                    os << " -";
+                
+                switch (sr->query_type){
+                case Z_SRW_query_type_cql:
+                    os << " CQL";
+                    if (sr->query.cql)
+                        os << " " << sr->query.cql;
+                    break;
+                case Z_SRW_query_type_xcql:
+                    os << " XCQL";
+                    break;
+                case Z_SRW_query_type_pqf:
+                    os << " PQF";
+                    if (sr->query.pqf)
+                        os << " " << sr->query.pqf;
+                    break;
+                }
+            }
+        }
+        break;
+    case  Z_SRW_searchRetrieve_response:
+        os << " " << "searchRetrieveResponse";
+        {
+            Z_SRW_searchRetrieveResponse *sr = srw_pdu.u.response;
+            if (sr)
+            {
+                if (! (sr->num_diagnostics))
+                {
+                    os << " OK";
+                    if (sr->numberOfRecords)
+                        os << " " << *(sr->numberOfRecords);
+                    else
+                        os << " -";
+                    //if (sr->num_records)
+                    os << " " << (sr->num_records);
+                    //else
+                    //os << " -";
+                    if (sr->nextRecordPosition)
+                        os << " " << *(sr->nextRecordPosition);
+                    else
+                        os << " -";
+                } 
+                else
+                {
+                    os << " DIAG";
+                    if (sr->diagnostics && sr->diagnostics->uri)
+                        os << " " << (sr->diagnostics->uri);
+                    else
+                        os << " -";
+                    if (sr->diagnostics && sr->diagnostics->message)
+                        os << " " << (sr->diagnostics->message);
+                    else
+                        os << " -";
+                    if (sr->diagnostics && sr->diagnostics->details)
+                        os << " " << (sr->diagnostics->details);
+                    else
+                        os << " -";
+                }
+                
+                    
+            }
+        }
+        break;
+    case  Z_SRW_explain_request:
+        os << " " << "explainRequest";
+        break;
+    case  Z_SRW_explain_response:
+        os << " " << "explainResponse";
+        break;
+    case  Z_SRW_scan_request:
+        os << " " << "scanRequest";
+        break;
+    case  Z_SRW_scan_response:
+        os << " " << "scanResponse";
+        break;
+    case  Z_SRW_update_request:
+        os << " " << "updateRequest";
+        break;
+    case  Z_SRW_update_response:
+        os << " " << "updateResponse";
+        break;
+    default: 
+        os << " " << "UNKNOWN";    
+    }
+
+    return os;    
+}
+
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
diff --git a/src/sru_util.hpp b/src/sru_util.hpp
new file mode 100644 (file)
index 0000000..fd9ef5a
--- /dev/null
@@ -0,0 +1,37 @@
+/* $Id: sru_util.hpp,v 1.1 2006-09-26 13:15:33 marc Exp $
+   Copyright (c) 2005-2006, Index Data.
+
+   See the LICENSE file for details
+ */
+
+#ifndef YP2_SDU_UTIL_HPP
+#define YP2_SDU_UTIL_HPP
+
+//#include <yaz/zgdu.h>
+//#include <yaz/z-core.h>
+#include <yaz/srw.h>
+
+#include <iosfwd>
+
+namespace std 
+{
+    std::ostream& operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu); 
+
+}
+
+
+namespace metaproxy_1 {
+    namespace sru  {
+
+    }    
+}
+
+#endif
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * c-file-style: "stroustrup"
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */