-I /usr/include/libxml2/libxml -I ../../include \
-I /pines/apps/apache2/include
-EXE_LD_OPTS = -L $(LIB_DIR) -lxml2 -lopensrf_transport -lopensrf_stack -ljson -lmd5
+EXE_LD_OPTS = -L $(LIB_DIR) -lxml2 -lopensrf_transport -lopensrf_stack -ljson -lmd5
all: gateway
warning_handler("No Post Body");
}
- char body[1024];
- memset(body,0,1024);
- buffer = buffer_init(1024);
+ char body[1025];
+ memset(body,0,1025);
+ buffer = buffer_init(1025);
while(ap_get_client_block(r, body, 1024)) {
+ debug_handler("Apache read POST block data: %s\n", body);
buffer_add( buffer, body );
- memset(body,0,1024);
+ memset(body,0,1025);
}
if(arg && arg[0]) {
buffer_add(tmp_buf,arg);
buffer_add(tmp_buf,buffer->buf);
arg = (char*) apr_pstrdup(p, tmp_buf->buf);
- // arg = buffer_data(tmp_buf);;
buffer_free(tmp_buf);
} else {
arg = (char*) apr_pstrdup(p, buffer->buf);
- // arg = buffer_data(buffer);
}
buffer_free(buffer);
r->allowed |= (AP_METHOD_BIT << M_POST);
- char* argcopy = (char*) apr_pstrdup(p, arg);
+ //char* argcopy = (char*) apr_pstrdup(p, arg);
- while( argcopy && (val = ap_getword(p, (const char**) &argcopy, '&'))) {
+ //while( argcopy && (val = ap_getword(p, (const char**) &argcopy, '&'))) {
+ while( arg && (val = ap_getword(p, (const char**) &arg, '&'))) {
//const char* val2 = val;
buffer_free(result_data);
if(content) {
+ debug_handler( "APACHE writing data to web client: %s", content );
ap_rputs(content,r);
free(content);
}
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
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
+EXE_LD_OPTS = -L $(LIB_DIR) -lxml2 -lopensrf_transport -lopensrf_stack -ljson -L /home/erickson/cc/lib #-ldmalloc
CC = gcc
all: lib
int parse_json_result = 1;
int parse_json_params = 1;
+static void recurse_doc( xmlNodePtr node ) {
+ if( node == NULL ) return;
+ debug_handler("Recurse: %s => %s", node->name, node->content );
+ xmlNodePtr t = node->children;
+ while(t) {
+ recurse_doc(t);
+ t = t->next;
+ }
+}
+
+
+
osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protocol ) {
osrf_message* msg = (osrf_message*) safe_malloc(sizeof(osrf_message));
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;
}
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 );
debug_handler( "Message Parse JSON is set to: %d", msg->parse_json_result );
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 );
xmlNodePtr status_node;
xmlNodePtr status_text_node;
xmlNodePtr status_code_node;
- xmlNodePtr method_node;
+ xmlNodePtr method_node = NULL;
xmlNodePtr method_name_node;
- xmlNodePtr params_node;
+ xmlNodePtr params_node = NULL;
xmlNodePtr result_node;
xmlNodePtr content_node;
}
} 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, "," );
+ if(string_array_get_string(msg->parray, k+1))
+ 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);
+ char* tmp = safe_malloc( (buf->n_used + 1) * sizeof(char));
+ memcpy(tmp, buf->buf, buf->n_used);
params_node = xmlNewChild( method_node, NULL,
- BAD_CAST "params", BAD_CAST buf->buf );
+ BAD_CAST "params", NULL );
+
+ xmlNodePtr tt = xmlNewDocTextLen( doc, BAD_CAST tmp, strlen(tmp) );
+ xmlAddChild(params_node, tt);
buffer_free(buf);
}
// -----------------------------------------------------
/* passing in a '1' means we want to retain the formatting */
- xmlDocDumpFormatMemory( doc, &xmlbuf, &bufsize, 0 );
+
+ //xmlDocDumpFormatMemory( doc, &xmlbuf, &bufsize, 0 );
+ //xmlDocDumpMemoryEnc( doc, &xmlbuf, &bufsize, "UTF-8" );
+ xmlDocDumpMemoryEnc( doc, &xmlbuf, &bufsize, "UTF-8" );
+
encoded_msg = strdup( (char*) xmlbuf );
+
if( encoded_msg == NULL )
fatal_handler("message_to_xml(): Out of Memory");
}
+
+
int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) {
if(!xml) return 0;
osrf_message* _do_server( osrf_app_session*, osrf_message* );
int osrf_stack_process( transport_client* client, int timeout ) {
- debug_handler("osrf_stack_process going into client_recv");
transport_message* msg = client_recv( client, timeout );
- debug_handler("osrf_stack_process after client_recv");
if(msg == NULL) return 0;
debug_handler( "Received message from transport code from %s", msg->sender );
int status = osrf_stack_transport_handler( msg );
}
//fprintf(stderr, "String is %s", str);
- debug_handler("string_array_add: Adding string %s", str);
+ //debug_handler("string_array_add: Adding string %s", str);
//arr->array[arr->size - 1] = (char*) safe_malloc(strlen(str));
arr->array[arr->size - 1] = strdup(str);
//fprintf(stderr,"we have %s\n", arr->array[arr->size - 1]);
if(str == NULL)
warning_handler("Somehow we have a NULL string in the string array");
- debug_handler("string_array_get_string: getting string %s", str);
+ //debug_handler("string_array_get_string: getting string %s", str);
return str;
}
int i;
for( i = 0; i!= arr->size; i++ ) {
if( arr->array[i] != NULL ) {
- debug_handler("Freeing string from string array %s", arr->array[i]);
+ //debug_handler("Freeing string from string array %s", arr->array[i]);
free(arr->array[i]);
}
}
}
- xmlDocDumpFormatMemory( doc, &xmlbuf, &bufsize, 0 );
+ xmlBufferPtr buf = xmlBufferCreate();
+ int status = xmlNodeDump( buf, doc, xmlDocGetRootElement(doc) , 1, 0 );
+
+ //xmlDocDumpFormatMemory( doc, &xmlbuf, &bufsize, 0 );
+ xmlDocDumpMemoryEnc( doc, &xmlbuf, &bufsize, "UTF-8" );
+
encoded_body = strdup( (char*) xmlbuf );
if( encoded_body == NULL )
transport_session* ses = (transport_session*) session;
if( ! ses ) { return; }
- debug_handler("transport_session: startElementHandler");
-
if( strcmp( name, "message" ) == 0 ) {
ses->state_machine->in_message = 1;
transport_session* ses = (transport_session*) session;
if( ! ses ) { return; }
- debug_handler("transport_session: endElementHandler");
-
if( strcmp( name, "message" ) == 0 ) {
/* pass off the message info the callback */
strncpy( data, (char*) ch, len );
data[len] = 0;
- debug_handler("transport_session: characterElementHandler");
-
//printf( "Handling characters: %s\n", data );
transport_session* ses = (transport_session*) session;
if( ! ses ) { return; }
// ------------------------------------------------------------------
// Send the data down the TCP pipe
// ------------------------------------------------------------------
- debug_handler( "Sending Data At %f Seconds", get_timestamp_millis() );
if( send( sock_obj->sock_fd, data, strlen(data), 0 ) < 0 ) {
fatal_handler( "tcp_send(): Error sending data" );
return 0;
}
+
+ debug_handler( "Sent Data %s At %f Seconds", data, get_timestamp_millis() );
return 1;
}
#endif
if( clr_fl( sock_fd, O_NONBLOCK ) < 0 ) {
+ warning_handler("Unable to clear O_NONBLOCK flag on socket");
return 0;
}
+
if( n < 0 ) {
if( errno != EAGAIN ) {
warning_handler( " * Error reading socket with errno %d", errno );