<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Calibri",sans-serif;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1467621179;
        mso-list-template-ids:-1710867246;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:36.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:72.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:108.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:144.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:180.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:216.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:252.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:288.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:324.0pt;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        mso-ansi-font-size:10.0pt;
        font-family:Symbol;}
@list l1
        {mso-list-id:1839423230;
        mso-list-type:hybrid;
        mso-list-template-ids:-338762380 1663062066 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l1:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Times New Roman";}
@list l1:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l1:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l1:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l1:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l1:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l2
        {mso-list-id:2042199405;
        mso-list-type:hybrid;
        mso-list-template-ids:240836248 -2009044172 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l2:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Calibri",sans-serif;
        mso-fareast-font-family:Calibri;}
@list l2:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l2:level3
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l2:level4
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l2:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l2:level6
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l2:level7
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l2:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l2:level9
        {mso-level-number-format:bullet;
        mso-level-text:;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-AU" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Hi All,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">I managed to solve my need to re-write NOTIFY packets with help from this thread:
<a href="https://www.mail-archive.com/sr-users@lists.kamailio.org/msg08088.html">
https://www.mail-archive.com/sr-users@lists.kamailio.org/msg08088.html</a><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">This seems to work well. I am re-writing the packets as shown below… I guess my only question is, is this relatively safe/smart to do? I basically copied what our standalone Asterisk PBXes are
 doing in my captures, so I guess so? But I’m not confident enough to say it won’t cause some weird edge case issues. I can only say it works fine with the Snom and Yealink handsets I am testing with. I’m just concerned because it feels a bit like a hack.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">For SUBSCRIBE I re-write:<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l2 level1 lfo4"><span lang="EN-GB" style="font-size:11.0pt">Request URI and To header from 101@ sent by the handset to tenant101@ (to match the SIP username of the handset - tenant101@)<o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">For NOTIFY I re-write:<o:p></o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l2 level1 lfo4"><span lang="EN-GB" style="font-size:11.0pt">From and Contact header to remove the tenant prefix, to go back to 101@ to match the BLF key configuration on the handsets.<o:p></o:p></span></li></ul>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<div>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Any advice would be appreciated on if this is a bad idea, and there’s a better way.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Thanks!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><br>
Rhys Hanrahan<br>
Chief Information Officer<br>
Nexus One Pty Ltd<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><br>
E: <a href="mailto:support@nexusone.com.au" target="_blank">support@nexusone.com.au</a><br>
P: +61 2 9191 0606<br>
W: http://www.nexusone.com.au/<br>
M: PO Box 127, Royal Exchange NSW 1225<br>
A: Level 12 227 Elizabeth St, Sydney NSW 2000</span><span style="font-size:11.0pt;color:black"><o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="color:black">From: </span></b><span style="color:black">sr-users <sr-users-bounces@lists.kamailio.org> on behalf of Rhys Hanrahan <rhys@nexusone.com.au><br>
<b>Reply-To: </b>"Kamailio (SER) - Users Mailing List" <sr-users@lists.kamailio.org><br>
<b>Date: </b>Tuesday, 26 March 2019 at 8:56 pm<br>
<b>To: </b>"sr-users@lists.kamailio.org" <sr-users@lists.kamailio.org><br>
<b>Subject: </b>[SR-Users] Adding presentity_uri prefix for multi-tenanted presence/dialoginfo configuration<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
</div>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Hi Everyone,</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">I’ve recently just started working with Kamailio – thanks everyone for this amazing software.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Like many people, I’m in the process of trying to put Kamailio in-front of Asterisk to allow it to scale out, and my plan is for Kamailio to take over registrations, usrloc and presence/dialoginfo,
 as we’ve had issues where handsets are failing to get BLF updates/notifys, so I am hoping a couple of Kamailio boxes can scale better in this regard. DMQ is particularly exciting in how it will allow me to build a truly distributed platform. But I’m struggling
 to get presence to work the way I need it to.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Our environment is multi-tenanted, but we do not (and can’t really) use multi-domains. Instead, we prefix the SIP usernames with the “tenant name” such as tenanta101 and tenantb101. My problem
 is that all the BLFs are configured for 101@PBX with no tenant name in the User part of the URI so that internal dialing and call pickup will work. Because in Asterisk we use “subscribecontext” this hasn’t been a problem in the past – Asterisk knows for subscriptions
 coming from that handset that it belongs to that tenant’s context in the dialplan and they are “isolated”, so having handsets subscribe as 101@ in their request URI was never a problem. Of course, with Kamailio I don’t have subscribecontext, and my main issue
 is that the “presentity_uri” being stored is 101@ while each of the SIP accounts of the handsets are registered as tenenata101@, and as such, no NOTIFYs are sent by Kamailio because it thinks that there are no watchers for the presentity_uri.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">If I change the SIP account username to 101 to match the BLF key, NOTIFYs are sent as expected. But then this breaks call pickup and internal dialing using the BLF keys. I would rather handle
 this in Kamailio than in Asterisk and having to re-configure the BLF keys for hundreds of handsets.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">I need to do something like:</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo3"><span lang="EN-GB" style="font-size:11.0pt">When a SUBSCRIBE comes in, I need to prefix presentity_uri with the tenant name so the subscription changes from 101@ to tenanta101@ in
 the active_watchers table.</span><o:p></o:p></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l1 level1 lfo3"><span lang="EN-GB" style="font-size:11.0pt">When Kamailio generates a NOTIFY, the notify would be built based on presentity_uri and would come out as tenanta101@, but the phone’s BLFs
 are configured for 101@ so I would need to *<b>remove</b>* the tenant prefix before sending out the notify.</span><o:p></o:p></li></ul>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Is there a good, or recommended way to handle this scenario? Maybe something entirely different to changing the presentity_uri?</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">I’ve written the following config to re-write the request URI and To field in any incoming subscribe requests, and successfully got the active_watchers table to store a presentity_uri containing
 my tenant prefix. But the problem I am having is that I can’t figure out how to modify the NOTIFY packets before they are sent – and looking at cfgtrace, it seems I might not be able to?</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">My “standard” presence + dialoginfo configuration was taken from here as a starting point:
<a href="https://kb.asipto.com/kamailio:presence:k43-blf">https://kb.asipto.com/kamailio:presence:k43-blf</a>
</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Here is what I have so far in terms of trying to make my modifications – any guidance would be greatly appreciated. It feels like there’s probably a better way to do this than re-writing critical
 headers like To and Request URI?</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">@@ -466,6 +467,8 @@ request_route {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        # authentication</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        route(AUTH);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+       route(REWRITE_PRESENCE);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        # record routing for dialog forming requests (in case they are routed)</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        # - remove preloaded route headers</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        remove_hf("Route");</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"># Presence server processing</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">route[PRESENCE] {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        if(!is_method("PUBLISH|SUBSCRIBE")) return;</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        if(is_method("SUBSCRIBE") && $hdr(Event)=="message-summary") {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                # Asterisk is our voicemail</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                route(TOASTERISK);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                # returns here if no voicemail server is configured</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                sl_send_reply("404", "No voicemail service");</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                exit;</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        }</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#!ifdef WITH_PRESENCE</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        if (!t_newtran()) {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                sl_reply_error();</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                exit;</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        }</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        if(is_method("PUBLISH")) {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                handle_publish();</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                t_release();</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        } else if(is_method("SUBSCRIBE")) {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                # See REWRITE_PRESENCE - this should have been executed before we get here.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                handle_subscribe();</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">                t_release();</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        }</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">        exit;</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#!endif</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+route[REWRITE_PRESENCE] {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+       if (is_method("SUBSCRIBE")) {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               xlog("Re-writing subscribe to include tenant prefix\n");</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                # The default presentity_uri needs to be prefixed with</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                # the tenant name</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               # So re-write the To header </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                route(TENANTINFO);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                # Now grab the tenant name.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                $var(subscribe_ru) = "sip:" + $var(tenant_name) + $rU + "@" + $rd;</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               xlog("Re-writing SUBSCRIBE To header as: $var(subscribe_ru)\n");</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                insert_hf("To: $var(subscribe_ru)\r\n", "From");</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               $ru = $var(subscribe_ru);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               # Force change immediately: </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               # http://www.kamailio.org/wiki/tutorials/faq/main#why_changes_made_to_headers_or</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                msg_apply_changes();</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+       } else if (is_method("NOTIFY")) {</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               xlog("Re-writing NOTIFY to remove tenant prefix\n"); # This code block does not get executed right now.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               # We are storing the presentity_uri with a tenant prefix</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               # handsets do not expect this, only 101@, 102@ etc... In their BLF configs</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               # So this tenant prefix must be removed when building the reply.</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                route(TENANTINFO);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               $var(notify_ru) = "sip:" + $(rU{s.substr,$(var(tenant_name){s.len}),0}) + "@" + $rd;</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               xlog("Re-writng NOTIFY to use: $var(notify_ru)\n");</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                insert_hf("To: $var(notify_ru)\r\n", "From");</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                $ru = $var(notify_ru);</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+               # Force change immediately: </span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                # http://www.kamailio.org/wiki/tutorials/faq/main#why_changes_made_to_headers_or</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+                msg_apply_changes();</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+       }</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+}</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"> </span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt">Thanks for your time.</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt;color:black"><br>
Rhys Hanrahan<br>
Chief Information Officer<br>
Nexus One Pty Ltd</span><o:p></o:p></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt;color:black"><br>
E: <a href="mailto:support@nexusone.com.au" target="_blank">support@nexusone.com.au</a><br>
P: +61 2 9191 0606<br>
W: http://www.nexusone.com.au/<br>
M: PO Box 127, Royal Exchange NSW 1225<br>
A: </span><span lang="EN-GB" style="font-size:11.0pt">Level 12 227 Elizabeth St<span style="color:black">, Sydney NSW 2000<br>
<br>
<img border="0" width="280" height="73" style="width:2.9166in;height:.7604in" id="Picture_x0020_1" src="cid:image001.jpg@01D4EA47.B1735410" alt="ttp://quintus.nexusone.com.au/~rhys/nexus1-email-sig.jpg"></span></span><o:p></o:p></p>
</div>
</body>
</html>