ZOOM: record objects "owned" by result sets.
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 15 Nov 2001 08:58:28 +0000 (08:58 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 15 Nov 2001 08:58:28 +0000 (08:58 +0000)
Added Z3950_record_dup.

CHANGELOG
doc/zoom.xml
include/yaz/zoom.h
zoom/zoom-c.c
zoom/zoomsh.c
zoom/zoomtst3.c
zoom/zoomtst5.c
zoom/zoomtst6.c
zoom/zoomtst7.c

index a3b69b8..993efc3 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,11 @@
 Possible compatibility problems with earlier versions marked with '*'.
 
+* ZOOO. Added Z3950_record_dup. Removed Z3950_resultset_get.
+Function Z3950_resultset_record(s) returns references to records
+"owned" by resultset. To become owner use Z3950_record_dup.
+
+Function z_ext_record handles Extended Services.
+
 --- 1.8.2 2001/11/12
 
 CCL Parser fix: ignore token comma when dealing with and-lists.
index 5049709..4b62b50 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $Id: zoom.xml,v 1.8 2001-11-13 23:00:42 adam Exp $ -->
+<!-- $Id: zoom.xml,v 1.9 2001-11-15 08:58:28 adam Exp $ -->
  <chapter id="zoom"><title>Building clients with ZOOM</title>
   
   <para>
   </para>
   <para>
    The lack of a simple Z39.50 client API for &yaz; has become more
-   and more apparent over time. So when the first ZOOM specification
+   and more apparent over time. So when the first &zoom; specification
    became available,
    an implementation for &yaz; was quickly developed. For the first time, it is
    now as easy (or easier!) to develop clients than servers with &yaz;. This
-   chapter describes the ZOOM C binding. Before going futher, please
+   chapter describes the &zoom; C binding. Before going futher, please
    reconsider whether C is the right programming language for the job.
    There are other language bindings available for &yaz;, and still
    more
-   are in active development. See the ZOOM website at
-   <ulink url="http://zoom.z3950.org/">zoom.z3950.org</ulink> for
+   are in active development. See the
+   <ulink url="http://zoom.z3950.org/">ZOOM website</ulink> for
    more information.
   </para>
 
                                          const char *key,
                                          const char *val);
 
-     int Z3950_resultset_size (Z3950_resultset r);
-
-     void *Z3950_resultset_get (Z3950_resultset s, size_t pos,
-                                const char *type, size_t *len);
+     size_t Z3950_resultset_size (Z3950_resultset r);
    </synopsis>
    <para>
     Function <function>Z3950_resultset_options</function> sets or
     The number of hits also called result-count is returned by
     function <function>Z3950_resultset_size</function>.
    </para>
-   <para>
-    Function <function>Z3950_resultset_get</function> is similar to
-    <link linkend="zoom.record.get">
-     <function>Z3950_record_get</function></link> but
-    instead of operating on a record object, it operates on a record on
-    a given offset within a result set.
-   </para>
    <table frame="top"><title>ZOOM Result set Options</title>
     <tgroup cols="3">
      <colspec colwidth="4*" colname="name"></colspec>
      void *Z3950_record_get (Z3950_record rec, const char *type,
                              size_t *len);
 
+     Z3950_record Z3950_record_dup (Z3950_record rec);
+
      void Z3950_record_destroy (Z3950_record rec);
    </synopsis>
    <para>
-    Records are created by functions 
+    References to temporary records are returned by functions 
     <function>Z3950_resultset_records</function> or
-    <function>Z3950_resultset_record</function>
-    and destroyed by <function>Z3950_record_destroy</function>.
+    <function>Z3950_resultset_record</function>.
+    </para>
+   <para>
+    If a persistent pointer to a record is desired
+    <function>Z3950_record_dup</function> should be used.
+    It returns a record reference that at any
+    later stage should be destroyed by
+    <function>Z3950_record_destroy</function>.
    </para>
    <para>
-    A single record is created and returned by function
+    A single record is returned by function
     <function>Z3950_resultset_record</function> that takes a 
     position as argument. First record has position zero.
     If no record could be obtained <literal>NULL</literal> is returned.
     the returned information.
     <variablelist>
      <varlistentry><term><literal>database</literal></term>
-      <listitem><para>The database that holds the record is returned
-        as a C string. Return type <literal>char *</literal>. 
+      <listitem><para>Database of record is returned
+        as a C null-terminated string. Return type <literal>char *</literal>. 
        </para></listitem>
       </varlistentry>
      <varlistentry><term><literal>syntax</literal></term>
       <listitem><para>The transfer syntax (OID) of the record is returned
-        as a C string. Return type <literal>char *</literal>. 
+        as a C null-terminated string. Return type <literal>char *</literal>. 
        </para></listitem>
       </varlistentry>
      <varlistentry><term><literal>render</literal></term>
