1 /* $Id: sru_util.cpp,v 1.2 2006-10-02 13:44:48 marc Exp $
2 Copyright (c) 2005-2006, Index Data.
4 See the LICENSE file for details
7 #include "sru_util.hpp"
10 //#include <yaz/wrbuf.h>
11 //#include <yaz/querytowrbuf.h>
16 namespace mp = metaproxy_1;
18 // Doxygen doesn't like mp::gdu, so we use this instead
19 namespace mp_util = metaproxy_1::util;
22 mp_util::SRU::SRU_protocol_type
23 mp_util::SRU::protocol(const Z_HTTP_Request &http_req) const
25 const std::string mime_urlencoded("application/x-www-form-urlencoded");
26 const std::string mime_text_xml("text/xml");
27 const std::string mime_soap_xml("application/soap+xml");
29 const std::string http_method(http_req.method);
30 const std::string http_type
31 = mp_util::http_header_value(http_req.headers, "Content-Type");
33 if (http_method == "GET")
36 if (http_method == "POST"
37 && http_type == mime_urlencoded)
40 if ( http_method == "POST"
41 && (http_type == mime_text_xml
42 || http_type == mime_soap_xml))
49 std::ostream& std::operator<<(std::ostream& os, Z_SRW_PDU& srw_pdu)
53 switch(srw_pdu.which) {
54 case Z_SRW_searchRetrieve_request:
55 os << " " << "searchRetrieveRequest";
57 Z_SRW_searchRetrieveRequest *sr = srw_pdu.u.request;
61 os << " " << (sr->database);
65 os << " " << *(sr->startRecord);
68 if (sr->maximumRecords)
69 os << " " << *(sr->maximumRecords);
72 if (sr->recordPacking)
73 os << " " << (sr->recordPacking);
78 os << " " << (sr->recordSchema);
82 switch (sr->query_type){
83 case Z_SRW_query_type_cql:
86 os << " " << sr->query.cql;
88 case Z_SRW_query_type_xcql:
91 case Z_SRW_query_type_pqf:
94 os << " " << sr->query.pqf;
100 case Z_SRW_searchRetrieve_response:
101 os << " " << "searchRetrieveResponse";
103 Z_SRW_searchRetrieveResponse *sr = srw_pdu.u.response;
106 if (! (sr->num_diagnostics))
109 if (sr->numberOfRecords)
110 os << " " << *(sr->numberOfRecords);
113 //if (sr->num_records)
114 os << " " << (sr->num_records);
117 if (sr->nextRecordPosition)
118 os << " " << *(sr->nextRecordPosition);
125 if (sr->diagnostics && sr->diagnostics->uri)
126 os << " " << (sr->diagnostics->uri);
129 if (sr->diagnostics && sr->diagnostics->message)
130 os << " " << (sr->diagnostics->message);
133 if (sr->diagnostics && sr->diagnostics->details)
134 os << " " << (sr->diagnostics->details);
143 case Z_SRW_explain_request:
144 os << " " << "explainRequest";
146 case Z_SRW_explain_response:
147 os << " " << "explainResponse";
149 case Z_SRW_scan_request:
150 os << " " << "scanRequest";
152 case Z_SRW_scan_response:
153 os << " " << "scanResponse";
155 case Z_SRW_update_request:
156 os << " " << "updateRequest";
158 case Z_SRW_update_response:
159 os << " " << "updateResponse";
162 os << " " << "UNKNOWN";
173 * indent-tabs-mode: nil
174 * c-file-style: "stroustrup"
176 * vim: shiftwidth=4 tabstop=8 expandtab