<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 12pt;
font-family:Calibri
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>Hello<div><br></div><div>You are amazing !!</div><div><br></div><div>Your example work perfect, but I have to work with mine cfg, because when I use part of Your route into my config it doesn't work like it should.</div><div>I think I have some problems with dialog module, because when I start Your script I get:</div><div><br></div><div>Apr 28 09:47:31 kamailio /usr/local/sbin/kamailio[3060]: INFO: <script>: dialog started</div><div><br></div><div>I don't see it using my config, so it looks like dialog module doesn't work in my config file in proper way.</div><div>I will let You know when I find a bug in my script.</div><div><br></div><div>Now when I have working example it will be easier.</div><div><br></div><div>Greetings</div><div>Andrzej Ciupek<br><br><div><hr id="stopSpelling">Date: Sun, 27 Apr 2014 21:29:34 -0500<br>Subject: Re: [SR-Users] cnxcc<br>From: carlos.ruizdiaz@gmail.com<br>To: andrzej.ciupek@hotmail.com<br>CC: sr-users@lists.sip-router.org<br><br><div dir="ltr">Kelvin,<div><br></div><div>can you update your copy and try again? Maybe your problem was related to this, or maybe not. In either case, I will try to reproduce your issue later this week :).</div><div><br></div>
<div>Regards,</div></div><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">On Sun, Apr 27, 2014 at 9:27 PM, Carlos Ruiz Díaz <span dir="ltr"><<a href="mailto:carlos.ruizdiaz@gmail.com" target="_blank">carlos.ruizdiaz@gmail.com</a>></span> wrote:<br>
<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">Hi Andrzej,<div><br></div><div>I found a deadlock situation using the script you posted, thanks to an unusual way of using the functions that the module exports. </div>
<div><br></div><div>About the script itself: I found a few inconsistencies that would have caused a problem with handing the calls even if there was no bug in the software. For example:</div>
<div><br></div><div>- if you want to set the maximum amount of calls per user, use the function "<span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:15px;white-space:pre-wrap;">cnxcc_set_max_channel"</span></div>

<div><span style="color:rgb(51,51,51);font-family:Consolas,'Liberation Mono',Courier,monospace;font-size:15px;white-space:pre-wrap;"><br></span></div><div>- the "call-shutdown" event route is only executed if the call runs out of credit, never for "normal call clearing". For that, use "dialog:end" or "dialog:failed" instead.<br>

</div><div><br></div><div>- you cannot access "$var(client)" from outside the process that created it. This means that when the call is killed, "$var(client)" will have a NULL value since this event is processed by a completely different process. If you want to have this information available everywhere, use a shared memory variable instead ($sht).</div>

<div><br></div><div>I created a sample script [1] that applies your requirements in a slightly different way:</div><div><br></div><div>- it authorizes the call by checking the balance</div><div>- it kills the call when the credit is over</div>

<div>- it doesn't allow more than one call per customer</div><div><br></div><div>[1] <a href="https://gist.github.com/caruizdiaz/11359122" target="_blank">https://gist.github.com/caruizdiaz/11359122</a></div><div><br>
</div><div>In this example I used a shared memory variable, to give you an idea of how to persist the customer's ID across processes. </div>
<div><br></div><div>Regards,</div><div>Carlos</div><div><br></div><div>- </div><div><br></div><div><div style="font-family:Calibri,'Segoe UI',Meiryo,'Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic',sans-serif;font-size:16.363636016845703px;">

<br></div></div></div><div class="ecxHOEnZb"><div class="h5"><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">On Sat, Apr 26, 2014 at 10:34 AM, Carlos Ruiz Díaz <span dir="ltr"><<a href="mailto:carlos.ruizdiaz@gmail.com" target="_blank">carlos.ruizdiaz@gmail.com</a>></span> wrote:<br>

<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;"><div dir="ltr">I did find a bug, using your config script, I will fix it this weekend. Try with this configuration file [1].<div>

<br></div><div>[1] <a href="https://gist.github.com/caruizdiaz/11323017" target="_blank">https://gist.github.com/caruizdiaz/11323017</a><br>
</div><div><br></div><div>In summary, you can't use more than one check mechanisms. It has to be credit, time or channels, exclusively. </div><div><br></div><div>Also, I need to test your config with Kam 4.1. I am using the trunk version.</div>


