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 <metaproxy/filter.hpp>
25 #include <yaz/querytowrbuf.h>
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 void yf::SD_Remove::process(mp::Package &package) const
71 Z_GDU *gdu_res = package.response().get();
72 if (gdu_res && gdu_res->which == Z_GDU_Z3950)
74 Z_NamePlusRecordList *records = 0;
75 Z_APDU *apdu = gdu_res->u.z3950;
76 if (apdu->which == Z_APDU_presentResponse)
78 Z_PresentResponse * pr_res = apdu->u.presentResponse;
79 if (pr_res->numberOfRecordsReturned
80 && *(pr_res->numberOfRecordsReturned) > 0
82 && pr_res->records->which == Z_Records_DBOSD)
84 records = pr_res->records->u.databaseOrSurDiagnostics;
87 if (apdu->which == Z_APDU_searchResponse)
89 Z_SearchResponse *sr_res = apdu->u.searchResponse;
91 sr_res->numberOfRecordsReturned
92 && *(sr_res->numberOfRecordsReturned) > 0
94 && sr_res->records->which == Z_Records_DBOSD)
96 records = sr_res->records->u.databaseOrSurDiagnostics;
101 mp::odr odr_en(ODR_ENCODE);
103 for (i = 0; i < records->num_records; i++)
105 Z_NamePlusRecord *npr = records->records[i];
106 if (npr->which == Z_NamePlusRecord_surrogateDiagnostic)
108 WRBUF w = wrbuf_alloc();
109 wrbuf_diags(w, 1, &npr->u.surrogateDiagnostic);
110 npr->which = Z_NamePlusRecord_databaseRecord;
111 npr->u.databaseRecord = z_ext_record_sutrs(odr_en,
117 package.response() = gdu_res;
123 static mp::filter::Base* filter_creator()
125 return new mp::filter::SD_Remove;
129 struct metaproxy_1_filter_struct metaproxy_1_filter_sd_remove = {
140 * c-file-style: "Stroustrup"
141 * indent-tabs-mode: nil
143 * vim: shiftwidth=4 tabstop=8 expandtab