diff options
Diffstat (limited to 'ctl-lib')
-rw-r--r-- | ctl-lib/afb-definitions.h | 201 | ||||
-rw-r--r-- | ctl-lib/ctl-action.c | 88 | ||||
-rw-r--r-- | ctl-lib/ctl-config.c | 44 | ||||
-rw-r--r-- | ctl-lib/ctl-config.h | 38 | ||||
-rw-r--r-- | ctl-lib/ctl-control.c | 4 | ||||
-rw-r--r-- | ctl-lib/ctl-event.c | 38 | ||||
-rw-r--r-- | ctl-lib/ctl-lua.c | 119 | ||||
-rw-r--r-- | ctl-lib/ctl-lua.h | 6 | ||||
-rw-r--r-- | ctl-lib/ctl-onload.c | 8 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.c | 54 | ||||
-rw-r--r-- | ctl-lib/ctl-plugin.h | 10 | ||||
-rw-r--r-- | ctl-lib/ctl-timer.c | 18 | ||||
-rw-r--r-- | ctl-lib/ctl-timer.h | 8 |
13 files changed, 196 insertions, 440 deletions
diff --git a/ctl-lib/afb-definitions.h b/ctl-lib/afb-definitions.h index 5a749c6..aaf4d17 100644 --- a/ctl-lib/afb-definitions.h +++ b/ctl-lib/afb-definitions.h @@ -20,118 +20,10 @@ #ifndef _AFB_DEFINITIONS_INCLUDE_ #define _AFB_DEFINITIONS_INCLUDE_ -// Legacy DYNAPI support. Deprecated and will be removed. -#if((AFB_BINDING_VERSION == 0) && defined(AFB_BINDING_WANT_DYNAPI)) +#if(AFB_BINDING_VERSION == 3) #include <afb/afb-binding.h> - #define AFB_BINDING_PREV3 #define AFB_ReqNone NULL - typedef struct afb_request* AFB_ReqT; - typedef struct afb_dynapi* AFB_ApiT; - - typedef struct afb_eventid* AFB_EventT; - #define AFB_EventIsValid(eventid) eventid - #define AFB_EventPush afb_eventid_push - #define AFB_ReqSubscribe afb_request_subscribe - #define AFB_EventMake(api, name) afb_dynapi_make_eventid(api, name) - - #define AFB_ReqJson(request) afb_request_json(request) - - #define AFB_ReqSuccess afb_request_success - #define AFB_ReqSuccessF afb_request_success_f - #define AFB_ReqFail afb_request_fail - #define AFB_ReqFailF afb_request_fail_f - - #define AFB_ReqNotice(request, ...) AFB_REQUEST_NOTICE (request, __VA_ARGS__) - #define AFB_ReqWarning(request, ...) AFB_REQUEST_WARNING (request, __VA_ARGS__) - #define AFB_ReqDebug(request, ...) AFB_REQUEST_DEBUG (request, __VA_ARGS__) - #define AFB_ReqError(request, ...) AFB_REQUEST_ERROR (request, __VA_ARGS__) - #define AFB_ReqInfo(request, ...) AFB_REQUEST_INFO (request, __VA_ARGS__) - - #define AFB_ApiVerbose(api, level, ...) afb_dynapi_verbose(api, level, __VA_ARGS__) - #define AFB_ApiNotice(api, ...) AFB_DYNAPI_NOTICE (api, __VA_ARGS__) - #define AFB_ApiWarning(api, ...) AFB_DYNAPI_WARNING (api, __VA_ARGS__) - #define AFB_ApiDebug(api, ...) AFB_DYNAPI_DEBUG (api, __VA_ARGS__) - #define AFB_ApiError(api, ...) AFB_DYNAPI_ERROR (api, __VA_ARGS__) - #define AFB_ApiInfo(api, ...) AFB_DYNAPI_INFO (api, __VA_ARGS__) - - #define AFB_GetApiSettings(api) json_object_new_object() - - #define AFB_ReqIsValid(request) request - #define AFB_EvtIsValid(evtHandle) evtHandle - - #define AFB_ServiceCall(api, ...) afb_dynapi_call(api, __VA_ARGS__) - #define AFB_ServiceSync(api, ...) afb_dynapi_call_sync(api, __VA_ARGS__) - - #define AFB_RequireApi(api, ...) afb_dynapi_require_api(api, __VA_ARGS__) - - - #define AFB_GetEventLoop(api) afb_dynapi_get_event_loop(api) - #define AFB_RootDirGetFD(api) afb_dynapi_rootdir_get_fd(api) - #define AFB_ReqVCBData afb_request_get_vcbdata - #define AFB_ReqGetApi afb_request_get_dynapi - - #define AFB_ClientCtxSet(request, replace, createCB, freeCB, handle) afb_request_context(request, replace, createCB, freeCB, handle) - #define AFB_ClientCtxClear(request) afb_request_context_clear(request) - - #define AFB_ReqSetLOA(request, level) afb_request_session_set_LOA(request, level) - - #define AFB_NewApi afb_dynapi_new_api - - #define AFB_ApiAddVerb(a,b,c,d,e,f,g,h) afb_dynapi_add_verb(a,b,c,d,e,f,g) - - #define AFB_ApiSetUserData afb_dynapi_set_userdata - #define AFB_ApiGetUserData afb_dynapi_get_userdata - - #define AFB_ApiOnEvent afb_dynapi_on_event - #define AFB_ApiOnInit afb_dynapi_on_init - #define AFB_ApiSeal afb_dynapi_seal - - typedef struct { - const char *verb; /* name of the verb, NULL only at end of the array */ - void (*callback)(AFB_ReqT req); /* callback function implementing the verb */ - const struct afb_auth *auth; /* required authorisation, can be NULL */ - const char *info; /* some info about the verb, can be NULL */ - uint32_t session; - } AFB_ApiVerbs; -#elif(AFB_BINDING_VERSION == 3) - #include <afb/afb-binding.h> - - #define AFB_ReqNone NULL - typedef afb_req_t AFB_ReqT; - typedef afb_api_t AFB_ApiT; - - typedef afb_event_t AFB_EventT; - #define AFB_EventIsValid(eventid) eventid - #define AFB_EventPush afb_event_push - #define AFB_ReqSubscribe afb_req_subscribe - #define AFB_EventMake(api, name) afb_api_make_event(api, name) - - #define AFB_ReqJson(request) afb_req_json(request) - - #define AFB_ReqSuccess afb_req_success - #define AFB_ReqSuccessF afb_req_success_f - #define AFB_ReqFail afb_req_fail - #define AFB_ReqFailF afb_req_fail_f - - #define AFB_ReqNotice(request, ...) AFB_REQ_NOTICE (request, __VA_ARGS__) - #define AFB_ReqWarning(request, ...) AFB_REQ_WARNING (request, __VA_ARGS__) - #define AFB_ReqDebug(request, ...) AFB_REQ_DEBUG (request, __VA_ARGS__) - #define AFB_ReqError(request, ...) AFB_REQ_ERROR (request, __VA_ARGS__) - #define AFB_ReqInfo(request, ...) AFB_REQ_INFO (request, __VA_ARGS__) - - #define AFB_ApiVerbose(api, level, ...) afb_api_verbose(api, level, __VA_ARGS__) - #define AFB_ApiNotice(api, ...) AFB_API_NOTICE (api, __VA_ARGS__) - #define AFB_ApiWarning(api, ...) AFB_API_WARNING (api, __VA_ARGS__) - #define AFB_ApiDebug(api, ...) AFB_API_DEBUG (api, __VA_ARGS__) - #define AFB_ApiError(api, ...) AFB_API_ERROR (api, __VA_ARGS__) - #define AFB_ApiInfo(api, ...) AFB_API_INFO (api, __VA_ARGS__) - - #define AFB_GetApiSettings afb_api_settings - - #define AFB_ReqIsValid(request) request - #define AFB_EvtIsValid(evtHandle) evtHandle - /* * Binder version < FF.RC4, we miss two defined calls. * This is for compatibility purpose that we defined them here. @@ -141,102 +33,13 @@ #define afb_service_call_sync_legacy afb_api_x3_call_sync_legacy #endif - #define AFB_ServiceCall(api, ...) afb_api_call_legacy(api, __VA_ARGS__) - #define AFB_ServiceSync(api, ...) afb_api_call_sync_legacy(api, __VA_ARGS__) - - #define AFB_ApiCall(api, ...) afb_api_call(api, __VA_ARGS__) - #define AFB_ApiSync(api, ...) afb_api_call_sync(api, __VA_ARGS__) - - #define AFB_RequireApi(api, ...) afb_api_require_api(api, __VA_ARGS__) - - #define AFB_GetEventLoop(api) afb_api_get_event_loop(api) - #define AFB_RootDirGetFD(api) afb_api_rootdir_get_fd(api) - #define AFB_ReqVCBData afb_req_get_vcbdata - #define AFB_ReqGetApi afb_req_get_api - - #define AFB_ClientCtxSet(request, replace, createCB, freeCB, handle) afb_req_context(request, replace, createCB, freeCB, handle) - #define AFB_ClientCtxClear(request) afb_req_context_clear(request) - - #define AFB_ReqSetLOA(request, level) afb_req_session_set_LOA(request, level) - - #define AFB_NewApi afb_api_new_api - - #define AFB_ApiAddVerb afb_api_add_verb - - #define AFB_ApiSetUserData afb_api_set_userdata - #define AFB_ApiGetUserData afb_api_get_userdata - - #define AFB_ApiOnEvent afb_api_on_event - #define AFB_ApiOnInit afb_api_on_init - #define AFB_ApiSeal afb_api_seal - typedef struct { const char *verb; /* name of the verb, NULL only at end of the array */ - void (*callback)(AFB_ReqT req); /* callback function implementing the verb */ + void (*callback)(afb_req_t req); /* callback function implementing the verb */ const struct afb_auth *auth; /* required authorisation, can be NULL */ const char *info; /* some info about the verb, can be NULL */ uint32_t session; } AFB_ApiVerbs; - -#else - #include <afb/afb-binding.h> - - typedef struct afb_req AFB_ReqT; - typedef void* AFB_ApiT; - #define AFB_ReqNone (struct afb_req){0,0} - - typedef struct afb_event AFB_EventT; - #define AFB_EventPush afb_event_push - #define AFB_ReqSubscribe afb_req_subscribe - #define AFB_EventIsValid(event) afb_event_is_valid(event) - #define AFB_EventMake(api, name) afb_daemon_make_event(name) - - #define AFB_ReqJson(request) afb_req_json(request) - #define AFB_ReqSuccess afb_req_success - #define AFB_ReqSuccessF afb_req_success_f - #define AFB_ReqFail afb_req_fail - #define AFB_ReqFailF afb_req_fail_f - - #define AFB_ReqNotice(request, ...) AFB_NOTICE (__VA_ARGS__) - #define AFB_ReqWarning(request, ...) AFB_WARNING (__VA_ARGS__) - #define AFB_ReqDebug(request, ...) AFB_DEBUG (__VA_ARGS__) - #define AFB_ReqError(request, ...) AFB_ERROR (__VA_ARGS__) - #define AFB_ReqInfo(request, ...) AFB_INFO (__VA_ARGS__) - - #define AFB_ApiVerbose(api, level, ...) afb_daemon_verbose_v2(level,__VA_ARGS__) - #define AFB_ApiNotice(api, ...) AFB_NOTICE (__VA_ARGS__) - #define AFB_ApiWarning(api, ...) AFB_WARNING (__VA_ARGS__) - #define AFB_ApiDebug(api, ...) AFB_DEBUG (__VA_ARGS__) - #define AFB_ApiError(api, ...) AFB_ERROR (__VA_ARGS__) - #define AFB_ApiInfo(api, ...) AFB_INFO (__VA_ARGS__) - - #define AFB_GetApiSettings(api) json_object_new_object() - - #define AFB_ReqIsValid(request) afb_req_is_valid(request) - #define AFB_EvtIsValid(evtHandle) afb_event_is_valid(evtHandle) - - #define AFB_ServiceCall(api, ...) afb_service_call(__VA_ARGS__) - #define AFB_ServiceSync(api, ...) afb_service_call_sync(__VA_ARGS__) - - #define AFB_RequireApi(api, ...) afb_daemon_require_api(__VA_ARGS__) - - #define AFB_GetEventLoop(api) afb_daemon_get_event_loop() - #define AFB_RootDirGetFD(api) afb_daemon_rootdir_get_fd() - #define AFB_ReqVCBData afb_req_get_vcbdata - - #define AFB_ReqSetLOA(request, level) afb_req_session_set_LOA(request, level) - - static inline void* AFB_ClientCtxSet(afb_req request, int replace, void *(*create_context)(void *closure), void (*free_context)(void*), void *closure) - { - void *ctx = create_context(closure); - if(ctx) - {afb_req_context_set(request, ctx, free_context);} - return ctx; - } - - #define AFB_ClientCtxClear(request) afb_req_context_clear(request) - - #define AFB_ApiVerbs afb_verb_v2 #endif #endif /* _AFB_DEFINITIONS_INCLUDE_ */ diff --git a/ctl-lib/ctl-action.c b/ctl-lib/ctl-action.c index 4c72105..d1ab471 100644 --- a/ctl-lib/ctl-action.c +++ b/ctl-lib/ctl-action.c @@ -34,7 +34,7 @@ int ActionLabelToIndex(CtlActionT*actions, const char* actionLabel) { return -1; } -void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ) { +void ActionExecUID(afb_req_t request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ) { for (int i = 0; ctlConfig->sections[i].key != NULL; i++) { if (ctlConfig->sections[i].actions) { for (int j = 0; ctlConfig->sections[i].actions[j].uid != NULL; j++) { @@ -73,7 +73,7 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { break; default: - AFB_ApiError(action->api, "ActionExecOne(queryJ should be an object) uid=%s args=%s", source->uid, json_object_get_string(queryJ)); + AFB_API_ERROR(action->api, "ActionExecOne(queryJ should be an object) uid=%s args=%s", source->uid, json_object_get_string(queryJ)); return -1; } } @@ -82,16 +82,16 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { } /* AFB Subcall will release the json_object doing the json_object_put() call */ - err = AFB_ServiceSync(action->api, action->exec.subcall.api, action->exec.subcall.verb, extendedQueryJ, &returnJ); - if(err && AFB_ReqIsValid(source->request)) - AFB_ReqFailF(source->request, "subcall-fail", "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ)); - else if(err && ! AFB_ReqIsValid(source->request)) - AFB_ApiError(action->api, "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ)); - else if(AFB_ReqIsValid(source->request)) { + err = afb_api_call_sync_legacy(action->api, action->exec.subcall.api, action->exec.subcall.verb, extendedQueryJ, &returnJ); + if(err && afb_req_is_valid(source->request)) + afb_req_fail_f(source->request, "subcall-fail", "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ)); + else if(err && ! afb_req_is_valid(source->request)) + AFB_API_ERROR(action->api, "ActionExecOne(AppFw) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ)); + else if(afb_req_is_valid(source->request)) { if(wrap_json_unpack(returnJ, "{s:o}", "response", &toReturnJ)) - AFB_ApiError(action->api, "ActionExecOne(Can't unpack response) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ)); + AFB_API_ERROR(action->api, "ActionExecOne(Can't unpack response) uid=%s api=%s verb=%s args=%s", source->uid, action->exec.subcall.api, action->exec.subcall.verb, json_object_get_string(action->argsJ)); else - AFB_ReqSuccess(source->request, toReturnJ, NULL); + afb_req_success(source->request, toReturnJ, NULL); } break; } @@ -100,7 +100,7 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { case CTL_TYPE_LUA: err = LuaCallFunc(source, action, queryJ); if (err) { - AFB_ApiError(action->api, "ActionExecOne(Lua) uid=%s func=%s args=%s", source->uid, action->exec.lua.funcname, json_object_get_string(action->argsJ)); + AFB_API_ERROR(action->api, "ActionExecOne(Lua) uid=%s func=%s args=%s", source->uid, action->exec.lua.funcname, json_object_get_string(action->argsJ)); } break; #endif @@ -108,13 +108,13 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { case CTL_TYPE_CB: err = (*action->exec.cb.callback) (source, action->argsJ, queryJ); if (err) { - AFB_ApiError(action->api, "ActionExecOne(Callback) uid%s plugin=%s function=%s args=%s", source->uid, action->exec.cb.plugin->uid, action->exec.cb.funcname, json_object_get_string(action->argsJ)); + AFB_API_ERROR(action->api, "ActionExecOne(Callback) uid%s plugin=%s function=%s args=%s", source->uid, action->exec.cb.plugin->uid, action->exec.cb.funcname, json_object_get_string(action->argsJ)); } break; default: { - AFB_ApiError(action->api, "ActionExecOne(unknown) API type uid=%s", source->uid); + AFB_API_ERROR(action->api, "ActionExecOne(unknown) API type uid=%s", source->uid); break; } } @@ -124,13 +124,10 @@ int ActionExecOne(CtlSourceT *source, CtlActionT* action, json_object *queryJ) { // Direct Request Call in APIV3 -#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) - -static void ActionDynRequest(AFB_ReqT request) { - +static void ActionDynRequest(afb_req_t request) { // retrieve action handle from request and execute the request - json_object *queryJ = AFB_ReqJson(request); - CtlActionT* action = (CtlActionT*) AFB_ReqVCBData(request); + json_object *queryJ = afb_req_json(request); + CtlActionT* action = (CtlActionT*) afb_req_get_vcbdata(request); CtlSourceT source; source.uid = action->uid; @@ -140,10 +137,8 @@ static void ActionDynRequest(AFB_ReqT request) { // provide request and execute the action ActionExecOne(&source, action, queryJ); } -#endif -void ParseURI(const char *uri, char **first, char **second) -{ +void ParseURI(const char *uri, char **first, char **second) { char *tmp; if(! uri || ! first || ! second) { @@ -174,12 +169,12 @@ void ParseURI(const char *uri, char **first, char **second) * the function * */ -static int BuildPluginAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *action) { +static int BuildPluginAction(afb_api_t apiHandle, const char *uri, CtlActionT *action) { char *plugin = NULL, *function = NULL; json_object *callbackJ = NULL; if (!action) { - AFB_ApiError(apiHandle, "Action not valid"); + AFB_API_ERROR(apiHandle, "Action not valid"); return -1; } @@ -192,13 +187,13 @@ static int BuildPluginAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *ac "plugin", plugin, "function", function, "args", action->argsJ)) { - AFB_ApiError(apiHandle, "Error packing Callback JSON object for plugin %s and function %s", uri, function); + AFB_API_ERROR(apiHandle, "Error packing Callback JSON object for plugin %s and function %s", uri, function); return -1; } else { return PluginGetCB(apiHandle, action, callbackJ); } } else { - AFB_ApiError(apiHandle, "Miss something uri or function."); + AFB_API_ERROR(apiHandle, "Miss something uri or function."); return -1; } @@ -213,18 +208,18 @@ static int BuildPluginAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *ac * unexpected result. * */ -static int BuildApiAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *action) { +static int BuildApiAction(afb_api_t apiHandle, const char *uri, CtlActionT *action) { char *api = NULL, *verb = NULL; if (!action) { - AFB_ApiError(apiHandle, "Action not valid"); + AFB_API_ERROR(apiHandle, "Action not valid"); return -1; } ParseURI(uri, &api, &verb); if(!api || !verb) { - AFB_ApiError(apiHandle, "Error parsing the action string"); + AFB_API_ERROR(apiHandle, "Error parsing the action string"); return -1; } @@ -245,18 +240,18 @@ static int BuildApiAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *actio */ #ifdef CONTROL_SUPPORT_LUA -static int BuildLuaAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *action) { +static int BuildLuaAction(afb_api_t apiHandle, const char *uri, CtlActionT *action) { char *plugin = NULL, *function = NULL; if (!action) { - AFB_ApiError(apiHandle, "Action not valid"); + AFB_API_ERROR(apiHandle, "Action not valid"); return -1; } ParseURI(uri, &plugin, &function); if(!plugin || !function) { - AFB_ApiError(apiHandle, "Error parsing the action string"); + AFB_API_ERROR(apiHandle, "Error parsing the action string"); return -1; } @@ -268,7 +263,7 @@ static int BuildLuaAction(AFB_ApiT apiHandle, const char *uri, CtlActionT *actio } #endif -static int BuildOneAction(AFB_ApiT apiHandle, CtlActionT *action, const char *uri) { +static int BuildOneAction(afb_api_t apiHandle, CtlActionT *action, const char *uri) { size_t lua_pre_len = strlen(LUA_ACTION_PREFIX); size_t api_pre_len = strlen(API_ACTION_PREFIX); size_t plugin_pre_len = strlen(PLUGIN_ACTION_PREFIX); @@ -278,7 +273,7 @@ static int BuildOneAction(AFB_ApiT apiHandle, CtlActionT *action, const char *ur #ifdef CONTROL_SUPPORT_LUA return BuildLuaAction(apiHandle, &uri[lua_pre_len], action); #else - AFB_ApiError(apiHandle, "LUA support not selected at build. Feature disabled"); + AFB_API_ERROR(apiHandle, "LUA support not selected at build. Feature disabled"); return -1; #endif } else if (!strncasecmp(uri, API_ACTION_PREFIX, api_pre_len)) { @@ -286,18 +281,18 @@ static int BuildOneAction(AFB_ApiT apiHandle, CtlActionT *action, const char *ur } else if (!strncasecmp(uri, PLUGIN_ACTION_PREFIX, plugin_pre_len)) { return BuildPluginAction(apiHandle, &uri[plugin_pre_len], action); } else { - AFB_ApiError(apiHandle, "Wrong uri specified. You have to specified 'lua://', 'plugin://' or 'api://'."); + AFB_API_ERROR(apiHandle, "Wrong uri specified. You have to specified 'lua://', 'plugin://' or 'api://'."); return -1; } } - AFB_ApiError(apiHandle, "Uri, Action or function not valid"); + AFB_API_ERROR(apiHandle, "Uri, Action or function not valid"); return -1; } // unpack individual action object -int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, int exportApi) { +int ActionLoadOne(afb_api_t apiHandle, CtlActionT *action, json_object *actionJ, int exportApi) { int err = 0; const char *uri = NULL; @@ -311,33 +306,30 @@ int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *actionJ, "privileges", &action->privileges, "args", &action->argsJ); if (!err) { - // in API V3 each control is optionally map to a verb -#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) if(!apiHandle) return -1; action->api = apiHandle; if (exportApi) { - err = AFB_ApiAddVerb(apiHandle, action->uid, action->info, ActionDynRequest, action, NULL, 0, 0); + err = afb_api_add_verb(apiHandle, action->uid, action->info, ActionDynRequest, action, NULL, 0, 0); if (err) { - AFB_ApiError(apiHandle, "ACTION-LOAD-ONE fail to register API verb=%s", action->uid); + AFB_API_ERROR(apiHandle, "ACTION-LOAD-ONE fail to register API verb=%s", action->uid); return -1; } } -#endif err = BuildOneAction(apiHandle, action, uri); } else { - AFB_ApiError(apiHandle, "Fail to parse action JSON : (%s)", json_object_to_json_string(actionJ)); + AFB_API_ERROR(apiHandle, "Fail to parse action JSON : (%s)", json_object_to_json_string(actionJ)); err = -1; } } else { - AFB_ApiError(apiHandle, "Wrong action JSON object parameter: (%s)", json_object_to_json_string(actionJ)); + AFB_API_ERROR(apiHandle, "Wrong action JSON object parameter: (%s)", json_object_to_json_string(actionJ)); err = -1; } return err; } -CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi) { +CtlActionT *ActionConfig(afb_api_t apiHandle, json_object *actionsJ, int exportApi) { int err; CtlActionT *actions; @@ -364,7 +356,7 @@ CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportAp return actions; } -int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi) { +int AddActionsToSection(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi) { if (actionsJ || section) { CtlActionT *actions = NULL; if(section->actions) { @@ -397,12 +389,12 @@ int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *a section->actions = actions; } else { - AFB_ApiError (apiHandle, "Missing actions to add or the section object"); + AFB_API_ERROR (apiHandle, "Missing actions to add or the section object"); return 1; } if (!section->actions) { - AFB_ApiError (apiHandle, "Adding '%s' fails to section %s", json_object_get_string(actionsJ), section->uid); + AFB_API_ERROR (apiHandle, "Adding '%s' fails to section %s", json_object_get_string(actionsJ), section->uid); return 1; } return 0; diff --git a/ctl-lib/ctl-config.c b/ctl-lib/ctl-config.c index f583158..6d46130 100644 --- a/ctl-lib/ctl-config.c +++ b/ctl-lib/ctl-config.c @@ -62,7 +62,7 @@ json_object* CtlConfigScan(const char *dirList, const char *prefix) { return responseJ; } -char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { +char* ConfigSearch(afb_api_t apiHandle, json_object *responseJ) { // We load 1st file others are just warnings size_t p_length; char *filepath = NULL; @@ -74,7 +74,7 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { int err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename); if (err) { - AFB_ApiError(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ)); + AFB_API_ERROR(apiHandle, "CTL-INIT HOOPs invalid JSON entry= %s", json_object_get_string(entryJ)); } if (index == 0) { @@ -86,7 +86,7 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { strncat(filepath, filename, p_length - strlen(filepath)); } else { - AFB_ApiWarning(apiHandle, "CTL-INIT JSON file found but not used : %s/%s", fullpath, filename); + AFB_API_WARNING(apiHandle, "CTL-INIT JSON file found but not used : %s/%s", fullpath, filename); } } @@ -94,7 +94,7 @@ char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ) { return filepath; } -char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) { +char* CtlConfigSearch(afb_api_t apiHandle, const char *dirList, const char *prefix) { // search for default dispatch config file json_object* responseJ = CtlConfigScan (dirList, prefix); @@ -104,11 +104,11 @@ char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefi return NULL; } -static int DispatchRequireOneApi(AFB_ApiT apiHandle, json_object * bindindJ) { +static int DispatchRequireOneApi(afb_api_t apiHandle, json_object * bindindJ) { const char* requireBinding = json_object_get_string(bindindJ); - int err = AFB_RequireApi(apiHandle, requireBinding, 1); + int err = afb_api_require_api(apiHandle, requireBinding, 1); if (err) { - AFB_ApiWarning(apiHandle, "CTL-LOAD-CONFIG:REQUIRE Fail to get=%s", requireBinding); + AFB_API_WARNING(apiHandle, "CTL-LOAD-CONFIG:REQUIRE Fail to get=%s", requireBinding); } return err; @@ -120,10 +120,10 @@ static int DispatchRequireOneApi(AFB_ApiT apiHandle, json_object * bindindJ) { * the CtlConfigExec could be called anywhere and not in binding init. * So you could call this function at init time. * - * @param apiHandle : a afb_daemon api handle, see AFB_ApiT in afb_definitions.h + * @param apiHandle : a afb_daemon api handle, see afb_api_t in afb_definitions.h * @param requireJ : json_object array of api name required. */ -void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) { +void DispatchRequireApi(afb_api_t apiHandle, json_object * requireJ) { static int init = 0, err = 0; int idx; @@ -140,7 +140,7 @@ void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ) { init = 1; } -int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) { +int CtlConfigExec(afb_api_t apiHandle, CtlConfigT *ctlConfig) { DispatchRequireApi(apiHandle, ctlConfig->requireJ); #ifdef CONTROL_SUPPORT_LUA @@ -152,7 +152,7 @@ int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) { int errcount=0; for (int idx = 0; ctlConfig->sections[idx].key != NULL; idx++) { if (!ctlConfig->sections[idx].loadCB) - AFB_ApiNotice(apiHandle, "CtlConfigLoad: notice empty section '%s'", ctlConfig->sections[idx].key); + AFB_API_NOTICE(apiHandle, "CtlConfigLoad: notice empty section '%s'", ctlConfig->sections[idx].key); else errcount += ctlConfig->sections[idx].loadCB(apiHandle, &ctlConfig->sections[idx], NULL); } @@ -160,7 +160,7 @@ int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) { return errcount; } -CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, const char *prefix) { +CtlConfigT *CtlLoadMetaDataJson(afb_api_t apiHandle, json_object *ctlConfigJ, const char *prefix) { json_object *metadataJ; CtlConfigT *ctlHandle=NULL; int err; @@ -177,7 +177,7 @@ CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, con "author", &ctlHandle->author, "date", &ctlHandle->date); if (err) { - AFB_ApiError(apiHandle, "CTL-LOAD-CONFIG:METADATA Missing something uid|api|version|[info]|[require]|[author]|[date] in:\n-- %s", json_object_get_string(metadataJ)); + AFB_API_ERROR(apiHandle, "CTL-LOAD-CONFIG:METADATA Missing something uid|api|version|[info]|[require]|[author]|[date] in:\n-- %s", json_object_get_string(metadataJ)); free(ctlHandle); return NULL; } @@ -190,18 +190,18 @@ CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle, json_object *ctlConfigJ, con return ctlHandle; } -CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) { +CtlConfigT *CtlLoadMetaDataUsingPrefix(afb_api_t apiHandle,const char* filepath, const char *prefix) { json_object *ctlConfigJ; // Load JSON file ctlConfigJ = json_object_from_file(filepath); if (!ctlConfigJ) { - AFB_ApiError(apiHandle, "CTL-LOAD-CONFIG Not invalid JSON %s ", filepath); + AFB_API_ERROR(apiHandle, "CTL-LOAD-CONFIG Not invalid JSON %s ", filepath); return NULL; } - AFB_ApiInfo(apiHandle, "CTL-LOAD-CONFIG: loading config filepath=%s", filepath); + AFB_API_INFO(apiHandle, "CTL-LOAD-CONFIG: loading config filepath=%s", filepath); return CtlLoadMetaDataJson(apiHandle, ctlConfigJ, prefix); } @@ -210,9 +210,9 @@ void wrap_json_array_add(void* array, json_object *val) { json_object_array_add(array, (json_object*)val); } -json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ); +json_object* LoadAdditionalsFiles(afb_api_t apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ); -json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ, json_object *filesJ) { +json_object* CtlUpdateSectionConfig(afb_api_t apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ, json_object *filesJ) { json_object *sectionArrayJ; char *oneFile = NULL; @@ -237,7 +237,7 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c responseJ = responseJ ? responseJ: ScanForConfig(bindingPath, CTL_SCAN_RECURSIVE, json_object_get_string(oneFileJ), ".json"); if(!responseJ) { - AFB_ApiError(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, bindingPath); + AFB_API_ERROR(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, bindingPath); return sectionArrayJ; } oneFile = ConfigSearch(apiHandle, responseJ); @@ -256,7 +256,7 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c responseJ = responseJ ? responseJ: ScanForConfig(bindingPath, CTL_SCAN_RECURSIVE, json_object_get_string(filesJ), ".json"); if(!responseJ) { - AFB_ApiError(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, bindingPath); + AFB_API_ERROR(apiHandle, "No config files found in search path. No changes has been made\n -- %s\n -- %s", CONTROL_CONFIG_PATH, bindingPath); return sectionArrayJ; } oneFile = ConfigSearch(apiHandle, responseJ); @@ -269,7 +269,7 @@ json_object* CtlUpdateSectionConfig(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, c return sectionArrayJ; } -json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ) +json_object* LoadAdditionalsFiles(afb_api_t apiHandle, CtlConfigT *ctlHandle, const char *key, json_object *sectionJ) { json_object *filesJ, *filesArrayJ = json_object_new_array(); if (json_object_get_type(sectionJ) == json_type_array) { @@ -306,7 +306,7 @@ json_object* LoadAdditionalsFiles(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, con return sectionJ; } -int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) { +int CtlLoadSections(afb_api_t apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections) { int err; #ifdef CONTROL_SUPPORT_LUA diff --git a/ctl-lib/ctl-config.h b/ctl-lib/ctl-config.h index 4216aa8..285de7d 100644 --- a/ctl-lib/ctl-config.h +++ b/ctl-lib/ctl-config.h @@ -59,7 +59,7 @@ typedef struct ConfigSectionS { const char *uid; const char *info; const char *prefix; - int (*loadCB)(AFB_ApiT apihandle, struct ConfigSectionS *section, json_object *sectionJ); + int (*loadCB)(afb_api_t apihandle, struct ConfigSectionS *section, json_object *sectionJ); void *handle; CtlActionT *actions; } CtlSectionT; @@ -91,41 +91,39 @@ typedef enum { } SectionEnumT; // ctl-action.c -extern int AddActionsToSection(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi); -extern int AddActionsToSectionFromPlugin(AFB_ApiT apiHandle, CtlPluginT *externalCtlPlugins, CtlSectionT *section, json_object *actionsJ, int exportApi); -extern CtlActionT *ActionConfig(AFB_ApiT apiHandle, json_object *actionsJ, int exportApi); -extern void ActionExecUID(AFB_ReqT request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ); +extern int AddActionsToSection(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ, int exportApi); +extern CtlActionT *ActionConfig(afb_api_t apiHandle, json_object *actionsJ, int exportApi); +extern void ActionExecUID(afb_req_t request, CtlConfigT *ctlConfig, const char *uid, json_object *queryJ); extern int ActionExecOne( CtlSourceT *source, CtlActionT* action, json_object *queryJ); -extern int ActionLoadOne(AFB_ApiT apiHandle, CtlActionT *action, json_object *, int exportApi); +extern int ActionLoadOne(afb_api_t apiHandle, CtlActionT *action, json_object *, int exportApi); extern int ActionLabelToIndex(CtlActionT* actions, const char* actionLabel); // ctl-config.c extern int CtlConfigMagicNew(); extern json_object* CtlConfigScan(const char *dirList, const char *prefix) ; -extern char* ConfigSearch(AFB_ApiT apiHandle, json_object *responseJ); -extern char* CtlConfigSearch(AFB_ApiT apiHandle, const char *dirList, const char *prefix) ; -extern void DispatchRequireApi(AFB_ApiT apiHandle, json_object * requireJ); -extern int CtlConfigExec(AFB_ApiT apiHandle, CtlConfigT *ctlConfig) ; -extern CtlConfigT *CtlLoadMetaDataJson(AFB_ApiT apiHandle,json_object *ctlConfigJ, const char *prefix) ; -extern CtlConfigT *CtlLoadMetaDataUsingPrefix(AFB_ApiT apiHandle,const char* filepath, const char *prefix) ; -extern int CtlLoadSections(AFB_ApiT apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections); +extern char* ConfigSearch(afb_api_t apiHandle, json_object *responseJ); +extern char* CtlConfigSearch(afb_api_t apiHandle, const char *dirList, const char *prefix) ; +extern void DispatchRequireApi(afb_api_t apiHandle, json_object * requireJ); +extern int CtlConfigExec(afb_api_t apiHandle, CtlConfigT *ctlConfig) ; +extern CtlConfigT *CtlLoadMetaDataJson(afb_api_t apiHandle,json_object *ctlConfigJ, const char *prefix) ; +extern CtlConfigT *CtlLoadMetaDataUsingPrefix(afb_api_t apiHandle,const char* filepath, const char *prefix) ; +extern int CtlLoadSections(afb_api_t apiHandle, CtlConfigT *ctlHandle, CtlSectionT *sections); #define CtlLoadMetaData(api, filepath) CtlLoadMetaDataUsingPrefix(api, filepath, NULL) // ctl-event.c -extern int EventConfig(AFB_ApiT apihandle, CtlSectionT *section, json_object *actionsJ); -extern void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ); +extern int EventConfig(afb_api_t apihandle, CtlSectionT *section, json_object *actionsJ); +extern void CtrlDispatchApiEvent (afb_api_t apiHandle, const char *evtLabel, struct json_object *eventJ); extern void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ); // ctl-control.c -extern int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); +extern int ControlConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ); // ctl-onload.c -extern int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ); +extern int OnloadConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ); // ctl-plugin.c -extern int PluginConfig(AFB_ApiT UNUSED_ARG(apiHandle), CtlSectionT *section, json_object *pluginsJ); -extern int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ); - +extern int PluginConfig(afb_api_t UNUSED_ARG(apiHandle), CtlSectionT *section, json_object *pluginsJ); +extern int PluginGetCB (afb_api_t apiHandle, CtlActionT *action , json_object *callbackJ); #ifdef __cplusplus } #endif diff --git a/ctl-lib/ctl-control.c b/ctl-lib/ctl-control.c index b28ff4c..43d3e2e 100644 --- a/ctl-lib/ctl-control.c +++ b/ctl-lib/ctl-control.c @@ -23,11 +23,11 @@ #include "ctl-config.h" // onload section receive one action or an array of actions -int ControlConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { +int ControlConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ) { int err = 0; if (actionsJ) { if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 1)) ) { - AFB_ApiError (apiHandle, "ControlLoad config fail processing actions for section %s", section->uid); + AFB_API_ERROR (apiHandle, "ControlLoad config fail processing actions for section %s", section->uid); return err; } } diff --git a/ctl-lib/ctl-event.c b/ctl-lib/ctl-event.c index 1bed333..37590b2 100644 --- a/ctl-lib/ctl-event.c +++ b/ctl-lib/ctl-event.c @@ -23,18 +23,13 @@ #include "ctl-config.h" // Event dynamic API-V3 mode -#if defined AFB_BINDING_PREV3 || AFB_BINDING_VERSION == 3 -void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json_object *eventJ) { +void CtrlDispatchApiEvent (afb_api_t apiHandle, const char *evtLabel, struct json_object *eventJ) { int idx = 0; CtlActionT* actions = NULL; - AFB_ApiDebug (apiHandle, "Received event=%s, query=%s", evtLabel, json_object_get_string(eventJ)); + AFB_API_DEBUG (apiHandle, "Received event=%s, query=%s", evtLabel, json_object_get_string(eventJ)); // retrieve section config from api handle - #ifdef AFB_BINDING_PREV3 - CtlConfigT *ctrlConfig = (CtlConfigT*) afb_dynapi_get_userdata(apiHandle); - #elif AFB_BINDING_VERSION == 3 CtlConfigT *ctrlConfig = (CtlConfigT*) afb_api_get_userdata(apiHandle); - #endif for (idx = 0; ctrlConfig->sections[idx].key != NULL; ++idx) { @@ -46,7 +41,7 @@ void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json idx = ActionLabelToIndex(actions, evtLabel); if (idx < 0) { - AFB_ApiWarning(apiHandle, "CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel); + AFB_API_WARNING(apiHandle, "CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel); return; } @@ -60,37 +55,14 @@ void CtrlDispatchApiEvent (AFB_ApiT apiHandle, const char *evtLabel, struct json (void) ActionExecOne (&source, &actions[idx], json_object_get(eventJ)); } -#else -// In API-V2 controller config is unique and static -extern CtlConfigT *ctrlConfig; - -// call action attached to even name if any -void CtrlDispatchV2Event(const char *evtLabel, json_object *eventJ) { - CtlActionT* actions = ctrlConfig->sections[CTL_SECTION_EVENT].actions; - - int index= ActionLabelToIndex(actions, evtLabel); - if (index < 0) { - AFB_WARNING_V2("CtlDispatchEvent: fail to find uid=%s in action event section", evtLabel); - return; - } - - CtlSourceT source; - source.uid = actions[index].uid; - source.api = actions[index].api; - source.request = AFB_ReqNone; - - // Best effort ignoring error to exec corresponding action - (void) ActionExecOne (&source, &actions[index], json_object_get(eventJ)); -} -#endif // onload section receive one action or an array of actions -int EventConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { +int EventConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ) { int err = 0; // Load time parse actions in config file if (actionsJ != NULL) { if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 0)) ) { - AFB_ApiError (apiHandle, "EventLoad config fail processing actions for section %s", section->uid); + AFB_API_ERROR (apiHandle, "EventLoad config fail processing actions for section %s", section->uid); return err; } } diff --git a/ctl-lib/ctl-lua.c b/ctl-lib/ctl-lua.c index 1a2554c..2f96448 100644 --- a/ctl-lib/ctl-lua.c +++ b/ctl-lib/ctl-lua.c @@ -57,7 +57,7 @@ static int TIMER_MAGIC; typedef struct { char *name; int count; - AFB_EventT event; + afb_event_t event; } LuaAfbEvent; typedef struct { @@ -90,7 +90,7 @@ static CtlSourceT *LuaSourcePop(lua_State *luaState, int index) { static LuaAfbSourceT *LuaSourcePush(lua_State *luaState, CtlSourceT *source) { LuaAfbSourceT *afbSource = (LuaAfbSourceT *) calloc(1, sizeof (LuaAfbSourceT)); if (!afbSource) { - AFB_ApiError(source->api, "LuaSourcePush fail to allocate user data context"); + AFB_API_ERROR(source->api, "LuaSourcePush fail to allocate user data context"); return NULL; } @@ -144,12 +144,12 @@ static int LuaPushArgument(CtlSourceT *source, json_object *argsJ) { lua_pushnumber(luaState, json_object_get_double(argsJ)); break; case json_type_null: - AFB_ApiNotice(source->api, "LuaPushArgument: NULL object type %s", json_object_to_json_string(argsJ)); + AFB_API_NOTICE(source->api, "LuaPushArgument: NULL object type %s", json_object_to_json_string(argsJ)); lua_pushnil(luaState); break; default: - AFB_ApiError(source->api, "LuaPushArgument: unsupported Json object type %s", json_object_to_json_string(argsJ)); + AFB_API_ERROR(source->api, "LuaPushArgument: unsupported Json object type %s", json_object_to_json_string(argsJ)); return 0; } return 1; @@ -180,7 +180,7 @@ static json_object *LuaTableToJson(CtlSourceT *source, lua_State* luaState, int tableJ = json_object_new_object(); tableType = LUA_TSTRING; } else if (tableType != LUA_TSTRING) { - AFB_ApiError(source->api, "MIX Lua Table with key string/numeric not supported"); + AFB_API_ERROR(source->api, "MIX Lua Table with key string/numeric not supported"); return NULL; } @@ -193,15 +193,13 @@ static json_object *LuaTableToJson(CtlSourceT *source, lua_State* luaState, int tableJ = json_object_new_array(); tableType = LUA_TNUMBER; } else if (tableType != LUA_TNUMBER) { - AFB_ApiError(source->api, "MIX Lua Table with key numeric/string not supported"); + AFB_API_ERROR(source->api, "MIX Lua Table with key numeric/string not supported"); return NULL; } json_object *argJ = LuaPopOneArg(source, luaState, LUA_VALUE_INDEX); json_object_array_add(tableJ, argJ); } - - lua_pop(luaState, 1); // removes 'value'; keeps 'key' for next iteration } @@ -247,7 +245,7 @@ static json_object *LuaPopOneArg(CtlSourceT *source, lua_State* luaState, int id break; default: - AFB_ApiNotice(source->api, "LuaPopOneArg: script returned Unknown/Unsupported idx=%d type:%d/%s", idx, luaType, lua_typename(luaState, luaType)); + AFB_API_NOTICE(source->api, "LuaPopOneArg: script returned Unknown/Unsupported idx=%d type:%d/%s", idx, luaType, lua_typename(luaState, luaType)); value = NULL; } @@ -351,7 +349,7 @@ static int LuaFormatMessage(lua_State* luaState, int verbosity, int level) { if (uidIdx >= LUA_MSG_MAX_LENGTH) { const char *trunc = "... <truncated> "; - AFB_ApiWarning(source->api, "LuaFormatMessage: message[%s] overflow LUA_MSG_MAX_LENGTH=%d\n", format, LUA_MSG_MAX_LENGTH); + AFB_API_WARNING(source->api, "LuaFormatMessage: message[%s] overflow LUA_MSG_MAX_LENGTH=%d\n", format, LUA_MSG_MAX_LENGTH); uidIdx = LUA_MSG_MAX_LENGTH - 1; memcpy(&message[uidIdx - strlen(trunc)], trunc, strlen(trunc)); break; @@ -364,7 +362,7 @@ static int LuaFormatMessage(lua_State* luaState, int verbosity, int level) { PrintMessage: // TBD: __file__ and __line__ should match LUA source code - AFB_ApiVerbose(source->api, level, __FILE__, __LINE__, source->uid, "%s", message); + afb_api_verbose(source->api, level, __FILE__, __LINE__, source->uid, "%s", message); json_object_put(responseJ); return 0; // nothing return to lua } @@ -405,7 +403,7 @@ static int LuaAfbSuccess(lua_State* luaState) { json_object *responseJ = LuaPopArgs(source, luaState, LUA_FIRST_ARG + 1); if (responseJ == JSON_ERROR) return 1; - AFB_ReqSuccess(source->request, responseJ, NULL); + afb_req_success(source->request, responseJ, NULL); return 0; } @@ -420,13 +418,13 @@ static int LuaAfbFail(lua_State* luaState) { json_object *responseJ = LuaPopArgs(source, luaState, LUA_FIRST_ARG + 1); if (responseJ == JSON_ERROR) return 1; - AFB_ReqFail(source->request, source->uid, json_object_get_string(responseJ)); + afb_req_success(source->request, json_object_new_string(source->uid), json_object_get_string(responseJ)); json_object_put(responseJ); return 0; } -static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *responseJ, AFB_ApiT apiHandle) { +static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *responseJ, afb_api_t apiHandle) { LuaCbHandleT *handleCb = (LuaCbHandleT*) handle; int count = 1; @@ -443,7 +441,7 @@ static void LuaAfbServiceCB(void *handle, int iserror, struct json_object *respo int err = lua_pcall(luaState, count, LUA_MULTRET, 0); if (err) { - AFB_ApiError(apiHandle, "LUA-SERVICE-CB:FAIL response=%s err=%s", json_object_to_json_string(responseJ), lua_tostring(luaState, -1)); + AFB_API_ERROR(apiHandle, "LUA-SERVICE-CB:FAIL response=%s err=%s", json_object_to_json_string(responseJ), lua_tostring(luaState, -1)); } free(handleCb->source); @@ -481,7 +479,7 @@ static int LuaAfbService(lua_State* luaState) { handleCb->source = malloc(sizeof (CtlSourceT)); handleCb->source = memcpy(handleCb->source, source, sizeof (CtlSourceT)); - AFB_ServiceCall(source->api, api, verb, queryJ, LuaAfbServiceCB, handleCb); + afb_api_call_legacy(source->api, api, verb, queryJ, LuaAfbServiceCB, handleCb); return 0; // no value return } @@ -510,7 +508,7 @@ static int LuaAfbServiceSync(lua_State* luaState) { const char *verb = lua_tostring(luaState, LUA_FIRST_ARG + 2); json_object *queryJ = LuaTableToJson(source, luaState, LUA_FIRST_ARG + 3); - int iserror = AFB_ServiceSync(source->api, api, verb, queryJ, &responseJ); + int iserror = afb_api_call_sync_legacy(source->api, api, verb, queryJ, &responseJ); // push error status & response count = 1; @@ -539,7 +537,7 @@ static int LuaAfbEventPush(lua_State* luaState) { afbevt = (LuaAfbEvent*) lua_touserdata(luaState, LUA_FIRST_ARG + 1); - if (!AFB_EventIsValid(afbevt->event)) { + if (!afb_event_is_valid(afbevt->event)) { lua_pushliteral(luaState, "LuaAfbMakePush-Fail invalid event"); lua_error(luaState); return 1; @@ -552,10 +550,10 @@ static int LuaAfbEventPush(lua_State* luaState) { return 1; } - int done = AFB_EventPush(afbevt->event, ctlEventJ); + int done = afb_event_push(afbevt->event, ctlEventJ); if (!done) { lua_pushliteral(luaState, "LuaAfbEventPush-Fail No Subscriber to event"); - AFB_ApiError(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count); + AFB_API_ERROR(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count); lua_error(luaState); return 1; } @@ -582,16 +580,16 @@ static int LuaAfbEventSubscribe(lua_State* luaState) { afbevt = (LuaAfbEvent*) lua_touserdata(luaState, LUA_FIRST_ARG + 1); - if (!AFB_EventIsValid(afbevt->event)) { + if (!afb_event_is_valid(afbevt->event)) { lua_pushliteral(luaState, "LuaAfbMakePush-Fail invalid event handle"); lua_error(luaState); return 1; } - int err = AFB_ReqSubscribe(source->request, afbevt->event); + int err = afb_req_subscribe(source->request, afbevt->event); if (err) { lua_pushliteral(luaState, "LuaAfbEventSubscribe-Fail No Subscriber to event"); - AFB_ApiError(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count); + AFB_API_ERROR(source->api, "LuaAfbEventPush-Fail name subscriber event=%s count=%d", afbevt->name, afbevt->count); lua_error(luaState); return 1; } @@ -637,9 +635,9 @@ static int LuaAfbEventMake(lua_State* luaState) { afbevt->name = strdup(lua_tostring(luaState, LUA_FIRST_ARG + 1)); // create a new binder event - afbevt->event = AFB_EventMake(source->api, afbevt->name); - if (!AFB_EventIsValid(afbevt->event)) { - AFB_ApiError(source->api, "Fail to CreateEvent evtname=%s", afbevt->name); + afbevt->event = afb_api_make_event(source->api, afbevt->name); + if (!afb_event_is_valid(afbevt->event)) { + AFB_API_ERROR(source->api, "Fail to CreateEvent evtname=%s", afbevt->name); lua_pushliteral(luaState, "LuaAfbEventMake-Fail to Create Binder event"); lua_error(luaState); return 1; @@ -749,7 +747,7 @@ int LuaCallFunc(CtlSourceT *source, CtlActionT *action, json_object *queryJ) { // effectively exec LUA script code err = lua_pcall(luaState, count, 1, 0); if (err) { - AFB_ApiError(source->api, "LuaCallFunc Fail calling %s error=%s", func, lua_tostring(luaState, -1)); + AFB_API_ERROR(source->api, "LuaCallFunc Fail calling %s error=%s", func, lua_tostring(luaState, -1)); return -1; } @@ -758,24 +756,24 @@ int LuaCallFunc(CtlSourceT *source, CtlActionT *action, json_object *queryJ) { return rc; } -int LuaLoadScript(AFB_ApiT apiHandle, const char *luaScriptPath) { +int LuaLoadScript(afb_api_t apiHandle, const char *luaScriptPath) { int err = 0; if (!luaScriptPath) { - AFB_ApiError(apiHandle, "Error: provided path is NULL"); + AFB_API_ERROR(apiHandle, "Error: provided path is NULL"); return -1; } err = luaL_loadfile(luaState, luaScriptPath); if (err) { - AFB_ApiError(apiHandle, "Error at load for %s: %s", luaScriptPath, lua_tostring(luaState, -1)); + AFB_API_ERROR(apiHandle, "Error at load for %s: %s", luaScriptPath, lua_tostring(luaState, -1)); return err; } // Script was loaded we need to parse to make it executable err = lua_pcall(luaState, 0, 0, 0); if (err) { - AFB_ApiError(apiHandle, "Error at execution for %s: %s", luaScriptPath, lua_tostring(luaState, -1)); + AFB_API_ERROR(apiHandle, "Error at execution for %s: %s", luaScriptPath, lua_tostring(luaState, -1)); return err; } return err; @@ -800,7 +798,7 @@ static int LuaDoScript(json_object *queryJ, CtlSourceT *source) { "args", &argsJ); if (err) { - AFB_ApiError(source->api, "LUA-DOSCRIPT-SCAN: Miss something in JSON object uid|[spath]|action|[args]: %s", json_object_to_json_string(queryJ)); + AFB_API_ERROR(source->api, "LUA-DOSCRIPT-SCAN: Miss something in JSON object uid|[spath]|action|[args]: %s", json_object_to_json_string(queryJ)); return -1; } @@ -812,7 +810,7 @@ static int LuaDoScript(json_object *queryJ, CtlSourceT *source) { } if(!luaScriptPathJ) { - AFB_ApiError(source->api, "LUA-DOSCRIPT-SCAN: No script found"); + AFB_API_ERROR(source->api, "LUA-DOSCRIPT-SCAN: No script found"); return -1; } @@ -821,7 +819,7 @@ static int LuaDoScript(json_object *queryJ, CtlSourceT *source) { err = wrap_json_unpack(entryJ, "{s:s, s:s !}", "fullpath", &fullpath, "filename", &filename); if (err) { - AFB_ApiError(source->api, "LUA-DOSCRIPT-SCAN:HOOPs invalid config file path = %s", json_object_to_json_string(entryJ)); + AFB_API_ERROR(source->api, "LUA-DOSCRIPT-SCAN:HOOPs invalid config file path = %s", json_object_to_json_string(entryJ)); return -1; } @@ -902,12 +900,12 @@ static int LuaDoString(const char *script, CtlSourceT *source) { // Execute LUA code from received API request -static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) { +static void LuaDoAction(LuaDoActionT action, afb_req_t request) { int err = 0, count = 0; CtlSourceT *source = alloca(sizeof (CtlSourceT)); source->request = request; - json_object* queryJ = AFB_ReqJson(request); + json_object* queryJ = afb_req_json(request); switch (action) { @@ -916,7 +914,7 @@ static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) { const char *script = json_object_get_string(queryJ); count = LuaDoString(script, source); if (count) - AFB_ApiError(source->api, "DOSTRING goes wrong err=%d, String=%s ", count, script); + AFB_API_ERROR(source->api, "DOSTRING goes wrong err=%d, String=%s ", count, script); break; } @@ -924,7 +922,7 @@ static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) { { count = LuaDoCall(queryJ, source); if (count) - AFB_ApiError(source->api, "DOCALL goes wrong, error = %d, query=%s", count, json_object_get_string(queryJ)); + AFB_API_ERROR(source->api, "DOCALL goes wrong, error = %d, query=%s", count, json_object_get_string(queryJ)); break; } @@ -932,35 +930,35 @@ static void LuaDoAction(LuaDoActionT action, AFB_ReqT request) { { // Fulup need to fix argument passing count = LuaDoScript(queryJ, source); if (count) - AFB_ApiError(source->api, "DOSCRIPT goes wrong error=%d query=%s", count, json_object_to_json_string(queryJ)); + AFB_API_ERROR(source->api, "DOSCRIPT goes wrong error=%d query=%s", count, json_object_to_json_string(queryJ)); break; } default: - AFB_ApiError(source->api, "LUA-DOSCRIPT-ACTION unknown query=%s", json_object_to_json_string(queryJ)); - AFB_ReqFail(request, "LUA:ERROR", lua_tostring(luaState, -1)); + AFB_API_ERROR(source->api, "LUA-DOSCRIPT-ACTION unknown query=%s", json_object_to_json_string(queryJ)); + afb_req_success(request, json_object_new_string("LUA:ERROR"), lua_tostring(luaState, -1)); return; } if (count >= 0) err = lua_pcall(luaState, count + 1, 0, 0); if (err) { - AFB_ApiError(source->api, "LUA-DO-EXEC:FAIL query=%s err=%s", json_object_to_json_string(queryJ), lua_tostring(luaState, -1)); - AFB_ReqFail(request, "LUA:ERROR", lua_tostring(luaState, -1)); + AFB_API_ERROR(source->api, "LUA-DO-EXEC:FAIL query=%s err=%s", json_object_to_json_string(queryJ), lua_tostring(luaState, -1)); + afb_req_success(request, json_object_new_string("LUA:ERROR"), lua_tostring(luaState, -1)); return; } return; } -void ctlapi_execlua(AFB_ReqT request) { +void ctlapi_execlua(afb_req_t request) { LuaDoAction(LUA_DOSTRING, request); } -void ctlapi_request(AFB_ReqT request) { +void ctlapi_request(afb_req_t request) { LuaDoAction(LUA_DOCALL, request); } -void ctlapi_debuglua(AFB_ReqT request) { +void ctlapi_debuglua(afb_req_t request) { LuaDoAction(LUA_DOSCRIPT, request); } @@ -985,13 +983,8 @@ static int LuaTimerClear(lua_State* luaState) { if (!timerHandle) return 1; -#if(AFB_BINDING_VERSION == 3) || ((AFB_BINDING_VERSION == 0) && defined(AFB_BINDING_WANT_DYNAPI)) - // API handle does not exit in API-V2 LuaCbHandleT *luaCbHandle = (LuaCbHandleT*) timerHandle->context; - AFB_ApiNotice(luaCbHandle->source->api, "LuaTimerClear timer=%s", timerHandle->uid); -#else - AFB_NOTICE("LuaTimerClear timer=%s", timerHandle->uid); -#endif + AFB_API_NOTICE(luaCbHandle->source->api, "LuaTimerClear timer=%s", timerHandle->uid); TimerEvtStop(timerHandle); @@ -1049,7 +1042,7 @@ static int LuaTimerSetCB(TimerHandleT *timer) { int err = lua_pcall(luaState, count, LUA_MULTRET, 0); if (err) { - AFB_ApiError(LuaCbHandle->source->api, "LUA-TIMER-CB:FAIL response=%s err=%s", json_object_to_json_string(LuaCbHandle->context), lua_tostring(luaState, -1)); + AFB_API_ERROR(LuaCbHandle->source->api, "LUA-TIMER-CB:FAIL response=%s err=%s", json_object_to_json_string(LuaCbHandle->context), lua_tostring(luaState, -1)); return 1; } @@ -1158,7 +1151,7 @@ static void *LuaClientCtxNew(void * handle) { int err = lua_pcall(luaState, count, 1, 0); if (err) { - AFB_ApiError(clientCtx->source->api, "LuaClientCtxNew:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1)); + AFB_API_ERROR(clientCtx->source->api, "LuaClientCtxNew:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1)); return NULL; } @@ -1194,7 +1187,7 @@ static void LuaClientCtxFree(void * handle) { int err = lua_pcall(luaState, count, LUA_MULTRET, 0); if (err) { - AFB_ApiError(clientCtx->source->api, "LuaClientCtxFree:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1)); + AFB_API_ERROR(clientCtx->source->api, "LuaClientCtxFree:FAIL response=%s err=%s", json_object_to_json_string(clientCtx->clientCtxJ), lua_tostring(luaState, -1)); return; } @@ -1217,7 +1210,7 @@ static int LuaClientCtx(lua_State* luaState) { return 1; // return error code } - if (!AFB_ReqIsValid(source->request)) { + if (!afb_req_is_valid(source->request)) { lua_pushliteral(luaState, "LuaSessionSet-Syntax should be called within client request context"); lua_error(luaState); return 1; // return error code @@ -1225,7 +1218,7 @@ static int LuaClientCtx(lua_State* luaState) { // in only one arg then we should free the clientCtx if (lua_gettop(luaState) == LUA_FIRST_ARG) { - AFB_ClientCtxClear(source->request); + afb_req_context_clear(source->request); lua_pushnil(luaState); return 1; } @@ -1247,7 +1240,7 @@ static int LuaClientCtx(lua_State* luaState) { memcpy(clientCtx->source, source, sizeof (CtlSourceT)); // source if free when command return // push client context within session - void *done = AFB_ClientCtxSet(source->request, 1, LuaClientCtxNew, LuaClientCtxFree, clientCtx); + void *done = afb_req_context(source->request, 1, LuaClientCtxNew, LuaClientCtxFree, clientCtx); if (!done) { lua_pushliteral(luaState, "LuaClientCtx-Fail to allocate client context)"); lua_error(luaState); @@ -1294,19 +1287,19 @@ static const luaL_Reg afbFunction[] = { // Load Lua Interpreter -int LuaConfigExec(AFB_ApiT apiHandle) { +int LuaConfigExec(afb_api_t apiHandle) { int err; // Load LUA utils functions. err = LuaDoString(lua_utils, NULL); if (err) { - AFB_ApiError(apiHandle, "Error loading lua_utils default functions.%s, %d", lua_utils, err); + AFB_API_ERROR(apiHandle, "Error loading lua_utils default functions.%s, %d", lua_utils, err); return -1; } err = lua_pcall(luaState, 0, 0, 0); if (err) { - AFB_ApiError(apiHandle, "Error loading lua_utils default functions at pcall.%s, %d", lua_tostring(luaState, 0), err); + AFB_API_ERROR(apiHandle, "Error loading lua_utils default functions at pcall.%s, %d", lua_tostring(luaState, 0), err); return -1; } return 0; @@ -1314,7 +1307,7 @@ int LuaConfigExec(AFB_ApiT apiHandle) { // Load Lua Interpreter -int LuaConfigLoad(AFB_ApiT apiHandle, const char *prefix) { +int LuaConfigLoad(afb_api_t apiHandle, const char *prefix) { size_t total_len = 0, base_len = 0, spath_len = 0; static int luaLoaded = 0; int token_nb = 0, i = 0; @@ -1327,7 +1320,7 @@ int LuaConfigLoad(AFB_ApiT apiHandle, const char *prefix) { // open a new LUA interpretor luaState = luaL_newstate(); if (!luaState) { - AFB_ApiError(apiHandle, "LUA_INIT: Fail to open lua interpretor"); + AFB_API_ERROR(apiHandle, "LUA_INIT: Fail to open lua interpretor"); free(luaState); return 1; } diff --git a/ctl-lib/ctl-lua.h b/ctl-lib/ctl-lua.h index a02c6e1..b686c37 100644 --- a/ctl-lib/ctl-lua.h +++ b/ctl-lib/ctl-lua.h @@ -52,12 +52,12 @@ typedef enum { } LuaDoActionT; extern const char *lua_utils; -extern int LuaLoadScript(AFB_ApiT apiHandle, const char *luaScriptPath); -extern int LuaConfigLoad (AFB_ApiT apiHandle, const char *prefix); +extern int LuaLoadScript(afb_api_t apiHandle, const char *luaScriptPath); +extern int LuaConfigLoad (afb_api_t apiHandle, const char *prefix); extern void LuaL2cNewLib(luaL_Reg *l2cFunc, int count, const char *prefix); extern int Lua2cWrapper(void* luaHandle, char *funcname, Lua2cFunctionT callback); extern int LuaCallFunc (CtlSourceT *source, CtlActionT *action, json_object *queryJ) ; -extern int LuaConfigExec(AFB_ApiT apiHandle); +extern int LuaConfigExec(afb_api_t apiHandle); #ifdef __cplusplus } diff --git a/ctl-lib/ctl-onload.c b/ctl-lib/ctl-onload.c index 6100f2a..46196c2 100644 --- a/ctl-lib/ctl-onload.c +++ b/ctl-lib/ctl-onload.c @@ -23,19 +23,19 @@ #include "ctl-config.h" // onload section receive one action or an array of actions -int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ) { +int OnloadConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *actionsJ) { int err = 0; // Load time parse actions in control file if (actionsJ != NULL) { if ( (err= AddActionsToSection(apiHandle, section, actionsJ, 0)) ) { - AFB_ApiError (apiHandle, "OnloadConfig control fail processing actions for section %s", section->uid); + AFB_API_ERROR (apiHandle, "OnloadConfig control fail processing actions for section %s", section->uid); return err; } } else { // Exec time process onload action now if (!section->actions) { - AFB_ApiWarning (apiHandle, "OnloadConfig Cannot Exec Non Existing Onload Action"); + AFB_API_WARNING (apiHandle, "OnloadConfig Cannot Exec Non Existing Onload Action"); return 1; } @@ -48,7 +48,7 @@ int OnloadConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *actionsJ if(!err) err = ActionExecOne(&source, §ion->actions[idx], NULL); else { - AFB_ApiError(apiHandle, "Onload action execution failed on: %s", source.uid); + AFB_API_ERROR(apiHandle, "Onload action execution failed on: %s", source.uid); return err; } } diff --git a/ctl-lib/ctl-plugin.c b/ctl-lib/ctl-plugin.c index 5d3ae1f..0a41c7f 100644 --- a/ctl-lib/ctl-plugin.c +++ b/ctl-lib/ctl-plugin.c @@ -24,13 +24,13 @@ #include "ctl-config.h" -int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ) { +int PluginGetCB (afb_api_t apiHandle, CtlActionT *action , json_object *callbackJ) { const char *plugin=NULL, *function=NULL; json_object *argsJ; int idx; if (!ctlPlugins) { - AFB_ApiError(apiHandle, "PluginGetCB plugin section missing cannot call '%s'", json_object_get_string(callbackJ)); + AFB_API_ERROR(apiHandle, "PluginGetCB plugin section missing cannot call '%s'", json_object_get_string(callbackJ)); return 1; } @@ -39,7 +39,7 @@ int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ "function", &function, "args", &argsJ); if (err) { - AFB_ApiError(apiHandle, "PluginGet missing plugin|function|[args] in %s", json_object_get_string(callbackJ)); + AFB_API_ERROR(apiHandle, "PluginGet missing plugin|function|[args] in %s", json_object_get_string(callbackJ)); return 1; } @@ -48,7 +48,7 @@ int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ } if (!ctlPlugins[idx].uid) { - AFB_ApiError(apiHandle, "PluginGetCB no plugin with uid=%s", plugin); + AFB_API_ERROR(apiHandle, "PluginGetCB no plugin with uid=%s", plugin); return 1; } @@ -57,7 +57,7 @@ int PluginGetCB (AFB_ApiT apiHandle, CtlActionT *action , json_object *callbackJ action->exec.cb.plugin= &ctlPlugins[idx]; if (!action->exec.cb.callback) { - AFB_ApiError(apiHandle, "PluginGetCB no plugin=%s no function=%s", plugin, function); + AFB_API_ERROR(apiHandle, "PluginGetCB no plugin=%s no function=%s", plugin, function); return 1; } return 0; @@ -74,31 +74,29 @@ static int DispatchOneL2c(void* luaState, char *funcname, Lua2cFunctionT callbac #endif } -static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_object *lua2csJ, const char *lua2c_prefix, void * handle, CtlPluginT *ctlPlugin) +static int PluginLoadCOne(afb_api_t apiHandle, const char *pluginpath, json_object *lua2csJ, const char *lua2c_prefix, void * handle, CtlPluginT *ctlPlugin) { void *dlHandle = dlopen(pluginpath, RTLD_NOW); if (!dlHandle) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Fail to load pluginpath=%s err= %s", pluginpath, dlerror()); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Fail to load pluginpath=%s err= %s", pluginpath, dlerror()); return -1; } CtlPluginMagicT *ctlPluginMagic = (CtlPluginMagicT*) dlsym(dlHandle, "CtlPluginMagic"); if (!ctlPluginMagic || ctlPluginMagic->magic != CTL_PLUGIN_MAGIC) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE symbol'CtlPluginMagic' missing or != CTL_PLUGIN_MAGIC plugin=%s", pluginpath); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE symbol'CtlPluginMagic' missing or != CTL_PLUGIN_MAGIC plugin=%s", pluginpath); return -1; } else { - AFB_ApiNotice(apiHandle, "CTL-PLUGIN-LOADONE %s successfully registered", ctlPluginMagic->uid); + AFB_API_NOTICE(apiHandle, "CTL-PLUGIN-LOADONE %s successfully registered", ctlPluginMagic->uid); } // store dlopen handle to enable onload action at exec time ctlPlugin->dlHandle = dlHandle; -#if (defined(AFB_BINDING_PREV3) || (AFB_BINDING_VERSION == 3)) // Jose hack to make verbosity visible from sharelib with API-V2 struct afb_binding_data_v2 *afbHidenData = dlsym(dlHandle, "afbBindingV2data"); if (afbHidenData) *afbHidenData = afbBindingV2data; -#endif // Push lua2cWrapper @ into plugin Lua2cWrapperT *lua2cInPlug = dlsym(dlHandle, "Lua2cWrap"); @@ -121,7 +119,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec Lua2cFunctionT l2cFunction = (Lua2cFunctionT) dlsym(dlHandle, funcName); if (!l2cFunction) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE symbol'%s' missing err=%s", funcName, dlerror()); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE symbol'%s' missing err=%s", funcName, dlerror()); return 1; } l2cFunc[index].func = (void*) l2cFunction; @@ -157,7 +155,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec count++; } if (errCount) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE %d symbols not found in plugin='%s'", errCount, pluginpath); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE %d symbols not found in plugin='%s'", errCount, pluginpath); return -1; } int total = ctlPlugin->ctlL2cFunc->l2cCount + count; @@ -179,7 +177,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec DispatchPluginInstallCbT ctlPluginOnload = dlsym(dlHandle, "CtlPluginOnload"); if (ctlPluginOnload) { if((*ctlPluginOnload) (ctlPlugin, handle)) { - AFB_ApiError(apiHandle, "Plugin Onload function hasn't finish well. Abort initialization"); + AFB_API_ERROR(apiHandle, "Plugin Onload function hasn't finish well. Abort initialization"); return -1; } } @@ -187,7 +185,7 @@ static int PluginLoadCOne(AFB_ApiT apiHandle, const char *pluginpath, json_objec return 0; } -static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_object *lua2csJ, const char *lua2c_prefix, void *handle, CtlPluginT *ctlPlugin) +static int LoadFoundPlugins(afb_api_t apiHandle, json_object *scanResult, json_object *lua2csJ, const char *lua2c_prefix, void *handle, CtlPluginT *ctlPlugin) { char pluginpath[CONTROL_MAXPATH_LEN]; char *filename; @@ -211,7 +209,7 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob "filename", &filename); if (err) { - AFB_ApiError(apiHandle, "HOOPs invalid plugin file path=\n-- %s", json_object_get_string(scanResult)); + AFB_API_ERROR(apiHandle, "HOOPs invalid plugin file path=\n-- %s", json_object_get_string(scanResult)); return -1; } @@ -232,18 +230,18 @@ static int LoadFoundPlugins(AFB_ApiT apiHandle, json_object *scanResult, json_ob } if(len > 1) - AFB_ApiWarning(apiHandle, "Plugin multiple instances in searchpath will use %s/%s", fullpath, filename); + AFB_API_WARNING(apiHandle, "Plugin multiple instances in searchpath will use %s/%s", fullpath, filename); return 0; } -char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix) +char *GetDefaultPluginSearchPath(afb_api_t apiHandle, const char *prefix) { char *searchPath, *rootDir, *path; const char *bindingPath; const char *envDirList; size_t envDirList_len; - json_object *settings = AFB_GetApiSettings(apiHandle); + json_object *settings = afb_api_settings(apiHandle); json_object *bpath; if(json_object_object_get_ex(settings, "binding-path", &bpath)) { @@ -282,18 +280,18 @@ char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix) return searchPath; } -static int FindPlugins(AFB_ApiT apiHandle, const char *searchPath, const char *file, json_object **pluginPathJ) +static int FindPlugins(afb_api_t apiHandle, const char *searchPath, const char *file, json_object **pluginPathJ) { *pluginPathJ = ScanForConfig(searchPath, CTL_SCAN_RECURSIVE, file, NULL); if (!*pluginPathJ || json_object_array_length(*pluginPathJ) == 0) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Missing plugin=%s* (config ldpath?) search=\n-- %s", file, searchPath); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Missing plugin=%s* (config ldpath?) search=\n-- %s", file, searchPath); return -1; } return 0; } -static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *pluginJ, void *handle, const char *prefix) +static int PluginLoad (afb_api_t apiHandle, CtlPluginT *ctlPlugin, json_object *pluginJ, void *handle, const char *prefix) { int err = 0, i = 0; char *searchPath; @@ -312,7 +310,7 @@ static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *p "params", &ctlPlugin->paramsJ ); if (err) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Plugin missing uid|[info]|libs|[spath]|[lua]|[params] in:\n-- %s", json_object_get_string(pluginJ)); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Plugin missing uid|[info]|libs|[spath]|[lua]|[params] in:\n-- %s", json_object_get_string(pluginJ)); return 1; } @@ -321,7 +319,7 @@ static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *p "prefix", &lua2c_prefix, "functions", &lua2csJ); if(err) { - AFB_ApiError(apiHandle, "CTL-PLUGIN-LOADONE Missing 'function' in:\n-- %s", json_object_get_string(pluginJ)); + AFB_API_ERROR(apiHandle, "CTL-PLUGIN-LOADONE Missing 'function' in:\n-- %s", json_object_get_string(pluginJ)); return 1; } } @@ -374,7 +372,7 @@ static int PluginLoad (AFB_ApiT apiHandle, CtlPluginT *ctlPlugin, json_object *p return 0; } -static int PluginParse(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ, int *pluginNb) { +static int PluginParse(afb_api_t apiHandle, CtlSectionT *section, json_object *pluginsJ, int *pluginNb) { int idx = 0, err = 0; switch (json_object_get_type(pluginsJ)) { @@ -394,7 +392,7 @@ static int PluginParse(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pl break; } default: { - AFB_ApiError(apiHandle, "Wrong JSON object passed: %s", json_object_get_string(pluginsJ)); + AFB_API_ERROR(apiHandle, "Wrong JSON object passed: %s", json_object_get_string(pluginsJ)); err = -1; } } @@ -402,7 +400,7 @@ static int PluginParse(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pl return err; } -int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ) { +int PluginConfig(afb_api_t apiHandle, CtlSectionT *section, json_object *pluginsJ) { int err = 0; int idx = 0, jdx = 0; int pluginNb = 0, newPluginsNb = 0, totalPluginNb = 0; @@ -445,7 +443,7 @@ int PluginConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *pluginsJ DispatchPluginInstallCbT ctlPluginInit = dlsym(ctlPlugins[idx].dlHandle, "CtlPluginInit"); if (ctlPluginInit) { if((*ctlPluginInit) (&ctlPlugins[idx], ctlPlugins[idx].context)) { - AFB_ApiError(apiHandle, "Plugin Init function hasn't finish well. Abort initialization"); + AFB_API_ERROR(apiHandle, "Plugin Init function hasn't finish well. Abort initialization"); return -1; } } diff --git a/ctl-lib/ctl-plugin.h b/ctl-lib/ctl-plugin.h index d931906..752d471 100644 --- a/ctl-lib/ctl-plugin.h +++ b/ctl-lib/ctl-plugin.h @@ -59,7 +59,7 @@ typedef struct { typedef struct { const char *uid; const char *info; - AFB_ApiT api; + afb_api_t api; void *dlHandle; void *context; json_object *paramsJ; @@ -84,8 +84,8 @@ typedef enum { typedef struct { const char *uid; - AFB_ApiT api; - AFB_ReqT request; + afb_api_t api; + afb_req_t request; void *context; CtlActionStatusT status; } CtlSourceT; @@ -94,7 +94,7 @@ typedef struct { const char *uid; const char *info; const char *privileges; - AFB_ApiT api; + afb_api_t api; json_object *argsJ; CtlActionTypeT type; union { @@ -135,7 +135,7 @@ typedef int (*Lua2cWrapperT) (void*luaHandle, const char *funcname, Lua2cFunctio int lua2c_ ## funcname (void* luaState){return((*Lua2cWrap)(luaState, MACRO_STR_VALUE(funcname), funcname));};\ int funcname (CtlSourceT* source, json_object* argsJ, json_object** responseJ) -extern char *GetDefaultPluginSearchPath(AFB_ApiT apiHandle, const char *prefix); +extern char *GetDefaultPluginSearchPath(afb_api_t apiHandle, const char *prefix); #ifdef __cplusplus } diff --git a/ctl-lib/ctl-timer.c b/ctl-lib/ctl-timer.c index c36d2b1..c4cba28 100644 --- a/ctl-lib/ctl-timer.c +++ b/ctl-lib/ctl-timer.c @@ -39,7 +39,7 @@ static int TimerNext (sd_event_source* source, uint64_t timer, void* handle) { done= timerHandle->callback(timerHandle); if (!done) { - AFB_ApiWarning(timerHandle->api, "TimerNext Callback Fail Tag=%s", timerHandle->uid); + AFB_API_WARNING(timerHandle->api, "TimerNext Callback Fail Tag=%s", timerHandle->uid); return -1; } @@ -53,7 +53,7 @@ static int TimerNext (sd_event_source* source, uint64_t timer, void* handle) { } else { // otherwise validate timer for a new run - sd_event_now(AFB_GetEventLoop(timerHandle->api), CLOCK_MONOTONIC, &usec); + sd_event_now(afb_api_get_event_loop(timerHandle->api), CLOCK_MONOTONIC, &usec); sd_event_source_set_enabled(source, SD_EVENT_ONESHOT); sd_event_source_set_time(source, usec + timerHandle->delay*1000); } @@ -68,7 +68,7 @@ void TimerEvtStop(TimerHandleT *timerHandle) { } -void TimerEvtStart(AFB_ApiT apiHandle, TimerHandleT *timerHandle, timerCallbackT callback, void *context) { +void TimerEvtStart(afb_api_t apiHandle, TimerHandleT *timerHandle, timerCallbackT callback, void *context) { uint64_t usec; // populate CB handle @@ -77,22 +77,22 @@ void TimerEvtStart(AFB_ApiT apiHandle, TimerHandleT *timerHandle, timerCallbackT timerHandle->api=apiHandle; // set a timer with ~250us accuracy - sd_event_now(AFB_GetEventLoop(apiHandle), CLOCK_MONOTONIC, &usec); - sd_event_add_time(AFB_GetEventLoop(apiHandle), &timerHandle->evtSource, CLOCK_MONOTONIC, usec+timerHandle->delay*1000, 250, TimerNext, timerHandle); + sd_event_now(afb_api_get_event_loop(apiHandle), CLOCK_MONOTONIC, &usec); + sd_event_add_time(afb_api_get_event_loop(apiHandle), &timerHandle->evtSource, CLOCK_MONOTONIC, usec+timerHandle->delay*1000, 250, TimerNext, timerHandle); } // Create Binding Event at Init -int TimerEvtInit (AFB_ApiT apiHandle) { +int TimerEvtInit (afb_api_t apiHandle) { - AFB_ApiDebug (apiHandle, "Timer-Init Done"); + AFB_API_DEBUG (apiHandle, "Timer-Init Done"); return 0; } -uint64_t LockWait(AFB_ApiT apiHandle, uint64_t utimeout) { +uint64_t LockWait(afb_api_t apiHandle, uint64_t utimeout) { uint64_t current_usec, pre_usec; - struct sd_event *event = AFB_GetEventLoop(apiHandle); + struct sd_event *event = afb_api_get_event_loop(apiHandle); sd_event_now(event, CLOCK_MONOTONIC, &pre_usec); sd_event_run(event, utimeout); diff --git a/ctl-lib/ctl-timer.h b/ctl-lib/ctl-timer.h index a65a906..ffc8f82 100644 --- a/ctl-lib/ctl-timer.h +++ b/ctl-lib/ctl-timer.h @@ -35,18 +35,18 @@ typedef struct TimerHandleS { const char*uid; void *context; sd_event_source *evtSource; - AFB_ApiT api; + afb_api_t api; int (*callback) (struct TimerHandleS *handle); int (*freeCB) (void *context) ; } TimerHandleT; typedef int (*timerCallbackT)(TimerHandleT *context); -extern int TimerEvtInit (AFB_ApiT apiHandle); -extern void TimerEvtStart(AFB_ApiT apiHandle, TimerHandleT *timerHandle, timerCallbackT callback, void *context); +extern int TimerEvtInit (afb_api_t apiHandle); +extern void TimerEvtStart(afb_api_t apiHandle, TimerHandleT *timerHandle, timerCallbackT callback, void *context); extern void TimerEvtStop(TimerHandleT *timerHandle); -extern uint64_t LockWait(AFB_ApiT apiHandle, uint64_t utimeout); +extern uint64_t LockWait(afb_api_t apiHandle, uint64_t utimeout); #ifdef __cplusplus } #endif |