all: test prep router srfsh jserver gateway rest_gateway
-test: test
- echo "TEST TEST TEST"
-
install: install-prep transport-install stack-install gateway-install \
router-install srfsh-install jserver-install perl-install \
objson-install utils-install info
# LIBS
# --------------------------------------------------------------------------------
c_utils: prep
- echo APXS2=$(APXS2) PREFIX=$(PREFIX) TMP=$(TMP) APCHE2_HEADERS=$(APACHE2_HEADERS) LIBXML2_HEADERS=$(LIBXML2_HEADERS)
- @echo -e "\n + c_utils"
make -C utils
transport: c_utils
- @echo -e "\n + transport"
make -C libtransport
objson: c_utils
- @echo -e "\n + objson"
make -C objson
stack: objson transport
- @echo -e "\n + stack"
make -C libstack
# BINARIES
# --------------------------------------------------------------------------------
router: stack
- @echo -e "\n + router"
make -C router
srfsh: stack
- @echo -e "\n + srfsh"
make -C srfsh
gateway: stack
- @echo -e "\n + gateway"
make -C gateway
rest_gateway: stack
- @echo -e "\n + rest_gateway"
make -e -C gateway rest_gateway
jserver: c_utils
- @echo -e "\n + jserver"
make -C jserver
# CLEAN
# --------------------------------------------------------------------------------
clean:
- @echo "Cleaning..."
make -C libtransport clean
make -C libstack clean
make -C router clean
CC_OPTS += -DASSUME_STATELESS
LD_OPTS += -lc_utils -lobjson -lxml2 -lopensrf_transport -lopensrf_stack
-all: libmod_ils_gateway.so
+all: msg libmod_ils_gateway.so
rest_gateway: libmod_ils_rest_gateway.so
+msg:
+ echo "-> $$(pwd)"
+
install:
cp gateway.xml.example $(ETCDIR)
+ echo installing ils_gateway
$(APXS2) -i -a -n ils_gateway $(TMPDIR)/libmod_ils_gateway.so
+ echo installing ils_rest_gateway
$(APXS2) -i -a -n ils_rest_gateway $(TMPDIR)/libmod_ils_rest_gateway.so
libmod_ils_gateway.so: mod_ils_gateway.c
+ echo $@
$(CC) -c $(CC_OPTS) mod_ils_gateway.c
$(CC) $(LD_OPTS) -shared -W1 mod_ils_gateway.o -o $(TMPDIR)/libmod_ils_gateway.so
libmod_ils_rest_gateway.so: mod_ils_gateway.c
+ echo $@
./fieldmapper-c-xml-out.pl rest_xml.h rest_xml.c
$(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
OBJECTS = jserver-c.o jserver-c_main.o jserver-c_session.o
-all: jserver-c
+all: msg jserver-c
+
+msg:
+ echo "-> $$(pwd)"
jserver-c: $(OBJECTS)
+ echo $@
$(CC) $(LD_OPTS) $(OBJECTS) -o $@
jserver-c_main.o: jserver-c_main.c
+ echo $@
$(CC) -c $(CC_OPTS) jserver-c_main.c -o $@
jserver-c.o: jserver-c.c jserver-c.h
+ echo $@
$(CC) -c $(CC_OPTS) jserver-c.c -o $@
jserver-c_session.o: jserver-c_session.c jserver-c_session.h
+ echo $@
$(CC) -c $(CC_OPTS) jserver-c_session.c -o $@
install:
+ echo installing jserver
cp jserver-c $(BINDIR)
TARGETS = osrf_message.o osrf_app_session.o osrf_stack.o osrf_system.o osrf_config.o
HEADERS = osrf_message.h osrf_app_session.h osrf_stack.h osrf_system.h osrf_config.h
-all: lib
+all: msg libopensrf_stack.so
-lib: $(SOURCES) $(HEADERS)
- $(CC) -c $(CC_OPTS) $(SOURCES)
+msg:
+ echo "-> $$(pwd)"
+
+libopensrf_stack.so: $(TARGETS)
+ echo $@
+ $(CC) -shared -W1 $(TARGETS) -o libopensrf_stack.so
$(CC) -shared -W1 $(TARGETS) -o $(TMPDIR)/libopensrf_stack.so
cp $(HEADERS) $(TMPDIR)/
+osrf_message.o: osrf_message.c osrf_message.h
+ echo $@; $(CC) -c $(CC_OPTS) osrf_message.c -o $@
+
+osrf_app_session.o: osrf_app_session.c osrf_app_session.h
+ echo $@; $(CC) -c $(CC_OPTS) osrf_app_session.c -o $@
+
+osrf_stack.o: osrf_stack.c osrf_stack.h
+ echo $@; $(CC) -c $(CC_OPTS) osrf_stack.c -o $@
+
+osrf_system.o: osrf_system.c osrf_system.h
+ echo $@; $(CC) -c $(CC_OPTS) osrf_system.c -o $@
+
+osrf_config.o: osrf_config.c osrf_config.h
+ echo $@; $(CC) -c $(CC_OPTS) osrf_config.c -o $@
+
install:
+ echo installing libopensrf_stack.so
cp $(HEADERS) $(INCLUDEDIR)/$(OPENSRF)
cp $(TMPDIR)/libopensrf_stack.so $(LIBDIR)/
clean:
- /bin/rm -f *.o
+ /bin/rm -f *.o libopensrf_stack.so
if(session == NULL) return 0;
int ret_val = 0;
debug_handler( "AppSession in queue_wait with timeout %d", timeout );
- ret_val = osrf_stack_process(session->transport_handle, timeout );
+ ret_val = osrf_stack_process(session->transport_handle, timeout);
return ret_val;
}
/** So we can be listified */
struct osrf_app_session_struct* next;
+
};
typedef struct osrf_app_session_struct osrf_app_session;
* the id of the request. This id is then used to perform work on the
* requeset.
*/
-
-
int osrf_app_session_make_req(
osrf_app_session* session, object* params,
char* method_name, int protocol, string_array* param_strings);
-/*
-int osrf_app_session_make_request(
- osrf_app_session* session, json* params,
- char* method_name, int protocol, string_array* arr );
- */
-
/** Sets the given request to complete state */
void osrf_app_session_set_complete( osrf_app_session* session, int request_id );
debug_handler( "Received message from transport code from %s", msg->sender );
int status = osrf_stack_transport_handler( msg );
- /* see if there are multiple message to be received */
while(1) {
transport_message* m = client_recv( client, 0 );
if(m) {
debug_handler( "We received %d messages from %s", num_msgs, msg->sender );
- /* XXX ERROR CHECKING, BAD XML, ETC... */
+ /* XXX ERROR CHECKING, BAD JSON, ETC... */
int i;
for( i = 0; i != num_msgs; i++ ) {
-
/* if we've received a jabber layer error message (probably talking to
someone who no longer exists) and we're not talking to the original
remote id for this server, consider it a redirect and pass it up */
if(msg->is_error) {
- warning_handler( "Received Jabber layer error message" );
+ warning_handler( " !!! Received Jabber layer error message" );
if(strcmp(session->remote_id,session->orig_remote_id)) {
warning_handler( "Treating jabber error as redirect for tt [%d] "
}
osrf_stack_message_handler( session, arr[i] );
- debug_handler("transport layer: message_handler returned, do we have more?");
}
- debug_handler("transport layer: no more messages to process in this batch");
message_free( msg );
debug_handler("after msg delete");
#define OSRF_STACK_H
/* the max number of oilsMessage blobs present in any one root packet */
-#define OSRF_MAX_MSGS_PER_PACKET 64
+#define OSRF_MAX_MSGS_PER_PACKET 256
// -----------------------------------------------------------------------------
+int osrf_stack_process( transport_client* client, int timeout );
int osrf_stack_transport_handler( transport_message* msg );
int osrf_stack_message_handler( osrf_app_session* session, osrf_message* msg );
-int osrf_stack_application_handler( osrf_app_session* session, osrf_message*msg );
+int osrf_stack_application_handler( osrf_app_session* session, osrf_message* msg );
#endif
char* username = config_value( "opensrf.bootstrap", "//bootstrap/username" );
char* password = config_value( "opensrf.bootstrap", "//bootstrap/passwd" );
char* port = config_value( "opensrf.bootstrap", "//bootstrap/port" );
+ char* unixpath = config_value( "opensrf.bootstrap", "//bootstrap/unixpath" );
int llevel = 0;
- int iport = atoi(port);
+ int iport = 0;
+ if(port) iport = atoi(port);
if (!strcmp(log_level, "ERROR")) llevel = LOG_ERROR;
else if (!strcmp(log_level, "WARN")) llevel = LOG_WARNING;
log_init( llevel, log_file );
+ info_handler("Bootstrapping system with domain %s, port %d, and unixpath %s", domain, iport, unixpath );
+
// XXX config values
- transport_client* client = client_init( domain, iport, 0 );
+ transport_client* client = client_init( domain, iport, unixpath, 0 );
char buf[256];
memset(buf,0,256);
char* host = getenv("HOSTNAME");
free(domain);
free(username);
free(password);
- free(port);
+ free(port);
+ free(unixpath);
if(global_client)
return 1;
+++ /dev/null
-#include "string_array.h"
-
-/*
-int main() {
- string_array* arr = init_string_array(1);
- string_array_add(arr, "1");
- fprintf(stderr,"adding 3\n");
- string_array_add(arr, "3");
- string_array_destroy(arr);
- return 0;
-}
-*/
-
-
-
-string_array* init_string_array(int size) {
- if(size > STRING_ARRAY_MAX_SIZE)
- fatal_handler("init_string_array size is too large");
-
- string_array* arr =
- (string_array*) safe_malloc(sizeof(string_array));
- arr->array = (char**) safe_malloc(size * sizeof(char*));
- arr->size = 0;
- arr->arr_size = size;
- return arr;
-}
-
-
-void string_array_add(string_array* arr, char* str) {
- if(arr == NULL || str == NULL ) {
- warning_handler("Invalid params to string_array_add");
- return;
- }
-
- if( strlen(str) < 1 ) return;
-
- arr->size++;
- //fprintf(stderr,"size is %d\n", arr->size);
-
- if( arr->size > STRING_ARRAY_MAX_SIZE )
- fatal_handler("string_array_add size is too large");
-
- /* if necessary, double capacity */
- if(arr->size >= arr->arr_size) {
- arr->arr_size *= 2;
- debug_handler("string_array: Doubling array size to %d", arr->arr_size);
- char** tmp = (char**) safe_malloc(arr->arr_size * sizeof(char*));
- int i;
-
- /* copy the string pointers over */
- for( i = 0; i!= arr->size; i++ )
- tmp[i] = arr->array[i];
-
- free(arr->array);
- arr->array = tmp;
- }
-
- //fprintf(stderr, "String is %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]);
-}
-
-char* string_array_get_string(string_array* arr, int index) {
- if(!arr || index < 0 || index >= arr->size )
- return NULL;
- char* str = arr->array[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);
- return str;
-}
-
-
-void string_array_destroy(string_array* arr) {
- if(!arr) return;
- 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]);
- free(arr->array[i]);
- }
- }
- free(arr->array);
- free(arr);
-}
LD_OPTS += -lxml2 -lc_utils
-SOURCES = transport_socket.c transport_session.c transport_message.c transport_client.c
-TARGETS = transport_socket.o transport_message.o transport_session.o transport_client.o
-HEADERS = transport_socket.h transport_message.h transport_session.h transport_client.h
-
-all: lib
-
-lib: $(SOURCES) $(HEADERS)
- $(CC) -c $(CC_OPTS) $(SOURCES)
+SOURCES = transport_session.c transport_message.c transport_client.c
+TARGETS = transport_message.o transport_session.o transport_client.o
+HEADERS = transport_message.h transport_session.h transport_client.h
+
+TARGET = libopensrf_transport.so
+
+all: msg libopensrf_transport.so
+
+msg:
+ echo "-> $$(pwd)"
+
+libopensrf_transport.so: $(TARGETS)
+ echo $@
+ $(CC) -shared -W1 $(LD_OPTS) $(TARGETS) -o libopensrf_transport.so
$(CC) -shared -W1 $(LD_OPTS) $(TARGETS) -o $(TMPDIR)/libopensrf_transport.so
cp $(HEADERS) $(TMPDIR)
+transport_session.o: transport_session.c transport_session.h
+ echo $@
+ $(CC) -c $(CC_OPTS) transport_session.c -o $@
+
+transport_message.o: transport_message.c transport_message.h
+ echo $@
+ $(CC) -c $(CC_OPTS) transport_message.c -o $@
+
+transport_client.o: transport_client.c transport_client.h
+ echo $@
+ $(CC) -c $(CC_OPTS) transport_client.c -o $@
install:
- @echo "Installing libopensrf_transport..."
+ echo installing $(TARGET)
cp $(TMPDIR)/libopensrf_transport.so $(LIBDIR)/
cp $(HEADERS) $(INCLUDEDIR)/$(OPENSRF)
clean:
- /bin/rm -f *.o basic_client component
+ echo $@
+ /bin/rm -f *.o libopensrf_transport.so
*/
-transport_client* client_init( char* server, int port, int component ) {
+transport_client* client_init( char* server, int port, char* unix_path, int component ) {
if(server == NULL) return NULL;
client->m_list = (transport_message_list*) safe_malloc( l_size );
client->m_list->type = MESSAGE_LIST_HEAD;
- client->session = init_transport( server, port, client, component );
+ client->session = init_transport( server, port, unix_path, client, component );
if(client->session == NULL) {
int wait_ret;
while( client->m_list->next == NULL && remaining >= 0 ) {
- if( ! (wait_ret= session_wait( client->session, remaining)) )
+ if( (wait_ret= session_wait( client->session, remaining)) )
return NULL;
++counter;
#ifdef _ROUTER
// session_wait returns -1 if there is no more data and we're a router
- if( remaining == 0 && wait_ret == -1 ) {
+ if( remaining == 0 ) { // && wait_ret == -1 ) {
break;
}
#else
// Allocates and initializes and transport_client. This does no connecting
// The user must call client_free(client) when finished with the allocated
// object.
+// if port > 0 => connect via TCP
+// else if unix_path != NULL => connect via UNIX socket
// ---------------------------------------------------------------------------
-transport_client* client_init( char* server, int port, int component );
+transport_client* client_init( char* server, int port, char* unix_path, int component );
// ---------------------------------------------------------------------------
// returns a built and allocated transport_session object.
// This codes does no network activity, only memory initilization
// ---------------------------------------------------------------------------------
-transport_session* init_transport( char* server, int port, void* user_data, int component ) {
+transport_session* init_transport( char* server,
+ int port, char* unix_path, void* user_data, int component ) {
/* create the session struct */
transport_session* session =
session->parser_ctxt = xmlCreatePushParserCtxt(SAXHandler, session, "", 0, NULL);
/* initialize the transport_socket structure */
- session->sock_obj = (transport_socket*) safe_malloc( sizeof(transport_socket) );
+ //session->sock_obj = (transport_socket*) safe_malloc( sizeof(transport_socket) );
+ session->sock_mgr = (socket_manager*) safe_malloc( sizeof(socket_manager) );
//int serv_size = strlen( server );
+/*
session->sock_obj->server = server;
session->sock_obj->port = port;
session->sock_obj->data_received_callback = &grab_incoming;
+*/
+
+ session->sock_mgr->data_received = &grab_incoming;
+ session->sock_mgr->blob = session;
+
+ session->port = port;
+ session->server = strdup(server);
+ session->unix_path = strdup(unix_path);
+ session->sock_id = 0;
/* this will be handed back to us in callbacks */
- session->sock_obj->user_data = session;
+ //session->sock_obj->user_data = session;
return session;
}
int session_free( transport_session* session ) {
if( ! session ) { return 0; }
- if( session->sock_obj )
- free( session->sock_obj );
+ //if( session->sock_obj )
+ // free( session->sock_obj );
+
+ if(session->sock_mgr)
+ socket_manager_free(session->sock_mgr);
if( session->state_machine ) free( session->state_machine );
if( session->parser_ctxt) {
buffer_free(session->router_command_buffer);
buffer_free(session->session_id);
+ free(session->server);
+ free(session->unix_path);
free( session );
return 1;
int session_wait( transport_session* session, int timeout ) {
- if( ! session || ! session->sock_obj ) {
+ if( ! session || ! session->sock_mgr ) {
return 0;
}
- int ret = tcp_wait( session->sock_obj, timeout );
- if( ! ret ) {
+
+ int ret = socket_wait( session->sock_mgr, timeout, session->sock_id );
+
+ if( ret ) {
session->state_machine->connected = 0;
}
return ret;
}
message_prepare_xml( msg );
- tcp_send( session->sock_obj, msg->msg_xml );
+ //tcp_send( session->sock_obj, msg->msg_xml );
+ socket_send( session->sock_id, msg->msg_xml );
return 1;
}
- char* server = session->sock_obj->server;
+ //char* server = session->sock_obj->server;
+ char* server = session->server;
- if( ! session->sock_obj ) {
- return 0;
- }
+ if( ! session->sock_id ) {
- if( ! session->sock_obj->connected ) {
- if( ! tcp_connect( session->sock_obj ))
+ if(session->port > 0) {
+ if( (session->sock_id = socket_open_tcp_client(
+ session->sock_mgr, session->port, session->server)) <= 0 )
return 0;
+
+ } else if(session->unix_path != NULL) {
+ if( (session->sock_id = socket_open_unix_client(
+ session->sock_mgr, session->unix_path)) <= 0 )
+ return 0;
+ }
}
if( session->component ) {
/* send the first stanze */
session->state_machine->connecting = CONNECTING_1;
- if( ! tcp_send( session->sock_obj, stanza1 ) ) {
+
+// if( ! tcp_send( session->sock_obj, stanza1 ) ) {
+ if( socket_send( session->sock_id, stanza1 ) ) {
warning_handler("error sending");
return 0;
}
/* wait for reply */
- tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
+ //tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
+ socket_wait(session->sock_mgr, connect_timeout, session->sock_id);
/* server acknowledges our existence, now see if we can login */
if( session->state_machine->connecting == CONNECTING_2 ) {
memset( stanza2, 0, size2 );
sprintf( stanza2, "<handshake>%s</handshake>", hash );
- if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ //if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ if( socket_send( session->sock_id, stanza2 ) ) {
warning_handler("error sending");
return 0;
}
/* send the first stanze */
session->state_machine->connecting = CONNECTING_1;
- if( ! tcp_send( session->sock_obj, stanza1 ) ) {
+ //if( ! tcp_send( session->sock_obj, stanza1 ) ) {
+ if( socket_send( session->sock_id, stanza1 ) ) {
warning_handler("error sending");
return 0;
}
/* wait for reply */
- tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
+ //tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
+ socket_wait( session->sock_mgr, connect_timeout, session->sock_id ); /* make the timeout smarter XXX */
if( auth_type == AUTH_PLAIN ) {
/* server acknowledges our existence, now see if we can login */
if( session->state_machine->connecting == CONNECTING_2 ) {
- if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ //if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ if( socket_send( session->sock_id, stanza2 ) ) {
warning_handler("error sending");
return 0;
}
/* server acknowledges our existence, now see if we can login */
if( session->state_machine->connecting == CONNECTING_2 ) {
- if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ //if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ if( socket_send( session->sock_id, stanza2 ) ) {
warning_handler("error sending");
return 0;
}
/* wait for reply */
- tcp_wait( session->sock_obj, connect_timeout );
+ //tcp_wait( session->sock_obj, connect_timeout );
+ socket_wait( session->sock_mgr, connect_timeout, session->sock_id );
if( session->state_machine->connected ) {
/* yar! */
// ---------------------------------------------------------------------------------
// TCP data callback. Shove the data into the push parser.
// ---------------------------------------------------------------------------------
-void grab_incoming( void * session, char* data ) {
- transport_session* ses = (transport_session*) session;
+//void grab_incoming( void * session, char* data ) {
+void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int parent) {
+ transport_session* ses = (transport_session*) blob;
if( ! ses ) { return; }
- debug_handler("Parsing incoming XML chunk");
xmlParseChunk(ses->parser_ctxt, data, strlen(data), 0);
- debug_handler("Completed parsing incoming XML chunk");
}
int session_disconnect( transport_session* session ) {
if( session == NULL ) { return 0; }
- tcp_send( session->sock_obj, "</stream:stream>");
- return tcp_disconnect( session->sock_obj );
+ //tcp_send( session->sock_obj, "</stream:stream>");
+ socket_send(session->sock_id, "</stream:stream>");
+ socket_disconnect(session->sock_mgr, session->sock_id);
+ return 0;
+ //return tcp_disconnect( session->sock_obj );
}
#include "utils.h"
#include "logging.h"
+#include "socket_bundle.h"
#include "sha.h"
// ---------------------------------------------------------------------------------
// Takes data from the socket handler and pushes it directly into the push parser
// ---------------------------------------------------------------------------------
-void grab_incoming( void * session, char* data );
+//void grab_incoming( void * session, char* data );
+void grab_incoming(void* blob, socket_manager* mgr, int sockid, char* data, int parent);
// ---------------------------------------------------------------------------------
// Callback for handling the startElement event. Much of the jabber logic occurs
struct transport_session_struct {
/* our socket connection */
- transport_socket* sock_obj;
+ //transport_socket* sock_obj;
+ socket_manager* sock_mgr;
+
/* our Jabber state machine */
jabber_machine* state_machine;
/* our SAX push parser context */
left untouched. */
void* user_data;
+ char* server;
+ char* unix_path;
+ int port;
+ int sock_id;
+
int component; /* true if we're a component */
/* the Jabber message callback */
// ------------------------------------------------------------------
// Allocates and initializes the necessary transport session
// data structures.
+// If port > 0, then this session uses TCP connection. Otherwise,
+// if unix_path != NULL, it uses a UNIX domain socket.
// ------------------------------------------------------------------
-transport_session* init_transport( char* server, int port, void* user_data, int component );
+transport_session* init_transport( char* server, int port,
+ char* unix_path, void* user_data, int component );
// ------------------------------------------------------------------
// Returns the value of the given XML attribute
// Get the hostname
// ------------------------------------------------------------------
if( (hptr = gethostbyname( sock_obj->server ) ) == NULL ) {
- fatal_handler( "tcp_connect(): Unknown Host" );
+ fatal_handler( "tcp_connect(): Unknown Host => %s", sock_obj->server );
return -1;
}
DEST_INCLUDE = objson
CC_OPTS += -DSTRICT_JSON_WRITE #-DSTRICT_JSON_READ
-all: test
+all: msg test
-test: lib
+msg:
+ echo "-> $$(pwd)"
+
+test: libobjson.so
+ echo $@
$(CC) $(CC_OPTS) $(LD_OPTS) -lobjson objson_test.c -o $@
install:
+ echo installing libobjson.so
mkdir -p $(INCLUDEDIR)/$(DEST_INCLUDE)
cp $(TMPDIR)/$(DEST_INCLUDE)/*.h $(INCLUDEDIR)/objson/
cp $(TMPDIR)/libobjson.so $(LIBDIR)/libobjson.so
-lib: $(OBJS)
+libobjson.so: $(OBJS)
+ echo $@
$(CC) -shared -W1 $(OBJS) -o $(TMPDIR)/libobjson.so
$(CC) -shared -W1 $(OBJS) -o libobjson.so
mkdir -p $(TMPDIR)/$(DEST_INCLUDE)/
cp *.h $(TMPDIR)/$(DEST_INCLUDE)/
object.o: object.h object.c
+ echo $@
$(CC) -c $(CC_OPTS) object.c -o $@
json_parser.o: json_parser.h json_parser.c
+ echo $@
$(CC) -c $(CC_OPTS) json_parser.c -o $@
utils.o: $(UTIL_DIR)/utils.h $(UTIL_DIR)/utils.c
+ echo $@
$(CC) -c $(CC_OPTS) $(UTIL_DIR)/utils.c -o $@
clean:
- /bin/rm -f *.o *.so test
+ /bin/rm -f *.o *.so test libobjson.so
LP = ../libtransport
LIB_SOURCES = $(LP)/transport_socket.c $(LP)/transport_session.c $(LP)/transport_message.c $(LP)/transport_client.c
-all: router
+all: msg router
+
+msg:
+ echo "-> $$(pwd)"
install:
+ echo installing router
cp router $(BINDIR)
cp router_config.xml.example $(ETCDIR)
router: router.c $(LIB_SOURCES)
+ echo $@
$(CC) $(LD_OPTS) -D_ROUTER $(CC_OPTS) $(LIB_SOURCES) router.c -o $@
clean:
#include <sys/types.h>
#include <signal.h>
-#define ROUTER_MAX_MSGS_PER_PACKET 12
+#define ROUTER_MAX_MSGS_PER_PACKET 256
char* router_resource;
transport_router_registrar* routt;
void _build_trusted_sites( transport_router_registrar* router );
/* laod the config options */
char* server = config_value("opensrf.router", "//router/transport/server");
char* port = config_value("opensrf.router", "//router/transport/port");
+ char* unixpath = config_value("opensrf.router", "//router/transport/unixpath");
char* username = config_value("opensrf.router", "//router/transport/username");
char* password = config_value("opensrf.router", "//router/transport/password");
router_resource = config_value("opensrf.router", "//router/transport/resource");
free(level);
free(log_file);
- fprintf(stderr, "Router connecting as \nserver: %s \nport: %s \nuser:%s \nresource:%s\n",
- server, port, username, router_resource );
+ fprintf(stderr, "Router connecting as \nserver: %s \nport: %s \nunixpath: %s\nuser:%s \nresource:%s\n",
+ server, port, unixpath, username, router_resource );
+
+ int iport = 0;
+ if(port) iport = atoi( port );
- int iport = atoi( port );
int con_itimeout = atoi( con_timeout );
int max_retries_ = atoi(max_retries);
int icomponent = 0;
if(component)
icomponent = atoi(component);
- if( iport < 1 ) {
- fatal_handler( "Port is negative or 0" );
- return 99;
- }
-
-
/* build the router_registrar */
transport_router_registrar* router_registrar =
- router_registrar_init( server, iport, username, password, router_resource, 0, con_itimeout, icomponent );
+ router_registrar_init( server, iport, unixpath, username, password, router_resource, 0, con_itimeout, icomponent );
routt = router_registrar;
free(server);
free(port);
+ free(unixpath);
free(username);
free(password);
free(con_timeout);
}
transport_router_registrar* router_registrar_init( char* server,
- int port, char* username, char* password,
+ int port, char* unixpath, char* username, char* password,
char* resource, int client_timeout, int con_timeout, int component ) {
if( server == NULL ) { return NULL; }
transport_router_registrar* router_registrar = (transport_router_registrar*) safe_malloc( size );
router_registrar->client_timeout = client_timeout;
- router_registrar->jabber = jabber_connect_init( server, port, username, password, resource, con_timeout, component );
+ router_registrar->jabber = jabber_connect_init( server, port, unixpath, username, password, resource, con_timeout, component );
_build_trusted_sites( router_registrar );
info_handler( "Trusted stuff %s, %s, %s", router_registrar->trusted_servers[0],
router_registrar->trusted_clients[0], router_registrar->trusted_clients[1] );
}
-jabber_connect* jabber_connect_init( char* server,
- int port, char* username, char* password, char* resource, int connect_timeout, int component ) {
+jabber_connect* jabber_connect_init(
+ char* server, int port, char* unixpath, char* username,
+ char* password, char* resource, int connect_timeout, int component ) {
size_t len = sizeof(jabber_connect);
jabber_connect* jabber = (jabber_connect*) safe_malloc( len );
jabber->port = port;
jabber->connect_timeout = connect_timeout;
+ jabber->unixpath = strdup(unixpath);
jabber->server = strdup(server);
jabber->username = strdup(username);
}
/* build the transport client */
- jabber->t_client = client_init( jabber->server, jabber->port, component );
+ jabber->t_client = client_init( jabber->server, jabber->port, unixpath, component );
return jabber;
}
int max_fd;
FD_ZERO(set);
- int router_fd = router->jabber->t_client->session->sock_obj->sock_fd;
+ int router_fd = router->jabber->t_client->session->sock_id;
max_fd = router_fd;
FD_SET( router_fd, set );
server_class_node* cur_node = router->server_class_list;
while( cur_node != NULL ) {
- int cur_class_fd = cur_node->jabber->t_client->session->sock_obj->sock_fd;
+ int cur_class_fd = cur_node->jabber->t_client->session->sock_id;
if( cur_class_fd > max_fd )
max_fd = cur_class_fd;
FD_SET( cur_class_fd, set );
return;
int select_ret;
- int router_fd = router->jabber->t_client->session->sock_obj->sock_fd;
+ int router_fd = router->jabber->t_client->session->sock_id;
transport_message* cur_msg;
while(1) {
fatal_handler( "fill_fd_set return bogus max_fd: %d", max_fd );
int num_handled = 0;
- info_handler( "Going into select" );
+ info_handler( "Router going into select() wait..." );
if( (select_ret=select(max_fd+ 1, &listen_set, NULL, NULL, NULL)) < 0 ) {
server_class_node* cur_node = router->server_class_list;
while( cur_node != NULL ) {
debug_handler( "Checking File Descriptor" );
- int cur_fd = cur_node->jabber->t_client->session->sock_obj->sock_fd;
+ int cur_fd = cur_node->jabber->t_client->session->sock_id;
+
+ debug_handler("Router checking file descriptor %d", cur_fd);
if( FD_ISSET(cur_fd, &listen_set) ) {
++num_handled;
FD_CLR(cur_fd,&listen_set);
+ debug_handler("Router has data on file descriptor %d", cur_fd);
cur_msg = client_recv( cur_node->jabber->t_client, 1 );
if(cur_msg) {
} else if( handle_ret == 0 ) {
/* delete and continue */
warning_handler( "server_class_handle_msg() returned 0" );
- //server_class_node* tmp_node = cur_node->next;
remove_server_class( router, cur_node );
debug_handler( "Removed Server Class" );
cur_node = router->server_class_list; /*start over*/
- //cur_node = tmp_node;
continue;
}
server_class_node* node = (server_class_node*) safe_malloc( len );
node->jabber = jabber_connect_init( router->jabber->server,
- router->jabber->port, router->jabber->username,
+ router->jabber->port, router->jabber->unixpath, router->jabber->username,
router->jabber->password, server_class, router->jabber->connect_timeout, router->component );
}
info_handler( "Jabber address in init for %s : address %x : username %s : resource %s",
- node->server_class, node->jabber->t_client->session->sock_obj->sock_fd,
+ node->server_class, node->jabber->t_client->session->sock_id,
node->jabber->username, node->jabber->resource );
return node;
osrf_message* arr[ROUTER_MAX_MSGS_PER_PACKET];
memset(arr, 0, ROUTER_MAX_MSGS_PER_PACKET );
- int num_msgs = osrf_message_from_xml( msg->body, arr );
+ //int num_msgs = osrf_message_from_xml( msg->body, arr );
+ int num_msgs = osrf_message_deserialize( msg->body, arr, ROUTER_MAX_MSGS_PER_PACKET );
int i;
for( i = 0; i != num_msgs; i++ ) {
osrf_message** result = NULL;
int num_responses;
- char* newxml = osrf_message_to_xml(omsg);
- debug_handler( "Received potential app request from client:\n%s\n", newxml );
- free(newxml);
+ //char* newxml = osrf_message_to_xml(omsg);
+ //debug_handler( "Received potential app request from client:\n%s\n", newxml );
+ //free(newxml);
if(omsg->m_type == CONNECT) {
/* now send our new message back */
if(success) {
- char* xml = osrf_message_to_xml(success);
+ //char* xml = osrf_message_to_xml(success);
+ char* xml = osrf_message_serialize(success);
debug_handler( "Sending XML to client app request:\n%s\n", xml );
transport_message* return_m = message_init(
xml, "", msg->thread, msg->sender, "" );
int i;
for(i=0; i!= num_responses; i++){
- char* xml = osrf_message_to_xml(result[i]);
+ //char* xml = osrf_message_to_xml(result[i]);
+ char* xml = osrf_message_serialize(result[i]);
debug_handler( "Sending XML to client app request:\n%s\n", xml );
transport_message* return_m = message_init(
xml, "", msg->thread, msg->sender, "" );
STATUS, result[i-1]->thread_trace, result[i-1]->protocol );
osrf_message_set_status_info( complete,
"oilsConnectStatus", "Request Complete", OSRF_STATUS_COMPLETE );
- char* complete_xml = osrf_message_to_xml(complete);
+ //char* complete_xml = osrf_message_to_xml(complete);
+ char* complete_xml = osrf_message_serialize(complete);
transport_message* complete_m = message_init(
complete_xml, "", msg->thread, msg->sender, "" );
client_send_message(router->jabber->t_client, complete_m);
debug_handler( "Removed server classes in registrar free");
}
- transport_router_registrar* router = router_registrar;
+ //transport_router_registrar* router = router_registrar;
/* make this better
int i = 0;
int jabber_connect_free( jabber_connect* jabber ) {
if( jabber == NULL ) { return 0; }
client_free( jabber->t_client );
+ free( jabber->unixpath );
free( jabber->username );
free( jabber->password );
free( jabber->resource );
char* username;
char* password;
char* resource;
+ char* unixpath;
int connect_timeout;
transport_client* t_client;
// attempt for the top level connection.
// ----------------------------------------------------------------------
transport_router_registrar* router_registrar_init( char* server,
- int port, char* username, char* password, char* resource,
+ int port, char* unixpath, char* username, char* password, char* resource,
int client_timeout, int connect_timeout, int component );
// ----------------------------------------------------------------------
// for freeing the memory with jabber_connect_free();
// ----------------------------------------------------------------------
jabber_connect* jabber_connect_init( char* server,
- int port, char* username, char* password,
+ int port, char* unixpath, char* username, char* password,
char* resource, int connect_timeout, int component );
// ----------------------------------------------------------------------
<transport>
<server>jabber_server.domain.com</server>
<port>5222</port>
+ <unixpath>/path/to/unix_sock</unixpath>
<username>router</username>
<password>my_password</password>
<resource>router</resource>
LD_OPTS += -lobjson -lreadline -lxml2 -lopensrf_transport -lopensrf_stack -lncurses -lc_utils -DEXEC_DEFAULT
-all: srfsh
+all: msg srfsh
+
+msg:
+ echo "-> $$(pwd)"
install:
+ echo installing srfsh
cp srfsh $(BINDIR)
srfsh: srfsh.c srfsh.h
+ echo $@
$(CC) $(CC_OPTS) $(LD_OPTS) srfsh.c -o $@
clean:
-LD_OPTS += -lc_utils
-
-#FM_HEADER = fieldmapper.h
-#FM_SOURCE = fieldmapper.c
-#HEADER_DIR = $(INCLUDE)/opensrf
+# ------------------------------------------------------------------------
+#CC_OPTS = -O2 -Wall
+#TMPDIR = ./tmp
+# ------------------------------------------------------------------------
+LD_OPTS += -lc_utils
+CC_OPTS -= -Wall
UTIL_SOURCES = logging.c utils.c socket_bundle.c md5.c sha.c string_array.c
UTIL_HEADERS = logging.h utils.h socket_bundle.h md5.h sha.h string_array.h
UTIL_OBJECTS = logging.o utils.o socket_bundle.o md5.o sha.o string_array.o
+all: msg libc_utils.so
-all: util
+msg:
+ echo "-> $$(pwd)"
install:
+ echo installing libc_utils.so
cp $(UTIL_HEADERS) $(INCLUDEDIR)/
cp $(TMPDIR)/libc_utils.so $(LIBDIR)/
-util: $(UTIL_OBJECTS)
+libc_utils.so: $(UTIL_OBJECTS)
+ @echo $@
+ $(CC) -shared -W1 $(UTIL_OBJECTS) -o libc_utils.so
$(CC) -shared -W1 $(UTIL_OBJECTS) -o $(TMPDIR)/libc_utils.so
cp $(UTIL_HEADERS) $(TMPDIR)/
logging.o: logging.c logging.h
+ @echo $@
$(CC) -c $(CC_OPTS) logging.c -o $@
utils.o: utils.c utils.h
+ @echo $@
$(CC) -c $(CC_OPTS) utils.c -o $@
socket_bundle.o: socket_bundle.c socket_bundle.h
+ @echo $@
$(CC) -c $(CC_OPTS) socket_bundle.c -o $@
md5.o: md5.c md5.h
+ @echo $@
$(CC) -c $(CC_OPTS) md5.c -o $@
sha.o: sha.c sha.h
+ @echo $@
$(CC) -c $(CC_OPTS) sha.c -o $@
string_array.o: string_array.c string_array.h
+ @echo $@
$(CC) -c $(CC_OPTS) string_array.c -o $@
clean:
- /bin/rm -f *.o socket_test
+ /bin/rm -f *.o socket_test libc_utils.so
snprintf(hashstr, 9, "%08x", hashval[x]);
hashstr+=8;
}
- snprintf(hashstr++, 1, "\0");
+ //snprintf(hashstr++, 1, "\0");
+ hashstr[0] = '\0';
+ hashstr++;
return 0;
}
int _socket_handle_client_data(socket_manager* mgr, socket_node* node) {
if(mgr == NULL || node == NULL) return -1;
- char buf[BUFSIZE];
+ char buf[RBUFSIZE];
int read_bytes;
int sock_fd = node->sock_fd;
- memset(buf, 0, BUFSIZE);
+ memset(buf, 0, RBUFSIZE);
set_fl(sock_fd, O_NONBLOCK);
debug_handler("Gathering client data for %d", node->sock_fd);
info_handler("%d : Received data at %lf\n", getpid(), get_timestamp_millis());
- while( (read_bytes = recv(sock_fd, buf, BUFSIZE-1, 0) ) > 0 ) {
+ while( (read_bytes = recv(sock_fd, buf, RBUFSIZE-1, 0) ) > 0 ) {
debug_handler("Socket %d Read %d bytes and data: %s", sock_fd, read_bytes, buf);
if(mgr->data_received)
mgr->data_received(mgr->blob, mgr, sock_fd, buf, node->parent_id);
- memset(buf, 0, BUFSIZE);
+ memset(buf, 0, RBUFSIZE);
}
if(socket_find_node(mgr, sock_fd)) { /* someone may have closed this socket */
#define UNIX 11
/* buffer used to read from the sockets */
-#define BUFSIZE 1024
+#define RBUFSIZE 1024
/* models a single socket connection */
va_list args;
va_list a_copy;
- char* f_copy = strdup(format);
+ //char* f_copy = strdup(format);
- va_copy(a_copy,args);
+ va_copy(a_copy, args);
- va_start(a_copy, f_copy);
- len = vsnprintf(NULL, 0, f_copy, a_copy);
- va_end(a_copy);
+ va_start(args, format);
+ len = vsnprintf(NULL, 0, format, a_copy);
+ va_end(args);
len += 2;
char buf[len];
memset(buf, 0, len);
- va_start(args, format);
+ va_start(a_copy, format);
vsnprintf(buf, len - 1, format, args);
- va_end(args);
+ va_end(a_copy);
- free(f_copy);
+ //free(f_copy);
return buffer_add(gb, buf);