added some debugging
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Sat, 9 Apr 2005 03:51:44 +0000 (03:51 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Sat, 9 Apr 2005 03:51:44 +0000 (03:51 +0000)
added the ability to not automatically parse json in inbound messages
fixed some typos and logic errors

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@269 9efc2488-bf62-4759-914b-345cdb29e865

src/libstack/osrf_app_session.c
src/libstack/osrf_message.c
src/libstack/osrf_stack.c

index e2efcce..27a3a04 100644 (file)
@@ -65,6 +65,7 @@ void osrf_app_session_request_finish(
                osrf_app_session* session, int req_id ){
 
        if(session == NULL) return;
+       debug_handler("Finishing request %d", req_id );
        osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
        if(req == NULL) return;
        _osrf_app_session_remove_request( req->session, req );
@@ -83,9 +84,9 @@ osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout ) {
        if( req->result != NULL ) {
                debug_handler("app_request receive already has a message, returning it");
                /* pop off the first message in the list */
-               osrf_message* tmp_msg = req->result->next;
-               req->result = tmp_msg;
-               return req->result;
+               osrf_message* tmp_msg = req->result;
+               req->result = req->result->next;
+               return tmp_msg;
        }
 
        time_t start = time(NULL);      
@@ -125,6 +126,7 @@ osrf_message* _osrf_app_request_recv( osrf_app_request* req, int timeout ) {
                remaining -= (int) (time(NULL) - start);
        }
 
+       debug_handler("Returning NULL from app_request_recv after timeout");
        return NULL;
 }
 
@@ -447,8 +449,6 @@ int osrf_app_session_push_queue(
                return 0;
        }
 
-       debug_handler( "The first request in the request queue has tt [%d]", req->request_id );
-
        while( req != NULL ) {
                if(req->request_id == msg->thread_trace) {
                        debug_handler( "Found app_request for tt [%d]", msg->thread_trace );
@@ -523,6 +523,7 @@ int osrf_app_session_disconnect( osrf_app_session* session){
 }
 
 int osrf_app_session_request_resend( osrf_app_session* session, int req_id ) {
+       debug_handler("In reqeust resend searching for resend-able messages");
        osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
        return _osrf_app_request_resend( req );
 }
@@ -605,6 +606,7 @@ osrf_message* osrf_app_session_request_recv(
                osrf_app_session* session, int req_id, int timeout ) {
        if(req_id < 0 || session == NULL)
                return NULL;
+       debug_handler("somebody callled recv");
        osrf_app_request* req = _osrf_app_session_get_request( session, req_id );
        return _osrf_app_request_recv( req, timeout );
 }
index c580f95..9b937a5 100644 (file)
@@ -1,5 +1,7 @@
 #include "opensrf/osrf_message.h"
 
+/* default to true */
+int parse_json = 1;
 
 osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol ) {
 
@@ -9,11 +11,17 @@ osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protoco
        msg->protocol = protocol;
        msg->next = NULL;
        msg->is_exception = 0;
+       msg->parse_json = parse_json;
 
        return msg;
 }
 
 
+void osrf_message_set_json_parse( int ibool ) {
+       parse_json = ibool;
+}
+
+
 void osrf_message_set_request_info( osrf_message* msg, char* method_name, json* json_params ) {
        if( msg == NULL || method_name == NULL )
                fatal_handler( "Bad params to osrf_message_set_request_params()" );
@@ -44,12 +52,17 @@ void osrf_message_set_status_info(
 }
 
 
-void osrf_message_set_result_content( osrf_message* msg, json* result_content ) {
-       if( msg == NULL )
-               fatal_handler( "Bad params to osrf_message_set_result_content()" );
-       msg->result_string =    strdup(json_object_to_json_string(result_content));
+void osrf_message_set_result_content( osrf_message* msg, char* json_string ) {
+       if( msg == NULL || json_string == NULL)
+               warning_handler( "Bad params to osrf_message_set_result_content()" );
+
+       msg->result_string =    strdup(json_string);
        debug_handler("Setting result_string to %s\n", msg->result_string );
-       msg->result_content = json_tokener_parse(msg->result_string);
+
+       debug_handler( "Message Parse JSON is set to: %d",  msg->parse_json );
+
+       if(msg->parse_json)
+               msg->result_content = json_tokener_parse(msg->result_string);
 }
 
 
@@ -289,6 +302,7 @@ int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) {
 
                xmlNodePtr cur_node = message_node->children;
                osrf_message* new_msg = safe_malloc(sizeof(osrf_message));
+               new_msg->parse_json = parse_json;
        
 
                while( cur_node ) {
@@ -395,8 +409,7 @@ int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) {
                                                                xmlChar* r_name = xmlGetProp( result_nodes, BAD_CAST "name" );
                                                                if(r_name) {
                                                                        if( !strcmp((char*)r_name,"oilsScalar") && result_nodes->children->content ) {
-                                                                               new_msg->result_string = strdup(result_nodes->children->content);
-                                                                               new_msg->result_content = json_tokener_parse(result_nodes->children->content);
+                                                                               osrf_message_set_result_content( new_msg, result_nodes->children->content);
                                                                        }
                                                                        xmlFree(r_name);
                                                                }
index 57fa8f7..f4b6fda 100644 (file)
@@ -6,13 +6,19 @@ osrf_message* _do_server( osrf_app_session*, osrf_message* );
 int osrf_stack_process( transport_client* client, int timeout ) {
        transport_message* msg = client_recv( client, timeout );
        if(msg == NULL) return 0;
+       debug_handler( "Received message from transport code from %s", msg->sender );
        int status = osrf_stack_transport_handler( msg );
 
        /* see if there are multiple message to be received */
        while(1) {
                transport_message* m = client_recv( client, 0 );
-               if(m) status = osrf_stack_transport_handler( m );
-               else break;
+               if(m) {
+                       debug_handler( "Received additional message from transport code from %s", msg->sender );
+                       status = osrf_stack_transport_handler( m );
+               } else  {
+                       debug_handler( "osrf_stack_process returning with only 1 received message" );
+                       break;
+               }
        }
 
        return status;