Skip to content

Commit

Permalink
cgrates: add attributes parsing example
Browse files Browse the repository at this point in the history
  • Loading branch information
razvancrainea committed Mar 23, 2018
1 parent 0fab92d commit 53f16a0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
57 changes: 41 additions & 16 deletions modules/cgrates/README
Expand Up @@ -62,14 +62,15 @@ Razvan Crainea
1.5. Set compat_mode parameter
1.6. cgrates_acc() usage
1.7. cgrates_auth() usage
1.8. cgrates_cmd() usage
1.9. $cgr(name) simple usage
1.10. $cgr(name) multiple sessions usage
1.11. $cgr_opt(name) usage
1.12. $cgrret(name) usage
1.13. async cgrates_auth usage
1.14. async cgrates_cmd compat_mode usage
1.15. async cgrates_cmd new usage
1.8. cgrates_auth() usage with attributes parsing
1.9. cgrates_cmd() usage
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.14. async cgrates_auth usage
1.15. async cgrates_cmd compat_mode usage
1.16. async cgrates_cmd new usage

Chapter 1. Admin Guide

Expand Down Expand Up @@ -396,6 +397,30 @@ modparam("cgrates", "compat_mode", 1)
}
...

Example 1.8. cgrates_auth() usage with attributes parsing
...
if (!has_totag()) {
...
$cgr_opt(GetAttributes) = 1;
if (!cgrates_auth("$fU", "$rU")) {
sl_send_reply("403", "Forbidden");
exit;
}
# 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,:});
$var(idx) = $var(idx) + 1;
}
...
}
...

1.9.3. cgrates_cmd(command[, session])

cgrates_cmd() can send arbitrary commands to the CGRateS
Expand All @@ -420,7 +445,7 @@ modparam("cgrates", "compat_mode", 1)

This function can be used from any route.

Example 1.8. cgrates_cmd() usage
Example 1.9. cgrates_cmd() usage
...
# cgrates_auth("$fU", "$rU"); simulation
$cgr_opt(Tenant) = $fd;
Expand Down Expand Up @@ -455,7 +480,7 @@ modparam("cgrates", "compat_mode", 1)
another. if the session tag does not exist, the default (no
name) one is used.

Example 1.9. $cgr(name) simple usage
Example 1.10. $cgr(name) simple usage
...
if (!has_totag()) {
...
Expand All @@ -470,7 +495,7 @@ ounting
}
...

Example 1.10. $cgr(name) multiple sessions usage
Example 1.11. $cgr(name) multiple sessions usage
...
if (!has_totag()) {
...
Expand Down Expand Up @@ -517,7 +542,7 @@ ounting
* GetSuppliers - request an array with all the suppliers for
that can terminate that call.

Example 1.11. $cgr_opt(name) usage
Example 1.12. $cgr_opt(name) usage
...
$cgr_opt(Tenant) = "cgrates.org";
$cgr_opt(GetMaxUsage) = 1; # also retrieve the max usage
Expand All @@ -532,7 +557,7 @@ ounting
when used in the non-compat mode, one of the objects within the
reply.

Example 1.12. $cgrret(name) usage
Example 1.13. $cgrret(name) usage
...
cgrates_auth("$fU", "$rU");

Expand Down Expand Up @@ -575,7 +600,7 @@ ounting
headers, or it is not an initial INVITE.
* -5 - CGRateS returned an invalid message.

Example 1.13. async cgrates_auth usage
Example 1.14. async cgrates_auth usage
route {
...
async(cgrates_auth("$fU", "$rU"), auth_reply);
Expand Down Expand Up @@ -614,7 +639,7 @@ route [auth_reply]
* -3 - No suitable CGRateS server found. message type (not an
initial INVITE).

Example 1.14. async cgrates_cmd compat_mode usage
Example 1.15. async cgrates_cmd compat_mode usage
route {
...
$cgr(Tenant) = $fd;
Expand All @@ -636,7 +661,7 @@ route [auth_reply]
...
}

Example 1.15. async cgrates_cmd new usage
Example 1.16. async cgrates_cmd new usage
route {
...
$cgr_opt(Tenant) = $fd;
Expand Down
24 changes: 24 additions & 0 deletions modules/cgrates/doc/cgrates_admin.xml
Expand Up @@ -515,6 +515,30 @@ modparam("cgrates", "compat_mode", 1)
</programlisting>
</example>

<example>
<title>cgrates_auth() usage with attributes parsing</title>
<programlisting format="linespecific">
...
if (!has_totag()) {
...
$cgr_opt(GetAttributes) = 1;
if (!cgrates_auth("$fU", "$rU")) {
sl_send_reply("403", "Forbidden");
exit;
}
# 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,:});
$var(idx) = $var(idx) + 1;
}
...
}
...
</programlisting>
</example>

</section>
<section id="cgrates_cmd">
<title>
Expand Down

0 comments on commit 53f16a0

Please sign in to comment.