Enclosed is a patch to update the OpenSRF autotools implementation. It
fixes most bugs such as:
-correctly replacing hardcoded directory paths in various files
-correctly implementing clean, and uninstall make targets
-fixes building src/c-apps modules without the lib prefix
-builds the src/gateway apache modules with apxs
-fixed the naming of the opensrf-c binary

Also, it implements more of the autotools features:
-rolling a tarball with make dist
-enables VPATH (parallel) builds
-checking a distribution with make distcheck


Kevin.

-----------------------------------------

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

Signed-off-by: [Kevin Beswick ([EMAIL PROTECTED])]

=== modified file 'Makefile.am'
--- Makefile.am	2008-07-17 18:15:09 +0000
+++ Makefile.am	2008-07-25 13:48:43 +0000
@@ -33,44 +33,44 @@
 
 AM_CFLAGS = $(DEF_CFLAGS)
 
-DOC_FILES = doc/Application-HOWTO.txt \
-	    doc/dokuwiki-doc-stubber.pl \
-	    doc/OpenSRF-Messaging-Protocol.html \
-	    doc/Persist-API.html \
-	    doc/Roadmap.txt
-
-EXAMPLES_FILES = examples/fieldmapper2cdbi.xsl \
-		 examples/fieldmapper2javascript.xsl \
-		 examples/fieldmapper2perl.xsl \
-		 examples/gen-fieldmapper.xml \
-		 examples/math_bench.pl \
-		 examples/multisession-test.pl \
-		 examples/register.pl \
-		 examples/srfsh_config.xsd \
-		 examples/math_xul_client/math \
-		 examples/math_xul_client/install.js
-
-strn_compat_FILES = src/ports/strn_compat/strndup.c \
-		    src/ports/strn_compat/strndup.h \
-		    src/ports/strn_compat/strnlen.c \
-		    src/ports/strn_compat/strnlen.h
-
-python_FILES = src/python/opensrf.py \
-	       src/python/setup.py \
-	       src/python/srfsh.py \
-	       src/python/osrf
-
-java_FILES = src/java/deps.inc \
-	     src/java/deps.sh \
-	     src/java/org
-
-libosrf_FILES = src/libopensrf/basic_client.c \
-		src/libopensrf/osrf_big_hash.c \
-		src/libopensrf/osrf_big_list.c \
-		src/libopensrf/osrfConfig.c
-
-
-EXTRA_DIST = $(DOC_FILES) $(EXAMPLES_FILES) $(libosrf_FILES) $(strn_compat_FILES) $(python_FILES) $(java_FILES) autogen.sh src/extras src/gateway/fieldmapper-c-xml-out.pl DCO-1.1.txt LICENSE.txt src/perlmods src/javascript
+DOC_FILES = @srcdir@/doc/Application-HOWTO.txt \
+	    @srcdir@/doc/dokuwiki-doc-stubber.pl \
+	    @srcdir@/doc/OpenSRF-Messaging-Protocol.html \
+	    @srcdir@/doc/Persist-API.html \
+	    @srcdir@/doc/Roadmap.txt
+
+EXAMPLES_FILES = @srcdir@/examples/fieldmapper2cdbi.xsl \
+		 @srcdir@/examples/fieldmapper2javascript.xsl \
+		 @srcdir@/examples/fieldmapper2perl.xsl \
+		 @srcdir@/examples/gen-fieldmapper.xml \
+		 @srcdir@/examples/math_bench.pl \
+		 @srcdir@/examples/multisession-test.pl \
+		 @srcdir@/examples/register.pl \
+		 @srcdir@/examples/srfsh_config.xsd \
+		 @srcdir@/examples/math_xul_client/math \
+		 @srcdir@/examples/math_xul_client/install.js
+
+strn_compat_FILES = @srcdir@/src/ports/strn_compat/strndup.c \
+		    @srcdir@/src/ports/strn_compat/strndup.h \
+		    @srcdir@/src/ports/strn_compat/strnlen.c \
+		    @srcdir@/src/ports/strn_compat/strnlen.h
+
+python_FILES = @srcdir@/src/python/opensrf.py \
+	       @srcdir@/src/python/setup.py \
+	       @srcdir@/src/python/srfsh.py \
+	       @srcdir@/src/python/osrf
+
+java_FILES = @srcdir@/src/java/deps.inc \
+	     @srcdir@/src/java/deps.sh \
+	     @srcdir@/src/java/org
+
+libosrf_FILES = @srcdir@/src/libopensrf/basic_client.c \
+		@srcdir@/src/libopensrf/osrf_big_hash.c \
+		@srcdir@/src/libopensrf/osrf_big_list.c \
+		@srcdir@/src/libopensrf/osrfConfig.c
+
+
+EXTRA_DIST = $(DOC_FILES) $(EXAMPLES_FILES) $(libosrf_FILES) $(strn_compat_FILES) $(python_FILES) $(java_FILES) @srcdir@/autogen.sh @srcdir@/src/extras @srcdir@/src/gateway/fieldmapper-c-xml-out.pl @srcdir@/DCO-1.1.txt @srcdir@/LICENSE.txt @srcdir@/src/perlmods @srcdir@/src/javascript
 
 objsonincludedir = @includedir@/objson
 opensrfincludedir = @includedir@/opensrf
@@ -122,5 +122,5 @@
 	make -s -C src javascript-install
 
 install-data-hook:
-	mv @srcdir@/src/gateway/apachetools.h @includedir@/opensrf/apachetools.h
+	cp @srcdir@/src/gateway/apachetools.h @includedir@/opensrf/apachetools.h
 

