提交 4b86fb08 authored 作者: Leon de Rooij's avatar Leon de Rooij

See if I can call a LUA script directly as dialplan

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk/contrib@15316 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 4c4be95a
Index: mod_lua.cpp
===================================================================
--- mod_lua.cpp (revision 15305)
+++ mod_lua.cpp (working copy)
@@ -461,10 +461,55 @@
return SWITCH_STATUS_SUCCESS;
}
+SWITCH_STANDARD_DIALPLAN(lua_dialplan_hunt)
+{
+ lua_State *L = lua_init();
+ switch_caller_extension_t *extension = NULL;
+ switch_channel_t *channel = switch_core_session_get_channel(session);
+ char *cmd;
+ switch_stream_handle_t stream = { 0 };
+ SWITCH_STANDARD_STREAM(stream);
+
+ if (!caller_profile) {
+ if (!(caller_profile = switch_channel_get_caller_profile(channel))) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Error Obtaining Profile!\n");
+ goto done;
+ }
+ }
+
+ if (!caller_profile->context) {
+ caller_profile->context = "lua/dialplan.lua";
+ }
+
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Processing %s->%s in script %s\n",
+ caller_profile->caller_id_name, caller_profile->destination_number, caller_profile->context);
+
+ if ((extension = switch_caller_extension_new(session, "_anon_", caller_profile->destination_number)) == 0) {
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_CRIT, "Memory Error!\n");
+ goto done;
+ }
+
+ cmd = strdup(caller_profile->context);
+ switch_assert(cmd);
+
+ mod_lua_conjure_session(L, session, "session", 1);
+ mod_lua_conjure_stream(L, &stream, "stream", 1);
+
+ lua_parse_and_execute(L, cmd); // TODO is it possible to call switch_caller_extension_add_application(session, *extension, application, app_data) from the script ?
+ lua_uninit(L);
+ free(cmd);
+
+ // loop through everything returned by stream:write and add it to 'switch_caller_extension_add_application'
+
+ done:
+ return extension;
+}
+
SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
{
switch_api_interface_t *api_interface;
switch_application_interface_t *app_interface;
+ switch_dialplan_interface_t *dp_interface;
/* connect my internal structure to the blank pointer passed to me */
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -472,6 +517,7 @@
SWITCH_ADD_API(api_interface, "luarun", "run a script", luarun_api_function, "<script>");
SWITCH_ADD_API(api_interface, "lua", "run a script as an api function", lua_api_function, "<script>");
SWITCH_ADD_APP(app_interface, "lua", "Launch LUA ivr", "Run a lua ivr on a channel", lua_function, "<script>", SAF_SUPPORT_NOMEDIA);
+ SWITCH_ADD_DIALPLAN(dp_interface, "LUA", lua_dialplan_hunt);
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论