aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt70
-rw-r--r--Controller-afb/CMakeLists.txt21
-rw-r--r--ctl-apidef.h30
-rw-r--r--ctl-apidef.json24
-rw-r--r--ctl-lua.c19
5 files changed, 43 insertions, 121 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
deleted file mode 100644
index e62a0e8..0000000
--- a/CMakeLists.txt
+++ /dev/null
@@ -1,70 +0,0 @@
-###########################################################################
-# Copyright 2015, 2016, 2017 IoT.bzh
-#
-# author: Fulup Ar Foll <fulup@iot.bzh>
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-###########################################################################
-
-# Include LUA only when requested
-if(CONTROL_SUPPORT_LUA)
- message(STATUS "Notice: LUA Controler Support Selected")
- set(CTL_LUA_SOURCE ctl-lua.c)
- ADD_COMPILE_OPTIONS(-DCONTROL_SUPPORT_LUA)
- ADD_COMPILE_OPTIONS(-DCONTROL_LUA_EVENT="luaevt")
- ADD_COMPILE_OPTIONS(-DCONTROL_LUA_PATH="${CMAKE_SOURCE_DIR}/conf.d/project/lua.d:${CMAKE_INSTALL_PREFIX}/controller-plugins/ctl-lua.d")
-else(CONTROL_SUPPORT_LUA)
- message(STATUS "Warning: LUA Without Support ")
-endif(CONTROL_SUPPORT_LUA)
-
-# Add target to project dependency list
-PROJECT_TARGET_ADD(control-afb)
-
- # Define project Targets
- ADD_LIBRARY(${TARGET_NAME} MODULE ctl-binding.c ctl-timer.c ctl-dispatch.c ${CTL_LUA_SOURCE} filescan-utils.c wrap-json.c)
-
- SET_OPENAPI_FILENAME("ctl-apidef")
- # Binder exposes a unique public entry point
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- PREFIX "afb-"
- LABELS "BINDINGV2"
- LINK_FLAGS ${BINDINGS_LINK_FLAG}
- OUTPUT_NAME ${TARGET_NAME}
- )
-
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- ${link_libraries}
- )
-
-
-PROJECT_TARGET_ADD(audio-plugin-sample)
-
- # Define targets
- ADD_LIBRARY(${TARGET_NAME} MODULE ctl-plugin-sample.c)
-
- # Alsa Plugin properties
- SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
- PREFIX ${CTL_PLUGIN_PRE}
- SUFFIX ${CTL_PLUGIN_EXT}
- OUTPUT_NAME ${TARGET_NAME}
- )
-
- # Library dependencies (include updates automatically)
- TARGET_LINK_LIBRARIES(${TARGET_NAME}
- ${link_libraries}
- )
-
- # installation directory
- INSTALL(TARGETS ${TARGET_NAME}
- LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/controler-plugins)
diff --git a/Controller-afb/CMakeLists.txt b/Controller-afb/CMakeLists.txt
new file mode 100644
index 0000000..22adb2a
--- /dev/null
+++ b/Controller-afb/CMakeLists.txt
@@ -0,0 +1,21 @@
+###########################################################################
+# Copyright 2015, 2016, 2017 IoT.bzh
+#
+# author: Fulup Ar Foll <rfulup@iot.bzh>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+###########################################################################
+CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
+
+# Do not change this file, config is located into conf.d
+include(${CMAKE_CURRENT_SOURCE_DIR}/conf.d/cmake/config.cmake)
diff --git a/ctl-apidef.h b/ctl-apidef.h
index 100fc79..9ce9e05 100644
--- a/ctl-apidef.h
+++ b/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/ctl-apidef.json b/ctl-apidef.json
index f292eec..e2207d0 100644
--- a/ctl-apidef.json
+++ b/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/ctl-lua.c b/ctl-lua.c
index 412a158..2aaa3a5 100644
--- a/ctl-lua.c
+++ b/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);
}