Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
f9a19ee5
提交
f9a19ee5
authored
11月 13, 2013
作者:
Ken Rice
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FS-5880 --resolve
上级
37d566c6
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
29 行增加
和
10 行删除
+29
-10
mod_nibblebill.c
src/mod/applications/mod_nibblebill/mod_nibblebill.c
+29
-10
没有找到文件。
src/mod/applications/mod_nibblebill/mod_nibblebill.c
浏览文件 @
f9a19ee5
...
...
@@ -28,9 +28,10 @@
* Contributor(s):
* Darren Schreiber <d@d-man.org>
* Rupa Schomaker <rupa@rupa.com>
* Emmanuel Schmidbauer <e.schmidbauer@gmail.com>
*
* mod_nibblebill.c - Nibble Billing
* Purpose is to allow real-time debiting of credit or cash from a database while calls are in progress. I had the following goals:
* Purpose is to allow real-time debiting of credit or cash from a database while calls are in progress. I had the following goals:
*
* Debit credit/cash from accounts real-time
* Allow for billing at different rates during a single call
...
...
@@ -91,6 +92,10 @@ static struct {
/* Other options */
int
global_heartbeat
;
/* Supervise and bill every X seconds, 0 means off */
/* Channel variable name options */
char
*
var_name_rate
;
char
*
var_name_account
;
/* Database settings */
char
*
dbname
;
char
*
odbc_dsn
;
...
...
@@ -125,6 +130,8 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_custom_sql_lookup, globals.custom_s
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_percall_action
,
globals
.
percall_action
);
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_lowbal_action
,
globals
.
lowbal_action
);
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_nobal_action
,
globals
.
nobal_action
);
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_var_name_rate
,
globals
.
var_name_rate
);
SWITCH_DECLARE_GLOBAL_STRING_FUNC
(
set_global_var_name_account
,
globals
.
var_name_account
);
static
switch_cache_db_handle_t
*
nibblebill_get_db_handle
(
void
)
{
...
...
@@ -242,6 +249,10 @@ static switch_status_t nibblebill_load_config(void)
set_global_nobal_action
(
val
);
}
else
if
(
!
strcasecmp
(
var
,
"nobal_amt"
))
{
globals
.
nobal_amt
=
atof
(
val
);
}
else
if
(
!
strcasecmp
(
var
,
"var_name_rate"
))
{
set_global_var_name_rate
(
val
);
}
else
if
(
!
strcasecmp
(
var
,
"var_name_account"
))
{
set_global_var_name_account
(
val
);
}
else
if
(
!
strcasecmp
(
var
,
"global_heartbeat"
))
{
globals
.
global_heartbeat
=
atoi
(
val
);
}
...
...
@@ -260,6 +271,12 @@ static switch_status_t nibblebill_load_config(void)
if
(
zstr
(
globals
.
nobal_action
))
{
set_global_nobal_action
(
"hangup"
);
}
if
(
zstr
(
globals
.
var_name_rate
))
{
set_global_var_name_rate
(
"nibble_rate"
);
}
if
(
zstr
(
globals
.
var_name_account
))
{
set_global_var_name_account
(
"nibble_account"
);
}
if
(
globals
.
odbc_dsn
)
{
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
...
...
@@ -449,10 +466,10 @@ static switch_status_t do_billing(switch_core_session_t *session)
}
/* Variables kept in FS but relevant only to this module */
billrate
=
switch_channel_get_variable
(
channel
,
"nibble_rate"
);
billrate
=
switch_channel_get_variable
(
channel
,
globals
.
var_name_rate
);
billincrement
=
switch_channel_get_variable
(
channel
,
"nibble_increment"
);
billaccount
=
switch_channel_get_variable
(
channel
,
"nibble_account"
);
billaccount
=
switch_channel_get_variable
(
channel
,
globals
.
var_name_account
);
if
(
!
zstr
(
switch_channel_get_variable
(
channel
,
"nobal_amt"
)))
{
nobal_amt
=
atof
(
switch_channel_get_variable
(
channel
,
"nobal_amt"
));
}
...
...
@@ -707,7 +724,7 @@ static void nibblebill_resume(switch_core_session_t *session)
switch_mutex_lock
(
globals
.
mutex
);
}
billrate
=
switch_channel_get_variable
(
channel
,
"nibble_rate"
);
billrate
=
switch_channel_get_variable
(
channel
,
globals
.
var_name_rate
);
/* Calculate how much was "lost" to billings during pause - we do this here because you never know when the billrate may change during a call */
nibble_data
->
bill_adjustments
+=
(
atof
(
billrate
)
/
1000000
/
60
)
*
((
ts
-
nibble_data
->
pausets
));
...
...
@@ -800,7 +817,7 @@ static void nibblebill_adjust(switch_core_session_t *session, double amount)
/* Variables kept in FS but relevant only to this module */
billaccount
=
switch_channel_get_variable
(
channel
,
"nibble_account"
);
billaccount
=
switch_channel_get_variable
(
channel
,
globals
.
var_name_account
);
/* Return if there's no billing information on this session */
if
(
!
billaccount
)
{
...
...
@@ -900,9 +917,9 @@ static switch_status_t sched_billing(switch_core_session_t *session)
}
/* Variables kept in FS but relevant only to this module */
billrate
=
switch_channel_get_variable
(
channel
,
"nibble_rate"
);
billaccount
=
switch_channel_get_variable
(
channel
,
"nibble_account"
);
billrate
=
switch_channel_get_variable
(
channel
,
globals
.
var_name_rate
);
billaccount
=
switch_channel_get_variable
(
channel
,
globals
.
var_name_account
);
/* Return if there's no billing information on this session */
if
(
!
billrate
||
!
billaccount
)
{
return
SWITCH_STATUS_SUCCESS
;
...
...
@@ -930,7 +947,7 @@ static switch_status_t process_hangup(switch_core_session_t *session)
/* Now go handle like normal billing */
do_billing
(
session
);
billaccount
=
switch_channel_get_variable
(
channel
,
"nibble_account"
);
billaccount
=
switch_channel_get_variable
(
channel
,
globals
.
var_name_account
);
if
(
billaccount
)
{
switch_channel_set_variable_printf
(
channel
,
"nibble_current_balance"
,
"%f"
,
get_balance
(
billaccount
,
channel
));
}
...
...
@@ -1012,6 +1029,8 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_nibblebill_shutdown)
switch_safe_free
(
globals
.
percall_action
);
switch_safe_free
(
globals
.
lowbal_action
);
switch_safe_free
(
globals
.
nobal_action
);
switch_safe_free
(
globals
.
var_name_rate
);
switch_safe_free
(
globals
.
var_name_account
);
return
SWITCH_STATUS_UNLOAD
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论