From: Adam Dickmeiss Date: Wed, 8 Oct 2003 08:15:01 +0000 (+0000) Subject: Syntax validation. Log implementation stuff X-Git-Tag: YAZPP.0.7.pre1~5 X-Git-Url: http://git.indexdata.com/?p=yazpp-moved-to-github.git;a=commitdiff_plain;h=72422e361f3ffd16766ff80bef553de08ea2f741 Syntax validation. Log implementation stuff --- diff --git a/include/yaz++/proxy.h b/include/yaz++/proxy.h index ca44ea0..8535546 100644 --- a/include/yaz++/proxy.h +++ b/include/yaz++/proxy.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: proxy.h,v 1.10 2003-10-06 08:08:49 adam Exp $ + * $Id: proxy.h,v 1.11 2003-10-08 08:15:01 adam Exp $ */ #include @@ -29,6 +29,8 @@ public: int *max_clients); void operator=(const Yaz_ProxyConfig &conf); int check_query(ODR odr, const char *name, Z_Query *query, char **addinfo); + int check_syntax(ODR odr, const char *name, + Odr_oid *syntax, char **addinfo); private: #if HAVE_XML2 xmlDocPtr m_docPtr; @@ -164,6 +166,7 @@ class YAZ_EXPORT Yaz_Proxy : public Yaz_Z_Assoc { const char *addinfo); Z_APDU *handle_query_validation(Z_APDU *apdu); + Z_APDU *handle_syntax_validation(Z_APDU *apdu); public: Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable); ~Yaz_Proxy(); diff --git a/src/config.xml b/src/config.xml index 19d0b06..cf9f8c3 100644 --- a/src/config.xml +++ b/src/config.xml @@ -3,7 +3,7 @@ - z3950.loc.gov:7094/voyager + z3950.loc.gov:7090/voyager 1 200000 @@ -11,8 +11,10 @@ 20 - 120 - 20 + 180 + 60 + + localhost:9999 @@ -23,6 +25,10 @@ 10 + + + + diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index d1ba17c..1abd49f 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy-config.cpp,v 1.4 2003-10-06 08:08:49 adam Exp $ + * $Id: yaz-proxy-config.cpp,v 1.5 2003-10-08 08:15:01 adam Exp $ */ #include @@ -326,6 +326,70 @@ int Yaz_ProxyConfig::check_query(ODR odr, const char *name, Z_Query *query, return 0; } +int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, + Odr_oid *syntax, char **addinfo) +{ +#if HAVE_XML2 + xmlNodePtr ptr; + + ptr = find_target_node(name); + if (!ptr) + return 0; + for(ptr = ptr->children; ptr; ptr = ptr->next) + { + if (ptr->type == XML_ELEMENT_NODE && + !strcmp((const char *) ptr->name, "syntax")) + { + int match = 0; // if we match record syntax + const char *match_type = 0; + const char *match_error = 0; + struct _xmlAttr *attr; + for (attr = ptr->properties; attr; attr = attr->next) + { + if (!strcmp((const char *) attr->name, "type") && + attr->children && attr->children->type == XML_TEXT_NODE) + match_type = (const char *) attr->children->content; + if (!strcmp((const char *) attr->name, "error") && + attr->children && attr->children->type == XML_TEXT_NODE) + match_error = (const char *) attr->children->content; + } + if (match_type) + { + if (!strcmp(match_type, "*")) + match = 1; + else if (!strcmp(match_type, "none")) + { + if (syntax == 0) + match = 1; + } + else if (syntax) + { + int match_oid[OID_SIZE]; + oid_name_to_oid(CLASS_RECSYN, match_type, match_oid); + if (oid_oidcmp(match_oid, syntax) == 0) + match = 1; + } + } + if (match) + { + if (match_error) + { + if (syntax) + { + char dotoid_str[100]; + oid_to_dotstring(syntax, dotoid_str); + *addinfo = odr_strdup(odr, dotoid_str); + } + return atoi(match_error); + } + return 0; + } + } + } +#endif + return 0; +} + #if HAVE_XML2 xmlNodePtr Yaz_ProxyConfig::find_target_node(const char *name) { diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 0f4678a..49992a3 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy.cpp,v 1.50 2003-10-04 06:44:16 adam Exp $ + * $Id: yaz-proxy.cpp,v 1.51 2003-10-08 08:15:01 adam Exp $ */ #include @@ -658,7 +658,7 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu) } } } - else + else // query doesn't match { delete m_client->m_last_query; m_client->m_last_query = this_query; @@ -769,13 +769,11 @@ Z_APDU *Yaz_Proxy::handle_query_validation(Z_APDU *apdu) if (err) { Z_APDU *new_apdu = create_Z_PDU(Z_APDU_searchResponse); - int *nulint = odr_intdup (odr_encode(), 0); new_apdu->u.searchResponse->referenceId = sr->referenceId; new_apdu->u.searchResponse->records = create_nonSurrogateDiagnostics(odr_encode(), err, addinfo); - new_apdu->u.searchResponse->searchStatus = nulint; - new_apdu->u.searchResponse->resultCount = nulint; + *new_apdu->u.searchResponse->searchStatus = 0; send_to_client(new_apdu); @@ -785,6 +783,59 @@ Z_APDU *Yaz_Proxy::handle_query_validation(Z_APDU *apdu) return apdu; } +Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu) +{ + if (apdu->which == Z_APDU_searchRequest) + { + Z_SearchRequest *sr = apdu->u.searchRequest; + if (*sr->smallSetUpperBound > 0 || *sr->largeSetLowerBound > 1) + { + int err; + char *addinfo = 0; + err = m_config.check_syntax(odr_encode(), m_default_target, + sr->preferredRecordSyntax, + &addinfo); + if (err) + { + Z_APDU *new_apdu = create_Z_PDU(Z_APDU_searchResponse); + + new_apdu->u.searchResponse->referenceId = sr->referenceId; + new_apdu->u.searchResponse->records = + create_nonSurrogateDiagnostics(odr_encode(), err, addinfo); + *new_apdu->u.searchResponse->searchStatus = 0; + + send_to_client(new_apdu); + + return 0; + } + } + } + else if (apdu->which == Z_APDU_presentRequest) + { + Z_PresentRequest *pr = apdu->u.presentRequest; + int err; + char *addinfo = 0; + err = m_config.check_syntax(odr_encode(), m_default_target, + pr->preferredRecordSyntax, + &addinfo); + if (err) + { + Z_APDU *new_apdu = create_Z_PDU(Z_APDU_presentResponse); + + new_apdu->u.presentResponse->referenceId = pr->referenceId; + new_apdu->u.presentResponse->records = + create_nonSurrogateDiagnostics(odr_encode(), err, addinfo); + *new_apdu->u.presentResponse->presentStatus = + Z_PresentStatus_failure; + + send_to_client(new_apdu); + + return 0; + } + } + return apdu; +} + void Yaz_Proxy::recv_Z_PDU_0(Z_APDU *apdu) { // Determine our client. @@ -798,6 +849,15 @@ void Yaz_Proxy::recv_Z_PDU_0(Z_APDU *apdu) if (apdu->which == Z_APDU_initRequest) { + if (apdu->u.initRequest->implementationId) + yaz_log(LOG_LOG, "%s implementationId: %s", + m_session_str, apdu->u.initRequest->implementationId); + if (apdu->u.initRequest->implementationName) + yaz_log(LOG_LOG, "%s implementationName: %s", + m_session_str, apdu->u.initRequest->implementationName); + if (apdu->u.initRequest->implementationVersion) + yaz_log(LOG_LOG, "%s implementationVersion: %s", + m_session_str, apdu->u.initRequest->implementationVersion); if (m_client->m_init_flag) { Z_APDU *apdu = m_client->m_initResponse; @@ -813,6 +873,9 @@ void Yaz_Proxy::recv_Z_PDU_0(Z_APDU *apdu) handle_max_record_retrieve(apdu); if (apdu) + apdu = handle_syntax_validation(apdu); + + if (apdu) apdu = handle_query_validation(apdu); if (apdu)