=== modified file 'bin/osrf_config.in'
--- bin/osrf_config.in	2008-07-17 18:15:09 +0000
+++ bin/osrf_config.in	2008-07-25 13:48:43 +0000
@@ -52,10 +52,10 @@
 
 function cconfig {
 	 
-sed -i 's|SYSCONFDIR|@sysconfdir@|g' '@srcdir@/src/gateway/osrf_json_gateway.c'
-sed -i 's|${prefix}|@prefix@|g' '@srcdir@/src/gateway/osrf_json_gateway.c'
-sed -i 's|osrf|@abs_top_srcdir@/src/python/osrf|g' '@srcdir@/src/python/setup.py'
-sed -i 's|srfsh\.py|@abs_top_srcdir@/src/python/srfsh.py|g' '@srcdir@/src/python/setup.py'
+sed -e 's|SYSCONFDIR|@sysconfdir@|g' \
+    -e 's|${prefix}|@prefix@|g' @srcdir@/src/gateway/osrf_json_gateway.c.in > @srcdir@/src/gateway/osrf_json_gateway.c
+sed -e 's|osrf|@abs_top_srcdir@/src/python/osrf|g' \
+    -e 's|srfsh\.py|@abs_top_srcdir@/src/python/srfsh.py|g' @srcdir@/src/python/setup.py.in > @srcdir@/src/python/setup.py
 }
 
 function showHelp {

=== modified file 'src/Makefile.am'
--- src/Makefile.am	2008-07-17 19:43:42 +0000
+++ src/Makefile.am	2008-07-25 13:48:43 +0000
@@ -14,13 +14,11 @@
 
 # Declare some directory variables
 
-export TMPDIR	= $(TMP)
 export OPENSRF	= opensrf
 export BINDIR	= @bindir@
 export LIBDIR	= @libdir@
 perldir	= $(LIBDIR)/perl5
 jsdir = $(LIBDIR)/javascript
-export INCLUDEDIR= @includedir@
 export OSRF_JAVA_DEPSDIR = @OSRF_JAVA_DEPSDIR@
 etcdir = $(ETCDIR)
 
@@ -43,28 +41,26 @@
 
 SUBDIRS = libopensrf c-apps router srfsh jserver gateway $(MAYBE_PY) $(MAYBE_JA)
 
-dist_bin_SCRIPTS = ../bin/osrf_ctl.sh
-bin_SCRIPTS = ../bin/osrf_config
+dist_bin_SCRIPTS = @top_srcdir@/bin/osrf_ctl.sh
+bin_SCRIPTS = @top_srcdir@/bin/osrf_config
 
-dist_etc_DATA = @top_srcdir@/examples/opensrf.xml.example @top_srcdir@/examples/opensrf_core.xml.example @top_srcdir@/examples/srfsh.xml.example 
+dist_sysconf_DATA = @top_srcdir@/examples/opensrf.xml.example @top_srcdir@/examples/opensrf_core.xml.example @top_srcdir@/examples/srfsh.xml.example 
 
 install-exec-local:
 	mkdir -p $(VAR)
 	mkdir -p $(PID)
 	mkdir -p $(LOG)
 	mkdir -p $(SOCK)
-	mkdir -p $(ETCDIR)
 	mkdir -p $(jsdir)
 	mkdir -p $(perldir)
 
-install-data-hook:
-	ln -sf $(BINDIR)/opensrf $(BINDIR)/opensrf-c
-	sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(ETCDIR)/opensrf.xml.example'
-	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(ETCDIR)/opensrf.xml.example'
-	sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(ETCDIR)/opensrf_core.xml.example'
-	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(ETCDIR)/opensrf_core.xml.example'
-	sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(ETCDIR)/srfsh.xml.example'
-	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(ETCDIR)/srfsh.xml.example'
+install-exec-hook:
+	sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(DESTDIR)@sysconfdir@/opensrf.xml.example'
+	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(DESTDIR)@sysconfdir@/opensrf.xml.example'
+	sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(DESTDIR)@sysconfdir@/opensrf_core.xml.example'
+	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(DESTDIR)@sysconfdir@/opensrf_core.xml.example'
+	sed -i 's|LOCALSTATEDIR|$(VAR)|g' '$(DESTDIR)@sysconfdir@/srfsh.xml.example'
+	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '$(DESTDIR)@sysconfdir@/srfsh.xml.example'
 	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '@abs_top_srcdir@/examples/math_bench.pl'
 	sed -i 's|LIBDIR|$(LIBDIR)|g' '@abs_top_srcdir@/examples/multisession-test.pl'
 	sed -i 's|SYSCONFDIR|$(ETCDIR)|g' '@abs_top_srcdir@/doc/dokuwiki-doc-stubber.pl'
@@ -74,5 +70,7 @@
 
 
 uninstall-hook:
-	rm $(INCLUDEDIR)/opensrf/apachetools.h
-	rm $(bindir)/opensrf-c
+	rm @includedir@/opensrf/apachetools.h
+	rm -R $(jsdir)
+	rm -R $(perldir)
+

=== modified file 'src/c-apps/Makefile.am'
--- src/c-apps/Makefile.am	2008-07-17 18:15:09 +0000
+++ src/c-apps/Makefile.am	2008-07-25 13:48:43 +0000
@@ -13,16 +13,19 @@
 
 
 AM_CFLAGS = $(DEF_CFLAGS) -DORSF_LOG_PARAMS 
-AM_LDFLAGS = $(DEF_LDFLAGS) -L../libopensrf/
+AM_LDFLAGS = $(DEF_LDFLAGS) [EMAIL PROTECTED]@/src/libopensrf
 
 noinst_PROGRAMS = timejson
-lib_LTLIBRARIES = libosrf_dbmath.la libosrf_math.la libosrf_version.la
+lib_LTLIBRARIES = osrf_dbmath.la osrf_math.la osrf_version.la
 
 timejson_SOURCES = timejson.c
 timejson_LDADD = -lobjson -lopensrf
-libosrf_dbmath_la_SOURCES = osrf_dbmath.c 
-libosrf_dbmath_la_LIBADD = -lobjson -lopensrf
-libosrf_math_la_SOURCES = osrf_math.c
-libosrf_math_la_LIBADD = -lobjson -lopensrf
-libosrf_version_la_SOURCES = osrf_version.c 
-libosrf_version_la_LIBADD = -lobjson -lopensrf
+osrf_dbmath_la_SOURCES = osrf_dbmath.c 
+osrf_dbmath_la_LDFLAGS = $(AM_LDFLAGS) -module
+osrf_dbmath_la_LIBADD = -lobjson -lopensrf
+osrf_math_la_SOURCES = osrf_math.c
+osrf_math_la_LDFLAGS = $(AM_LDFLAGS) -module
+osrf_math_la_LIBADD = -lobjson -lopensrf
+osrf_version_la_SOURCES = osrf_version.c 
+osrf_version_la_LDFLAGS = $(AM_LDFLAGS) -module
+osrf_version_la_LIBADD = -lobjson -lopensrf

=== modified file 'src/gateway/Makefile.am'
--- src/gateway/Makefile.am	2008-07-09 19:18:51 +0000
+++ src/gateway/Makefile.am	2008-07-23 17:17:45 +0000
@@ -12,21 +12,17 @@
 # GNU General Public License for more details.
 
 
-AM_LDFLAGS = $(DEF_LDFLAGS)
-AM_CFLAGS = $(DEF_CFLAGS) -DASSUME_STATELESS -L../libopensrf/
-
-curdir = @abs_top_builddir@/src/gateway/
-
-cur_LTLIBRARIES = libosrf_json_gateway.la libosrf_http_translator.la
-libosrf_json_gateway_la_SOURCES = apachetools.c apachetools.h osrf_json_gateway.c
-libosrf_json_gateway_la_LIBADD = -lobjson -lopensrf
-libosrf_http_translator_la_SOURCES = apachetools.c apachetools.h osrf_http_translator.c
-libosrf_http_translator_la_LIBADD = -lobjson -lopensrf
-
-include_HEADERS = apachetools.h
+EXTRA_DIST = @srcdir@/apachetools.c @srcdir@/apachetools.h @srcdir@/osrf_json_gateway.c @srcdir@/osrf_http_translator.c
+
+options=-D_LARGEFILE64_SOURCE -Wall [EMAIL PROTECTED]@/include/ -I$(LIBXML2_HEADERS) -I$(APACHE2_HEADERS) -I$(APR_HEADERS) -L$(LIBDIR) [EMAIL PROTECTED]@/src/libopensrf
+
+all-local:
+	$(APXS2) -c $(DEF_LDLIBS) $(options) @srcdir@/osrf_json_gateway.c
+	$(APXS2) -c $(DEF_LDLIBS) $(options) @srcdir@/osrf_http_translator.c
 
 install-exec-local: 
-	cp .libs/libosrf_json_gateway.so osrf_json_gateway.so
-	$(APXS2) -i -a -n osrf_json_gateway osrf_json_gateway.so
-	cp .libs/libosrf_http_translator.so osrf_http_translator.so
-	$(APXS2) -i -a -n osrf_http_translator osrf_http_translator.so
+	$(APXS2) -i -a @srcdir@/osrf_json_gateway.c
+	$(APXS2) -i -a @srcdir@/osrf_http_translator.c
+
+clean-local:
+	rm @srcdir@/osrf_http_translator.la @srcdir@/osrf_http_translator.lo @srcdir@/osrf_http_translator.slo @srcdir@/osrf_json_gateway.la @srcdir@/osrf_json_gateway.lo @srcdir@/osrf_json_gateway.slo

=== removed file 'src/gateway/osrf_json_gateway.c'
--- src/gateway/osrf_json_gateway.c	2008-07-17 18:15:09 +0000
+++ src/gateway/osrf_json_gateway.c	1970-01-01 00:00:00 +0000
@@ -1,466 +0,0 @@
-#include "apachetools.h"
-#include "opensrf/osrf_app_session.h"
-#include "opensrf/osrf_system.h"
-#include "opensrf/osrfConfig.h"
-#include <opensrf/osrf_json.h>
-#include <opensrf/osrf_json_xml.h>
-#include <opensrf/osrf_legacy_json.h>
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <unistd.h>
-#include <strings.h>
-
-
-#define MODULE_NAME "osrf_json_gateway_module"
-#define GATEWAY_CONFIG "OSRFGatewayConfig"
-#define DEFAULT_LOCALE "OSRFDefaultLocale"
-#define CONFIG_CONTEXT "gateway"
-#define JSON_PROTOCOL "OSRFGatewayLegacyJSON"
-#define GATEWAY_USE_LEGACY_JSON 1
-
-#define GATEWAY_DEFAULT_CONFIG "SYSCONFDIR/opensrf_core.xml"
-
-
-/* our config structure */
-typedef struct { 
-	char* configfile;  /* our bootstrap config file */
-} osrf_json_gateway_config;
-
-typedef struct { 
-	int legacyJSON;
-} osrf_json_gateway_dir_config;
-
-
-module AP_MODULE_DECLARE_DATA osrf_json_gateway_module;
-
-char* osrf_json_default_locale = "en-US";
-char* osrf_json_gateway_config_file = NULL;
-int bootstrapped = 0;
-int numserved = 0;
-osrfStringArray* allowedServices = NULL;
-
-static const char* osrf_json_gateway_set_default_locale(cmd_parms *parms, void *config, const char *arg) {
-	if (arg)
-		osrf_json_default_locale = (char*) arg;
-	return NULL;
-}
-
-static const char* osrf_json_gateway_set_config(cmd_parms *parms, void *config, const char *arg) {
-	osrf_json_gateway_config  *cfg;
-	cfg = ap_get_module_config(parms->server->module_config, &osrf_json_gateway_module);
-	cfg->configfile = (char*) arg;
-	osrf_json_gateway_config_file = (char*) arg;
-	return NULL;
-}
-
-static const char* osrf_json_gateway_set_json_proto(cmd_parms *parms, void *config, const char *arg) {
-	osrf_json_gateway_dir_config* cfg = (osrf_json_gateway_dir_config*) config;
-	cfg->legacyJSON = (!strcasecmp((char*) arg, "false")) ? 0 : 1;
-	return NULL;
-}
-
-/* tell apache about our commands */
-static const command_rec osrf_json_gateway_cmds[] = {
-	AP_INIT_TAKE1( GATEWAY_CONFIG, osrf_json_gateway_set_config, 
-			NULL, RSRC_CONF, "osrf json gateway config file"),
-	AP_INIT_TAKE1( DEFAULT_LOCALE, osrf_json_gateway_set_default_locale, 
-			NULL, RSRC_CONF, "osrf json gateway default locale"),
-	AP_INIT_TAKE1( JSON_PROTOCOL, osrf_json_gateway_set_json_proto,
-			NULL, ACCESS_CONF, "osrf json gateway config file"),
-	{NULL}
-};
-
-/* build the config object */
-static void* osrf_json_gateway_create_config( apr_pool_t* p, server_rec* s) {
-	osrf_json_gateway_config* cfg = (osrf_json_gateway_config*) 
-			apr_palloc(p, sizeof(osrf_json_gateway_config));
-	cfg->configfile = GATEWAY_DEFAULT_CONFIG;
-	return (void*) cfg;
-}
-
-static void* osrf_json_gateway_create_dir_config( apr_pool_t* p, char* dir) {
-	osrf_json_gateway_dir_config* cfg = (osrf_json_gateway_dir_config*) 
-			apr_palloc(p, sizeof(osrf_json_gateway_dir_config));
-	cfg->legacyJSON = GATEWAY_USE_LEGACY_JSON;
-	return (void*) cfg;
-}
-
-static apr_status_t child_exit(void* data) {
-    osrfLogInfo(OSRF_LOG_MARK, "Disconnecting on child cleanup...");
-    osrf_system_shutdown();
-    return OK;
-}
-
-static void osrf_json_gateway_child_init(apr_pool_t *p, server_rec *s) {
-
-	char* cfg = osrf_json_gateway_config_file;
-	char buf[32];
-	int t = time(NULL);
-	snprintf(buf, sizeof(buf), "%d", t);
-
-	if( ! osrfSystemBootstrapClientResc( cfg, CONFIG_CONTEXT, buf ) ) {
-		ap_log_error( APLOG_MARK, APLOG_ERR, 0, s, 
-			"Unable to Bootstrap OpenSRF Client with config %s..", cfg);
-		return;
-	}
-
-	bootstrapped = 1;
-	allowedServices = osrfNewStringArray(8);
-	osrfLogInfo(OSRF_LOG_MARK, "Bootstrapping gateway child for requests");
-	osrfConfigGetValueList( NULL, allowedServices, "/services/service" );
-
-	int i;
-	for( i = 0; i < allowedServices->size; i++ ) {
-		ap_log_error( APLOG_MARK, APLOG_DEBUG, 0, s, 
-			"allowed service: %s\n", osrfStringArrayGetString(allowedServices, i));
-	}
-
-    // when this pool is cleaned up, it means the child 
-    // process is going away.  register some cleanup code
-    apr_pool_cleanup_register(p, NULL, child_exit, NULL);
-}
-
-static int osrf_json_gateway_method_handler (request_rec *r) {
-
-	/* make sure we're needed first thing*/
-	if (strcmp(r->handler, MODULE_NAME )) return DECLINED;
-
-
-	osrf_json_gateway_dir_config* dir_conf =  
-		ap_get_module_config(r->per_dir_config, &osrf_json_gateway_module);
-
-
-	/* provide 2 different JSON parsers and serializers to support legacy JSON */
-	jsonObject* (*parseJSONFunc) (const char*) = legacy_jsonParseString;
-	char* (*jsonToStringFunc) (const jsonObject*) = legacy_jsonObjectToJSON;
-
-	if(dir_conf->legacyJSON) {
-		ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Using legacy JSON");
-
-	} else {
-		ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Not using legacy JSON");
-		parseJSONFunc = jsonParseString;
-		jsonToStringFunc = jsonObjectToJSON;
-	}
-
-
-	osrfLogDebug(OSRF_LOG_MARK, "osrf gateway: entered request handler");
-
-	/* verify we are connected */
-	if( !bootstrapped || !osrfSystemGetTransportClient()) {
-		ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, r, "Cannot process request "
-				"because the OpenSRF JSON gateway has not been bootstrapped...");
-		usleep( 100000 ); /* 100 milliseconds */
-		exit(1);
-	}
-
-	osrfLogSetAppname("osrf_json_gw");
-
-	char* osrf_locale	= NULL;
-	char* param_locale	= NULL;	/* locale for this call */
-	char* service		= NULL;	/* service to connect to */
-	char* method		= NULL;	/* method to perform */
-	char* format		= NULL;	/* method to perform */
-	char* a_l		= NULL;	/* request api level */
-	char* input_format	= NULL; /* POST data format, defaults to 'format' */
-	int   isXML		= 0;
-	int   api_level		= 1;
-
-	r->allowed |= (AP_METHOD_BIT << M_GET);
-	r->allowed |= (AP_METHOD_BIT << M_POST);
-
-	osrfLogDebug(OSRF_LOG_MARK, "osrf gateway: parsing URL params");
-	osrfStringArray* mparams	= NULL;
-	osrfStringArray* params	= apacheParseParms(r); /* free me */
-	param_locale		= apacheGetFirstParamValue( params, "locale" );
-	service			= apacheGetFirstParamValue( params, "service" );
-	method			= apacheGetFirstParamValue( params, "method" ); 
-	format			= apacheGetFirstParamValue( params, "format" ); 
-	input_format		= apacheGetFirstParamValue( params, "input_format" ); 
-	a_l			= apacheGetFirstParamValue( params, "api_level" ); 
-	mparams			= apacheGetParamValues( params, "param" ); /* free me */
-
-	if(format == NULL)
-		format = strdup( "json" );
-	if(input_format == NULL)
-		input_format = strdup( format );
-
-	/* set the user defined timeout value */
-	int timeout = 60;
-	char* tout = apacheGetFirstParamValue( params, "timeout" ); /* request timeout in seconds */
-	if( tout ) {
-		timeout = atoi(tout);
-		osrfLogDebug(OSRF_LOG_MARK, "Client supplied timeout of %d", timeout);
-		free( tout );
-	}
-
-	if (a_l) {
-		api_level = atoi(a_l);
-		free( a_l );
-	}
-
-	if (!strcasecmp(format, "xml")) {
-		isXML = 1;
-		ap_set_content_type(r, "application/xml");
-	} else {
-		ap_set_content_type(r, "text/plain");
-	}
-
-	free( format );
-	int ret = OK;
-
-	/* ----------------------------------------------------------------- */
-	/* Grab the requested locale using the Accept-Language header*/
-
-
-	if ( !param_locale ) {
-		if ( apr_table_get(r->headers_in, "X-OpenSRF-Language") ) {
-			param_locale = strdup( apr_table_get(r->headers_in, "X-OpenSRF-Language") );
-		} else if ( apr_table_get(r->headers_in, "Accept-Language") ) {
-			param_locale = strdup( apr_table_get(r->headers_in, "Accept-Language") );
-		}
-	}
-
-
-	if (param_locale) {
-		growing_buffer* osrf_locale_buf = buffer_init(16);	
-		if (index(param_locale, ',')) {
-			int ind = index(param_locale, ',') - param_locale;
-			int i;
-			for ( i = 0; i < ind && i < 128; i++ )
-				buffer_add_char( osrf_locale_buf, param_locale[i] );
-		} else {
-			buffer_add( osrf_locale_buf, param_locale );
-		}
-
-		free(param_locale);
-		osrf_locale = buffer_release( osrf_locale_buf );
-	} else {
-		osrf_locale = strdup( osrf_json_default_locale );
-	}
-	/* ----------------------------------------------------------------- */
-
-
-	if(!(service && method) || 
-		!osrfStringArrayContains(allowedServices, service)) {
-
-		osrfLogError(OSRF_LOG_MARK, 
-			"Service [%s] not found or not allowed", service);
-		ret = HTTP_NOT_FOUND;
-
-	} else {
-
-		/* This will log all heaers to the apache error log 
-		const apr_array_header_t* arr = apr_table_elts(r->headers_in);
-		const void* ptr;
-
-		while( (ptr = apr_array_pop(arr)) ) {
-			apr_table_entry_t* e = (apr_table_entry_t*) ptr;
-			fprintf(stderr, "Table entry: %s : %s\n", e->key, e->val );
-		}
-		fflush(stderr);
-		*/
-
-		osrfAppSession* session = osrfAppSessionClientInit(service);
-		osrf_app_session_set_locale(session, osrf_locale);
-
-		double starttime = get_timestamp_millis();
-		int req_id = -1;
-
-		if(!strcasecmp(input_format, "json")) {
-			jsonObject * arr = jsonNewObject(NULL);
-
-			char* str;
-			int i = 0;
-
-			while( (str = osrfStringArrayGetString(mparams, i++)) ) 
-				jsonObjectPush(arr, parseJSONFunc(str));
-
-			req_id = osrfAppSessionMakeRequest( session, arr, method, api_level, NULL );
-			jsonObjectFree(arr);
-		} else {
-
-			/**
-			* If we receive XML method params, convert each param to a JSON object
-			* and pass the array of JSON object params to the method */
-			if(!strcasecmp(input_format, "xml")) {
-				jsonObject* jsonParams = jsonNewObject(NULL);
-
-				char* str;
-				int i = 0;
-				while( (str = osrfStringArrayGetString(mparams, i++)) ) {
-					jsonObjectPush(jsonParams, jsonXMLToJSONObject(str));
-				}
-
-				req_id = osrfAppSessionMakeRequest( session, jsonParams, method, api_level, NULL );
-				jsonObjectFree(jsonParams);
-			}
-		}
-
-
-		if( req_id == -1 ) {
-			osrfLogError(OSRF_LOG_MARK, "I am unable to communicate with opensrf..going away...");
-			osrfAppSessionFree(session);
-			/* we don't want to spawn an intense re-forking storm 
-			 * if there is no jabber server.. so give it some time before we die */
-			usleep( 100000 ); /* 100 milliseconds */
-			exit(1);
-		}
-
-
-		/* ----------------------------------------------------------------- */
-		/* log all requests to the activity log */
-		const char* authtoken = apr_table_get(r->headers_in, "X-OILS-Authtoken");
-		if(!authtoken) authtoken = "";
-		growing_buffer* act = buffer_init(128);	
-		buffer_fadd(act, "[%s] [%s] %s %s", r->connection->remote_ip, authtoken, service, method );
-		char* str; int i = 0;
-		while( (str = osrfStringArrayGetString(mparams, i++)) ) {
-			if( i == 1 ) {
-				OSRF_BUFFER_ADD(act, " ");
-				OSRF_BUFFER_ADD(act, str);
-			} else {
-				OSRF_BUFFER_ADD(act, ", ");
-				OSRF_BUFFER_ADD(act, str);
-			}
-		}
-
-		osrfLogActivity( OSRF_LOG_MARK, act->buf );
-		buffer_free(act);
-		/* ----------------------------------------------------------------- */
-
-
-		osrfMessage* omsg = NULL;
-
-		int statuscode = 200;
-
-		/* kick off the object */
-		if (isXML)
-			ap_rputs("<response xmlns=\"http://opensrf.org/-/namespaces/gateway/v1\";><payload>", r);
-		else
-			ap_rputs("{\"payload\":[", r);
-
-		int morethan1		= 0;
-		char* statusname	= NULL;
-		char* statustext	= NULL;
-		char* output		= NULL;
-
-		while((omsg = osrfAppSessionRequestRecv( session, req_id, timeout ))) {
-	
-			statuscode = omsg->status_code;
-			jsonObject* res;	
-
-			if( ( res = osrfMessageGetResult(omsg)) ) {
-
-				if (isXML) {
-					output = jsonObjectToXML( res );
-				} else {
-					output = jsonToStringFunc( res );
-					if( morethan1 ) ap_rputs(",", r); /* comma between JSON array items */
-				}
-				ap_rputs(output, r);
-				free(output);
-				morethan1 = 1;
-		
-			} else {
-	
-				if( statuscode > 299 ) { /* the request returned a low level error */
-					statusname = omsg->status_name ? strdup(omsg->status_name) : strdup("Unknown Error");
-					statustext = omsg->status_text ? strdup(omsg->status_text) : strdup("No Error Message");
-					osrfLogError( OSRF_LOG_MARK,  "Gateway received error: %s", statustext );
-				}
-			}
-	
-			osrfMessageFree(omsg);
-			if(statusname) break;
-		}
-
-		double duration = get_timestamp_millis() - starttime;
-		osrfLogDebug(OSRF_LOG_MARK, "gateway request took %f seconds", duration);
-
-
-		if (isXML)
-			ap_rputs("</payload>", r);
-		else
-			ap_rputs("]",r); /* finish off the payload array */
-
-		if(statusname) {
-
-			/* add a debug field if the request died */
-			ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, 
-					"OpenSRF JSON Request returned error: %s -> %s", statusname, statustext );
-			int l = strlen(statusname) + strlen(statustext) + 32;
-			char buf[l];
-
-			if (isXML)
-				snprintf( buf, sizeof(buf), "<debug>\"%s : %s\"</debug>", statusname, statustext );
-
-			else {
-				char bb[l];
-				snprintf(bb, sizeof(bb),  "%s : %s", statusname, statustext);
-				jsonObject* tmp = jsonNewObject(bb);
-				char* j = jsonToStringFunc(tmp);
-				snprintf( buf, sizeof(buf), ",\"debug\": %s", j);
-				free(j);
-				jsonObjectFree(tmp);
-			}
-
-			ap_rputs(buf, r);
-
-			free(statusname);
-			free(statustext);
-		}
-
-		/* insert the status code */
-		char buf[32];
-
-		if (isXML)
-			snprintf(buf, sizeof(buf), "<status>%d</status>", statuscode );
-		else
-			snprintf(buf, sizeof(buf), ",\"status\":%d", statuscode );
-
-		ap_rputs( buf, r );
-
-		if (isXML)
-			ap_rputs("</response>", r);
-		else
-			ap_rputs( "}", r ); /* finish off the object */
-
-		osrfAppSessionFree(session);
-	}
-
-	osrfLogInfo(OSRF_LOG_MARK, "Completed processing service=%s, method=%s", service, method);
-	osrfStringArrayFree(params);
-	osrfStringArrayFree(mparams);
-	free( osrf_locale );
-	free( input_format );
-	free( method );
-	free( service );
-
-	osrfLogDebug(OSRF_LOG_MARK, "Gateway served %d requests", ++numserved);
-	osrfLogClearXid();
-
-	return ret;
-}
-
-
-
-static void osrf_json_gateway_register_hooks (apr_pool_t *p) {
-	ap_hook_handler(osrf_json_gateway_method_handler, NULL, NULL, APR_HOOK_MIDDLE);
-	ap_hook_child_init(osrf_json_gateway_child_init,NULL,NULL,APR_HOOK_MIDDLE);
-}
-
-
-module AP_MODULE_DECLARE_DATA osrf_json_gateway_module = {
-	STANDARD20_MODULE_STUFF,
-	osrf_json_gateway_create_dir_config,
-	NULL,
-	osrf_json_gateway_create_config,
-	NULL,
-	osrf_json_gateway_cmds,
-	osrf_json_gateway_register_hooks,
-};
-
-
-
-

