/*
- * 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.40 2005-11-11 22:07:11 adam Exp $
+ * $Id: srw.c,v 1.50 2006-10-27 11:22:09 adam Exp $
*/
/**
* \file srw.c
*/
#include <yaz/srw.h>
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
#include <libxml/parser.h>
#include <libxml/tree.h>
{
if (match_xsd_string(ptr, "recordId", o,
&rec->recordId ))
+ ; /* backward compatible */
+ else if (match_xsd_string(ptr, "recordIdentifier", o,
+ &rec->recordId ))
;
else if (match_xsd_string(ptr, "recordReviewCode", o,
&rec->recordReviewCode ))
{
xmlNodePtr ptr = pptr;
if ( rec->recordId )
- add_xsd_string(ptr, "recordId", rec->recordId);
+ add_xsd_string(ptr, "recordIdentfier", rec->recordId);
if ( rec->recordReviewCode )
add_xsd_string(ptr, "recordReviewCode", rec->recordReviewCode);
if ( rec->recordReviewNote )
}
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;
for (i = 0; i < *num; i++)
{
const char *std_diag = "info:srw/diagnostic/1/";
+ const char *ucp_diag = "info:srw/diagnostic/12/";
xmlNodePtr rptr = xmlNewChild(pptr, ns_diag,
BAD_CAST "diagnostic", 0);
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)))
+ else if ((*recs)[i].uri )
{
- 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);
+ if (!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);
+ }
+ else if (!strncmp((*recs)[i].uri, ucp_diag, strlen(ucp_diag)))
+ {
+ int no = atoi((*recs)[i].uri + strlen(ucp_diag));
+ const char *message = yaz_diag_sru_update_str(no);
+ if (message)
+ add_xsd_string(rptr, "message", message);
+ }
}
add_xsd_string(rptr, "details", (*recs)[i].details);
}
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 .. */
+ }
+ if (!req->query.cql && !req->query.pqf && !req->query.xcql)
+ {
+ /* should put proper diagnostic here */
+ return -1;
}
}
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"))
{
;
else if (match_xsd_string(ptr, "operation", o,
&oper)){
+ /* backward compatible */
if ( oper ){
if ( !strcmp(oper, "delete"))
req->operation = "delete";
req->operation = "insert";
}
}
+ else if (match_xsd_string(ptr, "action", o,
+ &oper)){
+ if ( oper ){
+ if ( !strcmp(oper, "info:srw/action/1/delete"))
+ req->operation = "delete";
+ else if (!strcmp(oper,"info:srw/action/1/replace" ))
+ req->operation = "replace";
+ else if ( !strcmp( oper, "info:srw/action/1/create"))
+ req->operation = "insert";
+ }
+ }
else if (match_xsd_string(ptr, "recordId", o,
&req->recordId))
+ ; /* backward compatible */
+ else if (match_xsd_string(ptr, "recordIdentifier", o,
+ &req->recordId))
;
else if (match_xsd_string(ptr, "recordVersion", o,
&req->recordVersion))
;
else if (match_xsd_string(ptr, "recordId", o,
&res->recordId))
+ ; /* backward compatible */
+ else if (match_xsd_string(ptr, "recordIdentifier", o,
+ &res->recordId))
;
else if (match_xsd_string(ptr, "recordVersion", o,
&res->recordVersion ))
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, "operationStatus", res->operationStatus );
- add_xsd_string(ptr, "recordId", res->recordId );
+ add_xsd_string(ptr, "recordIdentifier", res->recordId );
if (res->recordVersion)
add_xsd_string(ptr, "recordVersion", res->recordVersion );
if (res->recordChecksum)
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);
}