0

I am working on a project where I need to send back 302 reply. Everything seems to work, except I can't remove certain headers, i.e. From, Contact, etc. (I don't want to remove them completely, but rather substitute with my own version of it). I use KEMI with Lua to do so:

KSR.hdr.remove("From")

As I mentioned, this does not work (while other functions from hdr work fine in the same context, namely KSR.hdr.append_to_reply(...).

I decided to look at the Kamailio source code and found following lines of code in kemi.c file:

int sr_kemi_hdr_remove(sip_msg_t *msg, str *hname)
{
    ...
        anchor=del_lump(msg, hf->name.s - msg->buf, hf->len, 0);
        if (anchor==0) {
            LM_ERR("cannot remove hdr %.*s\n", hname->len, hname->s);
            return -1;
        }
    }
    return 1;
}

Looking at the last parameter that del_lump takes, it is of type _hdr_types_t which describes an enum of different header types. Now, in particular to me, there were three headers I was working with:

  • From (type 4)
  • Contact (type 7)
  • Other (type 0)

So my question is, why does that function is hardcoded to take only OTHER headers, but not other ones, i.e. From and Contact? Is that to safeguard from breaking the SIP request (inadvertently removing required headers)?

And as a follow up question, is it even possible to remove From and Contact from reply messages?

mike.tihonchik
  • 6,855
  • 3
  • 32
  • 47
  • 1
    From is not meant to be removed at all, it is used to inditify the dialog with the from-tag. Contact can be removed in theory but it should be replaced by a valid contact header. After all a redirect 302 purpose is to give new target uri using the contact field. Could you precise what you want to do ? Maybe it is possible to modify headers even if removing from and contact is not possible. – tomrtc Dec 22 '21 at 13:21

1 Answers1

1

I assume the 302 is generated by Kamailio, then several headers are copied from the incoming request, like From, To, Call-Id, CSeq. Therefore if you want a different From in the generated reply, change it in the request and then do msg_apply_changes().

Contact headers for redirect (3xx) replies are generated from the destination set of the request (modified R-URI and branches that can be created by append_branch(), lookup("location") etc.).

More headers can be added to the generated replies using append_to_reply().

Note that I gave the name of the functions for the native kamailio.cfg, but you can find them exported to Kemi as well (by core or textops, textopsx modules).

miconda
  • 1,754
  • 11
  • 14