/** Allocates a initializes a new app_session */
osrf_app_session* osrf_app_client_session_init( char* remote_service ) {
+
osrf_app_session* session = safe_malloc(sizeof(osrf_app_session));
session->transport_handle = osrf_system_get_transport_client();
/* build a chunky, random session id */
char id[256];
memset(id,0,256);
- srand((int)time(NULL));
- sprintf(id, "%d.%d%d", rand(), (int)time(NULL), getpid());
+ //srand((int)time(NULL));
+
+ sprintf(id, "%lf.%d%d", get_timestamp_millis(), (int)time(NULL), getpid());
session->session_id = strdup(id);
debug_handler( "Building a new client session with id [%s]", session->session_id );
while( session->state != OSRF_SESSION_CONNECTED && remaining >= 0 ) {
osrf_app_session_queue_wait( session, remaining );
+ debug_handler("In connect while with state: %x, %d [%s]", session, session->state, session->session_id );
remaining -= (int) (time(NULL) - start);
}
+ if(session->state == OSRF_SESSION_CONNECTED)
+ debug_handler(" * Connected Successfully");
+
if(session->state != OSRF_SESSION_CONNECTED)
return 0;
osrf_app_session* session = osrf_app_session_find_session( msg->thread );
if( session == NULL ) { /* we must be a server, build a new session */
- info_handler( "Server sessions not implemented yet ..." );
- return 0;
+ info_handler( "Received message for nonexistant session. Dropping..." );
+ message_free( msg );
+ return 1;
}
debug_handler("Session [%s] found, building message", msg->thread );
switch( msg->status_code ) {
case OSRF_STATUS_OK:
+ debug_handler("We connected successfully");
session->state = OSRF_SESSION_CONNECTED;
+ debug_handler( "State: %x => %s => %d", session, session->session_id, session->state );
return NULL;
case OSRF_STATUS_COMPLETE:
}
int osrf_system_bootstrap_client( char* config_file ) {
+
if( config_file == NULL )
fatal_handler("No Config File Specified\n" );
config_reader_init( "opensrf.bootstrap", config_file );
+
char* log_file = config_value( "opensrf.bootstrap", "//logs/client" );
char* log_level = config_value( "opensrf.bootstrap", "//bootstrap/debug" );
char* domain = config_value( "opensrf.bootstrap", "//bootstrap/domains/domain1" ); /* just the first for now */
char* username = config_value( "opensrf.bootstrap", "//bootstrap/username" );
char* password = config_value( "opensrf.bootstrap", "//bootstrap/passwd" );
char* port = config_value( "opensrf.bootstrap", "//bootstrap/port" );
+
int llevel = 0;
int iport = atoi(port);