From 1e0df792903c81929687fb03af4e72abe975ee51 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 2 May 2005 17:13:59 +0000 Subject: [PATCH] bug squashing party on the gateway. we now explicitly format the xml as UTF-8 when putting docs into memory git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@295 9efc2488-bf62-4759-914b-345cdb29e865 --- src/gateway/Makefile | 2 +- src/gateway/mod_ils_gateway.c | 17 +++++++------ src/libstack/Makefile | 4 +-- src/libstack/osrf_message.c | 47 ++++++++++++++++++++++++------------ src/libstack/osrf_stack.c | 2 -- src/libstack/string_array.c | 6 ++--- src/libtransport/transport_message.c | 7 +++++- src/libtransport/transport_session.c | 6 ----- src/libtransport/transport_socket.c | 5 +++- 9 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/gateway/Makefile b/src/gateway/Makefile index e933bd8..775aa2e 100644 --- a/src/gateway/Makefile +++ b/src/gateway/Makefile @@ -5,7 +5,7 @@ CC_OPTS = -fPIC -Wall -O2 -I /usr/include/libxml2 \ -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 diff --git a/src/gateway/mod_ils_gateway.c b/src/gateway/mod_ils_gateway.c index f74ef34..19d51a9 100644 --- a/src/gateway/mod_ils_gateway.c +++ b/src/gateway/mod_ils_gateway.c @@ -196,13 +196,14 @@ static int mod_ils_gateway_method_handler (request_rec *r) { 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]) { @@ -210,11 +211,9 @@ static int mod_ils_gateway_method_handler (request_rec *r) { 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); @@ -232,9 +231,10 @@ static int mod_ils_gateway_method_handler (request_rec *r) { 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; @@ -356,6 +356,7 @@ static int mod_ils_gateway_method_handler (request_rec *r) { buffer_free(result_data); if(content) { + debug_handler( "APACHE writing data to web client: %s", content ); ap_rputs(content,r); free(content); } diff --git a/src/libstack/Makefile b/src/libstack/Makefile index b1117c1..c3fda16 100644 --- a/src/libstack/Makefile +++ b/src/libstack/Makefile @@ -1,8 +1,8 @@ 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 diff --git a/src/libstack/osrf_message.c b/src/libstack/osrf_message.c index 1993baa..cebdf5d 100644 --- a/src/libstack/osrf_message.c +++ b/src/libstack/osrf_message.c @@ -4,6 +4,18 @@ 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)); @@ -16,7 +28,6 @@ osrf_message* osrf_message_init( enum M_TYPE type, int thread_trace, int protoco 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; } @@ -77,7 +88,6 @@ void osrf_message_set_result_content( osrf_message* msg, char* json_string ) { 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 ); @@ -106,9 +116,6 @@ void osrf_message_free( osrf_message* msg ) { 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 ); @@ -138,9 +145,9 @@ char* osrf_message_to_xml( osrf_message* msg ) { 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; @@ -220,26 +227,27 @@ char* osrf_message_to_xml( osrf_message* msg ) { } } 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); } @@ -285,9 +293,14 @@ char* osrf_message_to_xml( osrf_message* msg ) { // ----------------------------------------------------- /* 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"); @@ -326,6 +339,8 @@ char* osrf_message_to_xml( osrf_message* msg ) { } + + int osrf_message_from_xml( char* xml, osrf_message* msgs[] ) { if(!xml) return 0; diff --git a/src/libstack/osrf_stack.c b/src/libstack/osrf_stack.c index 87e2118..b2cda4a 100644 --- a/src/libstack/osrf_stack.c +++ b/src/libstack/osrf_stack.c @@ -4,9 +4,7 @@ osrf_message* _do_client( osrf_app_session*, osrf_message* ); 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 ); diff --git a/src/libstack/string_array.c b/src/libstack/string_array.c index 27d6c4e..f98815f 100644 --- a/src/libstack/string_array.c +++ b/src/libstack/string_array.c @@ -56,7 +56,7 @@ void string_array_add(string_array* arr, char* str) { } //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]); @@ -70,7 +70,7 @@ char* string_array_get_string(string_array* arr, int index) { 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; } @@ -80,7 +80,7 @@ void string_array_destroy(string_array* arr) { 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]); } } diff --git a/src/libtransport/transport_message.c b/src/libtransport/transport_message.c index f98747b..4517a84 100644 --- a/src/libtransport/transport_message.c +++ b/src/libtransport/transport_message.c @@ -295,7 +295,12 @@ char* message_to_xml( const transport_message* msg ) { } - 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 ) diff --git a/src/libtransport/transport_session.c b/src/libtransport/transport_session.c index ba79806..90b018d 100644 --- a/src/libtransport/transport_session.c +++ b/src/libtransport/transport_session.c @@ -330,8 +330,6 @@ void startElementHandler( 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; @@ -449,8 +447,6 @@ void endElementHandler( void *session, const xmlChar *name) { 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 */ @@ -566,8 +562,6 @@ void characterHandler( 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; } diff --git a/src/libtransport/transport_socket.c b/src/libtransport/transport_socket.c index 155204d..e2e0311 100644 --- a/src/libtransport/transport_socket.c +++ b/src/libtransport/transport_socket.c @@ -121,11 +121,12 @@ int tcp_send( transport_socket* sock_obj, const char* data ){ // ------------------------------------------------------------------ // 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; } @@ -220,9 +221,11 @@ int tcp_wait( transport_socket* sock_obj, int timeout ){ #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 ); -- 2.11.0