SRW/SRU recordPacking
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 20 Mar 2003 21:15:00 +0000 (21:15 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 20 Mar 2003 21:15:00 +0000 (21:15 +0000)
CHANGELOG
include/yaz/srw.h
server/seshigh.c
zutil/srw.c

index f5312b3..b80bb9c 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,7 @@
 Possible compatibility problems with earlier versions marked with '*'.
 
+recordPacking.
+
 SRU protocol support for frontend server.
 
 Fix compile bug for systems that have nl_langinfo but CODESET undefined.
index 5cbeab0..2243353 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2003, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.h,v 1.5 2003-02-23 14:26:57 adam Exp $
+ * $Id: srw.h,v 1.6 2003-03-20 21:15:00 adam Exp $
  */
 
 #ifndef YAZ_SRW_H
@@ -12,6 +12,9 @@
 
 typedef struct {
     char *recordSchema;
+    int recordPacking;
+#define Z_SRW_recordPacking_string 0
+#define Z_SRW_recordPacking_XML 1
     char *recordData_buf;
     int recordData_len;
     int *recordPosition;
index 5f8a5c2..9371662 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1995-2003, Index Data
  * See the file LICENSE for details.
  *
- * $Id: seshigh.c,v 1.149 2003-03-18 13:34:36 adam Exp $
+ * $Id: seshigh.c,v 1.150 2003-03-20 21:15:00 adam Exp $
  */
 
 /*
@@ -669,14 +669,20 @@ static void srw_bend_search(association *assoc, request *req,
             if (start <= rr.hits)
             {
                 int j = 0;
+                int packing = Z_SRW_recordPacking_string;
                 if (start + number > rr.hits)
                     number = rr.hits - start + 1;
+                if (srw_req->recordPacking && 
+                    !strcmp(srw_req->recordPacking, "xml"))
+                    packing = Z_SRW_recordPacking_XML;
                 srw_res->records = (Z_SRW_record *)
                     odr_malloc(assoc->encode,
                                number * sizeof(*srw_res->records));
                 for (i = 0; i<number; i++)
                 {
                     int errcode;
+                    
+                    srw_res->records[j].recordPacking = packing;
                     srw_res->records[j].recordData_buf = 0;
                     yaz_log(LOG_DEBUG, "srw_bend_fetch %d", i+start);
                     errcode = srw_bend_fetch(assoc, i+start, srw_req,
@@ -827,6 +833,7 @@ static void process_http_request(association *assoc, request *req)
                 sr->u.request->sort.sortKeys = sortKeys;
             }
             sr->u.request->recordSchema = uri_val(p1, "recordSchema", o);
+            sr->u.request->recordPacking = uri_val(p1, "recordPacking", o);
             uri_val_int(p1, "maximumRecords", o, 
                         &sr->u.request->maximumRecords);
             uri_val_int(p1, "startRecord", o,
index 2078563..e8337b1 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 2002-2003, Index Data.
  * See the file LICENSE for details.
  *
- * $Id: srw.c,v 1.9 2003-03-18 13:34:37 adam Exp $
+ * $Id: srw.c,v 1.10 2003-03-20 21:15:00 adam Exp $
  */
 
 #include <yaz/srw.h>
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
+static void add_XML_n(xmlNodePtr ptr, const char *elem, char *val, int len)
+{
+    if (val)
+    {
+        xmlDocPtr doc = xmlParseMemory(val,len);
+        if (doc)
+        {
+            xmlNodePtr c = xmlNewChild(ptr, 0, elem, 0);
+            xmlNodePtr t = xmlDocGetRootElement(doc);
+            xmlAddChild(c, xmlCopyNode(t,1));
+            xmlFreeDoc(doc);
+        }
+    }
+}
+
 static void add_xsd_string_n(xmlNodePtr ptr, const char *elem, char *val,
                              int len)
 {
@@ -141,6 +156,7 @@ static int yaz_srw_records(ODR o, xmlNodePtr pptr, Z_SRW_record **recs,
             {
                 xmlNodePtr rptr;
                 (*recs)[i].recordSchema = 0;
+                (*recs)[i].recordPacking = Z_SRW_recordPacking_string;
                 (*recs)[i].recordData_buf = 0;
                 (*recs)[i].recordData_len = 0;
                 (*recs)[i].recordPosition = 0;
@@ -167,8 +183,17 @@ static int yaz_srw_records(ODR o, xmlNodePtr pptr, Z_SRW_record **recs,
         {
             xmlNodePtr rptr = xmlNewChild(pptr, 0, "record", 0);
             add_xsd_string(rptr, "recordSchema", (*recs)[i].recordSchema);
-            add_xsd_string_n(rptr, "recordData", (*recs)[i].recordData_buf,
-                             (*recs)[i].recordData_len);
+            switch((*recs)[i].recordPacking)
+            {
+            case Z_SRW_recordPacking_string:
+                add_xsd_string_n(rptr, "recordData", (*recs)[i].recordData_buf,
+                                 (*recs)[i].recordData_len);
+                break;
+            case Z_SRW_recordPacking_XML:
+                add_XML_n(rptr, "recordXML", (*recs)[i].recordData_buf,
+                          (*recs)[i].recordData_len);
+                break;
+            }
             add_xsd_integer(rptr, "recordPosition", (*recs)[i].recordPosition);
         }
     }