1 /* This file is part of Metaproxy.
2 Copyright (C) 2005-2013 Index Data
4 Metaproxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "filter_sd_remove.hpp"
21 #include <metaproxy/package.hpp>
22 #include <metaproxy/util.hpp>
24 #include <yaz/diagbib1.h>
25 #include <metaproxy/filter.hpp>
27 namespace metaproxy_1 {
29 class SD_Remove : public Base {
33 void process(metaproxy_1::Package & package) const;
34 void configure(const xmlNode * ptr, bool test_only,
40 namespace mp = metaproxy_1;
41 namespace yf = mp::filter;
43 yf::SD_Remove::SD_Remove()
47 yf::SD_Remove::~SD_Remove()
51 void yf::SD_Remove::configure(const xmlNode *xmlnode, bool test_only,
57 for (ptr = xmlnode->children; ptr; ptr = ptr->next)
59 if (ptr->type == XML_ELEMENT_NODE)
60 throw mp::filter::FilterException("Bad element "
61 + std::string((const char *)
67 static void diagrec_to_sutrs(WRBUF b, Z_DiagRec *diag)
69 wrbuf_puts(b," ERROR ");
70 if (diag->which != Z_DiagRec_defaultFormat)
71 wrbuf_puts(b, "diag not in default format");
74 Z_DefaultDiagFormat *e = diag->u.defaultFormat;
75 wrbuf_printf(b, ODR_INT_PRINTF ": %s", *e->condition,
76 diagbib1_str(*e->condition));
77 if (e->u.v2Addinfo && *e->u.v2Addinfo) // v3Addinfo is same data
79 wrbuf_puts(b, " -- ");
80 wrbuf_puts(b, e->u.v2Addinfo);
86 void yf::SD_Remove::process(mp::Package &package) const
90 Z_GDU *gdu_res = package.response().get();
91 if (gdu_res && gdu_res->which == Z_GDU_Z3950)
93 Z_NamePlusRecordList *records = 0;
94 Z_APDU *apdu = gdu_res->u.z3950;
95 if (apdu->which == Z_APDU_presentResponse)
97 Z_PresentResponse * pr_res = apdu->u.presentResponse;
98 if (pr_res->numberOfRecordsReturned
99 && *(pr_res->numberOfRecordsReturned) > 0
101 && pr_res->records->which == Z_Records_DBOSD)
103 records = pr_res->records->u.databaseOrSurDiagnostics;
106 if (apdu->which == Z_APDU_searchResponse)
108 Z_SearchResponse *sr_res = apdu->u.searchResponse;
110 sr_res->numberOfRecordsReturned
111 && *(sr_res->numberOfRecordsReturned) > 0
113 && sr_res->records->which == Z_Records_DBOSD)
115 records = sr_res->records->u.databaseOrSurDiagnostics;
120 mp::odr odr_en(ODR_ENCODE);
122 for (i = 0; i < records->num_records; i++)
124 Z_NamePlusRecord *npr = records->records[i];
125 if (npr->which == Z_NamePlusRecord_surrogateDiagnostic)
127 WRBUF w = wrbuf_alloc();
128 diagrec_to_sutrs(w, npr->u.surrogateDiagnostic);
129 npr->which = Z_NamePlusRecord_databaseRecord;
130 npr->u.databaseRecord = z_ext_record_sutrs(odr_en,
136 package.response() = gdu_res;
142 static mp::filter::Base* filter_creator()
144 return new mp::filter::SD_Remove;
148 struct metaproxy_1_filter_struct metaproxy_1_filter_sd_remove = {
159 * c-file-style: "Stroustrup"
160 * indent-tabs-mode: nil
162 * vim: shiftwidth=4 tabstop=8 expandtab