#include "opensrf/generic_utils.h"
#include "osrf_message.h"
#include "osrf_system.h"
+#include "opensrf/string_array.h"
#ifndef OSRF_APP_SESSION
#define OSRF_APP_SESSION
* requeset.
*/
int osrf_app_session_make_request(
- osrf_app_session* session, json* params, char* method_name, int protocol );
+ osrf_app_session* session, json* params,
+ char* method_name, int protocol, string_array* arr );
/** Sets the given request to complete state */
void osrf_app_session_set_complete( osrf_app_session* session, int request_id );
#include "libjson/json.h"
#include "opensrf/generic_utils.h"
+#include "opensrf/string_array.h"
#ifndef osrf_message_h
#define osrf_message_h
enum M_TYPE { CONNECT, REQUEST, RESULT, STATUS, DISCONNECT };
+#define OSRF_MAX_PARAMS 128;
+
struct osrf_message_struct {
enum M_TYPE m_type;
int thread_trace;
int protocol;
- int parse_json;
+ int parse_json_result;
+ int parse_json_params;
/* if we're a STATUS message */
char* status_name;
we won't touch this variable */
struct osrf_message_struct* next;
+ string_array* parray;
+ char* full_param_string;
+
};
typedef struct osrf_message_struct osrf_message;
/* decides whether all message automatically parse incoming json data */
/* to change a single message, set msg->parse_json accordingly */
-void osrf_message_set_json_parse( int bool );
+//void osrf_message_set_json_parse( int bool );
+
+void osrf_message_set_json_parse_result( int ibool );
+void osrf_message_set_json_parse_params( int ibool );
+
+
+void osrf_message_add_param( osrf_message*, char* param_string );
#include "opensrf/generic_utils.h"
#include "opensrf/osrf_message.h"
#include "opensrf/osrf_app_session.h"
+#include "opensrf/string_array.h"
#include "md5.h"
/*
}
/* we don't want to waste time parsing json that we're not going to look at*/
- osrf_message_set_json_parse(0);
+ osrf_message_set_json_parse_result(0);
+ osrf_message_set_json_parse_params(0);
fprintf(stderr, "Bootstrapping %d\n", getpid() );
fflush(stderr);
}
char* service = NULL; /* service to connect to */
char* method = NULL; /* method to perform */
- json* params = NULL; /* method parameters */
json* exception = NULL; /* returned in error conditions */
+ string_array* sarray = init_string_array(12); /* method parameters */
growing_buffer* buffer = NULL; /* POST data */
growing_buffer* tmp_buf = NULL; /* temp buffer */
char* argcopy = (char*) apr_pstrdup(p, arg);
- params = json_object_new_array();;
while( argcopy && (val = ap_getword(p, &argcopy, '&'))) {
key = ap_getword(r->pool,&val, '=');
method = val;
if(!strcmp(key,"__param"))
- json_object_array_add( params, json_tokener_parse(val));
+ string_array_add(sarray, val);
+
}
- info_handler("Performing(%d): service %s | method %s | \nparams %s\n\n",
- getpid(), service, method, json_object_to_json_string(params));
+ info_handler("Performing(%d): service %s | method %s | \n",
+ getpid(), service, method );
+
+ int k;
+ for( k = 0; k!= sarray->size; k++ ) {
+ info_handler( "param %s", string_array_get_string(sarray,k));
+ }
osrf_app_session* session = find_session(service,1);
return OK;
}
- int req_id = osrf_app_session_make_request( session, params, method, 1 );
- json_object_put(params);
+ int req_id = osrf_app_session_make_request( session, NULL, method, 1, sarray );
+ string_array_destroy(sarray);
osrf_message* omsg = NULL;
LIB_DIR = ../../lib
CC_OPTS = -Wall -O2 -I /usr/include/libxml2 -I /usr/include/libxml2/libxml -I ../../include -fPIC
-LIB_SOURCES = osrf_message.c osrf_app_session.c osrf_stack.c osrf_system.c
-LIB_TARGETS = osrf_message.o osrf_app_session.o osrf_stack.o osrf_system.o
+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 -ljson
CC = gcc
int osrf_app_session_make_request(
- osrf_app_session* session, json* params, char* method_name, int protocol ) {
+ osrf_app_session* session, json* params,
+ char* method_name, int protocol, string_array* param_strings ) {
if(session == NULL) return -1;
osrf_message* req_msg = osrf_message_init( REQUEST, ++(session->thread_trace), protocol );
osrf_message_set_request_info( req_msg, method_name, params );
+
+ /* if we're not parsing the json, shove the strings in manually */
+ if(!req_msg->parse_json_params && param_strings) {
+ int i;
+ for(i = 0; i!= param_strings->size ; i++ ) {
+ osrf_message_add_param(req_msg,
+ string_array_get_string(param_strings,i));
+ }
+ }
+
osrf_app_request* req = _osrf_app_request_init( session, req_msg );
if(!_osrf_app_session_send( session, req_msg ) ) {
warning_handler( "Error sending request message [%d]", session->thread_trace );
#include "opensrf/osrf_message.h"
/* default to true */
-int parse_json = 1;
+int parse_json_result = 1;
+int parse_json_params = 1;
osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol ) {
- osrf_message* msg = safe_malloc(sizeof(osrf_message));
- msg->m_type = type;
- msg->thread_trace = thread_trace;
- msg->protocol = protocol;
- msg->next = NULL;
- msg->is_exception = 0;
- msg->parse_json = parse_json;
+ osrf_message* msg = (osrf_message*) safe_malloc(sizeof(osrf_message));
+ msg->m_type = type;
+ msg->thread_trace = thread_trace;
+ msg->protocol = protocol;
+ msg->next = NULL;
+ msg->is_exception = 0;
+ msg->parse_json_result = parse_json_result;
+ msg->parse_json_params = parse_json_params;
+ msg->parray = init_string_array(16); /* start out with a slot for 16 params. can grow */
+ msg->params = NULL;
+ msg->full_param_string = NULL;
return msg;
}
-void osrf_message_set_json_parse( int ibool ) {
- parse_json = ibool;
+void osrf_message_set_json_parse_result( int ibool ) {
+ parse_json_result = ibool;
}
+void osrf_message_set_json_parse_params( int ibool ) {
+ parse_json_params = ibool;
+}
+
+void osrf_message_set_request_info(
+ osrf_message* msg, char* method_name, json* json_params ) {
-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()" );
- if( json_params != NULL )
- msg->params = json_tokener_parse(json_object_to_json_string(json_params));
- else
- msg->params = json_tokener_parse("[]");
+ if(msg->parse_json_params) {
+ if( json_params != NULL )
+ msg->params = json_tokener_parse(json_object_to_json_string(json_params));
+ else
+ msg->params = json_tokener_parse("[]");
+ }
msg->method_name = strdup( method_name );
}
+/* only works of parse_json_params is false */
+void osrf_message_add_param( osrf_message* msg, char* param_string ) {
+ if(msg == NULL || param_string == NULL)
+ return;
+ if(!msg->parse_json_params)
+ string_array_add(msg->parray, param_string);
+}
+
void osrf_message_set_status_info(
osrf_message* msg, char* status_name, char* status_text, int status_code ) {
msg->result_string = strdup(json_string);
debug_handler("Setting result_string to %s\n", msg->result_string );
- debug_handler( "Message Parse JSON is set to: %d", msg->parse_json );
+ debug_handler( "Message Parse JSON is set to: %d", msg->parse_json_result );
- if(msg->parse_json)
+ if(msg->parse_json_result)
msg->result_content = json_tokener_parse(msg->result_string);
}
if( msg->method_name != NULL )
free(msg->method_name);
+ if(msg->full_param_string)
+ free(msg->full_param_string);
+
if( msg->params != NULL )
json_object_put( msg->params );
+ string_array_destroy(msg->parray);
+
free(msg);
}
xmlSetProp( method_name_node, BAD_CAST "name", BAD_CAST "method" );
xmlSetProp( method_name_node, BAD_CAST "value", BAD_CAST msg->method_name );
- if( msg->params != NULL ) {
- params_node = xmlNewChild( method_node, NULL,
- BAD_CAST "params", BAD_CAST json_object_to_json_string( msg->params ) );
+ 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 ) );
+ }
+ } else {
+ if( msg->parray != NULL ) {
+ /* construct the json array for the params */
+ growing_buffer* buf = buffer_init(128);
+ buffer_add( buf, "[");
+ int k;
+ for( k=0; k!= msg->parray->size; k++) {
+ buffer_add( buf, string_array_get_string(msg->parray, k) );
+ buffer_add( buf, "," );
+ }
+
+ /* remove trailing comma */
+ if(buf->buf[buf->n_used - 1] == ',') {
+ buf->buf[buf->n_used - 1] = '\0';
+ buf->n_used--;
+ }
+ buffer_add( buf, "]");
+ msg->full_param_string = buffer_data(buf);
+
+
+ params_node = xmlNewChild( method_node, NULL,
+ BAD_CAST "params", BAD_CAST buf->buf );
+
+ buffer_free(buf);
+ }
}
}
xmlNodePtr cur_node = message_node->children;
osrf_message* new_msg = safe_malloc(sizeof(osrf_message));
- new_msg->parse_json = parse_json;
+ new_msg->parse_json_result = parse_json_result;
while( cur_node ) {
}
}
- if( !strcmp((char*)meth_node->name,"params" ) && meth_node->children->content )
+ if( !strcmp((char*)meth_node->name,"params" ) && meth_node->children->content ) {
//new_msg->params = json_object_new_string( meth_node->children->content );
- new_msg->params = json_tokener_parse(meth_node->children->content);
-
+ if( new_msg->parse_json_params) {
+ new_msg->params = json_tokener_parse(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);
+ }
+ }
+
meth_node = meth_node->next;
}
} //oilsMethod
client = osrf_system_get_transport_client();
- osrf_message_set_json_parse(1);
+ //osrf_message_set_json_parse_result(1);
+ //osrf_message_set_json_parse_result(1);
/* main process loop */
}
double start = get_timestamp_millis();
- int req_id = osrf_app_session_make_request( session, params, method, 1 );
+ int req_id = osrf_app_session_make_request( session, params, method, 1, NULL );
osrf_message* omsg = osrf_app_session_request_recv( session, req_id, 12 );
+ debug_handler("srfsh0");
if(!omsg)
if(omsg->result_content) {
+ debug_handler("srfsh1");
osrf_message_free(last_result);
last_result = omsg;
else
content = json_object_get_string(omsg->result_content);
+ debug_handler("srfsh2");
+
buffer_add( resp_buffer, "\nReceived Data: " );
buffer_add( resp_buffer, content );
buffer_add( resp_buffer, "\n" );
struct timeb t2;
ftime(&t1);
- int req_id = osrf_app_session_make_request( session, params, methods[j], 1 );
+ int req_id = osrf_app_session_make_request( session, params, methods[j], 1, NULL );
osrf_message* omsg = osrf_app_session_request_recv( session, req_id, 5 );