From: Adam Dickmeiss Date: Tue, 6 Jan 2004 21:17:42 +0000 (+0000) Subject: Handle CQL diagnostics better. Use present always for SRW-to-Z. X-Git-Tag: YAZPP.0.7.4.larry~18 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=6019cb520cb877fa162d5915f9b578609cd7074d;p=yazpp-moved-to-github.git Handle CQL diagnostics better. Use present always for SRW-to-Z. --- diff --git a/TODO b/TODO index 42735b4..4ead807 100644 --- a/TODO +++ b/TODO @@ -1,17 +1,19 @@ +Per database config. + Control the various optimizations with config.. Live status (via search, present). Possible threading. -Throw proper diagnostic for bad schema (Z39.50/SRW). - Deal with Z39.50 options properly. Deal with Z39.50 messages sizes properly. For SRW/SRU, set schema for each returned record. -Fork to ensure that crashes are catched. +Character set conversion for SRW queries. + +Throw proper CQL conversion error. diff --git a/include/yaz++/proxy.h b/include/yaz++/proxy.h index 45507f4..ebc2be8 100644 --- a/include/yaz++/proxy.h +++ b/include/yaz++/proxy.h @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: proxy.h,v 1.26 2004-01-05 11:31:04 adam Exp $ + * $Id: proxy.h,v 1.27 2004-01-06 21:17:42 adam Exp $ */ #include @@ -177,7 +177,8 @@ class YAZ_EXPORT Yaz_cql2rpn { Yaz_cql2rpn(); ~Yaz_cql2rpn(); void set_pqf_file(const char *fname); - int query_transform(const char *cql, Z_RPNQuery **rpnquery, ODR o); + int query_transform(const char *cql, Z_RPNQuery **rpnquery, ODR o, + char **addinfop); private: cql_transform_t m_transform; }; diff --git a/src/yaz-cql2rpn.cpp b/src/yaz-cql2rpn.cpp index b012d92..c142428 100644 --- a/src/yaz-cql2rpn.cpp +++ b/src/yaz-cql2rpn.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2003, Index Data. * See the file LICENSE for details. * - * $Id: yaz-cql2rpn.cpp,v 1.2 2003-12-20 22:44:30 adam Exp $ + * $Id: yaz-cql2rpn.cpp,v 1.3 2004-01-06 21:17:42 adam Exp $ */ #include @@ -27,15 +27,20 @@ void Yaz_cql2rpn::set_pqf_file(const char *fname) } int Yaz_cql2rpn::query_transform(const char *cql_query, - Z_RPNQuery **rpnquery, ODR o) + Z_RPNQuery **rpnquery, ODR o, + char **addinfop) { + const char *addinfo = 0; if (!m_transform) return -3; CQL_parser cp = cql_parser_create(); int r = cql_parser_string(cp, cql_query); if (r) + { yaz_log(LOG_LOG, "CQL Parse Error"); + r = 10; + } else { char rpn_buf[1024]; @@ -59,13 +64,15 @@ int Yaz_cql2rpn::query_transform(const char *cql_query, } else { - const char *addinfo; - cql_transform_error(m_transform, &addinfo); + r = cql_transform_error(m_transform, &addinfo); yaz_log(LOG_LOG, "CQL Transform Error %d %s", r, addinfo ? addinfo : ""); - r = -2; } } cql_parser_destroy(cp); + if (addinfo) + *addinfop = odr_strdup(o, addinfo); + else + *addinfop = 0; return r; } diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index fbcc88d..3c0e2ff 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.18 2004-01-05 09:31:09 adam Exp $ + * $Id: yaz-proxy-config.cpp,v 1.19 2004-01-06 21:17:42 adam Exp $ */ #include @@ -396,6 +396,7 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, *stylesheet = 0; } #if HAVE_XSLT + int syntax_has_matched = 0; xmlNodePtr ptr; ptr = find_target_node(name, 0); @@ -445,8 +446,10 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, } } if (match) + { + syntax_has_matched = 1; match = check_esn(ptr->children, comp); - + } if (match) { if (stylesheet && match_stylesheet) @@ -460,6 +463,8 @@ int Yaz_ProxyConfig::check_syntax(ODR odr, const char *name, } if (match_error) { + if (syntax_has_matched) // if syntax did match, schema/ESN was bad + return 25; if (syntax) { char dotoid_str[100]; diff --git a/src/yaz-proxy-main.cpp b/src/yaz-proxy-main.cpp index 06df98e..62b478f 100644 --- a/src/yaz-proxy-main.cpp +++ b/src/yaz-proxy-main.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy-main.cpp,v 1.27 2004-01-05 11:31:04 adam Exp $ + * $Id: yaz-proxy-main.cpp,v 1.28 2004-01-06 21:17:42 adam Exp $ */ #include @@ -109,7 +109,6 @@ int args(Yaz_Proxy *proxy, int argc, char **argv) } if (addr) { - yaz_log(LOG_LOG, "0 Starting proxy " VERSION ); if (proxy->server(addr)) { yaz_log(LOG_FATAL|LOG_ERRNO, "listen %s", addr); @@ -133,9 +132,11 @@ static void sighup_handler(int num) } -static void child_run(Yaz_SocketManager *m) +static void child_run(Yaz_SocketManager *m, int run) { - yaz_log(LOG_LOG, "0 proxy pid=%ld", (long) getpid()); + signal(SIGHUP, sighup_handler); + + yaz_log(LOG_LOG, "0 proxy run=%d pid=%ld", run, (long) getpid()); if (pid_fname) { FILE *f = fopen(pid_fname, "w"); @@ -180,19 +181,19 @@ static void child_run(Yaz_SocketManager *m) int main(int argc, char **argv) { int cont = 1; + int run = 1; static int mk_pid = 0; Yaz_SocketManager mySocketManager; Yaz_Proxy proxy(new Yaz_PDU_Assoc(&mySocketManager)); static_yaz_proxy = &proxy; - signal(SIGHUP, sighup_handler); args(&proxy, argc, argv); if (debug) { - child_run(&mySocketManager); + child_run(&mySocketManager, run); exit(0); } while (cont) @@ -205,11 +206,14 @@ int main(int argc, char **argv) } else if (p == 0) { - child_run(&mySocketManager); + child_run(&mySocketManager, run); } pid_t p1; int status; p1 = wait(&status); + + yaz_log_reopen(); + if (p1 != p) { yaz_log(LOG_FATAL, "p1=%d != p=%d", p1, p); @@ -250,6 +254,7 @@ int main(int argc, char **argv) } if (cont) sleep(1); + run++; } exit (0); return 0; diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index 7da3e15..1ef2f5a 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -2,7 +2,7 @@ * Copyright (c) 1998-2004, Index Data. * See the file LICENSE for details. * - * $Id: yaz-proxy.cpp,v 1.76 2004-01-05 11:31:04 adam Exp $ + * $Id: yaz-proxy.cpp,v 1.77 2004-01-06 21:17:42 adam Exp $ */ #include @@ -1360,16 +1360,32 @@ Z_APDU *Yaz_Proxy::handle_query_transformation(Z_APDU *apdu) { Z_RPNQuery *rpnquery = 0; Z_SearchRequest *sr = apdu->u.searchRequest; + char *addinfo = 0; yaz_log(LOG_LOG, "%sCQL: %s", m_session_str, sr->query->u.type_104->u.cql); int r = m_cql2rpn.query_transform(sr->query->u.type_104->u.cql, - &rpnquery, odr_encode()); + &rpnquery, odr_encode(), + &addinfo); if (r == -3) yaz_log(LOG_LOG, "%sNo CQL to RPN table", m_session_str); else if (r) + { yaz_log(LOG_LOG, "%sCQL Conversion error %d", m_session_str, r); + 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(), + yaz_diag_srw_to_bib1(r), + addinfo); + *new_apdu->u.searchResponse->searchStatus = 0; + + send_to_client(new_apdu); + + return 0; + } else { sr->query->which = Z_Query_type_1; @@ -1631,7 +1647,9 @@ void Yaz_Proxy::handle_incoming_HTTP(Z_HTTP_Request *hreq) start = *srw_req->startRecord; if (max > 0) { - if (start <= 1) // Z39.50 piggyback + // Some backend, such as Voyager doesn't honor piggyback + // So we use present always (0 &&). + if (0 && start <= 1) // Z39.50 piggyback { *z_searchRequest->smallSetUpperBound = max; *z_searchRequest->mediumSetPresentNumber = max; @@ -2248,7 +2266,7 @@ int Yaz_Proxy::server(const char *addr) int r = Yaz_Z_Assoc::server(addr); if (!r) { - yaz_log(LOG_LOG, "%sStarted listener on %s", m_session_str, addr); + yaz_log(LOG_LOG, "%sStarted proxy " VERSION " on %s", m_session_str, addr); timeout(1); } return r;