[Opensrf-commits] r1360 - trunk/src/gateway

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Jul 8 12:16:23 EDT 2008


Author: erickson
Date: 2008-07-08 12:16:20 -0400 (Tue, 08 Jul 2008)
New Revision: 1360

Modified:
   trunk/src/gateway/osrf_http_translator.c
Log:
fixed broken call to sizeof(). replaced ap_rvputs with more appropriate ap_rprintf.  removed some unnecessary string freeing calls

Modified: trunk/src/gateway/osrf_http_translator.c
===================================================================
--- trunk/src/gateway/osrf_http_translator.c	2008-07-07 15:40:05 UTC (rev 1359)
+++ trunk/src/gateway/osrf_http_translator.c	2008-07-08 16:16:20 UTC (rev 1360)
@@ -69,7 +69,7 @@
  */
 static osrfHttpTranslator* osrfNewHttpTranslator(request_rec* apreq) {
     osrfHttpTranslator* trans;
-    OSRF_MALLOC(trans, sizeof(trans));
+    OSRF_MALLOC(trans, sizeof(osrfHttpTranslator));
     trans->apreq = apreq;
     trans->complete = 0;
     trans->connectOnly = 0;
@@ -120,7 +120,7 @@
     if(trans->delim)
         free(trans->delim);
     osrfListFree(trans->messages);
-    //free(trans); // why does freeing this cause Apache to croak??
+    free(trans);
 }
 
 static void osrfHttpTranslatorDebug(osrfHttpTranslator* trans) {
@@ -168,20 +168,13 @@
                 if(!strcmp(ipAddr, trans->remoteHost) && !strcmp(recipient, trans->recipient)) {
                     osrfLogDebug(OSRF_LOG_MARK, "Found cached session from host %s and recipient %s", 
                         trans->remoteHost, trans->recipient);
-                    jsonObjectFree(sessionCache);
                     stat = 1;
-                     
-                    // XXX free me
                     trans->service = jsonObjectGetString(jsonObjectGetKey(sessionCache, "service"));
 
                 } else {
                     osrfLogError(OSRF_LOG_MARK, 
                         "Session cache for thread %s does not match request", trans->thread);
                 }
-
-                free(ipAddr);
-                free(recipient);
-
             }  else {
                 osrfLogError(OSRF_LOG_MARK, 
                     "attempt to send directly to %s without a session", trans->recipient);
@@ -259,7 +252,7 @@
             osrfCacheRemove(trans->thread);
             return 0;
         }
-
+        // XXX hm, check for explicit status=COMPLETE message instead??
         if(last->status_code != OSRF_STATUS_CONTINUE)
             trans->complete = 1;
     }
@@ -274,7 +267,7 @@
         char buf[strlen(MULTIPART_CONTENT_TYPE) + strlen(trans->delim) + 1];
         sprintf(buf, MULTIPART_CONTENT_TYPE, trans->delim);
 	    ap_set_content_type(trans->apreq, buf);
-        ap_rvputs(trans->apreq, "--%s\n", trans->delim);
+        ap_rprintf(trans->apreq, "--%s\n", trans->delim);
     } else {
 	    ap_set_content_type(trans->apreq, JSON_CONTENT_TYPE);
     }
@@ -293,12 +286,12 @@
  * Writes a single chunk of multipart/x-mixed-replace content
  */
 static void osrfHttpTranslatorWriteChunk(osrfHttpTranslator* trans, transport_message* msg) {
-    ap_rvputs(trans->apreq, 
+    ap_rprintf(trans->apreq, 
         "Content-type: %s\n\n%s\n\n", JSON_CONTENT_TYPE, msg->body);
     if(trans->complete)
-        ap_rvputs(trans->apreq, "--%s--\n", trans->delim);
+        ap_rprintf(trans->apreq, "--%s--\n", trans->delim);
     else
-        ap_rvputs(trans->apreq, "--%s\n", trans->delim);
+        ap_rprintf(trans->apreq, "--%s\n", trans->delim);
     ap_rflush(trans->apreq);
 }
 
@@ -319,7 +312,7 @@
     transport_message* tmsg = message_init(
         trans->body, NULL, trans->thread, trans->recipient, NULL);
     client_send_message(trans->handle, tmsg);
-    message_free(tmsg);
+    message_free(tmsg); 
 
     if(trans->disconnectOnly) {
         osrfLogDebug(OSRF_LOG_MARK, "exiting early on disconnect");
@@ -329,9 +322,7 @@
     // process the response from the opensrf service
     int firstWrite = 1;
     while(!trans->complete) {
-        osrfLogDebug(OSRF_LOG_MARK, "1");
         transport_message* msg = client_recv(trans->handle, trans->timeout);
-        osrfLogDebug(OSRF_LOG_MARK, "2");
 
         if(trans->handle->error) {
             osrfLogError(OSRF_LOG_MARK, "Transport error");
@@ -380,6 +371,7 @@
 
 static void testConnection(request_rec* r) {
 	if(!osrfConnected || !osrfSystemGetTransportClient()) {
+        osrfLogError(OSRF_LOG_MARK, "We're not connected to OpenSRF");
 		ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, "We're not connected to OpenSRF");
 		usleep(100000); // .1 second to prevent process die/start overload
 		exit(1);
@@ -427,10 +419,7 @@
     if(trans->body) {
         stat = osrfHttpTranslatorProcess(trans);
         osrfHttpTranslatorDebug(trans);
-    
         osrfLogInfo(OSRF_LOG_MARK, "translator resulted in status %d", stat);
-    
-        ap_rputs(trans->body, r);
     } else {
         osrfLogWarning(OSRF_LOG_MARK, "no message body to process");
     }



More information about the opensrf-commits mailing list