diff --git a/modules/cgrates/README b/modules/cgrates/README index b3247ace5b..bb85af5502 100644 --- a/modules/cgrates/README +++ b/modules/cgrates/README @@ -44,7 +44,7 @@ Razvan Crainea 1.10.1. $cgr(name) / $(cgr(name)[session]) 1.10.2. $cgr_opt(name) / $(cgr_opt(name)[session]) - 1.10.3. $cgrret(name) + 1.10.3. $cgr_ret(name) 1.11. Exported Asynchronous Functions @@ -67,7 +67,7 @@ Razvan Crainea 1.10. $cgr(name) simple usage 1.11. $cgr(name) multiple sessions usage 1.12. $cgr_opt(name) usage - 1.13. $cgrret(name) usage + 1.13. $cgr_ret(name) usage 1.14. async cgrates_auth usage 1.15. async cgrates_cmd compat_mode usage 1.16. async cgrates_cmd new usage @@ -109,13 +109,13 @@ Chapter 1. Admin Guide start a new call and it has enough credit to call to that destination. This is done using the cgrates_auth() command, which returns the number of seconds a call is allowed to run in - the $cgrret pseudo-variable. + the $cgr_ret pseudo-variable. Usage example: ... if (cgrates_auth("$fU", "$rU")) - xlog("Call is allowed to run $cgrret seconds\n") -; + xlog("Call is allowed to run $cgr_ret seconds\n" +); } ... @@ -149,7 +149,7 @@ Chapter 1. Admin Guide sl_send_reply("403", "Forbidden"); exit; } - xlog("Call is allowed to run $cgrret seconds\n"); + xlog("Call is allowed to run $cgr_ret seconds\n"); # do accounting for this call cgrates_acc("cdr", "$fU", "$rU"); ... @@ -161,8 +161,8 @@ Chapter 1. Admin Guide 1.4. Other Commands You can use the cgrates_cmd() to send arbitrary commands to the - CGRateS engine, and use the $cgrret pseudo-variable to retrieve - the response. + CGRateS engine, and use the $cgr_ret pseudo-variable to + retrieve the response. The following example simulates the cgrates_auth() CGRateS call: @@ -175,8 +175,8 @@ ompat mode */ $cgr(RequestType) = "*prepaid"; $cgr(Destination) = $rU; cgrates_cmd("SessionSv1.AuthorizeEvent"); - xlog("Call is allowed to run $cgrret(MaxUsage) seconds\n -"); + xlog("Call is allowed to run $cgr_ret(MaxUsage) seconds\ +n"); ... 1.5. CGRateS Failover @@ -411,12 +411,12 @@ modparam("cgrates", "compat_mode", 1) # move attributes from AttributesDigest variable to plain AVPs $var(idx) = 0; - while ($(cgrret(AttributesDigest){s.select,$var( -idx),,}) != NULL) { - $avp($(cgrret(AttributesDigest){s.select -,$var(idx),,}{s.select,0,:})) - = $(cgrret(AttributesDigest){s.s -elect,$var(idx),,}{s.select,1,:}); + while ($(cgr_ret(AttributesDigest){s.select,$var +(idx),,}) != NULL) { + $avp($(cgr_ret(AttributesDigest){s.selec +t,$var(idx),,}{s.select,0,:})) + = $(cgr_ret(AttributesDigest){s. +select,$var(idx),,}{s.select,1,:}); $var(idx) = $var(idx) + 1; } ... @@ -457,7 +457,7 @@ elect,$var(idx),,}{s.select,1,:}); $cgr(RequestType) = "*prepaid"; $cgr(Destination) = $rU; cgrates_cmd("SessionSv1.AuthorizeEvent"); - xlog("Call is allowed to run $cgrret seconds\n"); + xlog("Call is allowed to run $cgr_ret seconds\n"); ... 1.10. Exported pseudo-variables @@ -553,22 +553,22 @@ ounting } ... -1.10.3. $cgrret(name) +1.10.3. $cgr_ret(name) Returns the reply message of a CGRateS command in script, or when used in the non-compat mode, one of the objects within the reply. - Example 1.13. $cgrret(name) usage + Example 1.13. $cgr_ret(name) usage ... cgrates_auth("$fU", "$rU"); # in compat mode - xlog("Call is allowed to run $cgrret seconds\n"); + xlog("Call is allowed to run $cgr_ret seconds\n"); # in non-compat mode - xlog("Call is allowed to run $cgrret(MaxUsage) seconds\n -"); + xlog("Call is allowed to run $cgr_ret(MaxUsage) seconds\ +n"); ... 1.11. Exported Asynchronous Functions @@ -611,7 +611,7 @@ route { route [auth_reply] { if ($rc < 0) { - xlog("Call not authorized: code=$cgrret!\n"); + xlog("Call not authorized: code=$cgr_ret!\n"); send_reply("403", "Forbidden"); exit; } @@ -656,7 +656,7 @@ route { route [auth_reply] { if ($rc < 0) { - xlog("Call not authorized: code=$cgrret!\n"); + xlog("Call not authorized: code=$cgr_ret!\n"); send_reply("403", "Forbidden"); exit; } @@ -679,8 +679,8 @@ eply); route [auth_reply] { if ($rc < 0) { - xlog("Call not authorized: MaxUsage=$cgrret(MaxUsage)!\n -"); + xlog("Call not authorized: MaxUsage=$cgr_ret(MaxUsage)!\ +n"); send_reply("403", "Forbidden"); exit; } diff --git a/modules/cgrates/cgrates.c b/modules/cgrates/cgrates.c index 71100dfec4..600f3ddfd5 100644 --- a/modules/cgrates/cgrates.c +++ b/modules/cgrates/cgrates.c @@ -75,6 +75,7 @@ static int w_pv_get_cgr_opt(struct sip_msg *msg, pv_param_t *param, pv_value_t *val); static int pv_parse_cgr(pv_spec_p sp, str *in); static int w_pv_parse_cgr(pv_spec_p sp, str *in); +static int w_pv_parse_cgr_warn(pv_spec_p sp, str *in); static int pv_parse_idx_cgr(pv_spec_p sp, str *in); static int pv_get_cgr_reply(struct sip_msg *msg, pv_param_t *param, pv_value_t *val); @@ -110,8 +111,10 @@ static pv_export_t pvars[] = { pv_parse_cgr, pv_parse_idx_cgr, 0, 0}, { str_init("cgr_opt"), 2004, w_pv_get_cgr_opt, w_pv_set_cgr_opt, w_pv_parse_cgr, pv_parse_idx_cgr, 0, 0}, - { str_init("cgrret"), 2005, pv_get_cgr_reply, 0, + { str_init("cgr_ret"), 2005, pv_get_cgr_reply, 0, pv_parse_cgr, 0, 0, 0}, + { str_init("cgrret"), 2005, pv_get_cgr_reply, 0, + w_pv_parse_cgr_warn, 0, 0, 0}, { {0, 0}, 0, 0, 0, 0, 0, 0, 0 } }; @@ -657,6 +660,16 @@ static int w_pv_parse_cgr(pv_spec_p sp, str *in) return pv_parse_cgr(sp, in); } +static int w_pv_parse_cgr_warn(pv_spec_p sp, str *in) +{ + static int warned = 0; + if (!warned) { + LM_WARN("$cgrret(name) is deprecated - please using $cgr_ret(name) instead!\n"); + warned = 1; + } + return pv_parse_cgr(sp, in); +} + static int pv_parse_idx_cgr(pv_spec_p sp, str *in) { str *s; diff --git a/modules/cgrates/doc/cgrates_admin.xml b/modules/cgrates/doc/cgrates_admin.xml index 4e4995e0d1..a1d44cb04c 100644 --- a/modules/cgrates/doc/cgrates_admin.xml +++ b/modules/cgrates/doc/cgrates_admin.xml @@ -46,14 +46,14 @@ The authorization is used to check if an account is allowed to start a new call and it has enough credit to call to that destination. This is done using the cgrates_auth() command, which returns the number of seconds - a call is allowed to run in the $cgrret pseudo-variable. + a call is allowed to run in the $cgr_ret pseudo-variable. Usage example: ... if (cgrates_auth("$fU", "$rU")) - xlog("Call is allowed to run $cgrret seconds\n"); + xlog("Call is allowed to run $cgr_ret seconds\n"); } ... @@ -92,7 +92,7 @@ sl_send_reply("403", "Forbidden"); exit; } - xlog("Call is allowed to run $cgrret seconds\n"); + xlog("Call is allowed to run $cgr_ret seconds\n"); # do accounting for this call cgrates_acc("cdr", "$fU", "$rU"); ... @@ -109,7 +109,7 @@ Other Commands You can use the cgrates_cmd() to send arbitrary - commands to the CGRateS engine, and use the $cgrret + commands to the CGRateS engine, and use the $cgr_ret pseudo-variable to retrieve the response. @@ -123,7 +123,7 @@ $cgr(RequestType) = "*prepaid"; $cgr(Destination) = $rU; cgrates_cmd("SessionSv1.AuthorizeEvent"); - xlog("Call is allowed to run $cgrret(MaxUsage) seconds\n"); + xlog("Call is allowed to run $cgr_ret(MaxUsage) seconds\n"); ... @@ -529,9 +529,9 @@ modparam("cgrates", "compat_mode", 1) } # move attributes from AttributesDigest variable to plain AVPs $var(idx) = 0; - while ($(cgrret(AttributesDigest){s.select,$var(idx),,}) != NULL) { - $avp($(cgrret(AttributesDigest){s.select,$var(idx),,}{s.select,0,:})) - = $(cgrret(AttributesDigest){s.select,$var(idx),,}{s.select,1,:}); + while ($(cgr_ret(AttributesDigest){s.select,$var(idx),,}) != NULL) { + $avp($(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,0,:})) + = $(cgr_ret(AttributesDigest){s.select,$var(idx),,}{s.select,1,:}); $var(idx) = $var(idx) + 1; } ... @@ -609,7 +609,7 @@ modparam("cgrates", "compat_mode", 1) $cgr(RequestType) = "*prepaid"; $cgr(Destination) = $rU; cgrates_cmd("SessionSv1.AuthorizeEvent"); - xlog("Call is allowed to run $cgrret seconds\n"); + xlog("Call is allowed to run $cgr_ret seconds\n"); ... @@ -739,23 +739,23 @@ modparam("cgrates", "compat_mode", 1)
- <varname>$cgrret(name)</varname> + <varname>$cgr_ret(name)</varname> Returns the reply message of a CGRateS command in script, or when used in the non-compat mode, one of the objects within the reply. - $cgrret(name) usage + $cgr_ret(name) usage ... cgrates_auth("$fU", "$rU"); # in compat mode - xlog("Call is allowed to run $cgrret seconds\n"); + xlog("Call is allowed to run $cgr_ret seconds\n"); # in non-compat mode - xlog("Call is allowed to run $cgrret(MaxUsage) seconds\n"); + xlog("Call is allowed to run $cgr_ret(MaxUsage) seconds\n"); ... @@ -841,7 +841,7 @@ route { route [auth_reply] { if ($rc < 0) { - xlog("Call not authorized: code=$cgrret!\n"); + xlog("Call not authorized: code=$cgr_ret!\n"); send_reply("403", "Forbidden"); exit; } @@ -916,7 +916,7 @@ route { route [auth_reply] { if ($rc < 0) { - xlog("Call not authorized: code=$cgrret!\n"); + xlog("Call not authorized: code=$cgr_ret!\n"); send_reply("403", "Forbidden"); exit; } @@ -941,7 +941,7 @@ route { route [auth_reply] { if ($rc < 0) { - xlog("Call not authorized: MaxUsage=$cgrret(MaxUsage)!\n"); + xlog("Call not authorized: MaxUsage=$cgr_ret(MaxUsage)!\n"); send_reply("403", "Forbidden"); exit; }