summaryrefslogtreecommitdiffstats
path: root/Controller-afb
diff options
context:
space:
mode:
Diffstat (limited to 'Controller-afb')
-rw-r--r--Controller-afb/ctl-apidef.h30
-rw-r--r--Controller-afb/ctl-apidef.json24
-rw-r--r--Controller-afb/ctl-lua.c19
3 files changed, 22 insertions, 51 deletions
diff --git a/Controller-afb/ctl-apidef.h b/Controller-afb/ctl-apidef.h
index 100fc79..9ce9e05 100644
--- a/Controller-afb/ctl-apidef.h
+++ b/Controller-afb/ctl-apidef.h
@@ -41,16 +41,12 @@ static const char _afb_description_v2_control[] =
"ons/navigation\"},\"parameters\":[{\"in\":\"query\",\"name\":\"func\",\""
"required\":true,\"schema\":{\"type\":\"string\"}},{\"in\":\"query\",\"na"
"me\":\"args\",\"required\":false,\"schema\":{\"type\":\"array\"}}],\"res"
- "ponses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\"/execlu"
- "a\":{\"description\":\"Execute LUA string script.\",\"get\":{\"x-permiss"
- "ions\":{\"$ref\":\"#/components/x-permissions/navigation\"},\"parameters"
- "\":[{\"in\":\"query\",\"required\":true,\"schema\":{\"type\":\"string\"}"
- "}],\"responses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\""
- "/scriptlua\":{\"description\":\"Execute LUA string script.\",\"get\":{\""
- "x-permissions\":{\"$ref\":\"#/components/x-permissions/navigation\"},\"p"
- "arameters\":[{\"in\":\"query\",\"name\":\"filename\",\"required\":true,\""
- "schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/co"
- "mponents/responses/200\"}}}}}}"
+ "ponses\":{\"200\":{\"$ref\":\"#/components/responses/200\"}}}},\"/debugl"
+ "ua\":{\"description\":\"Execute LUA string script.\",\"get\":{\"x-permis"
+ "sions\":{\"$ref\":\"#/components/x-permissions/navigation\"},\"parameter"
+ "s\":[{\"in\":\"query\",\"name\":\"filename\",\"required\":true,\"schema\""
+ ":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"$ref\":\"#/components"
+ "/responses/200\"}}}}}}"
;
static const struct afb_auth _afb_auths_v2_control[] = {
@@ -60,8 +56,7 @@ static const struct afb_auth _afb_auths_v2_control[] = {
void ctlapi_monitor(struct afb_req req);
void ctlapi_dispatch(struct afb_req req);
void ctlapi_request(struct afb_req req);
- void ctlapi_execlua(struct afb_req req);
- void ctlapi_scriptlua(struct afb_req req);
+ void ctlapi_debuglua(struct afb_req req);
static const struct afb_verb_v2 _afb_verbs_v2_control[] = {
{
@@ -86,15 +81,8 @@ static const struct afb_verb_v2 _afb_verbs_v2_control[] = {
.session = AFB_SESSION_NONE_V2
},
{
- .verb = "execlua",
- .callback = ctlapi_execlua,
- .auth = &_afb_auths_v2_control[0],
- .info = NULL,
- .session = AFB_SESSION_NONE_V2
- },
- {
- .verb = "scriptlua",
- .callback = ctlapi_scriptlua,
+ .verb = "debuglua",
+ .callback = ctlapi_debuglua,
.auth = &_afb_auths_v2_control[0],
.info = NULL,
.session = AFB_SESSION_NONE_V2
diff --git a/Controller-afb/ctl-apidef.json b/Controller-afb/ctl-apidef.json
index f292eec..e2207d0 100644
--- a/Controller-afb/ctl-apidef.json
+++ b/Controller-afb/ctl-apidef.json
@@ -201,29 +201,7 @@
}
}
},
- "/execlua": {
- "description": "Execute LUA string script.",
- "get": {
- "x-permissions": {
- "$ref": "#/components/x-permissions/navigation"
- },
- "parameters": [
- {
- "in": "query",
- "required": true,
- "schema": {
- "type": "string"
- }
- }
- ],
- "responses": {
- "200": {
- "$ref": "#/components/responses/200"
- }
- }
- }
- },
- "/scriptlua": {
+ "/debuglua": {
"description": "Execute LUA string script.",
"get": {
"x-permissions": {
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);
}