From: erickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Date: Tue, 28 Jun 2005 22:19:08 +0000 (+0000)
Subject: slowly replacing libjson with objson calls..
X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=46373e2c8b7030532cb329366496bfa8aad31b5a;p=working%2FOpenSRF.git

slowly replacing libjson with objson calls..


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

diff --git a/src/libstack/osrf_message.c b/src/libstack/osrf_message.c
index 4d8c152..95b1bba 100644
--- a/src/libstack/osrf_message.c
+++ b/src/libstack/osrf_message.c
@@ -49,10 +49,13 @@ void osrf_message_set_request_info(
 		fatal_handler( "Bad params to osrf_message_set_request_params()" );
 
 	if(msg->parse_json_params) {
-		if( json_params != NULL )
+		if( json_params != NULL ) {
 			msg->params = json_tokener_parse(json_object_to_json_string(json_params));
-		else
+			msg->_params = json_parse_string(json_object_to_json_string(json_params));
+		} else {
 			msg->params = json_tokener_parse("[]");
+			msg->_params = json_parse_string("[]");
+		}
 	}
 
 	msg->method_name = strdup( method_name );
@@ -104,8 +107,14 @@ void osrf_message_set_result_content( osrf_message* msg, char* json_string ) {
 
 	debug_handler( "Message Parse JSON is set to: %d",  msg->parse_json_result );
 
-	if(msg->parse_json_result)
+	if(msg->parse_json_result) {
 		msg->result_content = json_tokener_parse(msg->result_string);
+		msg->_result_content = json_parse_string(msg->result_string);
+
+		char* j = object_to_json(msg->_result_content);
+		debug_handler("PARSE json result content %s", j);
+		free(j);
+	} 
 }
 
 
@@ -123,6 +132,9 @@ void osrf_message_free( osrf_message* msg ) {
 	if( msg->result_content != NULL )
 		json_object_put( msg->result_content );
 
+	if( msg->_result_content != NULL )
+		free_object( msg->_result_content );
+
 	if( msg->result_string != NULL )
 		free( msg->result_string);
 
@@ -132,6 +144,10 @@ void osrf_message_free( osrf_message* msg ) {
 	if( msg->params != NULL )
 		json_object_put( msg->params );
 
+	if( msg->_params != NULL )
+		free_object(msg->_params);
+
+
 	string_array_destroy(msg->parray);
 
 	free(msg);
@@ -236,7 +252,8 @@ char* osrf_message_to_xml( osrf_message* msg ) {
 				if( msg->parse_json_params ) {
 					if( msg->params != NULL ) {
 
-						char* jj = json_object_to_json_string( msg->params );
+						//char* jj = json_object_to_json_string( msg->params );
+						char* jj = msg->_params->to_json(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);
@@ -458,12 +475,14 @@ int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) {
 								//new_msg->params = json_object_new_string( meth_node->children->content );
 								if( new_msg->parse_json_params) {
 									new_msg->params = json_tokener_parse(meth_node->children->content);
+									new_msg->_params = json_parse_string(meth_node->children->content);
 								} else {
 									/* XXX this will have to parse the JSON to 
 										grab the strings for full support! This should only be 
 										necessary for server support of 
 										non-json-param-parsing, though. Ugh. */
 									new_msg->params = json_tokener_parse(meth_node->children->content);
+									new_msg->_params = json_parse_string(meth_node->children->content);
 								}	
 							}
 
diff --git a/src/libstack/osrf_message.h b/src/libstack/osrf_message.h
index ffe94c2..1104fb1 100644
--- a/src/libstack/osrf_message.h
+++ b/src/libstack/osrf_message.h
@@ -66,6 +66,7 @@ struct osrf_message_struct {
 
 	/* if we're a RESULT */
 	json* result_content;
+	object* _result_content;
 
 	/* unparsed json string */
 	char* result_string;
@@ -73,6 +74,7 @@ struct osrf_message_struct {
 	/* if we're a REQUEST */
 	char* method_name;
 	json* params;
+	object* _params;
 
 	/* in case anyone wants to make a list of us.  
 		we won't touch this variable */
diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c
index 9b8fa66..fb6d3cf 100644
--- a/src/srfsh/srfsh.c
+++ b/src/srfsh/srfsh.c
@@ -216,7 +216,20 @@ int handle_login( char* words[]) {
 				"request open-ils.auth open-ils.auth.authenticate.init \"%s\"", username );
 		parse_request(buf); 
 
-		char* hash = json_object_get_string( last_result->result_content );
+		//char* hash = json_object_get_string( last_result->result_content );
+
+		char* hash;
+		if(last_result && last_result->_result_content) {
+			object* r = last_result->_result_content;
+			hash = r->string_data;
+		} else return 0;
+
+		/*
+		fprintf(stderr, "HASHES %s : %s\n", hash, hash2);
+		object* r = last_result->_result_content;
+		fprintf(stderr, "%s\n", r->to_json(r));
+		*/
+
 
 		char* pass_buf = md5sum(password);
 
@@ -227,7 +240,7 @@ int handle_login( char* words[]) {
 		char* mess_buf = md5sum(both_buf);
 
 		sprintf( buf2,
-				"request open-ils.auth open-ils.auth.authenticate.complete \"%s\", \"%s\"", 
+				"request open-ils.auth open-ils.auth.authenticate.complete \"%s\", \"%s\", \"opac\"", 
 				username, mess_buf );
 
 		free(pass_buf);
@@ -235,7 +248,8 @@ int handle_login( char* words[]) {
 
 		parse_request( buf2 );
 
-		login_session = strdup(json_object_get_string( last_result->result_content ));
+		//login_session = strdup(json_object_get_string( last_result->result_content ));
+		login_session = strdup(last_result->_result_content->string_data);
 
 		printf("Login Session: %s\n", login_session );
 		
@@ -469,7 +483,8 @@ int send_request( char* server,
 			if( pretty_print ) 
 				content = json_printer( omsg->result_content );
 			else
-				content = json_object_get_string(omsg->result_content);
+				//content = json_object_get_string(omsg->result_content);
+				content = object_get_string(omsg->_result_content);
 
 			debug_handler("srfsh2");