Rewriting SIP headers with Asterisk

I cannot find any documentation or reference on how to rewrite SIP headers in Asterisk.

Need to rewrite Contact header to “international format”, i.e. +45xxxxxx etc. per the instruction of the ITSP.
Also Diversion header has to be in this format, if it occurs in a SIP message.

I know one can use SIP proxies like Kamailio etc, but trying to avoid getting complex.

The ITSP’s instructions are wrong or their system is broken.

The user part of the Contact header is purely for the benefit of the system sending it. Although I don’t think that Asterisk really looks at it, potentially any manipulation of it could cause responses to be ignored.

There is, and should be, no way of changing it, other than by creating, deliberately broken, fork of the source code.

You are totally and completely correct - this “ITSP” is actually a traditional telephone company, and they recently, like 2 years ago, discovered SIP (wow).

I do know what you are saying is right, and they do violate the SIP standard on a few other counts too.
It is quite clear that the Contact header is not a telephone book or registry. Yet when I ask for clarification to that company they say “everybody understands SIP in their own way, and their way is as right as mine”.

As I am stuck with that company for the moment, at this stage, I just would like to know if I can do something in Asterisk with this or not. Asterisk is not a SIP proxy and I find very little in terms of fine grained control of SIP messages. So is there no way?

As this header is managed by the core code, I think there is no way to directly manipulate it, other than to modify the source code. Given that I don’t think Asterisk really uses the user part, I’m not sure how it derives it. I suspect it is the CLID for INVITEs, but I’m not sure how it is derived for REGISTER. You may be able to get the desired result by the way you name SIP devices and extensions, but I’d have to dig into the code to be sure.

Did you try using CallerID(num) for setting the CallerID before doing a Dial() on the provider’s SIP Trunk? That should influence the user part of the Contact header that Asterisk sends.