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

View File

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

View File

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