Hi carlos, sorry my ignorance, where is it the master link?
the test with only integers works perfect On Sun, May 11, 2014 at 10:48 PM, Carlos Ruiz Díaz < carlos.ruizd...@gmail.com> wrote: > Yep, assignment failed because the variables contain floating point values > and Kamailio does not handle well this kind of precision. > > I patched the module to add the check before initiating the call, it is in > master. > > As a way of testing your code, replace those values with integer ones, > like 5 and 6, and check if the call is actually terminated or even > initiated. This will give you a quick diagnosis of your routing script. > > Regards, > Carlos > > > On Sun, May 11, 2014 at 9:04 PM, Rene Montilva <renemonti...@gmail.com>wrote: > >> Hi Carlos >> >> kamailio version 4.1 >> El 11/05/2014 21:32, "Carlos Ruiz Díaz" <carlos.ruizd...@gmail.com> >> escribió: >> >> What Kamailio version are you using? >>> >>> >>> On Sat, May 10, 2014 at 9:33 PM, Rene Montilva >>> <renemonti...@gmail.com>wrote: >>> >>>> Hi Carlos >>>> >>>> kamailio config: >>>> >>>> log("L_INFO", "saldo:$var(credit) y seg:$var(cost_per_sec) "); >>>> >>>> >>>> if($var(cost_per_sec) > $var(credit)) { >>>> >>>> sl_send_reply("402","payment required"); >>>> exit; >>>> } >>>> >>>> >>>> if (!cnxcc_set_max_credit("$var(client)", >>>> "$var(credit)", >>>> "$var(cost_per_sec)", >>>> "$var(i_pulse)", >>>> "$var(f_pulse)")) { >>>> >>>> sl_send_reply("503", "something's wrong in the server"); >>>> exit; >>>> >>>> } >>>> >>>> >>>> >>>> >>>> >>>> i got this by syslog >>>> >>>> $var(credit) = "0.0005"; >>>> $var(cost_per_sec) = "0.0006"; >>>> >>>> >>>> >>>> #$var(credit) = $dbr(ra=>[0,0]); # 30$ of credit >>>> #$var(cost_per_sec) = $dbr(ra=>[0,1]); # 1$ per sec >>>> >>>> $var(i_pulse) = "1"; # 1$ to establish the call >>>> $var(f_pulse) = "1"; # 1$ per second >>>> >>>> if (!cnxcc_set_max_credit("$var(client)", >>>> "$var(credit)", >>>> "$var(cost_per_sec)", >>>> "$var(i_pulse)", >>>> "$var(f_pulse)")) { >>>> sl_send_reply("402", "Sin saldo PAPA"); >>>> xlog("Error setting up credit control"); >>>> exit; >>>> } >>>> >>>> >>>> >>>> /usr/sbin/kamailio[13336]: INFO: <script>: Setting up money based >>>> credit control >>>> /usr/sbin/kamailio[13336]: INFO: <script>: saldo:0.0005 y seg:0.0006 >>>> /usr/sbin/kamailio[13336]: WARNING: <core> [rvalue.c:1016]: >>>> rval_get_int(): automatic string to int conversion for "0.0005" failed >>>> /usr/sbin/kamailio[13336]: WARNING: <core> [rvalue.c:1920]: >>>> rval_expr_eval_int(): rval expression conversion to int failed >>>> (707,17-707,17) >>>> /usr/sbin/kamailio[13336]: WARNING: <core> [rvalue.c:1016]: >>>> rval_get_int(): automatic string to int conversion for "0.0006" failed >>>> /usr/sbin/kamailio[13336]: WARNING: <core> [rvalue.c:1920]: >>>> rval_expr_eval_int(): rval expression conversion to int failed >>>> (707,19-707,36) >>>> >>>> >>>> it still established the call >>>> >>>> >>>> with the function, kamailio doesn't evaluate the variable >>>> >>>> if($var(cost_per_sec) > $var(credit)) { >>>> >>>> sl_send_reply("402","payment required"); >>>> exit; >>>> } >>>> >>>> >>>> >>>> >>>> >>>> On Fri, May 9, 2014 at 4:41 PM, Carlos Ruiz Díaz < >>>> carlos.ruizd...@gmail.com> wrote: >>>> >>>>> >>>>> >>>>> >>>>> On Fri, May 9, 2014 at 3:52 PM, Rene Montilva >>>>> <renemonti...@gmail.com>wrote: >>>>> >>>>>> these are the values before the function call: >>>>>> >>>>>> /usr/sbin/kamailio[24933]: INFO: <script>: saldo:0.0005000000 y >>>>>> seg:0.000666666666666667 >>>>>> >>>>> >>>>> You are printing then before the assigment. >>>>> >>>>> *xlog("L_INFO", "saldo:$dbr(ra=>[0,0]) y seg:$dbr(ra=>[0,1]) ");* >>>>> >>>>> use >>>>> >>>>> *xlog("L_INFO", "saldo:$var(credit) y seg:$var(cost_per_second) ");* >>>>> >>>>> I just run a test with your values, and they did work. >>>>> >>>>> $var(credit) = "0.0005"; >>>>> $var(cost_per_second) = "0.0006"; >>>>> >>>>> *if (!cnxcc_set_max_credit("$var(client)",....* >>>>> >>>>> >>>>>> >>>>>> this function doesn't work, maybe are the long value: >>>>>> >>>>>> *if ($var(credit) < $var(cost_per_second)) {* >>>>>> * sl_send_reply("402", "payment required");* >>>>>> * exit;* >>>>>> *}* >>>>>> >>>>> >>>>> Did not get that, what does not work? >>>>> >>>>> >>>>>> >>>>>> >>>>>> >>>>>> On Fri, May 9, 2014 at 3:48 PM, Carlos Ruiz Díaz < >>>>>> carlos.ruizd...@gmail.com> wrote: >>>>>> >>>>>>> Oops, correction: >>>>>>> >>>>>>> *if ($var(credit) < $var(cost_per_second)) {* >>>>>>> * sl_send_reply("402", "payment required");* >>>>>>> * exit;* >>>>>>> *}* >>>>>>> >>>>>>> By the way, please inform of your results after doing your tests. >>>>>>> >>>>>>> Thanks, >>>>>>> Carlos >>>>>>> >>>>>>> >>>>>>> On Fri, May 9, 2014 at 3:17 PM, Carlos Ruiz Díaz < >>>>>>> carlos.ruizd...@gmail.com> wrote: >>>>>>> >>>>>>>> Hello, >>>>>>>> >>>>>>>> "i_pulse" and "f_pulse" are direct translations of the Spanish (I >>>>>>>> noticed you speak it) phrases "pulso inicial" and "pulso final", which >>>>>>>> I >>>>>>>> don't think have the same meaning in English. Updating the docs and >>>>>>>> using >>>>>>>> the proper terminology are pending matters on this module. >>>>>>>> >>>>>>>> Both values represent the initial and interim costs of the call, in >>>>>>>> your case, it is being billed second by second (1:1), subtracting >>>>>>>> "0.000666666666666667" >>>>>>>> every second from a pool of credit that is equal to "0.0006500000". >>>>>>>> >>>>>>>> The message that's being shown, looks like a precision loss error, >>>>>>>> which is unlikely because I used numbers even smaller than yours. >>>>>>>> Please >>>>>>>> print the values of $var(credit) and $var(cost_per_sec) before >>>>>>>> calling the cnxcc function. >>>>>>>> >>>>>>>> Furthermore, you should also consider checking your values before >>>>>>>> passing them to the function. For example: >>>>>>>> >>>>>>>> *1. check if the credit is greater than the cost per second, >>>>>>>> *before*.* >>>>>>>> >>>>>>>> *if ($var(credit) > $var(cost_per_second)) {* >>>>>>>> * sl_send_reply("402", "payment required");* >>>>>>>> * exit;* >>>>>>>> *}* >>>>>>>> >>>>>>>> There's no reason to call the function when the conditions are not >>>>>>>> met. Cnxcc will authorize the call and hang it immediately (1 second >>>>>>>> later). >>>>>>>> >>>>>>>> I may need to add this check myself inside the module. >>>>>>>> >>>>>>>> *2. make sure you are rejecting the call in case of module's >>>>>>>> error. * >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> *if (!cnxcc_set_max_credit("$var(client)", "$var(credit)", >>>>>>>> "$var(cost_per_sec)", "$var(i_pulse)",* >>>>>>>> >>>>>>>> * "$var(f_pulse)") { * >>>>>>>> >>>>>>>> * sl_send_reply("503", "something's wrong in the server"); * >>>>>>>> >>>>>>>> * exit; * >>>>>>>> *}* >>>>>>>> >>>>>>>> Regards, >>>>>>>> Carlos >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Fri, May 9, 2014 at 2:45 PM, Rene Montilva < >>>>>>>> renemonti...@gmail.com> wrote: >>>>>>>> >>>>>>>>> Hi Carlos >>>>>>>>> >>>>>>>>> This my kamailio config: >>>>>>>>> >>>>>>>>> #!ifdef CNXCC_MONEY >>>>>>>>> sql_query("ca", "select * from >>>>>>>>> billing.sel_customer_credit('pepe','xxxxxxx","ra"); >>>>>>>>> >>>>>>>>> xlog("L_INFO", "Setting up money based credit control"); >>>>>>>>> >>>>>>>>> if($dbr(ra=>rows)> 0){ >>>>>>>>> xlog("L_INFO", "saldo:$dbr(ra=>[0,0]) y seg:$dbr(ra=>[0,1]) "); >>>>>>>>> >>>>>>>>> $var(credit) = $dbr(ra=>[0,0]); # 30$ of credit >>>>>>>>> $var(cost_per_sec) = $dbr(ra=>[0,1]); # 1$ per sec >>>>>>>>> $var(i_pulse) = "1"; # 1$ to establish the call >>>>>>>>> $var(f_pulse) = "1"; # 1$ per second >>>>>>>>> >>>>>>>>> >>>>>>>>> } >>>>>>>>> >>>>>>>>> sql_result_free ("ra"); >>>>>>>>> >>>>>>>>> # if only one call is established, that call should last 9 seconds. >>>>>>>>> >>>>>>>>> if (!cnxcc_set_max_credit("$var(client)", >>>>>>>>> "$var(credit)", >>>>>>>>> "$var(cost_per_sec)", >>>>>>>>> "$var(i_pulse)", >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> And this are the values by syslog info >>>>>>>>> >>>>>>>>> INFO: <script>: saldo:0.0006500000 y seg:0.000666666666666667 >>>>>>>>> ERROR: cnxcc [cnxcc_mod.c:1425]: set_max_credit(): credit value >>>>>>>>> must be > 0: 0.000000 >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>>> On Fri, May 9, 2014 at 3:08 PM, Carlos Ruiz Díaz < >>>>>>>>> carlos.ruizd...@gmail.com> wrote: >>>>>>>>> >>>>>>>>>> Hi, >>>>>>>>>> >>>>>>>>>> Can you paste the code you are using, with the values that each >>>>>>>>>> variable contain at the moment of initiating the call? >>>>>>>>>> >>>>>>>>>> Regards, >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> On Fri, May 9, 2014 at 2:35 PM, Rene Montilva < >>>>>>>>>> renemonti...@gmail.com> wrote: >>>>>>>>>> >>>>>>>>>>> Hi list >>>>>>>>>>> >>>>>>>>>>> I don't understand prepaid logic calculation, because when my >>>>>>>>>>> credit is 0 or lees than cost per second, the call is established >>>>>>>>>>> equal >>>>>>>>>>> >>>>>>>>>>> $var(i_pulse) and $var(f_pulse) how this works???? >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>>> _______________________________________________ >>>>>>>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users >>>>>>>>>>> mailing list >>>>>>>>>>> sr-users@lists.sip-router.org >>>>>>>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>>>>>>>>> >>>>>>>>>>> >>>>>>>>>> >>>>>>>>>> >>>>>>>>>> -- >>>>>>>>>> Carlos >>>>>>>>>> http://caruizdiaz.com >>>>>>>>>> http://ngvoice.com >>>>>>>>>> +52 55 3048 3303 >>>>>>>>>> >>>>>>>>>> _______________________________________________ >>>>>>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users >>>>>>>>>> mailing list >>>>>>>>>> sr-users@lists.sip-router.org >>>>>>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>>>>>>>> >>>>>>>>>> >>>>>>>>> >>>>>>>>> _______________________________________________ >>>>>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing >>>>>>>>> list >>>>>>>>> sr-users@lists.sip-router.org >>>>>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>>>>>>> >>>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> -- >>>>>>>> Carlos >>>>>>>> http://caruizdiaz.com >>>>>>>> http://ngvoice.com >>>>>>>> +52 55 3048 3303 >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Carlos >>>>>>> http://caruizdiaz.com >>>>>>> http://ngvoice.com >>>>>>> +52 55 3048 3303 >>>>>>> >>>>>>> _______________________________________________ >>>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing >>>>>>> list >>>>>>> sr-users@lists.sip-router.org >>>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>>>>> >>>>>>> >>>>>> >>>>>> _______________________________________________ >>>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing >>>>>> list >>>>>> sr-users@lists.sip-router.org >>>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Carlos >>>>> http://caruizdiaz.com >>>>> http://ngvoice.com >>>>> +52 55 3048 3303 >>>>> >>>>> _______________________________________________ >>>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list >>>>> sr-users@lists.sip-router.org >>>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>>> >>>>> >>>> >>>> _______________________________________________ >>>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list >>>> sr-users@lists.sip-router.org >>>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>>> >>>> >>> >>> >>> -- >>> Carlos >>> http://caruizdiaz.com >>> http://ngvoice.com >>> +52 55 3048 3303 >>> >>> _______________________________________________ >>> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list >>> sr-users@lists.sip-router.org >>> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >>> >>> >> _______________________________________________ >> SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list >> sr-users@lists.sip-router.org >> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users >> >> > > > -- > Carlos > http://caruizdiaz.com > http://ngvoice.com > +52 55 3048 3303 > > _______________________________________________ > SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list > sr-users@lists.sip-router.org > http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users > >
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users