[Opensrf-commits] r1026 - in branches/new-json2: . src/srfsh
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jul 11 18:17:56 EDT 2007
Author: erickson
Date: 2007-07-11 18:13:11 -0400 (Wed, 11 Jul 2007)
New Revision: 1026
Removed:
branches/new-json2/src/srfsh/srfsh.h
Modified:
branches/new-json2/
branches/new-json2/src/srfsh/Makefile
branches/new-json2/src/srfsh/srfsh.c
Log:
merged in latest changes from trunk
Property changes on: branches/new-json2
___________________________________________________________________
Name: svnmerge-integrated
- /trunk:1-1016
+ /trunk:1-1025
Modified: branches/new-json2/src/srfsh/Makefile
===================================================================
--- branches/new-json2/src/srfsh/Makefile 2007-07-11 21:35:51 UTC (rev 1025)
+++ branches/new-json2/src/srfsh/Makefile 2007-07-11 22:13:11 UTC (rev 1026)
@@ -6,7 +6,7 @@
all: srfsh
srfsh: srfsh.o
-srfsh.o: srfsh.c srfsh.h
+srfsh.o: srfsh.c
install:
cp srfsh $(BINDIR)
Modified: branches/new-json2/src/srfsh/srfsh.c
===================================================================
--- branches/new-json2/src/srfsh/srfsh.c 2007-07-11 21:35:51 UTC (rev 1025)
+++ branches/new-json2/src/srfsh/srfsh.c 2007-07-11 22:13:11 UTC (rev 1026)
@@ -1,10 +1,81 @@
-#include "srfsh.h"
+#include <opensrf/transport_client.h>
+#include <opensrf/osrf_message.h>
+#include <opensrf/osrf_app_session.h>
+#include <time.h>
+#include <sys/timeb.h>
+#include <sys/types.h>
+#include <sys/wait.h>
-int recv_timeout = 120;
-int is_from_script = 0;
-FILE* shell_writer = NULL;
-FILE* shell_reader = NULL;
+#include <opensrf/utils.h>
+#include <opensrf/log.h>
+#include <signal.h>
+
+#include <stdio.h>
+#include <readline/readline.h>
+#include <readline/history.h>
+
+#define SRFSH_PORT 5222
+#define COMMAND_BUFSIZE 4096
+
+
+/* shell prompt */
+static const char* prompt = "srfsh# ";
+
+static char* history_file = NULL;
+
+//static int child_dead = 0;
+
+static char* login_session = NULL;
+
+/* true if we're pretty printing json results */
+static int pretty_print = 1;
+/* true if we're bypassing 'less' */
+static int raw_print = 0;
+
+/* our jabber connection */
+static transport_client* client = NULL;
+
+/* the last result we received */
+static osrf_message* last_result = NULL;
+
+/* functions */
+static int parse_request( char* request );
+
+/* handles router requests */
+static int handle_router( char* words[] );
+
+/* utility method for print time data */
+/* static int handle_time( char* words[] ); */
+
+/* handles app level requests */
+static int handle_request( char* words[], int relay );
+//static int handle_exec(char* words[], int new_shell);
+static int handle_set( char* words[]);
+static int handle_print( char* words[]);
+static int send_request( char* server,
+ char* method, growing_buffer* buffer, int relay );
+static int parse_error( char* words[] );
+static int router_query_servers( const char* server );
+static int print_help( void );
+
+//static int srfsh_client_connect();
+//static char* tabs(int count);
+//static void sig_child_handler( int s );
+//static void sig_int_handler( int s );
+
+static int load_history( void );
+static int handle_math( char* words[] );
+static int do_math( int count, int style );
+static int handle_introspect(char* words[]);
+static int handle_login( char* words[]);
+
+static int recv_timeout = 120;
+static int is_from_script = 0;
+static FILE* shell_writer = NULL;
+// static FILE* shell_reader = NULL;
+
+
int main( int argc, char* argv[] ) {
/* --------------------------------------------- */
@@ -85,9 +156,11 @@
return 0;
}
-void sig_child_handler( int s ) {
+/*
+static void sig_child_handler( int s ) {
child_dead = 1;
}
+*/
/*
void sig_int_handler( int s ) {
@@ -97,7 +170,7 @@
}
*/
-int load_history() {
+static int load_history( void ) {
char* home = getenv("HOME");
int l = strlen(home) + 24;
@@ -115,34 +188,32 @@
}
-int parse_error( char* words[] ) {
+static int parse_error( char* words[] ) {
if( ! words )
return 0;
-
- int i = 0;
- char* current;
- char buffer[256];
- memset(buffer, 0, 256);
- while( (current=words[i++]) ) {
- strcat(buffer, current);
- strcat(buffer, " ");
+ growing_buffer * gbuf = buffer_init( 64 );
+ buffer_add( gbuf, *words );
+ while( *++words ) {
+ buffer_add( gbuf, " " );
+ buffer_add( gbuf, *words );
}
- if( ! buffer || strlen(buffer) < 1 )
- printf("\n");
-
- fprintf( stderr, "???: %s\n", buffer );
+ fprintf( stderr, "???: %s\n", gbuf->buf );
+ buffer_free( gbuf );
+
return 0;
}
-int parse_request( char* request ) {
+static int parse_request( char* request ) {
if( request == NULL )
return 0;
+ char * original_request = strdup( request );
+
int ret_val = 0;
int i = 0;
char* words[COMMAND_BUFSIZE];
@@ -152,7 +223,10 @@
char* cur_tok = strtok( req, " " );
if( cur_tok == NULL )
+ {
+ free( original_request );
return 0;
+ }
while(cur_tok != NULL) {
words[i++] = cur_tok;
@@ -196,9 +270,14 @@
else if (!strcmp(words[0],"login"))
ret_val = handle_login(words);
- else if (words[0][0] == '!')
- ret_val = handle_exec( words, 1 );
-
+ else if (words[0][0] == '!') {
+ //ret_val = handle_exec( words, 1 );
+ system( original_request + 1 );
+ ret_val = 1;
+ }
+
+ free( original_request );
+
if(!ret_val) {
#ifdef EXEC_DEFAULT
return handle_exec( words, 0 );
@@ -212,7 +291,7 @@
}
-int handle_introspect(char* words[]) {
+static int handle_introspect(char* words[]) {
if(words[1] && words[2]) {
fprintf(stderr, "--> %s\n", words[1]);
@@ -236,7 +315,7 @@
}
-int handle_login( char* words[]) {
+static int handle_login( char* words[]) {
if( words[1] && words[2]) {
@@ -317,7 +396,7 @@
return 0;
}
-int handle_set( char* words[]) {
+static int handle_set( char* words[]) {
char* variable;
if( (variable=words[1]) ) {
@@ -358,7 +437,7 @@
}
-int handle_print( char* words[]) {
+static int handle_print( char* words[]) {
char* variable;
if( (variable=words[1]) ) {
@@ -381,7 +460,7 @@
return 0;
}
-int handle_router( char* words[] ) {
+static int handle_router( char* words[] ) {
if(!client)
return 1;
@@ -407,7 +486,8 @@
/* if new shell, spawn a new child and subshell to do the work,
otherwise pipe the request to the currently open (piped) shell */
-int handle_exec(char* words[], int new_shell) {
+/*
+static int handle_exec(char* words[], int new_shell) {
if(!words[0]) return 0;
@@ -416,7 +496,7 @@
char command[len];
memset(command,0,len);
- int i; /* chop out the ! */
+ int i; // chop out the !
for( i=1; i!= len; i++) {
command[i-1] = words[0][i];
}
@@ -451,33 +531,21 @@
buffer_add( b, "\n");
- //int reader;
- //int reader = dup2(STDOUT_FILENO, reader);
- //int reader = dup(STDOUT_FILENO);
- //close(STDOUT_FILENO);
-
fprintf( shell_writer, b->buf );
buffer_free(b);
fflush(shell_writer);
usleep(1000);
- /*
- char c[4096];
- bzero(c, 4096);
- read( reader, c, 4095 );
- fprintf(stderr, "read %s", c);
- dup2(reader, STDOUT_FILENO);
- */
-
}
return 1;
}
+*/
-int handle_request( char* words[], int relay ) {
+static int handle_request( char* words[], int relay ) {
if(!client)
return 1;
@@ -662,7 +730,7 @@
}
/*
-int handle_time( char* words[] ) {
+static int handle_time( char* words[] ) {
if( ! words[1] ) {
@@ -688,7 +756,7 @@
-int router_query_servers( char* router_server ) {
+static int router_query_servers( const char* router_server ) {
if( ! router_server || strlen(router_server) == 0 )
return 0;
@@ -724,17 +792,19 @@
return 1;
}
-
-int print_help() {
+static int print_help( void ) {
+
printf(
"---------------------------------------------------------------------------------\n"
"Commands:\n"
"---------------------------------------------------------------------------------\n"
"help - Display this message\n"
"!<command> [args] - Forks and runs the given command in the shell\n"
- "time - Prints the current time\n"
+ /*
+ "time - Prints the current time\n"
"time <timestamp> - Formats seconds since epoch into readable format\n"
+ */
"set <variable> <value> - set a srfsh variable (e.g. set pretty_print true )\n"
"print <variable> - Displays the value of a srfsh variable\n"
"---------------------------------------------------------------------------------\n"
@@ -778,8 +848,8 @@
}
-
-char* tabs(int count) {
+/*
+static char* tabs(int count) {
growing_buffer* buf = buffer_init(24);
int i;
for(i=0;i!=count;i++)
@@ -789,15 +859,17 @@
buffer_free( buf );
return final;
}
+*/
-int handle_math( char* words[] ) {
+
+static int handle_math( char* words[] ) {
if( words[1] )
return do_math( atoi(words[1]), 0 );
return 0;
}
-int do_math( int count, int style ) {
+static int do_math( int count, int style ) {
osrf_app_session* session = osrf_app_client_session_init( "opensrf.math" );
osrf_app_session_connect(session);
Deleted: branches/new-json2/src/srfsh/srfsh.h
===================================================================
--- branches/new-json2/src/srfsh/srfsh.h 2007-07-11 21:35:51 UTC (rev 1025)
+++ branches/new-json2/src/srfsh/srfsh.h 2007-07-11 22:13:11 UTC (rev 1026)
@@ -1,73 +0,0 @@
-#include <opensrf/transport_client.h>
-#include <opensrf/osrf_message.h>
-#include <opensrf/osrf_app_session.h>
-#include <time.h>
-#include <sys/timeb.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <opensrf/utils.h>
-#include <opensrf/log.h>
-
-#include <signal.h>
-
-#include <stdio.h>
-#include <readline/readline.h>
-#include <readline/history.h>
-
-
-
-
-#define SRFSH_PORT 5222
-#define COMMAND_BUFSIZE 4096
-
-
-/* shell prompt */
-char* prompt = "srfsh# ";
-
-char* history_file = NULL;
-
-int child_dead = 0;
-
-char* login_session = NULL;
-
-/* true if we're pretty printing json results */
-int pretty_print = 1;
-/* true if we're bypassing 'less' */
-int raw_print = 0;
-
-/* our jabber connection */
-transport_client* client = NULL;
-
-/* the last result we received */
-osrf_message* last_result = NULL;
-
-/* functions */
-int parse_request( char* request );
-
-/* handles router requests */
-int handle_router( char* words[] );
-
-/* utility method for print time data */
-int handle_time( char* words[] );
-
-/* handles app level requests */
-int handle_request( char* words[], int relay );
-int handle_exec(char* words[], int new_shell);
-int handle_set( char* words[]);
-int handle_print( char* words[]);
-int send_request( char* server,
- char* method, growing_buffer* buffer, int relay );
-int parse_error( char* words[] );
-int router_query_servers( char* server );
-int srfsh_client_connect();
-int print_help();
-char* tabs(int count);
-void sig_child_handler( int s );
-void sig_int_handler( int s );
-
-int load_history();
-int handle_math( char* words[] );
-int do_math( int count, int style );
-int handle_introspect(char* words[]);
-int handle_login( char* words[]);
More information about the opensrf-commits
mailing list