[OpenSIPS-Users] variable/avp value check
Alexey
slackway2me at gmail.com
Fri Feb 9 20:44:31 UTC 2024
Hi list,
the problem was solved.
Highlights:
1. Select data from DB using timer_route with timeout (for regular data updates)
and store it in AVP. This AVP is seen in timer_route only. So, put all
its values
into the local_cache (with the same timeout), to be able to use it in
the main route.
timer_route[id_update, 300] {
# get all IDs of customers who have some feature (our inner logic)
# and store all them in a single AVP.
avp_db_query("select customer_id from customers","$avp(goldencustomers)");
# put each AVP's index value into a separate local_cache
attribute (record) with value "1".
for ($var(blahblah) in $(avp(goldencustomers)[*]))
cache_store ("local","goldencustomers_$var(blahblah)","1",300);
}
--------------------------------------------------------------------------------
2. Get needed parts of SIP-headers according to our inner logic...
Don't forget to reset variables before applying the value!
(See "Hints" section:
https://www.opensips.org/Documentation/Script-CoreVar-3-2#varscript )
# main route
route {
...
# initial INVITES section
...
$var(customerfullid) = NULL;
$var(customerfullid) = $(fn{s.select,0, }); # get "Customer-1234
from full CallerID. index 0, separator is space.
$var(customerid) = NULL;
$var(customerid) = $(var(customerfullid){s.select,1,-}); # get
1234 from "Customer-1234
$var(ret) = NULL;
cache_fetch("local", "goldencustomers_$var(blahblah)", $var(ret));
# check if there is a local_cache attribute value for INVITE with such
ID in 'From:' header
if ($var(ret) == "1") {
xlog("L_INFO", "[$ci] attr value from cache_local is:
$var(ret) . $var(customerfullid) has privileges. goto route
customers_gold");
route(customers_gold);
} else {
xlog("L_INFO", "[$ci] attr value from cache_local is:
$var(ret) . $var(customerfullid) has no privileges. goto route
customers_all");
route(customers_all);
}
...
} #main route END
--------------------------------------------------------------------------------
3. Additional routes.
# do not apply global call-limits here
route[customers_gold] {
xlog("L_INFO", "[$ci] This is $route . This $var(customerfullid)
has privileges. Global call-limits not applied.");
...
}
# apply global call-limits here
route[customers_all] {
xlog("L_INFO", "[$ci] This is $route . This $var(customerfullid)
has no privileges. Global call-limits applied.");
... # call-limit logic
}
--
best regards, Alexey
https://alexeyka.zantsev.com/
More information about the Users
mailing list