25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

Merge branch 'master' of github.com:processone/ejabberd

This commit is contained in:
Christophe Romain 2016-11-25 10:07:04 +01:00
commit 18609befa4
7 changed files with 54 additions and 97 deletions

View 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.
%%====================================================================

View 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.

View 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().

View 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),

View 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),

View 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}

View 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,