// success, 0 otherwise.
// ---------------------------------------------------------------------------
int client_connect( transport_client* client,
- char* username, char* password, char* resource, int connect_timeout );
+ char* username, char* password, char* resource,
+ int connect_timeout, enum TRANSPORT_AUTH_TYPE auth_type );
int client_disconnect( transport_client* client );
};
typedef struct jabber_state_machine_struct jabber_machine;
+
+enum TRANSPORT_AUTH_TYPE { AUTH_PLAIN, AUTH_DIGEST };
+
// ---------------------------------------------------------------------------------
// Transport session. This maintains all the various parts of a session
// ---------------------------------------------------------------------------------
// seconds before failing
// ------------------------------------------------------------------
int session_connect( transport_session* session,
- const char* username, const char* password, const char* resource, int connect_timeout );
+ const char* username, const char* password,
+ const char* resource, int connect_timeout,
+ enum TRANSPORT_AUTH_TYPE auth_type );
int session_disconnect( transport_session* session );
clean:
- /bin/rm -f *.o $(LIB_DIR)/libopensrf_transport.so basic_client
+ /bin/rm -f *.o $(LIB_DIR)/libopensrf_transport.so basic_client component
transport_client* client = client_init( argv[2], 5222, 0 );
// try to connect, allow 15 second connect timeout
- if( client_connect( client, argv[1], "jkjkasdf", argv[3], 15 ) )
+ if( client_connect( client, argv[1], "jkjkasdf", argv[3], 15, AUTH_DIGEST ) )
info_handler("Connected...\n");
else
fatal_handler( "NOT Connected...\n" );
transport_client* client = client_init( argv[1], port, 1 );
// try to connect, allow 15 second connect timeout
- if( client_connect( client, argv[3], argv[4], "", 15 ) )
+ if( client_connect( client, argv[3], argv[4], "", 15, 1 ) )
info_handler("Connected...\n");
else
fatal_handler( "NOT Connected...\n" );
}
int client_connect( transport_client* client,
- char* username, char* password, char* resource, int connect_timeout ) {
+ char* username, char* password, char* resource,
+ int connect_timeout, enum TRANSPORT_AUTH_TYPE auth_type ) {
if(client == NULL) return 0;
- return session_connect( client->session, username, password, resource, connect_timeout );
+ return session_connect( client->session, username,
+ password, resource, connect_timeout, auth_type );
}
int client_disconnect( transport_client* client ) {
/* connects to server and connects to jabber */
int session_connect( transport_session* session,
- const char* username, const char* password, const char* resource, int connect_timeout ) {
+ const char* username, const char* password,
+ const char* resource, int connect_timeout, enum TRANSPORT_AUTH_TYPE auth_type ) {
int size1 = 0;
int size2 = 0;
"<stream:stream to='%s' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>",
server );
- /* the second jabber connect stanza including login info*/
- /* currently, we only support plain text login */
- size2 = 150 + strlen( username ) + strlen(password) + strlen(resource);
- char stanza2[ size2 ];
- memset( stanza2, 0, size2 );
-
- sprintf( stanza2,
- "<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'><username>%s</username><password>%s</password><resource>%s</resource></query></iq>",
- username, password, resource );
-
/* send the first stanze */
session->state_machine->connecting = CONNECTING_1;
warning_handler("error sending");
return 0;
}
-
+
+
/* wait for reply */
tcp_wait( session->sock_obj, connect_timeout ); /* make the timeout smarter XXX */
+
+ if( auth_type == AUTH_PLAIN ) {
+
+ /* the second jabber connect stanza including login info*/
+ size2 = 150 + strlen( username ) + strlen(password) + strlen(resource);
+ char stanza2[ size2 ];
+ memset( stanza2, 0, size2 );
+
+ sprintf( stanza2,
+ "<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'><username>%s</username><password>%s</password><resource>%s</resource></query></iq>",
+ username, password, resource );
- /* server acknowledges our existence, now see if we can login */
- if( session->state_machine->connecting == CONNECTING_2 ) {
- if( ! tcp_send( session->sock_obj, stanza2 ) ) {
- warning_handler("error sending");
- return 0;
+
+ /*
+ <iq type='set' id='auth2'>
+ <query xmlns='jabber:iq:auth'>
+ <username>bill</username>
+ <digest>48fc78be9ec8f86d8ce1c39c320c97c21d62334d</digest>
+ <resource>globe</resource>
+ </query>
+ </iq>
+ */
+
+
+ /* server acknowledges our existence, now see if we can login */
+ if( session->state_machine->connecting == CONNECTING_2 ) {
+ if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ warning_handler("error sending");
+ return 0;
+ }
+ }
+
+ } else if( auth_type == AUTH_DIGEST ) {
+
+ int ss = session->session_id->n_used + strlen(password) + 5;
+ char hashstuff[ss];
+ memset(hashstuff,0,ss);
+ sprintf( hashstuff, "%s%s", session->session_id->buf, password );
+
+ char* hash = shahash( hashstuff );
+
+ /* the second jabber connect stanza including login info*/
+ size2 = 150 + strlen( hash ) + strlen(password) + strlen(resource);
+ char stanza2[ size2 ];
+ memset( stanza2, 0, size2 );
+
+ sprintf( stanza2,
+ "<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'><username>%s</username><digest>%s</digest><resource>%s</resource></query></iq>",
+ username, hash, resource );
+
+
+ /*
+ <iq type='set' id='auth2'>
+ <query xmlns='jabber:iq:auth'>
+ <username>bill</username>
+ <digest>48fc78be9ec8f86d8ce1c39c320c97c21d62334d</digest>
+ <resource>globe</resource>
+ </query>
+ </iq>
+ */
+
+
+ /* server acknowledges our existence, now see if we can login */
+ if( session->state_machine->connecting == CONNECTING_2 ) {
+ if( ! tcp_send( session->sock_obj, stanza2 ) ) {
+ warning_handler("error sending");
+ return 0;
+ }
}
+
}
} // not component
-
+
+
/* wait for reply */
tcp_wait( session->sock_obj, connect_timeout );
-
if( session->state_machine->connected ) {
/* yar! */
return 1;
return 0;
}
- //fprintf( stderr, "TCP Sending: \n%s\n", data );
+ fprintf( stderr, "TCP Sending: \n%s\n", data );
// ------------------------------------------------------------------
// Send the data down the TCP pipe
#else // read everything we can
while( (n = recv(sock_fd, buf, BUFSIZE-1, 0) ) > 0 ) {
- //printf("\nReceived: %s\n", buf);
+ printf("\nReceived: %s\n", buf);
sock_obj->data_received_callback( sock_obj->user_data, buf );
memset( &buf, 0, BUFSIZE );
}
CC_OPTS = -Wall -O2 -I /usr/include/libxml2 -I /usr/include/libxml2/libxml -I ../../include
LD_OPTS = -lxml2
LP=../libtransport
-LIB_SOURCES = $(LP)/generic_utils.c $(LP)/transport_socket.c $(LP)/transport_session.c $(LP)/transport_message.c $(LP)/transport_client.c
+LIB_SOURCES = $(LP)/generic_utils.c $(LP)/transport_socket.c $(LP)/transport_session.c $(LP)/transport_message.c $(LP)/transport_client.c $(LP)/sha.c
all: router router_query
router_resource = config_value("//router/transport/resource");
char* con_timeout = config_value("//router/transport/connect_timeout" );
char* max_retries = config_value("//router/transport/max_reconnect_attempts" );
+ char* component = config_value("//router/component" );
fprintf(stderr, "Router connecting as \nserver: %s \nport: %s \nuser:%s \nresource:%s\n",
server, port, username, router_resource );
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" );
/* build the router_registrar */
transport_router_registrar* router_registrar =
- router_registrar_init( server, iport, username, password, router_resource, 0, con_itimeout );
+ router_registrar_init( server, iport, username, password, router_resource, 0, con_itimeout, icomponent );
routt = router_registrar;
transport_router_registrar* router_registrar_init( char* server,
int port, char* username, char* password,
- char* resource, int client_timeout, int con_timeout ) {
+ 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 );
+ router_registrar->jabber = jabber_connect_init( server, port, username, password, resource, con_timeout, component );
return router_registrar;
}
jabber_connect* jabber_connect_init( char* server,
- int port, char* username, char* password, char* resource, int connect_timeout ) {
+ int port, 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 );
}
/* build the transport client */
- jabber->t_client = client_init( jabber->server, jabber->port );
+ jabber->t_client = client_init( jabber->server, jabber->port, component );
return jabber;
}
int j_connect( jabber_connect* jabber ) {
if( jabber == NULL ) { return 0; }
return client_connect( jabber->t_client,
- jabber->username, jabber->password, jabber->resource, jabber->connect_timeout );
+ jabber->username, jabber->password, jabber->resource,
+ jabber->connect_timeout, AUTH_DIGEST );
}
int fill_fd_set( transport_router_registrar* router, fd_set* set ) {
node->jabber = jabber_connect_init( router->jabber->server,
router->jabber->port, router->jabber->username,
- router->jabber->password, server_class, router->jabber->connect_timeout );
+ router->jabber->password, server_class, router->jabber->connect_timeout, router->component );
do {
- char buf[36];
- memset(buf,0, 36);
-
- char* localtime = strdup( ctime( &(cur_node->la_time) ) );
- strcpy( buf, localtime );
- buf[ strlen(localtime)-1] = '\0'; // remove newline
- free(localtime);
+ char tbuf[124];
+ memset(tbuf,0,124);
+ sprintf( tbuf, "%d", (int)cur_node->reg_time );
+ buffer_add( buffer, tbuf );
+ buffer_add( buffer, " | ");
- buffer_add( buffer, buf );
+ memset(tbuf,0,124);
+ sprintf( tbuf, "%d", (int)cur_node->upd_time );
+ buffer_add( buffer, tbuf );
buffer_add( buffer, " | ");
- char tbuf[124];
memset(tbuf,0,124);
- sprintf( tbuf, "%d", cur_node->la_time );
+ sprintf( tbuf, "%d", (int)cur_node->la_time );
buffer_add( buffer, tbuf );
buffer_add( buffer, " | ");
memset(sbuf,0,64);
sprintf(sbuf,"%d",cur_node->serve_count);
- buffer_add( buffer, "serve_count: " );
+ buffer_add( buffer, "#" );
buffer_add( buffer, sbuf );
buffer_add( buffer, " | ");
/* our top level connection to the jabber server */
jabber_connect* jabber;
+ /* true if we connect to jabber as a jabber component */
+ int component;
+
};
typedef struct transport_router_registrar_struct transport_router_registrar;
// ----------------------------------------------------------------------
transport_router_registrar* router_registrar_init( char* server,
int port, char* username, char* password, char* resource,
- int client_timeout, int connect_timeout );
+ int client_timeout, int connect_timeout, int component );
// ----------------------------------------------------------------------
// Connects the top level router_registrar object to the Jabber server.
// ----------------------------------------------------------------------
jabber_connect* jabber_connect_init( char* server,
int port, char* username, char* password,
- char* resource, int connect_timeout );
+ char* resource, int connect_timeout, int component );
// ----------------------------------------------------------------------
// Allocates and initializes a server class instance. This will be