Users behind a PBX
Introduction
The system works as a softswitch in the center, with departments at the periphery. Departments are connected to the system through PBXs. PBXs register with the system as with a provider. The task is to call a PBX not as a phone but by passing the dialed number through.
That is, for example, the system has accounts dep1 (number 7777) and dep2 (number 8888).
11 calls from under dep1 and dials 888815; this call must be directed to account dep2, passing it number 15 in the request-uri.
The From number must be 777711, so that a callback is possible.
And DisplayName must pass through, since this is not a user.
The case was handled within tasks #86, #189 in 2017.
Specifics
Any other subscriber can also call the PBX; in this case their callback number is calculated in the standard way. And the PBX itself can call any other existing system subscriber. That is, not necessarily from PBX to another PBX. Thus the routing implementation (choosing the account and destination number) and presentation (building the From of the sent INVITE request) are separated.
Routing solution
An action type = internalpbx is introduced for vectorrule.
After the rule is modified by the b2b role, an account is searched by the featurecode search principle — by maximum prefix match (longmatch is used).
The remainder of the number is considered the extension.
B2BUA actually arranges a regular internal call using substitution rules; there the requesturi is already corrected during the search and processing of routing rules.
Presentation solution
From substitution when calling from a PBX. In this case action=internalpbx for vectorrule is not used.
The sign of a call from an internal PBX is the difference between the username in the From header of the incoming INVITE request and the real account registered in the system.
It is implemented in the r_sip_representative module. However b2bua_router_utils use an alternative entry point into representative, passing the Request. This is needed to find the real sipuser account. The standard interface method does not provide information about other request fields, so a special method is made for B2BUA. It compares the username from the AUTH header and the number (username) from the FROM header.
If the AUTH header is not found, this means that FROM is fine, the system passed the request considering it authorized, and therefore FROM.username matches AUTH.username. Presentation acts as usual.
If AUTH.username = FROM.username, presentation acts as usual.
If AUTH.username differs from FROM.username, the real account on whose behalf the call is made is searched based on AUTH.username (instead of FROM.username), its number is calculated, and it always goes to presentation search, even if the call is from the same domain.
The from-number = SipUserNum + FromNum is sent to the domain center for presentation search. That is, in the example above — 888811.
Presentation rules can modify this number as they see fit. And if none are found or they did not change it, it is substituted as is into the FROM of the sent invite.
The displayname value in this case (if From.username does not find an account) is passed through.
DisplayName modification
When servicing a call from a device registered under a sipuser account, its name field value is substituted as displayname in the From field of the request sent to the recipient.
The name field supports specifying modifiers.
-
{D}— substitute the original DisplayName from the incoming request. -
{d}— the same in lowercase. -
{U}— substitute the original UserName from the incoming request. -
{u}— the same in lowercase. -
{N}and{n}— substitute the formed full number of the request initiator (concatenated sipuser and extension numbers). -
{A}— substitute displayname from the account of the address book contact found by the full initiator number with extension. If the contact is not found, empty is substituted. Implemented per task #366. -
{a}— the same in lowercase. -
{E}— substitute empty. -
any other character is captured into the result at its corresponding position.
For example, the value may be specified as: "Peter - {D} - {N}", and the modifiers are replaced with the values described above from the current call context.
Displayname field modifiers are applied when passing the INVITE request to the second leg, when passing the response to the initiator, and when servicing re-INVITE.
from/extension substitution
The downstream PBX (B) is connected according to the scheme described above to an account with number 1234567, and it must be called as 1234567X, i.e., adding the dialed number to the account number. However, the PBX itself sends calls from 1234567X.
If the above number+extension concatenation model is applied in its pure form, the PBX will be called by number X, and calls coming from it will arrive for analysis in the system with number 12345671234567X.
The implementation adopted the concept of preserving the "account number" + "extension number" principle, but the extension is subject to modification. Fields are inserted into sipuser
-
opts.modextin, applied to incoming calls from the account in any case; -
opts.modextout, applied to the calculated extension when calling internalpbx.
By default modextin contains an empty string, so the modifier bypasses and extension use is refused.
And modextout by default contains "*", i.e., the call goes to the calculated extension by the remainder after long hunting.
If modextin contains something, it is applied to the field that differs from the account (it may be From username or Contact username, including an empty value), or to From username if both match.
The modifier may use X/X, *, {U} — sipuser login, {N} — sipuser number, {F} — from username, {C} — contact username, regex sequences.
Total for modextin (incoming calls from the account into the system):
-
For incoming to work without extension as a regular sipuser phone, do not specify
modextin, or specify it empty (""). From will be substituted with the account number. -
To work by the previous scheme (appending extension to username) — specify modextin =
"*". However there are two differences from the previous scheme: (a) there will be no check for the numeric value of the extension, (b) if contact username and from username match the account username, the output From = concatenation of sipuser phonenumber and the From username value. Total From will be substituted by concatenating the account number and the value from From or Contact that mostly differs from sipuser. If they do not differ, the From from the current request is appended to the account number. This behavior, in particular, allows normally servicing extension numbers that match the login of the system account itself "Incoplax". -
To handle the scheme with the downstream PBX (B), specify
"/XXXXXXX/X"asmodextin. Since From username (12345678) actually differs from the account (1234567), taking it as a basis and cutting the first seven characters, after concatenation with the sipuser account number the desired combination12345678is obtained. -
If it is known where the connected device (PBX) places information about the extension number, it can be specified explicitly in
modextin, for example{C}— the username value from the Contact header of the INVITE request is appended to the sipuser account number.
Regex sequences are also available for modifying the mostly differing value. Even if this value is empty (in particular, Contact username is empty), a series of applied regex replaces can handle this situation. And if it is non-empty and matches the account number, that is also easily described by a regular expression. The first handles emptiness, the second handles the number.
Total for modextout (outgoing from the account):
-
To call
internalpbxon the sipuser name itself and ban the extension, specify empty inmodextout. But then why internalpbx? It is better to use classic internal. This mode is retained for modifier generality, but the modification result is processed specially. -
To pass the calculated extension after long hunting — leave the default (set) — "*". That is, it will pass
123if the account number is13and13123was dialed. -
To solve the downstream PBX (B) call problem — when calling
12345678(account1234567, calculated extension8), specify1234567Xor567Xasmodextout. A sequence of regexes is possible. -
If we imagine the problem reverse to the described downstream PBX (B) (account
1234,12345678is dialed, and it expects8), then/XXX/X. That is, it will cut8from the calculated5678.
At the same time, after resolution in the number plan and registrar, each URI gets its own modifier according to the sipuser account it corresponds to.