[Opensrf-commits] r1626 - in trunk: include/opensrf src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jan 14 09:36:16 EST 2009


Author: scottmk
Date: 2009-01-14 09:36:14 -0500 (Wed, 14 Jan 2009)
New Revision: 1626

Modified:
   trunk/include/opensrf/osrf_application.h
   trunk/src/libopensrf/osrf_application.c
Log:
Add a function osrfMethodVerifyContext() to do what the
existing OSRF_METHOD_VERIFY_CONTEXT macro does.  Use it in
_osrfAppRunSystemMethod() and osrfAppEcho().


Modified: trunk/include/opensrf/osrf_application.h
===================================================================
--- trunk/include/opensrf/osrf_application.h	2009-01-13 23:17:45 UTC (rev 1625)
+++ trunk/include/opensrf/osrf_application.h	2009-01-14 14:36:14 UTC (rev 1626)
@@ -31,10 +31,10 @@
   This macro verifies methods receive the correct parameters */
 #define _OSRF_METHOD_VERIFY_CONTEXT(d) \
 	if(!d) return -1; \
-	if(!d->session) { osrfLogError( OSRF_LOG_MARK,  "Session is NULL in app reqeust" ); return -1; }\
-	if(!d->method) { osrfLogError( OSRF_LOG_MARK,  "Method is NULL in app reqeust" ); return -1; }\
+	if(!d->session) { osrfLogError( OSRF_LOG_MARK,  "Session is NULL in app request" ); return -1; }\
+	if(!d->method) { osrfLogError( OSRF_LOG_MARK,  "Method is NULL in app request" ); return -1; }\
 	if(d->method->argc) {\
-		if(!d->params) { osrfLogError( OSRF_LOG_MARK,  "Params is NULL in app reqeust %s", d->method->name ); return -1; }\
+		if(!d->params) { osrfLogError( OSRF_LOG_MARK,  "Params is NULL in app request %s", d->method->name ); return -1; }\
 		if( d->params->type != JSON_ARRAY ) { \
 			osrfLogError( OSRF_LOG_MARK,  "'params' is not a JSON array for method %s", d->method->name);\
 			return -1; }\
@@ -187,6 +187,12 @@
 int osrfAppRunChildInit(const char* appname);
 void osrfAppRunExitCode();
 
+/**
+  Determine whether the context looks healthy.
+  Return 0 if it does, or -1 if it doesn't.
+  */
+int osrfMethodVerifyContext( osrfMethodContext* ctx );
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/src/libopensrf/osrf_application.c
===================================================================
--- trunk/src/libopensrf/osrf_application.c	2009-01-13 23:17:45 UTC (rev 1625)
+++ trunk/src/libopensrf/osrf_application.c	2009-01-14 14:36:14 UTC (rev 1626)
@@ -419,7 +419,10 @@
   message
  */
 static int _osrfAppRunSystemMethod(osrfMethodContext* ctx) {
-	OSRF_METHOD_VERIFY_CONTEXT(ctx);
+	if( osrfMethodVerifyContext( ctx ) < 0 ) {
+		osrfLogError( OSRF_LOG_MARK,  "_osrfAppRunSystemMethod: Received invalid method context" );
+		return -1;
+	}
 
 	if(	!strcmp(ctx->method->name, OSRF_SYSMETHOD_INTROSPECT_ALL ) || 
 			!strcmp(ctx->method->name, OSRF_SYSMETHOD_INTROSPECT_ALL_ATOMIC )) {
@@ -502,7 +505,11 @@
 }
 
 static int osrfAppEcho( osrfMethodContext* ctx ) {
-	OSRF_METHOD_VERIFY_CONTEXT(ctx);
+	if( osrfMethodVerifyContext( ctx ) < 0 ) {
+		osrfLogError( OSRF_LOG_MARK,  "osrfAppEcho: Received invalid method context" );
+		return -1;
+	}
+	
 	int i;
 	for( i = 0; i < ctx->params->size; i++ ) {
 		const jsonObject* str = jsonObjectGetIndex(ctx->params,i);
@@ -511,3 +518,53 @@
 	return 1;
 }
 
+/**
+  Determine whether the context looks healthy.
+  Return 0 if it does, or -1 if it doesn't.
+ */
+int osrfMethodVerifyContext( osrfMethodContext* ctx )
+{
+	if( !ctx ) {
+		osrfLogError( OSRF_LOG_MARK,  "Context is NULL in app request" );
+		return -1;
+	}
+	
+	if( !ctx->session ) {
+		osrfLogError( OSRF_LOG_MARK,  "Session is NULL in app request" );
+		return -1;
+	}
+
+	if( !ctx->method )
+	{
+		osrfLogError( OSRF_LOG_MARK, "Method is NULL in app request" );
+		return -1;
+	}
+
+	if( ctx->method->argc ) {
+		if( !ctx->params ) {
+			osrfLogError( OSRF_LOG_MARK,
+				"Params is NULL in app request %s", ctx->method->name );
+			return -1;
+		}
+		if( ctx->params->type != JSON_ARRAY ) {
+			osrfLogError( OSRF_LOG_MARK,
+				"'params' is not a JSON array for method %s", ctx->method->name );
+			return -1;
+		}
+	}
+
+	if( !ctx->method->name ) {
+		osrfLogError( OSRF_LOG_MARK, "Method name is NULL" );
+		 return -1;
+	}
+
+	// Log the call, with the method and parameters
+	char* params_str = jsonObjectToJSON( ctx->params );
+	if( params_str ) {
+		osrfLogInfo( OSRF_LOG_MARK, "CALL:	%s %s - %s",
+			 ctx->session->remote_service, ctx->method->name, params_str );
+		free( params_str );
+	}
+	return 0;
+}
+



More information about the opensrf-commits mailing list