mirror of
https://github.com/processone/ejabberd
synced 2025-10-06 03:50:15 +02:00
Check for 'max_user_sessions' option
This commit is contained in:
parent
0117787317
commit
8e2bc8d19e
2 changed files with 13 additions and 5 deletions
|
@ -56,6 +56,7 @@
|
||||||
get_session_pid/3,
|
get_session_pid/3,
|
||||||
get_user_info/3,
|
get_user_info/3,
|
||||||
get_user_ip/3,
|
get_user_ip/3,
|
||||||
|
get_max_user_sessions/2,
|
||||||
is_existing_resource/3
|
is_existing_resource/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ unregister_session(US, SIPSocket, CallID, CSeq) ->
|
||||||
Msg = {delete, US, SIPSocket, CallID, CSeq},
|
Msg = {delete, US, SIPSocket, CallID, CSeq},
|
||||||
call(Msg).
|
call(Msg).
|
||||||
|
|
||||||
write_session(#sip_session{us = US,
|
write_session(#sip_session{us = {U, S} = US,
|
||||||
bindings = [#binding{socket = SIPSocket,
|
bindings = [#binding{socket = SIPSocket,
|
||||||
call_id = CallID,
|
call_id = CallID,
|
||||||
expires = Expires,
|
expires = Expires,
|
||||||
|
@ -216,10 +216,15 @@ write_session(#sip_session{us = US,
|
||||||
mnesia:dirty_write(
|
mnesia:dirty_write(
|
||||||
#sip_session{us = US, bindings = NewBindings});
|
#sip_session{us = US, bindings = NewBindings});
|
||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
NewTRef = erlang:start_timer(Expires * 1000, self(), US),
|
MaxSessions = ejabberd_sm:get_max_user_sessions(U, S),
|
||||||
NewBindings = [Binding#binding{tref = NewTRef}|Bindings],
|
if length(Bindings) < MaxSessions ->
|
||||||
mnesia:dirty_write(
|
NewTRef = erlang:start_timer(Expires * 1000, self(), US),
|
||||||
#sip_session{us = US, bindings = NewBindings})
|
NewBindings = [Binding#binding{tref = NewTRef}|Bindings],
|
||||||
|
mnesia:dirty_write(
|
||||||
|
#sip_session{us = US, bindings = NewBindings});
|
||||||
|
true ->
|
||||||
|
{error, too_many_sessions}
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
[] ->
|
[] ->
|
||||||
NewTRef = erlang:start_timer(Expires * 1000, self(), US),
|
NewTRef = erlang:start_timer(Expires * 1000, self(), US),
|
||||||
|
@ -307,5 +312,7 @@ make_status(cseq_out_of_order) ->
|
||||||
{500, <<"CSeq is Out of Order">>};
|
{500, <<"CSeq is Out of Order">>};
|
||||||
make_status(timeout) ->
|
make_status(timeout) ->
|
||||||
{408, esip:reason(408)};
|
{408, esip:reason(408)};
|
||||||
|
make_status(too_many_sessions) ->
|
||||||
|
{503, <<"Too Many Registered Sessions">>};
|
||||||
make_status(_) ->
|
make_status(_) ->
|
||||||
{500, esip:reason(500)}.
|
{500, esip:reason(500)}.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue