added stateless hack for now
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 8 Jun 2005 20:31:04 +0000 (20:31 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 8 Jun 2005 20:31:04 +0000 (20:31 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@335 9efc2488-bf62-4759-914b-345cdb29e865

src/libstack/Makefile
src/libstack/osrf_app_session.c
src/libstack/osrf_message.c

index 0808631..c3dd937 100644 (file)
@@ -1,5 +1,5 @@
 LIB_DIR = ../../lib
-CC_OPTS = -Wall -O2 -I /usr/include/libxml2 -I /usr/include/libxml2/libxml -I ../../include -fPIC 
+CC_OPTS = -Wall -O2 -I /usr/include/libxml2 -I /usr/include/libxml2/libxml -I ../../include -fPIC -DASSUME_STATELESS
 LIB_SOURCES = osrf_message.c osrf_app_session.c osrf_stack.c osrf_system.c string_array.c
 LIB_TARGETS = osrf_message.o osrf_app_session.o osrf_stack.o osrf_system.o string_array.o
 EXE_LD_OPTS = -L $(LIB_DIR) -lxml2 -lopensrf_transport  -lopensrf_stack -lobjson -ljson 
index f4c7b6d..22bea76 100644 (file)
@@ -243,10 +243,17 @@ osrf_app_session* osrf_app_client_session_init( char* remote_service ) {
        session->orig_remote_id = strdup(session->remote_id);
        session->remote_service = strdup(remote_service);
 
+       #ifdef ASSUME_STATELESS
+       session->stateless = 1;
+       debug_handler("session is stateless");
+       #else
+       session->stateless = 0;
+       debug_handler("session is NOT stateless");
+       #endif
+
        /* build a chunky, random session id */
        char id[256];
        memset(id,0,256);
-       //srand((int)time(NULL));
 
        sprintf(id, "%lf.%d%d", get_timestamp_millis(), (int)time(NULL), getpid());
        session->session_id = strdup(id);
@@ -282,6 +289,12 @@ osrf_app_session* osrf_app_server_session_init(
        session->session_id = strdup(session_id);
        session->remote_service = strdup(remote_service);
 
+       #ifdef ASSUME_STATELESS
+       session->stateless = 1;
+       #else
+       session->stateless = 0;
+       #endif
+
        debug_handler( "Building a new server session [%s] with id [%s]", 
                        session->remote_service,  session_id );
 
@@ -528,6 +541,14 @@ int osrf_app_session_disconnect( osrf_app_session* session){
 
        if(session->state == OSRF_SESSION_DISCONNECTED)
                return 1;
+
+       if(session->stateless && session->state != OSRF_SESSION_CONNECTED) {
+               debug_handler(
+                               "Exiting disconnect on stateless session %s", 
+                               session->session_id);
+               return 1;
+       }
+
        debug_handler( "AppSession disconnecting from %s", session->remote_id );
 
        osrf_message* dis_msg = osrf_message_init( DISCONNECT, session->thread_trace, 1 );
@@ -554,10 +575,16 @@ int _osrf_app_session_send( osrf_app_session* session, osrf_message* msg ){
        debug_handler( "AppSession sending type %d, and thread_trace %d",
                        msg->m_type, msg->thread_trace );
 
-       if( (msg->m_type != CONNECT) && (msg->m_type != DISCONNECT) &&
-                       (session->state != OSRF_SESSION_CONNECTED) ) {
-               if(!osrf_app_session_connect( session )) 
-                       return 0;
+       if(session->stateless) {
+               osrf_app_session_reset_remote(session);
+
+       } else {
+
+               if( (msg->m_type != CONNECT) && (msg->m_type != DISCONNECT) &&
+                               (session->state != OSRF_SESSION_CONNECTED) ) {
+                       if(!osrf_app_session_connect( session )) 
+                               return 0;
+               }
        }
 
        char* xml =  osrf_message_to_xml(msg);
index cebdf5d..873826f 100644 (file)
@@ -1,5 +1,9 @@
 #include "opensrf/osrf_message.h"
 
+#include "utils.h"
+#include "objson/object.h"
+#include "objson/json_parser.h"
+
 /* default to true */
 int parse_json_result = 1;
 int parse_json_params = 1;
@@ -89,6 +93,18 @@ void osrf_message_set_result_content( osrf_message* msg, char* json_string ) {
 
        msg->result_string =    strdup(json_string);
 
+       /* ----------------------------------------------------- */
+       object* o = json_parse_string(json_string);
+       char* string = o->to_json(o);
+       debug_handler("---------------------------------------------------");
+       debug_handler("Parsed JSON string \n%s\n", string);
+       if(o->classname)
+               debug_handler("Class is %s\n", o->classname);
+       debug_handler("---------------------------------------------------");
+       free_object(o);
+       free(string);
+       /* ----------------------------------------------------- */
+
        debug_handler( "Message Parse JSON is set to: %d",  msg->parse_json_result );
 
        if(msg->parse_json_result)
@@ -222,9 +238,13 @@ char* osrf_message_to_xml( osrf_message* msg ) {
 
                                if( msg->parse_json_params ) {
                                        if( msg->params != NULL ) {
-                                               params_node = xmlNewChild( method_node, NULL, 
-                                                       BAD_CAST "params", BAD_CAST json_object_to_json_string( msg->params ) );
+
+                                               char* jj = json_object_to_json_string( msg->params );
+                                               params_node = xmlNewChild( method_node, NULL, BAD_CAST "params", NULL );
+                                               xmlNodePtr tt = xmlNewDocTextLen( doc, BAD_CAST jj, strlen(jj) );
+                                               xmlAddChild(params_node, tt);
                                        }
+
                                } else {
                                        if( msg->parray != NULL ) {