LP#1268619: websocket : apache gateway minor fixes
authorBill Erickson <berick@esilibrary.com>
Mon, 3 Mar 2014 15:05:26 +0000 (10:05 -0500)
committerGalen Charlton <gmc@esilibrary.com>
Tue, 19 Aug 2014 22:50:48 +0000 (15:50 -0700)
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 <berick@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

include/opensrf/log.h
src/gateway/osrf_websocket_translator.c
src/libopensrf/log.c

index 71b0d60..78ba808 100644 (file)
@@ -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 );
 
index 6a0caac..7aa8676 100644 (file)
  * export OSRF_WEBSOCKET_CONFIG_CTXT=gateway
  */
 
-/**
- * TODO:
- * short-timeout mode for brick detachment where inactivity timeout drops way 
- * down for graceful disconnects.
- */
-
 #include <stdlib.h>
 #include <signal.h>
 #include <unistd.h>
@@ -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)); 
 }
 
 /**
index f298c65..27eb6f3 100644 (file)
@@ -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);
 }