From 822fd726f7bcef7bf7f77f05751fee63fb836970 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 12 Sep 2005 22:20:08 +0000 Subject: [PATCH] changed around the status method some added the framework for processing 'system' method (introspect, etc.) implemented opensrf.system.method.all git-svn-id: svn://svn.open-ils.org/ILS/trunk@1820 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- OpenSRF/src/libstack/Makefile | 2 +- OpenSRF/src/libstack/osrf_app_session.c | 4 +- OpenSRF/src/libstack/osrf_app_session.h | 2 +- OpenSRF/src/libstack/osrf_application.c | 71 +++++++++++++++++++++---- OpenSRF/src/libstack/osrf_application.h | 20 ++++++- OpenSRF/src/libstack/osrf_log.c | 3 ++ OpenSRF/src/libstack/osrf_stack.c | 4 +- 7 files changed, 89 insertions(+), 17 deletions(-) diff --git a/OpenSRF/src/libstack/Makefile b/OpenSRF/src/libstack/Makefile index a6e5c00566..1ff362a3c9 100644 --- a/OpenSRF/src/libstack/Makefile +++ b/OpenSRF/src/libstack/Makefile @@ -1,5 +1,5 @@ -CFLAGS += -DASSUME_STATELESS -rdynamic -fno-strict-aliasing +CFLAGS += -DASSUME_STATELESS -DOSRF_LOG_PARAMS -rdynamic -fno-strict-aliasing LDLIBS += -lxml2 -lobjson -ldl -lmemcache TARGETS = osrf_message.o \ diff --git a/OpenSRF/src/libstack/osrf_app_session.c b/OpenSRF/src/libstack/osrf_app_session.c index 559053a624..83a16445a5 100644 --- a/OpenSRF/src/libstack/osrf_app_session.c +++ b/OpenSRF/src/libstack/osrf_app_session.c @@ -757,11 +757,11 @@ int osrfAppRequestRespondComplete( -int osrfAppSessionStatus( osrfAppSession* ses, int type, int reqId, char* message ) { +int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message ) { if(ses) { osrf_message* msg = osrf_message_init( STATUS, reqId, 1); - osrf_message_set_status_info( msg, "Server Error", message, type ); + osrf_message_set_status_info( msg, name, message, type ); _osrf_app_session_send( ses, msg ); osrf_message_free( msg ); return 0; diff --git a/OpenSRF/src/libstack/osrf_app_session.h b/OpenSRF/src/libstack/osrf_app_session.h index 84a7c09d92..8489cf2836 100644 --- a/OpenSRF/src/libstack/osrf_app_session.h +++ b/OpenSRF/src/libstack/osrf_app_session.h @@ -225,7 +225,7 @@ int osrfAppSessionSendBatch( osrf_app_session*, osrf_message* msgs[], int size ) int osrfAppRequestRespond( osrfAppSession* ses, int requestId, jsonObject* data ); int osrfAppRequestRespondComplete( osrfAppSession* ses, int requestId, jsonObject* data ); -int osrfAppSessionStatus( osrfAppSession* ses, int type, int reqId, char* message ); +int osrfAppSessionStatus( osrfAppSession* ses, int type, char* name, int reqId, char* message ); #endif diff --git a/OpenSRF/src/libstack/osrf_application.c b/OpenSRF/src/libstack/osrf_application.c index cb2c16e700..4aa3369361 100644 --- a/OpenSRF/src/libstack/osrf_application.c +++ b/OpenSRF/src/libstack/osrf_application.c @@ -1,5 +1,6 @@ - #include "osrf_application.h" +#include "osrf_log.h" +#include "objson/object.h" osrfApplication* __osrfAppList = NULL; @@ -114,6 +115,10 @@ int osrfAppRunMethod( char* appName, char* methodName, osrfAppSession* ses, int osrfMethod* method; osrfMethodContext context; + context.session = ses; + context.params = params; + context.request = reqId; + /* this is the method we're gonna run */ int (*meth) (osrfMethodContext*); @@ -123,9 +128,25 @@ int osrfAppRunMethod( char* appName, char* methodName, osrfAppSession* ses, int if( !(app = _osrfAppFindApplication(appName)) ) return warning_handler( "Application not found: %s", appName ); - if( !(method = __osrfAppFindMethod( app, methodName )) ) + + if( !(method = __osrfAppFindMethod( app, methodName )) ) { + /* see if the unfound method is a system method */ + info_handler("Method %s not found, checking to see if it's a system method...", methodName ); + osrfMethod meth; + meth.name = methodName; + context.method = &meth; + int sysres = __osrfAppRunSystemMethod(&context); + if(sysres == 0) return 0; + if(sysres > 0) { + osrfAppSessionStatus( ses, OSRF_STATUS_COMPLETE, "osrfConnectStatus", reqId, "Request Complete" ); + return 0; + } return warning_handler( "NOT FOUND: app %s / method %s", appName, methodName ); + } + + context.method = method; + /* open the method */ *(void **) (&meth) = dlsym(app->handle, method->symbol); @@ -134,25 +155,55 @@ int osrfAppRunMethod( char* appName, char* methodName, osrfAppSession* ses, int "for method %s and app %s", method->symbol, method->name, app->name ); } - context.session = ses; - context.method = method; - context.params = params; - context.request = reqId; - /* run the method */ int ret = (*meth) (&context); debug_handler("method returned %d", ret ); - if(ret == -1) { - osrfAppSessionStatus( ses, OSRF_STATUS_INTERNALSERVERERROR, - reqId, "An unknown server error occurred" ); + osrfAppSessionStatus( ses, OSRF_STATUS_INTERNALSERVERERROR, + "Server Error", reqId, "An unknown server error occurred" ); return -1; } + if( ret > 0 ) + osrfAppSessionStatus( ses, OSRF_STATUS_COMPLETE, "osrfConnectStatus", reqId, "Request Complete" ); + return 0; } +int __osrfAppRunSystemMethod(osrfMethodContext* ctx) { + OSRF_METHOD_VERIFY_CONTEXT(ctx); + + if( !strcmp(ctx->method->name, OSRF_SYSMETHOD_INTROSPECT_ALL )) { + + jsonObject* resp = NULL; + osrfApplication* app = _osrfAppFindApplication( ctx->session->remote_service ); + if(app) { + osrfMethod* method = app->methods; + while(method) { + resp = jsonNewObject(NULL); + 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)); + osrfAppRequestRespond(ctx->session, ctx->request, resp); + method = method->next; + jsonObjectSetClass(resp, "method"); + jsonObjectFree(resp); + } + return 1; + } + + return -1; + } + + return -1; +} + + + + diff --git a/OpenSRF/src/libstack/osrf_application.h b/OpenSRF/src/libstack/osrf_application.h index 2921952aba..23e5a301bb 100644 --- a/OpenSRF/src/libstack/osrf_application.h +++ b/OpenSRF/src/libstack/osrf_application.h @@ -6,6 +6,7 @@ #include "objson/object.h" #include "osrf_app_session.h" + /** This macro verifies methods receive the correct parameters */ @@ -26,7 +27,7 @@ _OSRF_METHOD_VERIFY_CONTEXT(d); \ char* __j = jsonObjectToJSON(d->params);\ if(__j) { \ - osrfLog( OSRF_DEBUG, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\ + osrfLog( OSRF_INFO, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\ free(__j); \ } #else @@ -34,6 +35,12 @@ #endif + + +#define OSRF_SYSMETHOD_INTROSPECT "opensrf.system.method" +#define OSRF_SYSMETHOD_INTROSPECT_ALL "opensrf.system.method.all" + + @@ -124,3 +131,14 @@ int osrfAppRunMethod( char* appName, char* methodName, osrfAppSession* ses, int reqId, jsonObject* params ); +/** + Trys to run the requested method as a system method. + A system method is a well known method that all + servers implement. + @param context The current method context + @return 0 if the method is run, -1 otherwise + */ +int __osrfAppRunSystemMethod(osrfMethodContext* context); + + + diff --git a/OpenSRF/src/libstack/osrf_log.c b/OpenSRF/src/libstack/osrf_log.c index a39de329fc..2bdb2dc247 100644 --- a/OpenSRF/src/libstack/osrf_log.c +++ b/OpenSRF/src/libstack/osrf_log.c @@ -59,6 +59,9 @@ void osrfLog( enum OSRF_LOG_LEVEL level, char* msg, ... ) { VA_LIST_TO_STRING(msg); fprintf(file, "[%s.%s %d %d] %s\n", timebuf, millis + 2, getpid(), level, VA_BUF ); fclose(file); + + if( level == OSRF_ERROR ) + fprintf(stderr, "[%s.%s %d %d] %s\n", timebuf, millis + 2, getpid(), level, VA_BUF ); } diff --git a/OpenSRF/src/libstack/osrf_stack.c b/OpenSRF/src/libstack/osrf_stack.c index c69529fc98..4fb39550be 100644 --- a/OpenSRF/src/libstack/osrf_stack.c +++ b/OpenSRF/src/libstack/osrf_stack.c @@ -201,8 +201,8 @@ osrf_message* _do_server( osrf_app_session* session, osrf_message* msg ) { return NULL; case CONNECT: - osrfAppSessionStatus( session, - OSRF_STATUS_OK, msg->thread_trace, "Connection Successful" ); + osrfAppSessionStatus( session, OSRF_STATUS_OK, + "osrfConnectStatus", msg->thread_trace, "Connection Successful" ); return NULL; case REQUEST: -- 2.43.2