<div dir="ltr"><div><div><div><div><div><div>Hi Michael,<br><br></div>Actually, here is what happens:<br><br></div>Context: XML dialplan with the following extensions:<br> <extension name="limit_exceeded"><br> <condition field="destination_number" expression="^limit_exceeded$"><br> <action application="respond" data="503"/><br> </condition><br> </extension><br> <extension name="outgoing_call"><br> <condition><br> <action application="lua" data="dialplans/caller_script.lua"/><br> </condition><br> </extension><br></div><div><br>1/ a call is started, the second extension entry in the XML dialplan matches and the action starts the lua script<br></div>2/ after having set some (a lot actually) variables, here is the code part for checking call-rate limits:<br>-- Security (to avoid outage): limit CAPS<br>-- hash backend is needed when using interval<br>-- 2 call attempts per 10 seconds here<br>logz("[Calls limit] Checking caps for " .. billedcaller)<br>session:execute("limit", "hash " .. billedcaller .. " caps 2/10 !REQUESTED_CHAN_UNAVAIL")<br>rate_var = session:getVariable("limit_rate_" .. billedcaller .. "_caps")<br>if not rate_var then<br> logz("[Calls limit] CAPS limit reached for " .. billedcaller .. ", aborting the dialplan.")<br> return<br>end<br></div>3/ after this code part, a lot of processing is done (for instance checking call restrictions calling external web services and so on), it's like 600 lines of lua there<br></div>4/ in the end, the session:execute bridge app is run<br><br></div>At 2/, when limit is exceeded, I see in the log:<br><div><div><div><div><div><div>2015-03-13 12:22:40.454660 [INFO] switch_cpp.cpp:1328 * (caller/0) # 7a16c525263a8bb740517f5a28552016@trunkinge.voip * [Calls limit] Checking caps for asteriskrd@trunkinge.voip<br>EXECUTE sofia/internal_auth/asteriskrd@trunkinge.voip limit(hash asteriskrd@trunkinge.voip caps 2/10 !REQUESTED_CHAN_UNAVAIL)<br>2015-03-13 12:22:40.454660 [DEBUG] switch_limit.c:126 incr called: asteriskrd@trunkinge.voip_caps max:2, interval:10<br>2015-03-13 12:22:40.454660 [INFO] mod_hash.c:176 Usage for asteriskrd@trunkinge.voip_caps exceeds maximum rate of 2/10s, now at 3<br>2015-03-13 12:22:40.454660 [INFO] switch_cpp.cpp:1328 * (caller/0) # 7a16c525263a8bb740517f5a28552016@trunkinge.voip * [Calls limit] CAPS limit reached for asteriskrd@trunkinge.voip, aborting the dialplan.<br><br></div><div>and the a-leg is successfully hangup.<br></div><div><br></div><div>But here, 3/ and 4/ are aborting only because of that code part:<br>rate_var = session:getVariable("limit_rate_" .. billedcaller .. "_caps")<br>if not rate_var then<br> logz("[Calls limit] CAPS limit reached for " .. billedcaller .. ", aborting the dialplan.")<br> return<br>end<br><br></div><div>It works, but I'm pretty sure that it is not the proper way to do it.<br><br></div><div>If I remove that code part, even though the a-leg is hangup because of the leg being transferred to 'limit_exceeded', the rest of the dialplan is still processed, even though the call is aborted.<br><br></div><div>I'd like to be able to catch right after doing session:execute limit app, the return of the command.<br></div><div>If the call is transferred to 'limit_exceeded', then I'd like to abort the rest of the dialplan execution.<br><br></div><div>I have to admit I might be missing something here therefore if you can help me, that'd be amazing.<br></div><div>Thanks in advance<br></div><div>Florent<br></div><div><br></div></div></div></div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-03-12 21:28 GMT+01:00 Michael S Collins <span dir="ltr"><<a href="mailto:msc@freeswitch.org" target="_blank">msc@freeswitch.org</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="#0563C1" vlink="#954F72" lang="EN-US"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Some context here would be helpful. Can you pastebin your Lua script, or at least the relevant lines that demonstrate what is happening? Also, when you say that the rest of the Lua dialplan is still processed, what does that mean? <u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">-MC<u></u><u></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> <a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a> [mailto:<a href="mailto:freeswitch-users-bounces@lists.freeswitch.org" target="_blank">freeswitch-users-bounces@lists.freeswitch.org</a>] <b>On Behalf Of </b>Florent Krieg<br><b>Sent:</b> Thursday, March 12, 2015 11:43 AM<br><b>To:</b> FreeSWITCH Users Help<br><b>Subject:</b> [Freeswitch-users] Limit application usage in Lua<u></u><u></u></span></p><div><div class="h5"><p class="MsoNormal"><u></u> <u></u></p><div><div><div><div><div><div><div><div><div><div><div><div><p class="MsoNormal" style="margin-bottom:12.0pt">Hi all,<u></u><u></u></p></div></div><p class="MsoNormal" style="margin-bottom:12.0pt">I wanted to implement call rate limits using this Lua instruction:<br>session:execute("limit", "hash " .. billedcaller .. " caps 10/1 !REQUESTED_CHAN_UNAVAIL")<u></u><u></u></p></div><p class="MsoNormal" style="margin-bottom:12.0pt">It is actually working, but the rest of the Lua dialplan is still processed, which is a problem in my case.<u></u><u></u></p></div><p class="MsoNormal" style="margin-bottom:12.0pt">I made a dirty but quick workaround, looking like this:<br>rate_var = session:getVariable("limit_rate_" .. billedcaller .. "_caps")<br>if not rate_var then<br> logz("[Calls limit] CAPS limit reached for " .. billedcaller .. ", aborting the dialplan.")<br> return<br>end<u></u><u></u></p></div><p class="MsoNormal">How can it be done properly?<u></u><u></u></p></div><p class="MsoNormal">Is there a way to be able to get the result of the 'limit' app call?<u></u><u></u></p></div><p class="MsoNormal" style="margin-bottom:12.0pt">Or shall I check the status of the a-leg just after to decide to process the rest of the dialplan or not?<u></u><u></u></p></div><p class="MsoNormal" style="margin-bottom:12.0pt">I know that this issue doesn't occur in a 'pure' XML dialplan, but I'm trying to find a solution for my Lua-only dialplan.<u></u><u></u></p></div><p class="MsoNormal">Thanks in advance if you have any idea.<u></u><u></u></p></div><p class="MsoNormal" style="margin-bottom:12.0pt">I'm willing to try any possible solution you would think about!<u></u><u></u></p></div><p class="MsoNormal">Florent<u></u><u></u></p><div><div><div><div><div><div><div><div><p class="MsoNormal" style="margin-bottom:12.0pt"><u></u> <u></u></p></div></div></div></div></div></div></div></div></div></div></div></div></div><br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br></blockquote></div><br></div>