From bb67d01ee98ed3cf18982801204506495ad7df95 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 17 Aug 2005 14:43:44 +0000 Subject: [PATCH] fixed a problem in utils where I was using a va_list after calling va_end on the list found a couple of memory leaks in gateway got exceptions going through the REST gateway made makefile a little smarter git-svn-id: svn://svn.open-ils.org/ILS/trunk@1672 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- OpenSRF/bin/opensrf_all | 6 ++- OpenSRF/src/Makefile | 2 +- OpenSRF/src/gateway/Makefile | 39 +++++++++++++++----- OpenSRF/src/gateway/fieldmapper-c-xml-out.pl | 23 +++++++++--- OpenSRF/src/gateway/mod_ils_gateway.c | 25 ++++++++----- OpenSRF/src/utils/utils.c | 13 ++++--- 6 files changed, 74 insertions(+), 34 deletions(-) diff --git a/OpenSRF/bin/opensrf_all b/OpenSRF/bin/opensrf_all index cf6eaabf47..510fd0e919 100755 --- a/OpenSRF/bin/opensrf_all +++ b/OpenSRF/bin/opensrf_all @@ -54,6 +54,8 @@ export PATH="$PREFIX/bin:$PATH"; function fail { echo "$0 exited: $*"; exit 99; } +function usage { echo "$0 [ start | stop | restart ]"; } + function startJserver { @@ -137,7 +139,7 @@ function stopMe { [ "$1" = "stop" ] && stopMe && exit; [ "$1" = "restart" ] && stopMe && makeMeGo && exit; - -makeMeGo; +[ "$1" = "start" ] && makeMeGo && exit; +usage; diff --git a/OpenSRF/src/Makefile b/OpenSRF/src/Makefile index 13accc4c0f..25c7904e1c 100644 --- a/OpenSRF/src/Makefile +++ b/OpenSRF/src/Makefile @@ -21,7 +21,7 @@ export CC_OPTS = -g -Wall -O2 -fPIC -I$(LIBXML2_HEADERS) -I$(APACHE2_HEADERS) -I$(LIBXML2_HEADERS)/libxml -I$(TMP) -I$(TMPDIR) -all: test prep router srfsh jserver gateway rest_gateway +all: prep router srfsh jserver gateway rest_gateway install: install-prep transport-install stack-install gateway-install \ router-install srfsh-install jserver-install perl-install \ diff --git a/OpenSRF/src/gateway/Makefile b/OpenSRF/src/gateway/Makefile index b6ddbc8791..dfabd9e137 100644 --- a/OpenSRF/src/gateway/Makefile +++ b/OpenSRF/src/gateway/Makefile @@ -1,7 +1,17 @@ +# ------------------------------------------------------------------------------- +#CC_OPTS = -Wall -O2 -I /opt/include -I /openils/include -I /usr/include/libxml2 +#LD_OPTS = -L /openils/lib +#APXS2 = /opt/bin/apxs +#TMPDIR = /tmp/blah +#ETCDIR = /tmp/blah +# ------------------------------------------------------------------------------- + CC_OPTS += -DASSUME_STATELESS LD_OPTS += -lc_utils -lobjson -lxml2 -lopensrf_transport -lopensrf_stack -all: msg libmod_ils_gateway.so +all: msg ils_gateway rest_gateway + +ils_gateway: libmod_ils_gateway.so rest_gateway: libmod_ils_rest_gateway.so msg: @@ -10,21 +20,30 @@ msg: install: cp gateway.xml.example $(ETCDIR) echo installing ils_gateway - $(APXS2) -i -a -n ils_gateway $(TMPDIR)/libmod_ils_gateway.so + $(APXS2) -i -a -n ils_gateway libmod_ils_gateway.so echo installing ils_rest_gateway - $(APXS2) -i -a -n ils_rest_gateway $(TMPDIR)/libmod_ils_rest_gateway.so + $(APXS2) -i -a -n ils_rest_gateway libmod_ils_rest_gateway.so -libmod_ils_gateway.so: mod_ils_gateway.c +libmod_ils_gateway.so: mod_ils_gateway.o echo $@ - $(CC) -c $(CC_OPTS) mod_ils_gateway.c - $(CC) $(LD_OPTS) -shared -W1 mod_ils_gateway.o -o $(TMPDIR)/libmod_ils_gateway.so + $(CC) $(LD_OPTS) -shared -W1 mod_ils_gateway.o -o libmod_ils_gateway.so -libmod_ils_rest_gateway.so: mod_ils_gateway.c + +libmod_ils_rest_gateway.so: rest_xml.o mod_ils_gateway.c echo $@ + $(CC) -c -DRESTGATEWAY $(CC_OPTS) -o mod_ils_rest_gateway.o mod_ils_gateway.c + $(CC) $(LD_OPTS) -shared -W1 rest_xml.o mod_ils_rest_gateway.o -o libmod_ils_rest_gateway.so + +rest_xml.c: ./fieldmapper-c-xml-out.pl rest_xml.h rest_xml.c + +rest_xml.o: rest_xml.c rest_xml.h + echo $@ $(CC) -c $(CC_OPTS) -o rest_xml.o rest_xml.c - $(CC) -c -DRESTGATEWAY $(CC_OPTS) -o mod_ils_rest_gateway.o mod_ils_gateway.c - $(CC) $(LD_OPTS) -shared -W1 rest_xml.o mod_ils_rest_gateway.o -o $(TMPDIR)/libmod_ils_rest_gateway.so + +mod_ils_gateway.o: mod_ils_gateway.c + echo $@ + $(CC) -c $(CC_OPTS) mod_ils_gateway.c clean: - /bin/rm -f *.o *.so + /bin/rm -f *.o *.so rest_xml.c rest_xml.h diff --git a/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl b/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl index 1decf921c6..fa5829cca3 100755 --- a/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl +++ b/OpenSRF/src/gateway/fieldmapper-c-xml-out.pl @@ -44,7 +44,7 @@ print SOURCE < #include "objson/object.h" #include "objson/json_parser.h" -#include "opensrf/utils.h" +#include "utils.h" char* json_string_to_xml(char*); void _rest_xml_output(growing_buffer*, object*, char*, int, int); @@ -65,14 +65,19 @@ char* json_string_to_xml(char* content) { buffer_add(res_xml, ""); - for( i = 0; i!= obj->size; i++ ) { - _rest_xml_output(res_xml, obj->get_index(obj,i), NULL, 0,0); + if(obj->is_array) { + for( i = 0; i!= obj->size; i++ ) { + _rest_xml_output(res_xml, obj->get_index(obj,i), NULL, 0,0); + } + } else { + _rest_xml_output(res_xml, obj, NULL, 0,0); } buffer_add(res_xml, ""); output = buffer_data(res_xml); buffer_free(res_xml); + free_object(obj); return output; } @@ -101,6 +106,8 @@ void _rest_xml_output(growing_buffer* buf, object* obj, char * fm_class, int fm_ char * tag; int i; + if(!obj) return; + if (obj->classname) notag = 1; @@ -109,10 +116,11 @@ void _rest_xml_output(growing_buffer* buf, object* obj, char * fm_class, int fm_ } else { tag = strdup("datum"); } + - /* add class hints if we have a class name */ - if(obj->classname) { - if(obj->is_null) { + /* add class hints if we have a class name */ + if(obj->classname) { + if(obj->is_null) { buffer_fadd(buf,"<%s>", tag, obj->classname, tag); return; } else { @@ -120,6 +128,7 @@ void _rest_xml_output(growing_buffer* buf, object* obj, char * fm_class, int fm_ } } + /* now add the data */ if(obj->is_null) { if (!notag) @@ -148,11 +157,13 @@ void _rest_xml_output(growing_buffer* buf, object* obj, char * fm_class, int fm_ } } else if(obj->is_number) { + if (notag) buffer_fadd(buf,"%ld",obj->num_value); else buffer_fadd(buf,"<%s>%ld",tag,obj->num_value,tag); + } else if(obj->is_double) { if (notag) buffer_fadd(buf,"%lf",tag,obj->double_value,tag); diff --git a/OpenSRF/src/gateway/mod_ils_gateway.c b/OpenSRF/src/gateway/mod_ils_gateway.c index 340f2a7538..e8dd01b98b 100644 --- a/OpenSRF/src/gateway/mod_ils_gateway.c +++ b/OpenSRF/src/gateway/mod_ils_gateway.c @@ -9,7 +9,7 @@ #include "opensrf/transport_client.h" #include "opensrf/osrf_message.h" #include "opensrf/osrf_app_session.h" -#include "opensrf/string_array.h" +#include "string_array.h" #include "md5.h" #include "objson/object.h" #include "objson/json_parser.h" @@ -199,22 +199,29 @@ static int mod_ils_gateway_method_handler (request_rec *r) { char* content = NULL; - /* round up our data */ if(exception) { - content = strdup(exception->to_json(exception)); + content = exception->to_json(exception); free_object(exception); - } else { + } #ifdef RESTGATEWAY - /* set content type to text/xml for passing around XML objects */ - ap_set_content_type(r, "text/xml"); - content = json_string_to_xml( buffer_data(result_data) ); + /* set content type to text/xml for passing around XML objects */ + ap_set_content_type(r, "text/xml"); + if(content) { /* exception... */ + char* tmp = content; + content = json_string_to_xml( tmp ); + free(tmp); + } else { + content = json_string_to_xml( result_data->buf ); + } + #else - /* set content type to text/plain for passing around JSON objects */ + /* set content type to text/plain for passing around JSON objects */ + if(!content) { ap_set_content_type(r, "text/plain"); content = buffer_data(result_data); -#endif } +#endif buffer_free(result_data); diff --git a/OpenSRF/src/utils/utils.c b/OpenSRF/src/utils/utils.c index afdf7194aa..1d79de36ea 100644 --- a/OpenSRF/src/utils/utils.c +++ b/OpenSRF/src/utils/utils.c @@ -21,7 +21,7 @@ GNU General Public License for more details. #include #include -#include +//#include #include "utils.h" inline void* safe_malloc( int size ) { @@ -36,11 +36,12 @@ inline void* safe_malloc( int size ) { /* utility method for profiling */ double get_timestamp_millis() { - struct timeb t; + //struct timeb t; struct timeval tv; gettimeofday(&tv, NULL); - ftime(&t); - double time = (int)t.time + ( ((double)t.millitm) / 1000 ) + ( ((double)tv.tv_usec / 1000000) ); + //ftime(&t); +// double time = (int)t.time + ( ((double)t.millitm) / 1000 ) + ( ((double)tv.tv_usec / 1000000) ); + double time = (int)tv.tv_sec + ( ((double)tv.tv_usec / 1000000) ); return time; } @@ -117,7 +118,7 @@ int buffer_fadd(growing_buffer* gb, const char* format, ... ) { va_copy(a_copy, args); va_start(args, format); - len = vsnprintf(NULL, 0, format, a_copy); + len = vsnprintf(NULL, 0, format, args); va_end(args); len += 2; @@ -126,7 +127,7 @@ int buffer_fadd(growing_buffer* gb, const char* format, ... ) { memset(buf, 0, len); va_start(a_copy, format); - vsnprintf(buf, len - 1, format, args); + vsnprintf(buf, len - 1, format, a_copy); va_end(a_copy); //free(f_copy); -- 2.43.2