25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Replace some ?ERR_* macros with ?ERRT_*

This commit is contained in:
Evgeniy Khramtsov 2016-03-31 11:00:29 +03:00
parent b160bd7ac1
commit fced8dc3d9
33 changed files with 375 additions and 242 deletions

View File

@ -68,7 +68,9 @@ parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}
xdata = XData, xdata = XData,
others = Others 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 %% Borrowed from mod_vcard.erl
find_xdata_el(#xmlel{children = SubEls}) -> find_xdata_el(#xmlel{children = SubEls}) ->

View File

@ -619,8 +619,9 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
send_element(StateData, Res), send_element(StateData, Res),
fsm_next_state(wait_for_auth, StateData); fsm_next_state(wait_for_auth, StateData);
{auth, _ID, set, {_U, _P, _D, <<"">>}} -> {auth, _ID, set, {_U, _P, _D, <<"">>}} ->
Err = jlib:make_error_reply(El, Lang = StateData#state.lang,
?ERR_AUTH_NO_RESOURCE_PROVIDED((StateData#state.lang))), Txt = <<"No resource provided">>,
Err = jlib:make_error_reply(El, ?ERRT_NOT_ACCEPTABLE(Lang, Txt)),
send_element(StateData, Err), send_element(StateData, Err),
fsm_next_state(wait_for_auth, StateData); fsm_next_state(wait_for_auth, StateData);
{auth, _ID, set, {U, P, D, R}} -> {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, ejabberd_hooks:run(c2s_auth_result, StateData#state.server,
[false, U, StateData#state.server, [false, U, StateData#state.server,
StateData#state.ip]), 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), send_element(StateData, Err),
fsm_next_state(wait_for_auth, StateData) fsm_next_state(wait_for_auth, StateData)
end; end;
@ -706,7 +710,9 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
ejabberd_hooks:run(c2s_auth_result, StateData#state.server, ejabberd_hooks:run(c2s_auth_result, StateData#state.server,
[false, U, StateData#state.server, [false, U, StateData#state.server,
StateData#state.ip]), 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), send_element(StateData, Err),
fsm_next_state(wait_for_auth, StateData) fsm_next_state(wait_for_auth, StateData)
end end
@ -1013,7 +1019,7 @@ wait_for_bind({xmlstreamelement, #xmlel{name = Name, attrs = Attrs} = El},
end; end;
wait_for_bind({xmlstreamelement, El}, StateData) -> wait_for_bind({xmlstreamelement, El}, StateData) ->
case jlib:iq_query_info(El) of 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 -> IQ ->
U = StateData#state.user, U = StateData#state.user,
R1 = fxml:get_path_s(SubEl, R1 = fxml:get_path_s(SubEl,
@ -1025,7 +1031,8 @@ wait_for_bind({xmlstreamelement, El}, StateData) ->
end, end,
case R of case R of
error -> 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), send_element(StateData, Err),
fsm_next_state(wait_for_bind, StateData); fsm_next_state(wait_for_bind, StateData);
_ -> _ ->
@ -1099,6 +1106,7 @@ open_session(StateData) ->
U = StateData#state.user, U = StateData#state.user,
R = StateData#state.resource, R = StateData#state.resource,
JID = StateData#state.jid, JID = StateData#state.jid,
Lang = StateData#state.lang,
case acl:match_rule(StateData#state.server, case acl:match_rule(StateData#state.server,
StateData#state.access, JID) of StateData#state.access, JID) of
allow -> allow ->
@ -1136,7 +1144,8 @@ open_session(StateData) ->
StateData#state.server, [JID]), StateData#state.server, [JID]),
?INFO_MSG("(~w) Forbidden session for ~s", ?INFO_MSG("(~w) Forbidden session for ~s",
[StateData#state.socket, jid:to_string(JID)]), [StateData#state.socket, jid:to_string(JID)]),
{error, ?ERR_NOT_ALLOWED} Txt = <<"Denied by ACL">>,
{error, ?ERRT_NOT_ALLOWED(Lang, Txt)}
end. end.
session_established({xmlstreamelement, #xmlel{name = Name} = El}, StateData) session_established({xmlstreamelement, #xmlel{name = Name} = El}, StateData)
@ -2275,21 +2284,23 @@ get_priority_from_presence(PresencePacket) ->
end. end.
process_privacy_iq(From, To, process_privacy_iq(From, To,
#iq{type = Type, sub_el = SubEl} = IQ, StateData) -> #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ, StateData) ->
{Res, NewStateData} = case Type of Txt = <<"No module is handling this query">>,
{Res, NewStateData} =
case Type of
get -> get ->
R = ejabberd_hooks:run_fold(privacy_iq_get, R = ejabberd_hooks:run_fold(
privacy_iq_get,
StateData#state.server, StateData#state.server,
{error, {error, ?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)},
?ERR_FEATURE_NOT_IMPLEMENTED},
[From, To, IQ, [From, To, IQ,
StateData#state.privacy_list]), StateData#state.privacy_list]),
{R, StateData}; {R, StateData};
set -> set ->
case ejabberd_hooks:run_fold(privacy_iq_set, case ejabberd_hooks:run_fold(
privacy_iq_set,
StateData#state.server, StateData#state.server,
{error, {error, ?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)},
?ERR_FEATURE_NOT_IMPLEMENTED},
[From, To, IQ]) [From, To, IQ])
of of
{result, R, NewPrivList} -> {result, R, NewPrivList} ->
@ -2365,15 +2376,16 @@ process_unauthenticated_stanza(StateData, El) ->
_ -> El _ -> El
end, end,
case jlib:iq_query_info(NewEl) of case jlib:iq_query_info(NewEl) of
#iq{} = IQ -> #iq{lang = L} = IQ ->
Res = ejabberd_hooks:run_fold(c2s_unauthenticated_iq, Res = ejabberd_hooks:run_fold(c2s_unauthenticated_iq,
StateData#state.server, empty, StateData#state.server, empty,
[StateData#state.server, IQ, [StateData#state.server, IQ,
StateData#state.ip]), StateData#state.ip]),
case Res of case Res of
empty -> empty ->
Txt = <<"Authentication required">>,
ResIQ = IQ#iq{type = error, ResIQ = IQ#iq{type = error,
sub_el = [?ERR_SERVICE_UNAVAILABLE]}, sub_el = [?ERRT_SERVICE_UNAVAILABLE(L, Txt)]},
Res1 = jlib:replace_from_to(jid:make(<<"">>, Res1 = jlib:replace_from_to(jid:make(<<"">>,
StateData#state.server, StateData#state.server,
<<"">>), <<"">>),
@ -2879,6 +2891,7 @@ handle_unacked_stanzas(StateData)
false false
end end
end, end,
Lang = StateData#state.lang,
ReRoute = case ResendOnTimeout of ReRoute = case ResendOnTimeout of
true -> true ->
fun(From, To, El, Time) -> fun(From, To, El, Time) ->
@ -2887,9 +2900,11 @@ handle_unacked_stanzas(StateData)
end; end;
false -> false ->
fun(From, To, El, _Time) -> fun(From, To, El, _Time) ->
Txt = <<"User session not found">>,
Err = Err =
jlib:make_error_reply(El, jlib:make_error_reply(
?ERR_SERVICE_UNAVAILABLE), El,
?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)
end end
end, end,
@ -2897,7 +2912,9 @@ handle_unacked_stanzas(StateData)
?DEBUG("Dropping presence stanza from ~s", ?DEBUG("Dropping presence stanza from ~s",
[jid:to_string(From)]); [jid:to_string(From)]);
(From, To, #xmlel{name = <<"iq">>} = El, _Time) -> (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); ejabberd_router:route(To, From, Err);
(From, To, El, Time) -> (From, To, El, Time) ->
%% We'll drop the stanza if it was <forwarded/> by some %% We'll drop the stanza if it was <forwarded/> by some

View File

@ -74,7 +74,7 @@ start_link() ->
process_iq(From, To, Packet) -> process_iq(From, To, Packet) ->
IQ = jlib:iq_query_info(Packet), IQ = jlib:iq_query_info(Packet),
case IQ of case IQ of
#iq{xmlns = XMLNS} -> #iq{xmlns = XMLNS, lang = Lang} ->
Host = To#jid.lserver, Host = To#jid.lserver,
case ets:lookup(?IQTABLE, {XMLNS, Host}) of case ets:lookup(?IQTABLE, {XMLNS, Host}) of
[{_, Module, Function}] -> [{_, Module, Function}] ->
@ -87,8 +87,10 @@ process_iq(From, To, Packet) ->
gen_iq_handler:handle(Host, Module, Function, Opts, gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, IQ); From, To, IQ);
[] -> [] ->
Err = jlib:make_error_reply(Packet, Txt = <<"No module is handling this query">>,
?ERR_FEATURE_NOT_IMPLEMENTED), Err = jlib:make_error_reply(
Packet,
?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)
end; end;
reply -> reply ->
@ -166,8 +168,10 @@ refresh_iq_handlers() ->
ejabberd_local ! refresh_iq_handlers. ejabberd_local ! refresh_iq_handlers.
bounce_resource_packet(From, To, Packet) -> 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 = jlib:make_error_reply(Packet,
?ERR_ITEM_NOT_FOUND), ?ERRT_ITEM_NOT_FOUND(Lang, Txt)),
ejabberd_router:route(To, From, Err), ejabberd_router:route(To, From, Err),
stop. stop.

View File

@ -312,8 +312,10 @@ do_route(From, To, Packet) ->
<<"error">> -> ok; <<"error">> -> ok;
<<"result">> -> ok; <<"result">> -> ok;
_ -> _ ->
Err = jlib:make_error_reply(Packet, Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
?ERR_SERVICE_UNAVAILABLE), Txt = <<"No s2s connection found">>,
Err = jlib:make_error_reply(
Packet, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)
end, end,
false false

View File

@ -280,7 +280,9 @@ stream_established({xmlstreamelement, El}, StateData) ->
and (FromJID /= error) -> and (FromJID /= error) ->
ejabberd_router:route(FromJID, ToJID, NewEl); ejabberd_router:route(FromJID, ToJID, NewEl);
true -> 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), send_element(StateData, Err),
error error
end, end,
@ -360,7 +362,9 @@ handle_info({route, From, To, Packet}, StateName,
attrs = Attrs2, children = Els}), attrs = Attrs2, children = Els}),
send_text(StateData, Text); send_text(StateData, Text);
deny -> 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) ejabberd_router:route_error(To, From, Err, Packet)
end, end,
{next_state, StateName, StateData}; {next_state, StateName, StateData};

View File

@ -159,8 +159,10 @@ check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
-spec bounce_offline_message(jid(), jid(), xmlel()) -> stop. -spec bounce_offline_message(jid(), jid(), xmlel()) -> stop.
bounce_offline_message(From, To, Packet) -> bounce_offline_message(From, To, Packet) ->
Err = jlib:make_error_reply(Packet, Lang = fxml:get_tag_attr_s(<<"xml:lang">>, Packet),
?ERR_SERVICE_UNAVAILABLE), Txt = <<"User session not found">>,
Err = jlib:make_error_reply(
Packet, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
ejabberd_router:route(To, From, Err), ejabberd_router:route(To, From, Err),
stop. stop.
@ -423,6 +425,7 @@ do_route(From, To, #xmlel{} = Packet) ->
#jid{user = User, server = Server, #jid{user = User, server = Server,
luser = LUser, lserver = LServer, lresource = LResource} = To, luser = LUser, lserver = LServer, lresource = LResource} = To,
#xmlel{name = Name, attrs = Attrs} = Packet, #xmlel{name = Name, attrs = Attrs} = Packet,
Lang = fxml:get_attr_s(<<"xml:lang">>, Attrs),
case LResource of case LResource of
<<"">> -> <<"">> ->
case Name of case Name of
@ -496,8 +499,9 @@ do_route(From, To, #xmlel{} = Packet) ->
<<"headline">> -> route_message(From, To, Packet, headline); <<"headline">> -> route_message(From, To, Packet, headline);
<<"error">> -> ok; <<"error">> -> ok;
<<"groupchat">> -> <<"groupchat">> ->
Err = jlib:make_error_reply(Packet, ErrTxt = <<"Incorrect message type">>,
?ERR_SERVICE_UNAVAILABLE), Err = jlib:make_error_reply(
Packet, ?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
ejabberd_router:route(To, From, Err); ejabberd_router:route(To, From, Err);
_ -> _ ->
route_message(From, To, Packet, normal) route_message(From, To, Packet, normal)
@ -517,8 +521,10 @@ do_route(From, To, #xmlel{} = Packet) ->
<<"">> -> route_message(From, To, Packet, normal); <<"">> -> route_message(From, To, Packet, normal);
<<"error">> -> ok; <<"error">> -> ok;
_ -> _ ->
Err = jlib:make_error_reply(Packet, ErrTxt = <<"Incorrect message type">>,
?ERR_SERVICE_UNAVAILABLE), Err = jlib:make_error_reply(
Packet,
?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)
end; end;
<<"iq">> -> <<"iq">> ->
@ -526,8 +532,10 @@ do_route(From, To, #xmlel{} = Packet) ->
<<"error">> -> ok; <<"error">> -> ok;
<<"result">> -> ok; <<"result">> -> ok;
_ -> _ ->
Err = jlib:make_error_reply(Packet, ErrTxt = <<"User session not found">>,
?ERR_SERVICE_UNAVAILABLE), Err = jlib:make_error_reply(
Packet,
?ERRT_SERVICE_UNAVAILABLE(Lang, ErrTxt)),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)
end; end;
_ -> ?DEBUG("packet dropped~n", []) _ -> ?DEBUG("packet dropped~n", [])
@ -684,7 +692,7 @@ get_max_user_sessions(LUser, Host) ->
process_iq(From, To, Packet) -> process_iq(From, To, Packet) ->
IQ = jlib:iq_query_info(Packet), IQ = jlib:iq_query_info(Packet),
case IQ of case IQ of
#iq{xmlns = XMLNS} -> #iq{xmlns = XMLNS, lang = Lang} ->
Host = To#jid.lserver, Host = To#jid.lserver,
case ets:lookup(sm_iqtable, {XMLNS, Host}) of case ets:lookup(sm_iqtable, {XMLNS, Host}) of
[{_, Module, Function}] -> [{_, Module, Function}] ->
@ -697,8 +705,10 @@ process_iq(From, To, Packet) ->
gen_iq_handler:handle(Host, Module, Function, Opts, gen_iq_handler:handle(Host, Module, Function, Opts,
From, To, IQ); From, To, IQ);
[] -> [] ->
Err = jlib:make_error_reply(Packet, Txt = <<"No module is handling this query">>,
?ERR_SERVICE_UNAVAILABLE), Err = jlib:make_error_reply(
Packet,
?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)),
ejabberd_router:route(To, From, Err) ejabberd_router:route(To, From, Err)
end; end;
reply -> ok; reply -> ok;

View File

@ -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, adhoc_sm_commands).
process_adhoc_request(From, To, 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]), ?DEBUG("About to parse ~p...", [IQ]),
case adhoc:parse_request(IQ) of case adhoc:parse_request(IQ) of
{error, Error} -> {error, Error} ->
@ -245,8 +245,9 @@ process_adhoc_request(From, To,
of of
ignore -> ignore; ignore -> ignore;
empty -> empty ->
Txt = <<"No hook has processed this command">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}; sub_el = [SubEl, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)]};
{error, Error} -> {error, Error} ->
IQ#iq{type = error, sub_el = [SubEl, Error]}; IQ#iq{type = error, sub_el = [SubEl, Error]};
Command -> IQ#iq{type = result, sub_el = [Command]} Command -> IQ#iq{type = result, sub_el = [Command]}
@ -277,7 +278,9 @@ ping_command(_Acc, _From, _To,
[{<<"info">>, [{<<"info">>,
translate:translate(Lang, translate:translate(Lang,
<<"Pong">>)}]}); <<"Pong">>)}]});
true -> {error, ?ERR_BAD_REQUEST} true ->
Txt = <<"Incorrect value of 'action' attribute">>,
{error, ?ERRT_BAD_REQUEST(Lang, Txt)}
end; end;
ping_command(Acc, _From, _To, _Request) -> Acc. ping_command(Acc, _From, _To, _Request) -> Acc.

View File

@ -64,29 +64,33 @@ process_iq(_From, _To, IQ) ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}. IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}.
process_iq_get(_, From, _To, process_iq_get(_, From, _To,
#iq{xmlns = ?NS_BLOCKING, #iq{xmlns = ?NS_BLOCKING, lang = Lang,
sub_el = #xmlel{name = <<"blocklist">>}}, sub_el = #xmlel{name = <<"blocklist">>}},
_) -> _) ->
#jid{luser = LUser, lserver = LServer} = From, #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_get(Acc, _, _, _, _) -> Acc.
process_iq_set(_, From, _To, process_iq_set(_, From, _To,
#iq{xmlns = ?NS_BLOCKING, #iq{xmlns = ?NS_BLOCKING, lang = Lang,
sub_el = sub_el =
#xmlel{name = SubElName, children = SubEls}}) -> #xmlel{name = SubElName, children = SubEls}}) ->
#jid{luser = LUser, lserver = LServer} = From, #jid{luser = LUser, lserver = LServer} = From,
Res = case {SubElName, fxml:remove_cdata(SubEls)} of 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} -> {<<"block">>, Els} ->
JIDs = parse_blocklist_items(Els, []), JIDs = parse_blocklist_items(Els, []),
process_blocklist_block(LUser, LServer, JIDs); process_blocklist_block(LUser, LServer, JIDs, Lang);
{<<"unblock">>, []} -> {<<"unblock">>, []} ->
process_blocklist_unblock_all(LUser, LServer); process_blocklist_unblock_all(LUser, LServer, Lang);
{<<"unblock">>, Els} -> {<<"unblock">>, Els} ->
JIDs = parse_blocklist_items(Els, []), JIDs = parse_blocklist_items(Els, []),
process_blocklist_unblock(LUser, LServer, JIDs); process_blocklist_unblock(LUser, LServer, JIDs, Lang);
_ -> {error, ?ERR_BAD_REQUEST} _ ->
Txt = <<"Unknown blocking command">>,
{error, ?ERRT_BAD_REQUEST(Lang, Txt)}
end, end,
{stop, Res}; {stop, Res};
process_iq_set(Acc, _, _, _) -> Acc. 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) ->
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) -> Filter = fun (List) ->
AlreadyBlocked = list_to_blocklist_jids(List, []), AlreadyBlocked = list_to_blocklist_jids(List, []),
lists:foldr(fun (JID, List1) -> lists:foldr(fun (JID, List1) ->
@ -143,7 +147,7 @@ process_blocklist_block(LUser, LServer, JIDs) ->
end, end,
List, JIDs) List, JIDs)
end, end,
case process_blocklist_block(LUser, LServer, Filter, case process_blocklist_block_db(LUser, LServer, Filter,
gen_mod:db_type(LServer, mod_privacy)) gen_mod:db_type(LServer, mod_privacy))
of of
{atomic, {ok, Default, List}} -> {atomic, {ok, Default, List}} ->
@ -155,10 +159,10 @@ process_blocklist_block(LUser, LServer, JIDs) ->
{result, [], UserList}; {result, [], UserList};
_Err -> _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _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. end.
process_blocklist_block(LUser, LServer, Filter, process_blocklist_block_db(LUser, LServer, Filter,
mnesia) -> mnesia) ->
F = fun () -> F = fun () ->
case mnesia:wread({privacy, {LUser, LServer}}) of case mnesia:wread({privacy, {LUser, LServer}}) of
@ -185,7 +189,7 @@ process_blocklist_block(LUser, LServer, Filter,
{ok, NewDefault, NewList} {ok, NewDefault, NewList}
end, end,
mnesia:transaction(F); mnesia:transaction(F);
process_blocklist_block(LUser, LServer, Filter, process_blocklist_block_db(LUser, LServer, Filter,
riak) -> riak) ->
{atomic, {atomic,
begin begin
@ -218,7 +222,7 @@ process_blocklist_block(LUser, LServer, Filter,
Err Err
end end
end}; end};
process_blocklist_block(LUser, LServer, Filter, odbc) -> process_blocklist_block_db(LUser, LServer, Filter, odbc) ->
F = fun () -> F = fun () ->
Default = case Default = case
mod_privacy:sql_get_default_privacy_list_t(LUser) mod_privacy:sql_get_default_privacy_list_t(LUser)
@ -246,7 +250,7 @@ process_blocklist_block(LUser, LServer, Filter, odbc) ->
end, end,
ejabberd_odbc:sql_transaction(LServer, F). ejabberd_odbc:sql_transaction(LServer, F).
process_blocklist_unblock_all(LUser, LServer) -> process_blocklist_unblock_all(LUser, LServer, Lang) ->
Filter = fun (List) -> Filter = fun (List) ->
lists:filter(fun (#listitem{action = A}) -> A =/= deny lists:filter(fun (#listitem{action = A}) -> A =/= deny
end, end,
@ -263,10 +267,10 @@ process_blocklist_unblock_all(LUser, LServer) ->
{result, [], UserList}; {result, [], UserList};
_Err -> _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer}, _Err]), ?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer}, _Err]),
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, <<"Database failure">>)}
end. end.
process_blocklist_unblock(LUser, LServer, JIDs) -> process_blocklist_unblock(LUser, LServer, JIDs, Lang) ->
Filter = fun (List) -> Filter = fun (List) ->
lists:filter(fun (#listitem{action = deny, type = jid, lists:filter(fun (#listitem{action = deny, type = jid,
value = JID}) -> value = JID}) ->
@ -287,7 +291,7 @@ process_blocklist_unblock(LUser, LServer, JIDs) ->
{result, [], UserList}; {result, [], UserList};
_Err -> _Err ->
?ERROR_MSG("Error processing ~p: ~p", [{LUser, LServer, JIDs}, _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. end.
unblock_by_filter(LUser, LServer, Filter, mnesia) -> unblock_by_filter(LUser, LServer, Filter, mnesia) ->
@ -375,11 +379,12 @@ broadcast_blocklist_event(LUser, LServer, Event) ->
ejabberd_sm:route(JID, JID, ejabberd_sm:route(JID, JID,
{broadcast, {blocking, Event}}). {broadcast, {blocking, Event}}).
process_blocklist_get(LUser, LServer) -> process_blocklist_get(LUser, LServer, Lang) ->
case process_blocklist_get(LUser, LServer, case process_blocklist_get_db(LUser, LServer,
gen_mod:db_type(LServer, mod_privacy)) gen_mod:db_type(LServer, mod_privacy))
of of
error -> {error, ?ERR_INTERNAL_SERVER_ERROR}; error ->
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, <<"Database failure">>)};
List -> List ->
JIDs = list_to_blocklist_jids(List, []), JIDs = list_to_blocklist_jids(List, []),
Items = lists:map(fun (JID) -> Items = lists:map(fun (JID) ->
@ -397,7 +402,7 @@ process_blocklist_get(LUser, LServer) ->
children = Items}]} children = Items}]}
end. end.
process_blocklist_get(LUser, LServer, mnesia) -> process_blocklist_get_db(LUser, LServer, mnesia) ->
case catch mnesia:dirty_read(privacy, {LUser, LServer}) case catch mnesia:dirty_read(privacy, {LUser, LServer})
of of
{'EXIT', _Reason} -> error; {'EXIT', _Reason} -> error;
@ -408,7 +413,7 @@ process_blocklist_get(LUser, LServer, mnesia) ->
_ -> [] _ -> []
end end
end; end;
process_blocklist_get(LUser, LServer, riak) -> process_blocklist_get_db(LUser, LServer, riak) ->
case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(), case ejabberd_riak:get(privacy, mod_privacy:privacy_schema(),
{LUser, LServer}) of {LUser, LServer}) of
{ok, #privacy{default = Default, lists = Lists}} -> {ok, #privacy{default = Default, lists = Lists}} ->
@ -421,7 +426,7 @@ process_blocklist_get(LUser, LServer, riak) ->
{error, _} -> {error, _} ->
error error
end; end;
process_blocklist_get(LUser, LServer, odbc) -> process_blocklist_get_db(LUser, LServer, odbc) ->
case catch case catch
mod_privacy:sql_get_default_privacy_list(LUser, LServer) mod_privacy:sql_get_default_privacy_list(LUser, LServer)
of of

View File

@ -102,7 +102,9 @@ iq_handler2(From, To, IQ) ->
iq_handler1(From, To, IQ) -> iq_handler1(From, To, IQ) ->
iq_handler(From, To, IQ, ?NS_CARBONS_1). 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]), ?DEBUG("carbons IQ received: ~p", [IQ]),
{U, S, R} = jid:tolower(From), {U, S, R} = jid:tolower(From),
Result = case Operation of 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", []), ?DEBUG("carbons IQ result: ok", []),
IQ#iq{type=result, sub_el=[]}; IQ#iq{type=result, sub_el=[]};
{error,_Error} -> {error,_Error} ->
?WARNING_MSG("Error enabling / disabling carbons: ~p", [Result]), ?ERROR_MSG("Error enabling / disabling carbons: ~p", [Result]),
IQ#iq{type=error,sub_el = [?ERR_BAD_REQUEST]} Txt = <<"Database failure">>,
IQ#iq{type=error,sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]}
end; end;
iq_handler(_From, _To, IQ, _CC)-> iq_handler(_From, _To, #iq{lang = Lang, sub_el = SubEl} = IQ, _CC)->
IQ#iq{type=error, sub_el = [?ERR_NOT_ALLOWED]}. 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) -> user_send_packet(Packet, _C2SState, From, To) ->
check_and_forward(From, To, Packet, sent). check_and_forward(From, To, Packet, sent).

View File

@ -56,15 +56,17 @@ stop(Host) ->
?NS_ECONFIGURE). ?NS_ECONFIGURE).
process_local_iq(From, To, 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 case acl:match_rule(To#jid.lserver, configure, From) of
deny -> 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 -> allow ->
case Type of case Type of
set -> set ->
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
IQ#iq{type = error, 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 %%case fxml:get_tag_attr_s("type", SubEl) of
%% "cancel" -> %% "cancel" ->
%% IQ#iq{type = result, %% IQ#iq{type = result,
@ -98,7 +100,7 @@ process_local_iq(From, To,
%% sub_el = [SubEl, ?ERR_NOT_ALLOWED]} %% sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
%%end; %%end;
get -> get ->
case process_get(SubEl) of case process_get(SubEl, Lang) of
{result, Res} -> IQ#iq{type = result, sub_el = [Res]}; {result, Res} -> IQ#iq{type = result, sub_el = [Res]};
{error, Error} -> {error, Error} ->
IQ#iq{type = error, sub_el = [SubEl, Error]} IQ#iq{type = error, sub_el = [SubEl, Error]}
@ -106,7 +108,7 @@ process_local_iq(From, To,
end end
end. end.
process_get(#xmlel{name = <<"info">>}) -> process_get(#xmlel{name = <<"info">>}, _Lang) ->
S2SConns = ejabberd_s2s:dirty_get_connections(), S2SConns = ejabberd_s2s:dirty_get_connections(),
TConns = lists:usort([element(2, C) || C <- S2SConns]), TConns = lists:usort([element(2, C) || C <- S2SConns]),
Attrs = [{<<"registered-users">>, Attrs = [{<<"registered-users">>,
@ -130,7 +132,7 @@ process_get(#xmlel{name = <<"info">>}) ->
attrs = [{<<"xmlns">>, ?NS_ECONFIGURE} | Attrs], attrs = [{<<"xmlns">>, ?NS_ECONFIGURE} | Attrs],
children = []}}; children = []}};
process_get(#xmlel{name = <<"welcome-message">>, process_get(#xmlel{name = <<"welcome-message">>,
attrs = Attrs}) -> attrs = Attrs}, _Lang) ->
{Subj, Body} = ejabberd_config:get_option( {Subj, Body} = ejabberd_config:get_option(
welcome_message, welcome_message,
fun({Subj, Body}) -> fun({Subj, Body}) ->
@ -146,7 +148,7 @@ process_get(#xmlel{name = <<"welcome-message">>,
#xmlel{name = <<"body">>, attrs = [], #xmlel{name = <<"body">>, attrs = [],
children = [{xmlcdata, Body}]}]}}; children = [{xmlcdata, Body}]}]}};
process_get(#xmlel{name = <<"registration-watchers">>, process_get(#xmlel{name = <<"registration-watchers">>,
attrs = Attrs}) -> attrs = Attrs}, _Lang) ->
SubEls = ejabberd_config:get_option( SubEls = ejabberd_config:get_option(
registration_watchers, registration_watchers,
fun(JIDs) when is_list(JIDs) -> fun(JIDs) when is_list(JIDs) ->
@ -160,14 +162,14 @@ process_get(#xmlel{name = <<"registration-watchers">>,
{result, {result,
#xmlel{name = <<"registration_watchers">>, #xmlel{name = <<"registration_watchers">>,
attrs = Attrs, children = SubEls}}; 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.", Str = iolist_to_binary(io_lib:format("~p.",
[ets:tab2list(acl)])), [ets:tab2list(acl)])),
{result, {result,
#xmlel{name = <<"acls">>, attrs = Attrs, #xmlel{name = <<"acls">>, attrs = Attrs,
children = [{xmlcdata, Str}]}}; children = [{xmlcdata, Str}]}};
process_get(#xmlel{name = <<"access">>, process_get(#xmlel{name = <<"access">>,
attrs = Attrs}) -> attrs = Attrs}, _Lang) ->
Str = iolist_to_binary(io_lib:format("~p.", Str = iolist_to_binary(io_lib:format("~p.",
[ets:select(local_config, [ets:select(local_config,
[{{local_config, {access, '$1'}, [{{local_config, {access, '$1'},
@ -178,13 +180,14 @@ process_get(#xmlel{name = <<"access">>,
{result, {result,
#xmlel{name = <<"access">>, attrs = Attrs, #xmlel{name = <<"access">>, attrs = Attrs,
children = [{xmlcdata, Str}]}}; 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, case catch mnesia:dirty_select(last_activity,
[{{last_activity, '_', '$1', '_'}, [], [{{last_activity, '_', '$1', '_'}, [],
['$1']}]) ['$1']}])
of of
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR}; Txt = <<"Database failure">>,
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)};
Vals -> Vals ->
TimeStamp = p1_time_compat:system_time(seconds), TimeStamp = p1_time_compat:system_time(seconds),
Str = list_to_binary( Str = list_to_binary(
@ -196,7 +199,7 @@ process_get(#xmlel{name = <<"last">>, attrs = Attrs}) ->
end; end;
%%process_get({xmlelement, Name, Attrs, SubEls}) -> %%process_get({xmlelement, Name, Attrs, SubEls}) ->
%% {result, }; %% {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) -> fun gen_iq_handler:check_type/1;
mod_opt_type(_) -> [iqdisc]. mod_opt_type(_) -> [iqdisc].

View File

@ -118,7 +118,10 @@ handle_cast(_Msg, State) -> {noreply, State}.
handle_info({route, From, To, Packet}, State) -> handle_info({route, From, To, Packet}, State) ->
Packet2 = case From#jid.user of 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 _ -> Packet
end, end,
do_client_version(disabled, To, From), do_client_version(disabled, To, From),

View File

@ -569,7 +569,8 @@ process_iq(From,
deny -> deny ->
?DEBUG("Denying HTTP upload slot request from ~s", ?DEBUG("Denying HTTP upload slot request from ~s",
[jid:to_string(From)]), [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; end;
process_iq(_From, #iq{sub_el = SubEl} = IQ, _State) -> process_iq(_From, #iq{sub_el = SubEl} = IQ, _State) ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]}; 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)} {error, ?ERRT_BAD_REQUEST(Lang, Text)}
end; end;
_ -> _ ->
{error, ?ERR_BAD_REQUEST} Text = <<"No or invalid XML namespace">>,
{error, ?ERRT_BAD_REQUEST(Lang, Text)}
end; end;
parse_request(_El, _Lang) -> {error, ?ERR_BAD_REQUEST}. parse_request(_El, _Lang) -> {error, ?ERR_BAD_REQUEST}.
@ -639,7 +641,7 @@ create_slot(#state{service_url = undefined,
end; end;
create_slot(#state{service_url = ServiceURL}, create_slot(#state{service_url = ServiceURL},
#jid{luser = U, lserver = S} = JID, File, Size, ContentType, #jid{luser = U, lserver = S} = JID, File, Size, ContentType,
_Lang) -> Lang) ->
Options = [{body_format, binary}, {full_result, false}], Options = [{body_format, binary}, {full_result, false}],
HttpOptions = [{timeout, ?SERVICE_REQUEST_TIMEOUT}], HttpOptions = [{timeout, ?SERVICE_REQUEST_TIMEOUT}],
SizeStr = jlib:integer_to_binary(Size), SizeStr = jlib:integer_to_binary(Size),
@ -659,7 +661,8 @@ create_slot(#state{service_url = ServiceURL},
Lines -> Lines ->
?ERROR_MSG("Can't parse data received for ~s from <~s>: ~p", ?ERROR_MSG("Can't parse data received for ~s from <~s>: ~p",
[jid:to_string(JID), ServiceURL, Lines]), [jid:to_string(JID), ServiceURL, Lines]),
{error, ?ERR_SERVICE_UNAVAILABLE} Txt = <<"Failed to parse HTTP response">>,
{error, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)}
end; end;
{ok, {402, _Body}} -> {ok, {402, _Body}} ->
?INFO_MSG("Got status code 402 for ~s from <~s>", ?INFO_MSG("Got status code 402 for ~s from <~s>",

View File

@ -86,10 +86,11 @@ stop(Host) ->
%%% %%%
process_local_iq(_From, _To, process_local_iq(_From, _To,
#iq{type = Type, sub_el = SubEl} = IQ) -> #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
case Type of case Type of
set -> 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 -> get ->
Sec = get_node_uptime(), Sec = get_node_uptime(),
IQ#iq{type = result, IQ#iq{type = result,
@ -123,10 +124,11 @@ now_to_seconds({MegaSecs, Secs, _MicroSecs}) ->
%%% %%%
process_sm_iq(From, To, process_sm_iq(From, To,
#iq{type = Type, sub_el = SubEl} = IQ) -> #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
case Type of case Type of
set -> 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 -> get ->
User = To#jid.luser, User = To#jid.luser,
Server = To#jid.lserver, Server = To#jid.lserver,
@ -150,10 +152,12 @@ process_sm_iq(From, To,
of of
allow -> get_last_iq(IQ, SubEl, User, Server); allow -> get_last_iq(IQ, SubEl, User, Server);
deny -> 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; end;
true -> 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
end. end.
@ -193,16 +197,18 @@ get_last(LUser, LServer, odbc) ->
Reason -> {error, {invalid_result, Reason}} Reason -> {error, {invalid_result, Reason}}
end. 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 ejabberd_sm:get_user_resources(LUser, LServer) of
[] -> [] ->
case get_last(LUser, LServer) of case get_last(LUser, LServer) of
{error, _Reason} -> {error, _Reason} ->
Txt = <<"Database failure">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}; sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]};
not_found -> not_found ->
Txt = <<"No info about last activity found">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_SERVICE_UNAVAILABLE]}; sub_el = [SubEl, ?ERRT_SERVICE_UNAVAILABLE(Lang, Txt)]};
{ok, TimeStamp, Status} -> {ok, TimeStamp, Status} ->
TimeStamp2 = p1_time_compat:system_time(seconds), TimeStamp2 = p1_time_compat:system_time(seconds),
Sec = TimeStamp2 - TimeStamp, Sec = TimeStamp2 - TimeStamp,

View File

@ -447,7 +447,7 @@ process_iq(LServer, #iq{sub_el = #xmlel{attrs = Attrs}} = IQ) ->
% Preference setting (both v0.2 & v0.3) % Preference setting (both v0.2 & v0.3)
process_iq(#jid{luser = LUser, lserver = LServer}, process_iq(#jid{luser = LUser, lserver = LServer},
#jid{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 try {case fxml:get_tag_attr_s(<<"default">>, SubEl) of
<<"always">> -> always; <<"always">> -> always;
<<"never">> -> never; <<"never">> -> never;
@ -469,8 +469,9 @@ process_iq(#jid{luser = LUser, lserver = LServer},
NewPrefs = prefs_el(Default, Always, Never, IQ#iq.xmlns), NewPrefs = prefs_el(Default, Always, Never, IQ#iq.xmlns),
IQ#iq{type = result, sub_el = [NewPrefs]}; IQ#iq{type = result, sub_el = [NewPrefs]};
_Err -> _Err ->
Txt = <<"Database failure">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]} sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]}
end end
catch _:_ -> catch _:_ ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]} IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}

View File

@ -132,8 +132,9 @@ process_iq(From, To,
{error, Err} -> {error, Err} ->
IQ#iq{type = error, sub_el = [SubEl, Err]} IQ#iq{type = error, sub_el = [SubEl, Err]}
end; end;
process_iq(_From, _To, #iq{sub_el = SubEl} = IQ) -> process_iq(_From, _To, #iq{sub_el = SubEl, lang = Lang} = IQ) ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}. Txt = <<"Unsupported MIX query">>,
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}.
%%%=================================================================== %%%===================================================================
%%% gen_server callbacks %%% gen_server callbacks

View File

@ -1056,7 +1056,9 @@ iq_set_register_info(ServerHost, Host, From, Nick,
ErrText = <<"That nickname is registered by another " ErrText = <<"That nickname is registered by another "
"person">>, "person">>,
{error, ?ERRT_CONFLICT(Lang, ErrText)}; {error, ?ERRT_CONFLICT(Lang, ErrText)};
_ -> {error, ?ERR_INTERNAL_SERVER_ERROR} _ ->
Txt = <<"Database failure">>,
{error, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)}
end. end.
process_iq_register_set(ServerHost, Host, From, SubEl, process_iq_register_set(ServerHost, Host, From, SubEl,
@ -1073,7 +1075,9 @@ process_iq_register_set(ServerHost, Host, From, SubEl,
{?NS_XDATA, <<"submit">>} -> {?NS_XDATA, <<"submit">>} ->
XData = jlib:parse_xdata_submit(XEl), XData = jlib:parse_xdata_submit(XEl),
case XData of 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 case lists:keysearch(<<"nick">>, 1, XData) of
{value, {_, [Nick]}} when Nick /= <<"">> -> {value, {_, [Nick]}} when Nick /= <<"">> ->

View File

@ -387,8 +387,9 @@ handle_offline_query(#jid{luser = U, lserver = S} = From,
end end
end, end,
IQ#iq{type = result, sub_el = []}; IQ#iq{type = result, sub_el = []};
handle_offline_query(_From, _To, #iq{sub_el = SubEl} = IQ) -> handle_offline_query(_From, _To, #iq{sub_el = SubEl, lang = Lang} = IQ) ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}. 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}) -> handle_offline_items_view(JID, #xmlel{children = Items}) ->
{U, S, R} = jid:tolower(JID), {U, S, R} = jid:tolower(JID),

View File

@ -204,13 +204,14 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
%% Hook callbacks %% Hook callbacks
%%==================================================================== %%====================================================================
iq_ping(_From, _To, iq_ping(_From, _To,
#iq{type = Type, sub_el = SubEl} = IQ) -> #iq{type = Type, sub_el = SubEl, lang = Lang} = IQ) ->
case {Type, SubEl} of case {Type, SubEl} of
{get, #xmlel{name = <<"ping">>}} -> {get, #xmlel{name = <<"ping">>}} ->
IQ#iq{type = result, sub_el = []}; IQ#iq{type = result, sub_el = []};
_ -> _ ->
Txt = <<"Ping query is incorrect">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]} sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}
end. end.
user_online(_SID, JID, _Info) -> user_online(_SID, JID, _Info) ->

View File

@ -73,52 +73,58 @@ stop(Host) ->
?NS_PRIVATE). ?NS_PRIVATE).
process_sm_iq(#jid{luser = LUser, lserver = LServer}, 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 -> when IQ#iq.type == set ->
case IQ#iq.sub_el of case IQ#iq.sub_el of
#xmlel{name = <<"query">>, children = Xmlels} -> #xmlel{name = <<"query">>, children = Xmlels} ->
case filter_xmlels(Xmlels) of case filter_xmlels(Xmlels) of
[] -> [] ->
Txt = <<"No private data found in this query">>,
IQ#iq{type = error, 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 -> Data ->
set_data(LUser, LServer, Data), set_data(LUser, LServer, Data),
IQ#iq{type = result, sub_el = []} IQ#iq{type = result, sub_el = []}
end; end;
_ -> _ ->
Txt = <<"No query found">>,
IQ#iq{type = error, 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; end;
%% %%
process_sm_iq(#jid{luser = LUser, lserver = LServer}, 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 -> when IQ#iq.type == get ->
case IQ#iq.sub_el of case IQ#iq.sub_el of
#xmlel{name = <<"query">>, attrs = Attrs, #xmlel{name = <<"query">>, attrs = Attrs,
children = Xmlels} -> children = Xmlels} ->
case filter_xmlels(Xmlels) of case filter_xmlels(Xmlels) of
[] -> [] ->
Txt = <<"No private data found in this query">>,
IQ#iq{type = error, 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 -> Data ->
case catch get_data(LUser, LServer, Data) of case catch get_data(LUser, LServer, Data) of
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
Txt = <<"Database failure">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = sub_el =
[IQ#iq.sub_el, ?ERR_INTERNAL_SERVER_ERROR]}; [IQ#iq.sub_el, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]};
Storage_Xmlels -> Storage_Xmlels ->
IQ#iq{type = result, IQ#iq{type = result,
sub_el = [?Xmlel_Query(Attrs, Storage_Xmlels)]} sub_el = [?Xmlel_Query(Attrs, Storage_Xmlels)]}
end end
end; end;
_ -> _ ->
Txt = <<"No query found">>,
IQ#iq{type = error, 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; 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, 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, []). filter_xmlels(Xmlels) -> filter_xmlels(Xmlels, []).

View File

@ -150,7 +150,7 @@ process_iq(_,
children = iq_vcard(Lang)}]}; children = iq_vcard(Lang)}]};
%% bytestreams info request %% bytestreams info request
process_iq(JID, process_iq(JID,
#iq{type = get, sub_el = SubEl, #iq{type = get, sub_el = SubEl, lang = Lang,
xmlns = ?NS_BYTESTREAMS} = xmlns = ?NS_BYTESTREAMS} =
IQ, IQ,
#state{acl = ACL, stream_addr = StreamAddr, #state{acl = ACL, stream_addr = StreamAddr,
@ -165,11 +165,12 @@ process_iq(JID,
attrs = [{<<"xmlns">>, ?NS_BYTESTREAMS}], attrs = [{<<"xmlns">>, ?NS_BYTESTREAMS}],
children = StreamHostEl}]}; children = StreamHostEl}]};
deny -> 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; end;
%% bytestream activation request %% bytestream activation request
process_iq(InitiatorJID, process_iq(InitiatorJID,
#iq{type = set, sub_el = SubEl, #iq{type = set, sub_el = SubEl, lang = Lang,
xmlns = ?NS_BYTESTREAMS} = xmlns = ?NS_BYTESTREAMS} =
IQ, IQ,
#state{acl = ACL, serverhost = ServerHost}) -> #state{acl = ACL, serverhost = ServerHost}) ->
@ -194,22 +195,27 @@ process_iq(InitiatorJID,
of of
ok -> IQ#iq{type = result, sub_el = []}; ok -> IQ#iq{type = result, sub_el = []};
false -> false ->
Txt = <<"Failed to activate bytestream">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}; sub_el = [SubEl, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)]};
limit -> limit ->
Txt = <<"Too many active bytestreams">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_RESOURCE_CONSTRAINT]}; sub_el = [SubEl, ?ERRT_RESOURCE_CONSTRAINT(Lang, Txt)]};
conflict -> 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, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]} sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}
end; 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; end;
deny -> 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; end;
%% Unknown "set" or "get" request %% Unknown "set" or "get" request
process_iq(_, #iq{type = Type, sub_el = SubEl} = IQ, _) process_iq(_, #iq{type = Type, sub_el = SubEl} = IQ, _)

View File

@ -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_manager(From, To, IQ);
process_iq(From, To, IQ) -> process_iq(From, To, IQ) ->
#iq{sub_el = SubEl} = IQ, #iq{sub_el = SubEl, lang = Lang} = IQ,
#jid{lserver = LServer} = From, #jid{lserver = LServer} = From,
case lists:member(LServer, ?MYHOSTS) of case lists:member(LServer, ?MYHOSTS) of
true -> process_local_iq(From, To, IQ); true -> process_local_iq(From, To, IQ);
_ -> _ ->
Txt = <<"The query is only allowed from local users">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]} sub_el = [SubEl, ?ERRT_ITEM_NOT_FOUND(Lang, Txt)]}
end. end.
process_local_iq(From, To, #iq{type = Type} = IQ) -> process_local_iq(From, To, #iq{type = Type} = IQ) ->
@ -479,12 +480,13 @@ get_roster_by_jid_t(LUser, LServer, LJID, riak) ->
exit(Err) exit(Err)
end. 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, #jid{server = Server} = From,
Access = gen_mod:get_module_opt(Server, ?MODULE, access, fun(A) when is_atom(A) -> A end, all), 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 case acl:match_rule(Server, Access, From) of
deny -> 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 -> allow ->
process_iq_set(From, To, IQ) process_iq_set(From, To, IQ)
end. end.
@ -1616,8 +1618,9 @@ process_iq_manager(From, To, IQ) ->
true -> true ->
process_iq_manager2(MatchDomain, To, IQ); process_iq_manager2(MatchDomain, To, IQ);
false -> false ->
#iq{sub_el = SubEl} = IQ, #iq{sub_el = SubEl, lang = Lang} = IQ,
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]} Txt = <<"Roster management is not allowed from this domain">>,
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_BAD_REQUEST(Lang, Txt)]}
end. end.
process_iq_manager2(MatchDomain, To, IQ) -> process_iq_manager2(MatchDomain, To, IQ) ->

