Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
ad7f889a
提交
ad7f889a
authored
10月 21, 2012
作者:
Daniel Swarbrick
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mod_cdr_mongodb: add support for authentication
上级
e3da4e16
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
47 行增加
和
4 行删除
+47
-4
cdr_mongodb.conf.xml
...od_cdr_mongodb/conf/autoload_configs/cdr_mongodb.conf.xml
+4
-0
mod_cdr_mongodb.c
src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c
+43
-4
没有找到文件。
src/mod/event_handlers/mod_cdr_mongodb/conf/autoload_configs/cdr_mongodb.conf.xml
浏览文件 @
ad7f889a
...
...
@@ -7,6 +7,10 @@
<!-- Namespace format is database.collection -->
<param
name=
"namespace"
value=
"test.cdr"
/>
<!-- Set username and password to enable MongoDB authentication -->
<!-- <param name="username" value="freeswitch"/> -->
<!-- <param name="password" value="secret"/> -->
<!-- If true, create CDR for B-leg of call (default: true) -->
<param
name=
"log-b-leg"
value=
"false"
/>
</settings>
...
...
src/mod/event_handlers/mod_cdr_mongodb/mod_cdr_mongodb.c
浏览文件 @
ad7f889a
...
...
@@ -39,6 +39,8 @@ static struct {
char
*
mongo_host
;
uint32_t
mongo_port
;
char
*
mongo_namespace
;
char
*
mongo_username
;
char
*
mongo_password
;
mongo
mongo_conn
[
1
];
switch_mutex_t
*
mongo_mutex
;
switch_bool_t
log_b
;
...
...
@@ -48,6 +50,8 @@ static switch_xml_config_item_t config_settings[] = {
/* key, flags, ptr, default_value, syntax, helptext */
SWITCH_CONFIG_ITEM_STRING_STRDUP
(
"host"
,
CONFIG_REQUIRED
,
&
globals
.
mongo_host
,
"127.0.0.1"
,
NULL
,
"MongoDB server host address"
),
SWITCH_CONFIG_ITEM_STRING_STRDUP
(
"namespace"
,
CONFIG_REQUIRED
,
&
globals
.
mongo_namespace
,
NULL
,
"database.collection"
,
"MongoDB namespace"
),
SWITCH_CONFIG_ITEM_STRING_STRDUP
(
"username"
,
CONFIG_RELOADABLE
,
&
globals
.
mongo_username
,
NULL
,
NULL
,
"MongoDB username"
),
SWITCH_CONFIG_ITEM_STRING_STRDUP
(
"password"
,
CONFIG_RELOADABLE
,
&
globals
.
mongo_password
,
NULL
,
NULL
,
"MongoDB password"
),
/* key, type, flags, ptr, default_value, data, syntax, helptext */
SWITCH_CONFIG_ITEM
(
"port"
,
SWITCH_CONFIG_INT
,
CONFIG_REQUIRED
,
&
globals
.
mongo_port
,
27017
,
NULL
,
NULL
,
"MongoDB server TCP port"
),
...
...
@@ -79,6 +83,29 @@ static void set_bson_profile_data(bson *b, switch_caller_profile_t *caller_profi
}
static
switch_status_t
cdr_mongo_authenticate
()
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
mongo_error_t
db_status
;
char
*
ns_tmp
,
*
ns_split
[
2
];
/* Split namespace db.collection into separate vars */
switch_strdup
(
ns_tmp
,
globals
.
mongo_namespace
);
switch_separate_string
(
ns_tmp
,
'.'
,
ns_split
,
2
);
db_status
=
mongo_cmd_authenticate
(
globals
.
mongo_conn
,
ns_split
[
0
],
globals
.
mongo_username
,
globals
.
mongo_password
);
if
(
db_status
!=
MONGO_OK
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"mongo_cmd_authenticate: authentication failed
\n
"
);
status
=
SWITCH_STATUS_FALSE
;
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Successfully authenticated %s@%s
\n
"
,
globals
.
mongo_username
,
ns_split
[
0
]);
}
switch_safe_free
(
ns_tmp
);
return
status
;
}
static
switch_status_t
my_on_reporting
(
switch_core_session_t
*
session
)
{
switch_status_t
status
=
SWITCH_STATUS_SUCCESS
;
...
...
@@ -306,14 +333,22 @@ static switch_status_t my_on_reporting(switch_core_session_t *session)
status
=
SWITCH_STATUS_FALSE
;
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"MongoDB connection re-established.
\n
"
);
if
(
mongo_insert
(
globals
.
mongo_conn
,
globals
.
mongo_namespace
,
&
cdr
,
NULL
)
!=
MONGO_OK
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"mongo_insert: error code %d
\n
"
,
globals
.
mongo_conn
->
err
);
status
=
SWITCH_STATUS_FALSE
;
/* Re-authentication is necessary after a reconnect */
if
(
globals
.
mongo_username
&&
globals
.
mongo_password
)
{
status
=
cdr_mongo_authenticate
();
}
if
(
db_status
==
MONGO_OK
)
{
if
(
mongo_insert
(
globals
.
mongo_conn
,
globals
.
mongo_namespace
,
&
cdr
,
NULL
)
!=
MONGO_OK
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"mongo_insert: %s (error code %d)
\n
"
,
globals
.
mongo_conn
->
errstr
,
globals
.
mongo_conn
->
err
);
status
=
SWITCH_STATUS_FALSE
;
}
}
}
}
else
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"mongo_insert:
error code %d
\n
"
,
globals
.
mongo_conn
->
err
);
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_ERROR
,
"mongo_insert:
%s (error code %d)
\n
"
,
globals
.
mongo_conn
->
errstr
,
globals
.
mongo_conn
->
err
);
status
=
SWITCH_STATUS_FALSE
;
}
}
...
...
@@ -385,6 +420,10 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_mongodb_load)
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_INFO
,
"Connected to MongoDB server %s:%d
\n
"
,
globals
.
mongo_host
,
globals
.
mongo_port
);
}
if
(
globals
.
mongo_username
&&
globals
.
mongo_password
)
{
status
=
cdr_mongo_authenticate
();
}
switch_mutex_init
(
&
globals
.
mongo_mutex
,
SWITCH_MUTEX_NESTED
,
pool
);
switch_core_add_state_handler
(
&
state_handlers
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论