Added two new utilities for encoding SRW diagnostics via a URI rather
[yaz-moved-to-github.git] / src / srwutil.c
index 4fd23f1..6519422 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: srwutil.c,v 1.33 2005-11-09 17:48:11 adam Exp $
+ * $Id: srwutil.c,v 1.34 2005-12-14 14:05:55 adam Exp $
  */
 /**
  * \file srwutil.c
@@ -137,20 +137,33 @@ 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)
+void yaz_mk_srw_diagnostic(ODR o, Z_SRW_diagnostic *d, 
+                           const char *uri, const char *message,
+                           const char *details)
 {
-    d->uri = (char *) odr_malloc(o, 50);
-    sprintf(d->uri, "info:srw/diagnostic/1/%d", code);
-    d->message = 0;
+    d->uri = odr_strdup(o, uri);
+    if (message)
+        d->message = odr_strdup(o, message);
+    else
+        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)
+void yaz_mk_std_diagnostic(ODR o, Z_SRW_diagnostic *d, 
+                           int code, const char *details)
+{
+    char uri[40];
+    
+    sprintf(uri, "info:srw/diagnostic/1/%d", code);
+    return yaz_mk_srw_diagnostic(o, d, uri, 0, details);
+}
+
+void yaz_add_srw_diagnostic_uri(ODR o, Z_SRW_diagnostic **d,
+                                int *num, const char *uri,
+                                const char *message, const char *details)
 {
     Z_SRW_diagnostic *d_new;
     d_new = (Z_SRW_diagnostic *) odr_malloc (o, (*num + 1)* sizeof(**d));
@@ -158,10 +171,19 @@ void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
         memcpy (d_new, *d, *num *sizeof(**d));
     *d = d_new;
 
-    yaz_mk_std_diagnostic(o, *d + *num, code, addinfo);
+    yaz_mk_srw_diagnostic(o, *d + *num, uri, message, details);
     (*num)++;
 }
 
+void yaz_add_srw_diagnostic(ODR o, Z_SRW_diagnostic **d,
+                            int *num, int code, const char *addinfo)
+{
+    char uri[40];
+    
+    sprintf(uri, "info:srw/diagnostic/1/%d", code);
+    return yaz_add_srw_diagnostic_uri(o, d, num, uri, 0, addinfo);
+}
+
 int yaz_srw_decode(Z_HTTP_Request *hreq, Z_SRW_PDU **srw_pdu,
                    Z_SOAP **soap_package, ODR decode, char **charset)
 {