Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch-contrib
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch-contrib
Commits
601e8fe7
提交
601e8fe7
authored
4月 24, 2010
作者:
gled
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
woops
上级
dd789b67
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
35 行删除
+29
-35
Makefile
gled/mod_fgi/Makefile
+2
-2
mod_fgi.c
gled/mod_fgi/mod_fgi.c
+27
-33
没有找到文件。
gled/mod_fgi/Makefile
浏览文件 @
601e8fe7
BASE
=
../../../..
include
$(BASE)/build/modmake.rules
\ No newline at end of file
BASE
=
../../..
include
$(BASE)/build/modmake.rules
gled/mod_fgi/mod_fgi.c
浏览文件 @
601e8fe7
...
...
@@ -45,11 +45,13 @@ SWITCH_MODULE_DEFINITION(mod_fgi, mod_fgi_load, mod_fgi_shutdown, NULL);
#define FG_READ 0
#define FG_WRITE 1
#define _MAX_CMD_ARGS 128
static
void
parse_args
(
char
*
buf
,
int
*
argc
,
char
*
argv
[
_MAX_CMD_ARGS
]);
pid_t
fgi_open_process
(
const
char
*
cmd
,
int
*
in
,
int
*
out
);
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
static
void
parse_fgi_args
(
char
*
buf
,
int
*
argc
,
char
*
argv
[
_MAX_CMD_ARGS
]);
pid_t
fgi_open_process
(
const
char
*
cmd
,
int
*
in
,
int
*
out
,
int
*
thread_running
)
{
int
p_in
[
2
],
p_out
[
2
];
pid_t
pid
;
...
...
@@ -101,45 +103,39 @@ pid_t fgi_open_process( const char *cmd, int *in, int *out,int *thread_running)
static
switch_status_t
find_and_exec_command
(
char
*
cmd
,
int
fd_reply
)
{
char
*
argv
[
1024
];
int
argc
=
0
;
int
r
=
-
1
;
command_binding_t
*
bind
;
pargc
=
parse_fgi_args
(
cmd
,
argv
);
bind
=
find_binding
(
argv
);
if
(
bind
)
{
r
=
bind
->
handler
(
eslC
,
fd
,
&
argc
,
argv
);
}
return
r
;
parse_fgi_args
(
cmd
,
&
argc
,
argv
);
/* */
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
exec_fgi_run
()
{
static
switch_status_t
exec_fgi_run
(
char
*
argv
)
{
int
in
,
out
;
pid_t
pid
;
int
res
,
nfds
;
int
res
=
0
;
int
nfds
=
0
;
fd_set
rd
;
char
cmd_buf
[
2048
];
int
thread_running
;
char
cmdbuf
[
_MAX_CMD_ARGS
*
128
];
pid
=
fgi_open_process
(
cmd
,
&
in
,
&
out
,
&
thread_running
);
pid
=
fgi_open_process
(
argv
,
&
in
,
&
out
,
&
thread_running
);
if
(
pid
<=
0
)
return
SWITCH_STATUS_
FAIL
;
return
SWITCH_STATUS_
SUCCESS
;
while
(
thread_running
)
{
FD_ZERO
(
&
rd
);
FD_SET
(
in
,
&
rd
);
nfds
=
MAX
(
nfds
,
pipes
.
script
[
0
]
);
nfds
=
MAX
(
nfds
,
out
);
res
=
select
(
nfds
+
1
,
&
rd
,
NULL
,
NULL
,
NULL
);
if
(
r
==
-
1
)
if
(
r
es
==
-
1
)
break
;
else
if
(
FD_ISSET
(
out
,
&
rd
)
)
{
/* They have something to say
r = read(out,&cmdbuf,2047);
if (r<0)
else
if
(
FD_ISSET
(
out
,
&
rd
)
)
{
/* They have something to say
*/
r
es
=
read
(
out
,
&
cmdbuf
,
2047
);
if
(
r
es
<
0
)
goto
end
;
else
{
if ( find_and_exec_command(
char *) &cmdbuf,reply_fd
) != SWITCH_STATUS_SUCCESS )
if
(
find_and_exec_command
(
(
char
*
)
&
cmdbuf
,
in
)
!=
SWITCH_STATUS_SUCCESS
)
goto
end
;
}
}
...
...
@@ -155,7 +151,7 @@ SWITCH_STANDARD_APP(launch_fgi_thread) {
char
*
argv
[
6
]
=
{
0
};
int
argc
;
char
*
mydata
=
NULL
;
switch_channel_t *channel = switch_core_session_get_channel(session);
//
switch_channel_t *channel = switch_core_session_get_channel(session);
if
(
zstr
(
data
)
||
!
(
mydata
=
switch_core_session_strdup
(
session
,
data
)))
{
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"INVALID ARGS!
\n
"
);
...
...
@@ -166,20 +162,18 @@ SWITCH_STANDARD_APP(launch_fgi_thread) {
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"INVALID ARGS!
\n
"
);
return
;
}
exec_fgi_run(
argc,argv
);
return SWITCH_STATUS_SUCCESS;
exec_fgi_run
(
mydata
);
/* Free up things ? */
}
SWITCH_MODULE_LOAD_FUNCTION
(
mod_fgi_load
)
{
switch_app_interface_t *app_interface;
switch_application_interface_t
*
app_interface
;
/* connect my internal structure to the blank pointer passed to me */
*
module_interface
=
switch_loadable_module_create_module_interface
(
pool
,
modname
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Hello World!
\n
"
);
do_config
(
SWITCH_FALSE
);
SWITCH_ADD_APP
(
app_interface
,
"fgi"
,
"Freeswitch Gateway Interface"
,
launch_fgi_thread
,
"fgi path_to_executable args"
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_NOTICE
,
"Hello !
\n
"
);
SWITCH_ADD_APP
(
app_interface
,
"fgi"
,
"Fgi"
,
"launch and give control to an external entity with STDIN/STDOUT"
,
launch_fgi_thread
,
"fgi <path_to_executable> [<args>]"
,
SAF_NONE
);
/* indicate that the module should continue to be loaded */
return
SWITCH_STATUS_SUCCESS
;
...
...
@@ -193,7 +187,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fgi_shutdown) {
}
static
void
parse_args
(
char
*
buf
,
int
*
argc
,
char
*
argv
[
_MAX_CMD_ARGS
])
{
static
void
parse_
fgi_
args
(
char
*
buf
,
int
*
argc
,
char
*
argv
[
_MAX_CMD_ARGS
])
{
char
*
cur
;
int
x
=
0
;
int
quote
=
0
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论