4 #include "opensrf/utils.h"
5 #include "opensrf/logging.h"
6 #include "objson/object.h"
7 #include "osrf_app_session.h"
10 This macro verifies methods receive the correct parameters
13 #define _OSRF_METHOD_VERIFY_CONTEXT(d) \
15 if(!d->session) { osrfLog( OSRF_ERROR, "Session is NULL in app reqeust" ); return -1; }\
16 if(!d->method) { osrfLog( OSRF_ERROR, "Method is NULL in app reqeust" ); return -1; }\
17 if(!d->params) { osrfLog( OSRF_ERROR, "Params is NULL in app reqeust %s", d->method->name ); return -1; }\
18 if( d->params->type != JSON_ARRAY ) { \
19 osrfLog( OSRF_ERROR, "'params' is not a JSON array for method %s", d->method->name);\
21 if( !d->method->name ) { osrfLog(OSRF_ERROR, "Method name is NULL"); return -1; }
24 #ifdef OSRF_LOG_PARAMS
25 #define OSRF_METHOD_VERIFY_CONTEXT(d) \
26 _OSRF_METHOD_VERIFY_CONTEXT(d); \
27 char* __j = jsonObjectToJSON(d->params);\
29 osrfLog( OSRF_DEBUG, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\
33 #define OSRF_METHOD_VERIFY_CONTEXT(d) _OSRF_METHOD_VERIFY_CONTEXT(d);
41 struct _osrfApplicationStruct {
42 char* name; /* the name of our application */
43 void* handle; /* the lib handle */
44 struct _osrfMethodStruct* methods; /* list of methods */
45 struct _osrfApplicationStruct* next; /* next application */
47 typedef struct _osrfApplicationStruct osrfApplication;
50 struct _osrfMethodStruct {
51 char* name; /* the method name */
52 char* symbol; /* the symbol name (function) */
53 char* notes; /* public method documentation */
54 int argc; /* how many args this method expects */
55 void* methodHandle; /* cached version of the method handle */
56 struct _osrfMethodStruct* next;
58 typedef struct _osrfMethodStruct osrfMethod;
60 struct _osrfMethodContextStruct {
61 osrfAppSession* session;
66 typedef struct _osrfMethodContextStruct osrfMethodContext;
70 Register an application
71 @param appName The name of the application
72 @param soFile The library (.so) file that implements this application
73 @return 0 on success, -1 on error
75 int osrfAppRegisterApplication( char* appName, char* soFile );
79 @param appName The name of the application that implements the method
80 @param methodName The fully qualified name of the method
81 @param symbolName The symbol name (function) that implements the method
82 @param notes Public documentation for this method.
83 @params argc The number of arguments this method expects
84 @return 0 on success, -1 on error
86 int osrfAppRegisterMethod( char* appName,
87 char* methodName, char* symbolName, char* notes, int argc );
90 Finds the given app in the list of apps
91 @param name The name of the application
92 @return The application pointer or NULL if there is no such application
94 osrfApplication* _osrfAppFindApplication( char* name );
97 Finds the given method for the given app
98 @param appName The application
99 @param methodName The method to find
100 @return A method pointer or NULL if no such method
101 exists for the given application
103 osrfMethod* _osrfAppFindMethod( char* appName, char* methodName );
106 Finds the given method for the given app
107 @param app The application object
108 @param methodName The method to find
109 @return A method pointer or NULL if no such method
110 exists for the given application
112 osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName );
116 Runs the specified method for the specified application.
117 @param appName The name of the application who's method to run
118 @param methodName The name of the method to run
119 @param ses The app session attached to this request
120 @params reqId The request id for this request
121 @param params The method parameters
123 int osrfAppRunMethod( char* appName, char* methodName,
124 osrfAppSession* ses, int reqId, jsonObject* params );