SRW diagnostic code now a URI
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Jan 2004 12:15:11 +0000 (12:15 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Jan 2004 12:15:11 +0000 (12:15 +0000)
CHANGELOG
client/client.c
include/yaz/srw.h
src/seshigh.c
src/srw.c
src/srwutil.c
src/zoom-c.c
ztest/ztest.c

index bd4d74c..c609234 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,7 @@
 Possible compatibility problems with earlier versions marked with '*'.
 
+* SRW/SRU 1.1 updates. Diagnostic code now a URI.
+
 Added option -p <file> to make Generic Frontend Server to write PID file.
 
 Added option -D to put Generic Frontend Server in background on its own.
index 6fa6a4a..f485347 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: client.c,v 1.226 2004-01-15 10:16:26 adam Exp $
+ * $Id: client.c,v 1.227 2004-01-27 12:15:11 adam Exp $
  */
 
 #include <stdio.h>
@@ -3304,10 +3304,11 @@ static void handle_srw_response(Z_SRW_searchRetrieveResponse *res)
     
     for (i = 0; i<res->num_diagnostics; i++)
     {
-        printf ("SRW diagnostic %d %s\n",
-                *res->diagnostics[i].code,
-                yaz_diag_srw_str(*res->diagnostics[i].code));
+        printf ("SRW diagnostic %s\n",
+                res->diagnostics[i].code);
 
+       if (res->diagnostics[i].message)
+            printf ("Message: %s\n", res->diagnostics[i].message);
        if (res->diagnostics[i].details)
             printf ("Details: %s\n", res->diagnostics[i].details);
     }
index f937730..42f93e2 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.h,v 1.14 2004-01-09 18:10:31 adam Exp $
+ * $Id: srw.h,v 1.15 2004-01-27 12:15:11 adam Exp $
  */
 
 #ifndef YAZ_SRW_H
@@ -24,8 +24,9 @@ typedef struct {
 } Z_SRW_record;
 
 typedef struct {
-    int  *code;
+    char *code;
     char *details;
+    char *message;
 } Z_SRW_diagnostic;
     
 typedef struct {
@@ -146,9 +147,12 @@ YAZ_EXPORT int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                              char **charset,
                              Z_SRW_diagnostic **, int *num_diagnostic);
 
-void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
-                           int *num, int code, const char *addinfo);
+YAZ_EXPORT void yaz_add_srw_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);
 YAZ_END_CDECL
 
 #endif
