Fix attribute type checking
[yazpp-moved-to-github.git] / src / yaz-proxy.cpp
index 996f258..5864a12 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright (c) 1998-2003, Index Data.
  * See the file LICENSE for details.
  * 
- * $Id: yaz-proxy.cpp,v 1.63 2003-10-20 18:31:44 adam Exp $
+ * $Id: yaz-proxy.cpp,v 1.69 2003-10-23 13:59:37 adam Exp $
  */
 
 #include <assert.h>
@@ -72,7 +72,7 @@ Yaz_Proxy::Yaz_Proxy(IYaz_PDU_Observable *the_PDU_Observable,
     m_client_idletime = 600;
     m_target_idletime = 600;
     m_optimize = xstrdup ("1");
-    strcpy(m_session_str, "0");
+    strcpy(m_session_str, "0 ");
     m_session_no=0;
     m_bytes_sent = m_bytes_recv = 0;
     m_bw_hold_PDU = 0;
@@ -355,9 +355,8 @@ Yaz_ProxyClient *Yaz_Proxy::get_client(Z_APDU *apdu)
                !strcmp(m_proxyTarget, c->get_hostname()))
            {
                // found it in cache
-               yaz_log (LOG_LOG, "%sREUSE %d %d %s",
-                        m_session_str,
-                        c->m_seqno, parent->m_seqno, c->get_hostname());
+               yaz_log (LOG_LOG, "%sREUSE %s",
+                        m_session_str, c->get_hostname());
                
                c->m_seqno = parent->m_seqno;
                assert(c->m_server == 0);
@@ -665,7 +664,6 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu)
     if (apdu->which == Z_APDU_presentRequest)
     {
        Z_PresentRequest *pr = apdu->u.presentRequest;
-       Z_NamePlusRecordList *npr;
        int toget = *pr->numberOfRecordsRequested;
        int start = *pr->resultSetStartPoint;
 
@@ -684,6 +682,7 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu)
            send_to_client(new_apdu);
            return 0;
        }
+#if 0
        if (!strcmp(m_client->m_last_resultSetId, pr->resultSetId))
        {
            if (start+toget-1 > m_client->m_last_resultCount)
@@ -717,6 +716,7 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu)
                return 0;
            }
        }
+#endif
     }
 
     if (apdu->which != Z_APDU_searchRequest)
@@ -1010,37 +1010,34 @@ Z_APDU *Yaz_Proxy::handle_syntax_validation(Z_APDU *apdu)
     if (apdu->which == Z_APDU_searchRequest)
     {
        Z_SearchRequest *sr = apdu->u.searchRequest;
-       if (*sr->smallSetUpperBound > 0 || *sr->mediumSetPresentNumber > 0)
+       int err = 0;
+       char *addinfo = 0;
+       Yaz_ProxyConfig *cfg = check_reconfigure();
+       
+       if (cfg)
+           err = cfg->check_syntax(odr_encode(),
+                                   m_default_target,
+                                   sr->preferredRecordSyntax,
+                                   &addinfo);
+       if (err == -1)
        {
-           int err = 0;
-           char *addinfo = 0;
-           Yaz_ProxyConfig *cfg = check_reconfigure();
-
-           if (cfg)
-               err = cfg->check_syntax(odr_encode(),
-                                       m_default_target,
-                                       sr->preferredRecordSyntax,
-                                       &addinfo);
-           if (err == -1)
-           {
-               sr->preferredRecordSyntax =
-                   yaz_oidval_to_z3950oid(odr_decode(), CLASS_RECSYN,
-                                          VAL_USMARC);
-               m_marcxml_flag = 1;
-           }
-           else if (err)
-           {
-               Z_APDU *new_apdu = create_Z_PDU(Z_APDU_searchResponse);
-               
-               new_apdu->u.searchResponse->referenceId = sr->referenceId;
-               new_apdu->u.searchResponse->records =
-                   create_nonSurrogateDiagnostics(odr_encode(), err, addinfo);
-               *new_apdu->u.searchResponse->searchStatus = 0;
-               
-               send_to_client(new_apdu);
-               
-               return 0;
-           }
+           sr->preferredRecordSyntax =
+               yaz_oidval_to_z3950oid(odr_decode(), CLASS_RECSYN,
+                                      VAL_USMARC);
+           m_marcxml_flag = 1;
+       }
+       else if (err)
+       {
+           Z_APDU *new_apdu = create_Z_PDU(Z_APDU_searchResponse);
+           
+           new_apdu->u.searchResponse->referenceId = sr->referenceId;
+           new_apdu->u.searchResponse->records =
+               create_nonSurrogateDiagnostics(odr_encode(), err, addinfo);
+           *new_apdu->u.searchResponse->searchStatus = 0;
+           
+           send_to_client(new_apdu);
+           
+           return 0;
        }
     }
     else if (apdu->which == Z_APDU_presentRequest)
@@ -1343,8 +1340,8 @@ void Yaz_Proxy::pre_init()
                            other++;
                    }
                }
-               yaz_log(LOG_LOG, "%s pre-init %s %s use=%d other=%d spare=%d preinit=%d",
-                       m_session_str,
+               yaz_log(LOG_LOG, "%spre-init %s %s use=%d other=%d spare=%d "
+                       "preinit=%d",m_session_str,
                        name, zurl_in_use[j], in_use, other, spare, pre_init);
                if (spare < pre_init)
                {
@@ -1532,10 +1529,14 @@ void Yaz_ProxyClient::recv_Z_PDU(Z_APDU *apdu, int len)
     }
 }
 
-void Yaz_Proxy::server(const char *addr)
+int Yaz_Proxy::server(const char *addr)
 {
-    Yaz_Z_Assoc::server(addr);
-
-    timeout(1);
+    int r = Yaz_Z_Assoc::server(addr);
+    if (!r)
+    {
+       yaz_log(LOG_LOG, "%sStarted listener on %s", m_session_str, addr);
+       timeout(1);
+    }
+    return r;
 }