From 219ffa015c0e35b03fae0788b0e8e6abcfde1a81 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 13 Apr 2007 09:57:51 +0000 Subject: [PATCH] Update for YAZ 3s new OID system. --- src/filter_backend_test.cpp | 47 +++++++++++++++++++------------------- src/filter_record_transform.cpp | 17 +++++--------- src/filter_sru_to_z3950.cpp | 16 ++++++++----- src/gduutil.cpp | 15 ++++++++---- src/test_filter_z3950_client.cpp | 12 +++++++--- src/util.cpp | 35 +++++++++++++++++++--------- 6 files changed, 84 insertions(+), 58 deletions(-) diff --git a/src/filter_backend_test.cpp b/src/filter_backend_test.cpp index e025cf9..635d9eb 100644 --- a/src/filter_backend_test.cpp +++ b/src/filter_backend_test.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_backend_test.cpp,v 1.23 2007-03-08 09:38:31 adam Exp $ +/* $Id: filter_backend_test.cpp,v 1.24 2007-04-13 09:57:51 adam Exp $ Copyright (c) 2005-2007, Index Data. See the LICENSE file for details @@ -22,6 +22,7 @@ #include #include #include +#include namespace mp = metaproxy_1; namespace yf = mp::filter; @@ -91,8 +92,6 @@ Z_Records *yf::BackendTest::Rep::fetch( 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) @@ -101,21 +100,20 @@ Z_Records *yf::BackendTest::Rep::fetch( return 0; } - if (!(prefformat = oid_getentbyoid(preferredRecordSyntax))) - form = VAL_NONE; - else - form = prefformat->value; - switch(form) + const char *name_oid = OID_STR_USMARC; // default if syntax is given + 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; + name_oid = + yaz_oid_to_string(yaz_oid_std(), preferredRecordSyntax, 0); + if (name_oid && !strcmp(name_oid, OID_STR_USMARC)) + ; + else if (name_oid && !strcmp(name_oid, OID_STR_XML)) + ; + else + { + error_code = YAZ_BIB1_RECORD_SYNTAX_UNSUPP; + return 0; + } } // no element set, "B" and "F" are supported @@ -129,11 +127,14 @@ Z_Records *yf::BackendTest::Rep::fetch( } element_set_name = esn->u.generic; } - if (!strcmp(element_set_name, "B") && form == VAL_USMARC) + if (!strcmp(element_set_name, "B") + && !strcmp(name_oid, OID_STR_USMARC)) ; // Brief - else if (!strcmp(element_set_name, "F") && form == VAL_USMARC) + else if (!strcmp(element_set_name, "F") + && !strcmp(name_oid, OID_STR_USMARC)) ; // Full - else if (!strncmp(element_set_name, "FF", 2) && form == VAL_TEXT_XML) + else if (!strncmp(element_set_name, "FF", 2) + && !strcmp(name_oid, OID_STR_XML)) ; // Huge XML test record else { @@ -171,7 +172,7 @@ Z_Records *yf::BackendTest::Rep::fetch( memcpy(tmp_rec, "", 3); memcpy(tmp_rec + sz - 4, "", 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 @@ -180,8 +181,8 @@ Z_Records *yf::BackendTest::Rep::fetch( 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)); } } diff --git a/src/filter_record_transform.cpp b/src/filter_record_transform.cpp index 472ec9a..4cdfaf0 100644 --- a/src/filter_record_transform.cpp +++ b/src/filter_record_transform.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_record_transform.cpp,v 1.9 2007-03-20 07:57:54 adam Exp $ +/* $Id: filter_record_transform.cpp,v 1.10 2007-04-13 09:57:51 adam Exp $ Copyright (c) 2005-2007, Index Data. See the LICENSE file for details @@ -178,7 +178,7 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const else if (ret_code == 2) { char oidbuf[OID_STR_MAX]; - oid_to_dotstring(input_syntax, oidbuf); + oid_oid_to_dotstring(input_syntax, oidbuf); details = odr_strdup(odr_en, oidbuf); apdu = odr_en.create_presentResponse( @@ -189,16 +189,12 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const return; } - - // now re-coding the z3950 backend present request - // z3950'fy record syntax - if (backend_syntax) // TODO: this seems not to work - why ?? - pr_req->preferredRecordSyntax = backend_syntax; + if (backend_syntax) + pr_req->preferredRecordSyntax = odr_oiddup(odr_en, backend_syntax); else - pr_req->preferredRecordSyntax - = yaz_oidval_to_z3950oid(odr_en, CLASS_RECSYN, VAL_NONE); + pr_req->preferredRecordSyntax = 0; // z3950'fy record schema @@ -284,9 +280,8 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const output_record); if (ret_trans == 0) { - struct oident *ident = oid_getentbyoid(match_syntax); npr->u.databaseRecord = - z_ext_record(odr_en, ident->value, + z_ext_record_oid(odr_en, match_syntax, wrbuf_buf(output_record), wrbuf_len(output_record)); } diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 8cccea3..30be4da 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_sru_to_z3950.cpp,v 1.32 2007-03-20 07:20:16 adam Exp $ +/* $Id: filter_sru_to_z3950.cpp,v 1.33 2007-04-13 09:57:51 adam Exp $ Copyright (c) 2005-2007, Index Data. See the LICENSE file for details @@ -16,6 +16,7 @@ #include #include #include +#include #include @@ -566,8 +567,9 @@ yf::SRUtoZ3950::Impl::z3950_present_request(mp::Package &package, record_packing = Z_SRW_recordPacking_string; // RecordSyntax will always be XML - (apdu->u.presentRequest->preferredRecordSyntax) - = yaz_oidval_to_z3950oid (odr_en, CLASS_RECSYN, VAL_TEXT_XML); + apdu->u.presentRequest->preferredRecordSyntax + = yaz_string_to_oid_odr(yaz_oid_std(), CLASS_RECSYN, OID_STR_XML, + odr_en); // z3950'fy record schema if (sr_req->recordSchema) @@ -662,9 +664,11 @@ yf::SRUtoZ3950::Impl::z3950_present_request(mp::Package &package, else { Z_External *r = npr->u.databaseRecord; - oident *ent = oid_getentbyoid(r->direct_reference); - if (r->which == Z_External_octet - && ent->value == VAL_TEXT_XML) + const int *xml_oid = yaz_string_to_oid(yaz_oid_std(), + CLASS_RECSYN, + OID_STR_XML); + if (xml_oid && r->direct_reference + && !oid_oidcmp(r->direct_reference, xml_oid)) { sru_res->records[i].recordSchema = "dc"; sru_res->records[i].recordData_buf diff --git a/src/gduutil.cpp b/src/gduutil.cpp index eb7e18c..47014d6 100644 --- a/src/gduutil.cpp +++ b/src/gduutil.cpp @@ -1,4 +1,4 @@ -/* $Id: gduutil.cpp,v 1.19 2007-04-10 11:28:51 marc Exp $ +/* $Id: gduutil.cpp,v 1.20 2007-04-13 09:57:51 adam Exp $ Copyright (c) 2005-2007, Index Data. See the LICENSE file for details @@ -8,6 +8,7 @@ #include "util.hpp" #include +#include #include #include @@ -241,8 +242,13 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) else os << " -"; if (pr->preferredRecordSyntax) - //os << " " << pr->preferredRecordSyntax; - os << " " <<(oid_getentbyoid(pr->preferredRecordSyntax))->desc; + { + char oid_name_str[OID_STR_MAX]; + const char *oid_name = yaz_oid_to_string_buf( + pr->preferredRecordSyntax, 0, oid_name_str); + + os << " " << oid_name; + } else os << " -"; const char * msg = 0; @@ -343,7 +349,8 @@ std::ostream& std::operator<<(std::ostream& os, Z_APDU& zapdu) if (sr->termListAndStartPoint) { WRBUF wr = wrbuf_alloc(); - yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, VAL_NONE); + yaz_scan_to_wrbuf(wr, sr->termListAndStartPoint, + sr->attributeSet); os << wrbuf_cstr(wr); wrbuf_destroy(wr); } diff --git a/src/test_filter_z3950_client.cpp b/src/test_filter_z3950_client.cpp index addaf2c..4675f85 100644 --- a/src/test_filter_z3950_client.cpp +++ b/src/test_filter_z3950_client.cpp @@ -1,4 +1,4 @@ -/* $Id: test_filter_z3950_client.cpp,v 1.10 2007-01-25 14:05:54 adam Exp $ +/* $Id: test_filter_z3950_client.cpp,v 1.11 2007-04-13 09:57:51 adam Exp $ Copyright (c) 2005-2007, Index Data. See the LICENSE file for details @@ -20,6 +20,7 @@ #include #include +#include using namespace boost::unit_test; namespace mp = metaproxy_1; @@ -135,8 +136,13 @@ BOOST_AUTO_UNIT_TEST( test_filter_z3950_client_4 ) const char *vhost = "localhost:9999"; if (vhost) - yaz_oi_set_string_oidval(&apdu->u.initRequest->otherInfo, - odr, VAL_PROXY, 1, vhost); + { + const int *oid_proxy = yaz_string_to_oid(yaz_oid_std(), + CLASS_USERINFO, + OID_STR_PROXY); + yaz_oi_set_string_oid(&apdu->u.initRequest->otherInfo, + odr, oid_proxy, 1, vhost); + } BOOST_CHECK(apdu); pack.request() = apdu; diff --git a/src/util.cpp b/src/util.cpp index 64fd0b8..f0ea1d6 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,4 +1,4 @@ -/* $Id: util.cpp,v 1.26 2007-03-20 07:57:54 adam Exp $ +/* $Id: util.cpp,v 1.27 2007-04-13 09:57:51 adam Exp $ Copyright (c) 2005-2007, Index Data. See the LICENSE file for details @@ -10,7 +10,8 @@ #include #include #include -#include // for yaz_query_to_wrbuf() +#include +#include #include @@ -291,14 +292,17 @@ int mp_util::get_or_remove_vhost_otherinfo( std::list &vhosts) { int cat; + const int *oid_proxy = yaz_string_to_oid(yaz_oid_std(), + CLASS_USERINFO, + OID_STR_PROXY); for (cat = 1; ; cat++) { // check virtual host const char *vhost = - yaz_oi_get_string_oidval(otherInformation, - VAL_PROXY, - cat /* categoryValue */, - remove_flag /* delete flag */); + yaz_oi_get_string_oid(otherInformation, + oid_proxy, + cat /* categoryValue */, + remove_flag /* delete flag */); if (!vhost) break; vhosts.push_back(std::string(vhost)); @@ -327,10 +331,15 @@ void mp_util::set_vhost_otherinfo( { int cat; std::list::const_iterator it = vhosts.begin(); + + const int *oid_proxy = yaz_string_to_oid(yaz_oid_std(), + CLASS_USERINFO, + OID_STR_PROXY); + for (cat = 1; it != vhosts.end() ; cat++, it++) { - yaz_oi_set_string_oidval(otherInformation, odr, - VAL_PROXY, cat, it->c_str()); + yaz_oi_set_string_oid(otherInformation, odr, + oid_proxy, cat, it->c_str()); } } @@ -338,12 +347,16 @@ void mp_util::set_vhost_otherinfo( Z_OtherInformation **otherInformation, ODR odr, const std::string vhost, const int cat) { - yaz_oi_set_string_oidval(otherInformation, odr, - VAL_PROXY, cat, vhost.c_str()); + const int *oid_proxy = yaz_string_to_oid(yaz_oid_std(), + CLASS_USERINFO, + OID_STR_PROXY); + + yaz_oi_set_string_oid(otherInformation, odr, + oid_proxy, cat, vhost.c_str()); } void mp_util::split_zurl(std::string zurl, std::string &host, - std::list &db) + std::list &db) { const char *zurl_cstr = zurl.c_str(); const char *sep = strchr(zurl_cstr, '/'); -- 1.7.10.4