Use prefix for SRW diagset in ZOOM
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Jan 2004 21:22:43 +0000 (21:22 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Jan 2004 21:22:43 +0000 (21:22 +0000)
client/client.c
src/srw.c
src/srwutil.c
src/zoom-c.c
src/zoom-p.h
ztest/ztest.c

index f485347..90d3e94 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2004, Index Data
  * See the file LICENSE for details.
  *
  * Copyright (c) 1995-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: client.c,v 1.227 2004-01-27 12:15:11 adam Exp $
+ * $Id: client.c,v 1.228 2004-01-27 21:22:43 adam Exp $
  */
 
 #include <stdio.h>
  */
 
 #include <stdio.h>
@@ -3306,7 +3306,6 @@ static void handle_srw_response(Z_SRW_searchRetrieveResponse *res)
     {
         printf ("SRW diagnostic %s\n",
                 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)
        if (res->diagnostics[i].message)
             printf ("Message: %s\n", res->diagnostics[i].message);
        if (res->diagnostics[i].details)
index ca8ff01..9fdadce 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.
  *
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.c,v 1.19 2004-01-27 12:15:12 adam Exp $
+ * $Id: srw.c,v 1.20 2004-01-27 21:22:44 adam Exp $
  */
 
 #include <yaz/srw.h>
  */
 
 #include <yaz/srw.h>
@@ -321,7 +321,7 @@ 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++)
         {
            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/";
+           const char *std_diag = "info:srw/diagnostic/1/";
             xmlNodePtr rptr = xmlNewChild(pptr, ns_diag, "diagnostic", 0);
             add_xsd_string(rptr, "code", (*recs)[i].code);
            if ((*recs)[i].message)
             xmlNodePtr rptr = xmlNewChild(pptr, ns_diag, "diagnostic", 0);
             add_xsd_string(rptr, "code", (*recs)[i].code);
            if ((*recs)[i].message)
index cd89a33..a7bc839 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
  * Copyright (c) 2002-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srwutil.c,v 1.10 2004-01-27 12:15:12 adam Exp $
+ * $Id: srwutil.c,v 1.11 2004-01-27 21:22:44 adam Exp $
  */
 
 #include <yaz/srw.h>
  */
 
 #include <yaz/srw.h>
@@ -135,7 +135,7 @@ void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d,
                           int code, const char *details)
 {
     d->code = (char *) odr_malloc(o, 50);
                           int code, const char *details)
 {
     d->code = (char *) odr_malloc(o, 50);
-    sprintf(d->code, "info:srw/diagnostic/1/1/%d", code);
+    sprintf(d->code, "info:srw/diagnostic/1/%d", code);
     d->message = 0;
     if (details)
        d->details = odr_strdup(o, details);
     d->message = 0;
     if (details)
        d->details = odr_strdup(o, details);
index e161888..caeba59 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2000-2004, Index Data
  * See the file LICENSE for details.
  *
  * Copyright (c) 2000-2004, Index Data
  * See the file LICENSE for details.
  *
- * $Id: zoom-c.c,v 1.21 2004-01-27 12:15:12 adam Exp $
+ * $Id: zoom-c.c,v 1.22 2004-01-27 21:22:44 adam Exp $
  *
  * ZOOM layer for C, connections, result sets, queries.
  */
  *
  * ZOOM layer for C, connections, result sets, queries.
  */
@@ -90,10 +90,18 @@ static void set_dset_error (ZOOM_connection c, int error,
                             const char *dset,
                             const char *addinfo, const char *addinfo2)
 {
                             const char *dset,
                             const char *addinfo, const char *addinfo2)
 {
+    char *cp;
     xfree (c->addinfo);
     c->addinfo = 0;
     c->error = error;
     xfree (c->addinfo);
     c->addinfo = 0;
     c->error = error;
-    c->diagset = dset;
+    if (c->diagset && strcmp(dset, c->diagset))
+    {
+        xfree(c->diagset);
+        c->diagset = xstrdup(dset);
+       /* remove integer part from SRW diagset .. */
+        if ((cp = strrchr(c->diagset, '/')))
+          *cp = '\0';
+    }
     if (addinfo && addinfo2)
     {
         c->addinfo = xmalloc(strlen(addinfo) + strlen(addinfo2) + 2);
     if (addinfo && addinfo2)
     {
         c->addinfo = xmalloc(strlen(addinfo) + strlen(addinfo2) + 2);
@@ -219,6 +227,7 @@ ZOOM_connection_create (ZOOM_options options)
     c->reconnect_ok = 0;
     c->state = STATE_IDLE;
     c->addinfo = 0;
     c->reconnect_ok = 0;
     c->state = STATE_IDLE;
     c->addinfo = 0;
+    c->diagset = 0;
     set_ZOOM_error(c, ZOOM_ERROR_NONE, 0);
     c->buf_in = 0;
     c->len_in = 0;
     set_ZOOM_error(c, ZOOM_ERROR_NONE, 0);
     c->buf_in = 0;
     c->len_in = 0;
@@ -471,6 +480,7 @@ ZOOM_connection_destroy(ZOOM_connection c)
 
     xfree (c->buf_in);
     xfree (c->addinfo);
 
     xfree (c->buf_in);
     xfree (c->addinfo);
+    xfree (c->diagset);
     odr_destroy (c->odr_in);
     odr_destroy (c->odr_out);
     ZOOM_options_destroy (c->options);
     odr_destroy (c->odr_in);
     odr_destroy (c->odr_out);
     ZOOM_options_destroy (c->options);
@@ -922,7 +932,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));
 
        ZOOM_options_get(c->options, "implementationName"),
        odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
 
-    version = odr_strdup(c->odr_out, "$Revision: 1.21 $");
+    version = odr_strdup(c->odr_out, "$Revision: 1.22 $");
     if (strlen(version) > 10)  /* check for unexpanded CVS strings */
        version[strlen(version)-2] = '\0';
     ireq->implementationVersion = odr_prepend(c->odr_out,
     if (strlen(version) > 10)  /* check for unexpanded CVS strings */
        version[strlen(version)-2] = '\0';
     ireq->implementationVersion = odr_prepend(c->odr_out,
@@ -2949,20 +2959,16 @@ static void handle_srw_response(ZOOM_connection c,
     }
     if (res->num_diagnostics > 0)
     {
     }
     if (res->num_diagnostics > 0)
     {
-       const char *std_diag = "info:srw/diagnostic/1/1/";
        const char *code = res->diagnostics[0].code;
        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,
+       if (code)
+       {
+           int code_int = 0;   
+           const char *cp;
+           if ((cp = strrchr(code, '/')))
+               code_int = atoi(cp+1);
+           set_dset_error(c, code_int, code,
                           res->diagnostics[0].details, 0);
                           res->diagnostics[0].details, 0);
+       }
     }
     nmem = odr_extract_mem(c->odr_in);
     nmem_transfer(resultset->odr->mem, nmem);
     }
     nmem = odr_extract_mem(c->odr_in);
     nmem_transfer(resultset->odr->mem, nmem);
@@ -3246,7 +3252,7 @@ ZOOM_connection_error_x (ZOOM_connection c, const char **cp,
             *cp = z_HTTP_errmsg(c->error);
         else if (!strcmp(c->diagset, "Bib-1"))
             *cp = ZOOM_diag_str(error);
             *cp = z_HTTP_errmsg(c->error);
         else if (!strcmp(c->diagset, "Bib-1"))
             *cp = ZOOM_diag_str(error);
-        else if (!strcmp(c->diagset, "SRW"))
+        else if (!strcmp(c->diagset, "info:srw/diagnostic/1"))
             *cp = yaz_diag_srw_str(c->error);
         else
             *cp = "Unknown error and diagnostic set";
             *cp = yaz_diag_srw_str(c->error);
         else
             *cp = "Unknown error and diagnostic set";
index d852feb..a991aaf 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Private C header for ZOOM C.
 /*
  * Private C header for ZOOM C.
- * $Id: zoom-p.h,v 1.2 2003-12-20 00:51:19 adam Exp $
+ * $Id: zoom-p.h,v 1.3 2004-01-27 21:22:44 adam Exp $
  */
 
 #include <yaz/proto.h>
  */
 
 #include <yaz/proto.h>
@@ -33,7 +33,7 @@ struct ZOOM_connection_p {
     char *path;
     int error;
     char *addinfo;
     char *path;
     int error;
     char *addinfo;
-    const char *diagset;
+    char *diagset;
     int state;
     int mask;
     int reconnect_ok;
     int state;
     int mask;
     int reconnect_ok;
index e7e815f..bd4459e 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2004, Index Data.
  * See the file LICENSE for details.
  *
  * Copyright (c) 1995-2004, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: ztest.c,v 1.61 2004-01-27 12:15:12 adam Exp $
+ * $Id: ztest.c,v 1.62 2004-01-27 21:22:44 adam Exp $
  */
 
 /*
  */
 
 /*
@@ -437,7 +437,7 @@ int ztest_present (void *handle, bend_present_rr *rr)
 int ztest_fetch(void *handle, bend_fetch_rr *r)
 {
     char *cp;
 int ztest_fetch(void *handle, bend_fetch_rr *r)
 {
     char *cp;
-    r->errstring = 0;
+
     r->last_in_set = 0;
     r->basename = "Default";
     r->output_format = r->request_format;  
     r->last_in_set = 0;
     r->basename = "Default";
     r->output_format = r->request_format;