Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
dd6b8a82
提交
dd6b8a82
authored
8月 31, 2013
作者:
Chris Rienzo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mod_http_cache: added <domain> to <profile> configuration
上级
7012a1c4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
90 行增加
和
6 行删除
+90
-6
http_cache.conf.xml
.../mod_http_cache/conf/autoload_configs/http_cache.conf.xml
+6
-3
mod_http_cache.c
src/mod/applications/mod_http_cache/mod_http_cache.c
+84
-3
没有找到文件。
src/mod/applications/mod_http_cache/conf/autoload_configs/http_cache.conf.xml
浏览文件 @
dd6b8a82
...
...
@@ -12,15 +12,18 @@
<profiles>
<profile
name=
"s3"
>
<!-- Credentials for AWS account. Reference by name when sending HTTP request -->
<!-- http_get {profile=s3}http://bucket.s3.amazonaws.com/object.wav -->
<!-- http_put {profile=s3}http://bucket.s3.amazonaws.com/object.wav /tmp/file.wav -->
<!-- Credentials for AWS account. -->
<aws-s3>
<!-- 20 character key identifier -->
<access-key-id>
<![CDATA[AKIAIOSFODNN7EXAMPLE]]>
</access-key-id>
<!-- 40 character secret -->
<secret-access-key>
<![CDATA[wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY]]>
</secret-access-key>
</aws-s3>
<!-- Domains that this profile applies to -->
<domains>
<domain
name=
"bucket.s3.amazonaws.com"
/>
<domain
name=
"bucket2.s3.amazonaws.com"
/>
</domains>
</profile>
</profiles>
...
...
src/mod/applications/mod_http_cache/mod_http_cache.c
浏览文件 @
dd6b8a82
...
...
@@ -36,6 +36,9 @@
#include <switch_curl.h>
#include "aws.h"
/* 253 max domain size + '/' + NUL byte */
#define DOMAIN_BUF_SIZE 255
/* Defines module interface to FreeSWITCH */
SWITCH_MODULE_SHUTDOWN_FUNCTION
(
mod_http_cache_shutdown
);
SWITCH_MODULE_LOAD_FUNCTION
(
mod_http_cache_load
);
...
...
@@ -151,6 +154,8 @@ struct url_cache {
char
*
location
;
/** HTTP profiles */
switch_hash_t
*
profiles
;
/** profiles mapped by FQDN */
switch_hash_t
*
fqdn_profiles
;
/** Cache mapped by URL */
switch_hash_t
*
map
;
/** Cached URLs queued for replacement */
...
...
@@ -195,10 +200,41 @@ static void url_cache_lock(url_cache_t *cache, switch_core_session_t *session);
static
void
url_cache_unlock
(
url_cache_t
*
cache
,
switch_core_session_t
*
session
);
static
void
url_cache_clear
(
url_cache_t
*
cache
,
switch_core_session_t
*
session
);
static
http_profile_t
*
url_cache_http_profile_find
(
url_cache_t
*
cache
,
const
char
*
name
);
static
void
url_cache_http_profile_add
(
url_cache_t
*
cache
,
const
char
*
name
,
const
char
*
aws_s3_access_key_id
,
const
char
*
aws_s3_secret_access_key
);
static
http_profile_t
*
url_cache_http_profile_find_by_fqdn
(
url_cache_t
*
cache
,
const
char
*
url
);
static
http_profile_t
*
url_cache_http_profile_add
(
url_cache_t
*
cache
,
const
char
*
name
,
const
char
*
aws_s3_access_key_id
,
const
char
*
aws_s3_secret_access_key
);
static
switch_curl_slist_t
*
append_aws_s3_headers
(
switch_curl_slist_t
*
headers
,
http_profile_t
*
profile
,
const
char
*
verb
,
const
char
*
content_type
,
const
char
*
url
);
/**
* Parse FQDN from URL
*/
static
void
parse_domain
(
const
char
*
url
,
char
*
domain_buf
,
int
domain_buf_len
)
{
char
*
end
;
char
*
start
;
domain_buf
[
0
]
=
'\0'
;
if
(
zstr
(
url
))
{
return
;
}
start
=
strstr
(
url
,
"://"
);
if
(
!
start
)
{
return
;
}
start
+=
3
;
if
(
!*
start
)
{
return
;
}
strncpy
(
domain_buf
,
start
,
domain_buf_len
);
end
=
strchr
(
domain_buf
,
'/'
);
if
(
end
)
{
*
end
=
'\0'
;
}
else
{
/* bad URL */
domain_buf
[
0
]
=
'\0'
;
}
}
/**
* Put a file to the URL
* @param cache the cache
...
...
@@ -233,6 +269,12 @@ static switch_status_t http_put(url_cache_t *cache, http_profile_t *profile, swi
}
buf
=
switch_mprintf
(
"Content-Type: %s"
,
mime_type
);
/* find profile for domain */
if
(
!
profile
)
{
profile
=
url_cache_http_profile_find_by_fqdn
(
cache
,
url
);
}
headers
=
switch_curl_slist_append
(
headers
,
buf
);
headers
=
append_aws_s3_headers
(
headers
,
profile
,
"PUT"
,
mime_type
,
url
);
...
...
@@ -732,10 +774,25 @@ static http_profile_t *url_cache_http_profile_find(url_cache_t *cache, const cha
return
NULL
;
}
/**
* Find a profile by domain name
*/
static
http_profile_t
*
url_cache_http_profile_find_by_fqdn
(
url_cache_t
*
cache
,
const
char
*
url
)
{
if
(
cache
&&
!
zstr
(
url
))
{
char
fqdn
[
DOMAIN_BUF_SIZE
];
parse_domain
(
url
,
fqdn
,
DOMAIN_BUF_SIZE
);
if
(
!
zstr_buf
(
fqdn
))
{
return
(
http_profile_t
*
)
switch_core_hash_find
(
cache
->
fqdn_profiles
,
fqdn
);
}
}
return
NULL
;
}
/**
* Add a profile to the cache
*/
static
void
url_cache_http_profile_add
(
url_cache_t
*
cache
,
const
char
*
name
,
const
char
*
aws_s3_access_key_id
,
const
char
*
aws_s3_secret_access_key
)
static
http_profile_t
*
url_cache_http_profile_add
(
url_cache_t
*
cache
,
const
char
*
name
,
const
char
*
aws_s3_access_key_id
,
const
char
*
aws_s3_secret_access_key
)
{
http_profile_t
*
profile
=
switch_core_alloc
(
cache
->
pool
,
sizeof
(
*
profile
));
profile
->
name
=
switch_core_strdup
(
cache
->
pool
,
name
);
...
...
@@ -746,6 +803,7 @@ static void url_cache_http_profile_add(url_cache_t *cache, const char *name, con
profile
->
aws_s3_secret_access_key
=
switch_core_strdup
(
cache
->
pool
,
aws_s3_secret_access_key
);
}
switch_core_hash_insert
(
cache
->
profiles
,
profile
->
name
,
profile
);
return
profile
;
}
/**
...
...
@@ -901,6 +959,11 @@ static switch_status_t http_get(url_cache_t *cache, http_profile_t *profile, cac
get_data
.
fd
=
0
;
get_data
.
url
=
url
;
/* find profile for domain */
if
(
!
profile
)
{
profile
=
url_cache_http_profile_find_by_fqdn
(
cache
,
url
->
url
);
}
/* add optional AWS S3 headers if necessary */
headers
=
append_aws_s3_headers
(
headers
,
profile
,
"GET"
,
""
,
url
->
url
);
...
...
@@ -1329,6 +1392,8 @@ static switch_status_t do_config(url_cache_t *cache)
for
(
profile
=
switch_xml_child
(
profiles
,
"profile"
);
profile
;
profile
=
profile
->
next
)
{
const
char
*
name
=
switch_xml_attr_soft
(
profile
,
"name"
);
if
(
!
zstr
(
name
))
{
http_profile_t
*
profile_obj
;
switch_xml_t
domains
;
switch_xml_t
s3
=
switch_xml_child
(
profile
,
"aws-s3"
);
const
char
*
access_key_id
=
NULL
;
const
char
*
secret_access_key
=
NULL
;
...
...
@@ -1348,7 +1413,21 @@ static switch_status_t do_config(url_cache_t *cache)
}
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Adding profile
\"
%s
\"
to cache
\n
"
,
name
);
url_cache_http_profile_add
(
cache
,
name
,
access_key_id
,
secret_access_key
);
profile_obj
=
url_cache_http_profile_add
(
cache
,
name
,
access_key_id
,
secret_access_key
);
domains
=
switch_xml_child
(
profile
,
"domains"
);
if
(
domains
)
{
switch_xml_t
domain
;
for
(
domain
=
switch_xml_child
(
domains
,
"domain"
);
domain
;
domain
=
domain
->
next
)
{
const
char
*
fqdn
=
switch_xml_attr_soft
(
domain
,
"name"
);
if
(
!
zstr
(
fqdn
))
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Adding profile
\"
%s
\"
domain
\"
%s
\"
to cache
\n
"
,
name
,
fqdn
);
switch_core_hash_insert
(
cache
->
fqdn_profiles
,
fqdn
,
profile_obj
);
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"HTTP profile domain missing name!
\n
"
);
}
}
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_WARNING
,
"HTTP profile missing name
\n
"
);
}
...
...
@@ -1554,6 +1633,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_http_cache_load)
gcache
.
pool
=
pool
;
switch_core_hash_init
(
&
gcache
.
map
,
gcache
.
pool
);
switch_core_hash_init
(
&
gcache
.
profiles
,
gcache
.
pool
);
switch_core_hash_init
(
&
gcache
.
fqdn_profiles
,
gcache
.
pool
);
switch_mutex_init
(
&
gcache
.
mutex
,
SWITCH_MUTEX_UNNESTED
,
gcache
.
pool
);
switch_thread_rwlock_create
(
&
gcache
.
shutdown_lock
,
gcache
.
pool
);
...
...
@@ -1626,6 +1706,7 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_http_cache_shutdown)
url_cache_clear
(
&
gcache
,
NULL
);
switch_core_hash_destroy
(
&
gcache
.
map
);
switch_core_hash_destroy
(
&
gcache
.
profiles
);
switch_core_hash_destroy
(
&
gcache
.
fqdn_profiles
);
switch_mutex_destroy
(
gcache
.
mutex
);
return
SWITCH_STATUS_SUCCESS
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论