#define LOG_ERROR 1
#define LOG_WARNING 2
#define LOG_INFO 3
+#define LOG_DEBUG 4
void get_timestamp( char buf_25chars[]) {
time_t epoch = time(NULL);
}
+void debug_handler( char* msg, ... ) {
+
+ char buf[25];
+ memset( buf, 0, 25 );
+ get_timestamp( buf );
+ pid_t pid = getpid();
+ va_list args;
+
+ if( _init_log() ) {
+
+ if( log_level < LOG_DEBUG )
+ return;
+
+ pthread_mutex_lock( &(mutex) );
+ fprintf( log_file, "[%s %d] [%s] ", buf, pid, "DEBG" );
+
+ va_start(args, msg);
+ vfprintf(log_file, msg, args);
+ va_end(args);
+
+ fprintf(log_file, "\n");
+ fflush( log_file );
+ pthread_mutex_unlock( &(mutex) );
+
+ } else {
+
+ fprintf( stderr, "[%s %d] [%s] ", buf, pid, "DEBG" );
+ va_start(args, msg);
+ vfprintf(stderr, msg, args);
+ va_end(args);
+ fprintf( stderr, "\n" );
+ }
+
+}
+
+
+
int _init_log() {
if( log_level != -1 )
char* config_value( const char* xp_query, ... ) {
if( conf_reader == NULL || xp_query == NULL ) {
- fatal_handler( "config_value(): NULL param(s)" );
+ fatal_handler( "config_value(): NULL conf_reader or NULL param(s)" );
return NULL;
}
}
char* value = strdup(val);
- if( value == NULL ) { fatal_handler( "config_value(): Out of Memory!" ); }
+ if( value == NULL ) { warning_handler( "config_value(): Empty config value or Out of Memory!" ); }
// Free XPATH structures
if( xpathObj != NULL ) xmlXPathFreeObject( xpathObj );
char* router_resource;
transport_router_registrar* routt;
+void _build_trusted_sites( transport_router_registrar* router );
+
void sig_hup_handler( int a ) {
router_registrar_free( routt );
config_reader_free();
exit(0);
}
+ char b[256];
+ memset(b,0,256);
+ jid_get_domain( "client@elroy/test", b );
+ fprintf(stderr, "Domain %s\n", b );
config_reader_init( argv[1] );
if( conf_reader == NULL ) fatal_handler( "main(): Config is NULL" );
if(component)
icomponent = atoi(component);
-
if( iport < 1 ) {
fatal_handler( "Port is negative or 0" );
return 99;
router_registrar->client_timeout = client_timeout;
router_registrar->jabber = jabber_connect_init( server, port, 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] );
return router_registrar;
}
+void _build_trusted_sites( transport_router_registrar* router ) {
+
+ router->trusted_servers = (char**) safe_malloc(sizeof(char**));
+ router->trusted_clients = (char**) safe_malloc(sizeof(char**));
+
+ *(router->trusted_servers) = (char*) safe_malloc(ROUTER_MAX_TRUSTED);
+ *(router->trusted_clients) = (char*) safe_malloc(ROUTER_MAX_TRUSTED);
+
+ int i = 0;
+ while( ++i ) {
+ char* server = config_value("//router/trusted_domains/server%d", i );
+ if(server == NULL)
+ break;
+
+ router->trusted_servers[i-1] = server;
+ }
+
+ i = 0;
+ while( ++i ) {
+ char* client = config_value( "//router/trusted_domains/client%d", i );
+ if(client == NULL)
+ break;
+ router->trusted_clients[i-1] = client;
+ }
+
+ if( router->trusted_servers[0] == NULL ||
+ router->trusted_clients[0] == NULL )
+
+ fatal_handler( "You must specify at least one trusted server and client in the config file");
+}
+
+
jabber_connect* jabber_connect_init( char* server,
int port, char* username, char* password, char* resource, int connect_timeout, int component ) {
if( FD_ISSET( router_fd, &listen_set ) ) {
cur_msg = client_recv( router->jabber->t_client, 1 );
- router_registrar_handle_msg( router, cur_msg );
+
+ /* We only process a message if we have some trusted servers and the current
+ message came from one of those servers */
+ if(router->trusted_servers && router->trusted_servers[0]) {
+ int i = 0;
+ int found = 0;
+
+ char server_buf[256];
+ memset(server_buf,0,256);
+ jid_get_domain( cur_msg->sender, server_buf );
+ info_handler("Received top level message from %s", server_buf );
+
+ while(1) {
+ if(router->trusted_servers[i] == NULL)
+ break;
+ if(!strcmp(router->trusted_servers[i], server_buf)) {
+ found = 1;
+ break;
+ }
+ i++;
+ }
+ if(found)
+ router_registrar_handle_msg( router, cur_msg );
+ else
+ warning_handler( "Received top level message from unpriveleged sender %s", cur_msg->sender );
+ }
+
message_free( cur_msg );
if( ++num_handled == select_ret )
continue;
remove_server_class(router_registrar, router_registrar->server_class_list);
}
+ transport_router_registrar* router = router_registrar;
+
+ int i = 0;
+
+ while(1) {
+
+ if( router->trusted_servers[i] == NULL &&
+ router->trusted_clients[i] == NULL )
+ break;
+
+ if(router->trusted_servers[i] != NULL)
+ free(router->trusted_servers[i]);
+ if(router->trusted_clients[i] != NULL)
+ free(router->trusted_clients[i]);
+ i++;
+ }
+
free( router_registrar );