index 484a7cd..baa1084 100644 (file)
@@ -1,12 +1,14 @@
 /*
  * Public header for ZOOM C.
- * $Id: zoom.h,v 1.3 2001-11-06 17:05:19 adam Exp $
+ * $Id: zoom.h,v 1.4 2001-11-15 08:58:29 adam Exp $
  */
 
-/* 1. Modification
-      Renamed type Z3950_search to Z3950_query and the functions
+/* 1. Renamed type Z3950_search to Z3950_query and the functions
       that manipulate it..
       Changed positions/sizes to be of type size_t rather than int.
+   2. Deleted Z3950_resultset_get. Added Z3950_record_dup. Record
+      reference(s) returned by Z350_resultset_records and
+      Z3950_resultset_record are "owned" by result set.
 */
 #include <yaz/yconfig.h>
 
@@ -100,14 +102,10 @@ void Z3950_resultset_destroy(Z3950_resultset r);
 ZOOM_EXPORT
 const char *Z3950_resultset_option (Z3950_resultset r, const char *key,
                                    const char *val);
-/* return size of result set (hit count, AKA resultCount) */
+/* return size of result set (alias hit count AKA result count) */
 ZOOM_EXPORT
-int Z3950_resultset_size (Z3950_resultset r);
+size_t Z3950_resultset_size (Z3950_resultset r);
 
-/* return record at pos (starting from ), render given spec in type */
-ZOOM_EXPORT
-void *Z3950_resultset_get (Z3950_resultset s, size_t pos, const char *type,
-                          size_t *len);
 /* retrieve records */
 ZOOM_EXPORT
 void Z3950_resultset_records (Z3950_resultset r, Z3950_record *recs,
@@ -124,14 +122,18 @@ Z3950_record Z3950_resultset_record_immediate (Z3950_resultset s, size_t pos);
 /* ----------------------------------------------------------- */
 /* records */
 
-/* Get record information, in a form given by type */
+/* get record information, in a form given by type */
 ZOOM_EXPORT
 void *Z3950_record_get (Z3950_record rec, const char *type, size_t *len);
 
-/* Destroy record */
+/* destroy record */
 ZOOM_EXPORT
 void Z3950_record_destroy (Z3950_record rec);
 
+/* return copy of record */
+ZOOM_EXPORT
+Z3950_record Z3950_record_dup (Z3950_record srec);
+
 /* ----------------------------------------------------------- */
 /* searches */
 
@@ -148,7 +150,6 @@ int Z3950_query_prefix(Z3950_query s, const char *str);
 ZOOM_EXPORT
 int Z3950_query_sortby(Z3950_query s, const char *criteria);
 
-
 /* ----------------------------------------------------------- */
 /* options */
 typedef const char *(*Z3950_options_callback)(void *handle, const char *name);
index 45181e7..fa38d1d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoom-c.c,v 1.5 2001-11-13 22:57:03 adam Exp $
+ * $Id: zoom-c.c,v 1.6 2001-11-15 08:58:29 adam Exp $
  *
  * ZOOM layer for C, connections, result sets, queries.
  */
@@ -417,7 +417,7 @@ void Z3950_resultset_destroy(Z3950_resultset r)
     }
 }
 
-int Z3950_resultset_size (Z3950_resultset r)
+size_t Z3950_resultset_size (Z3950_resultset r)
 {
     return r->size;
 }
@@ -767,7 +767,7 @@ static void response_diag (Z3950_connection c, Z_DiagRec *p)
     c->error = *r->condition;
 }
 
-Z3950_record Z3950_record_dup (Z3950_record srec)
+Z3950_record Z3950_record_dup (const Z3950_record srec)
 {
     char *buf;
     int size;
@@ -791,10 +791,7 @@ Z3950_record Z3950_record_dup (Z3950_record srec)
 
 Z3950_record Z3950_resultset_record_immediate (Z3950_resultset s,size_t pos)
 {
-    Z3950_record rec = record_cache_lookup (s, pos, 0);
-    if (!rec)
-       return 0;
-    return Z3950_record_dup (rec);
+    return record_cache_lookup (s, pos, 0);
 }
 
 Z3950_record Z3950_resultset_record (Z3950_resultset r, size_t pos)
@@ -893,13 +890,6 @@ void *Z3950_record_get (Z3950_record rec, const char *type, size_t *len)
     return 0;
 }
 
