added a router_command type of "query". The only supported query so far is
authorerickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 9 Feb 2005 14:20:21 +0000 (14:20 +0000)
committererickson <erickson@9efc2488-bf62-4759-914b-345cdb29e865>
Wed, 9 Feb 2005 14:20:21 +0000 (14:20 +0000)
"servers" (which is passed in as the body of the message).  The router then
makes a list of all of the server_node's and returns the string to the
sender of the query

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

src/router/router.c
src/router/router.h

index 39d490b..adc70e6 100644 (file)
@@ -258,6 +258,22 @@ int router_registrar_handle_msg( transport_router_registrar* router_registrar, t
 
        if( router_registrar == NULL || msg == NULL ) { return 0; }
 
+       // user issued a ruoter query
+       /* a query command has router_command="query" and the actual query type
+               is the content of the message */
+       if( !strcmp(msg->router_command,"query")) {
+               info_handler( "Router received query command" );
+
+               // user issues a servers query
+               if( !strcmp(msg->body, "servers")) {
+
+                       info_handler( "Router received servers query command" );
+                       router_return_server_info( router_registrar, msg );
+                       return 1;
+               }
+       }
+
+
        info_handler("Looking for server_class_node %s...",msg->router_class);
        server_class_node* active_class_node = find_server_class( router_registrar, msg->router_class );
 
@@ -671,12 +687,67 @@ int  server_class_handle_msg( transport_router_registrar* router,
                message_free( new_msg ); // XXX
                return 1;
        }
-       info_handler( "message sent" );
        message_free( new_msg ); // XXX
 
        return 0;
 }
 
+
+int router_return_server_info( 
+               transport_router_registrar* router, transport_message* msg ) {
+
+       server_class_node* cur_class = router->server_class_list;
+       growing_buffer* buffer = buffer_init(1024);
+
+       while( cur_class != NULL ) {
+
+               server_node* start_node = cur_class->current_server_node;
+               server_node* cur_node = start_node;
+               if( cur_node == NULL ) continue; 
+
+               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);
+
+                       buffer_add( buffer, buf );
+                       buffer_add( buffer, " |  ");
+
+
+                       buffer_add( buffer, cur_class->server_class );
+                       buffer_add( buffer, "\t| ");
+                       buffer_add( buffer, cur_node->remote_id );
+
+                       buffer_add( buffer, "\n" );
+                       cur_node = cur_node->next;
+
+               } while( cur_node != start_node );
+
+               cur_class = cur_class->next;
+
+       }
+
+       info_handler( "Router returning servers query command: %s", buffer->buf );
+
+       transport_message* new_msg; 
+
+       if( buffer->buf == NULL || strlen(buffer->buf) == 0 )
+               new_msg = message_init( "0", NULL, NULL, msg->sender, NULL );
+       else
+               new_msg = message_init( buffer->buf, NULL, NULL, msg->sender, NULL );
+
+       client_send_message( router->jabber->t_client, new_msg );
+       message_free( new_msg );
+
+       return 1;
+
+}
+
 int router_registrar_free( transport_router_registrar* router_registrar ) {
        if( router_registrar == NULL ) return 0;
        jabber_connect_free( router_registrar->jabber );
index 1f0ba00..0162172 100644 (file)
@@ -224,6 +224,8 @@ int fill_fd_set( transport_router_registrar* router, fd_set* set );
 void listen_loop( transport_router_registrar* router );
 
 
+int router_return_server_info( transport_router_registrar* router, transport_message* msg );
+
 int remove_server_class( transport_router_registrar* router, server_class_node* class );
 // ----------------------------------------------------------------------
 // Adds a handler for the SIGUSR1 that we send to wake all the