=== added file 'src/gateway/osrf_json_gateway.c.in'
--- src/gateway/osrf_json_gateway.c.in	1970-01-01 00:00:00 +0000
+++ src/gateway/osrf_json_gateway.c.in	2008-07-08 15:17:01 +0000
@@ -0,0 +1,466 @@
+#include "apachetools.h"
+#include "opensrf/osrf_app_session.h"
+#include "opensrf/osrf_system.h"
+#include "opensrf/osrfConfig.h"
+#include <opensrf/osrf_json.h>
+#include <opensrf/osrf_json_xml.h>
+#include <opensrf/osrf_legacy_json.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <unistd.h>
+#include <strings.h>
+
+
+#define MODULE_NAME "osrf_json_gateway_module"
+#define GATEWAY_CONFIG "OSRFGatewayConfig"
+#define DEFAULT_LOCALE "OSRFDefaultLocale"
+#define CONFIG_CONTEXT "gateway"
+#define JSON_PROTOCOL "OSRFGatewayLegacyJSON"
+#define GATEWAY_USE_LEGACY_JSON 1
+
+#define GATEWAY_DEFAULT_CONFIG "SYSCONFDIR/opensrf_core.xml"
+
+
+/* our config structure */
+typedef struct { 
+	char* configfile;  /* our bootstrap config file */
+} osrf_json_gateway_config;
+
+typedef struct { 
+	int legacyJSON;
+} osrf_json_gateway_dir_config;
+
+
+module AP_MODULE_DECLARE_DATA osrf_json_gateway_module;
+
+char* osrf_json_default_locale = "en-US";
+char* osrf_json_gateway_config_file = NULL;
+int bootstrapped = 0;
+int numserved = 0;
+osrfStringArray* allowedServices = NULL;
+
+static const char* osrf_json_gateway_set_default_locale(cmd_parms *parms, void *config, const char *arg) {
+	if (arg)
+		osrf_json_default_locale = (char*) arg;
+	return NULL;
+}
+
+static const char* osrf_json_gateway_set_config(cmd_parms *parms, void *config, const char *arg) {
+	osrf_json_gateway_config  *cfg;
+	cfg = ap_get_module_config(parms->server->module_config, &osrf_json_gateway_module);
+	cfg->configfile = (char*) arg;
+	osrf_json_gateway_config_file = (char*) arg;
+	return NULL;
+}
+
+static const char* osrf_json_gateway_set_json_proto(cmd_parms *parms, void *config, const char *arg) {
+	osrf_json_gateway_dir_config* cfg = (osrf_json_gateway_dir_config*) config;
+	cfg->legacyJSON = (!strcasecmp((char*) arg, "false")) ? 0 : 1;
+	return NULL;
+}
+
+/* tell apache about our commands */
+static const command_rec osrf_json_gateway_cmds[] = {
+	AP_INIT_TAKE1( GATEWAY_CONFIG, osrf_json_gateway_set_config, 
+			NULL, RSRC_CONF, "osrf json gateway config file"),
+	AP_INIT_TAKE1( DEFAULT_LOCALE, osrf_json_gateway_set_default_locale, 
+			NULL, RSRC_CONF, "osrf json gateway default locale"),
+	AP_INIT_TAKE1( JSON_PROTOCOL, osrf_json_gateway_set_json_proto,
+			NULL, ACCESS_CONF, "osrf json gateway config file"),
+	{NULL}
+};
+
+/* build the config object */
+static void* osrf_json_gateway_create_config( apr_pool_t* p, server_rec* s) {
+	osrf_json_gateway_config* cfg = (osrf_json_gateway_config*) 
+			apr_palloc(p, sizeof(osrf_json_gateway_config));
+	cfg->configfile = GATEWAY_DEFAULT_CONFIG;
+	return (void*) cfg;
+}
+
+static void* osrf_json_gateway_create_dir_config( apr_pool_t* p, char* dir) {
+	osrf_json_gateway_dir_config* cfg = (osrf_json_gateway_dir_config*) 
+			apr_palloc(p, sizeof(osrf_json_gateway_dir_config));
+	cfg->legacyJSON = GATEWAY_USE_LEGACY_JSON;
+	return (void*) cfg;
+}
+
+static apr_status_t child_exit(void* data) {
+    osrfLogInfo(OSRF_LOG_MARK, "Disconnecting on child cleanup...");
+    osrf_system_shutdown();
+    return OK;
+}
+
+static void osrf_json_gateway_child_init(apr_pool_t *p, server_rec *s) {
+
+	char* cfg = osrf_json_gateway_config_file;
+	char buf[32];
+	int t = time(NULL);
+	snprintf(buf, sizeof(buf), "%d", t);
+
+	if( ! osrfSystemBootstrapClientResc( cfg, CONFIG_CONTEXT, buf ) ) {
+		ap_log_error( APLOG_MARK, APLOG_ERR, 0, s, 
+			"Unable to Bootstrap OpenSRF Client with config %s..", cfg);
+		return;
+	}
+
+	bootstrapped = 1;
+	allowedServices = osrfNewStringArray(8);
+	osrfLogInfo(OSRF_LOG_MARK, "Bootstrapping gateway child for requests");
+	osrfConfigGetValueList( NULL, allowedServices, "/services/service" );
+
+	int i;
+	for( i = 0; i < allowedServices->size; i++ ) {
+		ap_log_error( APLOG_MARK, APLOG_DEBUG, 0, s, 
+			"allowed service: %s\n", osrfStringArrayGetString(allowedServices, i));
+	}
+
+    // when this pool is cleaned up, it means the child 
+    // process is going away.  register some cleanup code
+    apr_pool_cleanup_register(p, NULL, child_exit, NULL);
+}
+
+static int osrf_json_gateway_method_handler (request_rec *r) {
+
+	/* make sure we're needed first thing*/
+	if (strcmp(r->handler, MODULE_NAME )) return DECLINED;
+
+
+	osrf_json_gateway_dir_config* dir_conf =  
+		ap_get_module_config(r->per_dir_config, &osrf_json_gateway_module);
+
+
+	/* provide 2 different JSON parsers and serializers to support legacy JSON */
+	jsonObject* (*parseJSONFunc) (const char*) = legacy_jsonParseString;
+	char* (*jsonToStringFunc) (const jsonObject*) = legacy_jsonObjectToJSON;
+
+	if(dir_conf->legacyJSON) {
+		ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Using legacy JSON");
+
+	} else {
+		ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, "Not using legacy JSON");
+		parseJSONFunc = jsonParseString;
+		jsonToStringFunc = jsonObjectToJSON;
+	}
+
+
+	osrfLogDebug(OSRF_LOG_MARK, "osrf gateway: entered request handler");
+
+	/* verify we are connected */
+	if( !bootstrapped || !osrfSystemGetTransportClient()) {
+		ap_log_rerror( APLOG_MARK, APLOG_ERR, 0, r, "Cannot process request "
+				"because the OpenSRF JSON gateway has not been bootstrapped...");
+		usleep( 100000 ); /* 100 milliseconds */
+		exit(1);
+	}
+
+	osrfLogSetAppname("osrf_json_gw");
+
+	char* osrf_locale	= NULL;
+	char* param_locale	= NULL;	/* locale for this call */
+	char* service		= NULL;	/* service to connect to */
+	char* method		= NULL;	/* method to perform */
+	char* format		= NULL;	/* method to perform */
+	char* a_l		= NULL;	/* request api level */
+	char* input_format	= NULL; /* POST data format, defaults to 'format' */
+	int   isXML		= 0;
+	int   api_level		= 1;
+
+	r->allowed |= (AP_METHOD_BIT << M_GET);
+	r->allowed |= (AP_METHOD_BIT << M_POST);
+
+	osrfLogDebug(OSRF_LOG_MARK, "osrf gateway: parsing URL params");
+	osrfStringArray* mparams	= NULL;
+	osrfStringArray* params	= apacheParseParms(r); /* free me */
+	param_locale		= apacheGetFirstParamValue( params, "locale" );
+	service			= apacheGetFirstParamValue( params, "service" );
+	method			= apacheGetFirstParamValue( params, "method" ); 
+	format			= apacheGetFirstParamValue( params, "format" ); 
+	input_format		= apacheGetFirstParamValue( params, "input_format" ); 
+	a_l			= apacheGetFirstParamValue( params, "api_level" ); 
+	mparams			= apacheGetParamValues( params, "param" ); /* free me */
+
+	if(format == NULL)
+		format = strdup( "json" );
+	if(input_format == NULL)
+		input_format = strdup( format );
+
+	/* set the user defined timeout value */
+	int timeout = 60;
+	char* tout = apacheGetFirstParamValue( params, "timeout" ); /* request timeout in seconds */
+	if( tout ) {
+		timeout = atoi(tout);
+		osrfLogDebug(OSRF_LOG_MARK, "Client supplied timeout of %d", timeout);
+		free( tout );
+	}
+
+	if (a_l) {
+		api_level = atoi(a_l);
+		free( a_l );
+	}
+
+	if (!strcasecmp(format, "xml")) {
+		isXML = 1;
+		ap_set_content_type(r, "application/xml");
+	} else {
+		ap_set_content_type(r, "text/plain");
+	}
+
+	free( format );
+	int ret = OK;
+
+	/* ----------------------------------------------------------------- */
+	/* Grab the requested locale using the Accept-Language header*/
+
+
+	if ( !param_locale ) {
+		if ( apr_table_get(r->headers_in, "X-OpenSRF-Language") ) {
+			param_locale = strdup( apr_table_get(r->headers_in, "X-OpenSRF-Language") );
+		} else if ( apr_table_get(r->headers_in, "Accept-Language") ) {
+			param_locale = strdup( apr_table_get(r->headers_in, "Accept-Language") );
+		}
+	}
+
+
+	if (param_locale) {
+		growing_buffer* osrf_locale_buf = buffer_init(16);	
+		if (index(param_locale, ',')) {
+			int ind = index(param_locale, ',') - param_locale;
+			int i;
+			for ( i = 0; i < ind && i < 128; i++ )
+				buffer_add_char( osrf_locale_buf, param_locale[i] );
+		} else {
+			buffer_add( osrf_locale_buf, param_locale );
+		}
+
+		free(param_locale);
+		osrf_locale = buffer_release( osrf_locale_buf );
+	} else {
+		osrf_locale = strdup( osrf_json_default_locale );
+	}
+	/* ----------------------------------------------------------------- */
+
+
+	if(!(service && method) || 
+		!osrfStringArrayContains(allowedServices, service)) {
+
+		osrfLogError(OSRF_LOG_MARK, 
+			"Service [%s] not found or not allowed", service);
+		ret = HTTP_NOT_FOUND;
+
+	} else {
+
+		/* This will log all heaers to the apache error log 
+		const apr_array_header_t* arr = apr_table_elts(r->headers_in);
+		const void* ptr;
+
+		while( (ptr = apr_array_pop(arr)) ) {
+			apr_table_entry_t* e = (apr_table_entry_t*) ptr;
+			fprintf(stderr, "Table entry: %s : %s\n", e->key, e->val );
+		}
+		fflush(stderr);
+		*/
+
+		osrfAppSession* session = osrfAppSessionClientInit(service);
+		osrf_app_session_set_locale(session, osrf_locale);
+
+		double starttime = get_timestamp_millis();
+		int req_id = -1;
+
+		if(!strcasecmp(input_format, "json")) {
+			jsonObject * arr = jsonNewObject(NULL);
+
+			char* str;
+			int i = 0;
+
+			while( (str = osrfStringArrayGetString(mparams, i++)) ) 
+				jsonObjectPush(arr, parseJSONFunc(str));
+
+			req_id = osrfAppSessionMakeRequest( session, arr, method, api_level, NULL );
+			jsonObjectFree(arr);
+		} else {
+
+			/**
+			* If we receive XML method params, convert each param to a JSON object
+			* and pass the array of JSON object params to the method */
+			if(!strcasecmp(input_format, "xml")) {
+				jsonObject* jsonParams = jsonNewObject(NULL);
+
+				char* str;
+				int i = 0;
+				while( (str = osrfStringArrayGetString(mparams, i++)) ) {
+					jsonObjectPush(jsonParams, jsonXMLToJSONObject(str));
+				}
+
+				req_id = osrfAppSessionMakeRequest( session, jsonParams, method, api_level, NULL );
+				jsonObjectFree(jsonParams);
+			}
+		}
+
+
+		if( req_id == -1 ) {
+			osrfLogError(OSRF_LOG_MARK, "I am unable to communicate with opensrf..going away...");
+			osrfAppSessionFree(session);
+			/* we don't want to spawn an intense re-forking storm 
+			 * if there is no jabber server.. so give it some time before we die */
+			usleep( 100000 ); /* 100 milliseconds */
+			exit(1);
+		}
+
+
+		/* ----------------------------------------------------------------- */
+		/* log all requests to the activity log */
+		const char* authtoken = apr_table_get(r->headers_in, "X-OILS-Authtoken");
+		if(!authtoken) authtoken = "";
+		growing_buffer* act = buffer_init(128);	
+		buffer_fadd(act, "[%s] [%s] %s %s", r->connection->remote_ip, authtoken, service, method );
+		char* str; int i = 0;
+		while( (str = osrfStringArrayGetString(mparams, i++)) ) {
+			if( i == 1 ) {
+				OSRF_BUFFER_ADD(act, " ");
+				OSRF_BUFFER_ADD(act, str);
+			} else {
+				OSRF_BUFFER_ADD(act, ", ");
+				OSRF_BUFFER_ADD(act, str);
+			}
+		}
+
+		osrfLogActivity( OSRF_LOG_MARK, act->buf );
+		buffer_free(act);
+		/* ----------------------------------------------------------------- */
+
+
+		osrfMessage* omsg = NULL;
+
+		int statuscode = 200;
+
+		/* kick off the object */
+		if (isXML)
+			ap_rputs("<response xmlns=\"http://opensrf.org/-/namespaces/gateway/v1\";><payload>", r);
+		else
+			ap_rputs("{\"payload\":[", r);
+
+		int morethan1		= 0;
+		char* statusname	= NULL;
+		char* statustext	= NULL;
+		char* output		= NULL;
+
+		while((omsg = osrfAppSessionRequestRecv( session, req_id, timeout ))) {
+	
+			statuscode = omsg->status_code;
+			jsonObject* res;	
+
+			if( ( res = osrfMessageGetResult(omsg)) ) {
+
+				if (isXML) {
+					output = jsonObjectToXML( res );
+				} else {
+					output = jsonToStringFunc( res );
+					if( morethan1 ) ap_rputs(",", r); /* comma between JSON array items */
+				}
+				ap_rputs(output, r);
+				free(output);
+				morethan1 = 1;
+		
+			} else {
+	
+				if( statuscode > 299 ) { /* the request returned a low level error */
+					statusname = omsg->status_name ? strdup(omsg->status_name) : strdup("Unknown Error");
+					statustext = omsg->status_text ? strdup(omsg->status_text) : strdup("No Error Message");
+					osrfLogError( OSRF_LOG_MARK,  "Gateway received error: %s", statustext );
+				}
+			}
+	
+			osrfMessageFree(omsg);
+			if(statusname) break;
+		}
+
+		double duration = get_timestamp_millis() - starttime;
+		osrfLogDebug(OSRF_LOG_MARK, "gateway request took %f seconds", duration);
+
+
+		if (isXML)
+			ap_rputs("</payload>", r);
+		else
+			ap_rputs("]",r); /* finish off the payload array */
+
+		if(statusname) {
+
+			/* add a debug field if the request died */
+			ap_log_rerror( APLOG_MARK, APLOG_INFO, 0, r, 
+					"OpenSRF JSON Request returned error: %s -> %s", statusname, statustext );
+			int l = strlen(statusname) + strlen(statustext) + 32;
+			char buf[l];
+
+			if (isXML)
+				snprintf( buf, sizeof(buf), "<debug>\"%s : %s\"</debug>", statusname, statustext );
+
+			else {
+				char bb[l];
+				snprintf(bb, sizeof(bb),  "%s : %s", statusname, statustext);
+				jsonObject* tmp = jsonNewObject(bb);
+				char* j = jsonToStringFunc(tmp);
+				snprintf( buf, sizeof(buf), ",\"debug\": %s", j);
+				free(j);
+				jsonObjectFree(tmp);
+			}
+
+			ap_rputs(buf, r);
+
+			free(statusname);
+			free(statustext);
+		}
+
+		/* insert the status code */
+		char buf[32];
+
+		if (isXML)
+			snprintf(buf, sizeof(buf), "<status>%d</status>", statuscode );
+		else
+			snprintf(buf, sizeof(buf), ",\"status\":%d", statuscode );
+
+		ap_rputs( buf, r );
+
+		if (isXML)
+			ap_rputs("</response>", r);
+		else
+			ap_rputs( "}", r ); /* finish off the object */
+
+		osrfAppSessionFree(session);
+	}
+
+	osrfLogInfo(OSRF_LOG_MARK, "Completed processing service=%s, method=%s", service, method);
+	osrfStringArrayFree(params);
+	osrfStringArrayFree(mparams);
+	free( osrf_locale );
+	free( input_format );
+	free( method );
+	free( service );
+
+	osrfLogDebug(OSRF_LOG_MARK, "Gateway served %d requests", ++numserved);
+	osrfLogClearXid();
+
+	return ret;
+}
+
+
+
+static void osrf_json_gateway_register_hooks (apr_pool_t *p) {
+	ap_hook_handler(osrf_json_gateway_method_handler, NULL, NULL, APR_HOOK_MIDDLE);
+	ap_hook_child_init(osrf_json_gateway_child_init,NULL,NULL,APR_HOOK_MIDDLE);
+}
+
+
+module AP_MODULE_DECLARE_DATA osrf_json_gateway_module = {
+	STANDARD20_MODULE_STUFF,
+	osrf_json_gateway_create_dir_config,
+	NULL,
+	osrf_json_gateway_create_config,
+	NULL,
+	osrf_json_gateway_cmds,
+	osrf_json_gateway_register_hooks,
+};
+
+
+
+

