moved transport code over to utils/socket_bundle so we can keep the code
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 16 Aug 2005 21:06:42 +0000 (21:06 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 16 Aug 2005 21:06:42 +0000 (21:06 +0000)
centralized and take advantage of the unix socket handling.

made makefiles smarter so that we're not re-compiling targets

make install less verbose so errors are easier to see

cleared up all but one of the build errors (still thinking about that one)

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@485 9efc2488-bf62-4759-914b-345cdb29e865

27 files changed:
src/Makefile
src/gateway/Makefile
src/jserver/Makefile
src/libstack/Makefile
src/libstack/osrf_app_session.c
src/libstack/osrf_app_session.h
src/libstack/osrf_stack.c
src/libstack/osrf_stack.h
src/libstack/osrf_system.c
src/libstack/string_array.c [deleted file]
src/libtransport/Makefile
src/libtransport/transport_client.c
src/libtransport/transport_client.h
src/libtransport/transport_session.c
src/libtransport/transport_session.h
src/libtransport/transport_socket.c
src/objson/Makefile
src/router/Makefile
src/router/router.c
src/router/router.h
src/router/router_config.xml.example
src/srfsh/Makefile
src/utils/Makefile
src/utils/sha.c
src/utils/socket_bundle.c
src/utils/socket_bundle.h
src/utils/utils.c

index 7e9bb9b..13accc4 100644 (file)
@@ -23,9 +23,6 @@ export CC_OPTS                        = -g -Wall -O2 -fPIC -I$(LIBXML2_HEADERS) -I$(APACHE2_HEADERS)
 
 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
@@ -37,20 +34,15 @@ prep:
 # 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
 
 
@@ -58,23 +50,18 @@ stack: objson transport
 # 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
 
 
@@ -143,7 +130,6 @@ info:
 # CLEAN        
 # --------------------------------------------------------------------------------
 clean:
-       @echo "Cleaning..."
        make -C libtransport clean
        make -C libstack clean
        make -C router clean
index 1743f94..b6ddbc8 100644 (file)
@@ -1,19 +1,26 @@
 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
index 9198f6c..a13df1a 100644 (file)
@@ -2,22 +2,30 @@ LD_OPTS       += -lc_utils -lxml2
 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)
 
 
index 744ad35..7f39955 100644 (file)
@@ -5,16 +5,36 @@ SOURCES = osrf_message.c osrf_app_session.c osrf_stack.c osrf_system.c osrf_conf
 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
index 61b6e05..5ccbcf0 100644 (file)
@@ -634,7 +634,7 @@ int osrf_app_session_queue_wait( osrf_app_session* session, int timeout ){
        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;
 }
 
index ca5ad35..5d4a91f 100644 (file)
@@ -70,6 +70,7 @@ struct osrf_app_session_struct {
 
        /** So we can be listified */
        struct osrf_app_session_struct* next;
+
 };
 typedef struct osrf_app_session_struct osrf_app_session;
 
@@ -95,18 +96,10 @@ osrf_app_session* osrf_app_session_find_session( char* session_id );
   * 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 );
 
