X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Fquerytowrbuf.c;h=3a0847ae79747d232d9ece42537027fd093507aa;hp=b686ba1ba92a3ed5ad07c607f7e19fa4bd60bf22;hb=ee6ab2ee3a9ee1a8c65d7272ec7fba1d886f5af0;hpb=2cb1374ad9b888dcb3462ec15b977fbb3a97c7cf diff --git a/src/querytowrbuf.c b/src/querytowrbuf.c index b686ba1..3a0847a 100644 --- a/src/querytowrbuf.c +++ b/src/querytowrbuf.c @@ -1,19 +1,18 @@ -/* - * Copyright (C) 1995-2005, Index Data ApS - * All rights reserved. - * - * $Id: querytowrbuf.c,v 1.1 2006-01-20 10:34:51 adam Exp $ +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2008 Index Data + * See the file LICENSE for details. */ -/** - * \file querytostr.c - * \brief Query to WRBUF (to strings) +/** \file querytowrbuf.c + \brief Query to WRBUF (to strings) */ #include #include +#include #include +#include static void yaz_term_to_wrbuf(WRBUF b, const char *term, int len) { @@ -40,14 +39,18 @@ static void yaz_attribute_element_to_wrbuf(WRBUF b, const Z_AttributeElement *element) { int i; - char *setname=""; - char *sep = ""; /* optional space after attrset name */ + char oid_name_str[OID_STR_MAX]; + const char *setname = 0; + char *sep = " "; /* optional space after attrset name */ if (element->attributeSet) { - oident *attrset; - attrset = oid_getentbyoid (element->attributeSet); - setname = attrset->desc; - sep = " "; + setname = yaz_oid_to_string_buf(element->attributeSet, + 0, oid_name_str); + } + if (!setname) + { + setname = ""; + sep = ""; } switch (element->which) { @@ -181,14 +184,13 @@ static void yaz_rpnstructure_to_wrbuf(WRBUF b, const Z_RPNStructure *zs) void yaz_rpnquery_to_wrbuf(WRBUF b, const Z_RPNQuery *rpn) { - oident *attrset; - enum oid_value ast; - - attrset = oid_getentbyoid (rpn->attributeSetId); - if (attrset) + if (rpn->attributeSetId) { - ast = attrset->value; - wrbuf_printf(b, " @attrset %s ", attrset->desc); + char oid_name_str[OID_STR_MAX]; + const char *oid_name = yaz_oid_to_string_buf(rpn->attributeSetId, + 0, oid_name_str); + if (oid_name) + wrbuf_printf(b, "@attrset %s ", oid_name); } yaz_rpnstructure_to_wrbuf(b, rpn->RPNStructure); wrbuf_chop_right(b); @@ -202,44 +204,52 @@ void yaz_query_to_wrbuf(WRBUF b, const Z_Query *q) { case Z_Query_type_1: case Z_Query_type_101: - wrbuf_printf(b,"RPN:"); + wrbuf_printf(b,"RPN "); yaz_rpnquery_to_wrbuf(b, q->u.type_1); break; case Z_Query_type_2: - wrbuf_printf(b, "CCL: %.*s", q->u.type_2->len, q->u.type_2->buf); + wrbuf_printf(b, "CCL %.*s", q->u.type_2->len, q->u.type_2->buf); break; case Z_Query_type_100: - wrbuf_printf(b, "Z39.58: %.*s", q->u.type_100->len, + wrbuf_printf(b, "Z39.58 %.*s", q->u.type_100->len, q->u.type_100->buf); break; case Z_Query_type_104: if (q->u.type_104->which == Z_External_CQL) - wrbuf_printf(b, "CQL: %s", q->u.type_104->u.cql); + wrbuf_printf(b, "CQL %s", q->u.type_104->u.cql); else - wrbuf_printf(b,"Unknown type 104 query %d", q->u.type_104->which); + wrbuf_printf(b,"UNKNOWN type 104 query %d", q->u.type_104->which); } } void yaz_scan_to_wrbuf(WRBUF b, const Z_AttributesPlusTerm *zapt, - oid_value ast) + const Odr_oid *attrbute_set) { /* should print attr set here */ + wrbuf_printf(b, "RPN "); yaz_apt_to_wrbuf(b, zapt); } -/* obsolete */ -void wrbuf_scan_term(WRBUF b, const Z_AttributesPlusTerm *zapt, oid_value ast) +void wrbuf_diags(WRBUF b, int num_diagnostics,Z_DiagRec **diags) { - yaz_apt_to_wrbuf(b, zapt); -} - -/* obsolete */ -void wrbuf_put_zquery(WRBUF b, const Z_Query *q) -{ - yaz_query_to_wrbuf(b, q); + /* we only dump the first diag - that keeps the log cleaner. */ + wrbuf_printf(b," ERROR "); + if (diags[0]->which != Z_DiagRec_defaultFormat) + wrbuf_printf(b,"(diag not in default format?)"); + else + { + Z_DefaultDiagFormat *e=diags[0]->u.defaultFormat; + if (e->condition) + wrbuf_printf(b, "%d ",*e->condition); + else + wrbuf_printf(b, "?? "); + if ((e->which==Z_DefaultDiagFormat_v2Addinfo) && (e->u.v2Addinfo)) + wrbuf_printf(b,"%s ",e->u.v2Addinfo); + else if ((e->which==Z_DefaultDiagFormat_v3Addinfo) && (e->u.v3Addinfo)) + wrbuf_printf(b,"%s ",e->u.v3Addinfo); + } } - /* * Local variables: * c-basic-offset: 4