index 6010c2f..34fe0b0 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.18 2004-01-23 18:16:07 adam Exp $
+ * $Id: seshigh.c,v 1.19 2004-01-27 12:15:12 adam Exp $
  */
 
 /*
@@ -631,9 +631,8 @@ static void srw_bend_search(association *assoc, request *req,
         srw_res->num_diagnostics = 1;
         srw_res->diagnostics = (Z_SRW_diagnostic *)
            odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics));
-        srw_res->diagnostics[0].code = 
-            odr_intdup(assoc->encode, srw_error);
-        srw_res->diagnostics[0].details = 0;
+       yaz_mk_std_diagnostic(assoc->encode,
+                             srw_res->diagnostics, srw_error, 0);
         return;
     }
     
@@ -661,13 +660,11 @@ static void srw_bend_search(association *assoc, request *req,
         srw_res->num_diagnostics = 1;
         srw_res->diagnostics = (Z_SRW_diagnostic *)
            odr_malloc(assoc->encode, sizeof(*srw_res->diagnostics));
-        srw_res->diagnostics[0].code = 
-            odr_intdup(assoc->encode, 
-                       yaz_diag_bib1_to_srw (rr.errcode));
-        srw_res->diagnostics[0].details = rr.errstring;
+       yaz_mk_std_diagnostic(assoc->encode, srw_res->diagnostics,
+                             yaz_diag_bib1_to_srw (rr.errcode),
+                             rr.errstring);
         yaz_log(LOG_DEBUG, "srw_bend_search returned SRW error %d",
                 *srw_res->diagnostics[0].code);
-                
     }
     else
     {
@@ -713,10 +710,11 @@ static void srw_bend_search(association *assoc, request *req,
                         srw_res->diagnostics = (Z_SRW_diagnostic *)
                             odr_malloc(assoc->encode, 
                                        sizeof(*srw_res->diagnostics));
-                        srw_res->diagnostics[0].code = 
-                            odr_intdup(assoc->encode, 
-                                       yaz_diag_bib1_to_srw (errcode));
-                        srw_res->diagnostics[0].details = rr.errstring;
+
+                       yaz_mk_std_diagnostic(assoc->encode, 
+                                             srw_res->diagnostics,
+                                             yaz_diag_bib1_to_srw (errcode),
+                                             rr.errstring);
                         break;
                     }
                     if (srw_res->records[j].recordData_buf)
@@ -1319,7 +1317,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.18 $");
+    version = odr_strdup(assoc->encode, "$Revision: 1.19 $");
     if (strlen(version) > 10)  /* check for unexpanded CVS strings */
        version[strlen(version)-2] = '\0';
     resp->implementationVersion = odr_prepend(assoc->encode,
index 7fb30b4..ca8ff01 100644 (file)
--- a/src/srw.c
+++ b/src/srw.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.c,v 1.18 2004-01-15 23:33:29 adam Exp $
+ * $Id: srw.c,v 1.19 2004-01-27 12:15:12 adam Exp $
  */
 
 #include <yaz/srw.h>
@@ -287,6 +287,7 @@ static int yaz_srw_diagnostics(ODR o, xmlNodePtr pptr, Z_SRW_diagnostic **recs,
        {
             (*recs)[i].code = 0;
             (*recs)[i].details = 0;
+            (*recs)[i].message = 0;
        } 
         for (i = 0, ptr = pptr->children; ptr; ptr = ptr->next)
         {
@@ -296,14 +297,18 @@ static int yaz_srw_diagnostics(ODR o, xmlNodePtr pptr, Z_SRW_diagnostic **recs,
                 xmlNodePtr rptr;
                 (*recs)[i].code = 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, "code", o, 
+                                        &(*recs)[i].code))
                         ;
                     else if (match_xsd_string(rptr, "details", o, 
                                               &(*recs)[i].details))
                         ;
+                    else if (match_xsd_string(rptr, "message", o, 
+                                              &(*recs)[i].message))
+                        ;
                 }
                 i++;
             }
@@ -316,11 +321,16 @@ static int yaz_srw_diagnostics(ODR o, xmlNodePtr pptr, Z_SRW_diagnostic **recs,
            xmlNewNs(pptr, "http://www.loc.gov/zing/srw/diagnostics/", "diag");
         for (i = 0; i < *num; i++)
         {
+           const char *std_diag = "info:srw/diagnostic/1/1/";
             xmlNodePtr rptr = xmlNewChild(pptr, ns_diag, "diagnostic", 0);
-            add_xsd_integer(rptr, "code", (*recs)[i].code);
-           if ((*recs)[i].code)
+            add_xsd_string(rptr, "code", (*recs)[i].code);
+           if ((*recs)[i].message)
+               add_xsd_string(rptr, "message", (*recs)[i].message);
+           else if ((*recs)[i].code && 
+                    !strncmp((*recs)[i].code, std_diag, strlen(std_diag)))
            {
-               const char *message = yaz_diag_srw_str(*(*recs)[i].code);
+               int no = atoi((*recs)[i].code + strlen(std_diag));
+               const char *message = yaz_diag_srw_str(no);
                if (message)
                    add_xsd_string(rptr, "message", message);
            }
index 0257c9c..cd89a33 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srwutil.c,v 1.9 2004-01-09 19:54:05 adam Exp $
+ * $Id: srwutil.c,v 1.10 2004-01-27 12:15:12 adam Exp $
  */
 
 #include <yaz/srw.h>
@@ -131,6 +131,18 @@ void yaz_uri_val_int(const char *path, const char *name, ODR o, int **intp)
         *intp = odr_intdup(o, atoi(v));
 }
 
+void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d, 
+                          int code, const char *details)
+{
+    d->code = (char *) odr_malloc(o, 50);
+    sprintf(d->code, "info:srw/diagnostic/1/1/%d", code);
+    d->message = 0;
+    if (details)
+       d->details = odr_strdup(o, details);
+    else
+       d->details = 0;
+}
+
 void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
                            int *num, int code, const char *addinfo)
 {
@@ -139,11 +151,8 @@ void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
     if (*num)
        memcpy (d_new, *d, *num *sizeof(**d));
     *d = d_new;
-    (*d + *num)->code = odr_intdup(o, code);
-    if (addinfo)
-       (*d + *num)->details = odr_strdup(o, addinfo);
-    else
-       (*d + *num)->details = 0;
+
+    yaz_mk_std_diagnostic(o, *d + *num, code, addinfo);
     (*num)++;
 }
 
