* 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
/* 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;
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)
{
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);
}
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
}
/* 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"));
}
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));
/* 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) {
}
/* 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;
/* 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));
}
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;
}