From c7c97d1a17ea20c931ae940e939b27df223e75b3 Mon Sep 17 00:00:00 2001 From: erickson Date: Fri, 11 Feb 2005 20:26:27 +0000 Subject: [PATCH] added a function to format a timestamp in human readable form git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@47 9efc2488-bf62-4759-914b-345cdb29e865 --- src/srfsh/srfsh.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/srfsh/srfsh.c b/src/srfsh/srfsh.c index baf9a70..40d3bd8 100644 --- a/src/srfsh/srfsh.c +++ b/src/srfsh/srfsh.c @@ -1,8 +1,8 @@ #include "opensrf/transport_client.h" +#include "opensrf/generic_utils.h" +#include -#define SRFSH_SERVER "elroy" #define SRFSH_PORT 5222 -#define SRFSH_USER "admin" #define COMMAND_BUFSIZE 12 @@ -11,6 +11,7 @@ transport_client* client = NULL; int parse_request( char* request ); int handle_router( char* words[] ); +int handle_time( char* words[] ); int parse_error( char* words[] ); int router_query_servers( char* server ); int srfsh_client_connect(); @@ -19,13 +20,16 @@ void print_help(); int main( int argc, char* argv[] ) { + if( argc < 4 ) + fatal_handler( "usage: %s ", argv[0] ); + char request[256]; memset(request, 0, 256); printf(prompt); - client = client_init( SRFSH_SERVER , SRFSH_PORT ); - if( ! client_connect( client, SRFSH_USER, "asdfjkjk", "srfsh", 5 ) ) { - fprintf(stderr, "Unable to connect to jabber server 'elroy' as 'admin'\n"); + client = client_init( argv[1], SRFSH_PORT ); + if( ! client_connect( client, argv[2], argv[3], "srfsh", 5 ) ) { + fprintf(stderr, "Unable to connect to jabber server '%s' as '%s'\n", argv[1], argv[2]); fprintf(stderr, "Most queries will be futile...\n" ); } @@ -105,6 +109,9 @@ int parse_request( char* request ) { if( !strcmp(words[0],"router") ) ret_val = handle_router( words ); + if( !strcmp(words[0],"time") ) + ret_val = handle_time( words ); + if(!ret_val) return parse_error( words ); @@ -136,6 +143,29 @@ int handle_router( char* words[] ) { return 0; } +int handle_time( char* words[] ) { + + if( ! words[1] ) { + + char buf[25]; + memset(buf,0,25); + get_timestamp(buf); + printf( "%s\n", buf ); + return 1; + } + + if( words[1] ) { + time_t epoch = (time_t)atoi( words[1] ); + char* localtime = strdup( ctime( &epoch ) ); + printf( "%s => %s", words[1], localtime ); + free(localtime); + return 1; + } + + return 0; + +} + int router_query_servers( char* router_server ) { @@ -180,7 +210,8 @@ void print_help() { "Commands:\n" "---------------------------------------------------------------------------------\n" "router query servers \n" - "router register \n" + "time\n" + "time \n" "---------------------------------------------------------------------------------\n" ); -- 2.11.0