Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch-contrib
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch-contrib
Commits
3ed2cbca
提交
3ed2cbca
authored
4月 24, 2010
作者:
gled
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
quick answer add
上级
601e8fe7
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
99 行增加
和
71 行删除
+99
-71
mod_fgi.c
gled/mod_fgi/mod_fgi.c
+99
-71
没有找到文件。
gled/mod_fgi/mod_fgi.c
浏览文件 @
3ed2cbca
...
@@ -50,7 +50,97 @@ SWITCH_MODULE_DEFINITION(mod_fgi, mod_fgi_load, mod_fgi_shutdown, NULL);
...
@@ -50,7 +50,97 @@ SWITCH_MODULE_DEFINITION(mod_fgi, mod_fgi_load, mod_fgi_shutdown, NULL);
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(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
]);
static
void
parse_fgi_args
(
char
*
buf
,
int
*
argc
,
char
*
argv
[
_MAX_CMD_ARGS
])
{
char
*
cur
;
int
x
=
0
;
int
quote
=
0
;
int
escaped
=
0
;
int
space
=
1
;
cur
=
buf
;
while
(
*
buf
)
{
switch
(
*
buf
)
{
case
'"'
:
if
(
escaped
)
goto
ok
;
else
quote
=
!
quote
;
if
(
quote
&&
space
)
{
argv
[
x
++
]
=
cur
;
space
=
0
;
}
escaped
=
0
;
break
;
case
' '
:
case
'\t'
:
if
(
!
quote
&&
!
escaped
)
{
space
=
1
;
*
(
cur
++
)
=
'\0'
;
}
else
goto
ok
;
break
;
case
'\\'
:
if
(
escaped
)
goto
ok
;
else
escaped
=
1
;
break
;
default:
ok:
if
(
space
)
{
argv
[
x
++
]
=
cur
;
space
=
0
;
}
*
(
cur
++
)
=
*
buf
;
escaped
=
0
;
}
buf
++
;
}
*
(
cur
++
)
=
'\0'
;
argv
[
x
]
=
NULL
;
*
argc
=
x
;
return
;
}
static
switch_status_t
find_and_exec_command
(
char
*
cmd
,
int
fd_reply
,
switch_core_session_t
*
session
)
{
char
*
argv
[
1024
];
int
argc
,
x
,
y
=
0
;
char
*
buf
=
NULL
;
parse_fgi_args
(
cmd
,
&
argc
,
argv
);
/*
TODO
Here we can do things :)
- First find cmd, then call cmd with args and return result on fd_reply formatted... easy no ?
*/
for
(
x
=
0
;
x
<
argc
;
x
++
)
{
if
(
!
strcasecmp
(
argv
[
x
],
"ANSWER"
)
)
{
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
y
=
switch_channel_answer
(
channel
);
buf
=
malloc
(
20
*
sizeof
(
char
));
sprintf
(
buf
,
"200 result=%d
\n\n
"
,
y
);
write
(
fd_reply
,
buf
,
strlen
(
buf
));
free
(
buf
);
}
else
if
(
!
strcasecmp
(
argv
[
x
],
"HANGUP"
))
{
}
else
if
(
!
strcasecmp
(
argv
[
x
],
"EXEC"
))
{
}
else
if
(
!
strcasecmp
(
argv
[
x
],
"STREAM"
)
&&
!
strcasecmp
(
argv
[
x
+
1
],
"FILE"
))
{
}
else
if
(
!
strcasecmp
(
argv
[
x
],
"SET"
)
&&
!
strcasecmp
(
argv
[
x
+
1
],
"CALLERID"
))
{
}
else
if
(
!
strcasecmp
(
argv
[
x
],
"GET"
)
&&
!
strcasecmp
(
argv
[
x
+
1
],
"DATA"
))
{
}
}
return
SWITCH_STATUS_SUCCESS
;
}
pid_t
fgi_open_process
(
const
char
*
cmd
,
int
*
in
,
int
*
out
,
int
*
thread_running
)
{
pid_t
fgi_open_process
(
const
char
*
cmd
,
int
*
in
,
int
*
out
,
int
*
thread_running
)
{
int
p_in
[
2
],
p_out
[
2
];
int
p_in
[
2
],
p_out
[
2
];
...
@@ -100,22 +190,14 @@ pid_t fgi_open_process( const char *cmd, int *in, int *out,int *thread_running)
...
@@ -100,22 +190,14 @@ pid_t fgi_open_process( const char *cmd, int *in, int *out,int *thread_running)
return
pid
;
return
pid
;
}
}
static
switch_status_t
find_and_exec_command
(
char
*
cmd
,
int
fd_reply
)
{
static
switch_status_t
exec_fgi_run
(
char
*
argv
,
switch_core_session_t
*
session
)
{
char
*
argv
[
1024
];
int
argc
=
0
;
parse_fgi_args
(
cmd
,
&
argc
,
argv
);
/* */
return
SWITCH_STATUS_SUCCESS
;
}
static
switch_status_t
exec_fgi_run
(
char
*
argv
)
{
int
in
,
out
;
int
in
,
out
;
pid_t
pid
;
pid_t
pid
;
int
res
=
0
;
int
res
=
0
;
int
nfds
=
0
;
int
nfds
=
0
;
fd_set
rd
;
int
thread_running
;
int
thread_running
;
fd_set
rd
;
char
cmdbuf
[
_MAX_CMD_ARGS
*
128
];
char
cmdbuf
[
_MAX_CMD_ARGS
*
128
];
pid
=
fgi_open_process
(
argv
,
&
in
,
&
out
,
&
thread_running
);
pid
=
fgi_open_process
(
argv
,
&
in
,
&
out
,
&
thread_running
);
...
@@ -126,7 +208,6 @@ static switch_status_t exec_fgi_run(char *argv) {
...
@@ -126,7 +208,6 @@ static switch_status_t exec_fgi_run(char *argv) {
FD_ZERO
(
&
rd
);
FD_ZERO
(
&
rd
);
FD_SET
(
in
,
&
rd
);
FD_SET
(
in
,
&
rd
);
nfds
=
MAX
(
nfds
,
out
);
nfds
=
MAX
(
nfds
,
out
);
res
=
select
(
nfds
+
1
,
&
rd
,
NULL
,
NULL
,
NULL
);
res
=
select
(
nfds
+
1
,
&
rd
,
NULL
,
NULL
,
NULL
);
if
(
res
==
-
1
)
if
(
res
==
-
1
)
break
;
break
;
...
@@ -135,7 +216,7 @@ static switch_status_t exec_fgi_run(char *argv) {
...
@@ -135,7 +216,7 @@ static switch_status_t exec_fgi_run(char *argv) {
if
(
res
<
0
)
if
(
res
<
0
)
goto
end
;
goto
end
;
else
{
else
{
if
(
find_and_exec_command
((
char
*
)
&
cmdbuf
,
in
)
!=
SWITCH_STATUS_SUCCESS
)
if
(
find_and_exec_command
((
char
*
)
&
cmdbuf
,
in
,
session
)
!=
SWITCH_STATUS_SUCCESS
)
goto
end
;
goto
end
;
}
}
}
}
...
@@ -162,7 +243,7 @@ SWITCH_STANDARD_APP(launch_fgi_thread) {
...
@@ -162,7 +243,7 @@ SWITCH_STANDARD_APP(launch_fgi_thread) {
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"INVALID ARGS!
\n
"
);
switch_log_printf
(
SWITCH_CHANNEL_SESSION_LOG
(
session
),
SWITCH_LOG_ERROR
,
"INVALID ARGS!
\n
"
);
return
;
return
;
}
}
exec_fgi_run
(
mydata
);
exec_fgi_run
(
mydata
,
session
);
/* Free up things ? */
/* Free up things ? */
}
}
...
@@ -186,56 +267,3 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fgi_shutdown) {
...
@@ -186,56 +267,3 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_fgi_shutdown) {
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
static
void
parse_fgi_args
(
char
*
buf
,
int
*
argc
,
char
*
argv
[
_MAX_CMD_ARGS
])
{
char
*
cur
;
int
x
=
0
;
int
quote
=
0
;
int
escaped
=
0
;
int
space
=
1
;
cur
=
buf
;
while
(
*
buf
)
{
switch
(
*
buf
)
{
case
'"'
:
if
(
escaped
)
goto
ok
;
else
quote
=
!
quote
;
if
(
quote
&&
space
)
{
argv
[
x
++
]
=
cur
;
space
=
0
;
}
escaped
=
0
;
break
;
case
' '
:
case
'\t'
:
if
(
!
quote
&&
!
escaped
)
{
space
=
1
;
*
(
cur
++
)
=
'\0'
;
}
else
goto
ok
;
break
;
case
'\\'
:
if
(
escaped
)
goto
ok
;
else
escaped
=
1
;
break
;
default
:
ok
:
if
(
space
)
{
argv
[
x
++
]
=
cur
;
space
=
0
;
}
*
(
cur
++
)
=
*
buf
;
escaped
=
0
;
}
buf
++
;
}
*
(
cur
++
)
=
'\0'
;
argv
[
x
]
=
NULL
;
*
argc
=
x
;
return
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论