index 6a2e76c..09f46d5 100644 (file)
@@ -9,7 +9,6 @@ int osrf_stack_process( transport_client* client, int timeout ) {
        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) {
@@ -52,16 +51,15 @@ int osrf_stack_transport_handler( transport_message* msg ) {
 
        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] "
@@ -77,10 +75,8 @@ int osrf_stack_transport_handler( transport_message* msg ) {
                }
 
                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");
 
index 6cacbd2..805f0c7 100644 (file)
@@ -7,12 +7,13 @@
 #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
index 65b2837..def7433 100644 (file)
@@ -19,9 +19,11 @@ int osrf_system_bootstrap_client( char* config_file ) {
        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;
@@ -30,8 +32,10 @@ int osrf_system_bootstrap_client( char* config_file ) {
 
        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");
@@ -46,7 +50,8 @@ int osrf_system_bootstrap_client( char* config_file ) {
        free(domain);
        free(username);
        free(password);
-       free(port);
+       free(port);     
+       free(unixpath);
 
        if(global_client)
                return 1;
diff --git a/src/libstack/string_array.c b/src/libstack/string_array.c
deleted file mode 100644 (file)
index 8290a43..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-#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);
-}
index bbbed00..456a3da 100644 (file)
@@ -3,22 +3,40 @@
 
 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
index b7b3b9e..61af363 100644 (file)
@@ -45,7 +45,7 @@ int main( int argc, char** argv ) {
 */
 
 
-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;
 
@@ -58,7 +58,7 @@ transport_client* client_init( char* server, int port, int component ) {
        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) {
@@ -133,14 +133,14 @@ transport_message* client_recv( transport_client* client, int timeout ) {
                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
index 6e5f4ec..318d3bf 100644 (file)
@@ -38,8 +38,10 @@ typedef struct transport_client_struct transport_client;
 // 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 );
 
 
 // ---------------------------------------------------------------------------
index ec6a296..07bdad0 100644 (file)
@@ -6,7 +6,8 @@
 // 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 = 
@@ -52,15 +53,26 @@ transport_session* init_transport(  char* server, int port, void* user_data, int
        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;
 }
@@ -71,8 +83,11 @@ transport_session* init_transport(  char* server, int port, void* user_data, int
 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) {
@@ -95,6 +110,8 @@ int session_free( transport_session* session ) {
        buffer_free(session->router_command_buffer);
        buffer_free(session->session_id);
 
+       free(session->server);
+       free(session->unix_path);
 
        free( session );
        return 1;
@@ -102,11 +119,13 @@ int session_free( transport_session* session ) {
 
 
 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;
@@ -123,7 +142,8 @@ int session_send_msg(
        }
 
        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;
 
@@ -144,15 +164,21 @@ int session_connect( transport_session* session,
        }
 
 
-       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 ) {
@@ -169,13 +195,16 @@ int session_connect( transport_session* session,
 
                /* 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 ) {
@@ -191,7 +220,8 @@ int session_connect( transport_session* session,
                        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;
                        }
@@ -211,14 +241,16 @@ int session_connect( transport_session* session,
 
                /* 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 ) {
 
@@ -234,7 +266,8 @@ int session_connect( transport_session* session,
        
                        /* 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;
                                }
@@ -261,7 +294,8 @@ int session_connect( transport_session* session,
        
                        /* 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;
                                }
@@ -273,7 +307,8 @@ int session_connect( transport_session* session,
 
 
        /* 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! */
@@ -286,12 +321,11 @@ int session_connect( transport_session* session,
 // ---------------------------------------------------------------------------------
 // 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");
 }
 
 
@@ -590,7 +624,10 @@ void  parseErrorHandler( void *session, const char* msg, ... ){
 
 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 );
 }
 
index 373ec1e..d5bfbe3 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "utils.h"
 #include "logging.h"
+#include "socket_bundle.h"
 
 #include "sha.h"
 
@@ -36,7 +37,8 @@
 // ---------------------------------------------------------------------------------
 // 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
@@ -133,7 +135,9 @@ enum TRANSPORT_AUTH_TYPE { AUTH_PLAIN, AUTH_DIGEST };
 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 */
@@ -162,6 +166,11 @@ struct transport_session_struct {
                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 */
@@ -174,8 +183,11 @@ typedef struct transport_session_struct transport_session;
 // ------------------------------------------------------------------
 // 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
index a2cbb15..b9ea09f 100644 (file)
@@ -56,7 +56,7 @@ int tcp_connect( transport_socket* sock_obj ){
        // 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;
        }
 
index d35bbc2..d8ed0b6 100644 (file)
@@ -31,30 +31,39 @@ UTIL_DIR            = ../utils
 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
index c1c5e12..ef877a6 100644 (file)
@@ -5,13 +5,18 @@ LD_OPTS               += -lc_utils -lxml2 -lopensrf_stack -lobjson
 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:
index 9311670..f3ddfba 100644 (file)
@@ -2,7 +2,7 @@
 #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 );
@@ -30,6 +30,7 @@ int main( int argc, char* argv[] ) {
        /* 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");
@@ -51,30 +52,27 @@ int main( int argc, char* argv[] ) {
        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);
@@ -114,7 +112,7 @@ int main( int argc, char* argv[] ) {
 }
 
 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; }
@@ -124,7 +122,7 @@ transport_router_registrar* router_registrar_init( char* server,
        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] );
@@ -164,14 +162,16 @@ void _build_trusted_sites( transport_router_registrar* router ) {
 }
 
 
-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);
@@ -185,7 +185,7 @@ jabber_connect* jabber_connect_init( char* server,
        }
 
        /* 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;
 }
@@ -208,13 +208,13 @@ int fill_fd_set( transport_router_registrar* router, fd_set* set ) {
        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 );
@@ -232,7 +232,7 @@ void listen_loop( transport_router_registrar* router ) {
                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) {
@@ -244,7 +244,7 @@ void listen_loop( transport_router_registrar* router ) {
                        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 ) {
 
@@ -307,12 +307,15 @@ void listen_loop( transport_router_registrar* router ) {
                        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) {
@@ -328,11 +331,9 @@ void listen_loop( transport_router_registrar* router ) {
                                                } 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;
                                                } 
        
@@ -642,7 +643,7 @@ server_class_node* init_server_class(
        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 );
 
 
@@ -667,7 +668,7 @@ server_class_node* init_server_class(
        }
 
        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;
@@ -888,7 +889,8 @@ int router_registrar_handle_app_request(
 
        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++ ) {
@@ -898,9 +900,9 @@ int router_registrar_handle_app_request(
                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) {
 
@@ -929,7 +931,8 @@ int router_registrar_handle_app_request(
                /* 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, "" );
@@ -943,7 +946,8 @@ int router_registrar_handle_app_request(
                        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, "" );
@@ -959,7 +963,8 @@ int router_registrar_handle_app_request(
                                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);
@@ -1163,7 +1168,7 @@ int router_registrar_free( transport_router_registrar* router_registrar ) {
                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;
@@ -1212,6 +1217,7 @@ int server_node_free( server_node* node ) {
 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 );
index 837b883..04b1557 100644 (file)
@@ -66,6 +66,7 @@ struct jabber_connect_struct {
        char* username;
        char* password;
        char* resource;
+       char* unixpath;
        int connect_timeout;
 
        transport_client* t_client;
@@ -136,7 +137,7 @@ typedef struct transport_router_registrar_struct transport_router_registrar;
 // 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 );
 
 // ----------------------------------------------------------------------
@@ -155,7 +156,7 @@ int j_connect( jabber_connect* jabber );
 // 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 );
 
 // ----------------------------------------------------------------------
index f55b10b..1020ddd 100644 (file)
@@ -26,6 +26,7 @@
        <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>
index 58fb93e..fe90f61 100644 (file)
@@ -2,12 +2,17 @@
 
 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:
index 2d7e444..6964e61 100644 (file)
@@ -1,46 +1,58 @@
-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
 
 
 
index 05cf14b..14791bd 100644 (file)
@@ -192,7 +192,9 @@ int strprintsha(char *dest, int *hashval)
                snprintf(hashstr, 9, "%08x", hashval[x]);
                hashstr+=8;
        }
-       snprintf(hashstr++, 1, "\0");
+       //snprintf(hashstr++, 1, "\0");
+       hashstr[0] = '\0';
+       hashstr++;
 
        return 0;
 }
index 40d48b9..7fb556c 100644 (file)
@@ -509,22 +509,22 @@ int _socket_handle_new_client(socket_manager* mgr, socket_node* node) {
 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 */
index 133ec7c..8b9d450 100644 (file)
@@ -34,7 +34,7 @@
 #define UNIX 11 
 
 /* buffer used to read from the sockets */
-#define BUFSIZE 1024 
+#define RBUFSIZE 1024 
 
 
 /* models a single socket connection */
index 103a106..afdf719 100644 (file)
@@ -112,24 +112,24 @@ int buffer_fadd(growing_buffer* gb, const char* format, ... ) {
        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);