[Users] AVP subst_uri example
Norman Brandinger
norm at goes.com
Wed Jun 29 22:09:04 CEST 2005
I have pulled this from my working OpenSER configuration file, so I can
verify that the logic works.
The following example takes advantage of the recent marriage of AVPs
with the TEXTOPS subst_uri() function.
The problem is to dynamically create a call to 1 (area code) 555-1212
for a user that dials 411 on his/her phone.
The area code (also known as an NPA) is assigned to a user in the
usr_preferences table. A simple change to the value in the table will
generate a call to a different "local directory assistance operator".
The ability to dynamically associate an NPA with a customer can be used
to give the customer a "virtual local calling area". If only 7 digits
of a phone number are entered by a user, OpenSER can easily prepend a 1
plus the users dynamic NPA. I remember the days when a 1 + area code
were optional for calls to your local calling area. This example is a
first step in that direction.
An important off-shoot of this will be to perhaps assist in one aspect
of the FCC's 911 decision. If the NPA (and perhaps the NXX) can be
pulled from a location database and associated to an end user in the
usr_preferences table, (did someone say LERG) then when a call to 911 is
made, the generated phone number could be routed to a specific PSAP
operator. If the end user changes his/her location, a web interface can
be used to copy the new NPA/NXX to the usr_preferences table.
Database Entries:
Table: usr_preferences
Username: user1
Attribute: npa
Value: 123
OpenSER.cfg
route[1] {
#---------------------------------------------------------------------------------------
# 411 Local Directory Assistance
#---------------------------------------------------------------------------------------
# check the called number to see if it is 411
if (uri=~"^sip:411 at .*") {
# check the AVP database for a match with the "user", not
"user at domain" part of the From: header
# checking for user at domain should also work.
# if the "user" has a database entry with an "npa" attribute, load
the AVP.
if (avp_db_load("$from/username","s:npa")) {
# rewrite the uri by replacing the 411 with 1 plus the AVP "npa"
plus 5551212
subst_uri('/^sip:411@(.*)$/sip:1$avp(npa)5551212@\1/');
# delete the AVP npa to release resources
# the release of AVP resources is supposed to happen automatically
so the delete
# may not be strictly required.
avp_delete("s:npa");
} else {
# the AVP database didn't find a match with the "user" so we rewrite
# the uri with a default call to "local directory assistance".
rewriteuri("sip:1xxx5551212 at example.com");
};
break;
};
}
Regards,
Norman Brandinger
norm at goes dot com
More information about the Users
mailing list