Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
93c05d9c
提交
93c05d9c
authored
2月 28, 2014
作者:
Brian West
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-4502 --resolve
上级
5b26558e
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
114 行增加
和
0 行删除
+114
-0
mod_snom.c
src/mod/applications/mod_snom/mod_snom.c
+114
-0
没有找到文件。
src/mod/applications/mod_snom/mod_snom.c
浏览文件 @
93c05d9c
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
*
*
*/
*/
#include <switch.h>
#include <switch.h>
#include <switch_curl.h>
SWITCH_MODULE_LOAD_FUNCTION
(
mod_snom_load
);
SWITCH_MODULE_LOAD_FUNCTION
(
mod_snom_load
);
SWITCH_MODULE_DEFINITION
(
mod_snom
,
mod_snom_load
,
NULL
,
NULL
);
SWITCH_MODULE_DEFINITION
(
mod_snom
,
mod_snom_load
,
NULL
,
NULL
);
...
@@ -104,6 +105,118 @@ SWITCH_STANDARD_API(snom_bind_key_api_function)
...
@@ -104,6 +105,118 @@ SWITCH_STANDARD_API(snom_bind_key_api_function)
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
static
size_t
curl_callback
(
void
*
ptr
,
size_t
size
,
size_t
nmemb
,
void
*
data
)
{
register
unsigned
int
realsize
=
(
unsigned
int
)
(
size
*
nmemb
);
return
realsize
;
}
#define COMMAND_SYNTAX "<ip|user> <command> <type> <username> <password>"
SWITCH_STANDARD_API
(
snom_command_api_function
)
{
int
argc
;
long
httpRes
=
0
;
char
*
url
=
NULL
;
char
*
argv
[
5
]
=
{
0
};
char
*
argdata
=
NULL
;
char
*
userpwd
=
NULL
;
char
*
apiresp
=
NULL
;
ip_t
ip
;
switch_CURL
*
curl_handle
=
NULL
;
if
(
zstr
(
cmd
)
||
!
(
argdata
=
strdup
(
cmd
)))
{
goto
end
;
}
argc
=
switch_separate_string
(
argdata
,
' '
,
argv
,
(
sizeof
(
argv
)
/
sizeof
(
argv
[
0
])));
if
(
argc
<
3
||
(
argc
>
3
&&
argc
<
5
))
{
stream
->
write_function
(
stream
,
"-ERR %s
\n
"
,
COMMAND_SYNTAX
);
goto
end
;
}
if
(
strcasecmp
(
argv
[
1
],
"key"
))
{
stream
->
write_function
(
stream
,
"-ERR only KEY command allowed at the moment
\n
"
);
goto
end
;
}
if
(
switch_inet_pton
(
AF_INET
,
argv
[
0
],
&
ip
))
{
url
=
switch_mprintf
(
"http://%s/command.htm?%s=%s"
,
argv
[
0
],
argv
[
1
],
argv
[
2
]);
}
else
{
char
*
sql
=
NULL
;
char
buf
[
32
];
char
*
ret
=
NULL
;
switch_cache_db_handle_t
*
db
=
NULL
;
switch_stream_handle_t
apistream
=
{
0
};
switch_status_t
status
;
SWITCH_STANDARD_STREAM
(
apistream
);
if
((
status
=
switch_api_execute
(
"sofia_contact"
,
argv
[
0
],
NULL
,
&
apistream
))
!=
SWITCH_STATUS_SUCCESS
)
{
stream
->
write_function
(
stream
,
"-ERR error executing sofia_contact
\n
"
);
goto
end
;
}
apiresp
=
(
char
*
)
apistream
.
data
;
if
(
!
zstr
(
apiresp
))
{
if
(
!
strcasecmp
(
apistream
.
data
,
"error/user_not_registered"
))
{
stream
->
write_function
(
stream
,
"-ERR user '%s' not registered
\n
"
,
argv
[
0
]);
goto
end
;
}
}
else
{
goto
end
;
}
if
(
switch_core_db_handle
(
&
db
)
!=
SWITCH_STATUS_SUCCESS
)
{
stream
->
write_function
(
stream
,
"%s"
,
"-ERR Database Error!
\n
"
);
goto
end
;
}
sql
=
switch_mprintf
(
"select network_ip from registrations where url = '%s'"
,
apiresp
);
ret
=
switch_cache_db_execute_sql2str
(
db
,
sql
,
buf
,
sizeof
(
buf
),
NULL
);
switch_safe_free
(
sql
);
switch_cache_db_release_db_handle
(
&
db
);
if
(
!
ret
)
{
stream
->
write_function
(
stream
,
"%s"
,
"-ERR Query '%s' failed!
\n
"
,
sql
);
goto
end
;
}
url
=
switch_mprintf
(
"http://%s/command.htm?%s=%s"
,
buf
,
argv
[
1
],
argv
[
2
]);
}
curl_handle
=
curl_easy_init
();
curl_easy_setopt
(
curl_handle
,
CURLOPT_HTTPGET
,
1
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_WRITEFUNCTION
,
curl_callback
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_USERAGENT
,
"freeswitch-curl/1.0"
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_FOLLOWLOCATION
,
1
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_MAXREDIRS
,
15
);
if
(
argc
==
5
)
{
userpwd
=
switch_mprintf
(
"%s:%s"
,
argv
[
3
],
argv
[
4
]);
curl_easy_setopt
(
curl_handle
,
CURLOPT_HTTPAUTH
,
(
long
)
CURLAUTH_ANY
);
curl_easy_setopt
(
curl_handle
,
CURLOPT_USERPWD
,
userpwd
);
}
curl_easy_perform
(
curl_handle
);
curl_easy_getinfo
(
curl_handle
,
CURLINFO_RESPONSE_CODE
,
&
httpRes
);
curl_easy_cleanup
(
curl_handle
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"curl url %s , result %ld
\n
"
,
url
,
httpRes
);
if
(
httpRes
!=
200
)
stream
->
write_function
(
stream
,
"-ERR %s [HTTP:%ld]
\n
"
,
cmd
,
httpRes
);
else
stream
->
write_function
(
stream
,
"+OK %s
\n
"
,
cmd
);
end
:
switch_safe_free
(
apiresp
);
switch_safe_free
(
userpwd
);
switch_safe_free
(
argdata
);
switch_safe_free
(
url
);
return
SWITCH_STATUS_SUCCESS
;
}
SWITCH_MODULE_LOAD_FUNCTION
(
mod_snom_load
)
SWITCH_MODULE_LOAD_FUNCTION
(
mod_snom_load
)
{
{
...
@@ -116,6 +229,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_snom_load)
...
@@ -116,6 +229,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_snom_load)
SWITCH_ADD_API
(
commands_api_interface
,
"snom_bind_key"
,
"Bind a key"
,
snom_bind_key_api_function
,
KEY_BIND_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"snom_bind_key"
,
"Bind a key"
,
snom_bind_key_api_function
,
KEY_BIND_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"snom_url"
,
"url"
,
snom_url_api_function
,
URL_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"snom_url"
,
"url"
,
snom_url_api_function
,
URL_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"snom_command"
,
"Sends Command over HTTP Request"
,
snom_command_api_function
,
COMMAND_SYNTAX
);
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论