Re: [SR-Users] Terminate dialog from another dialog

2018-03-27 Thread Joel Serrano
Hi Henning,

On Tue, Mar 27, 2018 at 12:50 PM, Henning Westerholt  wrote:
>
> Am Montag, 26. März 2018, 01:57:31 CEST schrieb Joel Serrano:
> > I'm trying to set kamailio to not allow simultaneous calls from the same
> > user, but if a second call comes in, the behavior desired is to process
> > that second call and terminate the previous (already active) one.
> >
> > Say you have call A that creates dialog A.
> >
> > Then you have call B come in, creates dialog B.
> >
> > Can I save some info from dialog (call) A in a htable for example, then
> > check that htable for the needed info from dialog (call) B and terminate
> > dialog (call) A if it exists?
> >
> > I think using dlg_get() and dlg_bye() would do the trick but not 100% sure
> > how they work..
> >
> >
> > The example in the docs seems exactly the case:
> >
> > dlg_get --> "Search and set current dialog based on Call-ID, From-Tag and
> > To-Tag parameters"
> >
> > if(dlg_get("abcdef", "123", "456"))
> > {
> > dlg_bye("all");
> > }
> >
> > After the dlg_get() and dlg_bye() what happens to call B? Does the route
> > continue running or does it end? Will it automatically switch back to the
> > current dialog or do you have to manually switch back running dlg_get()
> > again? (Sorry if I'm not explaining myself correctly, let me know if it
> > sounds confusing)
>
> Hello Joel,
>
> you coult track the number of current dialogs per user with the dialog
> profiles function.
>
> Have a look to the set_dlg_profile and get_profile_size function in the
> module. Its also explained generally in the top of the module docs. You could
> store the dialog information for the termination also in a htable, as you
> already mentioned. Then call dlg_bye() for the first call.

Problem is I need to allow current call, and hangup earlier one. This
is because of the design, the users are joining conferences really,
not placing calls, so it makes more sense like this:

- User-A joins conference-A from device-A
- User-A joins conference-B from device-B
- Kamailio must allow User-A on conf-B and terminate dialog of User-A on conf-A.

>
> If you would reverse your logic, like not allowing the second call setup if
> there is already one call, it would be much easier only with the two dialog
> functions mentioned above.
>
> Best regards,
>
> Henning

I ended up using the RPC command dlg.end_dlg instead of the
dlg.terminate_dlg as I can add an extra param "custom headers" which
is useful.

In case anyone else is curious (NOTE: Read my Update and Update2
emails in this thread to better understand where this piece of code
comes from):

