X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fsrw.c;h=c962922b9fb178589c39bab7db4695362e5e5b3b;hb=47db800079d3df8e8adfd93b466795d0803dabe8;hp=54aa7ba24372bc5029de7600e822467db2ecfd36;hpb=3f36e04a60f21ed11fbb7bdb32923cffcb519f2f;p=yaz-moved-to-github.git diff --git a/src/srw.c b/src/srw.c index 54aa7ba..c962922 100644 --- a/src/srw.c +++ b/src/srw.c @@ -1,8 +1,6 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2009 Index Data * See the file LICENSE for details. - * - * $Id: srw.c,v 1.57 2007-08-23 14:23:23 adam Exp $ */ /** * \file srw.c @@ -439,54 +437,86 @@ static int yaz_srw_versions(ODR o, xmlNodePtr pptr, return 0; } -static int yaz_srw_diagnostics(ODR o, xmlNodePtr pptr, Z_SRW_diagnostic **recs, - int *num, void *client_data, const char *ns) + +static int yaz_srw_decode_diagnostics(ODR o, xmlNodePtr pptr, + Z_SRW_diagnostic **recs, int *num, + void *client_data, const char *ns) + { - if (o->direction == ODR_DECODE) + int i; + xmlNodePtr ptr; + *num = 0; + for (ptr = pptr; ptr; ptr = ptr->next) { - int i; - xmlNodePtr ptr; - *num = 0; - for (ptr = pptr->children; ptr; ptr = ptr->next) - { if (ptr->type == XML_ELEMENT_NODE && !xmlStrcmp(ptr->name, BAD_CAST "diagnostic")) (*num)++; - } - if (!*num) - return 1; - *recs = (Z_SRW_diagnostic *) odr_malloc(o, *num * sizeof(**recs)); - for (i = 0; i < *num; i++) + } + if (!*num) + return 1; + *recs = (Z_SRW_diagnostic *) odr_malloc(o, *num * sizeof(**recs)); + for (i = 0; i < *num; i++) { (*recs)[i].uri = 0; (*recs)[i].details = 0; (*recs)[i].message = 0; } - for (i = 0, ptr = pptr->children; ptr; ptr = ptr->next) + for (i = 0, ptr = pptr; ptr; ptr = ptr->next) + { + if (ptr->type == XML_ELEMENT_NODE && + !xmlStrcmp(ptr->name, BAD_CAST "diagnostic")) { - if (ptr->type == XML_ELEMENT_NODE && - !xmlStrcmp(ptr->name, BAD_CAST "diagnostic")) + xmlNodePtr rptr; + (*recs)[i].uri = 0; + (*recs)[i].details = 0; + (*recs)[i].message = 0; + for (rptr = ptr->children; rptr; rptr = rptr->next) { - xmlNodePtr rptr; - (*recs)[i].uri = 0; - (*recs)[i].details = 0; - (*recs)[i].message = 0; - for (rptr = ptr->children; rptr; rptr = rptr->next) - { - if (match_xsd_string(rptr, "uri", o, - &(*recs)[i].uri)) - ; - else if (match_xsd_string(rptr, "details", o, - &(*recs)[i].details)) - ; - else if (match_xsd_string(rptr, "message", o, - &(*recs)[i].message)) - ; - } - i++; + if (match_xsd_string(rptr, "uri", o, + &(*recs)[i].uri)) + ; + else if (match_xsd_string(rptr, "details", o, + &(*recs)[i].details)) + ; + else if (match_xsd_string(rptr, "message", o, + &(*recs)[i].message)) + ; } + i++; } } + return 0; +} + +int sru_decode_surrogate_diagnostics(const char *buf, size_t len, + Z_SRW_diagnostic **diag, + int *num, ODR odr) +{ + int ret = 0; + xmlDocPtr doc = xmlParseMemory(buf, len); + if (doc) + { + xmlNodePtr ptr = xmlDocGetRootElement(doc); + while (ptr && ptr->type != XML_ELEMENT_NODE) + ptr = ptr->next; + if (ptr && ptr->ns + && !xmlStrcmp(ptr->ns->href, + BAD_CAST "http://www.loc.gov/zing/srw/diagnostic/")) + { + ret = yaz_srw_decode_diagnostics(odr, ptr, diag, num, 0, 0); + } + xmlFreeDoc(doc); + } + return ret; +} + +static int yaz_srw_diagnostics(ODR o, xmlNodePtr pptr, Z_SRW_diagnostic **recs, + int *num, void *client_data, const char *ns) +{ + if (o->direction == ODR_DECODE) + { + return yaz_srw_decode_diagnostics(o, pptr->children, recs, num, client_data, ns); + } else if (o->direction == ODR_ENCODE) { int i; @@ -1256,6 +1286,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data, /* * Local variables: * c-basic-offset: 4 + * c-file-style: "Stroustrup" * indent-tabs-mode: nil * End: * vim: shiftwidth=4 tabstop=8 expandtab