-/* $Id: filter_backend_test.cpp,v 1.23 2007-03-08 09:38:31 adam Exp $
- Copyright (c) 2005-2007, Index Data.
+/* This file is part of Metaproxy.
+ Copyright (C) Index Data
- See the LICENSE file for details
- */
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*/
#include "config.hpp"
-#include "filter.hpp"
-#include "package.hpp"
-#include "util.hpp"
+#include <metaproxy/filter.hpp>
+#include <metaproxy/package.hpp>
+#include <metaproxy/util.hpp>
#include "filter_backend_test.hpp"
#include <stdexcept>
#include <yaz/log.h>
#include <yaz/otherinfo.h>
#include <yaz/diagbib1.h>
+#include <yaz/oid_db.h>
namespace mp = metaproxy_1;
namespace yf = mp::filter;
namespace filter {
class Session_info {
int dummy;
+ public:
+ Session_info() { dummy = 0; };
};
class BackendTest::Rep {
friend class BackendTest;
int start, int number, int &error_code, std::string &addinfo,
int *number_returned, int *next_position)
{
- oident *prefformat;
- oid_value form;
const char *element_set_name = "F"; // default to use
-
+
if (number + start - 1 > result_set_size || start < 1)
{
error_code = YAZ_BIB1_PRESENT_REQUEST_OUT_OF_RANGE;
return 0;
}
- if (!(prefformat = oid_getentbyoid(preferredRecordSyntax)))
- form = VAL_NONE;
- else
- form = prefformat->value;
- switch(form)
+ if (!preferredRecordSyntax)
+ preferredRecordSyntax = odr_oiddup(odr, yaz_oid_recsyn_usmarc);
+
+ if (preferredRecordSyntax)
{
- case VAL_NONE:
- form = VAL_USMARC;
- break;
- case VAL_USMARC:
- case VAL_TEXT_XML:
- break;
- default:
- error_code = YAZ_BIB1_RECORD_SYNTAX_UNSUPP;
- return 0;
+ if (!oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml))
+ ;
+ else if (!oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc))
+ ;
+ else
+ {
+ error_code = YAZ_BIB1_RECORD_SYNTAX_UNSUPP;
+ return 0;
+ }
}
// no element set, "B" and "F" are supported
{
if (esn->which != Z_ElementSetNames_generic)
{
- error_code
+ error_code
= YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
return 0;
}
element_set_name = esn->u.generic;
}
- if (!strcmp(element_set_name, "B") && form == VAL_USMARC)
+ if (!strcmp(element_set_name, "B")
+ && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc))
; // Brief
- else if (!strcmp(element_set_name, "F") && form == VAL_USMARC)
+ else if (!strcmp(element_set_name, "F")
+ && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_usmarc))
; // Full
- else if (!strncmp(element_set_name, "FF", 2) && form == VAL_TEXT_XML)
+ else if (!strncmp(element_set_name, "FF", 2)
+ && !oid_oidcmp(preferredRecordSyntax, yaz_oid_recsyn_xml))
; // Huge XML test record
else
{
- error_code
+ error_code
= YAZ_BIB1_SPECIFIED_ELEMENT_SET_NAME_NOT_VALID_FOR_SPECIFIED_;
addinfo = std::string(element_set_name);
return 0;
memcpy(tmp_rec, "<a>", 3);
memcpy(tmp_rec + sz - 4, "</a>", 4);
- npr->u.databaseRecord = z_ext_record(odr, VAL_TEXT_XML, tmp_rec, sz);
+ npr->u.databaseRecord = z_ext_record_xml(odr, tmp_rec, sz);
xfree(tmp_rec);
}
else
char offset_str[30];
sprintf(offset_str, "test__%09d_", i+start);
memcpy(tmp_rec+186, offset_str, strlen(offset_str));
- npr->u.databaseRecord = z_ext_record(odr, VAL_USMARC,
- tmp_rec, strlen(tmp_rec));
+ npr->u.databaseRecord = z_ext_record_usmarc(
+ odr, tmp_rec, strlen(tmp_rec));
}
}
Z_APDU *apdu_req = gdu->u.z3950;
Z_APDU *apdu_res = 0;
mp::odr odr;
-
- if (apdu_req->which != Z_APDU_initRequest &&
+
+ if (apdu_req->which != Z_APDU_initRequest &&
!m_p->m_sessions.exist(package.session()))
{
apdu_res = odr.create_close(apdu_req,
Z_InitRequest *req = apdu_req->u.initRequest;
Z_InitResponse *resp = apdu_res->u.initResponse;
- resp->implementationName = "backend_test";
+ resp->implementationName = odr_strdup(odr, "backend_test");
if (ODR_MASK_GET(req->options, Z_Options_namedResultSets))
m_p->m_support_named_result_sets = true;
-
+
int i;
static const int masks[] = {
Z_Options_search, Z_Options_present,
- Z_Options_namedResultSets, -1
+ Z_Options_namedResultSets, -1
};
for (i = 0; masks[i] != -1; i++)
if (ODR_MASK_GET(req->options, masks[i]))
else
break;
+ *resp->preferredMessageSize = *req->preferredMessageSize;
+ *resp->maximumRecordSize = *req->maximumRecordSize;
+
Session_info info;
m_p->m_sessions.create(info, package.session());
}
else if (apdu_req->which == Z_APDU_searchRequest)
{
Z_SearchRequest *req = apdu_req->u.searchRequest;
-
- if (!m_p->m_support_named_result_sets &&
+
+ if (!m_p->m_support_named_result_sets &&
strcmp(req->resultSetName, "default"))
{
- apdu_res =
+ apdu_res =
odr.create_searchResponse(
apdu_req, YAZ_BIB1_RESULT_SET_NAMING_UNSUPP, 0);
}
int next_position = 0;
int error_code = 0;
std::string addinfo;
-
- int number = 0;
- mp::util::piggyback(*req->smallSetUpperBound,
- *req->largeSetLowerBound,
- *req->mediumSetPresentNumber,
- result_set_size,
- number);
-
- if (number)
- { // not a large set for sure
+ const char *element_set_name = 0;
+
+ Odr_int number = 0;
+ mp::util::piggyback_sr(req, result_set_size,
+ number, &element_set_name);
+
+ if (number)
+ { // not a large set for sure
Z_ElementSetNames *esn;
if (number > *req->smallSetUpperBound)
esn = req->mediumSetElementSetNames;
}
if (error_code)
{
- apdu_res =
+ apdu_res =
odr.create_searchResponse(
apdu_req, error_code, addinfo.c_str());
Z_SearchResponse *resp = apdu_res->u.searchResponse;
}
else
{
- apdu_res =
+ apdu_res =
odr.create_searchResponse(apdu_req, 0, 0);
Z_SearchResponse *resp = apdu_res->u.searchResponse;
*resp->resultCount = result_set_size;
}
}
else if (apdu_req->which == Z_APDU_presentRequest)
- {
+ {
Z_PresentRequest *req = apdu_req->u.presentRequest;
int number_returned = 0;
int next_position = 0;
*resp->nextResultSetPosition = next_position;
}
}
+ else if (apdu_req->which == Z_APDU_close)
+ {
+ apdu_res = odr.create_close(apdu_req,
+ Z_Close_finished, 0);
+ package.session().close();
+ }
else
{
apdu_res = odr.create_close(apdu_req,
m_p->m_sessions.release(package.session());
}
+void mp::filter::BackendTest::configure(const xmlNode * ptr, bool test_only,
+ const char *path)
+{
+ mp::xml::check_empty(ptr);
+}
+
static mp::filter::Base* filter_creator()
{
return new mp::filter::BackendTest;
/*
* Local variables:
* c-basic-offset: 4
+ * c-file-style: "Stroustrup"
* indent-tabs-mode: nil
- * c-file-style: "stroustrup"
* End:
* vim: shiftwidth=4 tabstop=8 expandtab
*/
+