Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
1d2c64d3
提交
1d2c64d3
authored
5月 11, 2010
作者:
Anthony Minessale
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
90c040ec
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
10 行增加
和
26 行删除
+10
-26
mod_nibblebill.c
src/mod/applications/mod_nibblebill/mod_nibblebill.c
+10
-26
没有找到文件。
src/mod/applications/mod_nibblebill/mod_nibblebill.c
浏览文件 @
1d2c64d3
...
...
@@ -50,10 +50,6 @@
#include <switch.h>
/* Defaults */
static
char
SQL_LOOKUP
[]
=
"SELECT %s AS nibble_balance FROM %s WHERE %s='%s'"
;
static
char
SQL_SAVE
[]
=
"UPDATE %s SET %s=%s-%f WHERE %s='%s'"
;
typedef
struct
{
switch_time_t
lastts
;
/* Last time we did any billing */
float
total
;
/* Total amount billed so far */
...
...
@@ -300,7 +296,6 @@ static void transfer_call(switch_core_session_t *session, char *destination)
/* At this time, billing never succeeds if you don't have a database. */
static
switch_status_t
bill_event
(
float
billamount
,
const
char
*
billaccount
,
switch_channel_t
*
channel
)
{
switch_stream_handle_t
sql_stream
=
{
0
};
char
*
sql
=
NULL
,
*
dsql
=
NULL
;
switch_odbc_statement_handle_t
stmt
=
NULL
;
switch_status_t
status
=
SWITCH_STATUS_FALSE
;
...
...
@@ -318,11 +313,9 @@ static switch_status_t bill_event(float billamount, const char *billaccount, swi
sql
=
globals
.
custom_sql_save
;
}
}
else
{
SWITCH_STANDARD_STREAM
(
sql_stream
);
sql_stream
.
write_function
(
&
sql_stream
,
SQL_SAVE
,
globals
.
db_table
,
globals
.
db_column_cash
,
globals
.
db_column_cash
,
billamount
,
globals
.
db_column_account
,
billaccount
);
sql
=
(
char
*
)
sql_stream
.
data
;
sql
=
dsql
=
switch_mprintf
(
"UPDATE %s SET %s=%s-%f WHERE %s='%s'"
,
globals
.
db_table
,
globals
.
db_column_cash
,
globals
.
db_column_cash
,
billamount
,
globals
.
db_column_account
,
billaccount
);
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Doing update query
\n
[%s]
\n
"
,
sql
);
...
...
@@ -339,23 +332,18 @@ static switch_status_t bill_event(float billamount, const char *billaccount, swi
}
switch_safe_free
(
dsql
);
switch_safe_free
(
sql_stream
.
data
);
return
status
;
}
static
float
get_balance
(
const
char
*
billaccount
,
switch_channel_t
*
channel
)
{
switch_stream_handle_t
sql_stream
=
{
0
};
char
*
sql
=
NULL
;
char
*
dsql
=
NULL
,
*
sql
=
NULL
;
nibblebill_results_t
pdata
;
float
balance
=
0
.
00
f
;
SWITCH_STANDARD_STREAM
(
sql_stream
);
if
(
!
switch_odbc_available
())
{
balance
=
-
1
.
00
f
;
goto
end
;
return
-
1
.
00
f
;
}
memset
(
&
pdata
,
0
,
sizeof
(
pdata
));
...
...
@@ -363,13 +351,15 @@ static float get_balance(const char *billaccount, switch_channel_t *channel)
if
(
globals
.
custom_sql_lookup
)
{
if
(
switch_string_var_check_const
(
globals
.
custom_sql_lookup
)
||
switch_string_has_escaped_data
(
globals
.
custom_sql_lookup
))
{
sql
=
switch_channel_expand_variables
(
channel
,
globals
.
custom_sql_lookup
);
if
(
sql
!=
globals
.
custom_sql_lookup
)
dsql
=
sql
;
}
else
{
sql
=
globals
.
custom_sql_lookup
;
}
}
else
{
sql
_stream
.
write_function
(
&
sql_stream
,
SQL_LOOKUP
,
globals
.
db_column_cash
,
globals
.
db_table
,
globals
.
db_column_account
,
billaccount
);
sql
=
sql_stream
.
data
;
sql
=
dsql
=
switch_mprintf
(
"SELECT %s AS nibble_balance FROM %s WHERE %s='%s'"
,
globals
.
db_column_cash
,
globals
.
db_table
,
globals
.
db_column_account
,
billaccount
)
;
}
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Doing lookup query
\n
[%s]
\n
"
,
sql
);
if
(
switch_odbc_handle_callback_exec
(
globals
.
master_odbc
,
sql
,
nibblebill_callback
,
&
pdata
,
NULL
)
!=
SWITCH_ODBC_SUCCESS
)
{
...
...
@@ -377,19 +367,13 @@ static float get_balance(const char *billaccount, switch_channel_t *channel)
/* Return -1 for safety */
balance
=
-
1
.
00
f
;
goto
end
;
}
else
{
/* Successfully retrieved! */
balance
=
pdata
.
balance
;
switch_log_printf
(
SWITCH_CHANNEL_LOG
,
SWITCH_LOG_DEBUG
,
"Retrieved current balance for account %s (balance = %f)
\n
"
,
billaccount
,
balance
);
}
end:
if
(
sql
!=
globals
.
custom_sql_lookup
&&
sql
!=
sql_stream
.
data
)
{
switch_safe_free
(
sql
);
}
switch_safe_free
(
sql_stream
.
data
);
switch_safe_free
(
dsql
);
return
balance
;
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论