Skip to content

Commit

Permalink
cgrates: deprecate $cgrret + replace with $cgr_ret
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Mar 28, 2018
1 parent 1f679cd commit 98754e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 43 deletions.
52 changes: 26 additions & 26 deletions modules/cgrates/README
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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"
);
}
...

Expand Down Expand Up @@ -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");
...
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
...
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
15 changes: 14 additions & 1 deletion modules/cgrates/cgrates.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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 }
};

Expand Down Expand Up @@ -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;
Expand Down
32 changes: 16 additions & 16 deletions modules/cgrates/doc/cgrates_admin.xml
Expand Up @@ -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
<emphasis>cgrates_auth()</emphasis> command, which returns the number of seconds
a call is allowed to run in the <emphasis>$cgrret</emphasis> pseudo-variable.
a call is allowed to run in the <emphasis>$cgr_ret</emphasis> pseudo-variable.
</para>
<para>
Usage example:
<programlisting format="linespecific">
...
if (cgrates_auth("$fU", "$rU"))
xlog("Call is allowed to run $cgrret seconds\n");
xlog("Call is allowed to run $cgr_ret seconds\n");
}
...
</programlisting>
Expand Down Expand Up @@ -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");
...
Expand All @@ -109,7 +109,7 @@
<title>Other Commands</title>
<para>
You can use the <emphasis>cgrates_cmd()</emphasis> to send arbitrary
commands to the CGRateS engine, and use the <emphasis>$cgrret</emphasis>
commands to the CGRateS engine, and use the <emphasis>$cgr_ret</emphasis>
pseudo-variable to retrieve the response.
</para>
<para>
Expand All @@ -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");
...
</programlisting>
</para>
Expand Down Expand Up @@ -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;
}
...
Expand Down Expand Up @@ -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");
...
</programlisting>
</example>
Expand Down Expand Up @@ -739,23 +739,23 @@ modparam("cgrates", "compat_mode", 1)
</example>
</section>
<section>
<title><varname>$cgrret(name)</varname></title>
<title><varname>$cgr_ret(name)</varname></title>
<para>
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.
</para>
<example>
<title>$cgrret(name) usage</title>
<title>$cgr_ret(name) usage</title>
<programlisting format="linespecific">
...
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");
...
</programlisting>
</example>
Expand Down Expand Up @@ -841,7 +841,7 @@ route {
route [auth_reply]
{
if ($rc &lt; 0) {
xlog("Call not authorized: code=$cgrret!\n");
xlog("Call not authorized: code=$cgr_ret!\n");
send_reply("403", "Forbidden");
exit;
}
Expand Down Expand Up @@ -916,7 +916,7 @@ route {
route [auth_reply]
{
if ($rc &lt; 0) {
xlog("Call not authorized: code=$cgrret!\n");
xlog("Call not authorized: code=$cgr_ret!\n");
send_reply("403", "Forbidden");
exit;
}
Expand All @@ -941,7 +941,7 @@ route {
route [auth_reply]
{
if ($rc &lt; 0) {
xlog("Call not authorized: MaxUsage=$cgrret(MaxUsage)!\n");
xlog("Call not authorized: MaxUsage=$cgr_ret(MaxUsage)!\n");
send_reply("403", "Forbidden");
exit;
}
Expand Down

0 comments on commit 98754e7

Please sign in to comment.