/*
- * Copyright (c) 2002-2003, Index Data.
+ * Copyright (c) 2002-2004, Index Data.
* See the file LICENSE for details.
*
- * $Id: srw.c,v 1.12 2004-01-05 14:05:56 adam Exp $
+ * $Id: srw.c,v 1.21 2004-02-14 15:58:42 adam Exp $
*/
#include <yaz/srw.h>
}
}
-xmlNodePtr add_xsd_string_n(xmlNodePtr ptr, const char *elem, char *val,
+xmlNodePtr add_xsd_string_n(xmlNodePtr ptr, const char *elem, const char *val,
int len)
{
if (val)
return 0;
}
-xmlNodePtr add_xsd_string(xmlNodePtr ptr, const char *elem, char *val)
+xmlNodePtr add_xsd_string(xmlNodePtr ptr, const char *elem, const char *val)
{
if (val)
return xmlNewChild(ptr, 0, elem, val);
return 0;
}
-static void add_xsd_integer(xmlNodePtr ptr, const char *elem, int *val)
+static void add_xsd_integer(xmlNodePtr ptr, const char *elem, const int *val)
{
if (val)
{
if (!match_element(ptr, elem))
return 0;
ptr = ptr->children;
+ while (ptr && ptr->type != XML_TEXT_NODE && ptr->type != XML_COMMENT_NODE)
+ ptr = ptr->next;
if (!ptr)
return 0;
buf = xmlBufferCreate();
-
+
xmlNodeDump(buf, ptr->doc, ptr, 0, 0);
-
+
*val = odr_malloc(o, buf->use+1);
memcpy (*val, buf->content, buf->use);
(*val)[buf->use] = '\0';
return 1;
}
-
static int match_xsd_integer(xmlNodePtr ptr, const char *elem, ODR o, int **val)
{
;
else if (match_xsd_string(ptr, "recordPacking", o, &spack))
{
- if (pack && !strcmp(spack, "xml"))
+ if (spack && !strcmp(spack, "xml"))
pack = Z_SRW_recordPacking_XML;
- if (pack && !strcmp(spack, "string"))
+ if (spack && !strcmp(spack, "string"))
pack = Z_SRW_recordPacking_string;
}
else if (match_xsd_integer(ptr, "recordPosition", o,
if (!*num)
return 1;
*recs = odr_malloc(o, *num * sizeof(**recs));
- for (i = 0, ptr = pptr->children; ptr; ptr = ptr->next, i++)
+ for (i = 0, ptr = pptr->children; ptr; ptr = ptr->next)
{
if (ptr->type == XML_ELEMENT_NODE &&
!strcmp(ptr->name, "record"))
+ {
yaz_srw_record(o, ptr, (*recs)+i, client_data, ns);
+ i++;
+ }
}
}
else if (o->direction == ODR_ENCODE)
*recs = odr_malloc(o, *num * sizeof(**recs));
for (i = 0; i < *num; i++)
{
- (*recs)[i].code = 0;
+ (*recs)[i].uri = 0;
(*recs)[i].details = 0;
+ (*recs)[i].message = 0;
}
for (i = 0, ptr = pptr->children; ptr; ptr = ptr->next)
{
!strcmp(ptr->name, "diagnostic"))
{
xmlNodePtr rptr;
- (*recs)[i].code = 0;
+ (*recs)[i].uri = 0;
(*recs)[i].details = 0;
+ (*recs)[i].message = 0;
for (rptr = ptr->children; rptr; rptr = rptr->next)
{
- if (match_xsd_integer(rptr, "code", o,
- &(*recs)[i].code))
+ 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++;
}
xmlNewNs(pptr, "http://www.loc.gov/zing/srw/diagnostics/", "diag");
for (i = 0; i < *num; i++)
{
+ const char *std_diag = "info:srw/diagnostic/1/";
xmlNodePtr rptr = xmlNewChild(pptr, ns_diag, "diagnostic", 0);
- add_xsd_integer(rptr, "code", (*recs)[i].code);
+ add_xsd_string(rptr, "uri", (*recs)[i].uri);
+ if ((*recs)[i].message)
+ add_xsd_string(rptr, "message", (*recs)[i].message);
+ else if ((*recs)[i].uri &&
+ !strncmp((*recs)[i].uri, std_diag, strlen(std_diag)))
+ {
+ int no = atoi((*recs)[i].uri + strlen(std_diag));
+ const char *message = yaz_diag_srw_str(no);
+ if (message)
+ add_xsd_string(rptr, "message", message);
+ }
add_xsd_string(rptr, "details", (*recs)[i].details);
}
}
for (; ptr; ptr = ptr->next)
{
- if (match_xsd_string(ptr, "query", o,
+ if (match_xsd_string(ptr, "version", o,
+ &(*p)->srw_version))
+ ;
+ else if (match_xsd_string(ptr, "query", o,
&req->query.cql))
req->query_type = Z_SRW_query_type_cql;
else if (match_xsd_string(ptr, "pQuery", o,
else if (match_xsd_string(ptr, "xQuery", o,
&req->query.xcql))
req->query_type = Z_SRW_query_type_xcql;
- else if (match_xsd_string(ptr, "sortKeys", o,
- &req->sort.sortKeys))
- req->sort_type = Z_SRW_sort_type_sort;
- else if (match_xsd_string(ptr, "recordSchema", o,
- &req->recordSchema))
+ else if (match_xsd_integer(ptr, "startRecord", o,
+ &req->startRecord))
+ ;
+ else if (match_xsd_integer(ptr, "maximumRecords", o,
+ &req->maximumRecords))
;
else if (match_xsd_string(ptr, "recordPacking", o,
&req->recordPacking))
;
+ else if (match_xsd_string(ptr, "recordSchema", o,
+ &req->recordSchema))
+ ;
else if (match_xsd_string(ptr, "recordXPath", o,
&req->recordXPath))
;
- else if (match_xsd_integer(ptr, "startRecord", o,
- &req->startRecord))
- ;
- else if (match_xsd_integer(ptr, "maximumRecords", o,
- &req->maximumRecords))
+ else if (match_xsd_string(ptr, "resultSetTTL", o,
+ &req->database))
;
+ else if (match_xsd_string(ptr, "sortKeys", o,
+ &req->sort.sortKeys))
+ req->sort_type = Z_SRW_sort_type_sort;
else if (match_xsd_string(ptr, "stylesheet", o,
&req->stylesheet))
;
else if (match_xsd_string(ptr, "database", o,
&req->database))
;
- else if (match_xsd_string(ptr, "resultSetTTL", o,
- &req->database))
- ;
- else if (match_xsd_string(ptr, "version", o,
- &(*p)->srw_version))
- ;
/* missing is xQuery, xSortKeys .. */
}
}
for (; ptr; ptr = ptr->next)
{
- if (match_xsd_integer(ptr, "numberOfRecords", o,
+ if (match_xsd_string(ptr, "version", o,
+ &(*p)->srw_version))
+ ;
+ else if (match_xsd_integer(ptr, "numberOfRecords", o,
&res->numberOfRecords))
;
else if (match_xsd_string(ptr, "resultSetId", o,
yaz_srw_records(o, ptr, &res->records,
&res->num_records, client_data,
ns);
+ else if (match_xsd_integer(ptr, "nextRecordPosition", o,
+ &res->nextRecordPosition))
+ ;
else if (match_element(ptr, "diagnostics"))
yaz_srw_diagnostics(o, ptr, &res->diagnostics,
&res->num_diagnostics,
client_data, ns);
- else if (match_xsd_integer(ptr, "nextRecordPosition", o,
- &res->nextRecordPosition))
- ;
- else if (match_xsd_string(ptr, "version", o,
- &(*p)->srw_version))
- ;
}
}
else if (!strcmp(method->name, "explainRequest"))
req = (*p)->u.explain_request = odr_malloc(o, sizeof(*req));
req->recordPacking = 0;
req->database = 0;
+ req->stylesheet = 0;
for (; ptr; ptr = ptr->next)
{
- if (match_xsd_string(ptr, "database", o,
- &req->database))
- ;
+ if (match_xsd_string(ptr, "version", o,
+ &(*p)->srw_version))
+ ;
+ else if (match_xsd_string(ptr, "stylesheet", o,
+ &req->stylesheet))
+ ;
else if (match_xsd_string(ptr, "recordPacking", o,
&req->recordPacking))
;
- else if (match_xsd_string(ptr, "version", o,
- &(*p)->srw_version))
- ;
+ else if (match_xsd_string(ptr, "database", o,
+ &req->database))
+ ;
}
}
else if (!strcmp(method->name, "explainResponse"))
for (; ptr; ptr = ptr->next)
{
- if (match_element(ptr, "record"))
- yaz_srw_record(o, ptr, &res->record, client_data, ns);
- else if (match_xsd_string(ptr, "version", o,
- &(*p)->srw_version))
+ if (match_xsd_string(ptr, "version", o,
+ &(*p)->srw_version))
;
+ else if (match_element(ptr, "record"))
+ yaz_srw_record(o, ptr, &res->record, client_data, ns);
else if (match_element(ptr, "diagnostics"))
yaz_srw_diagnostics(o, ptr, &res->diagnostics,
&res->num_diagnostics,
else if (match_xsd_string(ptr, "scanClause", o,
&req->scanClause))
;
- else if (match_xsd_string(ptr, "database", o,
- &req->database))
- ;
- else if (match_xsd_string(ptr, "stylesheet", o,
- &req->stylesheet))
- ;
else if (match_xsd_integer(ptr, "responsePosition", o,
&req->responsePosition))
;
else if (match_xsd_integer(ptr, "maximumTerms", o,
&req->maximumTerms))
;
+ else if (match_xsd_string(ptr, "stylesheet", o,
+ &req->stylesheet))
+ ;
+ else if (match_xsd_string(ptr, "database", o,
+ &req->database))
+ ;
}
}
else if (!strcmp(method->name, "scanResponse"))
for (; ptr; ptr = ptr->next)
{
- if (match_element(ptr, "terms"))
+ if (match_xsd_string(ptr, "version", o,
+ &(*p)->srw_version))
+ ;
+ else if (match_element(ptr, "terms"))
yaz_srw_terms(o, ptr, &res->terms,
&res->num_terms, client_data,
ns);
yaz_srw_diagnostics(o, ptr, &res->diagnostics,
&res->num_diagnostics,
client_data, ns);
- else if (match_xsd_string(ptr, "version", o,
- &(*p)->srw_version))
- ;
}
}
else
add_xsd_string(ptr, "pQuery", req->query.pqf);
break;
}
+ add_xsd_integer(ptr, "startRecord", req->startRecord);
+ add_xsd_integer(ptr, "maximumRecords", req->maximumRecords);
+ add_xsd_string(ptr, "recordPacking", req->recordPacking);
+ add_xsd_string(ptr, "recordSchema", req->recordSchema);
+ add_xsd_string(ptr, "recordXPath", req->recordXPath);
+ add_xsd_integer(ptr, "resultSetTTL", req->resultSetTTL);
switch(req->sort_type)
{
case Z_SRW_sort_type_none:
add_xsd_string(ptr, "xSortKeys", req->sort.xSortKeys);
break;
}
- add_xsd_integer(ptr, "startRecord", req->startRecord);
- add_xsd_integer(ptr, "maximumRecords", req->maximumRecords);
- add_xsd_string(ptr, "recordSchema", req->recordSchema);
- add_xsd_string(ptr, "recordPacking", req->recordPacking);
- add_xsd_string(ptr, "recordXPath", req->recordXPath);
- add_xsd_string(ptr, "database", req->database);
- add_xsd_integer(ptr, "resultSetTTL", req->resultSetTTL);
add_xsd_string(ptr, "stylesheet", req->stylesheet);
+ add_xsd_string(ptr, "database", req->database);
}
else if ((*p)->which == Z_SRW_searchRetrieve_response)
{
yaz_srw_records(o, rptr, &res->records, &res->num_records,
client_data, ns);
}
+ add_xsd_integer(ptr, "nextRecordPosition",
+ res->nextRecordPosition);
if (res->num_diagnostics)
{
xmlNodePtr rptr = xmlNewChild(ptr, 0, "diagnostics", 0);
yaz_srw_diagnostics(o, rptr, &res->diagnostics,
&res->num_diagnostics, client_data, ns);
}
- add_xsd_integer(ptr, "nextRecordPosition", res->nextRecordPosition);
}
else if ((*p)->which == Z_SRW_explain_request)
{
+ Z_SRW_explainRequest *req = (*p)->u.explain_request;
xmlNodePtr ptr = xmlNewChild(pptr, 0, "explainRequest", 0);
ns_srw = xmlNewNs(ptr, ns, "zs");
xmlSetNs(ptr, ns_srw);
add_xsd_string(ptr, "version", (*p)->srw_version);
+ add_xsd_string(ptr, "recordPacking", req->recordPacking);
+ add_xsd_string(ptr, "stylesheet", req->stylesheet);
+ add_xsd_string(ptr, "database", req->database);
}
else if ((*p)->which == Z_SRW_explain_response)
{
add_xsd_integer(ptr, "responsePosition", req->responsePosition);
add_xsd_integer(ptr, "maximumTerms", req->maximumTerms);
add_xsd_string(ptr, "stylesheet", req->stylesheet);
+ add_xsd_string(ptr, "database", req->database);
}
else if ((*p)->which == Z_SRW_scan_response)
{