Supply YAZ Proxy version in Z39.50 init responses
[yazproxy-moved-to-github.git] / src / yaz-proxy.cpp
index e2195ba..151a57c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy.cpp,v 1.49 2006-04-06 01:16:55 adam Exp $
+/* $Id: yaz-proxy.cpp,v 1.52 2006-04-06 17:23:14 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -232,8 +232,10 @@ Yaz_Proxy::Yaz_Proxy(IPDU_Observable *the_PDU_Observable,
     m_bw_max = 0;
     m_pdu_max = 0;
     m_search_max = 0;
-    m_connect_max = 0;
+    m_max_connect = 0;
+    m_max_connect_period = 0;
     m_limit_connect = 0;
+    m_limit_connect_period = 0;
     m_timeout_mode = timeout_normal;
     m_timeout_gdu = 0;
     m_max_record_retrieve = 0;
@@ -354,8 +356,12 @@ int Yaz_Proxy::set_config(const char *config)
     m_config_fname = xstrdup(config);
     int r = m_config->read_xml(config);
     if (!r)
+    {
+        int period = 60;
         m_config->get_generic_info(&m_log_mask, &m_max_clients,
-                                   &m_connect_max, &m_limit_connect);
+                                   &m_max_connect, &m_limit_connect, &period);
+        m_connect.set_period(period);
+    }
     return r;
 }
 
@@ -406,8 +412,11 @@ Yaz_ProxyConfig *Yaz_Proxy::check_reconfigure()
             else
             {
                 m_log_mask = 0;
+                int period = 60;
                 cfg->get_generic_info(&m_log_mask, &m_max_clients,
-                                      &m_connect_max, &m_limit_connect);
+                                      &m_max_connect, &m_limit_connect,
+                                      &period);
+                m_connect.set_period(period);
             }
         }
         else
@@ -423,17 +432,22 @@ IPDU_Observer *Yaz_Proxy::sessionNotify(IPDU_Observable
     check_reconfigure();
 
     char session_str[200];
-    sprintf(session_str, "%ld:%d ", (long) time(0), m_session_no);
+    const char *peername = the_PDU_Observable->getpeername();
+    if (m_log_mask & PROXY_LOG_IP_CLIENT)
+        sprintf(session_str, "%ld:%d %s 0 ",
+                (long) time(0), m_session_no, peername);
+    else
+        sprintf(session_str, "%ld:%d 0 ",
+                (long) time(0), m_session_no);        
     m_session_no++;
 
-    const char *peername = the_PDU_Observable->getpeername();
     yaz_log (YLOG_LOG, "%sNew session %s", session_str, peername);
 
     m_connect.cleanup(false);
     m_connect.add_connect(peername);
 
     int connect_total = m_connect.get_total(peername);
-    int connect_max = m_connect_max;
+    int connect_max = m_max_connect;
     if (connect_max && connect_total > connect_max)
     {
         yaz_log(YLOG_LOG, "%sconnect not accepted total=%d max=%d",
@@ -1829,9 +1843,12 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu)
 
 void Yaz_Proxy::inc_request_no()
 {
-    char *cp = strchr(m_session_str, ' ');
-    m_request_no++;
-    if (cp)
+    char *cp = m_session_str + strlen(m_session_str)-1;
+    if (*cp == ' ')
+        cp--;
+    while (*cp && *cp != ' ')
+        cp--;
+    if (*cp)
         sprintf(cp+1, "%d ", m_request_no);
 }
 
@@ -3560,8 +3577,19 @@ void Yaz_ProxyClient::recv_Z_PDU(Z_APDU *apdu, int len)
             *apdu->u.initResponse->maximumRecordSize;
 
         Z_InitResponse *ir = apdu->u.initResponse;
+       
+        // apply YAZ Proxy version
+        char *imv0 = ir->implementationVersion;
+        char *imv1 = (char*)
+            odr_malloc(m_init_odr, 20 + (imv0 ? strlen(imv0) : 0));
+        *imv1 = '\0';
+        if (imv0)
+            strcat(imv1, imv0);
+        strcat(imv1, "/" VERSION);
+        ir->implementationVersion = imv1;
+        
+        // apply YAZ Proxy implementation name
         char *im0 = ir->implementationName;
-
         char *im1 = (char*)
             odr_malloc(m_init_odr, 20 + (im0 ? strlen(im0) : 0));
         *im1 = '\0';