X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fzoom-c.c;h=cd13a010f568eb60c6c1fe2eb9b2ba8d34316707;hb=67945ae14416eb099fec28978f286ebba7f5313f;hp=41456e090f6d624ed3b3b9bf1d3cea2a52da72e9;hpb=67b4d800264ba7dd4c8b64719cbbc87464d3430f;p=yaz-moved-to-github.git diff --git a/src/zoom-c.c b/src/zoom-c.c index 41456e0..cd13a01 100644 --- a/src/zoom-c.c +++ b/src/zoom-c.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2005, Index Data ApS * See the file LICENSE for details. * - * $Id: zoom-c.c,v 1.59 2005-12-21 00:06:34 mike Exp $ + * $Id: zoom-c.c,v 1.62 2005-12-21 16:41:36 mike Exp $ */ /** * \file zoom-c.c @@ -167,7 +167,13 @@ static void set_ZOOM_error (ZOOM_connection c, int error, static void clear_error (ZOOM_connection c) { - + /* + * If an error is tied to an operation then it's ok to clear: for + * example, a diagnostic returned from a search is cleared by a + * subsequent search. However, problems such as Connection Lost + * or Init Refused are not cleared, because they are not + * recoverable: doing another search doesn't help. + */ switch (c->error) { case ZOOM_ERROR_CONNECT: @@ -524,6 +530,31 @@ ZOOM_query_cql(ZOOM_query s, const char *str) return 0; } +/* + * Translate the CQL string client-side into RPN which is passed to + * the server. This is useful for server's that don't themselves + * support CQL, for which ZOOM_query_cql() is useless. `conn' is used + * only as a place to stash diagnostics if compilation fails; if this + * information is not needed, a null pointer may be used. + */ +ZOOM_API(int) +ZOOM_query_cql2rpn(ZOOM_query s, const char *str, ZOOM_connection conn) +{ + char *rpn; + int ret; + + yaz_log(log_details, "%p ZOOM_query_cql2rpn str=%s conn=%p", s, str, conn); + if (conn == 0) + conn = ZOOM_connection_create(0); + + if ((rpn = cql2pqf(conn, str)) == 0) + return -1; + + ret = ZOOM_query_prefix(s, rpn); + xfree(rpn); + return ret; +} + ZOOM_API(int) ZOOM_query_sortby(ZOOM_query s, const char *criteria) { @@ -1098,7 +1129,7 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c) ZOOM_options_get(c->options, "implementationName"), odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName)); - version = odr_strdup(c->odr_out, "$Revision: 1.59 $"); + version = odr_strdup(c->odr_out, "$Revision: 1.62 $"); if (strlen(version) > 10) /* check for unexpanded CVS strings */ version[strlen(version)-2] = '\0'; ireq->implementationVersion = odr_prepend(c->odr_out, @@ -4020,7 +4051,6 @@ static char *cql2pqf(ZOOM_connection c, const char *cql) char pqfbuf[512]; parser = cql_parser_create(); - /*printf("*** got CQL parser %p\n", parser);*/ if ((error = cql_parser_string(parser, cql)) != 0) { cql_parser_destroy(parser); set_ZOOM_error(c, ZOOM_ERROR_CQL_PARSE, cql); @@ -4028,21 +4058,15 @@ static char *cql2pqf(ZOOM_connection c, const char *cql) } node = cql_parser_result(parser); - /*printf("*** got CQL node %p\n", node);*/ /* ### Do not call cql_parser_destroy() yet: it destroys `node'! */ cqlfile = ZOOM_connection_option_get(c, "cqlfile"); - /*printf("*** cqlfile is %p\n", cqlfile);*/ if (cqlfile == 0) { - /*printf("*** cqlfile is null\n");*/ cql_parser_destroy(parser); cql_node_destroy(node); - /*printf("*** destroyed node\n");*/ set_ZOOM_error(c, ZOOM_ERROR_CQL_TRANSFORM, "no CQL transform file"); - /*printf("*** set ZOOM_error\n");*/ return 0; } - /*printf("*** got CQL file %s\n", cqlfile);*/ if ((trans = cql_transform_open_fname(cqlfile)) == 0) { char buf[512]; @@ -4054,11 +4078,8 @@ static char *cql2pqf(ZOOM_connection c, const char *cql) return 0; } - /*printf("*** got trans %p\n", trans);*/ error = cql_transform_buf(trans, node, pqfbuf, sizeof pqfbuf); cql_parser_destroy(parser); - /*printf("*** destroyed parser\n");*/ - /*printf("*** got cql_transform_buf() retval %d\n", error);*/ cql_node_destroy(node); if (error != 0) { char buf[512]; @@ -4071,11 +4092,7 @@ static char *cql2pqf(ZOOM_connection c, const char *cql) } cql_transform_close(trans); - { - char *s = xstrdup(pqfbuf); - /*printf("*** translated '%s' to '%s'\n", cql, s);*/ - return s; - } + return xstrdup(pqfbuf); }