Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
7036c9b8
提交
7036c9b8
authored
7月 19, 2010
作者:
Mathieu Rene
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mod_hash: add api function
上级
90f33b83
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
89 行增加
和
3 行删除
+89
-3
mod_hash.c
src/mod/applications/mod_hash/mod_hash.c
+89
-3
没有找到文件。
src/mod/applications/mod_hash/mod_hash.c
浏览文件 @
7036c9b8
...
@@ -80,6 +80,18 @@ typedef enum {
...
@@ -80,6 +80,18 @@ typedef enum {
REMOTE_UP
/* < All good */
REMOTE_UP
/* < All good */
}
limit_remote_state_t
;
}
limit_remote_state_t
;
static
inline
const
char
*
state_str
(
limit_remote_state_t
state
)
{
switch
(
state
)
{
case
REMOTE_OFF
:
return
"Off"
;
case
REMOTE_DOWN
:
return
"Down"
;
case
REMOTE_UP
:
return
"Up"
;
}
return
""
;
}
typedef
struct
{
typedef
struct
{
const
char
*
name
;
const
char
*
name
;
const
char
*
host
;
const
char
*
host
;
...
@@ -102,6 +114,9 @@ typedef struct {
...
@@ -102,6 +114,9 @@ typedef struct {
}
limit_remote_t
;
}
limit_remote_t
;
static
limit_hash_item_t
get_remote_usage
(
const
char
*
key
);
static
limit_hash_item_t
get_remote_usage
(
const
char
*
key
);
void
limit_remote_destroy
(
limit_remote_t
**
r
);
static
void
do_config
(
switch_bool_t
reload
);
/* \brief Enforces limit_hash restrictions
/* \brief Enforces limit_hash restrictions
* \param session current session
* \param session current session
...
@@ -550,6 +565,66 @@ SWITCH_STANDARD_API(hash_dump_function)
...
@@ -550,6 +565,66 @@ SWITCH_STANDARD_API(hash_dump_function)
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
}
}
#define HASH_REMOTE_SYNTAX "list|kill [name]|rescan"
SWITCH_STANDARD_API
(
hash_remote_function
)
{
int
argc
;
char
*
argv
[
10
];
char
*
dup
=
NULL
;
if
(
!
zstr
(
cmd
))
{
dup
=
strdup
(
cmd
);
}
argc
=
switch_split
(
dup
,
' '
,
argv
);
if
(
argv
[
0
]
&&
!
strcmp
(
argv
[
0
],
"list"
))
{
switch_hash_index_t
*
hi
;
stream
->
write_function
(
stream
,
"Remote connections:
\n
Name
\t
State
\n
"
);
switch_thread_rwlock_rdlock
(
globals
.
remote_hash_rwlock
);
for
(
hi
=
switch_hash_first
(
NULL
,
globals
.
remote_hash
);
hi
;
hi
=
switch_hash_next
(
hi
))
{
void
*
val
;
const
void
*
key
;
switch_ssize_t
keylen
;
limit_remote_t
*
item
;
switch_hash_this
(
hi
,
&
key
,
&
keylen
,
&
val
);
item
=
(
limit_remote_t
*
)
val
;
stream
->
write_function
(
stream
,
"%s
\t
%s
\n
"
,
item
->
name
,
state_str
(
item
->
state
));
}
switch_thread_rwlock_unlock
(
globals
.
remote_hash_rwlock
);
stream
->
write_function
(
stream
,
"+OK
\n
"
);
}
else
if
(
argv
[
0
]
&&
!
strcmp
(
argv
[
0
],
"kill"
))
{
const
char
*
name
=
argv
[
1
];
limit_remote_t
*
remote
;
if
(
zstr
(
name
))
{
stream
->
write_function
(
stream
,
"-ERR "
HASH_REMOTE_SYNTAX
"
\n
"
);
goto
done
;
}
switch_thread_rwlock_rdlock
(
globals
.
remote_hash_rwlock
);
remote
=
switch_core_hash_find
(
globals
.
remote_hash
,
name
);
switch_thread_rwlock_unlock
(
globals
.
remote_hash_rwlock
);
limit_remote_destroy
(
&
remote
);
switch_thread_rwlock_wrlock
(
globals
.
remote_hash_rwlock
);
switch_core_hash_delete
(
globals
.
remote_hash
,
name
);
switch_thread_rwlock_unlock
(
globals
.
remote_hash_rwlock
);
stream
->
write_function
(
stream
,
"+OK
\n
"
);
}
else
if
(
argv
[
0
]
&&
!
strcmp
(
argv
[
0
],
"rescan"
))
{
do_config
(
SWITCH_TRUE
);
stream
->
write_function
(
stream
,
"+OK
\n
"
);
}
done
:
if
(
dup
)
{
free
(
dup
);
}
return
SWITCH_STATUS_SUCCESS
;
}
limit_remote_t
*
limit_remote_create
(
const
char
*
name
,
const
char
*
host
,
uint16_t
port
,
const
char
*
username
,
const
char
*
password
,
int
interval
)
limit_remote_t
*
limit_remote_create
(
const
char
*
name
,
const
char
*
host
,
uint16_t
port
,
const
char
*
username
,
const
char
*
password
,
int
interval
)
{
{
limit_remote_t
*
r
;
limit_remote_t
*
r
;
...
@@ -594,7 +669,8 @@ void limit_remote_destroy(limit_remote_t **r)
...
@@ -594,7 +669,8 @@ void limit_remote_destroy(limit_remote_t **r)
(
*
r
)
->
state
=
REMOTE_OFF
;
(
*
r
)
->
state
=
REMOTE_OFF
;
if
((
*
r
)
->
thread
)
{
if
((
*
r
)
->
thread
)
{
switch_thread_join
(
NULL
,
(
*
r
)
->
thread
);
switch_status_t
retval
;
switch_thread_join
(
&
retval
,
(
*
r
)
->
thread
);
}
}
switch_thread_rwlock_wrlock
((
*
r
)
->
rwlock
);
switch_thread_rwlock_wrlock
((
*
r
)
->
rwlock
);
...
@@ -737,7 +813,7 @@ static void *SWITCH_THREAD_FUNC limit_remote_thread(switch_thread_t *thread, voi
...
@@ -737,7 +813,7 @@ static void *SWITCH_THREAD_FUNC limit_remote_thread(switch_thread_t *thread, voi
return
NULL
;
return
NULL
;
}
}
static
void
do_config
()
static
void
do_config
(
switch_bool_t
reload
)
{
{
switch_xml_t
xml
=
NULL
,
x_lists
=
NULL
,
x_list
=
NULL
,
cfg
=
NULL
;
switch_xml_t
xml
=
NULL
,
x_lists
=
NULL
,
x_list
=
NULL
,
cfg
=
NULL
;
if
((
xml
=
switch_xml_open_cfg
(
"hash.conf"
,
&
cfg
,
NULL
)))
{
if
((
xml
=
switch_xml_open_cfg
(
"hash.conf"
,
&
cfg
,
NULL
)))
{
...
@@ -752,6 +828,15 @@ static void do_config()
...
@@ -752,6 +828,15 @@ static void do_config()
int
port
=
0
,
interval
=
0
;
int
port
=
0
,
interval
=
0
;
limit_remote_t
*
remote
;
limit_remote_t
*
remote
;
switch_threadattr_t
*
thd_attr
=
NULL
;
switch_threadattr_t
*
thd_attr
=
NULL
;
if
(
reload
)
{
switch_thread_rwlock_rdlock
(
globals
.
remote_hash_rwlock
);
if
(
switch_core_hash_find
(
globals
.
remote_hash
,
name
))
{
switch_thread_rwlock_unlock
(
globals
.
remote_hash_rwlock
);
continue
;
}
switch_thread_rwlock_unlock
(
globals
.
remote_hash_rwlock
);
}
if
(
!
zstr
(
szport
))
{
if
(
!
zstr
(
szport
))
{
port
=
atoi
(
szport
);
port
=
atoi
(
szport
);
...
@@ -811,12 +896,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_hash_load)
...
@@ -811,12 +896,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_hash_load)
SWITCH_ADD_APP
(
app_interface
,
"hash"
,
"Insert into the hashtable"
,
HASH_DESC
,
hash_function
,
HASH_USAGE
,
SAF_SUPPORT_NOMEDIA
)
SWITCH_ADD_APP
(
app_interface
,
"hash"
,
"Insert into the hashtable"
,
HASH_DESC
,
hash_function
,
HASH_USAGE
,
SAF_SUPPORT_NOMEDIA
)
SWITCH_ADD_API
(
commands_api_interface
,
"hash"
,
"hash get/set"
,
hash_api_function
,
"[insert|delete|select]/<realm>/<key>/<value>"
);
SWITCH_ADD_API
(
commands_api_interface
,
"hash"
,
"hash get/set"
,
hash_api_function
,
"[insert|delete|select]/<realm>/<key>/<value>"
);
SWITCH_ADD_API
(
commands_api_interface
,
"hash_dump"
,
"dump hash/limit_hash data (used for synchronization)"
,
hash_dump_function
,
HASH_DUMP_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"hash_dump"
,
"dump hash/limit_hash data (used for synchronization)"
,
hash_dump_function
,
HASH_DUMP_SYNTAX
);
SWITCH_ADD_API
(
commands_api_interface
,
"hash_remote"
,
"hash remote"
,
hash_remote_function
,
HASH_REMOTE_SYNTAX
);
switch_console_set_complete
(
"add hash insert"
);
switch_console_set_complete
(
"add hash insert"
);
switch_console_set_complete
(
"add hash delete"
);
switch_console_set_complete
(
"add hash delete"
);
switch_console_set_complete
(
"add hash select"
);
switch_console_set_complete
(
"add hash select"
);
do_config
();
do_config
(
SWITCH_FALSE
);
/* indicate that the module should continue to be loaded */
/* indicate that the module should continue to be loaded */
return
SWITCH_STATUS_SUCCESS
;
return
SWITCH_STATUS_SUCCESS
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论