Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
1965b3b1
提交
1965b3b1
authored
12月 30, 2014
作者:
Brian West
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-7106 #resolve Fix concurrency issue
上级
bf5210bf
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
22 行删除
+30
-22
mod_httapi.c
src/mod/applications/mod_httapi/mod_httapi.c
+30
-22
没有找到文件。
src/mod/applications/mod_httapi/mod_httapi.c
浏览文件 @
1965b3b1
...
...
@@ -149,6 +149,8 @@ static struct {
hash_node_t
*
hash_root
;
hash_node_t
*
hash_tail
;
switch_hash_t
*
profile_hash
;
switch_hash_t
*
request_hash
;
switch_mutex_t
*
request_mutex
;
switch_hash_t
*
parse_hash
;
char
cache_path
[
128
];
int
debug
;
...
...
@@ -170,7 +172,6 @@ struct http_file_context {
char
*
cache_file
;
char
*
cache_file_base
;
char
*
meta_file
;
char
*
lock_file
;
char
*
metadata
;
time_t
expires
;
switch_file_t
*
lock_fd
;
...
...
@@ -192,6 +193,8 @@ struct http_file_context {
char
*
name
;
char
uuid_str
[
SWITCH_UUID_FORMATTED_LENGTH
+
1
];
}
write
;
switch_mutex_t
*
mutex
;
};
typedef
struct
http_file_context
http_file_context_t
;
...
...
@@ -2381,7 +2384,6 @@ static char *load_cache_data(http_file_context_t *context, const char *url)
context
->
cache_file_base
=
switch_core_sprintf
(
context
->
pool
,
"%s%s%s"
,
globals
.
cache_path
,
SWITCH_PATH_SEPARATOR
,
digest
);
context
->
meta_file
=
switch_core_sprintf
(
context
->
pool
,
"%s%s%s.meta"
,
globals
.
cache_path
,
SWITCH_PATH_SEPARATOR
,
digest
);
context
->
lock_file
=
switch_core_sprintf
(
context
->
pool
,
"%s%s%s.lock"
,
globals
.
cache_path
,
SWITCH_PATH_SEPARATOR
,
digest
);
if
(
switch_file_exists
(
context
->
meta_file
,
context
->
pool
)
==
SWITCH_STATUS_SUCCESS
&&
((
fd
=
open
(
context
->
meta_file
,
O_RDONLY
,
0
))
>
-
1
))
{
if
((
bytes
=
read
(
fd
,
meta_buffer
,
sizeof
(
meta_buffer
)))
>
0
)
{
...
...
@@ -2703,27 +2705,29 @@ static switch_status_t lock_file(http_file_context_t *context, switch_bool_t loc
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
http_file_context_t
*
xcontext
=
NULL
;
if
(
lock
)
{
if
(
switch_file_open
(
&
context
->
lock_fd
,
context
->
lock_file
,
SWITCH_FOPEN_WRITE
|
SWITCH_FOPEN_CREATE
|
SWITCH_FOPEN_TRUNCATE
,
SWITCH_FPROT_UREAD
|
SWITCH_FPROT_UWRITE
,
context
->
pool
)
!=
SWITCH_STATUS_SUCCESS
)
{
return
SWITCH_STATUS_FALSE
;
switch_mutex_lock
(
globals
.
request_mutex
);
if
(
!
(
xcontext
=
switch_core_hash_find
(
globals
.
request_hash
,
context
->
dest_url
)))
{
switch_core_hash_insert
(
globals
.
request_hash
,
context
->
dest_url
,
context
);
xcontext
=
context
;
}
switch_mutex_lock
(
context
->
mutex
);
switch_mutex_unlock
(
globals
.
request_mutex
);
if
(
switch_file_lock
(
context
->
lock_fd
,
SWITCH_FLOCK_EXCLUSIVE
)
!=
SWITCH_STATUS_SUCCESS
)
{
return
SWITCH_STATUS_FALSE
;
if
(
context
!=
xcontext
)
{
switch_mutex_lock
(
xcontext
->
mutex
);
switch_mutex_unlock
(
xcontext
->
mutex
)
;
}
}
else
{
if
(
context
->
lock_fd
){
switch_file_close
(
context
->
lock_fd
);
s
tatus
=
SWITCH_STATUS_SUCCESS
;
switch_mutex_lock
(
globals
.
request_mutex
);
if
((
xcontext
=
switch_core_hash_find
(
globals
.
request_hash
,
context
->
dest_url
))
&&
xcontext
==
context
)
{
s
witch_core_hash_delete
(
globals
.
request_hash
,
context
->
dest_url
)
;
}
unlink
(
context
->
lock_file
);
switch_mutex_unlock
(
context
->
mutex
);
switch_mutex_unlock
(
globals
.
request_mutex
);
}
return
status
;
...
...
@@ -2745,8 +2749,6 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
return
SWITCH_STATUS_SUCCESS
;
}
lock_file
(
context
,
SWITCH_TRUE
);
if
(
context
->
url_params
)
{
ext
=
switch_event_get_header
(
context
->
url_params
,
"ext"
);
}
...
...
@@ -2837,8 +2839,6 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char
unlink
(
context
->
cache_file
);
}
lock_file
(
context
,
SWITCH_FALSE
);
switch_event_destroy
(
&
headers
);
return
status
;
...
...
@@ -2875,6 +2875,7 @@ static switch_status_t file_open(switch_file_handle_t *handle, const char *path,
context
=
switch_core_alloc
(
handle
->
memory_pool
,
sizeof
(
*
context
));
context
->
pool
=
handle
->
memory_pool
;
switch_mutex_init
(
&
context
->
mutex
,
SWITCH_MUTEX_NESTED
,
handle
->
memory_pool
);
pdup
=
switch_core_strdup
(
context
->
pool
,
pa
);
...
...
@@ -2953,10 +2954,14 @@ static switch_status_t file_open(switch_file_handle_t *handle, const char *path,
context
->
read
.
ext
=
switch_event_get_header
(
context
->
url_params
,
"ext"
);
}
lock_file
(
context
,
SWITCH_TRUE
);
if
((
status
=
locate_url_file
(
context
,
context
->
dest_url
))
!=
SWITCH_STATUS_SUCCESS
)
{
return
status
;
}
lock_file
(
context
,
SWITCH_FALSE
);
if
((
status
=
switch_core_file_open
(
&
context
->
fh
,
context
->
cache_file
,
handle
->
channels
,
...
...
@@ -2965,7 +2970,6 @@ static switch_status_t file_open(switch_file_handle_t *handle, const char *path,
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"Invalid cache file %s opening url %s Discarding file.
\n
"
,
context
->
cache_file
,
path
);
unlink
(
context
->
cache_file
);
unlink
(
context
->
meta_file
);
unlink
(
context
->
lock_file
);
return
status
;
}
}
...
...
@@ -3001,6 +3005,9 @@ static switch_status_t http_file_file_close(switch_file_handle_t *handle)
{
http_file_context_t
*
context
=
handle
->
private_info
;
switch_mutex_lock
(
context
->
mutex
);
switch_mutex_unlock
(
context
->
mutex
);
if
(
switch_test_flag
((
&
context
->
fh
),
SWITCH_FILE_OPEN
))
{
switch_core_file_close
(
&
context
->
fh
);
}
...
...
@@ -3041,7 +3048,6 @@ static switch_status_t http_file_file_close(switch_file_handle_t *handle)
if
(
context
->
cache_file
)
{
unlink
(
context
->
cache_file
);
unlink
(
context
->
meta_file
);
unlink
(
context
->
lock_file
);
}
}
...
...
@@ -3105,6 +3111,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_httapi_load)
globals
.
cache_ttl
=
300
;
globals
.
not_found_expires
=
300
;
switch_mutex_init
(
&
globals
.
request_mutex
,
SWITCH_MUTEX_NESTED
,
pool
);
http_file_supported_formats
[
0
]
=
"http"
;
...
...
@@ -3133,6 +3140,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_httapi_load)
switch_core_hash_init
(
&
globals
.
profile_hash
);
switch_core_hash_init
(
&
globals
.
request_hash
);
switch_core_hash_init_case
(
&
globals
.
parse_hash
,
SWITCH_FALSE
);
bind_parser
(
"execute"
,
parse_execute
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论