-void *Z3950_resultset_get (Z3950_resultset s, size_t pos, const char *type,
-                          size_t *len)
-{
-    Z3950_record rec = record_cache_lookup (s, pos, 0);
-    return Z3950_record_get (rec, type, len);
-}
-
 static void record_cache_add (Z3950_resultset r,
                              Z_NamePlusRecord *npr,
                              int pos,
index 8ff31b1..69e3195 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoomsh.c,v 1.3 2001-11-06 17:05:19 adam Exp $
+ * $Id: zoomsh.c,v 1.4 2001-11-15 08:58:29 adam Exp $
  *
  * ZOOM-C Shell
  */
@@ -117,16 +117,17 @@ static void display_records (Z3950_connection c,
     for (i = 0; i<count; i++)
     {
        int pos = i + start;
-       const char *db = Z3950_resultset_get (r, pos, "database", 0);
+        Z3950_record rec = Z3950_resultset_record (r, pos);
+       const char *db = Z3950_record_get (rec, "database", 0);
        int len;
-       const char *rec = Z3950_resultset_get (r, pos, "render", &len);
-       const char *syntax = Z3950_resultset_get (r, pos, "syntax", 0);
+       const char *render = Z3950_record_get (rec, "render", &len);
+       const char *syntax = Z3950_record_get (rec, "syntax", 0);
        /* if rec is non-null, we got a record for display */
        if (rec)
        {
            printf ("%d %s %s\n", pos+1, (db ? db : "unknown"), syntax);
-           if (rec)
-               fwrite (rec, 1, len, stdout);
+           if (render)
+               fwrite (render, 1, len, stdout);
            putchar ('\n');
        }
     }
index b52d1d1..f393f91 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoomtst3.c,v 1.2 2001-10-24 12:24:43 adam Exp $
+ * $Id: zoomtst3.c,v 1.3 2001-11-15 08:58:29 adam Exp $
  *
  * Asynchronous multi-target client doing search and piggyback retrieval
  */
@@ -75,7 +75,8 @@ int main(int argc, char **argv)
            {
                int len; /* length of buffer rec */
                const char *rec =
-                   Z3950_resultset_get (r[i], pos, "render", &len);
+                   Z3950_record_get (
+                        Z3950_resultset_record (r[i], pos), "render", &len);
                /* if rec is non-null, we got a record for display */
                if (rec)
                {
index fcf9560..79fedab 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoomtst5.c,v 1.3 2001-11-06 17:05:19 adam Exp $
+ * $Id: zoomtst5.c,v 1.4 2001-11-15 08:58:29 adam Exp $
  *
  * Asynchronous multi-target client doing search, sort and present
  */
@@ -108,7 +108,6 @@ int main(int argc, char **argv)
                        fwrite (str, 1, len, stdout);
                    putchar ('\n');
                }
-               Z3950_record_destroy (rec);
            }
        }
     }
@@ -121,4 +120,5 @@ int main(int argc, char **argv)
         Z3950_connection_destroy (z[i]);
     }
     Z3950_options_destroy(o);
+    exit(0);
 }
index 86f2d3e..910866d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoomtst6.c,v 1.3 2001-11-06 17:05:19 adam Exp $
+ * $Id: zoomtst6.c,v 1.4 2001-11-15 08:58:29 adam Exp $
  *
  * Asynchronous multi-target client doing two searches
  */
@@ -18,16 +18,18 @@ static void display_records (const char *tname, Z3950_resultset r)
     /* go through all records at target */
     for (pos = 0; pos < 20; pos++)
     {
+        Z3950_record rec = Z3950_resultset_record (r, pos);
+
        /* get database for record and record itself at pos */
-       const char *db = Z3950_resultset_get (r, pos, "database", 0);
+       const char *db = Z3950_record_get (rec, "database", 0);
        int len;
-       const char *rec = Z3950_resultset_get (r, pos, "render", &len);
+       const char *render = Z3950_record_get (rec, "render", &len);
        /* if rec is non-null, we got a record for display */
        if (rec)
        {
            printf ("%d %s\n", pos+1, (db ? db : "unknown"));
-           if (rec)
-               fwrite (rec, 1, len, stdout);
+           if (render)
+               fwrite (render, 1, len, stdout);
            putchar ('\n');
        }
     }
index 39c4bbb..2de80f6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: zoomtst7.c,v 1.5 2001-11-13 22:57:03 adam Exp $
+ * $Id: zoomtst7.c,v 1.6 2001-11-15 08:58:29 adam Exp $
  *
  * API test..
  */
@@ -58,7 +58,6 @@ int main(int argc, char **argv)
            for (j = 0; j < 10; j++)
            {
                Z3950_record recs[2];
-               size_t recs_count = 2;
                char query[40];
                Z3950_query s = Z3950_query_create ();
                
@@ -75,8 +74,6 @@ int main(int argc, char **argv)
                r[j] = Z3950_connection_search (z, s); /* non-piggy */
                
                Z3950_resultset_records (r[j], recs, 0, 2);  /* first two */
-               Z3950_record_destroy (recs[0]);
-               Z3950_record_destroy (recs[1]);
                
                Z3950_resultset_records (r[j], recs, 1, 2);  /* third */
 
@@ -90,8 +87,6 @@ int main(int argc, char **argv)
                        exit (1);
                    }
                }
-               Z3950_record_destroy (recs[0]);
-               Z3950_record_destroy (recs[1]);
                
                Z3950_query_destroy (s);
 
@@ -149,6 +144,9 @@ int main(int argc, char **argv)
        }
     }
     Z3950_options_destroy (o);
+    xmalloc_trav("");
+    nmem_exit();
+    xmalloc_trav("");
     exit (0);
 }