[asterisk-users] How to append custom option to Contact: header on outgoing SIP INVITE msgs?

Bob Beers bob.beers at gmail.com
Fri Nov 19 08:19:13 CST 2010


On Fri, Nov 5, 2010 at 10:58 AM, Bob Beers <bob.beers at gmail.com> wrote:
> Hi list,
>
> My need is to append a site specific parameter to the
>  Contact: header on all INVITEs exiting * via a SIP trunk.
> I'd like it to look something like this:
>
> Contact: <bob:3125551212 at 10.10.10.10;SITE-ID=us.here>
>
> where SITE-ID=us.here is set in a config file that * parses on
>  startup.  Or in a Dial() command option? Or I don't care exactly
>  how. :-)
>
> It is possible to affect the Contact: header via a line in sip.conf:
>  register =>  toronto:welcome at 192.168.1.101/contact
> but I can't get it to also accept any ;X=Y params for the
> contact.
>
> I can add a custom Contact header in the dialplan with SipAddHeader,
>  but then I have two.  SipRemoveHeader only removes headers
>  previously added by SipAddHeader, so no luck there.
>
> I have googled, and searched the asterisk-users mailing list archives
>  and not yet found a solution.  I did see some work back in 2004
>  (issues 732 and 777) which mentioned not stripping contact header
>  parameters from arriving requests/registrations, but nothing about
>  creating any such parameters.
>
> Thanks for any help/hints,

Am I on the wrong list?

I have not noticed any replies, so I have moved forward with this idea:

# cat redhat/SOURCES/asterisk-1.8.0-beta2-Contactoption-bbeers03.patch
--- asterisk-1.8.0-beta2.orig/channels/chan_sip.c       2010-07-26
15:59:03.000000000 -0400
+++ asterisk-1.8.0-beta2/channels/chan_sip.c    2010-11-05
12:18:53.000000000 -0400
@@ -722,6 +755,7 @@ static unsigned int global_cos_video;
 static unsigned int global_cos_text;     /*!< 802.1p class of service
for text RTP packets */
 static unsigned int recordhistory;       /*!< Record SIP history. Off
by default */
 static unsigned int dumphistory;         /*!< Dump history to verbose
before destroying SIP dialog */
+static char global_contactoption[AST_MAX_EXTENSION];    /*!< string
to append to Contact: for the SIP channel */
 static char global_useragent[AST_MAX_EXTENSION];    /*!< Useragent
for the SIP channel */
 static char global_sdpsession[AST_MAX_EXTENSION];   /*!< SDP session
name for the SIP channel */
 static char global_sdpowner[AST_MAX_EXTENSION];     /*!< SDP owner
name for the SIP channel */
@@ -10936,12 +12018,14 @@ static void extract_uri(struct sip_pvt *
 static void build_contact(struct sip_pvt *p)
 {
        if (p->socket.type == SIP_TRANSPORT_UDP) {
-               ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten,
-                       ast_strlen_zero(p->exten) ? "" : "@",
ast_sockaddr_stringify(&p->ourip));
+               ast_string_field_build(p, our_contact,
"<sip:%s%s%s%s%s>", p->exten,
+                       ast_strlen_zero(p->exten) ? "" : "@",
ast_sockaddr_stringify(&p->ourip),
+                       ast_strlen_zero(global_contactoption) ? "" :
";", global_contactoption);
        } else {
-               ast_string_field_build(p, our_contact,
"<sip:%s%s%s;transport=%s>", p->exten,
+               ast_string_field_build(p, our_contact,
"<sip:%s%s%s;transport=%s%s%s>", p->exten,
                        ast_strlen_zero(p->exten) ? "" : "@",
ast_sockaddr_stringify(&p->ourip),
-                       get_transport(p->socket.type));
+                       get_transport(p->socket.type),
+                       ast_strlen_zero(global_contactoption) ? "" :
";", global_contactoption);
        }
 }

@@ -26403,6 +28341,8 @@ static int reload_config(enum channelrel
                        global_relaxdtmf = ast_true(v->value);
                } else if (!strcasecmp(v->name, "vmexten")) {
                        ast_copy_string(default_vmexten, v->value,
sizeof(default_vmexten));
+               } else if (!strcasecmp(v->name, "contactoption")) {
+                       ast_copy_string(global_contactoption,
v->value, sizeof(global_contactoption));
                } else if (!strcasecmp(v->name, "rtptimeout")) {
                        if ((sscanf(v->value, "%30d",
&global_rtptimeout) != 1) || (global_rtptimeout < 0)) {
                                ast_log(LOG_WARNING, "'%s' is not a
valid RTP hold time at line %d.  Using default.\n", v->value,
v->lineno);


Then I add to the [general] section of sip.conf,

contactoption=SITE-ID=us.here

and it works for me, but I still wonder if there is a better way.

-- 
Thanks,
-Bob Beers



More information about the asterisk-users mailing list