X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Fxmlquery.c;h=d0cf454ca3d1e19a0a187ebff041c9efdb253d2a;hb=4cdc954013878a64caac253e1275a5ca80782206;hp=cb433ad74f952bff09a485fc3d30b65633afb354;hpb=8356ea58313ee1f350226172cf99bfb0b7c5583c;p=yaz-moved-to-github.git diff --git a/src/xmlquery.c b/src/xmlquery.c index cb433ad..d0cf454 100644 --- a/src/xmlquery.c +++ b/src/xmlquery.c @@ -20,8 +20,47 @@ #include #include -void yaz_query2xml_attribute_element(const Z_AttributeElement *element, - xmlNodePtr parent) +static int check_diagnostic(const xmlNode *ptr, ODR odr, + int *error_code, const char **addinfo) +{ + if (ptr && ptr->type == XML_ELEMENT_NODE && + !xmlStrcmp(ptr->name, BAD_CAST "diagnostic")) + { + struct _xmlAttr *attr; + const char *code_str = 0; + const char *addinfo_str = 0; + for (attr = ptr->properties; attr; attr = attr->next) + { + if (!xmlStrcmp(attr->name, BAD_CAST "code") && + attr->children && attr->children->type == XML_TEXT_NODE) + code_str = (const char *) attr->children->content; + else if (!xmlStrcmp(attr->name, BAD_CAST "addinfo") && + attr->children && attr->children->type == XML_TEXT_NODE) + addinfo_str = (const char *) attr->children->content; + else + { + *error_code = 1; + *addinfo = "bad attribute for diagnostic element"; + return 1; + } + } + if (!code_str) + { + *error_code = 1; + *addinfo = "missing @code for diagnostic element"; + return 1; + } + *error_code = atoi(code_str); + if (addinfo_str) + *addinfo = odr_strdup(odr, addinfo_str); + return 1; + } + else + return 0; +} + +static void yaz_query2xml_attribute_element(const Z_AttributeElement *element, + xmlNodePtr parent) { char formstr[30]; const char *setname = 0; @@ -78,8 +117,7 @@ void yaz_query2xml_attribute_element(const Z_AttributeElement *element, } -xmlNodePtr yaz_query2xml_term(const Z_Term *term, - xmlNodePtr parent) +static xmlNodePtr yaz_query2xml_term(const Z_Term *term, xmlNodePtr parent) { xmlNodePtr t = 0; xmlNodePtr node = xmlNewChild(parent, /* NS */ 0, BAD_CAST "term", 0); @@ -126,8 +164,8 @@ xmlNodePtr yaz_query2xml_term(const Z_Term *term, return node; } -xmlNodePtr yaz_query2xml_apt(const Z_AttributesPlusTerm *zapt, - xmlNodePtr parent) +static xmlNodePtr yaz_query2xml_apt(const Z_AttributesPlusTerm *zapt, + xmlNodePtr parent) { xmlNodePtr node = xmlNewChild(parent, /* NS */ 0, BAD_CAST "apt", 0); int num_attributes = zapt->attributes->num_attributes; @@ -140,7 +178,7 @@ xmlNodePtr yaz_query2xml_apt(const Z_AttributesPlusTerm *zapt, } -void yaz_query2xml_operator(Z_Operator *op, xmlNodePtr node) +static void yaz_query2xml_operator(Z_Operator *op, xmlNodePtr node) { const char *type = 0; switch(op->which) @@ -200,8 +238,8 @@ void yaz_query2xml_operator(Z_Operator *op, xmlNodePtr node) } } -xmlNodePtr yaz_query2xml_rpnstructure(const Z_RPNStructure *zs, - xmlNodePtr parent) +static xmlNodePtr yaz_query2xml_rpnstructure(const Z_RPNStructure *zs, + xmlNodePtr parent) { if (zs->which == Z_RPNStructure_complex) { @@ -226,7 +264,7 @@ xmlNodePtr yaz_query2xml_rpnstructure(const Z_RPNStructure *zs, return 0; } -xmlNodePtr yaz_query2xml_rpn(const Z_RPNQuery *rpn, xmlNodePtr parent) +static xmlNodePtr yaz_query2xml_rpn(const Z_RPNQuery *rpn, xmlNodePtr parent) { if (rpn->attributeSetId) { @@ -239,17 +277,17 @@ xmlNodePtr yaz_query2xml_rpn(const Z_RPNQuery *rpn, xmlNodePtr parent) return yaz_query2xml_rpnstructure(rpn->RPNStructure, parent); } -xmlNodePtr yaz_query2xml_ccl(const Odr_oct *ccl, xmlNodePtr node) +static xmlNodePtr yaz_query2xml_ccl(const Odr_oct *ccl, xmlNodePtr node) { return 0; } -xmlNodePtr yaz_query2xml_z3958(const Odr_oct *ccl, xmlNodePtr node) +static xmlNodePtr yaz_query2xml_z3958(const Odr_oct *ccl, xmlNodePtr node) { return 0; } -xmlNodePtr yaz_query2xml_cql(const char *cql, xmlNodePtr node) +static xmlNodePtr yaz_query2xml_cql(const char *cql, xmlNodePtr node) { return 0; } @@ -306,20 +344,21 @@ void yaz_query2xml(const Z_Query *q, xmlDocPtr *docp) } } -bool_t *boolVal(ODR odr, const char *str) +static bool_t *boolVal(ODR odr, const char *str) { if (*str == '\0' || strchr("0fF", *str)) return odr_booldup(odr, 0); return odr_booldup(odr, 1); } -Odr_int *intVal(ODR odr, const char *str) +static Odr_int *intVal(ODR odr, const char *str) { return odr_intdup(odr, atoi(str)); } -void yaz_xml2query_operator(const xmlNode *ptr, Z_Operator **op, - ODR odr, int *error_code, const char **addinfo) +static void yaz_xml2query_operator(const xmlNode *ptr, Z_Operator **op, + ODR odr, + int *error_code, const char **addinfo) { const char *type = (const char *) xmlGetProp((xmlNodePtr) ptr, BAD_CAST "type"); @@ -411,9 +450,10 @@ void yaz_xml2query_operator(const xmlNode *ptr, Z_Operator **op, } } -void yaz_xml2query_attribute_element(const xmlNode *ptr, - Z_AttributeElement **elem, ODR odr, - int *error_code, const char **addinfo) +static void yaz_xml2query_attribute_element(const xmlNode *ptr, + Z_AttributeElement **elem, ODR odr, + int *error_code, + const char **addinfo) { int i; xmlChar *set = 0; @@ -505,14 +545,13 @@ void yaz_xml2query_attribute_element(const xmlNode *ptr, } } -char *strVal(const xmlNode *ptr_cdata, ODR odr) +static char *strVal(const xmlNode *ptr_cdata, ODR odr) { return nmem_text_node_cdata(ptr_cdata, odr_getmem(odr)); } -void yaz_xml2query_term(const xmlNode *ptr, - Z_Term **term, ODR odr, - int *error_code, const char **addinfo) +static void yaz_xml2query_term(const xmlNode *ptr, Z_Term **term, ODR odr, + int *error_code, const char **addinfo) { xmlChar *type = 0; struct _xmlAttr *attr; @@ -575,9 +614,9 @@ void yaz_xml2query_term(const xmlNode *ptr, } } -void yaz_xml2query_apt(const xmlNode *ptr_apt, - Z_AttributesPlusTerm **zapt, ODR odr, - int *error_code, const char **addinfo) +static void yaz_xml2query_apt(const xmlNode *ptr_apt, + Z_AttributesPlusTerm **zapt, ODR odr, + int *error_code, const char **addinfo) { const xmlNode *ptr = ptr_apt->children; int i, num_attr = 0; @@ -619,6 +658,9 @@ void yaz_xml2query_apt(const xmlNode *ptr_apt, else break; } + if (check_diagnostic(ptr, odr, error_code, addinfo)) + return; + if (ptr && ptr->type == XML_ELEMENT_NODE) { if (!xmlStrcmp(ptr->name, BAD_CAST "term")) @@ -639,8 +681,8 @@ void yaz_xml2query_apt(const xmlNode *ptr_apt, } } -void yaz_xml2query_rset(const xmlNode *ptr, Z_ResultSetId **rset, - ODR odr, int *error_code, const char **addinfo) +static void yaz_xml2query_rset(const xmlNode *ptr, Z_ResultSetId **rset, + ODR odr, int *error_code, const char **addinfo) { if (ptr->children) { @@ -653,8 +695,9 @@ void yaz_xml2query_rset(const xmlNode *ptr, Z_ResultSetId **rset, } } -void yaz_xml2query_rpnstructure(const xmlNode *ptr, Z_RPNStructure **zs, - ODR odr, int *error_code, const char **addinfo) +static void yaz_xml2query_rpnstructure(const xmlNode *ptr, Z_RPNStructure **zs, + ODR odr, + int *error_code, const char **addinfo) { while (ptr && ptr->type != XML_ELEMENT_NODE) ptr = ptr->next; @@ -665,6 +708,9 @@ void yaz_xml2query_rpnstructure(const xmlNode *ptr, Z_RPNStructure **zs, *addinfo = "missing rpn operator, rset, apt node"; return; } + if (check_diagnostic(ptr, odr, error_code, addinfo)) + return; + *zs = (Z_RPNStructure *) odr_malloc(odr, sizeof(Z_RPNStructure)); if (!xmlStrcmp(ptr->name, BAD_CAST "operator")) { @@ -710,8 +756,8 @@ void yaz_xml2query_rpnstructure(const xmlNode *ptr, Z_RPNStructure **zs, } } -void yaz_xml2query_rpn(const xmlNode *ptr, Z_RPNQuery **query, ODR odr, - int *error_code, const char **addinfo) +static void yaz_xml2query_rpn(const xmlNode *ptr, Z_RPNQuery **query, ODR odr, + int *error_code, const char **addinfo) { const char *set = (const char *) xmlGetProp((xmlNodePtr) ptr, BAD_CAST "set"); @@ -729,6 +775,8 @@ void yaz_xml2query_rpn(const xmlNode *ptr, Z_RPNQuery **query, ODR odr, static void yaz_xml2query_(const xmlNode *ptr, Z_Query **query, ODR odr, int *error_code, const char **addinfo) { + if (check_diagnostic(ptr, odr, error_code, addinfo)) + return; if (ptr && ptr->type == XML_ELEMENT_NODE && !xmlStrcmp(ptr->name, BAD_CAST "query")) {