aboutsummaryrefslogtreecommitdiffstats
path: root/afb-source
diff options
context:
space:
mode:
Diffstat (limited to 'afb-source')
-rw-r--r--afb-source/ctl-binding.h8
-rw-r--r--afb-source/ctl-dispatch.c54
-rw-r--r--afb-source/ctl-policy.c96
-rw-r--r--afb-source/ctl-timer.c18
4 files changed, 88 insertions, 88 deletions
diff --git a/afb-source/ctl-binding.h b/afb-source/ctl-binding.h
index 0d16e56..f159440 100644
--- a/afb-source/ctl-binding.h
+++ b/afb-source/ctl-binding.h
@@ -70,7 +70,7 @@ typedef enum {
CTL_MODE_NONE=0,
CTL_MODE_API,
CTL_MODE_CB,
- CTL_MODE_LUA,
+ CTL_MODE_LUA,
} CtlRequestModeT;
@@ -130,14 +130,14 @@ PUBLIC void ctlapi_lua_doscript (afb_req request);
// sharelib ctl-plugin*
typedef struct {
- long magic;
- char *label;
+ long magic;
+ char *label;
} CtlPluginMagicT;
#define MACRO_STR_VALUE(arg) #arg
#define CTLP_REGISTER(pluglabel) CtlPluginMagicT CtlPluginMagic={.magic=CTL_PLUGIN_MAGIC,.label=pluglabel}; struct afb_binding_data_v2; Lua2cWrapperT Lua2cWrap;
-#define CTLP_ONLOAD(label,version,info) void* CtlPluginOnload(char* label, char* version, char* info)
+#define CTLP_ONLOAD(label,version,info) void* CtlPluginOnload(char* label, char* version, char* info)
#define CTLP_CAPI(funcname,source, label,argsJ, queryJ, context) int funcname(DispatchSourceT source, char* label, json_object* argsJ, json_object* queryJ, void* context)
diff --git a/afb-source/ctl-dispatch.c b/afb-source/ctl-dispatch.c
index 95d1315..bbc15ad 100644
--- a/afb-source/ctl-dispatch.c
+++ b/afb-source/ctl-dispatch.c
@@ -13,7 +13,7 @@
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, something express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* Reference:
* Json load using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
*/
@@ -58,7 +58,7 @@ typedef struct {
DispatchHandleT **controls;
} DispatchConfigT;
-// global config handle
+// global config handle
STATIC DispatchConfigT *configHandle = NULL;
STATIC int DispatchControlToIndex(DispatchHandleT **controls, const char* controlLabel) {
@@ -71,7 +71,7 @@ STATIC int DispatchControlToIndex(DispatchHandleT **controls, const char* contro
STATIC int DispatchOneControl(DispatchSourceT source, DispatchHandleT **controls, const char* controlLabel, json_object *queryJ, afb_req request) {
int err;
-
+
if (!configHandle) {
AFB_ERROR("DISPATCH-CTL-API: (Hoops/Bug!!!) No Config Loaded");
goto OnErrorExit;
@@ -87,12 +87,12 @@ STATIC int DispatchOneControl(DispatchSourceT source, DispatchHandleT **controls
AFB_ERROR("DISPATCH-CTL-API:NotFound/Error label=%s in Json Control Config File", controlLabel);
goto OnErrorExit;
}
-
+
// Fulup (Bug/Feature) in current version is unique to every onload profile
if (configHandle->plugin && configHandle->plugin->l2cCount) {
- LuaL2cNewLib (configHandle->plugin->label, configHandle->plugin->l2cFunc, configHandle->plugin->l2cCount);
+ LuaL2cNewLib (configHandle->plugin->label, configHandle->plugin->l2cFunc, configHandle->plugin->l2cCount);
}
-
+
// loop on action for this control
DispatchActionT *actions = controls[index]->actions;
for (int idx = 0; actions[idx].label; idx++) {
@@ -104,10 +104,10 @@ STATIC int DispatchOneControl(DispatchSourceT source, DispatchHandleT **controls
// if query is empty increment usage count and pass args
if (!queryJ || json_object_get_type(queryJ) != json_type_object) {
- json_object_get(actions[idx].argsJ);
+ json_object_get(actions[idx].argsJ);
queryJ= actions[idx].argsJ;
} else if (actions[idx].argsJ) {
-
+
// Merge queryJ and argsJ before sending request
if (json_object_get_type(actions[idx].argsJ) == json_type_object) {
json_object_object_foreach(actions[idx].argsJ, key, val) {
@@ -117,7 +117,7 @@ STATIC int DispatchOneControl(DispatchSourceT source, DispatchHandleT **controls
json_object_object_add(queryJ, "args", actions[idx].argsJ);
}
}
-
+
int err = afb_service_call_sync(actions[idx].api, actions[idx].call, queryJ, &returnJ);
if (err) {
static const char*format = "DispatchOneControl(Api) api=%s verb=%s args=%s";
@@ -180,7 +180,7 @@ PUBLIC void DispatchOneEvent(const char *evtLabel, json_object *eventJ) {
PUBLIC int DispatchOnLoad(const char *onLoadLabel) {
if (!configHandle) return 1;
-
+
DispatchHandleT **onloads = configHandle->onloads;
int err = DispatchOneControl(CTL_SOURCE_ONLOAD, onloads, onLoadLabel, NULL, NULL_AFBREQ);
@@ -192,14 +192,14 @@ PUBLIC void ctlapi_dispatch(afb_req request) {
json_object *queryJ, *argsJ=NULL;
const char *target;
DispatchSourceT source= CTL_SOURCE_UNKNOWN;
-
+
queryJ = afb_req_json(request);
int err = wrap_json_unpack(queryJ, "{s:s, s?i s?o !}", "target", &target, "source", &source, "args", &argsJ);
if (err) {
afb_req_fail_f(request, "CTL-DISPTACH-INVALID", "missing target or args not a valid json object query=%s", json_object_get_string(queryJ));
goto OnErrorExit;
}
-
+
(void) DispatchOneControl(source, controls, target, argsJ, request);
OnErrorExit:
@@ -211,7 +211,7 @@ PUBLIC int DispatchOneL2c(lua_State* luaState, char *funcname, Lua2cFunctionT ca
#ifndef CONTROL_SUPPORT_LUA
AFB_ERROR("DISPATCH-ONE-L2C: LUA support not selected (cf:CONTROL_SUPPORT_LUA) in config.cmake");
return 1;
-#else
+#else
int err=Lua2cWrapper(luaState, funcname, callback, configHandle->plugin->context);
return err;
#endif
@@ -223,13 +223,13 @@ PUBLIC int DispatchOneL2c(lua_State* luaState, char *funcname, Lua2cFunctionT ca
PUBLIC void ctlapi_config(struct afb_req request) {
json_object*tmpJ;
char *dirList;
-
+
json_object* queryJ = afb_req_json(request);
if (queryJ && json_object_object_get_ex(queryJ, "cfgpath", &tmpJ)) {
dirList = strdup(json_object_get_string(tmpJ));
} else {
-
+
dirList = getenv("CONTROL_CONFIG_PATH");
if (!dirList) dirList = strdup(CONTROL_CONFIG_PATH);
AFB_NOTICE("CONFIG-MISSING: use default CONTROL_CONFIG_PATH=%s", CONTROL_CONFIG_PATH);
@@ -399,7 +399,7 @@ STATIC DispatchHandleT *DispatchLoadOnload(DispatchConfigT *controlConfig, json_
// if search path not in Json config file, then try default
if (!ldSearchPath) ldSearchPath=CONTROL_PLUGIN_PATH;
-
+
// search for default policy config file
json_object *pluginPathJ = ScanForConfig(ldSearchPath, CTL_SCAN_RECURSIVE, dPlugin->sharelib, NULL);
if (!pluginPathJ || json_object_array_length(pluginPathJ) == 0) {
@@ -441,20 +441,20 @@ STATIC DispatchHandleT *DispatchLoadOnload(DispatchConfigT *controlConfig, json_
struct afb_binding_data_v2 *afbHidenData = dlsym(dPlugin->dlHandle, "afbBindingV2data");
if (afbHidenData) *afbHidenData = afbBindingV2data;
- // Push lua2cWrapper @ into plugin
+ // Push lua2cWrapper @ into plugin
Lua2cWrapperT *lua2cInPlug = dlsym(dPlugin->dlHandle, "Lua2cWrap");
-#ifndef CONTROL_SUPPORT_LUA
+#ifndef CONTROL_SUPPORT_LUA
if (lua2cInPlug) *lua2cInPlug = NULL;
#else
// Lua2cWrapper is part of binder and not expose to dynamic link
if (lua2cInPlug) *lua2cInPlug = DispatchOneL2c;
-
+
{
int Lua2cAddOne(luaL_Reg *l2cFunc, const char* l2cName, int index) {
char funcName[CONTROL_MAXPATH_LEN];
strncpy(funcName, "lua2c_", sizeof(funcName));
strncat(funcName, l2cName, sizeof(funcName));
-
+
Lua2cFunctionT l2cFunction= (Lua2cFunctionT)dlsym(dPlugin->dlHandle, funcName);
if (!l2cFunction) {
AFB_ERROR("DISPATCH-LOAD-CONFIG:Plugin symbol'%s' missing err=%s", funcName, dlerror());
@@ -462,14 +462,14 @@ STATIC DispatchHandleT *DispatchLoadOnload(DispatchConfigT *controlConfig, json_
}
l2cFunc[index].func=(void*)l2cFunction;
l2cFunc[index].name=strdup(l2cName);
-
+
return 0;
}
int errCount = 0;
luaL_Reg *l2cFunc=NULL;
int count=0;
-
+
// look on l2c command and push them to LUA
if (json_object_get_type(lua2csJ) == json_type_array) {
int length = json_object_array_length(lua2csJ);
@@ -531,8 +531,8 @@ STATIC DispatchConfigT *DispatchLoadConfig(const char* filepath) {
AFB_ERROR("DISPATCH-LOAD-CONFIG Missing something metadata|[onload]|[controls]|[events] in %s", json_object_get_string(controlConfigJ));
goto OnErrorExit;
}
-
-
+
+
DispatchConfigT *controlConfig = calloc(1, sizeof (DispatchConfigT));
if (metadataJ) {
@@ -542,7 +542,7 @@ STATIC DispatchConfigT *DispatchLoadConfig(const char* filepath) {
AFB_ERROR("DISPATCH-LOAD-CONFIG:METADATA Missing something label|version|[label] in %s", json_object_get_string(metadataJ));
goto OnErrorExit;
}
-
+
// if ctlname is provided change process name now
if (ctlname) {
err= prctl(PR_SET_NAME, ctlname,NULL,NULL,NULL);
@@ -620,7 +620,7 @@ OnErrorExit:
PUBLIC int DispatchInit() {
int index, err, luaLoaded = 0;
char controlFile [CONTROL_MAXPATH_LEN];
-
+
const char *dirList= getenv("CONTROL_CONFIG_PATH");
if (!dirList) dirList=CONTROL_CONFIG_PATH;
@@ -630,7 +630,7 @@ PUBLIC int DispatchInit() {
// search for default dispatch config file
json_object* responseJ = ScanForConfig(dirList, CTL_SCAN_RECURSIVE, controlFile, "json");
- // We load 1st file others are just warnings
+ // We load 1st file others are just warnings
for (index = 0; index < json_object_array_length(responseJ); index++) {
json_object *entryJ = json_object_array_get_idx(responseJ, index);
diff --git a/afb-source/ctl-policy.c b/afb-source/ctl-policy.c
index e9798b3..9fe220c 100644
--- a/afb-source/ctl-policy.c
+++ b/afb-source/ctl-policy.c
@@ -19,7 +19,7 @@
#include <stdio.h>
#include <string.h>
#include <dirent.h>
-#include <json-c/json_object.h>
+#include <json-c/json_object.h>
#include "wrap-json.h"
#include "ctl-binding.h"
@@ -32,17 +32,17 @@ STATIC json_object* ScanForConfig (char* searchPath) {
DIR *dirHandle;
char *dirPath;
char* dirList= strdup(searchPath);
-
+
responseJ = json_object_new_array();
for (dirPath= strtok(dirList, ":"); dirPath && *dirPath; dirPath=strtok(NULL,":")) {
struct dirent *dirEnt;
-
+
dirHandle = opendir (dirPath);
if (!dirHandle) {
AFB_NOTICE ("CONFIG-SCANNING dir=%s not readable", dirPath);
continue;
- }
-
+ }
+
AFB_NOTICE ("CONFIG-SCANNING:ctl_listconfig scanning: %s", dirPath);
while ((dirEnt = readdir(dirHandle)) != NULL) {
// Unknown type is accepted to support dump filesystems
@@ -54,18 +54,18 @@ STATIC json_object* ScanForConfig (char* searchPath) {
}
}
}
-
- free (dirList);
+
+ free (dirList);
return (responseJ);
}
PUBLIC void ctlapi_authorize (PolicyCtlEnumT control, afb_req request) {
json_object*tmpJ;
-
+
json_object* queryJ= afb_req_json(request);
int done=json_object_object_get_ex(queryJ, "closing", &tmpJ);
if (done) return;
-
+
}
@@ -73,34 +73,34 @@ PUBLIC void ctlapi_authorize (PolicyCtlEnumT control, afb_req request) {
PUBLIC void ctlapi_config (struct afb_req request) {
json_object*tmpJ;
char *dirList;
-
+
json_object* queryJ = afb_req_json(request);
if (queryJ && json_object_object_get_ex (queryJ, "cfgpath" , &tmpJ)) {
dirList = strdup (json_object_get_string(tmpJ));
- } else {
- dirList = strdup (CONTROL_CONFIG_PATH);
+ } else {
+ dirList = strdup (CONTROL_CONFIG_PATH);
AFB_NOTICE ("CONFIG-MISSING: use default CONTROL_CONFIG_PATH=%s", CONTROL_CONFIG_PATH);
}
-
+
// get list of config file
struct json_object *responseJ = ScanForConfig(dirList);
-
+
if (json_object_array_length(responseJ) == 0) {
- afb_req_fail(request, "CONFIGPATH:EMPTY", "No Config Found in CONTROL_CONFIG_PATH");
+ afb_req_fail(request, "CONFIGPATH:EMPTY", "No Config Found in CONTROL_CONFIG_PATH");
} else {
afb_req_success(request, responseJ, NULL);
}
-
+
return;
}
STATIC PolicyActionT **PolicyLoadActions (json_object *actionsJ) {
int err;
PolicyActionT ** actions;
-
+
// unpack individual action object
int actionUnpack (json_object *actionJ, PolicyActionT *action) {
-
+
err= wrap_json_unpack(actionJ, "{ss,s?s,s?s,s?s,s?s,s?s !}"
, "label",&action->label, "info",&action->info, "callback",&action->callback, "query",&queryJ, "api",&action->api, "verb", &action->verb);
if (err) {
@@ -108,34 +108,34 @@ STATIC PolicyActionT **PolicyLoadActions (json_object *actionsJ) {
return -1;
}
if (!action->callback || !(action->api && action->verb)) {
- AFB_ERROR ("POLICY-LOAD-ACTION Missing something callback|(api+verb) in %s", json_object_get_string(actionJ));
- return -1;
- }
+ AFB_ERROR ("POLICY-LOAD-ACTION Missing something callback|(api+verb) in %s", json_object_get_string(actionJ));
+ return -1;
+ }
return 0;
};
-
+
// action array is close with a nullvalue;
if (json_object_get_type(actionsJ) == json_type_array) {
int count = json_object_array_length(actionsJ);
actions = calloc (count+1, sizeof(PolicyActionT));
-
+
for (int idx=0; idx < count; idx++) {
json_object *actionJ = json_object_array_get_idx(actionsJ, idx);
err = actionUnpack (actionJ, &actions[idx]);
if (err) goto OnErrorExit;
}
-
+
} else {
- actions = calloc (2, sizeof(PolicyActionT));
+ actions = calloc (2, sizeof(PolicyActionT));
err = actionUnpack (actionsJ, &actions[0]);
if (err) goto OnErrorExit;
}
-
+
return actions;
-
+
OnErrorExit:
return NULL;
-
+
}
// load control policy from file using json_unpack https://jansson.readthedocs.io/en/2.9/apiref.html#parsing-and-validating-values
@@ -143,25 +143,25 @@ STATIC PolicyCtlConfigT *PolicyLoadConfig (const char* filepath) {
json_object *policyConfigJ, *ignoreJ, *actionsJ;
PolicyCtlConfigT *policyConfig = calloc (1, sizeof(PolicyCtlConfigT));
int err;
-
+
// Load JSON file
policyConfigJ= json_object_from_file(filepath);
if (!policyConfigJ) goto OnErrorExit;
-
+
json_object *metadataJ, *onloadJ, *controlsJ, *eventsJ;
err= wrap_json_unpack(policyConfigJ, "{s?o,so,s?o,so,so !}", "$schema", &ignoreJ, "metadata",&metadataJ, "onload",&onloadJ, "controls",&controlsJ, "events",&eventsJ);
if (err) {
AFB_ERROR ("POLICY-LOAD-ERRROR Missing something metadata|onload|controls|events in %s", json_object_get_string(policyConfigJ));
goto OnErrorExit;
}
-
+
PolicyHandleT *policyHandle = calloc (1, sizeof(PolicyHandleT));
err= wrap_json_unpack(metadataJ, "{so,s?s,s?s !}", "label", &policyHandle->label, "info",&policyHandle->info, "version",&policyHandle->version);
if (err) {
AFB_ERROR ("POLICY-LOAD-CONFIG Missing something label|info|version in %s", json_object_get_string(metadataJ));
goto OnErrorExit;
}
-
+
if (onloadJ) {
err= wrap_json_unpack(onloadJ, "{s?o,s?s,s?s !}", "info",&ignoreJ, "label",&ignoreJ, "actions",&actionsJ);
if (err) {
@@ -170,9 +170,9 @@ STATIC PolicyCtlConfigT *PolicyLoadConfig (const char* filepath) {
}
policyConfig->onload = PolicyLoadActions (actionsJ);
}
-
+
return policyControl;
-
+
OnErrorExit:
return NULL;
}
@@ -180,42 +180,42 @@ OnErrorExit:
// Load default config file at init
PUBLIC int PolicyInit () {
int index, err;
-
-
+
+
// search for default policy config file
json_object* responseJ = ScanForConfig(CONTROL_CONFIG_PATH);
-
+
for (index=0; index < json_object_array_length(responseJ); index++) {
json_object *entryJ=json_object_array_get_idx(responseJ, index);
-
+
char *filename; char*dirpath;
err= wrap_json_unpack (entryJ, "{s:s, s:s !}", "dirpath", &dirpath,"filename", &filename);
if (err) {
AFB_ERROR ("POLICY-INIT HOOPs invalid config file path = %s", json_object_get_string(entryJ));
goto OnErrorExit;
}
-
+
if (strcasestr(filename, CONTROL_CONFIG_FILE)) {
char filepath[255];
- strncpy(filepath, dirpath, sizeof(filepath));
- strncat(filepath, "/", sizeof(filepath));
- strncat(filepath, filename, sizeof(filepath));
+ strncpy(filepath, dirpath, sizeof(filepath));
+ strncat(filepath, "/", sizeof(filepath));
+ strncat(filepath, filename, sizeof(filepath));
ctlHandle = PolicyLoadConfig (filepath);
if (!ctlHandle) goto OnErrorExit;
break;
}
}
-
+
// no policy config found remove control API from binder
if (index == 0) goto OnErrorExit;
-
+
AFB_NOTICE ("SUCCES: Audio Control Policy Init");
return 0;
-
+
OnErrorExit:
AFB_NOTICE ("ERROR: Audio Control Policy Init");
- return 1;
+ return 1;
}
-
-
+
+
diff --git a/afb-source/ctl-timer.c b/afb-source/ctl-timer.c
index a826f9f..50e181b 100644
--- a/afb-source/ctl-timer.c
+++ b/afb-source/ctl-timer.c
@@ -45,7 +45,7 @@ STATIC int TimerNext (sd_event_source* source, uint64_t timer, void* handle) {
return 0;
}
else {
- // otherwise validate timer for a new run
+ // otherwise validate timer for a new run
sd_event_now(afb_daemon_get_event_loop(), CLOCK_MONOTONIC, &usec);
sd_event_source_set_enabled(source, SD_EVENT_ONESHOT);
sd_event_source_set_time(source, usec + timerHandle->delay*1000);
@@ -53,12 +53,12 @@ STATIC int TimerNext (sd_event_source* source, uint64_t timer, void* handle) {
done= timerHandle->callback(timerHandle->context);
if (!done) goto OnErrorExit;
-
+
return 0;
OnErrorExit:
AFB_WARNING("TimerNext Callback Fail Tag=%s", timerHandle->label);
- return -1;
+ return -1;
}
PUBLIC void TimerEvtStop(TimerHandleT *timerHandle) {
@@ -70,12 +70,12 @@ PUBLIC void TimerEvtStop(TimerHandleT *timerHandle) {
PUBLIC void TimerEvtStart(TimerHandleT *timerHandle, timerCallbackT callback, void *context) {
uint64_t usec;
-
+
// populate CB handle
timerHandle->callback=callback;
timerHandle->context=context;
-
- // set a timer with ~250us accuracy
+
+ // set a timer with ~250us accuracy
sd_event_now(afb_daemon_get_event_loop(), CLOCK_MONOTONIC, &usec);
sd_event_add_time(afb_daemon_get_event_loop(), &timerHandle->evtSource, CLOCK_MONOTONIC, usec+timerHandle->delay*1000, 250, TimerNext, timerHandle);
}
@@ -87,15 +87,15 @@ PUBLIC afb_event TimerEvtGet(void) {
// Create Binding Event at Init
PUBLIC int TimerEvtInit () {
-
+
// create binder event to send test pause/resume
afbevt = afb_daemon_make_event("control");
if (!afb_event_is_valid(afbevt)) {
AFB_ERROR ("POLCTL_INIT: Cannot register ctl-events");
return 1;
}
-
+
AFB_DEBUG ("Audio Control-Events Init Done");
return 0;
}
-
+