<p></p>
<p>I've been reviewing the code another time.</p>
<p>There are 3 different functions to control credit, time and channels: __set_max_credit(), __set_max_time() and __set_max_channels(). All of them do the same:</p>
<p><strong>function __set_max_money()</strong>:<br>
credit_data = __get_or_create_credit_data_entry(client_id, CREDIT_MONEY)<br>
call = __alloc_new_call_by_time(client_id) // Allocate new call for client<br>
__add_call_by_cid(cid, call, CREDIT_MONEY) // Allocate new CID_BY_CLIENT for client</p>
<p><strong>function __set_max_time()</strong>:<br>
credit_data = __get_or_create_credit_data_entry(client_id, CREDIT_TIME)<br>
call = __alloc_new_call_by_time(client_id) // Allocate new call for client<br>
__add_call_by_cid(cid, call, CREDIT_TIME)  // Allocate new CID_BY_CLIENT for client</p>
<p><strong>function __set_max_channel()</strong>:<br>
credit_data = __get_or_create_credit_data_entry(client_id, CREDIT_CHANNEL)<br>
call = __alloc_new_call_by_time(client_id)   // Allocate new call for client<br>
__add_call_by_cid(cid, call, CREDIT_CHANNEL) // Allocate new CID_BY_CLIENT for client</p>
<p>If credit is exhausted, the function <strong>__terminate_all()</strong> is called to kill all active calls for this client. This works fine:</p>
<p>__terminate_all(pointer_client_id) -> ki_terminate_all(client_id) -> terminate_all_calls(credit_data):<br>
foreach(call_list) {<br>
terminate_call(call)<br>
}</p>
<p>On the other hand, when a dialog is finished, the function called is <strong>__stop_billing()</strong>:</p>
<p>__dialog_terminated_callback() -> __stop_billing(callid) -> __delete_call(call, credit_data) -> __free_call(call)</p>
<p>In this case, there is no loop to delete and free all calls for this client with a same CID. Only remove the first match found.<br>
If the module has prepared to handle several times the same CID (by client), when dialog is finished, it should check and remove all calls with of this client with a same CID. Currently the module is not working in this way and I'm sure that nobody is using it to charge more than 1 times each CID, because it doesn't work. If anyone is trying to charge a call twice, is having problems because only one call by cid is terminated.</p>
<p>However, if you think that this feature could be important (being able to charge the same call more than once), it will be necessary to fix that, because currently it doesn't work.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/pull/2383#issuecomment-652352229">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZPMFEYOTKZRZUULUY3RZMJXPANCNFSM4OMKISIA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZMTCEB5JRENFCLCZX3RZMJXPA5CNFSM4OMKISIKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOE3RBVZI.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/pull/2383#issuecomment-652352229",
"url": "https://github.com/kamailio/kamailio/pull/2383#issuecomment-652352229",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>