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

Don't include sub-elements in IQ results where it's not required

by the corresponding spec (RFC or XEP).
This commit is contained in:
Evgeniy Khramtsov 2013-06-14 20:05:06 +02:00 committed by Alexey Shchepin
parent 1b96856d92
commit 7865c6a146
3 changed files with 11 additions and 25 deletions

View File

@ -539,8 +539,8 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
StateData#state.socket), StateData#state.socket),
Info = [{ip, StateData#state.ip}, {conn, Conn}, Info = [{ip, StateData#state.ip}, {conn, Conn},
{auth_module, AuthModule}], {auth_module, AuthModule}],
Res1 = jlib:make_result_iq_reply(El), Res = jlib:make_result_iq_reply(
Res = Res1#xmlel{children = []}, El#xmlel{children = []}),
send_element(StateData, Res), send_element(StateData, Res),
ejabberd_sm:open_session(SID, U, StateData#state.server, R, Info), ejabberd_sm:open_session(SID, U, StateData#state.server, R, Info),
change_shaper(StateData, JID), change_shaper(StateData, JID),
@ -976,7 +976,7 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
?INFO_MSG("(~w) Opened session for ~s", ?INFO_MSG("(~w) Opened session for ~s",
[StateData#state.socket, [StateData#state.socket,
jlib:jid_to_string(JID)]), jlib:jid_to_string(JID)]),
Res = jlib:make_result_iq_reply(El), Res = jlib:make_result_iq_reply(El#xmlel{children = []}),
send_element(StateData, Res), send_element(StateData, Res),
change_shaper(StateData, JID), change_shaper(StateData, JID),
{Fs, Ts} = ejabberd_hooks:run_fold( {Fs, Ts} = ejabberd_hooks:run_fold(

View File

@ -123,14 +123,14 @@ process_iq(From, To,
case From of case From of
#jid{user = User, lserver = Server} -> #jid{user = User, lserver = Server} ->
ejabberd_auth:remove_user(User, Server), ejabberd_auth:remove_user(User, Server),
IQ#iq{type = result, sub_el = [SubEl]}; IQ#iq{type = result, sub_el = []};
_ -> _ ->
if PTag /= false -> if PTag /= false ->
Password = xml:get_tag_cdata(PTag), Password = xml:get_tag_cdata(PTag),
case ejabberd_auth:remove_user(User, Server, case ejabberd_auth:remove_user(User, Server,
Password) Password)
of of
ok -> IQ#iq{type = result, sub_el = [SubEl]}; ok -> IQ#iq{type = result, sub_el = []};
%% TODO FIXME: This piece of %% TODO FIXME: This piece of
%% code does not work since %% code does not work since
%% the code have been changed %% the code have been changed
@ -160,7 +160,7 @@ process_iq(From, To,
#jid{user = User, lserver = Server, #jid{user = User, lserver = Server,
resource = Resource} -> resource = Resource} ->
ResIQ = #iq{type = result, xmlns = ?NS_REGISTER, ResIQ = #iq{type = result, xmlns = ?NS_REGISTER,
id = ID, sub_el = [SubEl]}, id = ID, sub_el = []},
ejabberd_router:route(jlib:make_jid(User, Server, ejabberd_router:route(jlib:make_jid(User, Server,
Resource), Resource),
jlib:make_jid(User, Server, jlib:make_jid(User, Server,
@ -326,7 +326,7 @@ try_register_or_set_password(User, Server, Password,
allow -> allow ->
case try_register(User, Server, Password, Source, Lang) case try_register(User, Server, Password, Source, Lang)
of of
ok -> IQ#iq{type = result, sub_el = [SubEl]}; ok -> IQ#iq{type = result, sub_el = []};
{error, Error} -> {error, Error} ->
IQ#iq{type = error, sub_el = [SubEl, Error]} IQ#iq{type = error, sub_el = [SubEl, Error]}
end; end;
@ -344,7 +344,7 @@ try_set_password(User, Server, Password, IQ, SubEl,
true -> true ->
case ejabberd_auth:set_password(User, Server, Password) case ejabberd_auth:set_password(User, Server, Password)
of of
ok -> IQ#iq{type = result, sub_el = [SubEl]}; ok -> IQ#iq{type = result, sub_el = []};
{error, empty_password} -> {error, empty_password} ->
IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]}; IQ#iq{type = error, sub_el = [SubEl, ?ERR_BAD_REQUEST]};
{error, not_allowed} -> {error, not_allowed} ->

View File

@ -223,10 +223,7 @@ register(Config) ->
#iq{type = set, #iq{type = set,
sub_els = [#register{username = ?config(user, Config), sub_els = [#register{username = ?config(user, Config),
password = ?config(password, Config)}]}), password = ?config(password, Config)}]}),
%% BUG: we should receive empty sub_els #iq{type = result, id = I2, sub_els = []} = recv(),
%% TODO: fix in ejabberd
%% #iq{type = result, id = I2, sub_els = []} = recv(),
#iq{type = result, id = I2, sub_els = [#register{}]} = recv(),
Config. Config.
test_unregister(Config) -> test_unregister(Config) ->
@ -242,10 +239,7 @@ try_unregister(Config) ->
I = send(Config, I = send(Config,
#iq{type = set, #iq{type = set,
sub_els = [#register{remove = true}]}), sub_els = [#register{remove = true}]}),
%% BUG: we should receive empty sub_els #iq{type = result, id = I, sub_els = []} = recv(),
%% TODO: fix in ejabberd
%% #iq{type = result, id = I, sub_els = []} = recv(),
#iq{type = result, id = I, sub_els = [#register{}]} = recv(),
#stream_error{reason = conflict} = recv(), #stream_error{reason = conflict} = recv(),
Config. Config.
@ -279,15 +273,7 @@ test_open_session(Config) ->
open_session(Config) -> open_session(Config) ->
ID = send(Config, #iq{type = set, sub_els = [#session{}]}), ID = send(Config, #iq{type = set, sub_els = [#session{}]}),
#iq{type = result, id = ID, sub_els = SubEls} = recv(), #iq{type = result, id = ID, sub_els = []} = recv(),
case SubEls of
[] ->
ok;
[#session{}] ->
%% BUG: we should not receive this!
%% TODO: should be fixed in ejabberd
ok
end,
Config. Config.
roster_get(Config) -> roster_get(Config) ->