<div><br></div><div>Regards,</div></div><div><div><div class="ecxgmail_extra"><br><br><div class="ecxgmail_quote">On Sat, Apr 26, 2014 at 10:23 AM, Andrzej Ciupek <span dir="ltr"><<a href="mailto:andrzej.ciupek@hotmail.com" target="_blank">andrzej.ciupek@hotmail.com</a>></span> wrote:<br>


<blockquote class="ecxgmail_quote" style="border-left:1px #ccc solid;padding-left:1ex;">



<div>
<div>
<div style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;">Yes. I want prepaid subscribers be able to create only one channel to prevent frauds for simultaneous calls.<br>
<br>
Greetings<span><font color="#888888"><br>
Andrzej Ciupek </font></span></div><span><font color="#888888">
</font></span></div><span><font color="#888888">
<div dir="ltr">
<hr>
<span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;FONT-WEIGHT:bold;">Od:
</span><span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;"><a href="mailto:carlos.ruizdiaz@gmail.com" target="_blank">Carlos Ruiz Díaz</a></span><br>
<span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;FONT-WEIGHT:bold;">Wysłano:
</span><span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;">‎2014-‎04-‎26 16:42</span><br>
<span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;FONT-WEIGHT:bold;">Do:
</span><span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;"><a href="mailto:andrzej.ciupek@hotmail.com" target="_blank">Andrzej Ciupek</a></span><br>
<span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;FONT-WEIGHT:bold;">DW:
</span><span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;"><a href="mailto:sr-users@lists.sip-router.org" target="_blank">Kamailio (SER) - Users Mailing List</a></span><br>
<span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;FONT-WEIGHT:bold;">Temat:
</span><span style="FONT-SIZE:11pt;FONT-FAMILY:Calibri,sans-serif;">Re: [SR-Users] cnxcc</span><br>
<br>
</div></font></span><div><div>
<div>
<div dir="ltr">Hi Andrzej,
<div><br>
</div>
<div>are you trying to setup cnxcc to check both credit and maximum simultaneous calls?</div>
<div><br>
</div>
<div>Regards,</div>
<div><br>
</div>
</div>
<div><br>
<br>
<div>On Sat, Apr 26, 2014 at 9:26 AM, Andrzej Ciupek <span dir="ltr">
<<a href="mailto:andrzej.ciupek@hotmail.com" target="_blank">andrzej.ciupek@hotmail.com</a>></span> wrote:<br>
<blockquote style="border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr">
<div dir="ltr" style="font-family:'Calibri','Segoe UI','Meiryo','Microsoft YaHei UI','Microsoft JhengHei UI','Malgun Gothic','sans-serif';font-size:12pt;">
<div>Hello</div>
<div><br>
</div>
<div>I’am using default config with options from an example. It looks like event route isn’t execuded after hangup.</div>
<div><br>
</div>
<div>Apr 26 16:26:14 kamailio /usr/local/sbin/kamailio[4611]: INFO: <script>: 1000 has 1 call(s)<br>
Apr 26 16:26:15 kamailio /usr/local/sbin/kamailio[4611]: INFO: <script>: 1000 has 1 call(s)<br>
Apr 26 16:26:16 kamailio /usr/local/sbin/kamailio[4611]: INFO: <script>: 1000 has 1 call(s)<br>
Apr 26 16:26:17 kamailio /usr/local/sbin/kamailio[4611]: INFO: <script>: 1000 has 1 call(s)<br>
Apr 26 16:26:18 kamailio /usr/local/sbin/kamailio[4611]: INFO: <script>: 1000 has 1 call(s)<br>
Apr 26 16:26:19 kamailio /usr/local/sbin/kamailio[4611]: INFO: <script>: 1000 has 1 call(s)<br>
Apr 26 16:26:20 kamailio /usr/local/sbin/kamailio[4611]: INFO: <script>: 1000 has 1 call(s)<br>
Apr 26 16:26:20 kamailio /usr/local/sbin/kamailio[4604]: INFO: <script>: Setting up money based credit control<br>
Apr 26 16:26:20 kamailio /usr/local/sbin/kamailio[4604]: INFO: <script>: Setting up channel based credit control<br>
Apr 26 16:26:20 kamailio /usr/local/sbin/kamailio[4604]: INFO: <script>: CNXCC ROUTE: 1000 has 2 call(s)<br>
</div>
<div><br>
</div>
<div>kamailio.cfg</div>
<div>…</div>
<div>…</div>
<div># ----- prepaid call controll -----</div>
<div>
<div><br>
</div>
<div>#!define DLG_FLAG 28<br>
#!define CC_FLAG 29</div>
<div><br>
</div>
</div>
<div>loadmodule "dialog.so"
<div><br>
modparam("dialog", "hash_size", 2048)<br>
modparam("dialog", "default_timeout", 3600)<br>
modparam("dialog", "db_mode", 0)<br>
modparam("dialog", "dlg_flag", DLG_FLAG)</div>
</div>
<div><br>
</div>
<div>modparam("rtimer", "timer", "name=ta;interval=1;mode=1;")<br>
modparam("rtimer", "exec", "timer=ta;route=SHOW_CHANNEL_COUNT")</div>
<div><br>
</div>
<div>loadmodule "cnxcc.so"
<div><br>
modparam("cnxcc", "dlg_flag", CC_FLAG)<br>
modparam("cnxcc", "credit_check_period", 1) #check every 1 second<br>
</div>
</div>
<div><br>
</div>
<div>…</div>
<div>…</div>
<div>…</div>
<div>route {</div>
<div>…</div>
<div>…</div>
<div> if (!allow_source_address("2") and !allow_source_address("1")){<br>
        route(CNXCC);<br>
        route(PSTN);<br>
        }<br>
</div>
<div>…</div>
<div>}<br>
</div>
<div>
<div><br>
</div>
<div>route[CNXCC]<br>
{</div>
<div><br>
</div>
<div>        $var(client)            = "1000";</div>
<div>
<div><br>
</div>
<div>        xlog("L_INFO", "Setting up money based credit control");</div>
<div><br>
</div>
<div>        $var(credit)            = "10"; # 10$ of credit<br>
        $var(cost_per_sec)      = "1";  # 1$ per sec<br>
        $var(i_pulse)           = "1";  # 1$ to establish the call<br>
        $var(f_pulse)           = "1";  # 1$ per second</div>
<div><br>
</div>
<div>        # if only one call is established, that call should last 9 seconds.</div>
<div><br>
</div>
<div>        if (!cnxcc_set_max_credit("$var(client)",<br>
                                  "$var(credit)",<br>
                                  "$var(cost_per_sec)",<br>
                                  "$var(i_pulse)",<br>
                                  "$var(f_pulse)")) {<br>
                xlog("Error setting up credit control");<br>
                return;<br>
        }<br>
</div>
</div>
<div>        $var(count)     = -1;</div>
<div><br>
</div>
<div>        if (!cnxcc_get_channel_count("$var(client)", "$var(count)")) {<br>
                xlog("Error getting customer's channel count");<br>
        }</div>
<div><br>
</div>
<div>        xlog("L_INFO", "CNXCC ROUTE: $var(client) has $var(count) call(s)");</div>
<div><br>
</div>
<div>        if ($var(retcode) < -1) {<br>
                xlog("Too many channels for customer");<br>
                sl_send_reply(403, "Forbidden");</div>
<div><br>
</div>
<div>                if (!cnxcc_terminate_all("$var(client)")) {<br>
                        xlog("Error terminating customer's calls");<br>
                } else {<br>
                        xlog("Terminating customer's call");<br>
                }</div>
<div><br>
</div>
<div>                exit;<br>
        }<br>
}</div>
<div><br>
</div>
<div>route[SHOW_CHANNEL_COUNT]<br>
{<br>
        $var(count) = @cnxcc.channels["1000"].count;<br>
        xlog("L_INFO", "1000 has $var(count) call(s)");<br>
}</div>
<div><br>
</div>
<div>event_route[dialog:failed]<br>
{<br>
        xlog("dialog failed");<br>
}</div>
<div><br>
</div>
<div>event_route[cnxcc:call-shutdown]<br>
{<br>
        xlog("L_INFO", "Shutting down channel by callcontroll");<br>
        xlog("L_INFO", "[$ci]: call killed");<br>
        $var(count)     = $var(count)-1;<br>
        if (!cnxcc_get_channel_count("$var(client)", "$var(count)")) {<br>
                xlog("Error getting customer's channel count");<br>
        }<br>
        xlog("L_INFO", "CNXCC ROUTE: $var(client) has $var(count) call(s)");<br>
        # perform some kind of notification, database update, email sending, etc<br>
}<br>
</div>
<div><br>
</div>
<div>Greetings</div>
<div>Andrzej Ciupek</div>
<div><br>
</div>
</div>
<div style="padding-top:5px;border-top-color:rgb(229,229,229);border-top-width:1px;border-top-style:solid;">
<div><font face=" 'Calibri', 'Segoe UI', 'Meiryo', 'Microsoft YaHei UI', 'Microsoft JhengHei UI', 'Malgun Gothic', 'sans-serif'" style="line-height:15pt;letter-spacing:0.02em;font-family:"Calibri","Segoe UI","Meiryo","Microsoft YaHei UI","Microsoft JhengHei UI","Malgun Gothic","sans-serif";font-size:12pt;"><b>Od:</b> <a href="mailto:carlos.ruizdiaz@gmail.com" target="_blank">Carlos
 Ruiz Díaz</a><br>
