Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
eb329ad5
提交
eb329ad5
authored
7月 10, 2013
作者:
Ken Rice
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-5524 --resolve
上级
be98eb34
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
51 行增加
和
1 行删除
+51
-1
lua.conf.xml
conf/vanilla/autoload_configs/lua.conf.xml
+2
-0
mod_lua.cpp
src/mod/languages/mod_lua/mod_lua.cpp
+49
-1
没有找到文件。
conf/vanilla/autoload_configs/lua.conf.xml
浏览文件 @
eb329ad5
...
...
@@ -26,5 +26,7 @@
-->
<!--<param name="startup-script" value="startup_script_1.lua"/>-->
<!--<param name="startup-script" value="startup_script_2.lua"/>-->
<!--<hook event="CUSTOM" subclass="conference::maintenance" script="catch-event.lua"/>-->
</settings>
</configuration>
src/mod/languages/mod_lua/mod_lua.cpp
浏览文件 @
eb329ad5
...
...
@@ -32,6 +32,7 @@
#include <switch.h>
#include <switch_event.h>
SWITCH_BEGIN_EXTERN_C
#include "lua.h"
#include <lauxlib.h>
...
...
@@ -44,6 +45,7 @@ SWITCH_MODULE_DEFINITION_EX(mod_lua, mod_lua_load, mod_lua_shutdown, NULL, SMODF
static
struct
{
switch_memory_pool_t
*
pool
;
char
*
xml_handler
;
switch_event_node_t
*
node
;
}
globals
;
int
luaopen_freeswitch
(
lua_State
*
L
);
...
...
@@ -287,10 +289,12 @@ static switch_xml_t lua_fetch(const char *section,
}
static
void
lua_event_handler
(
switch_event_t
*
event
);
static
switch_status_t
do_config
(
void
)
{
const
char
*
cf
=
"lua.conf"
;
switch_xml_t
cfg
,
xml
,
settings
,
param
;
switch_xml_t
cfg
,
xml
,
settings
,
param
,
hook
;
switch_stream_handle_t
path_stream
=
{
0
};
switch_stream_handle_t
cpath_stream
=
{
0
};
...
...
@@ -327,6 +331,31 @@ static switch_status_t do_config(void)
path_stream
.
write_function
(
&
path_stream
,
"%s"
,
val
);
}
}
for
(
hook
=
switch_xml_child
(
settings
,
"hook"
);
hook
;
hook
=
hook
->
next
)
{
char
*
event
=
(
char
*
)
switch_xml_attr_soft
(
hook
,
"event"
);
char
*
subclass
=
(
char
*
)
switch_xml_attr_soft
(
hook
,
"subclass"
);
//char *script = strdup( (char *) switch_xml_attr_soft(hook, "script"));
char
*
script
=
(
char
*
)
switch_xml_attr_soft
(
hook
,
"script"
);
switch_event_types_t
evtype
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"hook params: '%s' | '%s' | '%s'
\n
"
,
event
,
subclass
,
script
);
if
(
switch_name_event
(
event
,
&
evtype
)
==
SWITCH_STATUS_SUCCESS
)
{
if
(
!
zstr
(
script
))
{
if
(
switch_event_bind_removable
(
modname
,
evtype
,
!
zstr
(
subclass
)
?
subclass
:
SWITCH_EVENT_SUBCLASS_ANY
,
lua_event_handler
,
script
,
&
globals
.
node
)
==
SWITCH_STATUS_SUCCESS
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"event handler for '%s' set to '%s'
\n
"
,
switch_event_name
(
evtype
),
script
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set event handler: unsuccessful bind
\n
"
);
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set event handler: no script name
\n
"
,
event
);
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"cannot set event handler: unknown event type '%s'
\n
"
,
event
);
}
}
}
if
(
cpath_stream
.
data_len
)
{
...
...
@@ -405,6 +434,23 @@ int lua_thread(const char *text)
return
0
;
}
static
void
lua_event_handler
(
switch_event_t
*
event
)
{
lua_State
*
L
=
lua_init
();
char
*
script
=
NULL
;
if
(
event
->
bind_user_data
)
{
script
=
strdup
((
char
*
)
event
->
bind_user_data
);
}
mod_lua_conjure_event
(
L
,
event
,
"event"
,
1
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"lua event hook: execute '%s'
\n
"
,
(
char
*
)
script
);
lua_parse_and_execute
(
L
,
(
char
*
)
script
);
lua_uninit
(
L
);
switch_safe_free
(
script
);
}
SWITCH_STANDARD_APP
(
lua_function
)
{
lua_State
*
L
=
lua_init
();
...
...
@@ -645,6 +691,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_lua_load)
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_lua_shutdown
)
{
switch_event_unbind
(
&
globals
.
node
);
return
SWITCH_STATUS_SUCCESS
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论