diff options
author | Fulup Ar Foll <fulup@iot.bzh> | 2017-08-22 13:58:57 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-08-22 14:26:25 +0200 |
commit | 4a1abc060f6f68ab28b16baf1832a2edb1a4af1b (patch) | |
tree | d715ccab4653aec68dfe502397a0edb7f4e1f80d /Controller-afb/ctl-lua.c | |
parent | 9d6ad02739d0accf22634f73c72a1dce6ec92763 (diff) |
Minor Fix on LUA script search path
Diffstat (limited to 'Controller-afb/ctl-lua.c')
-rw-r--r-- | Controller-afb/ctl-lua.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/Controller-afb/ctl-lua.c b/Controller-afb/ctl-lua.c index 412a158..2aaa3a5 100644 --- a/Controller-afb/ctl-lua.c +++ b/Controller-afb/ctl-lua.c @@ -698,24 +698,29 @@ STATIC void LuaDoAction (LuaDoActionT action, afb_req request) { } case LUA_DOSCRIPT: { // Fulup need to fix argument passing - const char *script; - char*func=NULL; char *filename; char*fullpath; char luaScriptPath[CONTROL_MAXPATH_LEN]; - json_object *argsJ=NULL; int index; // scan luascript search path once static json_object *luaScriptPathJ =NULL; - err= wrap_json_unpack (queryJ, "{s:s, s?s s?o !}", "target", &script,"function", &func, "args", &argsJ); + // extract value from query + const char *target=NULL,*func=NULL; + json_object *argsJ=NULL; + err= wrap_json_unpack (queryJ, "{s:s,s?s,s?s,s?o !}","target", &target,"path",&luaScriptPathJ,"function",&func,"args",&argsJ); if (err) { - AFB_ERROR ("LUA-DOSCRIPT-SYNTAX:missing script|(args,arg) query=%s", json_object_get_string(queryJ)); + AFB_ERROR ("LUA-DOSCRIPT-SYNTAX:missing target|[path]|[function]|[args] query=%s", json_object_get_string(queryJ)); goto OnErrorExit; } // search for filename=script in CONTROL_LUA_PATH - if (!luaScriptPathJ) luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,CONTROL_DOSCRIPT_PRE "-", script); + if (!luaScriptPathJ) { + strncpy(luaScriptPath,CONTROL_DOSCRIPT_PRE, sizeof(luaScriptPath)); + strncat(luaScriptPath,"-", sizeof(luaScriptPath)); + strncat(luaScriptPath,target, sizeof(luaScriptPath)); + luaScriptPathJ= ScanForConfig(CONTROL_LUA_PATH , CTL_SCAN_RECURSIVE,luaScriptPath,".lua"); + } for (index=0; index < json_object_array_length(luaScriptPathJ); index++) { json_object *entryJ=json_object_array_get_idx(luaScriptPathJ, index); @@ -801,7 +806,7 @@ PUBLIC void ctlapi_request (afb_req request) { LuaDoAction (LUA_DOCALL, request); } -PUBLIC void ctlapi_scriptlua (afb_req request) { +PUBLIC void ctlapi_debuglua (afb_req request) { LuaDoAction (LUA_DOSCRIPT, request); } |