Prepare for YAZ 3s new OID system
[pazpar2-moved-to-github.git] / src / pazpar2.c
index 2e13c5d..b5c638f 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: pazpar2.c,v 1.75 2007-04-12 09:59:47 marc Exp $
+/* $Id: pazpar2.c,v 1.77 2007-04-12 13:46:28 adam Exp $
    Copyright (c) 2006-2007, Index Data.
 
 This file is part of Pazpar2.
@@ -39,6 +39,10 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
 #include <yaz/otherinfo.h>
 #include <yaz/yaz-util.h>
 #include <yaz/nmem.h>
+#include <yaz/querytowrbuf.h>
+#if YAZ_VERSIONL >= 0x020163
+#include <yaz/oid_db.h>
+#endif
 
 #if HAVE_CONFIG_H
 #include "cconfig.h"
@@ -178,9 +182,19 @@ static void send_init(IOCHAN i)
     
     if (0 < strlen(global_parameters.zproxy_override) 
         && 0 < strlen(cl->database->database->url))
-        yaz_oi_set_string_oidval(&a->u.initRequest->otherInfo, 
+    {
+#if YAZ_VERSIONL >= 0x020163
+        const int *oid_proxy = yaz_string_to_oid(yaz_oid_std(),
+                                                 CLASS_USERINFO, OID_STR_PROXY);
+        yaz_oi_set_string_oid(&a->u.initRequest->otherInfo,
+                              global_parameters.odr_out, oid_proxy,
+                              1, cl->database->database->url);
+#else
+        yaz_oi_set_string_oidval(&a->u.initRequest->otherInfo,
                                  global_parameters.odr_out, VAL_PROXY,
                                  1, cl->database->database->url);
+#endif
+    }
 
     if (send_apdu(cl, a) >= 0)
     {
@@ -235,7 +249,7 @@ static void send_search(IOCHAN i)
     char *recsyn;
     char *piggyback;
 
-    yaz_log(YLOG_DEBUG, "Sending search");
+    yaz_log(YLOG_DEBUG, "Sending search to %s", cl->database->database->url);
 
     cn = ccl_find_str(sdb->database->ccl_map, se->query, &cerror, &cpos);
     if (!cn)
@@ -265,9 +279,18 @@ static void send_search(IOCHAN i)
     if (!(piggyback = session_setting_oneval(sdb, PZ_PIGGYBACK)) || *piggyback == '1')
     {
         if ((recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX)))
+        {
+#if YAZ_VERSIONL >= 0x020163
+            a->u.searchRequest->preferredRecordSyntax =
+                yaz_string_to_oid_odr(yaz_oid_std(),
+                                      CLASS_RECSYN, recsyn,
+                                      global_parameters.odr_out);
+#else
             a->u.searchRequest->preferredRecordSyntax =
-                    yaz_str_to_z3950oid(global_parameters.odr_out,
-                    CLASS_RECSYN, recsyn);
+                yaz_str_to_z3950oid(global_parameters.odr_out,
+                                    CLASS_RECSYN, recsyn);
+#endif
+        }
         a->u.searchRequest->smallSetUpperBound = &ssub;
         a->u.searchRequest->largeSetLowerBound = &lslb;
         a->u.searchRequest->mediumSetPresentNumber = &mspn;
@@ -276,14 +299,27 @@ static void send_search(IOCHAN i)
     a->u.searchRequest->databaseNames = databaselist;
     a->u.searchRequest->num_databaseNames = ndb;
 
-    if (send_apdu(cl, a) >= 0)
-    {
-       iochan_setflags(i, EVENT_INPUT);
-       cl->state = Client_Searching;
-        cl->requestid = se->requestid;
-    }
-    else
-        cl->state = Client_Error;
+    
+    {  //scope for sending and logging queries 
+        WRBUF wbquery = wrbuf_alloc();
+        yaz_query_to_wrbuf(wbquery, zquery);
+
+        if (send_apdu(cl, a) >= 0)
+            {
+                iochan_setflags(i, EVENT_INPUT);
+                cl->state = Client_Searching;
+                cl->requestid = se->requestid;
+                yaz_log(YLOG_LOG, "SearchRequest %s  %s", 
+                         cl->database->database->url, wrbuf_cstr(wbquery));
+            }
+        else {
+            cl->state = Client_Error;
+                yaz_log(YLOG_WARN, "Failed SearchRequest %s  %s", 
+                         cl->database->database->url, wrbuf_cstr(wbquery));
+        }
+        
+        wrbuf_destroy(wbquery);
+    }    
 
     odr_reset(global_parameters.odr_out);
 }
@@ -312,9 +348,18 @@ static void send_present(IOCHAN i)
     a->u.presentRequest->resultSetId = "Default";
 
     if ((recsyn = session_setting_oneval(sdb, PZ_REQUESTSYNTAX)))
+    {
+#if YAZ_VERSIONL >= 0x020163
         a->u.presentRequest->preferredRecordSyntax =
-                yaz_str_to_z3950oid(global_parameters.odr_out,
-                CLASS_RECSYN, recsyn);
+            yaz_string_to_oid_odr(yaz_oid_std(),
+                                  CLASS_RECSYN, recsyn,
+                                  global_parameters.odr_out);
+#else
+        a->u.presentRequest->preferredRecordSyntax =
+            yaz_str_to_z3950oid(global_parameters.odr_out,
+                                CLASS_RECSYN, recsyn);
+#endif
+    }
 
     if (send_apdu(cl, a) >= 0)
     {