]> granicus.if.org Git - ejabberd/commitdiff
Check for 'max_user_sessions' option
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Thu, 1 May 2014 16:58:14 +0000 (20:58 +0400)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 2 May 2014 13:42:13 +0000 (17:42 +0400)
src/ejabberd_sm.erl
src/mod_sip_registrar.erl

index 58debf0c15d2b335d2e4fdee942a2d960370f40a..3ef21ade46d4c684cc1a1d86b25a747e7920bbac 100644 (file)
@@ -56,6 +56,7 @@
         get_session_pid/3,
         get_user_info/3,
         get_user_ip/3,
+        get_max_user_sessions/2,
         is_existing_resource/3
        ]).
 
index 386391327b4dad34b97b8dc90a06b4a4ee23f627..602ef5bb3158cfa5732bf142584670acaa66a1ac 100644 (file)
@@ -198,7 +198,7 @@ unregister_session(US, SIPSocket, CallID, CSeq) ->
     Msg = {delete, US, SIPSocket, CallID, CSeq},
     call(Msg).
 
-write_session(#sip_session{us = US,
+write_session(#sip_session{us = {U, S} = US,
                           bindings = [#binding{socket = SIPSocket,
                                                call_id = CallID,
                                                expires = Expires,
@@ -216,10 +216,15 @@ write_session(#sip_session{us = US,
                    mnesia:dirty_write(
                      #sip_session{us = US, bindings = NewBindings});
                {error, notfound} ->
-                   NewTRef = erlang:start_timer(Expires * 1000, self(), US),
-                   NewBindings = [Binding#binding{tref = NewTRef}|Bindings],
-                   mnesia:dirty_write(
-                     #sip_session{us = US, bindings = NewBindings})
+                   MaxSessions = ejabberd_sm:get_max_user_sessions(U, S),
+                   if length(Bindings) < MaxSessions ->
+                           NewTRef = erlang:start_timer(Expires * 1000, self(), US),
+                           NewBindings = [Binding#binding{tref = NewTRef}|Bindings],
+                           mnesia:dirty_write(
+                             #sip_session{us = US, bindings = NewBindings});
+                      true ->
+                           {error, too_many_sessions}
+                   end
            end;
        [] ->
            NewTRef = erlang:start_timer(Expires * 1000, self(), US),
@@ -307,5 +312,7 @@ make_status(cseq_out_of_order) ->
     {500, <<"CSeq is Out of Order">>};
 make_status(timeout) ->
     {408, esip:reason(408)};
+make_status(too_many_sessions) ->
+    {503, <<"Too Many Registered Sessions">>};
 make_status(_) ->
     {500, esip:reason(500)}.