4 #include "opensrf/utils.h"
5 #include "opensrf/logging.h"
6 #include "objson/object.h"
7 #include "osrf_app_session.h"
11 This macro verifies methods receive the correct parameters
14 #define _OSRF_METHOD_VERIFY_CONTEXT(d) \
16 if(!d->session) { osrfLog( OSRF_ERROR, "Session is NULL in app reqeust" ); return -1; }\
17 if(!d->method) { osrfLog( OSRF_ERROR, "Method is NULL in app reqeust" ); return -1; }\
18 if(!d->params) { osrfLog( OSRF_ERROR, "Params is NULL in app reqeust %s", d->method->name ); return -1; }\
19 if( d->params->type != JSON_ARRAY ) { \
20 osrfLog( OSRF_ERROR, "'params' is not a JSON array for method %s", d->method->name);\
22 if( !d->method->name ) { osrfLog(OSRF_ERROR, "Method name is NULL"); return -1; }
25 #ifdef OSRF_LOG_PARAMS
26 #define OSRF_METHOD_VERIFY_CONTEXT(d) \
27 _OSRF_METHOD_VERIFY_CONTEXT(d); \
28 char* __j = jsonObjectToJSON(d->params);\
30 osrfLog( OSRF_INFO, "[%s:%s] params: %s", d->session->remote_service, d->method->name, __j);\
34 #define OSRF_METHOD_VERIFY_CONTEXT(d) _OSRF_METHOD_VERIFY_CONTEXT(d);
40 #define OSRF_SYSMETHOD_INTROSPECT "opensrf.system.method"
41 #define OSRF_SYSMETHOD_INTROSPECT_ALL "opensrf.system.method.all"
48 struct _osrfApplicationStruct {
49 char* name; /* the name of our application */
50 void* handle; /* the lib handle */
51 struct _osrfMethodStruct* methods; /* list of methods */
52 struct _osrfApplicationStruct* next; /* next application */
54 typedef struct _osrfApplicationStruct osrfApplication;
57 struct _osrfMethodStruct {
58 char* name; /* the method name */
59 char* symbol; /* the symbol name (function) */
60 char* notes; /* public method documentation */
61 int argc; /* how many args this method expects */
62 void* methodHandle; /* cached version of the method handle */
63 struct _osrfMethodStruct* next;
65 typedef struct _osrfMethodStruct osrfMethod;
67 struct _osrfMethodContextStruct {
68 osrfAppSession* session;
73 typedef struct _osrfMethodContextStruct osrfMethodContext;
77 Register an application
78 @param appName The name of the application
79 @param soFile The library (.so) file that implements this application
80 @return 0 on success, -1 on error
82 int osrfAppRegisterApplication( char* appName, char* soFile );
86 @param appName The name of the application that implements the method
87 @param methodName The fully qualified name of the method
88 @param symbolName The symbol name (function) that implements the method
89 @param notes Public documentation for this method.
90 @params argc The number of arguments this method expects
91 @return 0 on success, -1 on error
93 int osrfAppRegisterMethod( char* appName,
94 char* methodName, char* symbolName, char* notes, int argc );
97 Finds the given app in the list of apps
98 @param name The name of the application
99 @return The application pointer or NULL if there is no such application
101 osrfApplication* _osrfAppFindApplication( char* name );
104 Finds the given method for the given app
105 @param appName The application
106 @param methodName The method to find
107 @return A method pointer or NULL if no such method
108 exists for the given application
110 osrfMethod* _osrfAppFindMethod( char* appName, char* methodName );
113 Finds the given method for the given app
114 @param app The application object
115 @param methodName The method to find
116 @return A method pointer or NULL if no such method
117 exists for the given application
119 osrfMethod* __osrfAppFindMethod( osrfApplication* app, char* methodName );
123 Runs the specified method for the specified application.
124 @param appName The name of the application who's method to run
125 @param methodName The name of the method to run
126 @param ses The app session attached to this request
127 @params reqId The request id for this request
128 @param params The method parameters
130 int osrfAppRunMethod( char* appName, char* methodName,
131 osrfAppSession* ses, int reqId, jsonObject* params );
135 Trys to run the requested method as a system method.
136 A system method is a well known method that all
138 @param context The current method context
139 @return 0 if the method is run, -1 otherwise
141 int __osrfAppRunSystemMethod(osrfMethodContext* context);