Allow client-ip to be logged for each log entry. Speciy
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 6 Apr 2006 12:04:18 +0000 (12:04 +0000)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 6 Apr 2006 12:04:18 +0000 (12:04 +0000)
<log>client-ip</log> in the configuration.

NEWS
doc/reference.xml
etc/config.xml
include/yazproxy/proxy.h
src/yaz-proxy-config.cpp
src/yaz-proxy.cpp

diff --git a/NEWS b/NEWS
index adfd8fe..e8a6f42 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,7 @@
 
 
+Allow client-ip to be logged for each log entry. Speciy
+<log>client-ip</log> in the configuration.
+
 Added support for limiting the number of initiating connections
 from a single IP. limit-connect specifies a limit and if that
 is reached a delay is introduced (just as limit-pdu, etc).
 Added support for limiting the number of initiating connections
 from a single IP. limit-connect specifies a limit and if that
 is reached a delay is introduced (just as limit-pdu, etc).
index bdbb9e3..099fd21 100644 (file)
          and the size of the APDU is logged.
         </entry>
        </row>
          and the size of the APDU is logged.
         </entry>
        </row>
+       <row>
+        <entry><literal>client-ip</literal></entry>
+        <entry>
+         Log the client IP for each log entry. By default, the client IP
+         is only logged when a new session starts.
+        </entry>
+       </row>
        </tbody>
       </tgroup>
      </table>
        </tbody>
       </tgroup>
      </table>
    <screen><![CDATA[
 <?xml version="1.0"?>
 <!-- XML Schema for YAZ proxy config file.
    <screen><![CDATA[
 <?xml version="1.0"?>
 <!-- XML Schema for YAZ proxy config file.
-    $Id: reference.xml,v 1.16 2006-04-06 10:30:16 adam Exp $
+    $Id: reference.xml,v 1.17 2006-04-06 12:04:19 adam Exp $
 -->
 <xs:schema
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
 -->
 <xs:schema
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
index a709758..7b3cf3c 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
 <?xml version="1.0"?>
-<!-- $Id: config.xml,v 1.17 2006-04-06 01:16:54 adam Exp $ -->
+<!-- $Id: config.xml,v 1.18 2006-04-06 12:04:19 adam Exp $ -->
 <proxy xmlns="http://indexdata.dk/yazproxy/schema/0.9/"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 <proxy xmlns="http://indexdata.dk/yazproxy/schema/0.9/"
  xmlns:xi="http://www.w3.org/2001/XInclude"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -50,6 +50,6 @@
   <max-clients>30</max-clients>
   <max-connect>10</max-connect>
   <limit-connect>5</limit-connect>
   <max-clients>30</max-clients>
   <max-connect>10</max-connect>
   <limit-connect>5</limit-connect>
-  <log>client-requests server-requests</log>
+  <log>client-requests server-requests client-ip</log>
   <docpath>doc</docpath>
 </proxy>
   <docpath>doc</docpath>
 </proxy>
index d50b28a..07d6b08 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: proxy.h,v 1.30 2006-04-06 01:16:55 adam Exp $
+/* $Id: proxy.h,v 1.31 2006-04-06 12:04:19 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -41,6 +41,7 @@ class Yaz_Proxy;
 #define PROXY_LOG_APDU_SERVER 2
 #define PROXY_LOG_REQ_CLIENT 4
 #define PROXY_LOG_REQ_SERVER 8
 #define PROXY_LOG_APDU_SERVER 2
 #define PROXY_LOG_REQ_CLIENT 4
 #define PROXY_LOG_REQ_SERVER 8
+#define PROXY_LOG_IP_CLIENT 16
 
 class Yaz_usemarcon;
 class Yaz_ProxyConfig;
 
 class Yaz_usemarcon;
 class Yaz_ProxyConfig;
index cccfaf7..ec7e396 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: yaz-proxy-config.cpp,v 1.28 2006-04-06 01:20:02 adam Exp $
+/* $Id: yaz-proxy-config.cpp,v 1.29 2006-04-06 12:04:19 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -1037,6 +1037,8 @@ void Yaz_ProxyConfig::get_generic_info(int *log_mask,
                     *log_mask |= PROXY_LOG_REQ_CLIENT;
                 if (m_cp->mycmp(v, "server-requests", len))
                     *log_mask |= PROXY_LOG_REQ_SERVER;
                     *log_mask |= PROXY_LOG_REQ_CLIENT;
                 if (m_cp->mycmp(v, "server-requests", len))
                     *log_mask |= PROXY_LOG_REQ_SERVER;
+                if (m_cp->mycmp(v, "client-ip", len))
+                    *log_mask |= PROXY_LOG_IP_CLIENT;
                 if (isdigit(*v))
                     *log_mask |= atoi(v);
                 if (*cp == ',')
                 if (isdigit(*v))
                     *log_mask |= atoi(v);
                 if (*cp == ',')
index e2195ba..a6930ea 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.50 2006-04-06 12:04:20 adam Exp $
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
    Copyright (c) 1998-2006, Index Data.
 
 This file is part of the yazproxy.
@@ -423,10 +423,15 @@ IPDU_Observer *Yaz_Proxy::sessionNotify(IPDU_Observable
     check_reconfigure();
 
     char session_str[200];
     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++;
 
     m_session_no++;
 
-    const char *peername = the_PDU_Observable->getpeername();
     yaz_log (YLOG_LOG, "%sNew session %s", session_str, peername);
 
     m_connect.cleanup(false);
     yaz_log (YLOG_LOG, "%sNew session %s", session_str, peername);
 
     m_connect.cleanup(false);
@@ -1829,9 +1834,12 @@ Z_APDU *Yaz_Proxy::result_set_optimize(Z_APDU *apdu)
 
 void Yaz_Proxy::inc_request_no()
 {
 
 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);
 }
 
         sprintf(cp+1, "%d ", m_request_no);
 }