From 7aac2f36f0986c1d80ee7970d26391d838ba0e0b Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 5 Oct 2005 14:05:12 +0000 Subject: [PATCH] slight C api change, method options are now passed as a single OR'ed group of option flags added some info logging to system git-svn-id: svn://svn.open-ils.org/ILS/trunk@1895 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/c-apps/oils_auth.c | 16 ++--- OpenSRF/bin/opensrf_all | 15 ++++- OpenSRF/src/Makefile | 3 +- OpenSRF/src/c-apps/osrf_dbmath.c | 12 ++-- OpenSRF/src/c-apps/osrf_math.c | 12 ++-- OpenSRF/src/c-apps/osrf_version.c | 4 +- OpenSRF/src/libstack/Makefile | 2 +- OpenSRF/src/libstack/opensrf.c | 84 ++----------------------- OpenSRF/src/libstack/osrf_application.c | 71 ++++++++++----------- OpenSRF/src/libstack/osrf_application.h | 43 +++++-------- OpenSRF/src/libstack/osrf_system.c | 6 +- 11 files changed, 94 insertions(+), 174 deletions(-) diff --git a/Open-ILS/src/c-apps/oils_auth.c b/Open-ILS/src/c-apps/oils_auth.c index 432d8439e9..7ea3556d58 100644 --- a/Open-ILS/src/c-apps/oils_auth.c +++ b/Open-ILS/src/c-apps/oils_auth.c @@ -20,29 +20,29 @@ int osrfAppInitialize() { MODULENAME, "open-ils.auth.authenticate.init", "oilsAuthInit", - "Start the authentication process and returns the intermediate authentication seed", - " [ username ]", 1, 0 ); + "Start the authentication process and returns the intermediate authentication seed" + " PARAMS( username )", 1, 0 ); osrfAppRegisterMethod( MODULENAME, "open-ils.auth.authenticate.complete", "oilsAuthComplete", - "Completes the authentication process and returns the auth token", - "[ username, md5sum( seed + password ) ]", 2, 0 ); + "Completes the authentication process and returns the auth token " + "PARAMS(username, md5sum( seed + password ) )", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "open-ils.auth.session.retrieve", "oilsAuthSessionRetrieve", - "Returns the user object (password blanked) for the given login session", - "[ authToken ]", 1, 0 ); + "Returns the user object (password blanked) for the given login session " + "PARAMS( authToken )", 1, 0 ); osrfAppRegisterMethod( MODULENAME, "open-ils.auth.session.delete", "oilsAuthSessionDelete", - "Destroys the given login session", - "[ authToken ]", 1, 0 ); + "Destroys the given login session " + "PARAMS( authToken )", 1, 0 ); return 0; } diff --git a/OpenSRF/bin/opensrf_all b/OpenSRF/bin/opensrf_all index 10eda5b578..be84350e0b 100755 --- a/OpenSRF/bin/opensrf_all +++ b/OpenSRF/bin/opensrf_all @@ -36,6 +36,7 @@ BOOTSTRAP="$ETCDIR/bootstrap.conf"; # opensrf config is here JSERVER="1"; ROUTER="1"; OPENSRF="1"; +OPENSRFC="1"; JSERVERSOCK="$PREFIX/var/sock/jserver.sock"; # jabber server socket file JSERVERLOG="$LOGDIR/jserver.log" # jabber server log @@ -85,9 +86,16 @@ function startRouter { } function startOpenSRF { - "$BINDIR/opensrf_ctl" start "$BOOTSTRAP"; -} + "$BINDIR/opensrf_ctl" start "$BOOTSTRAP"; + + if [ ! -z "$OPENSRFC" ]; then + echo "Starting OpenSRF-C..."; + # localhost will need to be changed... + "$BINDIR/opensrf-c" localhost "$ETCDIR//opensrf_core.xml" "opensrf" + echo "OpenSRF-C started OK"; + fi +} function makeMeGo { @@ -113,8 +121,8 @@ function makeMeGo { startOpenSRF; echo "OpenSRF started OK"; fi + return 0; - } @@ -122,6 +130,7 @@ function stopMe { echo "Stopping OpenSRF..."; "$BINDIR/opensrf_ctl" stop; + killall -9 opensrf-c; sleep 1; echo "Stopping The Router..."; diff --git a/OpenSRF/src/Makefile b/OpenSRF/src/Makefile index 864b0fca4c..10f9a17ebb 100644 --- a/OpenSRF/src/Makefile +++ b/OpenSRF/src/Makefile @@ -89,6 +89,7 @@ opensrf-install: objson-install @echo $@ cp $(TMPDIR)/$(LIBOPENSRF) $(LIBDIR)/$(LIBOPENSRF) cp $(OPENSRF_HEADERS) $(INCLUDEDIR)/opensrf/ + cp libstack/opensrf $(BINDIR)/opensrf-c make -C c-apps install @@ -101,7 +102,7 @@ objson/libobjson.so: prep # -------------------------------------------------------------------------------- libstack/opensrf.o: libstack/opensrf.c libstack/opensrf: libstack/opensrf.o - $(CC) $(CFLAGS) $(LDFLAGS) -lxml2 -lopensrf -lobjson libstack/opensrf.o -o $@ + $(CC) $(CFLAGS) $(LDFLAGS) -lJudy -lxml2 -lopensrf -lobjson libstack/opensrf.o -o $@ router: libopensrf.so diff --git a/OpenSRF/src/c-apps/osrf_dbmath.c b/OpenSRF/src/c-apps/osrf_dbmath.c index d05a138502..b9d8c807db 100644 --- a/OpenSRF/src/c-apps/osrf_dbmath.c +++ b/OpenSRF/src/c-apps/osrf_dbmath.c @@ -16,29 +16,25 @@ int osrfAppInitialize() { MODULENAME, "add", "osrfMathRun", - "Addss two numbers", - "[ num1, num2 ]", 2, 0 ); + "Addss two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "sub", "osrfMathRun", - "Subtracts two numbers", - "[ num1, num2 ]", 2, 0 ); + "Subtracts two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "mult", "osrfMathRun", - "Multiplies two numbers", - "[ num1, num2 ]", 2, 0 ); + "Multiplies two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "div", "osrfMathRun", - "Divides two numbers", - "[ num1, num2 ]", 2, 0 ); + "Divides two numbers", 2, 0 ); return 0; } diff --git a/OpenSRF/src/c-apps/osrf_math.c b/OpenSRF/src/c-apps/osrf_math.c index fc2bc448ce..a9b955fdd0 100644 --- a/OpenSRF/src/c-apps/osrf_math.c +++ b/OpenSRF/src/c-apps/osrf_math.c @@ -17,30 +17,26 @@ int osrfAppInitialize() { "add", /* the name of the method */ "osrfMathRun", /* the symbol that runs the method */ "Adds two numbers", /* description of the method */ - "( num1, num2 )", /* description of the method params */ 2, /* the minimum number of params required to run the method */ - 0 ); /* streaming method? yes / no */ + 0 ); /* method options, 0 for not special options */ osrfAppRegisterMethod( MODULENAME, "sub", "osrfMathRun", - "Subtracts two numbers", - "( num1, num2 )", 2, 0 ); + "Subtracts two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "mult", "osrfMathRun", - "Multiplies two numbers", - "( num1, num2 )", 2, 0 ); + "Multiplies two numbers", 2, 0 ); osrfAppRegisterMethod( MODULENAME, "div", "osrfMathRun", - "Divides two numbers", - "( num1, num2 )", 2, 0 ); + "Divides two numbers", 2, 0 ); return 0; } diff --git a/OpenSRF/src/c-apps/osrf_version.c b/OpenSRF/src/c-apps/osrf_version.c index ac0e3fbceb..a2187f0ee3 100644 --- a/OpenSRF/src/c-apps/osrf_version.c +++ b/OpenSRF/src/c-apps/osrf_version.c @@ -19,8 +19,8 @@ int osrfAppInitialize() { "osrfVersion", "The data for a service/method/params combination will be retrieved " "from the necessary server and the MD5 sum of the total values received " - "will be returned", - "( serviceName, methodName, [param1, ...] )", 2, 0 ); + "will be returned. PARAMS( serviceName, methodName, [param1, ...] )", + 2, 0 ); return 0; } diff --git a/OpenSRF/src/libstack/Makefile b/OpenSRF/src/libstack/Makefile index 8399594833..badde68691 100644 --- a/OpenSRF/src/libstack/Makefile +++ b/OpenSRF/src/libstack/Makefile @@ -60,4 +60,4 @@ osrf_hash.o: osrf_hash.c osrf_hash.h clean: - /bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c + /bin/rm -f *.o libopensrf_stack.so xml_utils.h xml_utils.c opensrf diff --git a/OpenSRF/src/libstack/opensrf.c b/OpenSRF/src/libstack/opensrf.c index 995fa84383..8bbf880d60 100644 --- a/OpenSRF/src/libstack/opensrf.c +++ b/OpenSRF/src/libstack/opensrf.c @@ -2,84 +2,8 @@ #include "osrf_hash.h" #include "osrf_list.h" -//static void _free(void* i) { free(i); } -//static void _hfree(char* c, void* i) { free(i); } - int main( int argc, char* argv[] ) { - /* - osrfHash* list = osrfNewHash(); - list->freeItem = _hfree; - - char* x = strdup("X"); - char* y = strdup("Y"); - char* z = strdup("Z"); - osrfHashSet( list, x, "test1" ); - osrfHashSet( list, y, "test2" ); - osrfHashSet( list, z, "test3" ); - - char* q = (char*) osrfHashGet( list, "test1" ); - printf( "%s\n", q ); - - q = (char*) osrfHashGet( list, "test2" ); - printf( "%s\n", q ); - - q = (char*) osrfHashGet( list, "test3" ); - printf( "%s\n", q ); - - osrfHashIterator* itr = osrfNewHashIterator(list); - char* val; - - while( (val = osrfHashIteratorNext(itr)) ) - printf("Iterated item: %s\n", val ); - - osrfHashIteratorReset(itr); - while( (val = osrfHashIteratorNext(itr)) ) - printf("Iterated item: %s\n", val ); - - printf( "Count: %lu\n", osrfHashGetCount(list)); - - osrfHashIteratorFree(itr); - - osrfHashFree(list); - - exit(1); - - osrfList* list = osrfNewList(); - list->freeItem = _free; - - char* x = strdup("X"); - char* y = strdup("Y"); - char* z = strdup("Z"); - osrfListSet( list, x, 0 ); - osrfListSet( list, y, 2 ); - osrfListSet( list, z, 4 ); - - char* q = (char*) osrfListGetIndex( list, 4 ); - printf( "%s\n", q ); - - osrfListIterator* itr = osrfNewListIterator( list ); - char* val; - - while( (val = osrfListIteratorNext(itr)) ) - printf("Found val: %s\n", val ); - - osrfListIteratorReset(itr); - printf("\n"); - while( (val = osrfListIteratorNext(itr)) ) - printf("Found val: %s\n", val ); - - osrfListIteratorFree(itr); - - printf( "Count: %lu\n", osrfListGetCount(list)); - - osrfListFree(list); - - exit(1); - */ - - - if( argc < 4 ) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; @@ -88,9 +12,11 @@ int main( int argc, char* argv[] ) { fprintf(stderr, "Loading OpenSRF host %s with bootstrap config %s " "and config context %s\n", argv[1], argv[2], argv[3] ); - char* host = strdup( argv[1] ); - char* config = strdup( argv[2] ); - char* context = strdup( argv[3] ); + /* these must be strdup'ed because init_proc_title / set_proc_title + are evil and overwrite the argv memory */ + char* host = strdup( argv[1] ); + char* config = strdup( argv[2] ); + char* context = strdup( argv[3] ); init_proc_title( argc, argv ); set_proc_title( "OpenSRF System" ); diff --git a/OpenSRF/src/libstack/osrf_application.c b/OpenSRF/src/libstack/osrf_application.c index 0feb9b803e..9f962e55b8 100644 --- a/OpenSRF/src/libstack/osrf_application.c +++ b/OpenSRF/src/libstack/osrf_application.c @@ -59,14 +59,7 @@ int osrfAppRegisterApplication( char* appName, char* soFile ) { int osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming ) { - - return _osrfAppRegisterMethod(appName, methodName, - symbolName, notes, params, argc, streaming, 0 ); -} - -int _osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming, int system ) { + char* symbolName, char* notes, int argc, int options ) { if( !appName || ! methodName ) return -1; @@ -76,15 +69,16 @@ int _osrfAppRegisterMethod( char* appName, char* methodName, debug_handler("Registering method %s for app %s", methodName, appName ); osrfMethod* method = _osrfAppBuildMethod( - methodName, symbolName, notes, params, argc, system, 0 ); - method->streaming = streaming; + methodName, symbolName, notes, argc, options ); + method->options = options; /* plug the method into the list of methods */ osrfHashSet( app->methods, method, method->name ); - if( streaming ) { /* build the atomic counterpart */ + if( options & OSRF_METHOD_STREAMING ) { /* build the atomic counterpart */ + int newops = options | OSRF_METHOD_ATOMIC; osrfMethod* atomicMethod = _osrfAppBuildMethod( - methodName, symbolName, notes, params, argc, system, 1 ); + methodName, symbolName, notes, argc, newops ); osrfHashSet( app->methods, atomicMethod, atomicMethod->name ); } @@ -94,50 +88,46 @@ int _osrfAppRegisterMethod( char* appName, char* methodName, osrfMethod* _osrfAppBuildMethod( char* methodName, - char* symbolName, char* notes, char* params, int argc, int sysmethod, int atomic ) { + char* symbolName, char* notes, int argc, int options ) { osrfMethod* method = safe_malloc(sizeof(osrfMethod)); if(methodName) method->name = strdup(methodName); if(symbolName) method->symbol = strdup(symbolName); if(notes) method->notes = strdup(notes); - if(params) method->paramNotes = strdup(params); method->argc = argc; - method->sysmethod = sysmethod; - method->atomic = atomic; - method->cachable = 0; + method->options = options; - if(atomic) { /* add ".atomic" to the end of the name */ + if(options & OSRF_METHOD_ATOMIC) { /* add ".atomic" to the end of the name */ char mb[strlen(method->name) + 8]; sprintf(mb, "%s.atomic", method->name); free(method->name); method->name = strdup(mb); - method->streaming = 1; + method->options |= OSRF_METHOD_STREAMING; } - debug_handler("Built method %s", method->name ); - return method; } int __osrfAppRegisterSysMethods( char* app ) { - _osrfAppRegisterMethod( + osrfAppRegisterMethod( app, OSRF_SYSMETHOD_INTROSPECT, NULL, "Return a list of methods whose names have the same initial " - "substring as that of the provided method name", - "( methodNameSubstring )", 1, 1 , 1); + "substring as that of the provided method name PARAMS( methodNameSubstring )", + 1, OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING ); - _osrfAppRegisterMethod( + osrfAppRegisterMethod( app, OSRF_SYSMETHOD_INTROSPECT_ALL, NULL, - "Returns a complete list of methods", "()", 0, 1, 1 ); + "Returns a complete list of methods. PARAMS()", 0, + OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING ); - _osrfAppRegisterMethod( + osrfAppRegisterMethod( app, OSRF_SYSMETHOD_ECHO, NULL, - "Echos all data sent to the server back to the client", - "([a, b, ...])", 0, 1, 1); + "Echos all data sent to the server back to the client. PARAMS([a, b, ...])", 0, + OSRF_METHOD_SYSTEM | OSRF_METHOD_STREAMING ); return 0; } @@ -199,7 +189,7 @@ int osrfAppRunMethod( char* appName, char* methodName, int retcode = 0; - if( method->sysmethod ) { + if( method->options & OSRF_METHOD_SYSTEM ) { retcode = __osrfAppRunSystemMethod(&context); } else { @@ -235,7 +225,7 @@ int osrfAppRespondComplete( osrfMethodContext* context, jsonObject* data ) { int _osrfAppRespond( osrfMethodContext* ctx, jsonObject* data, int complete ) { if(!(ctx && ctx->method)) return -1; - if( ctx->method->atomic ) { + if( ctx->method->options & OSRF_METHOD_ATOMIC ) { osrfLog( OSRF_DEBUG, "Adding responses to stash for atomic method %s", ctx->method ); @@ -245,7 +235,9 @@ int _osrfAppRespond( osrfMethodContext* ctx, jsonObject* data, int complete ) { } - if( !ctx->method->atomic && ! ctx->method->cachable ) { + if( !(ctx->method->options & OSRF_METHOD_ATOMIC) && + !(ctx->method->options & OSRF_METHOD_CACHABLE) ) { + if(complete) osrfAppRequestRespondComplete( ctx->session, ctx->request, data ); else @@ -265,7 +257,7 @@ int __osrfAppPostProcess( osrfMethodContext* ctx, int retcode ) { osrfLog( OSRF_DEBUG, "Postprocessing method %s with retcode %d", ctx->method->name, retcode ); - if(ctx->responses) { /* we have cached responses to return */ + if(ctx->responses) { /* we have cached responses to return (no responses have been sent) */ osrfAppRequestRespondComplete( ctx->session, ctx->request, ctx->responses ); jsonObjectFree(ctx->responses); @@ -294,15 +286,20 @@ int osrfAppRequestRespondException( osrfAppSession* ses, int request, char* msg, static void __osrfAppSetIntrospectMethod( osrfMethodContext* ctx, osrfMethod* method, jsonObject* resp ) { if(!(ctx && resp)) return; + jsonObjectSetKey(resp, "api_name", jsonNewObject(method->name)); jsonObjectSetKey(resp, "method", jsonNewObject(method->symbol)); jsonObjectSetKey(resp, "service", jsonNewObject(ctx->session->remote_service)); jsonObjectSetKey(resp, "notes", jsonNewObject(method->notes)); jsonObjectSetKey(resp, "argc", jsonNewNumberObject(method->argc)); - jsonObjectSetKey(resp, "params", jsonNewObject(method->paramNotes) ); - jsonObjectSetKey(resp, "sysmethod", jsonNewNumberObject(method->sysmethod) ); - jsonObjectSetKey(resp, "atomic", jsonNewNumberObject(method->atomic) ); - jsonObjectSetKey(resp, "cachable", jsonNewNumberObject(method->cachable) ); + + jsonObjectSetKey(resp, "sysmethod", + jsonNewNumberObject( (method->options & OSRF_METHOD_SYSTEM) ? 1 : 0 )); + jsonObjectSetKey(resp, "atomic", + jsonNewNumberObject( (method->options & OSRF_METHOD_ATOMIC) ? 1 : 0 )); + jsonObjectSetKey(resp, "cachable", + jsonNewNumberObject( (method->options & OSRF_METHOD_CACHABLE) ? 1 : 0 )); + jsonObjectSetClass(resp, "method"); } diff --git a/OpenSRF/src/libstack/osrf_application.h b/OpenSRF/src/libstack/osrf_application.h index 4dea5a2809..78868d88b9 100644 --- a/OpenSRF/src/libstack/osrf_application.h +++ b/OpenSRF/src/libstack/osrf_application.h @@ -67,17 +67,16 @@ #define OSRF_SYSMETHOD_ECHO "opensrf.system.echo" #define OSRF_SYSMETHOD_ECHO_ATOMIC "opensrf.system.echo.atomic" -//#define OSRF_METHOD_ATOMIC 1 -//#define OSRF_METHOD_CACHABLE 2 +#define OSRF_METHOD_SYSTEM 1 +#define OSRF_METHOD_STREAMING 2 +#define OSRF_METHOD_ATOMIC 4 +#define OSRF_METHOD_CACHABLE 8 struct _osrfApplicationStruct { - //char* name; /* the name of our application */ void* handle; /* the lib handle */ osrfHash* methods; - //struct _osrfMethodStruct* methods; /* list of methods */ -// struct _osrfApplicationStruct* next; /* next application */ }; typedef struct _osrfApplicationStruct osrfApplication; @@ -87,12 +86,15 @@ struct _osrfMethodStruct { char* symbol; /* the symbol name (function) */ char* notes; /* public method documentation */ int argc; /* how many args this method expects */ - char* paramNotes; /* Description of the params expected for this method */ -// struct _osrfMethodStruct* next; /* nest method in the list */ - int sysmethod; /* true if this is a system method */ - int streaming; /* true if this is a streamable method */ - int atomic; /* true if the method is an atomic method */ - int cachable; /* true if the method is cachable */ + //char* paramNotes; /* Description of the params expected for this method */ + int options; /* describes the various options for this method */ + + /* + int sysmethod; + int streaming; + int atomic; + int cachable; + */ }; typedef struct _osrfMethodStruct osrfMethod; @@ -117,33 +119,22 @@ int osrfAppRegisterApplication( char* appName, char* soFile ); /** Register a method + Any method with the OSRF_METHOD_STREAMING option set will have a ".atomic" + version of the method registered automatically @param appName The name of the application that implements the method @param methodName The fully qualified name of the method @param symbolName The symbol name (function) that implements the method @param notes Public documentation for this method. - @params params String description description of the params expected @params argc The number of arguments this method expects @param streaming True if this is a streaming method that requires an atomic version @return 0 on success, -1 on error */ int osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming ); + char* symbolName, char* notes, int argc, int options ); -int _osrfAppRegisterMethod( char* appName, char* methodName, - char* symbolName, char* notes, char* params, int argc, int streaming, int system ); osrfMethod* _osrfAppBuildMethod( char* methodName, - char* symbolName, char* notes, char* params, int argc, int sysmethod, int streaming ); - -/** - Registher a method - @param appName The name of the application that implements the method - @params desc The method description - @return 0 on success, -1 on error - */ -/* -int osrfAppRegisterMethod( char* appName, osrfMethodDescription* desc ); -*/ + char* symbolName, char* notes, int argc, int options ); /** Finds the given app in the list of apps diff --git a/OpenSRF/src/libstack/osrf_system.c b/OpenSRF/src/libstack/osrf_system.c index d6c9e854b5..eac1c692d6 100644 --- a/OpenSRF/src/libstack/osrf_system.c +++ b/OpenSRF/src/libstack/osrf_system.c @@ -103,6 +103,7 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) { } else { + fprintf(stderr, " * Running application %s\n", appname); if( osrfAppRegisterApplication( appname, libfile ) == 0 ) osrf_prefork_run(appname); @@ -114,7 +115,8 @@ int osrfSystemBootstrap( char* hostname, char* configfile, char* contextNode ) { /** daemonize me **/ - /* let our children do their thing */ + /* background and let our children do their thing */ + daemonize(); while(1) { signal(SIGCHLD, __osrfSystemSignalHandler); sleep(10000); @@ -215,3 +217,5 @@ void __osrfSystemSignalHandler( int sig ) { /** relaunch the server **/ } + + -- 2.43.2