Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
1e6d7ea1
提交
1e6d7ea1
authored
5月 07, 2013
作者:
Raymond Chandler
提交者:
Anthony Minessale
5月 24, 2013
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-4871 --resolve
上级
22076b7b
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
89 行增加
和
35 行删除
+89
-35
switch_xml.c
src/switch_xml.c
+89
-35
没有找到文件。
src/switch_xml.c
浏览文件 @
1e6d7ea1
...
@@ -26,6 +26,7 @@
...
@@ -26,6 +26,7 @@
* Anthony Minessale II <anthm@freeswitch.org>
* Anthony Minessale II <anthm@freeswitch.org>
* Simon Capper <skyjunky@sbcglobal.net>
* Simon Capper <skyjunky@sbcglobal.net>
* Marc Olivier Chouinard <mochouinard@moctel.com>
* Marc Olivier Chouinard <mochouinard@moctel.com>
* Raymond Chandler <intralanman@freeswitch.org>
*
*
* switch_xml.c -- XML PARSER
* switch_xml.c -- XML PARSER
*
*
...
@@ -150,6 +151,7 @@ static switch_xml_open_root_function_t XML_OPEN_ROOT_FUNCTION = (switch_xml_open
...
@@ -150,6 +151,7 @@ static switch_xml_open_root_function_t XML_OPEN_ROOT_FUNCTION = (switch_xml_open
static
void
*
XML_OPEN_ROOT_FUNCTION_USER_DATA
=
NULL
;
static
void
*
XML_OPEN_ROOT_FUNCTION_USER_DATA
=
NULL
;
static
switch_hash_t
*
CACHE_HASH
=
NULL
;
static
switch_hash_t
*
CACHE_HASH
=
NULL
;
static
switch_hash_t
*
CACHE_EXPIRES_HASH
=
NULL
;
struct
xml_section_t
{
struct
xml_section_t
{
const
char
*
name
;
const
char
*
name
;
...
@@ -1897,6 +1899,9 @@ SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char
...
@@ -1897,6 +1899,9 @@ SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char
if
((
lookup
=
switch_core_hash_find
(
CACHE_HASH
,
mega_key
)))
{
if
((
lookup
=
switch_core_hash_find
(
CACHE_HASH
,
mega_key
)))
{
switch_core_hash_delete
(
CACHE_HASH
,
mega_key
);
switch_core_hash_delete
(
CACHE_HASH
,
mega_key
);
if
((
lookup
=
switch_core_hash_find
(
CACHE_EXPIRES_HASH
,
mega_key
)))
{
switch_core_hash_delete
(
CACHE_EXPIRES_HASH
,
mega_key
);
}
switch_xml_free
(
lookup
);
switch_xml_free
(
lookup
);
r
++
;
r
++
;
}
}
...
@@ -1909,6 +1914,12 @@ SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char
...
@@ -1909,6 +1914,12 @@ SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char
switch_core_hash_delete
(
CACHE_HASH
,
var
);
switch_core_hash_delete
(
CACHE_HASH
,
var
);
r
++
;
r
++
;
}
}
while
((
hi
=
switch_hash_first
(
NULL
,
CACHE_EXPIRES_HASH
)))
{
switch_hash_this
(
hi
,
&
var
,
NULL
,
&
val
);
switch_safe_free
(
val
);
switch_core_hash_delete
(
CACHE_EXPIRES_HASH
,
var
);
}
}
}
switch_mutex_unlock
(
CACHE_MUTEX
);
switch_mutex_unlock
(
CACHE_MUTEX
);
...
@@ -1920,33 +1931,61 @@ SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char
...
@@ -1920,33 +1931,61 @@ SWITCH_DECLARE(uint32_t) switch_xml_clear_user_cache(const char *key, const char
static
switch_status_t
switch_xml_locate_user_cache
(
const
char
*
key
,
const
char
*
user_name
,
const
char
*
domain_name
,
switch_xml_t
*
user
)
static
switch_status_t
switch_xml_locate_user_cache
(
const
char
*
key
,
const
char
*
user_name
,
const
char
*
domain_name
,
switch_xml_t
*
user
)
{
{
char
mega_key
[
1024
];
char
mega_key
[
1024
];
switch_xml_t
lookup
;
switch_status_t
status
=
SWITCH_STATUS_FALSE
;
switch_status_t
status
=
SWITCH_STATUS_FALSE
;
switch_xml_t
lookup
;
switch_snprintf
(
mega_key
,
sizeof
(
mega_key
),
"%s%s%s"
,
key
,
user_name
,
domain_name
);
switch_snprintf
(
mega_key
,
sizeof
(
mega_key
),
"%s%s%s"
,
key
,
user_name
,
domain_name
);
switch_mutex_lock
(
CACHE_MUTEX
);
switch_mutex_lock
(
CACHE_MUTEX
);
if
((
lookup
=
switch_core_hash_find
(
CACHE_HASH
,
mega_key
)))
{
if
((
lookup
=
switch_core_hash_find
(
CACHE_HASH
,
mega_key
)))
{
char
*
expires_lookup
=
NULL
;
if
((
expires_lookup
=
switch_core_hash_find
(
CACHE_EXPIRES_HASH
,
mega_key
)))
{
switch_time_t
time_expires
=
0
;
switch_time_t
time_now
=
0
;
time_now
=
switch_micro_time_now
();
time_expires
=
atol
(
expires_lookup
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Cache Info
\n
Time Now:
\t
%ld
\n
Expires:
\t
%ld
\n
"
,
time_now
,
time_expires
);
if
(
time_expires
<
time_now
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Cache expired for %s@%s, doing fresh lookup
\n
"
,
user_name
,
domain_name
);
}
else
{
*
user
=
switch_xml_dup
(
lookup
);
*
user
=
switch_xml_dup
(
lookup
);
status
=
SWITCH_STATUS_SUCCESS
;
status
=
SWITCH_STATUS_SUCCESS
;
}
}
}
else
{
*
user
=
switch_xml_dup
(
lookup
);
status
=
SWITCH_STATUS_SUCCESS
;
}
}
switch_mutex_unlock
(
CACHE_MUTEX
);
switch_mutex_unlock
(
CACHE_MUTEX
);
return
status
;
return
status
;
}
}
static
void
switch_xml_user_cache
(
const
char
*
key
,
const
char
*
user_name
,
const
char
*
domain_name
,
switch_xml_t
user
)
static
void
switch_xml_user_cache
(
const
char
*
key
,
const
char
*
user_name
,
const
char
*
domain_name
,
switch_xml_t
user
,
switch_time_t
expires
)
{
{
char
mega_key
[
1024
];
char
mega_key
[
1024
];
switch_xml_t
lookup
;
switch_xml_t
lookup
;
char
*
expires_lookup
;
switch_snprintf
(
mega_key
,
sizeof
(
mega_key
),
"%s%s%s"
,
key
,
user_name
,
domain_name
);
switch_snprintf
(
mega_key
,
sizeof
(
mega_key
),
"%s%s%s"
,
key
,
user_name
,
domain_name
);
switch_mutex_lock
(
CACHE_MUTEX
);
switch_mutex_lock
(
CACHE_MUTEX
);
if
((
lookup
=
switch_core_hash_find
(
CACHE_HASH
,
mega_key
)))
{
if
((
lookup
=
switch_core_hash_find
(
CACHE_HASH
,
mega_key
)))
{
switch_core_hash_delete
(
CACHE_HASH
,
mega_key
);
switch_core_hash_delete
(
CACHE_HASH
,
mega_key
);
switch_xml_free
(
lookup
);
switch_xml_free
(
lookup
);
}
}
if
((
expires_lookup
=
switch_core_hash_find
(
CACHE_EXPIRES_HASH
,
mega_key
)))
{
switch_core_hash_delete
(
CACHE_EXPIRES_HASH
,
mega_key
);
switch_safe_free
(
expires_lookup
);
}
if
(
expires
)
{
char
*
expires_val
=
malloc
(
1024
);
if
(
sprintf
(
expires_val
,
"%ld"
,
expires
))
{
switch_core_hash_insert
(
CACHE_EXPIRES_HASH
,
mega_key
,
expires_val
);
}
}
switch_core_hash_insert
(
CACHE_HASH
,
mega_key
,
switch_xml_dup
(
user
));
switch_core_hash_insert
(
CACHE_HASH
,
mega_key
,
switch_xml_dup
(
user
));
switch_mutex_unlock
(
CACHE_MUTEX
);
switch_mutex_unlock
(
CACHE_MUTEX
);
}
}
...
@@ -1960,10 +1999,24 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_merged(const char *key, c
...
@@ -1960,10 +1999,24 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate_user_merged(const char *key, c
if
((
status
=
switch_xml_locate_user_cache
(
key
,
user_name
,
domain_name
,
&
x_user
))
==
SWITCH_STATUS_SUCCESS
)
{
if
((
status
=
switch_xml_locate_user_cache
(
key
,
user_name
,
domain_name
,
&
x_user
))
==
SWITCH_STATUS_SUCCESS
)
{
*
user
=
x_user
;
*
user
=
x_user
;
}
else
if
((
status
=
switch_xml_locate_user
(
key
,
user_name
,
domain_name
,
ip
,
&
xml
,
&
domain
,
&
x_user
,
&
group
,
params
))
==
SWITCH_STATUS_SUCCESS
)
{
}
else
if
((
status
=
switch_xml_locate_user
(
key
,
user_name
,
domain_name
,
ip
,
&
xml
,
&
domain
,
&
x_user
,
&
group
,
params
))
==
SWITCH_STATUS_SUCCESS
)
{
const
char
*
cacheable
=
NULL
;
x_user_dup
=
switch_xml_dup
(
x_user
);
x_user_dup
=
switch_xml_dup
(
x_user
);
switch_xml_merge_user
(
x_user_dup
,
domain
,
group
);
switch_xml_merge_user
(
x_user_dup
,
domain
,
group
);
if
(
switch_true
(
switch_xml_attr
(
x_user_dup
,
"cacheable"
)))
{
switch_xml_user_cache
(
key
,
user_name
,
domain_name
,
x_user_dup
);
cacheable
=
switch_xml_attr
(
x_user_dup
,
"cacheable"
);
if
(
switch_true
(
cacheable
))
{
switch_time_t
expires
=
0
;
switch_time_t
time_now
=
0
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"caching lookup for user %s@%s
\n
"
,
user_name
,
domain_name
);
if
(
switch_is_number
(
cacheable
))
{
int
cache_ms
=
atol
(
cacheable
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"caching lookup for %d milliseconds
\n
"
,
cache_ms
);
time_now
=
switch_micro_time_now
();
expires
=
time_now
+
(
cache_ms
*
1000
);
}
switch_xml_user_cache
(
key
,
user_name
,
domain_name
,
x_user_dup
,
expires
);
}
}
*
user
=
x_user_dup
;
*
user
=
x_user_dup
;
switch_xml_free
(
xml
);
switch_xml_free
(
xml
);
...
@@ -2225,6 +2278,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_init(switch_memory_pool_t *pool, cons
...
@@ -2225,6 +2278,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_init(switch_memory_pool_t *pool, cons
switch_mutex_init
(
&
FILE_LOCK
,
SWITCH_MUTEX_NESTED
,
XML_MEMORY_POOL
);
switch_mutex_init
(
&
FILE_LOCK
,
SWITCH_MUTEX_NESTED
,
XML_MEMORY_POOL
);
switch_mutex_init
(
&
XML_GEN_LOCK
,
SWITCH_MUTEX_NESTED
,
XML_MEMORY_POOL
);
switch_mutex_init
(
&
XML_GEN_LOCK
,
SWITCH_MUTEX_NESTED
,
XML_MEMORY_POOL
);
switch_core_hash_init
(
&
CACHE_HASH
,
XML_MEMORY_POOL
);
switch_core_hash_init
(
&
CACHE_HASH
,
XML_MEMORY_POOL
);
switch_core_hash_init
(
&
CACHE_EXPIRES_HASH
,
XML_MEMORY_POOL
);
switch_thread_rwlock_create
(
&
B_RWLOCK
,
XML_MEMORY_POOL
);
switch_thread_rwlock_create
(
&
B_RWLOCK
,
XML_MEMORY_POOL
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论