AnsweredAssumed Answered

Modify Request-URI, To Header, From Header and Contact Header

Question asked by rschuknecht on Aug 4, 2015
Latest reply on Aug 7, 2015 by rschuknecht

Hello all,

 

first of all i am very new to SIP Normalization Scripts and LUA programming.

 

I am trying to modify the Request-URI, To Header, From Header and Contact Header with a SIP Normalization script. But, without much luck so far and i am looking for any help or tip to get my script working.

 

I am able to modify the Requst-URI and the To Header one at a time but not all of them in one go.

 

This is my script which i am working on:

 

M = {}

trace.enable()

function M.inbound_INVITE(msg)

    local mwi_number_length = scriptParameters.getValue("MWI-Number-Length") -- MWI-Number-Length equals to 7

  

-- Get the SIP Request

  

    local method, ruri, version = msg:getRequestLine()  

  

-- Adjust SIP Request URI

    -- Get the first digits of the Request URI to form the new Called number

  

        local dnis_start = string.find(ruri, "%d")

        local dnis_end = dnis_start+mwi_number_length-1

        local dnis = string.sub(ruri, dnis_start, dnis_end)

  

    -- Get the Right Hand Side from the Request URI

  

        local host_start = string.find(ruri, "\@")

        local host_end = string.find(ruri, "%d", -1)

        local host = string.sub(ruri, host_start, host_end)

        local ruri_new = "sip:" .. dnis .. host

  

    -- Tracing

        trace.format("New DNIS is %s:%s", dnis)

        trace.format("New RURI is %s:%s", ruri_new)

  

    -- Set the new Request URI

  

        msg:setRequestUri(ruri_new)

      

      

end

trace.enable()

function M.inbound_INVITE(msg)

    local mwi_number_length = scriptParameters.getValue("MWI-Number-Length")  

          

-- Adjust SIP To Header

    -- Get the SIP To Header

  

        local to = msg:getHeader("To")

  

    -- Extract DNIS from SIP To Header

      

        local to_dnis_start = string.find(to, "%d")

        local to_dnis_end = to_dnis_start+mwi_number_length-1

        local to_dnis_new = string.sub(to, to_dnis_start, to_dnis_end)

 

    -- Extract RHS from SIP To Header

  

        local to_rhs = string.match(to, "\@.*")

 

    -- Create New SIP To Header

  

        local to_new = "<sip:" .. to_dnis_new .. to_rhs

      

    -- Tracing

        trace.format("New To DNIS is %s:%s", to_dnis_new)

        trace.format("New To Header is %s:%s", to_new)      

          

    -- Set the new SIP To Header

      

        msg:modifyHeader("To", to_new)

      

 

end

return M

 

This is the original SIP Invite:

 

INVITE sip:91249874955566677788@10.123.255.145:5060;transport=udp SIP/2.0

Via: SIP/2.0/UDP 10.122.185.5:5060;branch=z9hG4bKQv9ZAYlmXawDkxKenpWp9g~~21

Max-Forwards: 70

To: <sip:91249874955566677788@10.123.255.145:5060>

From: <sip:9124980@10.122.185.5>;tag=ds2f74cdd

Call-ID: 143871259893526@10.122.185.5

CSeq: 100 INVITE

Content-Length: 190

Contact: <sip:9124980@10.122.185.5:5060;transport=udp>

Content-Type: application/sdp

Allow: INVITE, BYE, CANCEL, ACK, REFER, SUBSCRIBE, NOTIFY, INFO

Cisco-Gcid: F9F41197-014E-1000-5EE4-BDDE9F0E867D

 

The modified SIP Invite should look like this:

 

INVITE sip:9124987@10.123.255.145:5060;transport=udp SIP/2.0

Via: SIP/2.0/UDP 10.122.185.5:5060;branch=z9hG4bKQv9ZAYlmXawDkxKenpWp9g~~21

Max-Forwards: 70

To: <sip:9124987@10.123.255.145:5060>

From: <sip:4955566677788@10.122.185.5>;tag=ds2f74cdd

Call-ID: 143871259893526@10.122.185.5

CSeq: 100 INVITE

Content-Length: 190

Contact: <sip:4955566677788@10.122.185.5:5060;transport=udp>

Content-Type: application/sdp

Allow: INVITE, BYE, CANCEL, ACK, REFER, SUBSCRIBE, NOTIFY, INFO

Cisco-Gcid: F9F41197-014E-1000-5EE4-BDDE9F0E867D

 

 

Any help or tip is welcome!

 

/Robert

Outcomes