Kamailio replacing From and To header in INVITE request

92 Views Asked by At

i use dispatcher to send my invite away to asterisk, but i found problem where i need to replace from and to header, since asterisk knows the other user inside uacreg. i change the header like this

   remove_hf("From");
   remove_hf_re("^From.*");
   append_hf("$var(new_from)", "Call-ID");
   remove_hf("To");
   remove_hf_re("^To.*");
   append_hf("$var(new_to)", "From");

this does remove From and To which are generated from softphone. and replace it with correct From and To. the problem was when 1st dispatcher did not work, and its automatically choose next dispatcher. From and To did which contains earlier dispatcher uri did not get removed. both first time and failover will call same code to replace header and uri before relaying the invite.

Content-Length:  2095
From:  <sip:[email protected]>
To:  <sip:[email protected]>
From:  <sip:[email protected]>
To:  <sip:[email protected]>

i tried removing it and expecting its gone. uac_replace_ would give me something like this, and i don't even know if this works

To:  12345678 12345678 <sip:[email protected]:[email protected]>
From:  userbusera <sip:[email protected]:[email protected]>;tag=smrfmpicup
1

There are 1 best solutions below

0
miconda On

To have different headers for each branch of the request to be sent out, then you have to place the header changing operations in a branch_route{} block. Before a t_relay() in the request_route{} processing you have to arm a branch route like:

...
t_on_branch("HDROPS");
t_relay();
...

And the branch route block defined like:

branch_route[HDROPS] {
  # header changing operations
  ...
}

On failover, inside the failure_route{} processing, the t_on_branch("HDROPS") has to be used again before relaying out again.