From e375a1e31b87a3d645b6da05e83f2a29f885f1fc Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 3 Mar 2014 10:05:26 -0500 Subject: [PATCH] LP#1268619: websocket : apache gateway minor fixes Replace remaining remote_ip calls with a get_client_ip() function which operates for apache2 and apache4. Make log functions for applying a log trace value accept const char*'s Signed-off-by: Bill Erickson Signed-off-by: Galen Charlton --- include/opensrf/log.h | 4 ++-- src/gateway/osrf_websocket_translator.c | 27 ++++++++++--------------- src/libopensrf/log.c | 4 ++-- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/include/opensrf/log.h b/include/opensrf/log.h index 71b0d60..78ba808 100644 --- a/include/opensrf/log.h +++ b/include/opensrf/log.h @@ -107,9 +107,9 @@ void osrfLogCleanup( void ); void osrfLogClearXid( void ); -void osrfLogSetXid(char* xid); +void osrfLogSetXid(const char* xid); -void osrfLogForceXid(char* xid); +void osrfLogForceXid(const char* xid); void osrfLogMkXid( void ); diff --git a/src/gateway/osrf_websocket_translator.c b/src/gateway/osrf_websocket_translator.c index 6a0caac..7aa8676 100644 --- a/src/gateway/osrf_websocket_translator.c +++ b/src/gateway/osrf_websocket_translator.c @@ -68,12 +68,6 @@ * export OSRF_WEBSOCKET_CONFIG_CTXT=gateway */ -/** - * TODO: - * short-timeout mode for brick detachment where inactivity timeout drops way - * down for graceful disconnects. - */ - #include #include #include @@ -111,6 +105,14 @@ static void sigusr1_handler(int sig) { osrfLogInfo(OSRF_LOG_MARK, "WS received SIGUSR1 - Graceful Shutdown"); } +static const char* get_client_ip(const request_rec* r) { +#ifdef APACHE_MIN_24 + return r->connection->client_ip; +#else + return r->connection->remote_ip; +#endif +} + typedef struct _osrfWebsocketTranslator { /** Our handle for communicating with the caller */ @@ -603,12 +605,7 @@ void* CALLBACK on_connect_handler(const WebSocketServer *server) { apr_thread_t *thread = NULL; apr_threadattr_t *thread_attr = NULL; -#ifdef APACHE_MIN_24 - char* client_ip = r->connection->client_ip; -#else - char* client_ip = r->connection->remote_ip; -#endif - + const char* client_ip = get_client_ip(r); osrfLogInfo(OSRF_LOG_MARK, "WS connect from %s", client_ip); if (!trans) { @@ -674,7 +671,7 @@ static char* extract_inbound_messages( growing_buffer* act = buffer_init(128); char* method = msg->method_name; buffer_fadd(act, "[%s] [%s] %s %s", - r->connection->remote_ip, "", service, method); + get_client_ip(r), "", service, method); const jsonObject* obj = NULL; int i = 0; @@ -880,9 +877,7 @@ void CALLBACK on_disconnect_handler( request_rec *r = server->request(server); - osrfLogInfo(OSRF_LOG_MARK, - "WS disconnect from %s", r->connection->remote_ip); - //"WS disconnect from %s", r->connection->client_ip); // apache 2.4 + osrfLogInfo(OSRF_LOG_MARK, "WS disconnect from %s", get_client_ip(r)); } /** diff --git a/src/libopensrf/log.c b/src/libopensrf/log.c index f298c65..27eb6f3 100644 --- a/src/libopensrf/log.c +++ b/src/libopensrf/log.c @@ -126,7 +126,7 @@ void osrfLogClearXid( void ) { _osrfLogSetXid(""); } @brief Store a transaction id, unless running as a client process. @param xid Pointer to the new transaction id */ -void osrfLogSetXid(char* xid) { +void osrfLogSetXid(const char* xid) { if(!_osrfLogIsClient) _osrfLogSetXid(xid); } @@ -134,7 +134,7 @@ void osrfLogSetXid(char* xid) { @brief Store a transaction id for future use, whether running as a client or as a server. @param xid Pointer to the new transaction id */ -void osrfLogForceXid(char* xid) { +void osrfLogForceXid(const char* xid) { _osrfLogSetXid(xid); } -- 2.43.2