View File

@ -60,8 +60,9 @@ process_local_iq(#jid{user = User, server = Server,
_To, #iq{type = get, sub_el = _SubEl} = IQ) -> _To, #iq{type = get, sub_el = _SubEl} = IQ) ->
get_ip({User, Server, Resource}, IQ); get_ip({User, Server, Resource}, IQ);
process_local_iq(_From, _To, process_local_iq(_From, _To,
#iq{type = set, sub_el = SubEl} = IQ) -> #iq{type = set, sub_el = SubEl, lang = Lang} = IQ) ->
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)]}.
process_sm_iq(#jid{user = User, server = Server, process_sm_iq(#jid{user = User, server = Server,
resource = Resource}, resource = Resource},
@ -69,14 +70,17 @@ process_sm_iq(#jid{user = User, server = Server,
#iq{type = get, sub_el = _SubEl} = IQ) -> #iq{type = get, sub_el = _SubEl} = IQ) ->
get_ip({User, Server, Resource}, IQ); get_ip({User, Server, Resource}, IQ);
process_sm_iq(_From, _To, process_sm_iq(_From, _To,
#iq{type = get, sub_el = SubEl} = IQ) -> #iq{type = get, sub_el = SubEl, lang = Lang} = IQ) ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_FORBIDDEN]}; Txt = <<"Query to another users is forbidden">>,
IQ#iq{type = error, sub_el = [SubEl, ?ERRT_FORBIDDEN(Lang, Txt)]};
process_sm_iq(_From, _To, process_sm_iq(_From, _To,
#iq{type = set, sub_el = SubEl} = IQ) -> #iq{type = set, sub_el = SubEl, lang = Lang} = IQ) ->
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_ip({User, Server, Resource}, get_ip({User, Server, Resource},
#iq{sub_el = #iq{lang = Lang,
sub_el =
#xmlel{name = Name, attrs = Attrs} = SubEl} = #xmlel{name = Name, attrs = Attrs} = SubEl} =
IQ) -> IQ) ->
case ejabberd_sm:get_user_ip(User, Server, Resource) of case ejabberd_sm:get_user_ip(User, Server, Resource) of
@ -88,8 +92,9 @@ get_ip({User, Server, Resource},
[{xmlcdata, [{xmlcdata,
iolist_to_binary(jlib:ip_to_list(IP))}]}]}; iolist_to_binary(jlib:ip_to_list(IP))}]}]};
_ -> _ ->
Txt = <<"User session not found">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]} sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]}
end. end.
mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1; mod_opt_type(iqdisc) -> fun gen_iq_handler:check_type/1;