@@ -298,7 +307,7 @@ int yaz_sru_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                else if (!strcmp(n, "startRecord"))
                    startRecord = v;
                else
-                   yaz_add_srw_diagnostic(decode, diag, num_diag, 9, n);
+                   yaz_add_srw_diagnostic(decode, diag, num_diag, 8, n);
            }
        }
        if (!version)
@@ -536,8 +545,7 @@ static struct {
 {5, "Unsupported version"},
 {6, "Unsupported parameter value"},
 {7, "Mandatory parameter not supplied"},
-{8, "Unknown database"},
-{9, "Unknown parameter type"},
+{8, "Unsupported parameter"},
 /* Diagnostics Relating to CQL */
 {10, "Query syntax error"}, 
 {11, "Unsupported query type"}, 
@@ -694,7 +702,7 @@ static int srw_bib1_map[] = {
     108, 27,
     108, 45,
         
-    109, 9,
+    109, 2,
     110, 37,
     111, 1,
     112, 58,
index a37e14a..e161888 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2000-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: zoom-c.c,v 1.20 2004-01-22 11:20:54 adam Exp $
+ * $Id: zoom-c.c,v 1.21 2004-01-27 12:15:12 adam Exp $
  *
  * ZOOM layer for C, connections, result sets, queries.
  */
@@ -922,7 +922,7 @@ static zoom_ret ZOOM_connection_send_init (ZOOM_connection c)
        ZOOM_options_get(c->options, "implementationName"),
        odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
 
-    version = odr_strdup(c->odr_out, "$Revision: 1.20 $");
+    version = odr_strdup(c->odr_out, "$Revision: 1.21 $");
     if (strlen(version) > 10)  /* check for unexpanded CVS strings */
        version[strlen(version)-2] = '\0';
     ireq->implementationVersion = odr_prepend(c->odr_out,
@@ -2949,8 +2949,20 @@ static void handle_srw_response(ZOOM_connection c,
     }
     if (res->num_diagnostics > 0)
     {
-        set_dset_error(c, *res->diagnostics[0].code, "SRW",
-                       res->diagnostics[0].details, 0);
+       const char *std_diag = "info:srw/diagnostic/1/1/";
+       const char *code = res->diagnostics[0].code;
+       const char *cp;
+       const char *category = code;
+       int code_int = 0;
+
+       if (code && (cp = strrchr(code, '/')))
+           code_int = atoi(cp+1);
+       if (code && !strncmp(code, std_diag, strlen(std_diag)))
+           category = "SRW";
+
+       if (category)
+           set_dset_error(c, code_int, category,
+                          res->diagnostics[0].details, 0);
     }
     nmem = odr_extract_mem(c->odr_in);
     nmem_transfer(resultset->odr->mem, nmem);
index a92a335..e7e815f 100644 (file)
@@ -1,8 +1,8 @@
 /*
- * Copyright (c) 1995-2003, Index Data.
+ * Copyright (c) 1995-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: ztest.c,v 1.60 2004-01-15 10:04:39 adam Exp $
+ * $Id: ztest.c,v 1.61 2004-01-27 12:15:12 adam Exp $
  */
 
 /*
@@ -34,12 +34,14 @@ int ztest_search (void *handle, bend_search_rr *rr)
         rr->errcode = 23;
         return 0;
     }
-    /* if database is stop, stop this process.. For debugging only.
+#if NMEM_DEBUG
+    /* if database is stop, stop this process.. For debugging only. */
     if (!yaz_matchstr (rr->basenames[0], "stop"))
     {
        nmem_print_list_l(LOG_LOG);
         exit(0);
     }
+#endif
     /* Throw Database unavailable if other than Default */
     if (yaz_matchstr (rr->basenames[0], "Default"))
     {