]> granicus.if.org Git - ejabberd/commitdiff
Use ejabberd_router:route_error/4 wherever possible
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 25 Nov 2016 08:41:24 +0000 (11:41 +0300)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 25 Nov 2016 08:41:24 +0000 (11:41 +0300)
src/ejabberd_local.erl
src/ejabberd_sm.erl
src/gen_iq_handler.erl
src/mod_announce.erl
src/mod_muc.erl
src/mod_muc_room.erl
src/mod_offline.erl

index 74d86945d095947c6f154baf77b3c45f3cd5dd75..3406192f7438e6c1f054c1e09714599c94b50448 100644 (file)
@@ -87,14 +87,12 @@ process_iq(From, To, #iq{type = T, lang = Lang, sub_els = [El]} = Packet)
                                  From, To, Packet);
        [] ->
            Txt = <<"No module is handling this query">>,
-           Err = xmpp:make_error(
-                   Packet,
-                   xmpp:err_service_unavailable(Txt, Lang)),
-           ejabberd_router:route(To, From, Err)
+           Err = xmpp:err_service_unavailable(Txt, Lang),
+           ejabberd_router:route_error(To, From, Packet, Err)
     end;
 process_iq(From, To, #iq{type = T} = Packet) when T == get; T == set ->
-    Err = xmpp:make_error(Packet, xmpp:err_bad_request()),
-    ejabberd_router:route(To, From, Err);
+    Err = xmpp:err_bad_request(),
+    ejabberd_router:route_error(To, From, Packet, Err);
 process_iq(From, To, #iq{type = T} = Packet) when T == result; T == error ->
     process_iq_reply(From, To, Packet).
 
@@ -186,9 +184,8 @@ bounce_resource_packet(_From, #jid{lresource = <<"">>},
 bounce_resource_packet(From, To, Packet) ->
     Lang = xmpp:get_lang(Packet),
     Txt = <<"No available resource found">>,
-    Err = xmpp:make_error(Packet,
-                         xmpp:err_item_not_found(Txt, Lang)),
-    ejabberd_router:route(To, From, Err),
+    Err = xmpp:err_item_not_found(Txt, Lang),
+    ejabberd_router:route_error(To, From, Packet, Err),
     stop.
 
 %%====================================================================
index d40db28cc3f6db97c067e18913f0e70473488d27..56dc3092e6531bc81cee7393b6e29912a198abdd 100644 (file)
@@ -173,9 +173,8 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
 bounce_offline_message(From, To, Packet) ->
     Lang = xmpp:get_lang(Packet),
     Txt = <<"User session not found">>,
-    Err = xmpp:make_error(
-           Packet, xmpp:err_service_unavailable(Txt, Lang)),
-    ejabberd_router:route(To, From, Err),
+    Err = xmpp:err_service_unavailable(Txt, Lang),
+    ejabberd_router:route_error(To, From, Packet, Err),
     stop.
 
 -spec disconnect_removed_user(binary(), binary()) -> ok.
@@ -602,9 +601,8 @@ route_message(From, To, Packet, Type) ->
                    ejabberd_hooks:run(offline_message_hook, LServer,
                                       [From, To, Packet]);
                false ->
-                   Err = xmpp:make_error(Packet,
-                                         xmpp:err_service_unavailable()),
-                   ejabberd_router:route(To, From, Err)
+                   Err = xmpp:err_service_unavailable(),
+                   ejabberd_router:route_error(To, From, Packet, Err)
            end
     end.
 
@@ -724,14 +722,12 @@ process_iq(From, To, #iq{type = T, lang = Lang, sub_els = [El]} = Packet)
                                  From, To, Packet);
        [] ->
            Txt = <<"No module is handling this query">>,
-           Err = xmpp:make_error(
-                   Packet,
-                   xmpp:err_service_unavailable(Txt, Lang)),
-           ejabberd_router:route(To, From, Err)
+           Err = xmpp:err_service_unavailable(Txt, Lang),
+           ejabberd_router:route_error(To, From, Packet, Err)
     end;
 process_iq(From, To, #iq{type = T} = Packet) when T == get; T == set ->
-    Err = xmpp:make_error(Packet, xmpp:err_bad_request()),
-    ejabberd_router:route(To, From, Err),
+    Err = xmpp:err_bad_request(),
+    ejabberd_router:route_error(To, From, Packet, Err),
     ok;
 process_iq(_From, _To, #iq{}) ->
     ok.
index bcbda1d1e24a5c6b63530ea7285809a4c815c5ea..4a7a03c27eaf94187847915b29c096a83cf23b31 100644 (file)
@@ -147,7 +147,7 @@ process_iq(_Host, Module, Function, From, To, IQ0) ->
                       [xmpp:pp(IQ), {E, {R, erlang:get_stacktrace()}}]),
            Txt = <<"Module failed to handle the query">>,
            Err = xmpp:err_internal_server_error(Txt, IQ#iq.lang),
-           ejabberd_router:route(To, From, xmpp:make_error(IQ, Err))
+           ejabberd_router:route_error(To, From, IQ, Err)
     end.
 
 -spec process_iq(module(), atom(), iq()) -> ignore | iq().
index a1c60f3c9c5eae71a159ab991373f63cab2d1e3f..2e182ed1e4d3acdbf5aec270ec28733436076a26 100644 (file)
@@ -601,10 +601,7 @@ announce_all(From, To, Packet) ->
     Access = get_access(Host),
     case acl:match_rule(Host, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            Local = jid:make(To#jid.server),
            lists:foreach(
@@ -618,10 +615,7 @@ announce_all_hosts_all(From, To, Packet) ->
     Access = get_access(global),
     case acl:match_rule(global, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            Local = jid:make(To#jid.server),
            lists:foreach(
@@ -636,10 +630,7 @@ announce_online(From, To, Packet) ->
     Access = get_access(Host),
     case acl:match_rule(Host, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            announce_online1(ejabberd_sm:get_vh_session_list(Host),
                             To#jid.server,
@@ -650,10 +641,7 @@ announce_all_hosts_online(From, To, Packet) ->
     Access = get_access(global),
     case acl:match_rule(global, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            announce_online1(ejabberd_sm:dirty_get_sessions_list(),
                             To#jid.server,
@@ -673,10 +661,7 @@ announce_motd(From, To, Packet) ->
     Access = get_access(Host),
     case acl:match_rule(Host, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            announce_motd(Host, Packet)
     end.
@@ -685,10 +670,7 @@ announce_all_hosts_motd(From, To, Packet) ->
     Access = get_access(global),
     case acl:match_rule(global, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            Hosts = ?MYHOSTS,
            [announce_motd(Host, Packet) || Host <- Hosts]
@@ -707,10 +689,7 @@ announce_motd_update(From, To, Packet) ->
     Access = get_access(Host),
     case acl:match_rule(Host, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            announce_motd_update(Host, Packet)
     end.
@@ -719,10 +698,7 @@ announce_all_hosts_motd_update(From, To, Packet) ->
     Access = get_access(global),
     case acl:match_rule(global, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            Hosts = ?MYHOSTS,
            [announce_motd_update(Host, Packet) || Host <- Hosts]
@@ -738,10 +714,7 @@ announce_motd_delete(From, To, Packet) ->
     Access = get_access(Host),
     case acl:match_rule(Host, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            announce_motd_delete(Host)
     end.
@@ -750,10 +723,7 @@ announce_all_hosts_motd_delete(From, To, Packet) ->
     Access = get_access(global),
     case acl:match_rule(global, Access, From) of
        deny ->
-           Lang = xmpp:get_lang(Packet),
-           Txt = <<"Denied by ACL">>,
-           Err = xmpp:make_error(Packet, xmpp:err_forbidden(Txt, Lang)),
-           ejabberd_router:route(To, From, Err);
+           route_forbidden_error(From, To, Packet);
        allow ->
            Hosts = ?MYHOSTS,
            [announce_motd_delete(Host) || Host <- Hosts]
@@ -827,6 +797,12 @@ get_access(Host) ->
 add_store_hint(El) ->
     xmpp:set_subtag(El, #hint{type = store}).
 
+-spec route_forbidden_error(jid(), jid(), stanza()) -> ok.
+route_forbidden_error(From, To, Packet) ->
+    Lang = xmpp:get_lang(Packet),
+    Err = xmpp:err_forbidden(<<"Denied by ACL">>, Lang),
+    ejabberd_router:route_error(To, From, Packet, Err).
+
 %%-------------------------------------------------------------------------
 export(LServer) ->
     Mod = gen_mod:db_mod(LServer, ?MODULE),
index 554a2170499116c101039da35727fc5e43e95901..ab358b957a2d5000db79a137c14a52dbb7cc9759 100644 (file)
@@ -378,9 +378,8 @@ do_route1(Host, ServerHost, Access, _HistorySize, _RoomShaper,
                deny ->
                    ErrText = <<"Only service administrators are allowed "
                                "to send service messages">>,
-                   Err = xmpp:make_error(
-                           Packet, xmpp:err_forbidden(ErrText, Lang)),
-                   ejabberd_router:route(To, From, Err)
+                   Err = xmpp:err_forbidden(ErrText, Lang),
+                   ejabberd_router:route_error(To, From, Packet, Err)
            end
     end;
 do_route1(_Host, _ServerHost, _Access, _HistorySize, _RoomShaper,
@@ -409,9 +408,8 @@ do_route1(Host, ServerHost, Access, HistorySize, RoomShaper,
                        false ->
                            Lang = xmpp:get_lang(Packet),
                            ErrText = <<"Room creation is denied by service policy">>,
-                           Err = xmpp:make_error(
-                                   Packet, xmpp:err_forbidden(ErrText, Lang)),
-                           ejabberd_router:route(To, From, Err)
+                           Err = xmpp:err_forbidden(ErrText, Lang),
+                           ejabberd_router:route_error(To, From, Packet, Err)
                    end;
                false ->
                    Lang = xmpp:get_lang(Packet),
index aa1c77aadf077fa100ac9aa89d1a4b9eb5834d16..2d21365d532c38f92fef2d531be787291baaa91e 100644 (file)
@@ -167,10 +167,8 @@ normal_state({route, From, <<"">>,
                shaper:update(Activity#activity.message_shaper, Size),
            if Activity#activity.message /= undefined ->
                    ErrText = <<"Traffic rate limit is exceeded">>,
-                   Err = xmpp:make_error(
-                           Packet,
-                           xmpp:err_resource_constraint(ErrText, Lang)),
-                   ejabberd_router:route(StateData#state.jid, From, Err),
+                   Err = xmpp:err_resource_constraint(ErrText, Lang),
+                   ejabberd_router:route_error(StateData#state.jid, From, Packet, Err),
                    {next_state, normal_state, StateData};
               Now >= Activity#activity.message_time + MinMessageInterval,
               MessageShaperInterval == 0 ->
@@ -328,8 +326,8 @@ normal_state({route, From, <<"">>,
        end
     catch _:{xmpp_codec, Why} ->
            ErrTxt = xmpp:format_error(Why),
-           Err = xmpp:make_error(IQ0, xmpp:err_bad_request(ErrTxt, Lang)),
-           ejabberd_router:route(StateData#state.jid, From, Err)
+           Err = xmpp:err_bad_request(ErrTxt, Lang),
+           ejabberd_router:route_error(StateData#state.jid, From, IQ0, Err)
     end;
 normal_state({route, From, <<"">>, #iq{} = IQ}, StateData) ->
     Err = xmpp:err_bad_request(),
@@ -1821,9 +1819,8 @@ add_new_user(From, Nick, Packet, StateData) ->
       {false, _, _, _} when NUsers >= MaxUsers orelse NUsers >= MaxAdminUsers ->
          Txt = <<"Too many users in this conference">>,
          Err = xmpp:err_resource_constraint(Txt, Lang),
-         ErrPacket = xmpp:make_error(Packet, Err),
          if not IsSubscribeRequest ->
-                 ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                 ejabberd_router:route_error(UserRoomJID, From, Packet, Err),
                  StateData;
             true ->
                  {error, Err}
@@ -1831,18 +1828,16 @@ add_new_user(From, Nick, Packet, StateData) ->
       {false, _, _, _} when NConferences >= MaxConferences ->
          Txt = <<"You have joined too many conferences">>,
          Err = xmpp:err_resource_constraint(Txt, Lang),
-         ErrPacket = xmpp:make_error(Packet, Err),
          if not IsSubscribeRequest ->
-                 ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                 ejabberd_router:route_error(UserRoomJID, From, Packet, Err),
                  StateData;
             true ->
                  {error, Err}
          end;
       {false, _, _, _} ->
          Err = xmpp:err_service_unavailable(),
-         ErrPacket = xmpp:make_error(Packet, Err),
          if not IsSubscribeRequest ->
-                 ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                 ejabberd_router:route_error(UserRoomJID, From, Packet, Err),
                  StateData;
             true ->
                  {error, Err}
@@ -1856,9 +1851,8 @@ add_new_user(From, Nick, Packet, StateData) ->
                        ErrText = <<"Membership is required to enter this room">>,
                        xmpp:err_registration_required(ErrText, Lang)
                end,
-         ErrPacket = xmpp:make_error(Packet, Err),
          if not IsSubscribeRequest ->
-                 ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                 ejabberd_router:route_error(UserRoomJID, From, Packet, Err),
                  StateData;
             true ->
                  {error, Err}
@@ -1866,9 +1860,8 @@ add_new_user(From, Nick, Packet, StateData) ->
       {_, true, _, _} ->
          ErrText = <<"That nickname is already in use by another occupant">>,
          Err = xmpp:err_conflict(ErrText, Lang),
-         ErrPacket = xmpp:make_error(Packet, Err),
          if not IsSubscribeRequest ->
-                 ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                 ejabberd_router:route_error(UserRoomJID, From, Packet, Err),
                  StateData;
             true ->
                  {error, Err}
@@ -1876,9 +1869,8 @@ add_new_user(From, Nick, Packet, StateData) ->
       {_, _, false, _} ->
          ErrText = <<"That nickname is registered by another person">>,
          Err = xmpp:err_conflict(ErrText, Lang),
-         ErrPacket = xmpp:make_error(Packet, Err),
          if not IsSubscribeRequest ->
-                 ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                 ejabberd_router:route_error(UserRoomJID, From, Packet, Err),
                  StateData;
             true ->
                  {error, Err}
@@ -1918,9 +1910,8 @@ add_new_user(From, Nick, Packet, StateData) ->
            nopass ->
                ErrText = <<"A password is required to enter this room">>,
                Err = xmpp:err_not_authorized(ErrText, Lang),
-               ErrPacket = xmpp:make_error(Packet, Err),
                if not IsSubscribeRequest ->
-                       ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                       ejabberd_router:route_error(UserRoomJID, From, Packet, Err),
                        StateData;
                   true ->
                        {error, Err}
@@ -1948,9 +1939,9 @@ add_new_user(From, Nick, Packet, StateData) ->
                  {error, limit} ->
                      ErrText = <<"Too many CAPTCHA requests">>,
                      Err = xmpp:err_resource_constraint(ErrText, Lang),
-                     ErrPacket = xmpp:make_error(Packet, Err),
                      if not IsSubscribeRequest ->
-                             ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                             ejabberd_router:route_error(
+                               UserRoomJID, From, Packet, Err),
                              StateData;
                         true ->
                              {error, Err}
@@ -1958,9 +1949,9 @@ add_new_user(From, Nick, Packet, StateData) ->
                  _ ->
                      ErrText = <<"Unable to generate a CAPTCHA">>,
                      Err = xmpp:err_internal_server_error(ErrText, Lang),
-                     ErrPacket = xmpp:make_error(Packet, Err),
                      if not IsSubscribeRequest ->
-                             ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                             ejabberd_router:route_error(
+                               UserRoomJID, From, Packet, Err),
                              StateData;
                         true ->
                              {error, Err}
@@ -1969,9 +1960,9 @@ add_new_user(From, Nick, Packet, StateData) ->
            _ ->
                ErrText = <<"Incorrect password">>,
                Err = xmpp:err_not_authorized(ErrText, Lang),
-               ErrPacket = xmpp:make_error(Packet, Err),
                if not IsSubscribeRequest ->
-                       ejabberd_router:route(UserRoomJID, From, ErrPacket),
+                       ejabberd_router:route_error(
+                         UserRoomJID, From, Packet, Err),
                        StateData;
                   true ->
                        {error, Err}
index eedbcaeb17ec55dc10765323fb1d3f618e22de9f..42bc46631e9e911d1dbea07d74610ac39788fa9c 100644 (file)
@@ -623,9 +623,8 @@ discard_warn_sender(Msgs) ->
              ErrText = <<"Your contact offline message queue is "
                          "full. The message has been discarded.">>,
              Lang = xmpp:get_lang(Packet),
-             Err = xmpp:make_error(
-                     Packet, xmpp:err_resource_constraint(ErrText, Lang)),
-             ejabberd_router:route(To, From, Err)
+             Err = xmpp:err_resource_constraint(ErrText, Lang),
+             ejabberd_router:route_error(To, From, Packet, Err)
       end, Msgs).
 
 webadmin_page(_, Host,