/*
- * Copyright (C) 1995-2005, Index Data ApS
+ * Copyright (C) 1995-2006, Index Data ApS
* See the file LICENSE for details.
*
- * $Id: srw.c,v 1.38 2005-11-09 17:47:07 adam Exp $
+ * $Id: srw.c,v 1.48 2006-08-18 06:30:05 adam Exp $
*/
/**
* \file srw.c
*/
#include <yaz/srw.h>
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
#include <libxml/parser.h>
#include <libxml/tree.h>
char *spack = 0;
int pack = Z_SRW_recordPacking_string;
xmlNodePtr ptr;
- xmlNodePtr data_ptr;
+ xmlNodePtr data_ptr = 0;
rec->recordSchema = 0;
rec->recordData_buf = 0;
rec->recordData_len = 0;
{
if (match_xsd_string(ptr, "recordSchema", o,
- &rec->recordSchema)){
- }
+ &rec->recordSchema))
+ ;
else if (match_xsd_string(ptr, "recordPacking", o, &spack))
{
if (spack && !strcmp(spack, "xml"))
else if (match_xsd_integer(ptr, "recordPosition", o,
&rec->recordPosition))
;
- else if (match_element(ptr, "recordData")){
+ else if (match_element(ptr, "recordData"))
+ {
/* save position of Data until after the loop
then we will know the packing (hopefully), and
unpacking is done once
*/
data_ptr = ptr;
}
- else if (match_element(ptr, "extraRecordData")){
+ else if (match_element(ptr, "extraRecordData"))
+ {
*extra = (Z_SRW_extra_record *)
odr_malloc(o, sizeof(Z_SRW_extra_record));
yaz_srw_extra_record(o, ptr, *extra, client_data, ns);
}
}
- switch(pack)
+ if (data_ptr)
{
- case Z_SRW_recordPacking_XML:
- match_xsd_XML_n(data_ptr, "recordData", o,
- &rec->recordData_buf, &rec->recordData_len);
- break;
- case Z_SRW_recordPacking_URL:
- /* just store it as a string.
- leave it to the backend to collect the document */
- match_xsd_string_n(ptr, "recordData", o,
- &rec->recordData_buf, &rec->recordData_len);
- break;
- case Z_SRW_recordPacking_string:
- match_xsd_string_n(ptr, "recordData", o,
- &rec->recordData_buf, &rec->recordData_len);
- break;
- default:
- rec->recordData_buf = 0;
- rec->recordData_len = 0;
- /* need some way to signal diagnostic here */
+ switch(pack)
+ {
+ case Z_SRW_recordPacking_XML:
+ match_xsd_XML_n(data_ptr, "recordData", o,
+ &rec->recordData_buf, &rec->recordData_len);
+ break;
+ case Z_SRW_recordPacking_URL:
+ /* just store it as a string.
+ leave it to the backend to collect the document */
+ match_xsd_string_n(data_ptr, "recordData", o,
+ &rec->recordData_buf, &rec->recordData_len);
+ break;
+ case Z_SRW_recordPacking_string:
+ match_xsd_string_n(data_ptr, "recordData", o,
+ &rec->recordData_buf, &rec->recordData_len);
+ break;
+ }
}
rec->recordPacking = pack;
}
}
if (rec->recordPosition)
add_xsd_integer(ptr, "recordPosition", rec->recordPosition );
- if (*extra)
+ if (extra && *extra)
{
xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "extraRecordData",
0);
{
xmlNodePtr rptr = xmlNewChild(pptr, 0, BAD_CAST "record",
0);
- yaz_srw_record(o, rptr, (*recs)+i, *extra + i, client_data, ns);
+ yaz_srw_record(o, rptr, (*recs)+i, (*extra ? *extra + i : 0),
+ client_data, ns);
}
}
return 0;
if (method->type != XML_ELEMENT_NODE)
return -1;
- *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(**p));
- (*p)->srw_version = odr_strdup(o, "1.1");
+ *p = yaz_srw_get_core_v_1_1(o);
if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveRequest"))
{
else if (match_xsd_string(ptr, "recordXPath", o,
&req->recordXPath))
;
- else if (match_xsd_string(ptr, "resultSetTTL", o,
- &req->database))
+ else if (match_xsd_integer(ptr, "resultSetTTL", o,
+ &req->resultSetTTL))
;
else if (match_xsd_string(ptr, "sortKeys", o,
&req->sort.sortKeys))
else if (match_xsd_string(ptr, "database", o,
&req->database))
;
- /* missing is xQuery, xSortKeys .. */
}
}
else if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveResponse"))
if (method->type != XML_ELEMENT_NODE)
return -1;
- *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(**p));
- (*p)->srw_version = odr_strdup(o, "1.1");
+ *p = yaz_srw_get_core_v_1_1(o);
if (!xmlStrcmp(method->name, BAD_CAST "updateRequest"))
{
if ((*p)->which == Z_SRW_update_request)
{
Z_SRW_updateRequest *req = (*p)->u.update_request;
- xmlNodePtr ptr = xmlNewChild(pptr, 0, "updateRequest", 0);
- ns_srw = xmlNewNs(ptr, ns, "zu");
+ xmlNodePtr ptr = xmlNewChild(pptr, 0, BAD_CAST "updateRequest", 0);
+ ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zu");
xmlSetNs(ptr, ns_srw);
add_xsd_string(ptr, "version", (*p)->srw_version);
else if ((*p)->which == Z_SRW_update_response)
{
Z_SRW_updateResponse *res = (*p)->u.update_response;
- xmlNodePtr ptr = xmlNewChild(pptr, 0, "updateResponse", 0);
- ns_srw = xmlNewNs(ptr, ns, "zu");
+ xmlNodePtr ptr = xmlNewChild(pptr, 0, (xmlChar *)
+ "updateResponse", 0);
+ ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zu");
xmlSetNs(ptr, ns_srw);
add_xsd_string(ptr, "version", (*p)->srw_version);
add_xsd_string(ptr, "recordChecksum", res->recordChecksum );
if (res->record.recordData_len)
{
- xmlNodePtr rptr = xmlNewChild(ptr, 0, "record", 0);
+ xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "record", 0);
yaz_srw_record(o, rptr, &res->record, &res->extra_record,
client_data, ns);
}
if (res->num_diagnostics)
{
- xmlNodePtr rptr = xmlNewChild(ptr, 0, "diagnostics", 0);
+ xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "diagnostics", 0);
yaz_srw_diagnostics(o, rptr, &res->diagnostics,
&res->num_diagnostics, client_data, ns);
}