event_route[dialog:start] {

...
if ($sht(bcalls=>$fU::callid) != $null) {
jsonrpc_exec('{"jsonrpc": "2.0","method":
"dlg.end_dlg","params": [$sht(bcalls=>$fU::h_entry),
$sht(bcalls=>$fU::h_id), "X-Reason: MAX_ACTIVE_CHANNELS\r\n"],"id":
1}');
if ($jsonrpl(code)==200) {
xlog("L_INFO", "User check: previous active
call terminated, current call added to cache - M=$rm R=$ru ID=$ci\n");
} else {
xlog("L_INFO", "User check: couldn't terminate
previous call, updated cache with current call - M=$rm R=$ru
ID=$ci\n");
}
} else {
xlog("L_INFO", "User check: Call OK, added to cache -
M=$rm R=$ru ID=$ci\n");
}
$sht(bcalls=>$fU::h_id) = $dlg(h_id);
$sht(bcalls=>$fU::h_entry) = $dlg(h_entry);
$sht(bcalls=>$fU::callid) = $dlg(callid);
...

}


The part I still don't like is the jsonrpc_exec(), but I don't know
other ways of doing it, and I don't know really if there is a
performance hit doing it like this rather than using some function,
for now, it's working ;)


Cheers,
Joel.

___
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users


Re: [SR-Users] Terminate dialog from another dialog

2018-03-27 Thread Henning Westerholt
Am Montag, 26. März 2018, 01:57:31 CEST schrieb Joel Serrano:
> I'm trying to set kamailio to not allow simultaneous calls from the same
> user, but if a second call comes in, the behavior desired is to process
> that second call and terminate the previous (already active) one.
> 
> Say you have call A that creates dialog A.
> 
> Then you have call B come in, creates dialog B.
> 
> Can I save some info from dialog (call) A in a htable for example, then
> check that htable for the needed info from dialog (call) B and terminate
> dialog (call) A if it exists?
> 
> I think using dlg_get() and dlg_bye() would do the trick but not 100% sure
> how they work..
> 
> 
> The example in the docs seems exactly the case:
> 
> dlg_get --> "Search and set current dialog based on Call-ID, From-Tag and
> To-Tag parameters"
> 
> if(dlg_get("abcdef", "123", "456"))
> {
> dlg_bye("all");
> }
> 
> After the dlg_get() and dlg_bye() what happens to call B? Does the route
> continue running or does it end? Will it automatically switch back to the
> current dialog or do you have to manually switch back running dlg_get()
> again? (Sorry if I'm not explaining myself correctly, let me know if it
> sounds confusing)

Hello Joel,

you coult track the number of current dialogs per user with the dialog 
profiles function.

Have a look to the set_dlg_profile and get_profile_size function in the 
module. Its also explained generally in the top of the module docs. You could 
store the dialog information for the termination also in a htable, as you 
already mentioned. Then call dlg_bye() for the first call.

If you would reverse your logic, like not allowing the second call setup if 
there is already one call, it would be much easier only with the two dialog 
functions mentioned above.

Best regards,

Henning

___
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users


Re: [SR-Users] Terminate dialog from another dialog

2018-03-27 Thread Joel Serrano
Update 2:

Unfortunately dlg_get() can't be used in event_route so I don't know how I
can use dlg_bye() on a different dialog (not the current one)  :(

This bit of code does the job, but I don't know if it's really messy:


...bcalls is the name of the htable, for each dialog I save the callid,
from_tag and to_tag (needed params for dialog termination)..


event_route[dialog:start] {
  if ($sht(bcalls=>$fU::callid) != $null) {
jsonrpc_exec('{"jsonrpc": "2.0","method": "dlg.terminate_dlg","params":
["$sht(bcalls=>$fU::callid)", "$sht(bcalls=>$fU::from_tag)",
"$sht(bcalls=>$fU::to_tag)"],"id": 1}');   < This is what I think is
messy...
xlog("L_NOTICE", "User check: Previous call terminated:
$jsonrpl(body)\n");
$sht(bcalls=>$fU::callid) = $dlg(callid);
$sht(bcalls=>$fU::from_tag) = $dlg(from_tag);
$sht(bcalls=>$fU::to_tag) = $tt;
xlog("L_NOTICE", "User check: Updated call-info for $fU in htable\n");
  } else {
$sht(bcalls=>$fU::callid) = $dlg(callid);
$sht(bcalls=>$fU::from_tag) = $dlg(from_tag);
$sht(bcalls=>$fU::to_tag) = $tt;
xlog("L_NOTICE", "User check: Added call-info for $fU to htable\n");
  }
}


Any comments???

On Tue, Mar 27, 2018 at 8:23 AM, Joel Serrano  wrote:

> Update:
>
> I have been testing and I think the way to go is taking advantage of the
> events generated by the dialog module (start/end/failed)...
>
> I don't know if this is a bug, but shouldn't the $dlg(to_tag) be available
> in the event_route[dialog:start] ??
>
> I can access $dlg(callid), $dlg(from_tag) but not the $dlg(to_tag) and all
> 3 are needed to search and terminate an existing dialog. For now i'm using
> $tt, but I'm wondering if this is correct or not? Let me know if I should
> move this topic to github...
>
> Thanks!
> Joel.
>
>
>
>
>
>
> On Sun, Mar 25, 2018 at 4:57 PM, Joel Serrano  wrote:
>
>> Hi guys,
>>
>> I'm trying to set kamailio to not allow simultaneous calls from the same
>> user, but if a second call comes in, the behavior desired is to process
>> that second call and terminate the previous (already active) one.
>>
>> Say you have call A that creates dialog A.
>>
>> Then you have call B come in, creates dialog B.
>>
>> Can I save some info from dialog (call) A in a htable for example, then
>> check that htable for the needed info from dialog (call) B and terminate
>> dialog (call) A if it exists?
>>
>> I think using dlg_get() and dlg_bye() would do the trick but not 100%
>> sure how they work..
>>
>>
>> The example in the docs seems exactly the case:
>>
>> dlg_get --> "Search and set current dialog based on Call-ID, From-Tag
>> and To-Tag parameters"
>>
>> if(dlg_get("abcdef", "123", "456"))
>> {
>> dlg_bye("all");
>> }
>>
>> After the dlg_get() and dlg_bye() what happens to call B? Does the route
>> continue running or does it end? Will it automatically switch back to the
>> current dialog or do you have to manually switch back running dlg_get()
>> again? (Sorry if I'm not explaining myself correctly, let me know if it
>> sounds confusing)
>>
>> Does anyone have experience with these two functions?
>>
>>
>> Thanks,
>> Joel.
>>
>>
>
___
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users


Re: [SR-Users] Terminate dialog from another dialog

2018-03-27 Thread Joel Serrano
Update:

I have been testing and I think the way to go is taking advantage of the
events generated by the dialog module (start/end/failed)...

I don't know if this is a bug, but shouldn't the $dlg(to_tag) be available
in the event_route[dialog:start] ??

I can access $dlg(callid), $dlg(from_tag) but not the $dlg(to_tag) and all
3 are needed to search and terminate an existing dialog. For now i'm using
$tt, but I'm wondering if this is correct or not? Let me know if I should
move this topic to github...

Thanks!
Joel.






On Sun, Mar 25, 2018 at 4:57 PM, Joel Serrano  wrote:

> Hi guys,
>
> I'm trying to set kamailio to not allow simultaneous calls from the same
> user, but if a second call comes in, the behavior desired is to process
> that second call and terminate the previous (already active) one.
>
> Say you have call A that creates dialog A.
>
> Then you have call B come in, creates dialog B.
>
> Can I save some info from dialog (call) A in a htable for example, then
> check that htable for the needed info from dialog (call) B and terminate
> dialog (call) A if it exists?
>
> I think using dlg_get() and dlg_bye() would do the trick but not 100% sure
> how they work..
>
>
> The example in the docs seems exactly the case:
>
> dlg_get --> "Search and set current dialog based on Call-ID, From-Tag and
> To-Tag parameters"
>
> if(dlg_get("abcdef", "123", "456"))
> {
> dlg_bye("all");
> }
>
> After the dlg_get() and dlg_bye() what happens to call B? Does the route
> continue running or does it end? Will it automatically switch back to the
> current dialog or do you have to manually switch back running dlg_get()
> again? (Sorry if I'm not explaining myself correctly, let me know if it
> sounds confusing)
>
> Does anyone have experience with these two functions?
>
>
> Thanks,
> Joel.
>
>
___
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users


[SR-Users] Terminate dialog from another dialog

2018-03-25 Thread Joel Serrano
Hi guys,

I'm trying to set kamailio to not allow simultaneous calls from the same
user, but if a second call comes in, the behavior desired is to process
that second call and terminate the previous (already active) one.

Say you have call A that creates dialog A.

Then you have call B come in, creates dialog B.

Can I save some info from dialog (call) A in a htable for example, then
check that htable for the needed info from dialog (call) B and terminate
dialog (call) A if it exists?

I think using dlg_get() and dlg_bye() would do the trick but not 100% sure
how they work..


The example in the docs seems exactly the case:

dlg_get --> "Search and set current dialog based on Call-ID, From-Tag and
To-Tag parameters"

if(dlg_get("abcdef", "123", "456"))
{
dlg_bye("all");
}

After the dlg_get() and dlg_bye() what happens to call B? Does the route
continue running or does it end? Will it automatically switch back to the
current dialog or do you have to manually switch back running dlg_get()
again? (Sorry if I'm not explaining myself correctly, let me know if it
sounds confusing)

Does anyone have experience with these two functions?


Thanks,
Joel.
___
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users