=== modified file 'src/jserver/Makefile.am'
--- src/jserver/Makefile.am	2008-07-01 03:33:23 +0000
+++ src/jserver/Makefile.am	2008-07-22 14:10:14 +0000
@@ -13,7 +13,7 @@
 
 
 LDADD = -lxml2 $(DEF_LDLIBS)
-AM_CFLAGS = $(DEF_CFLAGS) -D_GNU_SOURCE -L../libopensrf/
+AM_CFLAGS = $(DEF_CFLAGS) -D_GNU_SOURCE [EMAIL PROTECTED]@/src/libopensrf
 AM_LDFLAGS = $(DEF_LDFLAGS)
 
 bin_PROGRAMS = chopchop

=== modified file 'src/libopensrf/Makefile.am'
--- src/libopensrf/Makefile.am	2008-07-17 18:15:09 +0000
+++ src/libopensrf/Makefile.am	2008-07-25 13:48:43 +0000
@@ -90,9 +90,9 @@
 
 noinst_PROGRAMS = osrf_json_test
 
-bin_PROGRAMS = opensrf
-opensrf_SOURCES = opensrf.c
-opensrf_DEPENDENCIES = libopensrf.la
+bin_PROGRAMS = opensrf-c
+opensrf_c_SOURCES = opensrf.c
+opensrf_c_DEPENDENCIES = libopensrf.la
 
 osrf_json_test_SOURCES = osrf_json_test.c $(JSON_TARGS) $(JSON_DEP) $(JSON_TARGS_HEADS) $(JSON_DEP_HEADS)

