Updates for SRU Update by Ko van der Sloot:
authorAdam Dickmeiss <adam@indexdata.dk>
Fri, 27 Oct 2006 11:22:08 +0000 (11:22 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Fri, 27 Oct 2006 11:22:08 +0000 (11:22 +0000)
1. Changed name from "operation" to "action"
2. Fixed that that "recordIdentifier" was called "recordId". Kept the old
versions in the code, marked as 'backward compatible'.
3. Added diagnostics for SRU Update.

NEWS
include/yaz/Makefile.am
include/yaz/srw.h
src/Makefile.am
src/csvtosru_update.tcl [new file with mode: 0644]
src/seshigh.c
src/sru_update.csv [new file with mode: 0644]
src/srw.c
src/srwutil.c

diff --git a/NEWS b/NEWS
index fe97563..b040417 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+
+Updates for SRU Update by Ko van der Sloot:
+1. Changed name from "operation" to "action"
+2. Fixed that that "recordIdentifier" was called "recordId". Kept the old
+versions in the code, marked as 'backward compatible'.
+3. Added diagnostics for SRU Update.
+
 --- 2.1.36 2006/10/13
 
 Implemented yaz_filepath_comp which splits a path into file path
index 4f8de2a..14ef421 100644 (file)
@@ -1,7 +1,7 @@
-## $Id: Makefile.am,v 1.32 2006-07-04 12:59:56 heikki Exp $
+## $Id: Makefile.am,v 1.33 2006-10-27 11:22:08 adam Exp $
 
 pkginclude_HEADERS= backend.h ccl.h cql.h comstack.h \
- diagbib1.h diagsrw.h sortspec.h log.h logrpn.h marcdisp.h \
+ diagbib1.h diagsrw.h diagsru_update.h sortspec.h log.h logrpn.h marcdisp.h \
  nfa.h nfaxml.h \
  nmem.h odr.h \
  oid.h options.h otherinfo.h pquery.h prt-ext.h querytowrbuf.h \
index 9be6695..14dc8b9 100644 (file)
@@ -24,7 +24,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
-/* $Id: srw.h,v 1.30 2006-10-13 11:30:37 adam Exp $ */
+/* $Id: srw.h,v 1.31 2006-10-27 11:22:08 adam Exp $ */
 
 /**
  * \file srw.h
@@ -37,6 +37,7 @@
 #include <yaz/soap.h>
 #include <yaz/zgdu.h>
 #include <yaz/diagsrw.h>
+#include <yaz/diagsru_update.h>
 
 YAZ_BEGIN_CDECL
 
@@ -233,6 +234,9 @@ YAZ_EXPORT void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
                                        int *num, int code,
                                        const char *addinfo);
     
+YAZ_EXPORT void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d,
+                                              int *num, int code,
+                                              const char *addinfo);
 
 YAZ_EXPORT void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d, 
                                       int code, const char *details);
index c54d47a..891e5e9 100644 (file)
@@ -1,6 +1,6 @@
 ## This file is part of the YAZ toolkit.
 ## Copyright (C) 1994-2006, Index Data, All rights reserved.
-## $Id: Makefile.am,v 1.41 2006-10-09 21:12:44 adam Exp $
+## $Id: Makefile.am,v 1.42 2006-10-27 11:22:09 adam Exp $
 
 YAZ_VERSION_INFO=2:1:0
 
@@ -19,7 +19,8 @@ illdata_DATA=ill9702.asn item-req.asn ill.tcl
 
 EXTRA_DIST=$(tabdata_DATA) $(illdata_DATA) \
  charconv.tcl codetables.xml \
- csvtodiag.tcl csvtobib1.tcl csvtosrw.tcl bib1.csv srw.csv
+ csvtodiag.tcl csvtobib1.tcl csvtosrw.tcl bib1.csv srw.csv \
+ csvtosru_update.tcl sru_update.csv
 
 YAZCOMP=$(top_srcdir)/util/yaz-asncomp
 YAZCOMP_Z = $(YAZCOMP) -d $(srcdir)/z.tcl -i yaz -I$(top_srcdir)/include
@@ -45,6 +46,9 @@ diagbib1.c $(top_srcdir)/include/yaz/diagbib1.h: csvtobib1.tcl bib1.csv
 diagsrw.c $(top_srcdir)/include/yaz/diagsrw.h: csvtosrw.tcl srw.csv
        $(TCLSH) $(srcdir)/csvtosrw.tcl $(srcdir)
 
+diagsru_update.c $(top_srcdir)/include/yaz/diagsru_update.h: csvtosru_update.tcl sru_update.csv
+       $(TCLSH) $(srcdir)/csvtosru_update.tcl $(srcdir)
+
 libyaz_la_SOURCES=version.c options.c log.c marcdisp.c oid.c wrbuf.c \
   nmemsdup.c xmalloc.c readconf.c tpath.c nmem.c matchstr.c atoin.c \
   siconv.c marc8.c marc8r.c \
@@ -62,7 +66,8 @@ libyaz_la_SOURCES=version.c options.c log.c marcdisp.c oid.c wrbuf.c \
   z-charneg.c \
   prt-ext.c \
   ill-core.c item-req.c ill-get.c \
-  zget.c yaz-ccl.c diag-entry.c diag-entry.h diagbib1.c diagsrw.c logrpn.c \
+  zget.c yaz-ccl.c diag-entry.c diag-entry.h diagbib1.c diagsrw.c \
+  diagsru_update.c logrpn.c \
   otherinfo.c pquery.c sortspec.c z3950oid.c charneg.c initopt.c \
   zoom-c.c zoom-opt.c zoom-p.h grs1disp.c zgdu.c soap.c srw.c srwutil.c \
   opacdisp.c cclfind.c ccltoken.c cclerrms.c cclqual.c cclptree.c \
diff --git a/src/csvtosru_update.tcl b/src/csvtosru_update.tcl
new file mode 100644 (file)
index 0000000..7b51605
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh
+# the next line restats using tclsh \
+exec tclsh "$0" "$@"
+#
+# This file is part of the YAZ toolkit
+# Copyright (c) Index Data 1996-2006
+# See the file LICENSE for details.
+#
+# $Id: csvtosru_update.tcl,v 1.1 2006-10-27 11:22:09 adam Exp $
+#
+# Converts a CSV file with SRU update diagnostics to C+H file for easy
+# maintenance
+#
+# $Id: csvtosru_update.tcl,v 1.1 2006-10-27 11:22:09 adam Exp $
+
+source [lindex $argv 0]/csvtodiag.tcl
+
+csvtodiag [list [lindex $argv 0]/sru_update.csv diagsru_update.c [lindex $argv 0]/../include/yaz/diagsru_update.h] sru_update {}
index 236069a..de71c65 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.102 2006-10-24 08:12:12 adam Exp $
+ * $Id: seshigh.c,v 1.103 2006-10-27 11:22:09 adam Exp $
  */
 /**
  * \file seshigh.c
@@ -1477,24 +1477,60 @@ static void srw_bend_update(association *assoc, request *req,
         rr.uri = 0;
         rr.message = 0;
         rr.details = 0;
-
+        
+        if ( rr.operation == 0 ){
+            yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                          &srw_res->num_diagnostics,
+                                          9, "action" );
+            return;
+        }
         yaz_log(YLOG_DEBUG, "basename = %s", rr.basenames[0] );
         yaz_log(YLOG_DEBUG, "Operation = %s", rr.operation );
        if ( !strcmp( rr.operation, "delete" ) ){
             if ( !srw_req->recordId ){
-                yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
-                                       &srw_res->num_diagnostics,
-                                       7, "recordId" );
+                if ( srw_req->record.recordData_len ){
+                    if ( srw_req->record.recordSchema == 0 ){
+                        yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                                      &srw_res->num_diagnostics,
+                                                      9, "recordSchema" );
+                    }
+                    else {
+                        rr.record_schema = odr_strdup(assoc->encode,
+                                                      srw_req->record.recordSchema );
+                    }
+                    switch (srw_req->record.recordPacking)
+                        {
+                        case Z_SRW_recordPacking_string: 
+                            rr.record_packing = "string";
+                            break;
+                        case Z_SRW_recordPacking_XML: 
+                            rr.record_packing = "xml";
+                            break;
+                        case Z_SRW_recordPacking_URL: 
+                            rr.record_packing = "url";
+                            break;
+                        }
+                    rr.record_data = odr_strdupn(assoc->encode, 
+                                                 srw_req->record.recordData_buf,
+                                                 srw_req->record.recordData_len );
+                    rr.request_extra_record = srw_req->extra_record;
+                }
+                else {
+                    yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                                  &srw_res->num_diagnostics,
+                                                  9, "recordIdentifier OR recordData" );
+                }
             }
             else {
                 rr.record_id = srw_req->recordId;
+                if ( srw_req->record.recordData_len ){
+                    yaz_add_sru_update_diagnostic(assoc->encode, 
+                                                  &srw_res->diagnostics,
+                                                  &srw_res->num_diagnostics,
+                                                  9, "recordData" );
+                }
             }
-            if (  !srw_req->recordVersion ){
-                yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
-                                       &srw_res->num_diagnostics,
-                                       7, "recordVersion" );
-            }
-            else {
+            if (  srw_req->recordVersion ){
                 rr.record_version = odr_strdup( assoc->encode,
                                                 srw_req->recordVersion );
                 
@@ -1510,17 +1546,17 @@ static void srw_bend_update(association *assoc, request *req,
        }
        else if ( !strcmp( rr.operation, "replace" ) ){
             if ( !srw_req->recordId ){
-                yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
-                                       &srw_res->num_diagnostics,
-                                       7, "recordId" );
+                yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                              &srw_res->num_diagnostics,
+                                              9, "recordIdentifier" );
             }
             else {
                 rr.record_id = srw_req->recordId;
             }
             if ( srw_req->record.recordSchema == 0 ){
-                yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
-                                       &srw_res->num_diagnostics,
-                                       7, "recordSchema" );
+                yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                              &srw_res->num_diagnostics,
+                                              9, "recordSchema" );
             }
             else {
                 rr.record_schema = odr_strdup(assoc->encode,
@@ -1545,21 +1581,20 @@ static void srw_bend_update(association *assoc, request *req,
                 rr.request_extra_record = srw_req->extra_record;
             }
             else {
-                yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
-                                       &srw_res->num_diagnostics,
-                                       7, "recordData" );
+                yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                              &srw_res->num_diagnostics,
+                                              9, "recordData" );
             }
             if (srw_req->extraRequestData)
                 rr.extra_request_data = odr_strdup(assoc->encode,
                                                    srw_req->extraRequestData );
        }
-       else if ( !strcmp( rr.operation, "insert" ) )
-        {
+       else if (!strcmp( rr.operation, "insert" ) ) {
             rr.record_id = srw_req->recordId; 
             if ( srw_req->record.recordSchema == 0 ){
-                yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
-                                       &srw_res->num_diagnostics,
-                                       7, "recordSchema" );
+                yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                              &srw_res->num_diagnostics,
+                                              9, "recordSchema" );
             }
             else {
                 rr.record_schema = odr_strdup(assoc->encode,
@@ -1586,13 +1621,18 @@ static void srw_bend_update(association *assoc, request *req,
                 rr.request_extra_record = srw_req->extra_record;
             }
             else
-                yaz_add_srw_diagnostic(assoc->encode, &srw_res->diagnostics,
-                                       &srw_res->num_diagnostics,
-                                       7, "recordData" );
+                yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                             &srw_res->num_diagnostics,
+                                             9, "recordData" );
             if ( srw_req->extraRequestData )
                 rr.extra_request_data = odr_strdup(assoc->encode,
                                                    srw_req->extraRequestData );
        }
+       else { 
+            yaz_add_sru_update_diagnostic(assoc->encode, &srw_res->diagnostics,
+                                          &srw_res->num_diagnostics,
+                                          100, rr.operation );
+        }
         if (srw_res->num_diagnostics == 0)
         {
             if ( assoc->init->bend_srw_update)
@@ -2321,7 +2361,7 @@ static Z_APDU *process_initRequest(association *assoc, request *reqb)
                 assoc->init->implementation_name,
                 odr_prepend(assoc->encode, "GFS", resp->implementationName));
 
-    version = odr_strdup(assoc->encode, "$Revision: 1.102 $");
+    version = odr_strdup(assoc->encode, "$Revision: 1.103 $");
     if (strlen(version) > 10)   /* check for unexpanded CVS strings */
         version[strlen(version)-2] = '\0';
     resp->implementationVersion = odr_prepend(assoc->encode,
diff --git a/src/sru_update.csv b/src/sru_update.csv
new file mode 100644 (file)
index 0000000..354f742
--- /dev/null
@@ -0,0 +1,47 @@
+1, "Invalid component:  record rejected"
+2, "Invalid component:  component rejected"
+3, "Invalid component:  warning only"
+4, "Invalid component:  default value applied"
+5, "Invalid component:  data corrected by server"
+6, "Invalid repetition of component: record rejected"
+7, "Invalid repetition of component: component rejected"
+8, "Invalid repetition of component: warning only"
+9, "Missing mandatory element: record rejected"
+10, "Missing mandatory element: warning only"
+11, "Missing mandatory element: default value applied"
+12, "Invalid data structure: record rejected"
+13, "Invalid data structure: component rejected"
+14, "Invalid data structure: warning only"
+15, "Invalid data structure: default value applied"
+16, "Invalid data structure: data corrected by server"
+17, "Incorrect element length: record rejected"
+18, "Incorrect element length : component rejected"
+19, "Incorrect element length : warning only"
+20, "Incorrect element length : default value applied"
+21, "Incorrect element length : data corrected by server"
+22, "Invalid record identifier : record rejected"
+23, "Invalid record identifier : warning only"
+24, "Invalid record identifier : default applied"
+25, "Invalid record identifier : data corrected by server"
+26, "Invalid component identifier : record rejected"
+27, "Invalid component identifier: component rejected"
+28, "Invalid component identifier: warning only"
+29, "Invalid component identifier: data corrected by server"
+30, "Record schema unacceptable: record rejected"
+31, "Record schema unacceptable: component rejected"
+32, "Record schema unrecognised: warning only"
+33, "Record schema unacceptable: record converted"
+50, "Record not found (replacement or delete)"
+51, "Component not found (replacement or delete)"
+52, "Record protected or locked by another user"
+53, "Cannot delete or replace record or component, authorization failure"
+54, "Cannot delete or replace record or component without locking first"
+55, "Cannot process update, incorrect or invalid version"
+56, "Linked records exist, cannot delete record"
+57, "Record or component not found, replacement request processed as an insert"
+58, "Suspect duplicate: record or component insert rejected"
+59, "Suspect duplicate: warning only"
+60, "Incoming record matches with database record, records merged"
+61, "Unspecified database error"
+62, "Cannot process or store record, insufficient space"
+100, "invalid action"
\ No newline at end of file
index 197a5de..f7b2f55 100644 (file)
--- a/src/srw.c
+++ b/src/srw.c
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: srw.c,v 1.49 2006-10-24 08:07:02 adam Exp $
+ * $Id: srw.c,v 1.50 2006-10-27 11:22:09 adam Exp $
  */
 /**
  * \file srw.c
@@ -188,6 +188,9 @@ static int yaz_srw_extra_record(ODR o, xmlNodePtr pptr,
        {
            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 ))
@@ -210,7 +213,7 @@ static int yaz_srw_extra_record(ODR o, xmlNodePtr pptr,
     {
         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 )
@@ -431,18 +434,28 @@ static int yaz_srw_diagnostics(ODR o, xmlNodePtr pptr, Z_SRW_diagnostic **recs,
         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);
         }
@@ -1001,6 +1014,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                     ;
                 else if (match_xsd_string(ptr, "operation", o, 
                                           &oper)){
+                    /* backward compatible */
                     if ( oper ){
                         if ( !strcmp(oper, "delete"))
                             req->operation = "delete";
@@ -1010,8 +1024,22 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                             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))
@@ -1059,6 +1087,9 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                     ;
                 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 ))
@@ -1110,7 +1141,7 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
             
            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)
index 5e5eab6..560976b 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2006, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: srwutil.c,v 1.52 2006-10-24 09:18:34 adam Exp $
+ * $Id: srwutil.c,v 1.53 2006-10-27 11:22:09 adam Exp $
  */
 /**
  * \file srwutil.c
@@ -329,6 +329,16 @@ void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
 }
 
 
+void yaz_add_sru_update_diagnostic(ODR o, Z_SRW_diagnostic **d,
+                                   int *num, int code, const char *addinfo)
+{
+    char uri[40];
+    
+    sprintf(uri, "info:srw/diagnostic/12/%d", code);
+    yaz_add_srw_diagnostic_uri(o, d, num, uri, 0, addinfo);
+}
+
+
 static void grab_charset(ODR o, const char *content_type, char **charset)
 {
     if (charset)