From 2687af689ae79c5a823e28e0ecb3429106df1caa Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 6 Apr 2006 12:04:18 +0000 Subject: [PATCH] Allow client-ip to be logged for each log entry. Speciy client-ip in the configuration. --- NEWS | 3 +++ doc/reference.xml | 9 ++++++++- etc/config.xml | 4 ++-- include/yazproxy/proxy.h | 3 ++- src/yaz-proxy-config.cpp | 4 +++- src/yaz-proxy.cpp | 20 ++++++++++++++------ 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index adfd8fe..e8a6f42 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,7 @@ +Allow client-ip to be logged for each log entry. Speciy +client-ip 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). diff --git a/doc/reference.xml b/doc/reference.xml index bdbb9e3..099fd21 100644 --- a/doc/reference.xml +++ b/doc/reference.xml @@ -703,6 +703,13 @@ and the size of the APDU is logged. + + client-ip + + Log the client IP for each log entry. By default, the client IP + is only logged when a new session starts. + + @@ -817,7 +824,7 @@ - + 30 10 5 - client-requests server-requests + client-requests server-requests client-ip doc diff --git a/include/yazproxy/proxy.h b/include/yazproxy/proxy.h index d50b28a..07d6b08 100644 --- a/include/yazproxy/proxy.h +++ b/include/yazproxy/proxy.h @@ -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. @@ -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_IP_CLIENT 16 class Yaz_usemarcon; class Yaz_ProxyConfig; diff --git a/src/yaz-proxy-config.cpp b/src/yaz-proxy-config.cpp index cccfaf7..ec7e396 100644 --- a/src/yaz-proxy-config.cpp +++ b/src/yaz-proxy-config.cpp @@ -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. @@ -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; + if (m_cp->mycmp(v, "client-ip", len)) + *log_mask |= PROXY_LOG_IP_CLIENT; if (isdigit(*v)) *log_mask |= atoi(v); if (*cp == ',') diff --git a/src/yaz-proxy.cpp b/src/yaz-proxy.cpp index e2195ba..a6930ea 100644 --- a/src/yaz-proxy.cpp +++ b/src/yaz-proxy.cpp @@ -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. @@ -423,10 +423,15 @@ 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); @@ -1829,9 +1834,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); } -- 1.7.10.4