For Libxml2 and friends, YAZ defines YAZ_HAVE_{XML2,XSLT,EXSLT) in
[yaz-moved-to-github.git] / src / srw.c
index 474af62..aaadd43 100644 (file)
--- a/src/srw.c
+++ b/src/srw.c
@@ -2,7 +2,7 @@
  * Copyright (C) 1995-2005, Index Data ApS
  * See the file LICENSE for details.
  *
- * $Id: srw.c,v 1.38 2005-11-09 17:47:07 adam Exp $
+ * $Id: srw.c,v 1.46 2006-07-06 10:17:54 adam Exp $
  */
 /**
  * \file srw.c
@@ -10,7 +10,7 @@
  */
 
 #include <yaz/srw.h>
-#if HAVE_XML2
+#if YAZ_HAVE_XML2
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 
@@ -234,7 +234,7 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec,
         char *spack = 0;
         int pack = Z_SRW_recordPacking_string;
         xmlNodePtr ptr;
-        xmlNodePtr data_ptr;
+        xmlNodePtr data_ptr = 0;
         rec->recordSchema = 0;
         rec->recordData_buf = 0;
         rec->recordData_len = 0;
@@ -244,8 +244,8 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec,
         {
             
             if (match_xsd_string(ptr, "recordSchema", o, 
-                                 &rec->recordSchema)){
-            }
+                                 &rec->recordSchema))
+                ;
             else if (match_xsd_string(ptr, "recordPacking", o, &spack))
             {
                 if (spack && !strcmp(spack, "xml"))
@@ -258,39 +258,40 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec,
             else if (match_xsd_integer(ptr, "recordPosition", o, 
                                        &rec->recordPosition))
                 ;
-            else if (match_element(ptr, "recordData")){
+            else if (match_element(ptr, "recordData"))
+            {
                 /* save position of Data until after the loop
                    then we will know the packing (hopefully), and
                    unpacking is done once
                 */
                 data_ptr = ptr;
             }
-            else if (match_element(ptr, "extraRecordData")){
+            else if (match_element(ptr, "extraRecordData"))
+            {
                 *extra = (Z_SRW_extra_record *)
                     odr_malloc(o, sizeof(Z_SRW_extra_record));
                 yaz_srw_extra_record(o, ptr, *extra, client_data, ns);
             }
         }
-        switch(pack)
+        if (data_ptr)
         {
-        case Z_SRW_recordPacking_XML:
-            match_xsd_XML_n(data_ptr, "recordData", o, 
-                            &rec->recordData_buf, &rec->recordData_len);
-            break;
-        case Z_SRW_recordPacking_URL:
-            /* just store it as a string.
-               leave it to the backend to collect the document */
-            match_xsd_string_n(ptr, "recordData", o, 
-                               &rec->recordData_buf, &rec->recordData_len);
-            break;
-        case Z_SRW_recordPacking_string:
-            match_xsd_string_n(ptr, "recordData", o, 
-                               &rec->recordData_buf, &rec->recordData_len);
-            break;
-        default:
-            rec->recordData_buf = 0;
-            rec->recordData_len = 0;
-            /* need some way to signal diagnostic here */
+            switch(pack)
+            {
+            case Z_SRW_recordPacking_XML:
+                match_xsd_XML_n(data_ptr, "recordData", o, 
+                                &rec->recordData_buf, &rec->recordData_len);
+                break;
+            case Z_SRW_recordPacking_URL:
+                /* just store it as a string.
+                   leave it to the backend to collect the document */
+                match_xsd_string_n(data_ptr, "recordData", o, 
+                                   &rec->recordData_buf, &rec->recordData_len);
+                break;
+            case Z_SRW_recordPacking_string:
+                match_xsd_string_n(data_ptr, "recordData", o, 
+                                   &rec->recordData_buf, &rec->recordData_len);
+                break;
+            }
         }
         rec->recordPacking = pack;
     }
@@ -320,7 +321,7 @@ static int yaz_srw_record(ODR o, xmlNodePtr pptr, Z_SRW_record *rec,
         }
         if (rec->recordPosition)
             add_xsd_integer(ptr, "recordPosition", rec->recordPosition );
-        if (*extra)
+        if (extra && *extra)
         {
             xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "extraRecordData",
                                           0);
@@ -366,7 +367,8 @@ static int yaz_srw_records(ODR o, xmlNodePtr pptr, Z_SRW_record **recs,
         {
             xmlNodePtr rptr = xmlNewChild(pptr, 0, BAD_CAST "record",
                                           0);
-            yaz_srw_record(o, rptr, (*recs)+i, *extra + i, client_data, ns);
+            yaz_srw_record(o, rptr, (*recs)+i, (*extra ? *extra + i : 0),
+                           client_data, ns);
         }
     }
     return 0;
@@ -539,6 +541,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
 
         *p = (Z_SRW_PDU *) odr_malloc(o, sizeof(**p));
         (*p)->srw_version = odr_strdup(o, "1.1");
+        (*p)->username = 0;
+        (*p)->password = 0;
         
         if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveRequest"))
         {
@@ -590,8 +594,8 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                 else if (match_xsd_string(ptr, "recordXPath", o,
                                           &req->recordXPath))
                     ;
-                else if (match_xsd_string(ptr, "resultSetTTL", o,
-                                           &req->database))
+                else if (match_xsd_integer(ptr, "resultSetTTL", o,
+                                           &req->resultSetTTL))
                     ;
                 else if (match_xsd_string(ptr, "sortKeys", o, 
                                           &req->sort.sortKeys))
@@ -602,7 +606,6 @@ int yaz_srw_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                 else if (match_xsd_string(ptr, "database", o,
                                            &req->database))
                     ;
-                /* missing is xQuery, xSortKeys .. */
             }
         }
         else if (!xmlStrcmp(method->name, BAD_CAST "searchRetrieveResponse"))
