From: erickson Date: Wed, 17 Aug 2005 14:43:44 +0000 (+0000) Subject: fixed a problem in utils where I was using a va_list after calling va_end on the... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=768ae9cec7bd4a022476e77d73bd03f917b99319;p=working%2FOpenSRF.git 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/OpenSRF/trunk@487 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/bin/opensrf_all b/bin/opensrf_all index cf6eaab..510fd0e 100755 --- a/bin/opensrf_all +++ b/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/src/Makefile b/src/Makefile index 13accc4..25c7904 100644 --- a/src/Makefile +++ b/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/src/gateway/Makefile b/src/gateway/Makefile index b6ddbc8..dfabd9e 100644 --- a/src/gateway/Makefile +++ b/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/src/gateway/fieldmapper-c-xml-out.pl b/src/gateway/fieldmapper-c-xml-out.pl index 1decf92..fa5829c 100755 --- a/src/gateway/fieldmapper-c-xml-out.pl +++ b/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/src/gateway/mod_ils_gateway.c b/src/gateway/mod_ils_gateway.c index 340f2a7..e8dd01b 100644 --- a/src/gateway/mod_ils_gateway.c +++ b/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/src/utils/utils.c b/src/utils/utils.c index afdf719..1d79de3 100644 --- a/src/utils/utils.c +++ b/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);