View File

@ -50,17 +50,18 @@ stop(Host) ->
process_local_iq(_From, To, process_local_iq(_From, To,
#iq{id = _ID, type = Type, xmlns = XMLNS, #iq{id = _ID, type = Type, xmlns = XMLNS,
sub_el = SubEl} = sub_el = SubEl, lang = Lang} =
IQ) -> IQ) ->
case Type of case Type of
set -> 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 -> get ->
#xmlel{children = Els} = SubEl, #xmlel{children = Els} = SubEl,
Node = str:tokens(fxml:get_tag_attr_s(<<"node">>, SubEl), Node = str:tokens(fxml:get_tag_attr_s(<<"node">>, SubEl),
<<"/">>), <<"/">>),
Names = get_names(Els, []), 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} -> {result, Res} ->
IQ#iq{type = result, IQ#iq{type = result,
sub_el = sub_el =
@ -87,18 +88,18 @@ get_names([_ | Els], Res) -> get_names(Els, Res).
#xmlel{name = <<"stat">>, attrs = [{<<"name">>, Name}], #xmlel{name = <<"stat">>, attrs = [{<<"name">>, Name}],
children = []}). children = []}).
get_local_stats(_Server, [], []) -> get_local_stats(_Server, [], [], _Lang) ->
{result, {result,
[?STAT(<<"users/online">>), ?STAT(<<"users/total">>), [?STAT(<<"users/online">>), ?STAT(<<"users/total">>),
?STAT(<<"users/all-hosts/online">>), ?STAT(<<"users/all-hosts/online">>),
?STAT(<<"users/all-hosts/total">>)]}; ?STAT(<<"users/all-hosts/total">>)]};
get_local_stats(Server, [], Names) -> get_local_stats(Server, [], Names, _Lang) ->
{result, {result,
lists:map(fun (Name) -> get_local_stat(Server, [], Name) lists:map(fun (Name) -> get_local_stat(Server, [], Name)
end, end,
Names)}; Names)};
get_local_stats(_Server, [<<"running nodes">>, _], get_local_stats(_Server, [<<"running nodes">>, _],
[]) -> [], _Lang) ->
{result, {result,
[?STAT(<<"time/uptime">>), ?STAT(<<"time/cputime">>), [?STAT(<<"time/uptime">>), ?STAT(<<"time/cputime">>),
?STAT(<<"users/online">>), ?STAT(<<"users/online">>),
@ -107,16 +108,19 @@ get_local_stats(_Server, [<<"running nodes">>, _],
?STAT(<<"transactions/restarted">>), ?STAT(<<"transactions/restarted">>),
?STAT(<<"transactions/logged">>)]}; ?STAT(<<"transactions/logged">>)]};
get_local_stats(_Server, [<<"running nodes">>, ENode], get_local_stats(_Server, [<<"running nodes">>, ENode],
Names) -> Names, Lang) ->
case search_running_node(ENode) of 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 -> Node ->
{result, {result,
lists:map(fun (Name) -> get_node_stat(Node, Name) end, lists:map(fun (Name) -> get_node_stat(Node, Name) end,
Names)} Names)}
end; end;
get_local_stats(_Server, _, _) -> get_local_stats(_Server, _, _, Lang) ->
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}. Txt = <<"No statistics found for this item">>,
{error, ?ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Txt)}.
-define(STATVAL(Val, Unit), -define(STATVAL(Val, Unit),
#xmlel{name = <<"stat">>, #xmlel{name = <<"stat">>,

View File

@ -51,10 +51,11 @@ stop(Host) ->
?NS_TIME). ?NS_TIME).
process_local_iq(_From, _To, process_local_iq(_From, _To,
#iq{type = Type, sub_el = SubEl} = IQ) -> #iq{type = Type, sub_el = SubEl, lang = Lang} = IQ) ->
case Type of case Type of
set -> 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 -> get ->
Now_universal = calendar:universal_time(), Now_universal = calendar:universal_time(),
Now_local = calendar:universal_time_to_local_time(Now_universal), Now_local = calendar:universal_time_to_local_time(Now_universal),

View File

@ -152,7 +152,8 @@ process_local_iq(_From, _To,
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) -> #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
case Type of case Type of
set -> 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 -> get ->
IQ#iq{type = result, IQ#iq{type = result,
sub_el = sub_el =
@ -176,7 +177,7 @@ process_local_iq(_From, _To,
end. end.
process_sm_iq(From, To, process_sm_iq(From, To,
#iq{type = Type, sub_el = SubEl} = IQ) -> #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
case Type of case Type of
set -> set ->
#jid{user = User, lserver = LServer} = From, #jid{user = User, lserver = LServer} = From,
@ -185,14 +186,16 @@ process_sm_iq(From, To,
set_vcard(User, LServer, SubEl), set_vcard(User, LServer, SubEl),
IQ#iq{type = result, sub_el = []}; IQ#iq{type = result, sub_el = []};
false -> 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; end;
get -> get ->
#jid{luser = LUser, lserver = LServer} = To, #jid{luser = LUser, lserver = LServer} = To,
case get_vcard(LUser, LServer) of case get_vcard(LUser, LServer) of
error -> error ->
Txt = <<"Database failure">>,
IQ#iq{type = error, IQ#iq{type = error,
sub_el = [SubEl, ?ERR_INTERNAL_SERVER_ERROR]}; sub_el = [SubEl, ?ERRT_INTERNAL_SERVER_ERROR(Lang, Txt)]};
[] -> [] ->
IQ#iq{type = result, IQ#iq{type = result,
sub_el = [#xmlel{name = <<"vCard">>, sub_el = [#xmlel{name = <<"vCard">>,
@ -422,15 +425,17 @@ do_route(ServerHost, From, To, Packet) ->
XDataEl = find_xdata_el(SubEl), XDataEl = find_xdata_el(SubEl),
case XDataEl of case XDataEl of
false -> false ->
Err = jlib:make_error_reply(Packet, Txt = <<"Data form not found">>,
?ERR_BAD_REQUEST), Err = jlib:make_error_reply(
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
ejabberd_router:route(To, From, Err); ejabberd_router:route(To, From, Err);
_ -> _ ->
XData = jlib:parse_xdata_submit(XDataEl), XData = jlib:parse_xdata_submit(XDataEl),
case XData of case XData of
invalid -> invalid ->
Err = jlib:make_error_reply(Packet, Txt = <<"Incorrect data form">>,
?ERR_BAD_REQUEST), Err = jlib:make_error_reply(
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
ejabberd_router:route(To, From, Err); ejabberd_router:route(To, From, Err);
_ -> _ ->
ResIQ = IQ#iq{type = result, ResIQ = IQ#iq{type = result,
@ -470,7 +475,8 @@ do_route(ServerHost, From, To, Packet) ->
#iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} -> #iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} ->
case Type of case Type of
set -> 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); ejabberd_router:route(To, From, Err);
get -> get ->
Info = ejabberd_hooks:run_fold(disco_info, ServerHost, Info = ejabberd_hooks:run_fold(disco_info, ServerHost,
@ -516,10 +522,11 @@ do_route(ServerHost, From, To, Packet) ->
++ Info}]}, ++ Info}]},
ejabberd_router:route(To, From, jlib:iq_to_xml(ResIQ)) ejabberd_router:route(To, From, jlib:iq_to_xml(ResIQ))
end; end;
#iq{type = Type, xmlns = ?NS_DISCO_ITEMS} -> #iq{type = Type, lang = Lang, xmlns = ?NS_DISCO_ITEMS} ->
case Type of case Type of
set -> 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); ejabberd_router:route(To, From, Err);
get -> get ->
ResIQ = IQ#iq{type = result, ResIQ = IQ#iq{type = result,

View File

@ -206,7 +206,8 @@ process_local_iq(_From, _To,
#iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) -> #iq{type = Type, lang = Lang, sub_el = SubEl} = IQ) ->
case Type of case Type of
set -> 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 -> get ->
IQ#iq{type = result, IQ#iq{type = result,
sub_el = sub_el =
@ -240,10 +241,11 @@ process_sm_iq(_From, #jid{lserver = LServer} = To,
process_vcard_ldap(To, IQ, Server) -> process_vcard_ldap(To, IQ, Server) ->
{ok, State} = eldap_utils:get_state(Server, ?PROCNAME), {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 case Type of
set -> 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 -> get ->
#jid{luser = LUser} = To, #jid{luser = LUser} = To,
LServer = State#state.serverhost, LServer = State#state.serverhost,
@ -455,15 +457,17 @@ route(State, From, To, Packet) ->
XDataEl = find_xdata_el(SubEl), XDataEl = find_xdata_el(SubEl),
case XDataEl of case XDataEl of
false -> false ->
Err = jlib:make_error_reply(Packet, Txt = <<"Data form not found">>,
?ERR_BAD_REQUEST), Err = jlib:make_error_reply(
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
ejabberd_router:route(To, From, Err); ejabberd_router:route(To, From, Err);
_ -> _ ->
XData = jlib:parse_xdata_submit(XDataEl), XData = jlib:parse_xdata_submit(XDataEl),
case XData of case XData of
invalid -> invalid ->
Err = jlib:make_error_reply(Packet, Txt = <<"Incorrect data form">>,
?ERR_BAD_REQUEST), Err = jlib:make_error_reply(
Packet, ?ERRT_BAD_REQUEST(Lang, Txt)),
ejabberd_router:route(To, From, Err); ejabberd_router:route(To, From, Err);
_ -> _ ->
ResIQ = IQ#iq{type = result, ResIQ = IQ#iq{type = result,
@ -505,7 +509,8 @@ route(State, From, To, Packet) ->
#iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} -> #iq{type = Type, xmlns = ?NS_DISCO_INFO, lang = Lang} ->
case Type of case Type of
set -> 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); ejabberd_router:route(To, From, Err);
get -> get ->
Info = ejabberd_hooks:run_fold(disco_info, ServerHost, Info = ejabberd_hooks:run_fold(disco_info, ServerHost,
@ -545,10 +550,11 @@ route(State, From, To, Packet) ->
++ Info}]}, ++ Info}]},
ejabberd_router:route(To, From, jlib:iq_to_xml(ResIQ)) ejabberd_router:route(To, From, jlib:iq_to_xml(ResIQ))
end; end;
#iq{type = Type, xmlns = ?NS_DISCO_ITEMS} -> #iq{type = Type, lang = Lang, xmlns = ?NS_DISCO_ITEMS} ->
case Type of case Type of
set -> 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); ejabberd_router:route(To, From, Err);
get -> get ->
ResIQ = IQ#iq{type = result, ResIQ = IQ#iq{type = result,

