<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:x="urn:schemas-microsoft-com:office:excel" 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=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@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;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.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;}
code
        {mso-style-priority:99;
        font-family:"Courier New";}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></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-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">Hi All,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I have modified this excellent example LUA script (<a href="https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example">https://confluence.freeswitch.org/display/FREESWITCH/Lua+Intercom+example</a>) to return “true” if an
extension is in use and “false” otherwise”. Just FYI: this is great for Cisco phones because an auto-answer (intercom) connection will interrupt the current call unless you block ALL intercom use. With this I can sent intercom if not in use, or send as a
standard call otherwise. My complements to the original chef!<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My request is for someone to explain the pattern matching pattern used in this function:<o:p></o:p></p>
<p class="MsoNormal" style="line-height:15.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:#333333"> function trim (s)</span><span style="font-size:10.5pt;font-family:Consolas;color:#333333"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:15.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:#333333"> return (string.gsub(s, "^%s*(.-)%s*$", "%1"))</span><span style="font-size:10.5pt;font-family:Consolas;color:#333333"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:15.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:#333333"> end</span><span style="font-size:10.5pt;font-family:Consolas;color:#333333"><o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">It takes a string like this:<o:p></o:p></p>
<p class="MsoNormal">“uuid,direction,created,created_epoch,name,state,cid_name,cid_num,ip_addr,dest,application,application_data,dialplan,context,read_codec,read_rate,read_bit_rate,write_codec,write_rate,write_bit_rate,secure,hostname,presence_id,presence_data,callstate,callee_name,callee_num,callee_direction,call_uuid,sent_callee_name,sent_callee_num<o:p></o:p></p>
<p class="MsoNormal">d7bd917c-efca-4333-81f6-692c727069a2,inbound,2014-07-18 11:59:41,1405699181,sofia/external_noauth/4107673000@66.241.96.237,CS_EXECUTE,+14107673000,4107673000,66.241.96.237,BOOKKEEPING,voicemail,default voicemail_ESTA 40,XML,from-internal-ESTA,L16,8000,128000,PCMU,8000,64000,,fs_bfis.bizfocused.com,4107673000@66.241.96.237,,ACTIVE,,,,,,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">1 total.”<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">or just this:<o:p></o:p></p>
<p class="MsoNormal">“<o:p></o:p></p>
<p class="MsoNormal">0 total.”<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">And returns just the number and the “Total.” at the end, like “1 total.” Or “0 total.”<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am fairly regex pattern savvy so I understand pattern matching, but I cannot decipher this LUA pattern. I see it works, but I would like to understand how/why.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks as always,<o:p></o:p></p>
<p class="MsoNormal">Sean <o:p></o:p></p>
</div>
</body>
</html>