=== modified file 'src/python/Makefile.am'
--- src/python/Makefile.am	2008-07-17 18:15:09 +0000
+++ src/python/Makefile.am	2008-07-23 18:28:19 +0000
@@ -11,3 +11,12 @@
 	@echo $@
 	python @srcdir@/setup.py install
 
+distclean-local:
+	rm @builddir@/OpenSRF.egg-info/PKG-INFO
+	rm @builddir@/OpenSRF.egg-info/requires.txt
+	rm @builddir@/OpenSRF.egg-info/top_level.txt
+	rm @builddir@/OpenSRF.egg-info/SOURCES.txt
+	rm @builddir@/OpenSRF.egg-info/dependency_links.txt
+	rm @builddir@/build/scripts-2.5/srfsh.py
+	rm @builddir@/dist/OpenSRF-1.0.0-py2.5.egg
+

=== removed file 'src/python/setup.py'
--- src/python/setup.py	2008-03-06 03:02:59 +0000
+++ src/python/setup.py	1970-01-01 00:00:00 +0000
@@ -1,24 +0,0 @@
-#!/usr/bin/env python
-
-from setuptools import setup
-
-setup(name='OpenSRF',
-    version='1.0.0',
-    install_requires=[
-        'dnspython', # required by pyxmpp
-    	'python-memcached',
-        'pyxmpp>=1.0.0',
-        'simplejson>=1.7.1'
-    ],
-    dependency_links = [
-        "http://pyxmpp.jajcus.net/downloads/";,
-        "ftp://ftp.tummy.com/pub/python-memcached/python-memcached-latest.tar.gz";
-    ],
-    description='OpenSRF Python Modules',
-    author='Bill Erickson',
-    author_email='[EMAIL PROTECTED]',
-    license="GPL",
-    url='http://www.open-ils.org/',
-    packages=['osrf'],
-    scripts=['srfsh.py']
-)

