Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
21534d46
提交
21534d46
authored
7月 11, 2008
作者:
Brian West
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add api
git-svn-id:
http://svn.freeswitch.org/svn/freeswitch/trunk@8999
d0543943-73ff-0310-b7d9-9358b9ac24b2
上级
a3ccefa7
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
62 行增加
和
40 行删除
+62
-40
mod_python.c
src/mod/languages/mod_python/mod_python.c
+62
-38
mod_python_extra.c
src/mod/languages/mod_python/mod_python_extra.c
+0
-2
没有找到文件。
src/mod/languages/mod_python/mod_python.c
浏览文件 @
21534d46
...
@@ -54,7 +54,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load);
...
@@ -54,7 +54,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_python_shutdown
);
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_python_shutdown
);
SWITCH_MODULE_DEFINITION
(
mod_python
,
mod_python_load
,
mod_python_shutdown
,
NULL
);
SWITCH_MODULE_DEFINITION
(
mod_python
,
mod_python_load
,
mod_python_shutdown
,
NULL
);
static
void
eval_some_python
(
char
*
uuid
,
char
*
args
,
switch_core_session_t
*
session
)
static
void
eval_some_python
(
char
*
args
,
switch_core_session_t
*
session
,
switch_stream_handle_t
*
stream
)
{
{
PyThreadState
*
tstate
=
NULL
;
PyThreadState
*
tstate
=
NULL
;
char
*
dupargs
=
NULL
;
char
*
dupargs
=
NULL
;
...
@@ -62,10 +62,11 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
...
@@ -62,10 +62,11 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
int
argc
;
int
argc
;
int
lead
=
0
;
int
lead
=
0
;
char
*
script
=
NULL
;
char
*
script
=
NULL
;
PyObject
*
module
=
NULL
,
*
sp
=
NULL
;
PyObject
*
module
=
NULL
,
*
sp
=
NULL
,
*
stp
=
NULL
,
*
eve
=
NULL
;
PyObject
*
function
=
NULL
;
PyObject
*
function
=
NULL
;
PyObject
*
arg
=
NULL
;
PyObject
*
arg
=
NULL
;
PyObject
*
result
=
NULL
;
PyObject
*
result
=
NULL
;
char
*
uuid
=
NULL
;
if
(
args
)
{
if
(
args
)
{
dupargs
=
strdup
(
args
);
dupargs
=
strdup
(
args
);
...
@@ -93,6 +94,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
...
@@ -93,6 +94,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
// swap in thread state
// swap in thread state
PyEval_AcquireThread
(
tstate
);
PyEval_AcquireThread
(
tstate
);
if
(
session
)
{
if
(
session
)
{
uuid
=
switch_core_session_get_uuid
(
session
);
// record the fact that thread state is swapped in
// record the fact that thread state is swapped in
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
switch_channel_t
*
channel
=
switch_core_session_get_channel
(
session
);
switch_channel_set_private
(
channel
,
"SwapInThreadState"
,
NULL
);
switch_channel_set_private
(
channel
,
"SwapInThreadState"
,
NULL
);
...
@@ -115,6 +117,17 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
...
@@ -115,6 +117,17 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
PyErr_Clear
();
PyErr_Clear
();
goto
done_swap_out
;
goto
done_swap_out
;
}
}
if
(
stream
)
{
printf
(
"doh
\n\n\n
"
);
stp
=
mod_python_conjure_stream
(
module
,
stream
,
"stream"
);
if
(
stream
->
param_event
)
{
eve
=
mod_python_conjure_event
(
module
,
stream
->
param_event
,
"env"
);
}
}
// get the handler function to be called
// get the handler function to be called
function
=
PyObject_GetAttrString
(
module
,
"handler"
);
function
=
PyObject_GetAttrString
(
module
,
"handler"
);
if
(
!
function
)
{
if
(
!
function
)
{
...
@@ -162,14 +175,15 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
...
@@ -162,14 +175,15 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
Py_XDECREF
(
sp
);
Py_XDECREF
(
sp
);
}
}
done_swap_out:
if
(
stp
)
{
Py_XDECREF
(
stp
);
}
if
(
eve
)
{
Py_XDECREF
(
eve
);
}
// decrement ref counts
done_swap_out:
Py_XDECREF
(
module
);
Py_XDECREF
(
function
);
Py_XDECREF
(
arg
);
Py_XDECREF
(
result
);
// swap out thread state
// swap out thread state
if
(
session
)
{
if
(
session
)
{
...
@@ -199,6 +213,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
...
@@ -199,6 +213,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
PyEval_ReleaseThread
(
tstate
);
PyEval_ReleaseThread
(
tstate
);
}
}
switch_safe_free
(
dupargs
);
switch_safe_free
(
dupargs
);
...
@@ -206,7 +221,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
...
@@ -206,7 +221,7 @@ static void eval_some_python(char *uuid, char *args, switch_core_session_t *sess
SWITCH_STANDARD_APP
(
python_function
)
SWITCH_STANDARD_APP
(
python_function
)
{
{
eval_some_python
(
switch_core_session_get_uuid
(
session
),
(
char
*
)
data
,
session
);
eval_some_python
(
(
char
*
)
data
,
session
,
NULL
);
}
}
...
@@ -220,7 +235,7 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
...
@@ -220,7 +235,7 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
switch_memory_pool_t
*
pool
;
switch_memory_pool_t
*
pool
;
struct
switch_py_thread
*
pt
=
(
struct
switch_py_thread
*
)
obj
;
struct
switch_py_thread
*
pt
=
(
struct
switch_py_thread
*
)
obj
;
eval_some_python
(
NULL
,
strdup
(
pt
->
args
)
,
NULL
);
eval_some_python
(
pt
->
args
,
NULL
,
NULL
);
pool
=
pt
->
pool
;
pool
=
pt
->
pool
;
switch_core_destroy_memory_pool
(
&
pool
);
switch_core_destroy_memory_pool
(
&
pool
);
...
@@ -228,6 +243,14 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
...
@@ -228,6 +243,14 @@ static void *SWITCH_THREAD_FUNC py_thread_run(switch_thread_t *thread, void *obj
return
NULL
;
return
NULL
;
}
}
SWITCH_STANDARD_API
(
api_python
)
{
eval_some_python
((
char
*
)
cmd
,
session
,
stream
);
return
SWITCH_STATUS_SUCCESS
;
}
SWITCH_STANDARD_API
(
launch_python
)
SWITCH_STANDARD_API
(
launch_python
)
{
{
switch_thread_t
*
thread
;
switch_thread_t
*
thread
;
...
@@ -288,7 +311,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load)
...
@@ -288,7 +311,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_python_load)
/* connect my internal structure to the blank pointer passed to me */
/* connect my internal structure to the blank pointer passed to me */
*
module_interface
=
switch_loadable_module_create_module_interface
(
pool
,
modname
);
*
module_interface
=
switch_loadable_module_create_module_interface
(
pool
,
modname
);
SWITCH_ADD_API
(
api_interface
,
"python"
,
"run a python script"
,
launch_python
,
"python </path/to/script>"
);
SWITCH_ADD_API
(
api_interface
,
"pyrun"
,
"run a python script"
,
launch_python
,
"python </path/to/script>"
);
SWITCH_ADD_API
(
api_interface
,
"python"
,
"run a python script"
,
api_python
,
"python </path/to/script>"
);
SWITCH_ADD_APP
(
app_interface
,
"python"
,
"Launch python ivr"
,
"Run a python ivr on a channel"
,
python_function
,
"<script> [additional_vars [...]]"
,
SWITCH_ADD_APP
(
app_interface
,
"python"
,
"Launch python ivr"
,
"Run a python ivr on a channel"
,
python_function
,
"<script> [additional_vars [...]]"
,
SAF_SUPPORT_NOMEDIA
);
SAF_SUPPORT_NOMEDIA
);
...
...
src/mod/languages/mod_python/mod_python_extra.c
浏览文件 @
21534d46
...
@@ -8,7 +8,6 @@ PyObject *mod_python_conjure_event(PyObject *module, switch_event_t *event, cons
...
@@ -8,7 +8,6 @@ PyObject *mod_python_conjure_event(PyObject *module, switch_event_t *event, cons
obj
=
SWIG_NewPointerObj
(
SWIG_as_voidptr
(
result
),
SWIGTYPE_p_Event
,
SWIG_POINTER_OWN
);
obj
=
SWIG_NewPointerObj
(
SWIG_as_voidptr
(
result
),
SWIGTYPE_p_Event
,
SWIG_POINTER_OWN
);
if
(
module
&&
name
)
{
if
(
module
&&
name
)
{
PyDict_SetItem
(
PyModule_GetDict
(
module
),
Py_BuildValue
(
"s"
,
name
),
obj
);
PyDict_SetItem
(
PyModule_GetDict
(
module
),
Py_BuildValue
(
"s"
,
name
),
obj
);
Py_DECREF
(
obj
);
}
}
return
obj
;
return
obj
;
...
@@ -24,7 +23,6 @@ PyObject *mod_python_conjure_stream(PyObject *module, switch_stream_handle_t *st
...
@@ -24,7 +23,6 @@ PyObject *mod_python_conjure_stream(PyObject *module, switch_stream_handle_t *st
if
(
module
&&
name
)
{
if
(
module
&&
name
)
{
PyDict_SetItem
(
PyModule_GetDict
(
module
),
Py_BuildValue
(
"s"
,
name
),
obj
);
PyDict_SetItem
(
PyModule_GetDict
(
module
),
Py_BuildValue
(
"s"
,
name
),
obj
);
Py_DECREF
(
obj
);
}
}
return
obj
;
return
obj
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论