mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-24 03:47:39 +00:00
FS-5880 --resolve
This commit is contained in:
parent
37d566c6f6
commit
f9a19ee57f
@ -28,6 +28,7 @@
|
|||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
* Darren Schreiber <d@d-man.org>
|
* Darren Schreiber <d@d-man.org>
|
||||||
* Rupa Schomaker <rupa@rupa.com>
|
* Rupa Schomaker <rupa@rupa.com>
|
||||||
|
* Emmanuel Schmidbauer <e.schmidbauer@gmail.com>
|
||||||
*
|
*
|
||||||
* mod_nibblebill.c - Nibble Billing
|
* 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:
|
||||||
@ -91,6 +92,10 @@ static struct {
|
|||||||
/* Other options */
|
/* Other options */
|
||||||
int global_heartbeat; /* Supervise and bill every X seconds, 0 means off */
|
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 */
|
/* Database settings */
|
||||||
char *dbname;
|
char *dbname;
|
||||||
char *odbc_dsn;
|
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_percall_action, globals.percall_action);
|
||||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_lowbal_action, globals.lowbal_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_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)
|
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);
|
set_global_nobal_action(val);
|
||||||
} else if (!strcasecmp(var, "nobal_amt")) {
|
} else if (!strcasecmp(var, "nobal_amt")) {
|
||||||
globals.nobal_amt = atof(val);
|
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")) {
|
} else if (!strcasecmp(var, "global_heartbeat")) {
|
||||||
globals.global_heartbeat = atoi(val);
|
globals.global_heartbeat = atoi(val);
|
||||||
}
|
}
|
||||||
@ -260,6 +271,12 @@ static switch_status_t nibblebill_load_config(void)
|
|||||||
if (zstr(globals.nobal_action)) {
|
if (zstr(globals.nobal_action)) {
|
||||||
set_global_nobal_action("hangup");
|
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) {
|
if (globals.odbc_dsn) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG
|
||||||
@ -449,9 +466,9 @@ static switch_status_t do_billing(switch_core_session_t *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Variables kept in FS but relevant only to this module */
|
/* 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");
|
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"))) {
|
if (!zstr(switch_channel_get_variable(channel, "nobal_amt"))) {
|
||||||
nobal_amt = atof(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);
|
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 */
|
/* 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));
|
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 */
|
/* 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 */
|
/* Return if there's no billing information on this session */
|
||||||
if (!billaccount) {
|
if (!billaccount) {
|
||||||
@ -900,8 +917,8 @@ static switch_status_t sched_billing(switch_core_session_t *session)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Variables kept in FS but relevant only to this module */
|
/* 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);
|
||||||
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 */
|
/* Return if there's no billing information on this session */
|
||||||
if (!billrate || !billaccount) {
|
if (!billrate || !billaccount) {
|
||||||
@ -930,7 +947,7 @@ static switch_status_t process_hangup(switch_core_session_t *session)
|
|||||||
/* Now go handle like normal billing */
|
/* Now go handle like normal billing */
|
||||||
do_billing(session);
|
do_billing(session);
|
||||||
|
|
||||||
billaccount = switch_channel_get_variable(channel, "nibble_account");
|
billaccount = switch_channel_get_variable(channel, globals.var_name_account);
|
||||||
if (billaccount) {
|
if (billaccount) {
|
||||||
switch_channel_set_variable_printf(channel, "nibble_current_balance", "%f", get_balance(billaccount, channel));
|
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.percall_action);
|
||||||
switch_safe_free(globals.lowbal_action);
|
switch_safe_free(globals.lowbal_action);
|
||||||
switch_safe_free(globals.nobal_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;
|
return SWITCH_STATUS_UNLOAD;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user