Select Page

Using LUA Script to Allow SIP-Based Phones to Dial from the CUCM Corporate Directory

Eric Lavoie

If you sync your Cisco Unified Communications Manager (CUCM) to an enterprise directory, such as Microsoft Active Directory, and the phone format is entered in a fancy “human-friendly” way, users with SIP-based phones will have some issues to dial.

In my last case with a customer, the phone number format in the corporate directory had been formatted as follows: +1 514-940-1480 x5661.

From SCCP phones and Jabber, this string is interpreted, and the resulting number is respectively +151494014805661 or +1514940148095661 (note the extra “9” digit between the main number and the extension).

With SIP-based phones, there is no parsing before the call is initiated with CUCM. At the time of writing, it is still unclear whether this is a bug or is in-line with the RFC.

Given the elusive answers provided by TAC on this matter, I decided to leverage the “SIP Normalization” feature of CUCM to workaround this situation and achieve my goal of allowing SIP-based phones to dial numbers from within the CUCM Corporate Directory.

Below is a typical INVITE sent by the phone when dialing “+1 514-940-1480 x5661” from the Corporate Directory in CUCM.

 

Spaces are replaced by “%20”, hyphens and the letter x are sent as-is. Obviously, there is no way in CUCM to create a translation pattern which would match this string.

INVITE sip:+1%20514-940-1480%20x5661@cucm.acme.com SIP/2.0 Via: SIP/2.0/TCP 10.10.10.10:50291;branch=z9hG4bK7673093f From: "Test phone" <sip:2890@cucm.acme.com>;tag=00a289fbb820000f2624e8cf-1f9deb31 To: <sip:+1%20514-940-1480%20x5661@cucm.acme.com> Call-ID: 00a289fb-b8200004-5f91f053-241493e7@10.10.10.10 Max-Forwards: 70

With the help of a LUA script applied on a SIP Profile, which is in turn applied to the SIP-based phones, we have a resulting INVITE looking like this:

INVITE sip:+151494014805661@cucm.acme.com SIP/2.0 Via: SIP/2.0/TCP 10.10.10.10:50291;branch=z9hG4bK7673093f From: "Test phone" <sip:2890@cucm.acme.com>;tag=00a289fbb820000f2624e8cf-1f9deb31 To: <sip:+151494014805661@cucm.acme.com> Call-ID: 00a289fb-b8200004-5f91f053-241493e7@10.10.10.10 Max-Forwards: 70

As you can see, the number is now routable by CUCM. The LUA script I have developed to remove the unwanted characters can be found below. You can be as fancy as you want with adapting this script to your particular needs.

M={} function M.inbound_INVITE(msg) --[[ Extract data from SIP INVITE --]] local to = msg:getHeader("To") local method, ruri, ver = msg:getRequestLine() --[[ Isolate both side of "@" in variables --]] local to_left_side, to_right_side = string.match(to, "<sip:(.*)@(.*)") local ruri_left_side, ruri_right_side = string.match(ruri, "sip:(.*)@(.*)") --[[ Search and replace for "To" Header and Request URI --]] to_left_side = string.gsub(to_left_side , "%%20", "") to_left_side = string.gsub(to_left_side , "-", "") to_left_side = string.gsub(to_left_side , "x", "") ruri_left_side = string.gsub(ruri_left_side , "%%20", "") ruri_left_side = string.gsub(ruri_left_side , "-", "") ruri_left_side = string.gsub(ruri_left_side , "x", "") --[[ If the left side of "@" contain only numbers and begin OR not begin with "+", then update the "To" Header and Request URI --]] if string.find(to_left_side, "^+?%d*$") then msg:modifyHeader("To", "<sip:" .. to_left_side .. "@" .. to_right_side) end if string.find(ruri_left_side, "^+?%d*$") then msg:setRequestUri("sip:" .. ruri_left_side .. "@" .. ruri_right_side) end end return M

March 29, 2017

Eric Lavoie