From a2d288bc0361884aa6e2fa953ef2766e3e1a90e7 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 10 Aug 2004 09:02:16 +0000 Subject: [PATCH] New attribute "backendtype" for syntax section which specifies record syntax to be transmitted to backend. YAZ proxy no longer transmits element set name to backend target when doing schema conversions. It just gets unset instead (it's optional). --- NEWS | 10 ++- doc/reference.xml | 9 +- etc/fennica.xml | 209 ++++++++++++++++++++++++++++++++++++++++++++++ etc/helka.xml | 207 +++++++++++++++++++++++++++++++++++++++++++++ etc/yazproxy.xsd | 3 +- include/yazproxy/proxy.h | 8 +- src/yaz-proxy-config.cpp | 20 ++++- src/yaz-proxy.cpp | 102 ++++++++++++++++++++-- 8 files changed, 553 insertions(+), 15 deletions(-) create mode 100644 etc/fennica.xml create mode 100644 etc/helka.xml diff --git a/NEWS b/NEWS index 61fa5d5..63956ac 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,12 @@ -Use YAZ_DOC macro to setup documentation. Add yaz.m4. + +New attribute "backendtype" for syntax section which specifies +record syntax to be transmitted to backend. This allows proxy to +offer a record syntax different from that offered by backend. + +YAZ proxy no longer transmits element set name to backend target when +doing schema conversions. It just gets unset instead (it's optional). + +Use YAZ_DOC macro to setup documentation. Added yaz.m4. --- 0.8 2004/04/23 diff --git a/doc/reference.xml b/doc/reference.xml index 6983679..109eb2a 100644 --- a/doc/reference.xml +++ b/doc/reference.xml @@ -434,7 +434,12 @@ If attribute marcxml is given, the proxy will perform MARC21 to MARCXML conversion. In this case the type should be XML. The proxy will use - preferred record syntax USMARC/MARC21 against the backend target. + preferred record syntax USMARC/MARC21 or backendtype + (if given) against the backend target. + + + If attribute backendtype is given, that holds the + record syntax to be transmitted to backend. If attribute stylesheet is given, the proxy @@ -691,7 +696,7 @@ + + + + + + 193.166.7.194:11390 + localhost:9999 + + + 300 + + + 180 + + + + 500000 + 500 + + + + + 200000 + 31 + 50 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MARCXML + marcxml + + + Dublin Core + dc + + + MODS v2 + mods2 + + + MODS v3 + mods3 + mods + + + + + + 0 + + + + indexdata.dk + 9000 + voyager + + + + LoC gateway + + SRW/SRU/Z39.50 Gateway to HELKA (The OPAC of the Helsinki University Libraries) + + + + + + + + + + title + title + + + subject + subject + + + creator + creator + author + + + + editor + editor + + + + publisher + publisher + + + + description + description + + + + date + date + + + + name + name + + + + isbn + isbn + + + issn + issn + + + + + + MARCXML + + + + Dublin Core + + + + MODS v2 + + + + MODS v3 + + + + + + 0 + + + pqf.properties + + + + + 500 + + + client-requests server-requests + diff --git a/etc/helka.xml b/etc/helka.xml new file mode 100644 index 0000000..3bb1a2d --- /dev/null +++ b/etc/helka.xml @@ -0,0 +1,207 @@ + + + + + + + 193.166.7.193:7590 + + + 300 + + + 180 + + + + 500000 + 500 + + + + + 200000 + 31 + 50 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + MARCXML + marcxml + + + Dublin Core + dc + + + MODS v2 + mods2 + + + MODS v3 + mods3 + mods + + + + + + 0 + + + + indexdata.dk + 9000 + voyager + + + + LoC gateway + + SRW/SRU/Z39.50 Gateway to HELKA (The OPAC of the Helsinki University Libraries) + + + + + + + + + + title + title + + + subject + subject + + + creator + creator + author + + + + editor + editor + + + + publisher + publisher + + + + description + description + + + + date + date + + + + name + name + + + + isbn + isbn + + + issn + issn + + + + + + MARCXML + + + + Dublin Core + + + + MODS v2 + + + + MODS v3 + + + + + + 0 + + + pqf.properties + + + + + 500 + + + client-requests server-requests + diff --git a/etc/yazproxy.xsd b/etc/yazproxy.xsd index 07464ef..49cbc0d 100644 --- a/etc/yazproxy.xsd +++ b/etc/yazproxy.xsd @@ -1,6 +1,6 @@ + diff --git a/include/yazproxy/proxy.h b/include/yazproxy/proxy.h index 2936c1a..9c87ab8 100644 --- a/include/yazproxy/proxy.h +++ b/include/yazproxy/proxy.h @@ -1,4 +1,4 @@ -/* $Id: proxy.h,v 1.4 2004-04-22 07:46:21 adam Exp $ +/* $Id: proxy.h,v 1.5 2004-08-10 09:02:16 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -71,7 +71,8 @@ public: int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo); int check_syntax(ODR odr, const char *name, Odr_oid *syntax, Z_RecordComposition *comp, - char **addinfo, char **stylesheet, char **schema); + char **addinfo, char **stylesheet, char **schema, + char **backend_type); char *get_explain(ODR odr, const char *name, const char *db, int *len); private: @@ -208,6 +209,9 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { Z_APDU *m_stylesheet_apdu; Z_NamePlusRecordList *m_stylesheet_nprl; char *m_schema; + char *m_backend_type; + int m_frontend_type; + void convert_to_frontend_type(Z_NamePlusRecordList *p); void convert_to_marcxml(Z_NamePlusRecordList *p); int convert_xsl(Z_NamePlusRecordList *p, Z_APDU *apdu); void convert_xsl_delay(); diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index dc5c883..772b678 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy-config.cpp,v 1.4 2004-04-22 07:46:21 adam Exp $ +/* $Id: yaz-proxy-config.cpp,v 1.5 2004-08-10 09:02:16 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -446,7 +446,8 @@ int Yaz_ProxyConfigP::check_schema(xmlNodePtr ptr, Z_RecordComposition *comp, int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, Odr_oid *syntax, Z_RecordComposition *comp, char **addinfo, - char **stylesheet, char **schema) + char **stylesheet, char **schema, + char **backend_type) { if (stylesheet) { @@ -458,6 +459,11 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, xfree (*schema); *schema = 0; } + if (backend_type) + { + xfree (*backend_type); + *backend_type = 0; + } #if HAVE_XSLT int syntax_has_matched = 0; xmlNodePtr ptr; @@ -476,6 +482,7 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, const char *match_marcxml = 0; const char *match_stylesheet = 0; const char *match_identifier = 0; + const char *match_backend_type = 0; struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) { @@ -494,6 +501,10 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, if (!strcmp((const char *) attr->name, "identifier") && attr->children && attr->children->type == XML_TEXT_NODE) match_identifier = (const char *) attr->children->content; + if (!strcmp((const char *) attr->name, "backendtype") && + attr->children && attr->children->type == XML_TEXT_NODE) + match_backend_type = (const char *) + attr->children->content; } if (match_type) { @@ -531,6 +542,11 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, xfree(*schema); *schema = xstrdup(match_identifier); } + if (backend_type && match_backend_type) + { + xfree(*backend_type); + *backend_type = xstrdup(match_backend_type); + } if (match_marcxml) { return -1; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index b246554..f319d5d 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -1,4 +1,4 @@ -/* $Id: yaz-proxy.cpp,v 1.4 2004-04-22 07:46:21 adam Exp $ +/* $Id: yaz-proxy.cpp,v 1.5 2004-08-10 09:02:16 adam Exp $ Copyright (c) 1998-2004, Index Data. This file is part of the yaz-proxy. @@ -141,6 +141,8 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable, m_s2z_stylesheet = 0; m_s2z_database = 0; m_schema = 0; + m_backend_type = 0; + m_frontend_type = 0; m_initRequest_apdu = 0; m_initRequest_mem = 0; m_initRequest_preferredMessageSize = 0; @@ -190,6 +192,7 @@ Yaz_Proxy::~Yaz_Proxy() xfree (m_time_tv); xfree (m_schema); + xfree (m_backend_type); if (m_s2z_odr_init) odr_destroy(m_s2z_odr_init); if (m_s2z_odr_search) @@ -725,6 +728,30 @@ void Yaz_Proxy::convert_xsl_delay() timeout(0); } +void Yaz_Proxy::convert_to_frontend_type(Z_NamePlusRecordList *p) +{ + if (m_frontend_type != VAL_NONE) + { + int i; + for (i = 0; i < p->num_records; i++) + { + Z_NamePlusRecord *npr = p->records[i]; + if (npr->which == Z_NamePlusRecord_databaseRecord) + { + Z_External *r = npr->u.databaseRecord; + if (r->which == Z_External_octet) + { + npr->u.databaseRecord = + z_ext_record(odr_encode(), + m_frontend_type, + (char*) r->u.octet_aligned->buf, + r->u.octet_aligned->len); + } + } + } + } +} + void Yaz_Proxy::convert_to_marcxml(Z_NamePlusRecordList *p) { int i; @@ -1062,6 +1089,8 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) { if (p && p->which == Z_Records_DBOSD) { + if (m_backend_type) + convert_to_frontend_type(p->u.databaseOrSurDiagnostics); if (m_marcxml_flag) convert_to_marcxml(p->u.databaseOrSurDiagnostics); if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu)) @@ -1100,6 +1129,8 @@ int Yaz_Proxy::send_to_client(Z_APDU *apdu) } if (p && p->which == Z_Records_DBOSD) { + if (m_backend_type) + convert_to_frontend_type(p->u.databaseOrSurDiagnostics); if (m_marcxml_flag) convert_to_marcxml(p->u.databaseOrSurDiagnostics); if (convert_xsl(p->u.databaseOrSurDiagnostics, apdu)) @@ -1208,6 +1239,12 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu) return 0; } Z_NamePlusRecordList *npr; + int oclass = 0; +#if 0 + yaz_log(LOG_LOG, "%sCache lookup %d+%d syntax=%s", + m_session_str, start, toget, yaz_z3950oid_to_str( + pr->preferredRecordSyntax, &oclass)); +#endif if (m_client->m_cache.lookup (odr_encode(), &npr, start, toget, pr->preferredRecordSyntax, pr->recordComposition)) @@ -1593,12 +1630,22 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) rc = &rc_temp; } + if (sr->preferredRecordSyntax) + { + struct oident *ent; + ent = oid_getentbyoid(sr->preferredRecordSyntax); + m_frontend_type = ent->value; + } + else + m_frontend_type = VAL_NONE; + char *stylesheet_name = 0; if (cfg) err = cfg->check_syntax(odr_encode(), m_default_target, sr->preferredRecordSyntax, rc, - &addinfo, &stylesheet_name, &m_schema); + &addinfo, &stylesheet_name, &m_schema, + &m_backend_type); if (stylesheet_name) { m_parent->low_socket_close(); @@ -1616,8 +1663,19 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) } if (err == -1) { - sr->preferredRecordSyntax = - yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, VAL_USMARC); + sr->smallSetElementSetNames = 0; + sr->mediumSetElementSetNames = 0; + if (m_backend_type) + { + + sr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, + m_backend_type); + } + else + sr->preferredRecordSyntax = + yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, + VAL_USMARC); m_marcxml_flag = 1; } else if (err) @@ -1633,6 +1691,11 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) return 0; } + else if (m_backend_type) + { + sr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, m_backend_type); + } } else if (apdu->which == Z_APDU_presentRequest) { @@ -1641,12 +1704,22 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) char *addinfo = 0; Yaz_ProxyConfig *cfg = check_reconfigure(); + if (pr->preferredRecordSyntax) + { + struct oident *ent; + ent = oid_getentbyoid(pr->preferredRecordSyntax); + m_frontend_type = ent->value; + } + else + m_frontend_type = VAL_NONE; + char *stylesheet_name = 0; if (cfg) err = cfg->check_syntax(odr_encode(), m_default_target, pr->preferredRecordSyntax, pr->recordComposition, - &addinfo, &stylesheet_name, &m_schema); + &addinfo, &stylesheet_name, &m_schema, + &m_backend_type); if (stylesheet_name) { m_parent->low_socket_close(); @@ -1664,8 +1737,18 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) } if (err == -1) { - pr->preferredRecordSyntax = - yaz_oidval_to_z3950oid(odr_decode(), CLASS_RECSYN, VAL_USMARC); + pr->recordComposition = 0; + if (m_backend_type) + { + + pr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, + m_backend_type); + } + else + pr->preferredRecordSyntax = + yaz_oidval_to_z3950oid(odr_encode(), CLASS_RECSYN, + VAL_USMARC); m_marcxml_flag = 1; } else if (err) @@ -1682,6 +1765,11 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) return 0; } + else if (m_backend_type) + { + pr->preferredRecordSyntax = + yaz_str_to_z3950oid(odr_encode(), CLASS_RECSYN, m_backend_type); + } } return apdu; } -- 1.7.10.4