]> granicus.if.org Git - ejabberd/commitdiff
Move some code in a separate function
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Thu, 1 May 2014 12:31:03 +0000 (16:31 +0400)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 2 May 2014 13:38:47 +0000 (17:38 +0400)
src/mod_sip_registrar.erl

index 48740d0ed91e681c79ca8a75f197435070b0350e..3e65564c1a57dc13d9e91e2488a5a0015000d9fa 100644 (file)
@@ -168,24 +168,7 @@ handle_info({delete, US, SIPSocket, CallID, CSeq}, State) ->
     delete_session(US, SIPSocket, CallID, CSeq),
     {noreply, State};
 handle_info({timeout, TRef, US}, State) ->
-    case mnesia:dirty_read(sip_session, US) of
-       [#sip_session{bindings = Bindings}] ->
-           case lists:filter(
-                  fun(#binding{tref = TRef1}) when TRef1 == TRef ->
-                          false;
-                     (_) ->
-                          true
-                  end, Bindings) of
-               [] ->
-                   mnesia:dirty_delete(sip_session, US);
-               NewBindings ->
-                   mnesia:dirty_write(sip_session,
-                                      #sip_session{us = US,
-                                                   bindings = NewBindings})
-           end;
-       [] ->
-           ok
-    end,
+    delete_expired_session(US, TRef),
     {noreply, State};
 handle_info(_Info, State) ->
     ?ERROR_MSG("got unexpected info: ~p", [_Info]),
@@ -264,6 +247,26 @@ delete_session(US, SIPSocket, CallID, CSeq) ->
            {error, notfound}
     end.
 
+delete_expired_session(US, TRef) ->
+    case mnesia:dirty_read(sip_session, US) of
+       [#sip_session{bindings = Bindings}] ->
+           case lists:filter(
+                  fun(#binding{tref = TRef1}) when TRef1 == TRef ->
+                          false;
+                     (_) ->
+                          true
+                  end, Bindings) of
+               [] ->
+                   mnesia:dirty_delete(sip_session, US);
+               NewBindings ->
+                   mnesia:dirty_write(sip_session,
+                                      #sip_session{us = US,
+                                                   bindings = NewBindings})
+           end;
+       [] ->
+           ok
+    end.
+
 min_expires() ->
     60.