mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Replace some ?ERR_* macros with ?ERRT_*
This commit is contained in:
parent
b160bd7ac1
commit
fced8dc3d9
@ -68,7 +68,9 @@ parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}
|
||||
xdata = XData,
|
||||
others = Others
|
||||
};
|
||||
parse_request(_) -> {error, ?ERR_BAD_REQUEST}.
|
||||
parse_request(#iq{lang = Lang}) ->
|
||||
Text = <<"Failed to parse ad-hoc command request">>,
|
||||
{error, ?ERRT_BAD_REQUEST(Lang, Text)}.
|
||||
|
||||
%% Borrowed from mod_vcard.erl
|
||||
find_xdata_el(#xmlel{children = SubEls}) ->
|
||||
|
@ -619,8 +619,9 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
|
||||
send_element(StateData, Res),
|
||||
fsm_next_state(wait_for_auth, StateData);
|
||||
{auth, _ID, set, {_U, _P, _D, <<"">>}} ->
|
||||
Err = jlib:make_error_reply(El,
|
||||
?ERR_AUTH_NO_RESOURCE_PROVIDED((StateData#state.lang))),
|
||||
Lang = StateData#state.lang,
|
||||
Txt = <<"No resource provided">>,
|
||||
Err = jlib:make_error_reply(El, ?ERRT_NOT_ACCEPTABLE(Lang, Txt)),
|
||||
send_element(StateData, Err),
|
||||
fsm_next_state(wait_for_auth, StateData);
|
||||
{auth, _ID, set, {U, P, D, R}} ->
|
||||
@ -685,7 +686,10 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
|
||||
ejabberd_hooks:run(c2s_auth_result, StateData#state.server,
|
||||
[false, U, StateData#state.server,
|
||||
StateData#state.ip]),
|
||||
Err = jlib:make_error_reply(El, ?ERR_NOT_AUTHORIZED),
|
||||
Lang = StateData#state.lang,
|
||||
Txt = <<"Legacy authentication failed">>,
|
||||
Err = jlib:make_error_reply(
|
||||
El, ?ERRT_NOT_AUTHORIZED(Lang, Txt)),
|
||||
send_element(StateData, Err),
|
||||
fsm_next_state(wait_for_auth, StateData)
|
||||
end;
|
||||
@ -706,7 +710,9 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
|
||||
ejabberd_hooks:run(c2s_auth_result, StateData#state.server,
|
||||
[false, U, StateData#state.server,
|
||||
StateData#state.ip]),
|
||||
Err = jlib:make_error_reply(El, ?ERR_NOT_ALLOWED),
|
||||
Lang = StateData#state.lang,
|
||||
Txt = <<"Legacy authentication forbidden">>,
|
||||
Err = jlib:make_error_reply(El, ?ERRT_NOT_ALLOWED(Lang, Txt)),
|
||||
send_element(StateData, Err),
|
||||
fsm_next_state(wait_for_auth, StateData)
|
||||
end
|
||||
@ -1013,7 +1019,7 @@ wait_for_bind({xmlstreamelement, #xmlel{name = Name, attrs = Attrs} = El},
|
||||
end;
|
||||
wait_for_bind({xmlstreamelement, El}, StateData) ->
|
||||
case jlib:iq_query_info(El) of
|
||||
#iq{type = set, xmlns = ?NS_BIND, sub_el = SubEl} =
|
||||
#iq{type = set, lang = Lang, xmlns = ?NS_BIND, sub_el = SubEl} =
|
||||
IQ ->
|
||||
U = StateData#state.user,
|
||||
R1 = fxml:get_path_s(SubEl,
|
||||
@ -1025,7 +1031,8 @@ wait_for_bind({xmlstreamelement, El}, StateData) ->
|
||||
end,
|
||||
case R of
|
||||
error ->
|
||||
Err = jlib:make_error_reply(El, ?ERR_BAD_REQUEST),
|
||||
Txt = <<"Malformed resource">>,
|
||||
Err = jlib:make_error_reply(El, ?ERRT_BAD_REQUEST(Lang, Txt)),
|
||||
send_element(StateData, Err),
|
||||
fsm_next_state(wait_for_bind, StateData);
|
||||
_ ->
|
||||
@ -1099,6 +1106,7 @@ open_session(StateData) ->
|
||||
U = StateData#state.user,
|
||||
R = StateData#state.resource,
|
||||
JID = StateData#state.jid,
|
||||
Lang = StateData#state.lang,
|
||||
case acl:match_rule(StateData#state.server,
|
||||
StateData#state.access, JID) of
|
||||
allow ->
|
||||
@ -1136,7 +1144,8 @@ open_session(StateData) ->
|
||||
StateData#state.server, [JID]),
|
||||
?INFO_MSG("(~w) Forbidden session for ~s",
|
||||
[StateData#state.socket, jid:to_string(JID)]),
|
||||
{error, ?ERR_NOT_ALLOWED}
|
||||
Txt = <<"Denied by ACL">>,
|
||||
{error, ?ERRT_NOT_ALLOWED(Lang, Txt)}
|
||||
end.
|
||||
|
||||
session_established({xmlstreamelement, #xmlel{name = Name} = El}, StateData)
|
||||
@ -2275,30 +2284,32 @@ get_priority_from_presence(PresencePacket) ->
|
||||
end.
|
||||
|
||||
process_privacy_iq(From, To,
|
||||
#iq{type = Type, sub_el = SubEl} = IQ, StateData) ->
|
||||
{Res, NewStateData} = case Type of
|
||||
get ->
|
||||
R = ejabberd_hooks:run_fold(privacy_iq_get,
|
||||
StateData#state.server,
|
||||
{error,
|
||||
?ERR_FEATURE_NOT_IMPLEMENTED},
|
||||
[From, To, IQ,
|
||||
StateData#state.privacy_list]),
|
||||
{R, StateData};
|
||||
set ->
|
||||
case ejabberd_hooks:run_fold(privacy_iq_set,
|
||||
StateData#state.server,
|
||||
{error,
|
||||
?ERR_FEATURE_NOT_IMPLEMENTED},
|
||||
[From, To, IQ])
|
||||
of
|
||||
{result, R, NewPrivList} ->
|
||||
{{result, R},
|
||||
StateData#state{privacy_list =
|
||||
NewPrivList}};
|
||||
R -> {R, StateData}
|
||||
end
|
||||
end,
|
||||
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ, StateData) ->
|
||||
Txt = <<"No module is handling this query">>,
|
||||
{Res, NewStateData} =
|
||||
case Type of
|
||||
get ->
|
||||
R = ejabberd_hooks:run_fold(
|
||||
privacy_iq_get,
|
||||
StateData#state.server,
|
||||
{error, ?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)},
|
||||
[From, To, IQ,
|
||||
StateData#state.privacy_list]),
|
||||
{R, StateData};
|
||||
set ->
|
||||
case ejabberd_hooks:run_fold(
|
||||
privacy_iq_set,
|
||||
StateData#state.server,
|
||||
{error, ?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)},
|
||||
[From, To, IQ])
|
||||
of
|
||||
{result, R, NewPrivList} ->
|
||||
{{result, R},
|
||||
StateData#state{privacy_list =
|
||||
NewPrivList}};
|
||||
R -> {R, StateData}
|
||||
end
|
||||
end,
|
||||
IQRes = case Res of
|
||||
{result, Result} ->
|
||||
IQ#iq{type = result, sub_el = Result};
|
||||
@ -2365,15 +2376,16 @@ process_unauthenticated_stanza(StateData, El) ->
|
||||
_ -> El
|
||||
end,
|
||||
case jlib:iq_query_info(NewEl) of
|
||||
#iq{} = IQ ->
|
||||
#iq{lang = L} = IQ ->
|
||||
Res = ejabberd_hooks:run_fold(c2s_unauthenticated_iq,
|
||||
StateData#state.server, empty,
|
||||
[StateData#state.server, IQ,
|
||||
StateData#state.ip]),
|
||||
case Res of
|
||||
empty ->
|
||||
Txt = <<"Authentication required">>,
|
||||
ResIQ = IQ#iq{type = error,
|
||||
sub_el = [?ERR_SERVICE_UNAVAILABLE]},
|
||||
sub_el = [?ERRT_SERVICE_UNAVAILABLE(L, Txt)]},
|
||||
Res1 = jlib:replace_from_to(jid:make(<<"">>,
|
||||
StateData#state.server,
|
||||
<<"">>),
|
||||
@ -2879,6 +2891,7 @@ handle_unacked_stanzas(StateData)
|
||||
false
|
||||
end
|
||||
end,
|
||||
Lang = StateData#state.lang,
|
||||
ReRoute = case ResendOnTimeout of
|
||||
true ->
|
||||
fun(From, To, El, Time) ->
|
||||
@ -2887,9 +2900,11 @@ handle_unacked_stanzas(StateData)
|
||||
end;
|
||||
false ->
|
||||
fun(From, To, El, _Time) ->
|
||||
Txt = <<"User session not found">>,
|
||||
Err =
|
||||
jlib:make_error_reply(El,
|
||||
?ERR_SERVICE_UNAVAILABLE),
|
||||
jlib:make_error_reply(
|
||||
El,
|
||||
?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end
|
||||
end,
|
||||
@ -2897,7 +2912,9 @@ handle_unacked_stanzas(StateData)
|
||||
?DEBUG("Dropping presence stanza from ~s",
|
||||
[jid:to_string(From)]);
|
||||
(From, To, #xmlel{name = <<"iq">>} = El, _Time) ->
|
||||
Err = jlib:make_error_reply(El, ?ERR_SERVICE_UNAVAILABLE),
|
||||
Txt = <<"User session not found">>,
|
||||
Err = jlib:make_error_reply(
|
||||
El, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
(From, To, El, Time) ->
|
||||
%% We'll drop the stanza if it was <forwarded/> by some
|
||||
|
@ -74,7 +74,7 @@ start_link() ->
|
||||
process_iq(From, To, Packet) ->
|
||||
IQ = jlib:iq_query_info(Packet),
|
||||
case IQ of
|
||||
#iq{xmlns = XMLNS} ->
|
||||
#iq{xmlns = XMLNS, lang = Lang} ->
|
||||
Host = To#jid.lserver,
|
||||
case ets:lookup(?IQTABLE, {XMLNS, Host}) of
|
||||
[{_, Module, Function}] ->
|
||||
@ -87,8 +87,10 @@ process_iq(From, To, Packet) ->
|
||||
gen_iq_handler:handle(Host, Module, Function, Opts,
|
||||
From, To, IQ);
|
||||
[] ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_FEATURE_NOT_IMPLEMENTED),
|
||||
Txt = <<"No module is handling this query">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet,
|
||||
?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end;
|
||||
reply ->
|
||||
@ -166,8 +168,10 @@ refresh_iq_handlers() ->
|
||||
ejabberd_local ! refresh_iq_handlers.
|
||||
|
||||
bounce_resource_packet(From, To, Packet) ->
|
||||
Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
|
||||
Txt = <<"No available resource found">>,
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_ITEM_NOT_FOUND),
|
||||
?ERRT_ITEM_NOT_FOUND(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err),
|
||||
stop.
|
||||
|
||||
|
@ -312,8 +312,10 @@ do_route(From, To, Packet) ->
|
||||
<<"error">> -> ok;
|
||||
<<"result">> -> ok;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_SERVICE_UNAVAILABLE),
|
||||
Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
|
||||
Txt = <<"No s2s connection found">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end,
|
||||
false
|
||||
|
@ -280,7 +280,9 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
||||
and (FromJID /= error) ->
|
||||
ejabberd_router:route(FromJID, ToJID, NewEl);
|
||||
true ->
|
||||
Err = jlib:make_error_reply(NewEl, ?ERR_BAD_REQUEST),
|
||||
Lang = fxml:get_tag_attr_s(<<"xml:lang">>, El),
|
||||
Txt = <<"Incorrect stanza name or from/to JID">>,
|
||||
Err = jlib:make_error_reply(NewEl, ?ERRT_BAD_REQUEST(Lang, Txt)),
|
||||
send_element(StateData, Err),
|
||||
error
|
||||
end,
|
||||
@ -360,7 +362,9 @@ handle_info({route, From, To, Packet}, StateName,
|
||||
attrs = Attrs2, children = Els}),
|
||||
send_text(StateData, Text);
|
||||
deny ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED),
|
||||
Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
|
||||
Txt = <<"Denied by ACL">>,
|
||||
Err = jlib:make_error_reply(Packet, ?ERRT_NOT_ALLOWED(Lang, Txt)),
|
||||
ejabberd_router:route_error(To, From, Err, Packet)
|
||||
end,
|
||||
{next_state, StateName, StateData};
|
||||
|
@ -159,8 +159,10 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
|
||||
-spec bounce_offline_message(jid(), jid(), xmlel()) -> stop.
|
||||
|
||||
bounce_offline_message(From, To, Packet) ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_SERVICE_UNAVAILABLE),
|
||||
Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
|
||||
Txt = <<"User session not found">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err),
|
||||
stop.
|
||||
|
||||
@ -423,6 +425,7 @@ do_route(From, To, #xmlel{} = Packet) ->
|
||||
#jid{user = User, server = Server,
|
||||
luser = LUser, lserver = LServer, lresource = LResource} = To,
|
||||
#xmlel{name = Name, attrs = Attrs} = Packet,
|
||||
Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
|
||||
case LResource of
|
||||
<<"">> ->
|
||||
case Name of
|
||||
@ -496,8 +499,9 @@ do_route(From, To, #xmlel{} = Packet) ->
|
||||
<<"headline">> -> route_message(From, To, Packet, headline);
|
||||
<<"error">> -> ok;
|
||||
<<"groupchat">> ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_SERVICE_UNAVAILABLE),
|
||||
ErrTxt = <<"Incorrect message type">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
_ ->
|
||||
route_message(From, To, Packet, normal)
|
||||
@ -517,8 +521,10 @@ do_route(From, To, #xmlel{} = Packet) ->
|
||||
<<"">> -> route_message(From, To, Packet, normal);
|
||||
<<"error">> -> ok;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_SERVICE_UNAVAILABLE),
|
||||
ErrTxt = <<"Incorrect message type">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet,
|
||||
?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end;
|
||||
<<"iq">> ->
|
||||
@ -526,8 +532,10 @@ do_route(From, To, #xmlel{} = Packet) ->
|
||||
<<"error">> -> ok;
|
||||
<<"result">> -> ok;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_SERVICE_UNAVAILABLE),
|
||||
ErrTxt = <<"User session not found">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet,
|
||||
?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end;
|
||||
_ -> ?DEBUG("packet dropped~n", [])
|
||||
@ -684,7 +692,7 @@ get_max_user_sessions(LUser, Host) ->
|
||||
process_iq(From, To, Packet) ->
|
||||
IQ = jlib:iq_query_info(Packet),
|
||||
case IQ of
|
||||
#iq{xmlns = XMLNS} ->
|
||||
#iq{xmlns = XMLNS, lang = Lang} ->
|
||||
Host = To#jid.lserver,
|
||||
case ets:lookup(sm_iqtable, {XMLNS, Host}) of
|
||||
[{_, Module, Function}] ->
|
||||
@ -697,8 +705,10 @@ process_iq(From, To, Packet) ->
|
||||
gen_iq_handler:handle(Host, Module, Function, Opts,
|
||||
From, To, IQ);
|
||||
[] ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_SERVICE_UNAVAILABLE),
|
||||
Txt = <<"No module is handling this query">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet,
|
||||
?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err)
|
||||
end;
|
||||
reply -> ok;
|
||||
|
@ -233,7 +233,7 @@ process_sm_iq(From, To, IQ) ->
|
||||
process_adhoc_request(From, To, IQ, adhoc_sm_commands).
|
||||
|
||||
process_adhoc_request(From, To,
|
||||
#iq{sub_el = SubEl} = IQ, Hook) ->
|
||||
#iq{sub_el = SubEl, lang = Lang} = IQ, Hook) ->
|
||||
?DEBUG("About to parse ~p...", [IQ]),
|
||||
case adhoc:parse_request(IQ) of
|
||||
{error, Error} ->
|
||||
@ -245,8 +245,9 @@ process_adhoc_request(From, To,
|
||||
of
|
||||
ignore -> ignore;
|
||||
empty ->
|
||||
Txt = <<"No hook has processed this command">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]};
|
||||
sub_el = [SubEl, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)]};
|
||||
{error, Error} ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, Error]};
|
||||
Command -> IQ#iq{type = result, sub_el = [Command]}
|
||||
@ -277,7 +278,9 @@ ping_command(_Acc, _From, _To,
|
||||
[{<<"info">>,
|
||||
translate:translate(Lang,
|
||||
<<"Pong">>)}]});
|
||||
true -> {error, ?ERR_BAD_REQUEST}
|
||||
true ->
|
||||
Txt = <<"Incorrect value of 'action' attribute">>,
|
||||
{error, ?ERRT_BAD_REQUEST(Lang, Txt)}
|
||||
end;
|
||||
ping_command(Acc, _From, _To, _Request) -> Acc.
|
||||
|
||||
|
@ -64,29 +64,33 @@ process_iq(_From, _To, IQ) ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
|
||||
|
||||
process_iq_get(_, From, _To,
|
||||
#iq{xmlns = ?NS_BLOCKING,
|
||||
#iq{xmlns = ?NS_BLOCKING, lang = Lang,
|
||||
sub_el = #xmlel{name = <<"blocklist">>}},
|
||||
_) ->
|
||||
#jid{luser = LUser, lserver = LServer} = From,
|
||||
{stop, process_blocklist_get(LUser, LServer)};
|
||||
{stop, process_blocklist_get(LUser, LServer, Lang)};
|
||||
process_iq_get(Acc, _, _, _, _) -> Acc.
|
||||
|
||||
process_iq_set(_, From, _To,
|
||||
#iq{xmlns = ?NS_BLOCKING,
|
||||
#iq{xmlns = ?NS_BLOCKING, lang = Lang,
|
||||
sub_el =
|
||||
#xmlel{name = SubElName, children = SubEls}}) ->
|
||||
#jid{luser = LUser, lserver = LServer} = From,
|
||||
Res = case {SubElName, fxml:remove_cdata(SubEls)} of
|
||||
{<<"block">>, []} -> {error, ?ERR_BAD_REQUEST};
|
||||
{<<"block">>, []} ->
|
||||
Txt = <<"No items found in this query">>,
|
||||
{error, ?ERRT_BAD_REQUEST(Lang, Txt)};
|
||||
{<<"block">>, Els} ->
|
||||
JIDs = parse_blocklist_items(Els, []),
|
||||
process_blocklist_block(LUser, LServer, JIDs);
|
||||
process_blocklist_block(LUser, LServer, JIDs, Lang);
|
||||
{<<"unblock">>, []} ->
|
||||
process_blocklist_unblock_all(LUser, LServer);
|
||||
process_blocklist_unblock_all(LUser, LServer, Lang);
|
||||
{<<"unblock">>, Els} ->
|
||||
JIDs = parse_blocklist_items(Els, []),
|
||||
process_blocklist_unblock(LUser, LServer, JIDs);
|
||||
_ -> {error, ?ERR_BAD_REQUEST}
|
||||
process_blocklist_unblock(LUser, LServer, JIDs, Lang);
|
||||
_ ->
|
||||
Txt = <<"Unknown blocking command">>,
|
||||
{error, ?ERRT_BAD_REQUEST(Lang, Txt)}
|
||||
end,
|
||||
{stop, Res};
|
||||
process_iq_set(Acc, _, _, _) -> Acc.
|
||||
@ -125,7 +129,7 @@ parse_blocklist_items([#xmlel{name = <<"item">>,
|
||||
parse_blocklist_items([_ | Els], JIDs) ->
|
||||
parse_blocklist_items(Els, JIDs).
|
||||
|
||||
process_blocklist_block(LUser, LServer, JIDs) ->
|
||||
process_blocklist_block(LUser, LServer, JIDs, Lang) ->
|
||||
Filter = fun (List) ->
|
||||
AlreadyBlocked = list_to_blocklist_jids(List, []),
|
||||
lists:foldr(fun (JID, List1) ->
|
||||
@ -143,8 +147,8 @@ process_blocklist_block(LUser, LServer, JIDs) ->
|
||||
end,
|
||||
List, JIDs)
|
||||
end,
|
||||
case process_blocklist_block(LUser, LServer, Filter,
|
||||
gen_mod:db_type(LServer, mod_privacy))
|
||||
case process_blocklist_block_db(LUser, LServer, Filter,
|
||||
gen_mod:db_type(LServer, mod_privacy))
|
||||
of
|
||||
{atomic, {ok, Default, List}} ->
|
||||
UserList = make_userlist(Default, List),
|
||||
@ -155,11 +159,11 @@ process_blocklist_block(LUser, LServer, JIDs) ->
|
||||
{result, [], UserList};
|
||||
_Err ->
|
||||
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, <<"Database failure">>)}
|
||||
end.
|
||||
|
||||
process_blocklist_block(LUser, LServer, Filter,
|
||||
mnesia) ->
|
||||
process_blocklist_block_db(LUser, LServer, Filter,
|
||||
mnesia) ->
|
||||
F = fun () ->
|
||||
case mnesia:wread({privacy, {LUser, LServer}}) of
|
||||
[] ->
|
||||
@ -185,8 +189,8 @@ process_blocklist_block(LUser, LServer, Filter,
|
||||
{ok, NewDefault, NewList}
|
||||
end,
|
||||
mnesia:transaction(F);
|
||||
process_blocklist_block(LUser, LServer, Filter,
|
||||
riak) ->
|
||||
process_blocklist_block_db(LUser, LServer, Filter,
|
||||
riak) ->
|
||||
{atomic,
|
||||
begin
|
||||
case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(),
|
||||
@ -218,7 +222,7 @@ process_blocklist_block(LUser, LServer, Filter,
|
||||
Err
|
||||
end
|
||||
end};
|
||||
process_blocklist_block(LUser, LServer, Filter, odbc) ->
|
||||
process_blocklist_block_db(LUser, LServer, Filter, odbc) ->
|
||||
F = fun () ->
|
||||
Default = case
|
||||
mod_privacy:sql_get_default_privacy_list_t(LUser)
|
||||
@ -246,7 +250,7 @@ process_blocklist_block(LUser, LServer, Filter, odbc) ->
|
||||
end,
|
||||
ejabberd_odbc:sql_transaction(LServer, F).
|
||||
|
||||
process_blocklist_unblock_all(LUser, LServer) ->
|
||||
process_blocklist_unblock_all(LUser, LServer, Lang) ->
|
||||
Filter = fun (List) ->
|
||||
lists:filter(fun (#listitem{action = A}) -> A =/= deny
|
||||
end,
|
||||
@ -263,10 +267,10 @@ process_blocklist_unblock_all(LUser, LServer) ->
|
||||
{result, [], UserList};
|
||||
_Err ->
|
||||
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer}, _Err]),
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, <<"Database failure">>)}
|
||||
end.
|
||||
|
||||
process_blocklist_unblock(LUser, LServer, JIDs) ->
|
||||
process_blocklist_unblock(LUser, LServer, JIDs, Lang) ->
|
||||
Filter = fun (List) ->
|
||||
lists:filter(fun (#listitem{action = deny, type = jid,
|
||||
value = JID}) ->
|
||||
@ -287,7 +291,7 @@ process_blocklist_unblock(LUser, LServer, JIDs) ->
|
||||
{result, [], UserList};
|
||||
_Err ->
|
||||
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _Err]),
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, <<"Database failure">>)}
|
||||
end.
|
||||
|
||||
unblock_by_filter(LUser, LServer, Filter, mnesia) ->
|
||||
@ -375,11 +379,12 @@ broadcast_blocklist_event(LUser, LServer, Event) ->
|
||||
ejabberd_sm:route(JID, JID,
|
||||
{broadcast, {blocking, Event}}).
|
||||
|
||||
process_blocklist_get(LUser, LServer) ->
|
||||
case process_blocklist_get(LUser, LServer,
|
||||
gen_mod:db_type(LServer, mod_privacy))
|
||||
process_blocklist_get(LUser, LServer, Lang) ->
|
||||
case process_blocklist_get_db(LUser, LServer,
|
||||
gen_mod:db_type(LServer, mod_privacy))
|
||||
of
|
||||
error -> {error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
error ->
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, <<"Database failure">>)};
|
||||
List ->
|
||||
JIDs = list_to_blocklist_jids(List, []),
|
||||
Items = lists:map(fun (JID) ->
|
||||
@ -397,7 +402,7 @@ process_blocklist_get(LUser, LServer) ->
|
||||
children = Items}]}
|
||||
end.
|
||||
|
||||
process_blocklist_get(LUser, LServer, mnesia) ->
|
||||
process_blocklist_get_db(LUser, LServer, mnesia) ->
|
||||
case catch mnesia:dirty_read(privacy, {LUser, LServer})
|
||||
of
|
||||
{'EXIT', _Reason} -> error;
|
||||
@ -408,7 +413,7 @@ process_blocklist_get(LUser, LServer, mnesia) ->
|
||||
_ -> []
|
||||
end
|
||||
end;
|
||||
process_blocklist_get(LUser, LServer, riak) ->
|
||||
process_blocklist_get_db(LUser, LServer, riak) ->
|
||||
case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(),
|
||||
{LUser, LServer}) of
|
||||
{ok, #privacy{default = Default, lists = Lists}} ->
|
||||
@ -421,7 +426,7 @@ process_blocklist_get(LUser, LServer, riak) ->
|
||||
{error, _} ->
|
||||
error
|
||||
end;
|
||||
process_blocklist_get(LUser, LServer, odbc) ->
|
||||
process_blocklist_get_db(LUser, LServer, odbc) ->
|
||||
case catch
|
||||
mod_privacy:sql_get_default_privacy_list(LUser, LServer)
|
||||
of
|
||||
|
@ -102,7 +102,9 @@ iq_handler2(From, To, IQ) ->
|
||||
iq_handler1(From, To, IQ) ->
|
||||
iq_handler(From, To, IQ, ?NS_CARBONS_1).
|
||||
|
||||
iq_handler(From, _To, #iq{type=set, sub_el = #xmlel{name = Operation, children = []}} = IQ, CC)->
|
||||
iq_handler(From, _To,
|
||||
#iq{type=set, lang = Lang,
|
||||
sub_el = #xmlel{name = Operation} = SubEl} = IQ, CC)->
|
||||
?DEBUG("carbons IQ received: ~p", [IQ]),
|
||||
{U, S, R} = jid:tolower(From),
|
||||
Result = case Operation of
|
||||
@ -118,12 +120,14 @@ iq_handler(From, _To, #iq{type=set, sub_el = #xmlel{name = Operation, children
|
||||
?DEBUG("carbons IQ result: ok", []),
|
||||
IQ#iq{type=result, sub_el=[]};
|
||||
{error,_Error} ->
|
||||
?WARNING_MSG("Error enabling / disabling carbons: ~p", [Result]),
|
||||
IQ#iq{type=error,sub_el = [?ERR_BAD_REQUEST]}
|
||||
?ERROR_MSG("Error enabling / disabling carbons: ~p", [Result]),
|
||||
Txt = <<"Database failure">>,
|
||||
IQ#iq{type=error,sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]}
|
||||
end;
|
||||
|
||||
iq_handler(_From, _To, IQ, _CC)->
|
||||
IQ#iq{type=error, sub_el = [?ERR_NOT_ALLOWED]}.
|
||||
iq_handler(_From, _To, #iq{lang = Lang, sub_el = SubEl} = IQ, _CC)->
|
||||
Txt = <<"Value 'get' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type=error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]}.
|
||||
|
||||
user_send_packet(Packet, _C2SState, From, To) ->
|
||||
check_and_forward(From, To, Packet, sent).
|
||||
|
@ -56,15 +56,17 @@ stop(Host) ->
|
||||
?NS_ECONFIGURE).
|
||||
|
||||
process_local_iq(From, To,
|
||||
#iq{type = Type, lang = _Lang, sub_el = SubEl} = IQ) ->
|
||||
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
||||
case acl:match_rule(To#jid.lserver, configure, From) of
|
||||
deny ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Denied by ACL">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
allow ->
|
||||
case Type of
|
||||
set ->
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]};
|
||||
sub_el = [SubEl, ?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)]};
|
||||
%%case fxml:get_tag_attr_s("type", SubEl) of
|
||||
%% "cancel" ->
|
||||
%% IQ#iq{type = result,
|
||||
@ -98,7 +100,7 @@ process_local_iq(From, To,
|
||||
%% sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
|
||||
%%end;
|
||||
get ->
|
||||
case process_get(SubEl) of
|
||||
case process_get(SubEl, Lang) of
|
||||
{result, Res} -> IQ#iq{type = result, sub_el = [Res]};
|
||||
{error, Error} ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, Error]}
|
||||
@ -106,7 +108,7 @@ process_local_iq(From, To,
|
||||
end
|
||||
end.
|
||||
|
||||
process_get(#xmlel{name = <<"info">>}) ->
|
||||
process_get(#xmlel{name = <<"info">>}, _Lang) ->
|
||||
S2SConns = ejabberd_s2s:dirty_get_connections(),
|
||||
TConns = lists:usort([element(2, C) || C <- S2SConns]),
|
||||
Attrs = [{<<"registered-users">>,
|
||||
@ -130,7 +132,7 @@ process_get(#xmlel{name = <<"info">>}) ->
|
||||
attrs = [{<<"xmlns">>, ?NS_ECONFIGURE} | Attrs],
|
||||
children = []}};
|
||||
process_get(#xmlel{name = <<"welcome-message">>,
|
||||
attrs = Attrs}) ->
|
||||
attrs = Attrs}, _Lang) ->
|
||||
{Subj, Body} = ejabberd_config:get_option(
|
||||
welcome_message,
|
||||
fun({Subj, Body}) ->
|
||||
@ -146,7 +148,7 @@ process_get(#xmlel{name = <<"welcome-message">>,
|
||||
#xmlel{name = <<"body">>, attrs = [],
|
||||
children = [{xmlcdata, Body}]}]}};
|
||||
process_get(#xmlel{name = <<"registration-watchers">>,
|
||||
attrs = Attrs}) ->
|
||||
attrs = Attrs}, _Lang) ->
|
||||
SubEls = ejabberd_config:get_option(
|
||||
registration_watchers,
|
||||
fun(JIDs) when is_list(JIDs) ->
|
||||
@ -160,14 +162,14 @@ process_get(#xmlel{name = <<"registration-watchers">>,
|
||||
{result,
|
||||
#xmlel{name = <<"registration_watchers">>,
|
||||
attrs = Attrs, children = SubEls}};
|
||||
process_get(#xmlel{name = <<"acls">>, attrs = Attrs}) ->
|
||||
process_get(#xmlel{name = <<"acls">>, attrs = Attrs}, _Lang) ->
|
||||
Str = iolist_to_binary(io_lib:format("~p.",
|
||||
[ets:tab2list(acl)])),
|
||||
{result,
|
||||
#xmlel{name = <<"acls">>, attrs = Attrs,
|
||||
children = [{xmlcdata, Str}]}};
|
||||
process_get(#xmlel{name = <<"access">>,
|
||||
attrs = Attrs}) ->
|
||||
attrs = Attrs}, _Lang) ->
|
||||
Str = iolist_to_binary(io_lib:format("~p.",
|
||||
[ets:select(local_config,
|
||||
[{{local_config, {access, '$1'},
|
||||
@ -178,13 +180,14 @@ process_get(#xmlel{name = <<"access">>,
|
||||
{result,
|
||||
#xmlel{name = <<"access">>, attrs = Attrs,
|
||||
children = [{xmlcdata, Str}]}};
|
||||
process_get(#xmlel{name = <<"last">>, attrs = Attrs}) ->
|
||||
process_get(#xmlel{name = <<"last">>, attrs = Attrs}, Lang) ->
|
||||
case catch mnesia:dirty_select(last_activity,
|
||||
[{{last_activity, '_', '$1', '_'}, [],
|
||||
['$1']}])
|
||||
of
|
||||
{'EXIT', _Reason} ->
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
Txt = <<"Database failure">>,
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)};
|
||||
Vals ->
|
||||
TimeStamp = p1_time_compat:system_time(seconds),
|
||||
Str = list_to_binary(
|
||||
@ -196,7 +199,7 @@ process_get(#xmlel{name = <<"last">>, attrs = Attrs}) ->
|
||||
end;
|
||||
%%process_get({xmlelement, Name, Attrs, SubEls}) ->
|
||||
%% {result, };
|
||||
process_get(_) -> {error, ?ERR_BAD_REQUEST}.
|
||||
process_get(_, _) -> {error, ?ERR_BAD_REQUEST}.
|
||||
|
||||
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
||||
mod_opt_type(_) -> [iqdisc].
|
||||
|
@ -118,7 +118,10 @@ handle_cast(_Msg, State) -> {noreply, State}.
|
||||
handle_info({route, From, To, Packet}, State) ->
|
||||
Packet2 = case From#jid.user of
|
||||
<<"">> ->
|
||||
jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST);
|
||||
Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
|
||||
Txt = <<"User part of JID in 'from' is empty">>,
|
||||
jlib:make_error_reply(
|
||||
Packet, ?ERRT_BAD_REQUEST(Lang, Txt));
|
||||
_ -> Packet
|
||||
end,
|
||||
do_client_version(disabled, To, From),
|
||||
|
@ -569,7 +569,8 @@ process_iq(From,
|
||||
deny ->
|
||||
?DEBUG("Denying HTTP upload slot request from ~s",
|
||||
[jid:to_string(From)]),
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}
|
||||
Txt = <<"Denied by ACL">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]}
|
||||
end;
|
||||
process_iq(_From, #iq{sub_el = SubEl} = IQ, _State) ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
@ -601,7 +602,8 @@ parse_request(#xmlel{name = <<"request">>, attrs = Attrs} = Request, Lang) ->
|
||||
{error, ?ERRT_BAD_REQUEST(Lang, Text)}
|
||||
end;
|
||||
_ ->
|
||||
{error, ?ERR_BAD_REQUEST}
|
||||
Text = <<"No or invalid XML namespace">>,
|
||||
{error, ?ERRT_BAD_REQUEST(Lang, Text)}
|
||||
end;
|
||||
parse_request(_El, _Lang) -> {error, ?ERR_BAD_REQUEST}.
|
||||
|
||||
@ -639,7 +641,7 @@ create_slot(#state{service_url = undefined,
|
||||
end;
|
||||
create_slot(#state{service_url = ServiceURL},
|
||||
#jid{luser = U, lserver = S} = JID, File, Size, ContentType,
|
||||
_Lang) ->
|
||||
Lang) ->
|
||||
Options = [{body_format, binary}, {full_result, false}],
|
||||
HttpOptions = [{timeout, ?SERVICE_REQUEST_TIMEOUT}],
|
||||
SizeStr = jlib:integer_to_binary(Size),
|
||||
@ -659,7 +661,8 @@ create_slot(#state{service_url = ServiceURL},
|
||||
Lines ->
|
||||
?ERROR_MSG("Can't parse data received for ~s from <~s>: ~p",
|
||||
[jid:to_string(JID), ServiceURL, Lines]),
|
||||
{error, ?ERR_SERVICE_UNAVAILABLE}
|
||||
Txt = <<"Failed to parse HTTP response">>,
|
||||
{error, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)}
|
||||
end;
|
||||
{ok, {402, _Body}} ->
|
||||
?INFO_MSG("Got status code 402 for ~s from <~s>",
|
||||
|
@ -86,10 +86,11 @@ stop(Host) ->
|
||||
%%%
|
||||
|
||||
process_local_iq(_From, _To,
|
||||
#iq{type = Type, sub_el = SubEl} = IQ) ->
|
||||
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
Sec = get_node_uptime(),
|
||||
IQ#iq{type = result,
|
||||
@ -123,10 +124,11 @@ now_to_seconds({MegaSecs, Secs, _MicroSecs}) ->
|
||||
%%%
|
||||
|
||||
process_sm_iq(From, To,
|
||||
#iq{type = Type, sub_el = SubEl} = IQ) ->
|
||||
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
User = To#jid.luser,
|
||||
Server = To#jid.lserver,
|
||||
@ -150,10 +152,12 @@ process_sm_iq(From, To,
|
||||
of
|
||||
allow -> get_last_iq(IQ, SubEl, User, Server);
|
||||
deny ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}
|
||||
Txt = <<"Denied by privacy lists">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]}
|
||||
end;
|
||||
true ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}
|
||||
Txt = <<"Not subscribed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]}
|
||||
end
|
||||
end.
|
||||
|
||||
@ -193,16 +197,18 @@ get_last(LUser, LServer, odbc) ->
|
||||
Reason -> {error, {invalid_result, Reason}}
|
||||
end.
|
||||
|
||||
get_last_iq(IQ, SubEl, LUser, LServer) ->
|
||||
get_last_iq(#iq{lang = Lang} = IQ, SubEl, LUser, LServer) ->
|
||||
case ejabberd_sm:get_user_resources(LUser, LServer) of
|
||||
[] ->
|
||||
case get_last(LUser, LServer) of
|
||||
{error, _Reason} ->
|
||||
Txt = <<"Database failure">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
|
||||
sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]};
|
||||
not_found ->
|
||||
Txt = <<"No info about last activity found">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]};
|
||||
sub_el = [SubEl, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)]};
|
||||
{ok, TimeStamp, Status} ->
|
||||
TimeStamp2 = p1_time_compat:system_time(seconds),
|
||||
Sec = TimeStamp2 - TimeStamp,
|
||||
|
@ -447,7 +447,7 @@ process_iq(LServer, #iq{sub_el = #xmlel{attrs = Attrs}} = IQ) ->
|
||||
% Preference setting (both v0.2 & v0.3)
|
||||
process_iq(#jid{luser = LUser, lserver = LServer},
|
||||
#jid{lserver = LServer},
|
||||
#iq{type = set, sub_el = #xmlel{name = <<"prefs">>} = SubEl} = IQ) ->
|
||||
#iq{type = set, lang = Lang, sub_el = #xmlel{name = <<"prefs">>} = SubEl} = IQ) ->
|
||||
try {case fxml:get_tag_attr_s(<<"default">>, SubEl) of
|
||||
<<"always">> -> always;
|
||||
<<"never">> -> never;
|
||||
@ -469,8 +469,9 @@ process_iq(#jid{luser = LUser, lserver = LServer},
|
||||
NewPrefs = prefs_el(Default, Always, Never, IQ#iq.xmlns),
|
||||
IQ#iq{type = result, sub_el = [NewPrefs]};
|
||||
_Err ->
|
||||
Txt = <<"Database failure">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
|
||||
sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]}
|
||||
end
|
||||
catch _:_ ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}
|
||||
|
@ -132,8 +132,9 @@ process_iq(From, To,
|
||||
{error, Err} ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, Err]}
|
||||
end;
|
||||
process_iq(_From, _To, #iq{sub_el = SubEl} = IQ) ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}.
|
||||
process_iq(_From, _To, #iq{sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
Txt = <<"Unsupported MIX query">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}.
|
||||
|
||||
%%%===================================================================
|
||||
%%% gen_server callbacks
|
||||
|
@ -1056,7 +1056,9 @@ iq_set_register_info(ServerHost, Host, From, Nick,
|
||||
ErrText = <<"That nickname is registered by another "
|
||||
"person">>,
|
||||
{error, ?ERRT_CONFLICT(Lang, ErrText)};
|
||||
_ -> {error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||
_ ->
|
||||
Txt = <<"Database failure">>,
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)}
|
||||
end.
|
||||
|
||||
process_iq_register_set(ServerHost, Host, From, SubEl,
|
||||
@ -1073,7 +1075,9 @@ process_iq_register_set(ServerHost, Host, From, SubEl,
|
||||
{?NS_XDATA, <<"submit">>} ->
|
||||
XData = jlib:parse_xdata_submit(XEl),
|
||||
case XData of
|
||||
invalid -> {error, ?ERR_BAD_REQUEST};
|
||||
invalid ->
|
||||
Txt = <<"Incorrect data form">>,
|
||||
{error, ?ERRT_BAD_REQUEST(Lang, Txt)};
|
||||
_ ->
|
||||
case lists:keysearch(<<"nick">>, 1, XData) of
|
||||
{value, {_, [Nick]}} when Nick /= <<"">> ->
|
||||
|
@ -387,8 +387,9 @@ handle_offline_query(#jid{luser = U, lserver = S} = From,
|
||||
end
|
||||
end,
|
||||
IQ#iq{type = result, sub_el = []};
|
||||
handle_offline_query(_From, _To, #iq{sub_el = SubEl} = IQ) ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}.
|
||||
handle_offline_query(_From, _To, #iq{sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
Txt = <<"Query to another users is forbidden">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]}.
|
||||
|
||||
handle_offline_items_view(JID, #xmlel{children = Items}) ->
|
||||
{U, S, R} = jid:tolower(JID),
|
||||
|
@ -204,13 +204,14 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
||||
%% Hook callbacks
|
||||
%%====================================================================
|
||||
iq_ping(_From, _To,
|
||||
#iq{type = Type, sub_el = SubEl} = IQ) ->
|
||||
#iq{type = Type, sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
case {Type, SubEl} of
|
||||
{get, #xmlel{name = <<"ping">>}} ->
|
||||
IQ#iq{type = result, sub_el = []};
|
||||
_ ->
|
||||
Txt = <<"Ping query is incorrect">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]}
|
||||
sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}
|
||||
end.
|
||||
|
||||
user_online(_SID, JID, _Info) ->
|
||||
|
@ -73,52 +73,58 @@ stop(Host) ->
|
||||
?NS_PRIVATE).
|
||||
|
||||
process_sm_iq(#jid{luser = LUser, lserver = LServer},
|
||||
#jid{luser = LUser, lserver = LServer}, IQ)
|
||||
#jid{luser = LUser, lserver = LServer}, #iq{lang = Lang} = IQ)
|
||||
when IQ#iq.type == set ->
|
||||
case IQ#iq.sub_el of
|
||||
#xmlel{name = <<"query">>, children = Xmlels} ->
|
||||
case filter_xmlels(Xmlels) of
|
||||
[] ->
|
||||
Txt = <<"No private data found in this query">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [IQ#iq.sub_el, ?ERR_NOT_ACCEPTABLE]};
|
||||
sub_el = [IQ#iq.sub_el, ?ERRT_NOT_ACCEPTABLE(Lang, Txt)]};
|
||||
Data ->
|
||||
set_data(LUser, LServer, Data),
|
||||
IQ#iq{type = result, sub_el = []}
|
||||
end;
|
||||
_ ->
|
||||
Txt = <<"No query found">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [IQ#iq.sub_el, ?ERR_NOT_ACCEPTABLE]}
|
||||
sub_el = [IQ#iq.sub_el, ?ERRT_NOT_ACCEPTABLE(Lang, Txt)]}
|
||||
end;
|
||||
%%
|
||||
process_sm_iq(#jid{luser = LUser, lserver = LServer},
|
||||
#jid{luser = LUser, lserver = LServer}, IQ)
|
||||
#jid{luser = LUser, lserver = LServer}, #iq{lang = Lang} = IQ)
|
||||
when IQ#iq.type == get ->
|
||||
case IQ#iq.sub_el of
|
||||
#xmlel{name = <<"query">>, attrs = Attrs,
|
||||
children = Xmlels} ->
|
||||
case filter_xmlels(Xmlels) of
|
||||
[] ->
|
||||
Txt = <<"No private data found in this query">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [IQ#iq.sub_el, ?ERR_BAD_FORMAT]};
|
||||
sub_el = [IQ#iq.sub_el, ?ERRT_BAD_FORMAT(Lang, Txt)]};
|
||||
Data ->
|
||||
case catch get_data(LUser, LServer, Data) of
|
||||
{'EXIT', _Reason} ->
|
||||
Txt = <<"Database failure">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el =
|
||||
[IQ#iq.sub_el, ?ERR_INTERNAL_SERVER_ERROR]};
|
||||
[IQ#iq.sub_el, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]};
|
||||
Storage_Xmlels ->
|
||||
IQ#iq{type = result,
|
||||
sub_el = [?Xmlel_Query(Attrs, Storage_Xmlels)]}
|
||||
end
|
||||
end;
|
||||
_ ->
|
||||
Txt = <<"No query found">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [IQ#iq.sub_el, ?ERR_BAD_FORMAT]}
|
||||
sub_el = [IQ#iq.sub_el, ?ERRT_BAD_FORMAT(Lang, Txt)]}
|
||||
end;
|
||||
%%
|
||||
process_sm_iq(_From, _To, IQ) ->
|
||||
process_sm_iq(_From, _To, #iq{lang = Lang} = IQ) ->
|
||||
Txt = <<"Query to another users is forbidden">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [IQ#iq.sub_el, ?ERR_FORBIDDEN]}.
|
||||
sub_el = [IQ#iq.sub_el, ?ERRT_FORBIDDEN(Lang, Txt)]}.
|
||||
|
||||
filter_xmlels(Xmlels) -> filter_xmlels(Xmlels, []).
|
||||
|
||||
|
@ -150,7 +150,7 @@ process_iq(_,
|
||||
children = iq_vcard(Lang)}]};
|
||||
%% bytestreams info request
|
||||
process_iq(JID,
|
||||
#iq{type = get, sub_el = SubEl,
|
||||
#iq{type = get, sub_el = SubEl, lang = Lang,
|
||||
xmlns = ?NS_BYTESTREAMS} =
|
||||
IQ,
|
||||
#state{acl = ACL, stream_addr = StreamAddr,
|
||||
@ -165,11 +165,12 @@ process_iq(JID,
|
||||
attrs = [{<<"xmlns">>, ?NS_BYTESTREAMS}],
|
||||
children = StreamHostEl}]};
|
||||
deny ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}
|
||||
Txt = <<"Denied by ACL">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]}
|
||||
end;
|
||||
%% bytestream activation request
|
||||
process_iq(InitiatorJID,
|
||||
#iq{type = set, sub_el = SubEl,
|
||||
#iq{type = set, sub_el = SubEl, lang = Lang,
|
||||
xmlns = ?NS_BYTESTREAMS} =
|
||||
IQ,
|
||||
#state{acl = ACL, serverhost = ServerHost}) ->
|
||||
@ -194,22 +195,27 @@ process_iq(InitiatorJID,
|
||||
of
|
||||
ok -> IQ#iq{type = result, sub_el = []};
|
||||
false ->
|
||||
Txt = <<"Failed to activate bytestream">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]};
|
||||
sub_el = [SubEl, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)]};
|
||||
limit ->
|
||||
Txt = <<"Too many active bytestreams">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_RESOURCE_CONSTRAINT]};
|
||||
sub_el = [SubEl, ?ERRT_RESOURCE_CONSTRAINT(Lang, Txt)]};
|
||||
conflict ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_CONFLICT]};
|
||||
Txt = <<"Bytestream already activated">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_CONFLICT(Lang, Txt)]};
|
||||
_ ->
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
|
||||
end;
|
||||
_ ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}
|
||||
Txt = <<"Malformed JID">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}
|
||||
end;
|
||||
deny ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}
|
||||
Txt = <<"Denied by ACL">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]}
|
||||
end;
|
||||
%% Unknown "set" or "get" request
|
||||
process_iq(_, #iq{type = Type, sub_el = SubEl} = IQ, _)
|
||||
|
@ -137,13 +137,14 @@ process_iq(From, To, IQ) when ((From#jid.luser == <<"">>) andalso (From#jid.reso
|
||||
process_iq_manager(From, To, IQ);
|
||||
|
||||
process_iq(From, To, IQ) ->
|
||||
#iq{sub_el = SubEl} = IQ,
|
||||
#iq{sub_el = SubEl, lang = Lang} = IQ,
|
||||
#jid{lserver = LServer} = From,
|
||||
case lists:member(LServer, ?MYHOSTS) of
|
||||
true -> process_local_iq(From, To, IQ);
|
||||
_ ->
|
||||
Txt = <<"The query is only allowed from local users">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
|
||||
sub_el = [SubEl, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)]}
|
||||
end.
|
||||
|
||||
process_local_iq(From, To, #iq{type = Type} = IQ) ->
|
||||
@ -479,12 +480,13 @@ get_roster_by_jid_t(LUser, LServer, LJID, riak) ->
|
||||
exit(Err)
|
||||
end.
|
||||
|
||||
try_process_iq_set(From, To, #iq{sub_el = SubEl} = IQ) ->
|
||||
try_process_iq_set(From, To, #iq{sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
#jid{server = Server} = From,
|
||||
Access = gen_mod:get_module_opt(Server, ?MODULE, access, fun(A) when is_atom(A) -> A end, all),
|
||||
case acl:match_rule(Server, Access, From) of
|
||||
deny ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Denied by ACL">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
allow ->
|
||||
process_iq_set(From, To, IQ)
|
||||
end.
|
||||
@ -1616,8 +1618,9 @@ process_iq_manager(From, To, IQ) ->
|
||||
true ->
|
||||
process_iq_manager2(MatchDomain, To, IQ);
|
||||
false ->
|
||||
#iq{sub_el = SubEl} = IQ,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}
|
||||
#iq{sub_el = SubEl, lang = Lang} = IQ,
|
||||
Txt = <<"Roster management is not allowed from this domain">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}
|
||||
end.
|
||||
|
||||
process_iq_manager2(MatchDomain, To, IQ) ->
|
||||
|
@ -60,8 +60,9 @@ process_local_iq(#jid{user = User, server = Server,
|
||||
_To, #iq{type = get, sub_el = _SubEl} = IQ) ->
|
||||
get_ip({User, Server, Resource}, IQ);
|
||||
process_local_iq(_From, _To,
|
||||
#iq{type = set, sub_el = SubEl} = IQ) ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
|
||||
#iq{type = set, sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]}.
|
||||
|
||||
process_sm_iq(#jid{user = User, server = Server,
|
||||
resource = Resource},
|
||||
@ -69,14 +70,17 @@ process_sm_iq(#jid{user = User, server = Server,
|
||||
#iq{type = get, sub_el = _SubEl} = IQ) ->
|
||||
get_ip({User, Server, Resource}, IQ);
|
||||
process_sm_iq(_From, _To,
|
||||
#iq{type = get, sub_el = SubEl} = IQ) ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]};
|
||||
#iq{type = get, sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
Txt = <<"Query to another users is forbidden">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]};
|
||||
process_sm_iq(_From, _To,
|
||||
#iq{type = set, sub_el = SubEl} = IQ) ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
|
||||
#iq{type = set, sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]}.
|
||||
|
||||
get_ip({User, Server, Resource},
|
||||
#iq{sub_el =
|
||||
#iq{lang = Lang,
|
||||
sub_el =
|
||||
#xmlel{name = Name, attrs = Attrs} = SubEl} =
|
||||
IQ) ->
|
||||
case ejabberd_sm:get_user_ip(User, Server, Resource) of
|
||||
@ -88,8 +92,9 @@ get_ip({User, Server, Resource},
|
||||
[{xmlcdata,
|
||||
iolist_to_binary(jlib:ip_to_list(IP))}]}]};
|
||||
_ ->
|
||||
Txt = <<"User session not found">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
|
||||
sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]}
|
||||
end.
|
||||
|
||||
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;
|
||||
|
@ -50,17 +50,18 @@ stop(Host) ->
|
||||
|
||||
process_local_iq(_From, To,
|
||||
#iq{id = _ID, type = Type, xmlns = XMLNS,
|
||||
sub_el = SubEl} =
|
||||
sub_el = SubEl, lang = Lang} =
|
||||
IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
#xmlel{children = Els} = SubEl,
|
||||
Node = str:tokens(fxml:get_tag_attr_s(<<"node">>, SubEl),
|
||||
<<"/">>),
|
||||
Names = get_names(Els, []),
|
||||
case get_local_stats(To#jid.server, Node, Names) of
|
||||
case get_local_stats(To#jid.server, Node, Names, Lang) of
|
||||
{result, Res} ->
|
||||
IQ#iq{type = result,
|
||||
sub_el =
|
||||
@ -87,18 +88,18 @@ get_names([_ | Els], Res) -> get_names(Els, Res).
|
||||
#xmlel{name = <<"stat">>, attrs = [{<<"name">>, Name}],
|
||||
children = []}).
|
||||
|
||||
get_local_stats(_Server, [], []) ->
|
||||
get_local_stats(_Server, [], [], _Lang) ->
|
||||
{result,
|
||||
[?STAT(<<"users/online">>), ?STAT(<<"users/total">>),
|
||||
?STAT(<<"users/all-hosts/online">>),
|
||||
?STAT(<<"users/all-hosts/total">>)]};
|
||||
get_local_stats(Server, [], Names) ->
|
||||
get_local_stats(Server, [], Names, _Lang) ->
|
||||
{result,
|
||||
lists:map(fun (Name) -> get_local_stat(Server, [], Name)
|
||||
end,
|
||||
Names)};
|
||||
get_local_stats(_Server, [<<"running nodes">>, _],
|
||||
[]) ->
|
||||
[], _Lang) ->
|
||||
{result,
|
||||
[?STAT(<<"time/uptime">>), ?STAT(<<"time/cputime">>),
|
||||
?STAT(<<"users/online">>),
|
||||
@ -107,16 +108,19 @@ get_local_stats(_Server, [<<"running nodes">>, _],
|
||||
?STAT(<<"transactions/restarted">>),
|
||||
?STAT(<<"transactions/logged">>)]};
|
||||
get_local_stats(_Server, [<<"running nodes">>, ENode],
|
||||
Names) ->
|
||||
Names, Lang) ->
|
||||
case search_running_node(ENode) of
|
||||
false -> {error, ?ERR_ITEM_NOT_FOUND};
|
||||
false ->
|
||||
Txt = <<"No running node found">>,
|
||||
{error, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)};
|
||||
Node ->
|
||||
{result,
|
||||
lists:map(fun (Name) -> get_node_stat(Node, Name) end,
|
||||
Names)}
|
||||
end;
|
||||
get_local_stats(_Server, _, _) ->
|
||||
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}.
|
||||
get_local_stats(_Server, _, _, Lang) ->
|
||||
Txt = <<"No statistics found for this item">>,
|
||||
{error, ?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)}.
|
||||
|
||||
-define(STATVAL(Val, Unit),
|
||||
#xmlel{name = <<"stat">>,
|
||||
|
@ -51,10 +51,11 @@ stop(Host) ->
|
||||
?NS_TIME).
|
||||
|
||||
process_local_iq(_From, _To,
|
||||
#iq{type = Type, sub_el = SubEl} = IQ) ->
|
||||
#iq{type = Type, sub_el = SubEl, lang = Lang} = IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
Now_universal = calendar:universal_time(),
|
||||
Now_local = calendar:universal_time_to_local_time(Now_universal),
|
||||
|
@ -152,7 +152,8 @@ process_local_iq(_From, _To,
|
||||
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
IQ#iq{type = result,
|
||||
sub_el =
|
||||
@ -176,7 +177,7 @@ process_local_iq(_From, _To,
|
||||
end.
|
||||
|
||||
process_sm_iq(From, To,
|
||||
#iq{type = Type, sub_el = SubEl} = IQ) ->
|
||||
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
#jid{user = User, lserver = LServer} = From,
|
||||
@ -185,14 +186,16 @@ process_sm_iq(From, To,
|
||||
set_vcard(User, LServer, SubEl),
|
||||
IQ#iq{type = result, sub_el = []};
|
||||
false ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
|
||||
Txt = <<"The query is only allowed from local users">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]}
|
||||
end;
|
||||
get ->
|
||||
#jid{luser = LUser, lserver = LServer} = To,
|
||||
case get_vcard(LUser, LServer) of
|
||||
error ->
|
||||
Txt = <<"Database failure">>,
|
||||
IQ#iq{type = error,
|
||||
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]};
|
||||
sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]};
|
||||
[] ->
|
||||
IQ#iq{type = result,
|
||||
sub_el = [#xmlel{name = <<"vCard">>,
|
||||
@ -422,15 +425,17 @@ do_route(ServerHost, From, To, Packet) ->
|
||||
XDataEl = find_xdata_el(SubEl),
|
||||
case XDataEl of
|
||||
false ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_BAD_REQUEST),
|
||||
Txt = <<"Data form not found">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
_ ->
|
||||
XData = jlib:parse_xdata_submit(XDataEl),
|
||||
case XData of
|
||||
invalid ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_BAD_REQUEST),
|
||||
Txt = <<"Incorrect data form">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
_ ->
|
||||
ResIQ = IQ#iq{type = result,
|
||||
@ -470,7 +475,8 @@ do_route(ServerHost, From, To, Packet) ->
|
||||
#iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} ->
|
||||
case Type of
|
||||
set ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED),
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
Err = jlib:make_error_reply(Packet, ?ERRT_NOT_ALLOWED(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
get ->
|
||||
Info = ejabberd_hooks:run_fold(disco_info, ServerHost,
|
||||
@ -516,10 +522,11 @@ do_route(ServerHost, From, To, Packet) ->
|
||||
++ Info}]},
|
||||
ejabberd_router:route(To, From, jlib:iq_to_xml(ResIQ))
|
||||
end;
|
||||
#iq{type = Type, xmlns = ?NS_DISCO_ITEMS} ->
|
||||
#iq{type = Type, lang = Lang, xmlns = ?NS_DISCO_ITEMS} ->
|
||||
case Type of
|
||||
set ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED),
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
Err = jlib:make_error_reply(Packet, ?ERRT_NOT_ALLOWED(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
get ->
|
||||
ResIQ = IQ#iq{type = result,
|
||||
|
@ -206,7 +206,8 @@ process_local_iq(_From, _To,
|
||||
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
IQ#iq{type = result,
|
||||
sub_el =
|
||||
@ -240,10 +241,11 @@ process_sm_iq(_From, #jid{lserver = LServer} = To,
|
||||
|
||||
process_vcard_ldap(To, IQ, Server) ->
|
||||
{ok, State} = eldap_utils:get_state(Server, ?PROCNAME),
|
||||
#iq{type = Type, sub_el = SubEl} = IQ,
|
||||
#iq{type = Type, sub_el = SubEl, lang = Lang} = IQ,
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
#jid{luser = LUser} = To,
|
||||
LServer = State#state.serverhost,
|
||||
@ -455,15 +457,17 @@ route(State, From, To, Packet) ->
|
||||
XDataEl = find_xdata_el(SubEl),
|
||||
case XDataEl of
|
||||
false ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_BAD_REQUEST),
|
||||
Txt = <<"Data form not found">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
_ ->
|
||||
XData = jlib:parse_xdata_submit(XDataEl),
|
||||
case XData of
|
||||
invalid ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
?ERR_BAD_REQUEST),
|
||||
Txt = <<"Incorrect data form">>,
|
||||
Err = jlib:make_error_reply(
|
||||
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
_ ->
|
||||
ResIQ = IQ#iq{type = result,
|
||||
@ -505,7 +509,8 @@ route(State, From, To, Packet) ->
|
||||
#iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} ->
|
||||
case Type of
|
||||
set ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED),
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
Err = jlib:make_error_reply(Packet, ?ERRT_NOT_ALLOWED(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
get ->
|
||||
Info = ejabberd_hooks:run_fold(disco_info, ServerHost,
|
||||
@ -545,10 +550,11 @@ route(State, From, To, Packet) ->
|
||||
++ Info}]},
|
||||
ejabberd_router:route(To, From, jlib:iq_to_xml(ResIQ))
|
||||
end;
|
||||
#iq{type = Type, xmlns = ?NS_DISCO_ITEMS} ->
|
||||
#iq{type = Type, lang = Lang, xmlns = ?NS_DISCO_ITEMS} ->
|
||||
case Type of
|
||||
set ->
|
||||
Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED),
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
Err = jlib:make_error_reply(Packet, ?ERRT_NOT_ALLOWED(Lang, Txt)),
|
||||
ejabberd_router:route(To, From, Err);
|
||||
get ->
|
||||
ResIQ = IQ#iq{type = result,
|
||||
|
@ -52,11 +52,12 @@ stop(Host) ->
|
||||
|
||||
process_local_iq(_From, To,
|
||||
#iq{id = _ID, type = Type, xmlns = _XMLNS,
|
||||
sub_el = SubEl} =
|
||||
sub_el = SubEl, lang = Lang} =
|
||||
IQ) ->
|
||||
case Type of
|
||||
set ->
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
||||
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
||||
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_NOT_ALLOWED(Lang, Txt)]};
|
||||
get ->
|
||||
Host = To#jid.lserver,
|
||||
OS = case gen_mod:get_module_opt(Host, ?MODULE, show_os,
|
||||
|
@ -77,8 +77,9 @@ publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
|
||||
#pubsub_node{options = Options} ->
|
||||
case find_opt(node_type, Options) of
|
||||
collection ->
|
||||
Txt = <<"Publishing items to collection node is not allowed">>,
|
||||
{error,
|
||||
?ERR_EXTENDED((?ERR_NOT_ALLOWED), <<"publish">>)};
|
||||
?ERR_EXTENDED(?ERRT_NOT_ALLOWED(?MYLANG, Txt), <<"publish">>)};
|
||||
_ ->
|
||||
node_hometree:publish_item(Nidx, Publisher, Model,
|
||||
MaxItems, ItemId, Payload)
|
||||
|
@ -69,13 +69,13 @@ create_node(Key, Node, Type, Owner, Options, Parents) ->
|
||||
Other -> Other
|
||||
end;
|
||||
_ ->
|
||||
{error, ?ERR_CONFLICT}
|
||||
{error, ?ERRT_CONFLICT(?MYLANG, <<"Node already exists">>)}
|
||||
end.
|
||||
|
||||
delete_node(Key, Node) ->
|
||||
case find_node(Key, Node) of
|
||||
false ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND};
|
||||
{error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
|
||||
Record ->
|
||||
lists:foreach(fun (#pubsub_node{options = Opts} = Child) ->
|
||||
NewOpts = remove_config_parent(Node, Opts),
|
||||
@ -99,7 +99,7 @@ get_node(Host, Node, _From) ->
|
||||
|
||||
get_node(Host, Node) ->
|
||||
case find_node(Host, Node) of
|
||||
false -> {error, ?ERR_ITEM_NOT_FOUND};
|
||||
false -> {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
|
||||
Record -> Record
|
||||
end.
|
||||
|
||||
@ -115,7 +115,7 @@ get_nodes(Key) ->
|
||||
get_parentnodes(Host, Node, _From) ->
|
||||
case find_node(Host, Node) of
|
||||
false ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND};
|
||||
{error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
|
||||
#pubsub_node{parents = Parents} ->
|
||||
Q = qlc:q([N
|
||||
|| #pubsub_node{nodeid = {NHost, NNode}} = N
|
||||
@ -139,7 +139,7 @@ get_subnodes(Host, <<>>) ->
|
||||
get_subnodes_helper(Host, <<>>);
|
||||
get_subnodes(Host, Node) ->
|
||||
case find_node(Host, Node) of
|
||||
false -> {error, ?ERR_ITEM_NOT_FOUND};
|
||||
false -> {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
|
||||
_ -> get_subnodes_helper(Host, Node)
|
||||
end.
|
||||
|
||||
@ -238,7 +238,7 @@ validate_parentage(Key, Owners, [<<>> | T]) ->
|
||||
validate_parentage(Key, Owners, [ParentID | T]) ->
|
||||
case find_node(Key, ParentID) of
|
||||
false ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND};
|
||||
{error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
|
||||
#pubsub_node{owners = POwners, options = POptions} ->
|
||||
NodeType = find_opt(node_type, ?DEFAULT_NODETYPE, POptions),
|
||||
MutualOwners = [O || O <- Owners, PO <- POwners, O == PO],
|
||||
|
@ -74,15 +74,15 @@ get_node(Host, Node, _From) ->
|
||||
get_node(Host, Node).
|
||||
|
||||
get_node(Host, Node) ->
|
||||
case catch mnesia:read({pubsub_node, {Host, Node}}) of
|
||||
case mnesia:read({pubsub_node, {Host, Node}}) of
|
||||
[Record] when is_record(Record, pubsub_node) -> Record;
|
||||
_ -> {error, ?ERR_ITEM_NOT_FOUND}
|
||||
_ -> {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)}
|
||||
end.
|
||||
|
||||
get_node(Nidx) ->
|
||||
case catch mnesia:index_read(pubsub_node, Nidx, #pubsub_node.id) of
|
||||
case mnesia:index_read(pubsub_node, Nidx, #pubsub_node.id) of
|
||||
[Record] when is_record(Record, pubsub_node) -> Record;
|
||||
_ -> {error, ?ERR_ITEM_NOT_FOUND}
|
||||
_ -> {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)}
|
||||
end.
|
||||
|
||||
get_nodes(Host, _From) ->
|
||||
@ -147,7 +147,7 @@ get_subnodes_tree(Host, Node) ->
|
||||
|
||||
create_node(Host, Node, Type, Owner, Options, Parents) ->
|
||||
BJID = jid:tolower(jid:remove_resource(Owner)),
|
||||
case catch mnesia:read({pubsub_node, {Host, Node}}) of
|
||||
case mnesia:read({pubsub_node, {Host, Node}}) of
|
||||
[] ->
|
||||
ParentExists = case Host of
|
||||
{_U, _S, _R} ->
|
||||
@ -183,7 +183,7 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
|
||||
{error, ?ERR_FORBIDDEN}
|
||||
end;
|
||||
_ ->
|
||||
{error, ?ERR_CONFLICT}
|
||||
{error, ?ERRT_CONFLICT(?MYLANG, <<"Node already exists">>)}
|
||||
end.
|
||||
|
||||
delete_node(Host, Node) ->
|
||||
|
@ -93,7 +93,8 @@ set_node(Record) when is_record(Record, pubsub_node) ->
|
||||
end,
|
||||
case Nidx of
|
||||
none ->
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
Txt = <<"Node index not found">>,
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, Txt)};
|
||||
_ ->
|
||||
lists:foreach(fun ({Key, Value}) ->
|
||||
SKey = iolist_to_binary(atom_to_list(Key)),
|
||||
@ -125,9 +126,9 @@ get_node(Host, Node) ->
|
||||
[<<"node">>, <<"parent">>, <<"type">>, <<"nodeid">>], [RItem]} ->
|
||||
raw_to_node(Host, RItem);
|
||||
{'EXIT', _Reason} ->
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)};
|
||||
_ ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND}
|
||||
{error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)}
|
||||
end.
|
||||
|
||||
get_node(Nidx) ->
|
||||
@ -140,9 +141,9 @@ get_node(Nidx) ->
|
||||
[<<"host">>, <<"node">>, <<"parent">>, <<"type">>], [[Host, Node, Parent, Type]]} ->
|
||||
raw_to_node(Host, [Node, Parent, Type, Nidx]);
|
||||
{'EXIT', _Reason} ->
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)};
|
||||
_ ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND}
|
||||
{error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)}
|
||||
end.
|
||||
|
||||
get_nodes(Host, _From) ->
|
||||
@ -211,7 +212,7 @@ get_subnodes_tree(Host, Node) ->
|
||||
create_node(Host, Node, Type, Owner, Options, Parents) ->
|
||||
BJID = jid:tolower(jid:remove_resource(Owner)),
|
||||
case nodeidx(Host, Node) of
|
||||
{error, ?ERR_ITEM_NOT_FOUND} ->
|
||||
{error, not_found} ->
|
||||
ParentExists = case Host of
|
||||
{_U, _S, _R} ->
|
||||
%% This is special case for PEP handling
|
||||
@ -248,9 +249,9 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
|
||||
{error, ?ERR_FORBIDDEN}
|
||||
end;
|
||||
{result, _} ->
|
||||
{error, ?ERR_CONFLICT};
|
||||
Error ->
|
||||
Error
|
||||
{error, ?ERRT_CONFLICT(?MYLANG, <<"Node already exists">>)};
|
||||
{error, db_fail} ->
|
||||
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)}
|
||||
end.
|
||||
|
||||
delete_node(Host, Node) ->
|
||||
@ -303,9 +304,9 @@ nodeidx(Host, Node) ->
|
||||
{selected, [<<"nodeid">>], [[Nidx]]} ->
|
||||
{result, Nidx};
|
||||
{'EXIT', _Reason} ->
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
{error, db_fail};
|
||||
_ ->
|
||||
{error, ?ERR_ITEM_NOT_FOUND}
|
||||
{error, not_found}
|
||||
end.
|
||||
|
||||
nodeowners(Nidx) ->
|
||||
|
@ -237,31 +237,40 @@ var_xfield(?PUBSUB_SUBSCRIPTION_TYPE) -> subscription_type;
|
||||
var_xfield(?PUBSUB_SUBSCRIPTION_DEPTH) -> subscription_depth;
|
||||
var_xfield(_) -> {error, badarg}.
|
||||
|
||||
val_xfield(deliver, [Val]) -> xopt_to_bool(Val);
|
||||
val_xfield(digest, [Val]) -> xopt_to_bool(Val);
|
||||
val_xfield(digest_frequency, [Val]) ->
|
||||
val_xfield(deliver = Opt, [Val]) -> xopt_to_bool(Opt, Val);
|
||||
val_xfield(digest = Opt, [Val]) -> xopt_to_bool(Opt, Val);
|
||||
val_xfield(digest_frequency = Opt, [Val]) ->
|
||||
case catch jlib:binary_to_integer(Val) of
|
||||
N when is_integer(N) -> N;
|
||||
_ -> {error, ?ERR_NOT_ACCEPTABLE}
|
||||
_ ->
|
||||
Txt = <<"Value of '~s' should be integer">>,
|
||||
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
|
||||
{error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}
|
||||
end;
|
||||
val_xfield(expire, [Val]) -> jlib:datetime_string_to_timestamp(Val);
|
||||
val_xfield(include_body, [Val]) -> xopt_to_bool(Val);
|
||||
val_xfield(include_body = Opt, [Val]) -> xopt_to_bool(Opt, Val);
|
||||
val_xfield(show_values, Vals) -> Vals;
|
||||
val_xfield(subscription_type, [<<"items">>]) -> items;
|
||||
val_xfield(subscription_type, [<<"nodes">>]) -> nodes;
|
||||
val_xfield(subscription_depth, [<<"all">>]) -> all;
|
||||
val_xfield(subscription_depth, [Depth]) ->
|
||||
val_xfield(subscription_depth = Opt, [Depth]) ->
|
||||
case catch jlib:binary_to_integer(Depth) of
|
||||
N when is_integer(N) -> N;
|
||||
_ -> {error, ?ERR_NOT_ACCEPTABLE}
|
||||
_ ->
|
||||
Txt = <<"Value of '~s' should be integer">>,
|
||||
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
|
||||
{error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}
|
||||
end.
|
||||
|
||||
%% Convert XForm booleans to Erlang booleans.
|
||||
xopt_to_bool(<<"0">>) -> false;
|
||||
xopt_to_bool(<<"1">>) -> true;
|
||||
xopt_to_bool(<<"false">>) -> false;
|
||||
xopt_to_bool(<<"true">>) -> true;
|
||||
xopt_to_bool(_) -> {error, ?ERR_NOT_ACCEPTABLE}.
|
||||
xopt_to_bool(_, <<"0">>) -> false;
|
||||
xopt_to_bool(_, <<"1">>) -> true;
|
||||
xopt_to_bool(_, <<"false">>) -> false;
|
||||
xopt_to_bool(_, <<"true">>) -> true;
|
||||
xopt_to_bool(Option, _) ->
|
||||
Txt = <<"Value of '~s' should be boolean">>,
|
||||
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Option])),
|
||||
{error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}.
|
||||
|
||||
-spec(get_option_xfield/3 ::
|
||||
(
|
||||
|
@ -200,31 +200,40 @@ var_xfield(?PUBSUB_SUBSCRIPTION_TYPE) -> subscription_type;
|
||||
var_xfield(?PUBSUB_SUBSCRIPTION_DEPTH) -> subscription_depth;
|
||||
var_xfield(_) -> {error, badarg}.
|
||||
|
||||
val_xfield(deliver, [Val]) -> xopt_to_bool(Val);
|
||||
val_xfield(digest, [Val]) -> xopt_to_bool(Val);
|
||||
val_xfield(digest_frequency, [Val]) ->
|
||||
val_xfield(deliver = Opt, [Val]) -> xopt_to_bool(Opt, Val);
|
||||
val_xfield(digest = Opt, [Val]) -> xopt_to_bool(Opt, Val);
|
||||
val_xfield(digest_frequency = Opt, [Val]) ->
|
||||
case catch jlib:binary_to_integer(Val) of
|
||||
N when is_integer(N) -> N;
|
||||
_ -> {error, ?ERR_NOT_ACCEPTABLE}
|
||||
_ ->
|
||||
Txt = <<"Value of '~s' should be integer">>,
|
||||
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
|
||||
{error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}
|
||||
end;
|
||||
val_xfield(expire, [Val]) -> jlib:datetime_string_to_timestamp(Val);
|
||||
val_xfield(include_body, [Val]) -> xopt_to_bool(Val);
|
||||
val_xfield(include_body = Opt, [Val]) -> xopt_to_bool(Opt, Val);
|
||||
val_xfield(show_values, Vals) -> Vals;
|
||||
val_xfield(subscription_type, [<<"items">>]) -> items;
|
||||
val_xfield(subscription_type, [<<"nodes">>]) -> nodes;
|
||||
val_xfield(subscription_depth, [<<"all">>]) -> all;
|
||||
val_xfield(subscription_depth, [Depth]) ->
|
||||
val_xfield(subscription_depth = Opt, [Depth]) ->
|
||||
case catch jlib:binary_to_integer(Depth) of
|
||||
N when is_integer(N) -> N;
|
||||
_ -> {error, ?ERR_NOT_ACCEPTABLE}
|
||||
_ ->
|
||||
Txt = <<"Value of '~s' should be integer">>,
|
||||
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Opt])),
|
||||
{error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}
|
||||
end.
|
||||
|
||||
%% Convert XForm booleans to Erlang booleans.
|
||||
xopt_to_bool(<<"0">>) -> false;
|
||||
xopt_to_bool(<<"1">>) -> true;
|
||||
xopt_to_bool(<<"false">>) -> false;
|
||||
xopt_to_bool(<<"true">>) -> true;
|
||||
xopt_to_bool(_) -> {error, ?ERR_NOT_ACCEPTABLE}.
|
||||
xopt_to_bool(_, <<"0">>) -> false;
|
||||
xopt_to_bool(_, <<"1">>) -> true;
|
||||
xopt_to_bool(_, <<"false">>) -> false;
|
||||
xopt_to_bool(_, <<"true">>) -> true;
|
||||
xopt_to_bool(Option, _) ->
|
||||
Txt = <<"Value of '~s' should be boolean">>,
|
||||
ErrTxt = iolist_to_binary(io_lib:format(Txt, [Option])),
|
||||
{error, ?ERRT_NOT_ACCEPTABLE(?MYLANG, ErrTxt)}.
|
||||
|
||||
%% Return a field for an XForm for Key, with data filled in, if
|
||||
%% applicable, from Options.
|
||||
|
Loading…
Reference in New Issue
Block a user