<b>Wysłano:</b> ‎sobota‎, ‎26‎ ‎kwietnia‎ ‎2014 ‎15‎:‎19<br>
<b>Do:</b> <a href="mailto:sr-users@lists.sip-router.org" target="_blank">Kamailio (SER) - Users Mailing List</a>,
<a href="mailto:andrzej.ciupek@hotmail.com" target="_blank">Andrzej Ciupek</a></font></div>
</div>
<div>
<div>
<div><br>
</div>
<div dir="">
<div dir="ltr">Hi,
<div><br>
</div>
<div>sorry guys, I forgot about this. I will make my own tests and post the results.</div>
<div><br>
</div>
<div>Andrzej, can you post the configuration file you are using?</div>
<div><br>
</div>
<div>Regards,</div>
<div>Carlos</div>
</div>
<div><br>
<br>
<div>On Sat, Apr 26, 2014 at 4:15 AM, Kelvin Chua <span dir="ltr">
<<a href="mailto:kelchy@gmail.com" target="_blank">kelchy@gmail.com</a>></span> wrote:<br>
<blockquote style="padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid;">
<p dir="ltr">No, I have not yet found the solution for this issue on my setup.</p>
<p dir="ltr">Maybe Carlos can help us out</p>
<div>On Apr 26, 2014 5:10 PM, "Andrzej Ciupek" <<a href="mailto:andrzej.ciupek@hotmail.com" target="_blank">andrzej.ciupek@hotmail.com</a>> wrote:<br>
<blockquote style="padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid;">
<div dir="ltr">
<div dir="ltr">
<div style="font-family:"Calibri";font-size:12pt;">
<div>Hello</div>
<div> </div>
<div>Have You solved this issue ?</div>
<div>I’am using Kamailio 4.1.3 and I’am getting the same results. </div>
<div> </div>
<div>Greetings</div>
<div>Andrzej Ciupek</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
_______________________________________________<br>
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list<br>
<a href="mailto:sr-users@lists.sip-router.org" target="_blank">sr-users@lists.sip-router.org</a><br>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">Carlos
<div><a href="http://caruizdiaz.com" target="_blank">http://caruizdiaz.com</a></div>
<div><a href="http://ngvoice.com" target="_blank">http://ngvoice.com</a></div>
<div><a target="_blank">+52 55 3048 3303</a></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
<div dir="ltr">Carlos
<div><a href="http://caruizdiaz.com" target="_blank">http://caruizdiaz.com</a></div>
<div><a href="http://ngvoice.com" target="_blank">http://ngvoice.com</a></div>
<div><a target="_blank">+52 55 3048 3303</a></div>
</div>
</div>
</div>
</div></div></div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Carlos<div><a href="http://caruizdiaz.com" target="_blank">http://caruizdiaz.com</a></div><div><a href="http://ngvoice.com" target="_blank">http://ngvoice.com</a></div>


<div><a target="_blank">+52 55 3048 3303</a></div></div>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Carlos<div><a href="http://caruizdiaz.com" target="_blank">http://caruizdiaz.com</a></div><div><a href="http://ngvoice.com" target="_blank">http://ngvoice.com</a></div>

<div><a target="_blank">+52 55 3048 3303</a></div></div>
</div>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr">Carlos<div><a href="http://caruizdiaz.com" target="_blank">http://caruizdiaz.com</a></div><div><a href="http://ngvoice.com" target="_blank">http://ngvoice.com</a></div>
<div>+52 55 3048 3303</div></div>
</div></div></div>                                      </div></body>
</html>