@@ -1088,8 +1091,8 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
         if ((*p)->which == Z_SRW_update_request)
         {
             Z_SRW_updateRequest *req = (*p)->u.update_request;
-            xmlNodePtr ptr = xmlNewChild(pptr, 0, "updateRequest", 0);
-           ns_srw = xmlNewNs(ptr, ns, "zu");
+            xmlNodePtr ptr = xmlNewChild(pptr, 0, BAD_CAST "updateRequest", 0);
+           ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zu");
            xmlSetNs(ptr, ns_srw);
 
            add_xsd_string(ptr, "version", (*p)->srw_version);
@@ -1099,8 +1102,9 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
         else if ((*p)->which == Z_SRW_update_response)
         {
             Z_SRW_updateResponse *res = (*p)->u.update_response;
-            xmlNodePtr ptr = xmlNewChild(pptr, 0, "updateResponse", 0);
-           ns_srw = xmlNewNs(ptr, ns, "zu");
+            xmlNodePtr ptr = xmlNewChild(pptr, 0, (xmlChar *) 
+                                         "updateResponse", 0);
+           ns_srw = xmlNewNs(ptr, BAD_CAST ns, BAD_CAST "zu");
            xmlSetNs(ptr, ns_srw);
             
            add_xsd_string(ptr, "version", (*p)->srw_version);
@@ -1112,13 +1116,13 @@ int yaz_ucp_codec(ODR o, void * vptr, Z_SRW_PDU **handler_data,
                 add_xsd_string(ptr, "recordChecksum", res->recordChecksum );
            if (res->record.recordData_len)
             {
-                xmlNodePtr rptr = xmlNewChild(ptr, 0, "record", 0);
+                xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "record", 0);
                 yaz_srw_record(o, rptr, &res->record, &res->extra_record,
                                client_data, ns);
            }
            if (res->num_diagnostics)
            {
-               xmlNodePtr rptr = xmlNewChild(ptr, 0, "diagnostics", 0);
+               xmlNodePtr rptr = xmlNewChild(ptr, 0, BAD_CAST "diagnostics", 0);
                yaz_srw_diagnostics(o, rptr, &res->diagnostics,
                                     &res->num_diagnostics, client_data, ns);
             }