View File

@ -52,11 +52,12 @@ stop(Host) ->
process_local_iq(_From, To, process_local_iq(_From, To,
#iq{id = _ID, type = Type, xmlns = _XMLNS, #iq{id = _ID, type = Type, xmlns = _XMLNS,
sub_el = SubEl} = sub_el = SubEl, lang = Lang} =
IQ) -> IQ) ->
case Type of case Type of
set -> 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 -> get ->
Host = To#jid.lserver, Host = To#jid.lserver,
OS = case gen_mod:get_module_opt(Host, ?MODULE, show_os, OS = case gen_mod:get_module_opt(Host, ?MODULE, show_os,

View File

@ -77,8 +77,9 @@ publish_item(Nidx, Publisher, Model, MaxItems, ItemId, Payload) ->
#pubsub_node{options = Options} -> #pubsub_node{options = Options} ->
case find_opt(node_type, Options) of case find_opt(node_type, Options) of
collection -> collection ->
Txt = <<"Publishing items to collection node is not allowed">>,
{error, {error,
?ERR_EXTENDED((?ERR_NOT_ALLOWED), <<"publish">>)}; ?ERR_EXTENDED(?ERRT_NOT_ALLOWED(?MYLANG, Txt), <<"publish">>)};
_ -> _ ->
node_hometree:publish_item(Nidx, Publisher, Model, node_hometree:publish_item(Nidx, Publisher, Model,
MaxItems, ItemId, Payload) MaxItems, ItemId, Payload)

View File

@ -69,13 +69,13 @@ create_node(Key, Node, Type, Owner, Options, Parents) ->
Other -> Other Other -> Other
end; end;
_ -> _ ->
{error, ?ERR_CONFLICT} {error, ?ERRT_CONFLICT(?MYLANG, <<"Node already exists">>)}
end. end.
delete_node(Key, Node) -> delete_node(Key, Node) ->
case find_node(Key, Node) of case find_node(Key, Node) of
false -> false ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
Record -> Record ->
lists:foreach(fun (#pubsub_node{options = Opts} = Child) -> lists:foreach(fun (#pubsub_node{options = Opts} = Child) ->
NewOpts = remove_config_parent(Node, Opts), NewOpts = remove_config_parent(Node, Opts),
@ -99,7 +99,7 @@ get_node(Host, Node, _From) ->
get_node(Host, Node) -> get_node(Host, Node) ->
case find_node(Host, Node) of case find_node(Host, Node) of
false -> {error, ?ERR_ITEM_NOT_FOUND}; false -> {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
Record -> Record Record -> Record
end. end.
@ -115,7 +115,7 @@ get_nodes(Key) ->
get_parentnodes(Host, Node, _From) -> get_parentnodes(Host, Node, _From) ->
case find_node(Host, Node) of case find_node(Host, Node) of
false -> false ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
#pubsub_node{parents = Parents} -> #pubsub_node{parents = Parents} ->
Q = qlc:q([N Q = qlc:q([N
|| #pubsub_node{nodeid = {NHost, NNode}} = N || #pubsub_node{nodeid = {NHost, NNode}} = N
@ -139,7 +139,7 @@ get_subnodes(Host, <<>>) ->
get_subnodes_helper(Host, <<>>); get_subnodes_helper(Host, <<>>);
get_subnodes(Host, Node) -> get_subnodes(Host, Node) ->
case find_node(Host, Node) of 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) _ -> get_subnodes_helper(Host, Node)
end. end.
@ -238,7 +238,7 @@ validate_parentage(Key, Owners, [<<>> | T]) ->
validate_parentage(Key, Owners, [ParentID | T]) -> validate_parentage(Key, Owners, [ParentID | T]) ->
case find_node(Key, ParentID) of case find_node(Key, ParentID) of
false -> false ->
{error, ?ERR_ITEM_NOT_FOUND}; {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)};
#pubsub_node{owners = POwners, options = POptions} -> #pubsub_node{owners = POwners, options = POptions} ->
NodeType = find_opt(node_type, ?DEFAULT_NODETYPE, POptions), NodeType = find_opt(node_type, ?DEFAULT_NODETYPE, POptions),
MutualOwners = [O || O <- Owners, PO <- POwners, O == PO], MutualOwners = [O || O <- Owners, PO <- POwners, O == PO],

View File

@ -74,15 +74,15 @@ get_node(Host, Node, _From) ->
get_node(Host, Node). get_node(Host, Node).
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; [Record] when is_record(Record, pubsub_node) -> Record;
_ -> {error, ?ERR_ITEM_NOT_FOUND} _ -> {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)}
end. end.
get_node(Nidx) -> 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; [Record] when is_record(Record, pubsub_node) -> Record;
_ -> {error, ?ERR_ITEM_NOT_FOUND} _ -> {error, ?ERRT_ITEM_NOT_FOUND(?MYLANG, <<"Node not found">>)}
end. end.
get_nodes(Host, _From) -> get_nodes(Host, _From) ->
@ -147,7 +147,7 @@ get_subnodes_tree(Host, Node) ->
create_node(Host, Node, Type, Owner, Options, Parents) -> create_node(Host, Node, Type, Owner, Options, Parents) ->
BJID = jid:tolower(jid:remove_resource(Owner)), 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 ParentExists = case Host of
{_U, _S, _R} -> {_U, _S, _R} ->
@ -183,7 +183,7 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
{error, ?ERR_FORBIDDEN} {error, ?ERR_FORBIDDEN}
end; end;
_ -> _ ->
{error, ?ERR_CONFLICT} {error, ?ERRT_CONFLICT(?MYLANG, <<"Node already exists">>)}
end. end.
delete_node(Host, Node) -> delete_node(Host, Node) ->

View File

@ -93,7 +93,8 @@ set_node(Record) when is_record(Record, pubsub_node) ->
end, end,
case Nidx of case Nidx of
none -> none ->
{error, ?ERR_INTERNAL_SERVER_ERROR}; Txt = <<"Node index not found">>,
{error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, Txt)};
_ -> _ ->
lists:foreach(fun ({Key, Value}) -> lists:foreach(fun ({Key, Value}) ->
SKey = iolist_to_binary(atom_to_list(Key)), SKey = iolist_to_binary(atom_to_list(Key)),
@ -125,9 +126,9 @@ get_node(Host, Node) ->
[<<"node">>, <<"parent">>, <<"type">>, <<"nodeid">>], [RItem]} -> [<<"node">>, <<"parent">>, <<"type">>, <<"nodeid">>], [RItem]} ->
raw_to_node(Host, RItem); raw_to_node(Host, RItem);
{'EXIT', _Reason} -> {'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. end.
get_node(Nidx) -> get_node(Nidx) ->
@ -140,9 +141,9 @@ get_node(Nidx) ->
[<<"host">>, <<"node">>, <<"parent">>, <<"type">>], [[Host, Node, Parent, Type]]} -> [<<"host">>, <<"node">>, <<"parent">>, <<"type">>], [[Host, Node, Parent, Type]]} ->
raw_to_node(Host, [Node, Parent, Type, Nidx]); raw_to_node(Host, [Node, Parent, Type, Nidx]);
{'EXIT', _Reason} -> {'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. end.
get_nodes(Host, _From) -> get_nodes(Host, _From) ->
@ -211,7 +212,7 @@ get_subnodes_tree(Host, Node) ->
create_node(Host, Node, Type, Owner, Options, Parents) -> create_node(Host, Node, Type, Owner, Options, Parents) ->
BJID = jid:tolower(jid:remove_resource(Owner)), BJID = jid:tolower(jid:remove_resource(Owner)),
case nodeidx(Host, Node) of case nodeidx(Host, Node) of
{error, ?ERR_ITEM_NOT_FOUND} -> {error, not_found} ->
ParentExists = case Host of ParentExists = case Host of
{_U, _S, _R} -> {_U, _S, _R} ->
%% This is special case for PEP handling %% This is special case for PEP handling
@ -248,9 +249,9 @@ create_node(Host, Node, Type, Owner, Options, Parents) ->
{error, ?ERR_FORBIDDEN} {error, ?ERR_FORBIDDEN}
end; end;
{result, _} -> {result, _} ->
{error, ?ERR_CONFLICT}; {error, ?ERRT_CONFLICT(?MYLANG, <<"Node already exists">>)};
Error -> {error, db_fail} ->
Error {error, ?ERRT_INTERNAL_SERVER_ERROR(?MYLANG, <<"Database failure">>)}
end. end.
delete_node(Host, Node) -> delete_node(Host, Node) ->
@ -303,9 +304,9 @@ nodeidx(Host, Node) ->
{selected, [<<"nodeid">>], [[Nidx]]} -> {selected, [<<"nodeid">>], [[Nidx]]} ->
{result, Nidx}; {result, Nidx};
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
{error, ?ERR_INTERNAL_SERVER_ERROR}; {error, db_fail};
_ -> _ ->
{error, ?ERR_ITEM_NOT_FOUND} {error, not_found}
end. end.
nodeowners(Nidx) -> nodeowners(Nidx) ->

View File

@ -237,31 +237,40 @@ var_xfield(?PUBSUB_SUBSCRIPTION_TYPE) -> subscription_type;
var_xfield(?PUBSUB_SUBSCRIPTION_DEPTH) -> subscription_depth; var_xfield(?PUBSUB_SUBSCRIPTION_DEPTH) -> subscription_depth;
var_xfield(_) -> {error, badarg}. var_xfield(_) -> {error, badarg}.
val_xfield(deliver, [Val]) -> xopt_to_bool(Val); val_xfield(deliver = Opt, [Val]) -> xopt_to_bool(Opt, Val);
val_xfield(digest, [Val]) -> xopt_to_bool(Val); val_xfield(digest = Opt, [Val]) -> xopt_to_bool(Opt, Val);
val_xfield(digest_frequency, [Val]) -> val_xfield(digest_frequency = Opt, [Val]) ->
case catch jlib:binary_to_integer(Val) of case catch jlib:binary_to_integer(Val) of
N when is_integer(N) -> N; 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; end;
val_xfield(expire, [Val]) -> jlib:datetime_string_to_timestamp(Val); 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(show_values, Vals) -> Vals;
val_xfield(subscription_type, [<<"items">>]) -> items; val_xfield(subscription_type, [<<"items">>]) -> items;
val_xfield(subscription_type, [<<"nodes">>]) -> nodes; val_xfield(subscription_type, [<<"nodes">>]) -> nodes;
val_xfield(subscription_depth, [<<"all">>]) -> all; 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 case catch jlib:binary_to_integer(Depth) of
N when is_integer(N) -> N; 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. end.
%% Convert XForm booleans to Erlang booleans. %% Convert XForm booleans to Erlang booleans.
xopt_to_bool(<<"0">>) -> false; xopt_to_bool(_, <<"0">>) -> false;
xopt_to_bool(<<"1">>) -> true; xopt_to_bool(_, <<"1">>) -> true;
xopt_to_bool(<<"false">>) -> false; xopt_to_bool(_, <<"false">>) -> false;
xopt_to_bool(<<"true">>) -> true; xopt_to_bool(_, <<"true">>) -> true;
xopt_to_bool(_) -> {error, ?ERR_NOT_ACCEPTABLE}. 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 :: -spec(get_option_xfield/3 ::
( (

View File

@ -200,31 +200,40 @@ var_xfield(?PUBSUB_SUBSCRIPTION_TYPE) -> subscription_type;
var_xfield(?PUBSUB_SUBSCRIPTION_DEPTH) -> subscription_depth; var_xfield(?PUBSUB_SUBSCRIPTION_DEPTH) -> subscription_depth;
var_xfield(_) -> {error, badarg}. var_xfield(_) -> {error, badarg}.
val_xfield(deliver, [Val]) -> xopt_to_bool(Val); val_xfield(deliver = Opt, [Val]) -> xopt_to_bool(Opt, Val);
val_xfield(digest, [Val]) -> xopt_to_bool(Val); val_xfield(digest = Opt, [Val]) -> xopt_to_bool(Opt, Val);
val_xfield(digest_frequency, [Val]) -> val_xfield(digest_frequency = Opt, [Val]) ->
case catch jlib:binary_to_integer(Val) of case catch jlib:binary_to_integer(Val) of
N when is_integer(N) -> N; 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; end;
val_xfield(expire, [Val]) -> jlib:datetime_string_to_timestamp(Val); 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(show_values, Vals) -> Vals;
val_xfield(subscription_type, [<<"items">>]) -> items; val_xfield(subscription_type, [<<"items">>]) -> items;
val_xfield(subscription_type, [<<"nodes">>]) -> nodes; val_xfield(subscription_type, [<<"nodes">>]) -> nodes;
val_xfield(subscription_depth, [<<"all">>]) -> all; 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 case catch jlib:binary_to_integer(Depth) of
N when is_integer(N) -> N; 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. end.
%% Convert XForm booleans to Erlang booleans. %% Convert XForm booleans to Erlang booleans.
xopt_to_bool(<<"0">>) -> false; xopt_to_bool(_, <<"0">>) -> false;
xopt_to_bool(<<"1">>) -> true; xopt_to_bool(_, <<"1">>) -> true;
xopt_to_bool(<<"false">>) -> false; xopt_to_bool(_, <<"false">>) -> false;
xopt_to_bool(<<"true">>) -> true; xopt_to_bool(_, <<"true">>) -> true;
xopt_to_bool(_) -> {error, ?ERR_NOT_ACCEPTABLE}. 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 %% Return a field for an XForm for Key, with data filled in, if
%% applicable, from Options. %% applicable, from Options.