[Opensrf-commits] r1541 - branches/rel_1_0/src/gateway

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Dec 18 15:54:37 EST 2008


Author: erickson
Date: 2008-12-18 15:54:33 -0500 (Thu, 18 Dec 2008)
New Revision: 1541

Modified:
   branches/rel_1_0/src/gateway/osrf_http_translator.c
Log:
correctly capture the JID of the backend server process for the session cache.  only create a session cache if there is a CONNECT message in the batch.  be more aggressive about removing session caches

Modified: branches/rel_1_0/src/gateway/osrf_http_translator.c
===================================================================
--- branches/rel_1_0/src/gateway/osrf_http_translator.c	2008-12-18 20:49:09 UTC (rev 1540)
+++ branches/rel_1_0/src/gateway/osrf_http_translator.c	2008-12-18 20:54:33 UTC (rev 1541)
@@ -63,8 +63,10 @@
     int complete;
     int timeout;
     int multipart;
-    int connectOnly;
-    int disconnectOnly;
+    int connectOnly; // there is only 1 message, a CONNECT
+    int disconnectOnly; // there is only 1 message, a DISCONNECT
+    int connecting; // there is a connect message in this batch
+    int disconnecting; // there is a connect message in this batch
     int localXid;
 } osrfHttpTranslator;
 
@@ -107,6 +109,8 @@
     trans->complete = 0;
     trans->connectOnly = 0;
     trans->disconnectOnly = 0;
+    trans->connecting = 0;
+    trans->disconnecting = 0;
     trans->remoteHost = apreq->connection->remote_ip;
     trans->messages = NULL;
 
@@ -245,23 +249,35 @@
     int i;
     for(i = 0; i < numMsgs; i++) {
         msg = msgList[i];
-        if(msg->m_type == REQUEST) {
 
-            jsonObject* params = msg->_params;
-            growing_buffer* act = buffer_init(128);	
-            buffer_fadd(act, "[%s] [%s] %s %s", trans->remoteHost, "", trans->service, msg->method_name);
+        switch(msg->m_type) {
 
-            char* str; 
-            int i = 0;
-            while((str = jsonObjectGetString(jsonObjectGetIndex(params, i++)))) {
-                if( i == 1 )
-                    OSRF_BUFFER_ADD(act, " ");
-                else 
-                    OSRF_BUFFER_ADD(act, ", ");
-                OSRF_BUFFER_ADD(act, str);
+            case REQUEST: {
+                jsonObject* params = msg->_params;
+                growing_buffer* act = buffer_init(128);	
+                buffer_fadd(act, "[%s] [%s] %s %s", trans->remoteHost, "", trans->service, msg->method_name);
+
+                char* str; 
+                int i = 0;
+                while((str = jsonObjectGetString(jsonObjectGetIndex(params, i++)))) {
+                    if( i == 1 )
+                        OSRF_BUFFER_ADD(act, " ");
+                    else 
+                        OSRF_BUFFER_ADD(act, ", ");
+                    OSRF_BUFFER_ADD(act, str);
+                }
+                osrfLogActivity(OSRF_LOG_MARK, act->buf);
+                buffer_free(act);
+                break;
             }
-            osrfLogActivity(OSRF_LOG_MARK, act->buf);
-            buffer_free(act);
+
+            case CONNECT:
+                trans->connecting = 1;
+                break;
+
+            case DISCONNECT:
+                trans->disconnecting = 1;
+                break;
         }
     }
 
@@ -303,10 +319,13 @@
     }
 }
 
-static void osrfHttpTranslatorCacheSession(osrfHttpTranslator* trans) {
+/**
+ * Cache the transaction with the JID of the backend process we are talking to
+ */
+static void osrfHttpTranslatorCacheSession(osrfHttpTranslator* trans, const char* jid) {
     jsonObject* cacheObj = jsonNewObject(NULL);
     jsonObjectSetKey(cacheObj, "ip", jsonNewObject(trans->remoteHost));
-    jsonObjectSetKey(cacheObj, "jid", jsonNewObject(trans->recipient));
+    jsonObjectSetKey(cacheObj, "jid", jsonNewObject(jid));
     jsonObjectSetKey(cacheObj, "service", jsonNewObject(trans->service));
     osrfCachePutObject((char*) trans->thread, cacheObj, CACHE_TIME);
 }
@@ -316,6 +335,7 @@
  * Writes a single chunk of multipart/x-mixed-replace content
  */
 static void osrfHttpTranslatorWriteChunk(osrfHttpTranslator* trans, transport_message* msg) {
+    osrfLogInternal(OSRF_LOG_MARK, "sending multipart chunk %s", msg->body);
     ap_rprintf(trans->apreq, 
         "Content-type: %s\n\n%s\n\n", JSON_CONTENT_TYPE, msg->body);
     if(trans->complete)
@@ -347,6 +367,7 @@
 
     if(trans->disconnectOnly) {
         osrfLogDebug(OSRF_LOG_MARK, "exiting early on disconnect");
+        osrfCacheRemove(trans->thread);
         return OK;
     }
 
@@ -357,6 +378,7 @@
 
         if(trans->handle->error) {
             osrfLogError(OSRF_LOG_MARK, "Transport error");
+            osrfCacheRemove(trans->thread);
             return HTTP_INTERNAL_SERVER_ERROR;
         }
 
@@ -365,6 +387,7 @@
 
         if(msg->is_error) {
             osrfLogError(OSRF_LOG_MARK, "XMPP message resulted in error code %d", msg->error_code);
+            osrfCacheRemove(trans->thread);
             return HTTP_NOT_FOUND;
         }
 
@@ -373,7 +396,8 @@
 
         if(firstWrite) {
             osrfHttpTranslatorInitHeaders(trans, msg);
-            osrfHttpTranslatorCacheSession(trans);
+            if(trans->connecting)
+                osrfHttpTranslatorCacheSession(trans, msg->sender);
             firstWrite = 0;
         }
 
@@ -405,6 +429,9 @@
         }
     }
 
+    if(trans->disconnecting) // DISCONNECT within a multi-message batch
+        osrfCacheRemove(trans->thread);
+
     return OK;
 }
 



More information about the opensrf-commits mailing list