<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;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@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:1839423230;
mso-list-type:hybrid;
mso-list-template-ids:-338762380 1663062066 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0: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 l0: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 l0: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 l0: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 l0: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 l0: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 l0: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 l0: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 l0: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 Everyone,<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’ve recently just started working with Kamailio – thanks everyone for this amazing software.<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">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.<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">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.<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">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.<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 need to do something like:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:11.0pt"><o:p> </o:p></span></p>
<ul style="margin-top:0cm" type="disc">
<li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><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.<o:p></o:p></span></li><li class="MsoListParagraph" style="margin-left:0cm;mso-list:l0 level1 lfo1"><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.<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">Is there a good, or recommended way to handle this scenario? Maybe something entirely different to changing the presentity_uri?<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’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?<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">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>
<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">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?<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 style="font-size:11.0pt">@@ -466,6 +467,8 @@ request_route {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> # authentication<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> route(AUTH);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ route(REWRITE_PRESENCE);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> # record routing for dialog forming requests (in case they are routed)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> # - remove preloaded route headers<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> remove_hf("Route");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"># Presence server processing<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">route[PRESENCE] {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> if(!is_method("PUBLISH|SUBSCRIBE")) return;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> if(is_method("SUBSCRIBE") && $hdr(Event)=="message-summary") {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> # Asterisk is our voicemail<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> route(TOASTERISK);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> # returns here if no voicemail server is configured<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> sl_send_reply("404", "No voicemail service");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> exit;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#!ifdef WITH_PRESENCE<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> if (!t_newtran()) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> sl_reply_error();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> exit;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> if(is_method("PUBLISH")) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> handle_publish();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> t_release();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> } else if(is_method("SUBSCRIBE")) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> # See REWRITE_PRESENCE - this should have been executed before we get here.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> handle_subscribe();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> t_release();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> exit;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">#!endif<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 style="font-size:11.0pt">+route[REWRITE_PRESENCE] {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ if (is_method("SUBSCRIBE")) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ xlog("Re-writing subscribe to include tenant prefix\n");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # The default presentity_uri needs to be prefixed with<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # the tenant name<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # So re-write the To header <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ route(TENANTINFO);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # Now grab the tenant name.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ $var(subscribe_ru) = "sip:" + $var(tenant_name) + $rU + "@" + $rd;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ xlog("Re-writing SUBSCRIBE To header as: $var(subscribe_ru)\n");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ insert_hf("To: $var(subscribe_ru)\r\n", "From");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ $ru = $var(subscribe_ru);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # Force change immediately: <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # http://www.kamailio.org/wiki/tutorials/faq/main#why_changes_made_to_headers_or<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ msg_apply_changes();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ } else if (is_method("NOTIFY")) {<o:p></o:p></span></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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # We are storing the presentity_uri with a tenant prefix<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # handsets do not expect this, only 101@, 102@ etc... In their BLF configs<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # So this tenant prefix must be removed when building the reply.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ route(TENANTINFO);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ $var(notify_ru) = "sip:" + $(rU{s.substr,$(var(tenant_name){s.len}),0}) + "@" + $rd;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ xlog("Re-writng NOTIFY to use: $var(notify_ru)\n");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ insert_hf("To: $var(notify_ru)\r\n", "From");<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ $ru = $var(notify_ru);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # Force change immediately: <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ # http://www.kamailio.org/wiki/tutorials/faq/main#why_changes_made_to_headers_or<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ msg_apply_changes();<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+ }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">+}<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"><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 for your time.<o:p></o:p></span></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<o:p></o:p></span></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"><span style="color:#0563C1">support@nexusone.com.au</span></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@01D4E415.9317BE80" alt="ttp://quintus.nexusone.com.au/~rhys/nexus1-email-sig.jpg"></span></span><span lang="EN-GB"><o:p></o:p></span></p>
</div>
</body>
</html>