function fail { echo "$0 exited: $*"; exit 99; }
+function usage { echo "$0 [ start | stop | restart ]"; }
+
function startJserver {
[ "$1" = "stop" ] && stopMe && exit;
[ "$1" = "restart" ] && stopMe && makeMeGo && exit;
-
-makeMeGo;
+[ "$1" = "start" ] && makeMeGo && exit;
+usage;
-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 \
+# -------------------------------------------------------------------------------
+#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:
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
#include <stdio.h>
#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);
buffer_add(res_xml, "<response>");
- 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, "</response>");
output = buffer_data(res_xml);
buffer_free(res_xml);
+ free_object(obj);
return output;
}
char * tag;
int i;
+ if(!obj) return;
+
if (obj->classname)
notag = 1;
} 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><Object class_hint=\\\"%s\\\"/></%s>", tag, obj->classname, tag);
return;
} else {
}
}
+
/* now add the data */
if(obj->is_null) {
if (!notag)
}
} else if(obj->is_number) {
+
if (notag)
buffer_fadd(buf,"%ld",obj->num_value);
else
buffer_fadd(buf,"<%s>%ld</%s>",tag,obj->num_value,tag);
+
} else if(obj->is_double) {
if (notag)
buffer_fadd(buf,"%lf",tag,obj->double_value,tag);
#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"
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);
#include <stdlib.h>
#include <string.h>
-#include <sys/timeb.h>
+//#include <sys/timeb.h>
#include "utils.h"
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;
}
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;
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);