=== added file 'src/python/setup.py.in'
--- src/python/setup.py.in	1970-01-01 00:00:00 +0000
+++ src/python/setup.py.in	2008-06-25 13:48:05 +0000
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+from setuptools import setup
+
+setup(name='OpenSRF',
+    version='1.0.0',
+    install_requires=[
+        'dnspython', # required by pyxmpp
+    	'python-memcached',
+        'pyxmpp>=1.0.0',
+        'simplejson>=1.7.1'
+    ],
+    dependency_links = [
+        "http://pyxmpp.jajcus.net/downloads/";,
+        "ftp://ftp.tummy.com/pub/python-memcached/python-memcached-latest.tar.gz";
+    ],
+    description='OpenSRF Python Modules',
+    author='Bill Erickson',
+    author_email='[EMAIL PROTECTED]',
+    license="GPL",
+    url='http://www.open-ils.org/',
+    packages=['osrf'],
+    scripts=['srfsh.py']
+)

=== modified file 'src/router/Makefile.am'
--- src/router/Makefile.am	2008-07-01 03:33:23 +0000
+++ src/router/Makefile.am	2008-07-22 14:10:36 +0000
@@ -13,7 +13,7 @@
 
 
 LDADD = -lxml2 $(DEF_LDLIBS) 
-AM_CFLAGS = $(DEF_CFLAGS) -D_ROUTER -L../libopensrf/
+AM_CFLAGS = $(DEF_CFLAGS) -D_ROUTER [EMAIL PROTECTED]@/src/libopensrf
 AM_LDFLAGS = $(DEF_LDFLAGS)
 
 bin_PROGRAMS = opensrf_router

=== modified file 'src/srfsh/Makefile.am'
--- src/srfsh/Makefile.am	2008-07-01 03:33:23 +0000
+++ src/srfsh/Makefile.am	2008-07-22 14:10:49 +0000
@@ -13,7 +13,7 @@
 
 
 LDADD = -lreadline -lxml2 -lncurses $(DEF_LDLIBS) 
-AM_CFLAGS = $(DEF_CFLAGS) -DEXEC_DEFAULT -L../libopensrf/
+AM_CFLAGS = $(DEF_CFLAGS) -DEXEC_DEFAULT [EMAIL PROTECTED]@/src/libopensrf
 AM_LDFLAGS = $(DEF_LDFLAGS)
 
 bin_PROGRAMS = srfsh

Reply via email to