]> granicus.if.org Git - ejabberd/commitdiff
Avoid using maps:get/2 to keep compatibility with OTP 17.5
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 23 Jan 2017 13:30:16 +0000 (16:30 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Mon, 23 Jan 2017 13:30:16 +0000 (16:30 +0300)
src/ejabberd_c2s.erl
src/mod_client_state.erl
src/mod_offline.erl
src/xmpp_stream_pkix.erl

index fd26556325af7a8d5965b60c5b5527f9db9a3caf..e6a7f9c39f792482afb83e6a87b2966d129d0958 100644 (file)
@@ -176,10 +176,9 @@ open_session(#{user := U, server := S, resource := R,
     change_shaper(State),
     Conn = get_conn_type(State),
     State1 = State#{conn => Conn, resource => R, jid => JID},
-    Prio = try maps:get(pres_last, State) of
+    Prio = case maps:get(pres_last, State, undefined) of
+              undefined -> undefined;
               Pres -> get_priority_from_presence(Pres)
-          catch _:{badkey, _} ->
-                  undefined
           end,
     Info = [{ip, IP}, {conn, Conn}, {auth_module, AuthModule}],
     ejabberd_sm:open_session(SID, U, S, R, Prio, Info),
@@ -211,10 +210,9 @@ process_info(#{lserver := LServer} = State,
            State1
     end;
 process_info(State, force_update_presence) ->
-    try maps:get(pres_last, State) of
+    case maps:get(pres_last, State, error) of
+       error -> State;
        Pres -> process_self_presence(State, Pres)
-    catch _:{badkey, _} ->
-           State
     end;
 process_info(State, Info) ->
     ?WARNING_MSG("got unexpected info: ~p", [Info]),
@@ -498,10 +496,11 @@ init([State, Opts]) ->
     ejabberd_hooks:run_fold(c2s_init, {ok, State1}, [Opts]).
 
 handle_call(get_presence, From, #{jid := JID} = State) ->
-    Pres = try maps:get(pres_last, State)
-          catch _:{badkey, _} ->
+    Pres = case maps:get(pres_last, State, error) of
+              error ->
                   BareJID = jid:remove_resource(JID),
-                  #presence{from = JID, to = BareJID, type = unavailable}
+                  #presence{from = JID, to = BareJID, type = unavailable};
+              P -> P
           end,
     reply(From, Pres),
     State;
index 1243e7bf289420654209178cb006c0bfa4853797..f57e3e32d660d53c5752bf8ff2da1bd5520323c4 100644 (file)
@@ -339,7 +339,10 @@ queue_new() ->
 queue_in(Key, Type, Val, {N, Seq, Q}) ->
     Seq1 = Seq + 1,
     Time = {Seq1, p1_time_compat:timestamp()},
-    try maps:get(Key, Q) of
+    case maps:get(Key, Q, error) of
+       error ->
+           Q1 = maps:put(Key, [{Type, Time, Val}], Q),
+           {N + 1, Seq1, Q1};
        TypeVals ->
            case lists:keymember(Type, 1, TypeVals) of
                true ->
@@ -352,9 +355,6 @@ queue_in(Key, Type, Val, {N, Seq, Q}) ->
                    Q1 = maps:put(Key, TypeVals1, Q),
                    {N + 1, Seq1, Q1}
            end
-    catch _:{badkey, _} ->
-           Q1 = maps:put(Key, [{Type, Time, Val}], Q),
-           {N + 1, Seq1, Q1}
     end.
 
 -spec queue_take(term(), csi_queue()) -> {list(), csi_queue()} | error.
index 43f13a62950535b6d7969fba505e11d6c0ee8513..61fa65bc56433f912095318842e85b71b637efe0 100644 (file)
@@ -565,10 +565,9 @@ c2s_self_presence({_Pres, #{resend_offline := false}} = Acc) ->
     Acc;
 c2s_self_presence({#presence{type = available} = NewPres, State} = Acc) ->
     NewPrio = get_priority_from_presence(NewPres),
-    LastPrio = try maps:get(pres_last, State) of
+    LastPrio = case maps:get(pres_last, State, error) of
+                  error -> -1;
                   LastPres -> get_priority_from_presence(LastPres)
-              catch _:{badkey, _} ->
-                      -1
               end,
     if LastPrio < 0 andalso NewPrio >= 0 ->
            route_offline_messages(State);
index 9d3da58be025cec8109a151ce0163006175e5e4d..16b7efa42159f3e8659588d16b3739f65483085c 100644 (file)
@@ -40,9 +40,7 @@ authenticate(State) ->
       -> {ok, binary()} | {error, atom(), binary()}.
 authenticate(#{xmlns := ?NS_SERVER, sockmod := SockMod,
               socket := Socket} = State, Authzid) ->
-    Peer = try maps:get(remote_server, State)
-          catch _:{badkey, _} -> Authzid
-          end,
+    Peer = maps:get(remote_server, State, Authzid),
     case SockMod:get_peer_certificate(Socket) of
        {ok, Cert} ->
            case SockMod:get_verify_result(Socket) of