Fix presenting features and returning results of inline bind2 elements

This commit is contained in:
Paweł Chmielowski 2023-11-20 18:50:11 +01:00
parent 59bb6dae14
commit fdee4efe98
5 changed files with 40 additions and 29 deletions

View File

@ -114,7 +114,7 @@ defmodule Ejabberd.MixProject do
{:p1_utils, "~> 1.0"},
{:pkix, "~> 1.0"},
{:stringprep, ">= 1.0.26"},
{:xmpp, git: "https://github.com/processone/xmpp.git", ref: "d39576cf1e1545f1860966b36a659f26a9df9c1a", override: true},
{:xmpp, git: "https://github.com/processone/xmpp.git", ref: "add2a3dd773afa2dcf5cd5db66fb6ad90669a9d9", override: true},
{:yconf, "~> 1.0"}]
++ cond_deps()
end

View File

@ -77,7 +77,7 @@
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.29"}}},
{if_var_true, stun,
{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.2.10"}}}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "d39576cf1e1545f1860966b36a659f26a9df9c1a"}},
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "add2a3dd773afa2dcf5cd5db66fb6ad90669a9d9"}},
{yconf, ".*", {git, "https://github.com/processone/yconf", {tag, "1.0.15"}}}
]}.

View File

@ -42,7 +42,8 @@
handle_auth_success/4, handle_auth_failure/4, handle_send/3,
handle_recv/3, handle_cdata/2, handle_unbinded_packet/2,
inline_stream_features/1, handle_sasl2_inline/2,
handle_sasl2_inline_post/3, handle_bind2_inline/2]).
handle_sasl2_inline_post/3, handle_bind2_inline/2,
handle_bind2_inline_post/3]).
%% Hooks
-export([handle_unexpected_cast/2, handle_unexpected_call/3,
process_auth_result/3, reject_unauthenticated_packet/2,
@ -548,7 +549,11 @@ handle_sasl2_inline_post(Els, Results, #{lserver := LServer} = State) ->
handle_bind2_inline(Els, #{lserver := LServer} = State) ->
ejabberd_hooks:run_fold(c2s_handle_bind2_inline, LServer,
State, [Els]).
{State, Els, []}, []).
handle_bind2_inline_post(Els, Results, #{lserver := LServer} = State) ->
ejabberd_hooks:run_fold(c2s_handle_bind2_inline_post, LServer,
State, [Els, Results]).
handle_recv(El, Pkt, #{lserver := LServer} = State) ->
ejabberd_hooks:run_fold(c2s_handle_recv, LServer, State, [El, Pkt]).

View File

@ -62,7 +62,7 @@
webadmin_page/3,
webadmin_user/4,
webadmin_user_parse_query/5,
c2s_handle_bind2_inline/2]).
c2s_handle_bind2_inline/1]).
-export([mod_opt_type/1, mod_options/1, mod_doc/0, depends/2]).
@ -299,9 +299,9 @@ c2s_copy_session(State, #{resend_offline := Flag}) ->
c2s_copy_session(State, _) ->
State.
c2s_handle_bind2_inline(#{jid := #jid{luser = LUser, lserver = LServer}} = State, _Els) ->
c2s_handle_bind2_inline({#{jid := #jid{luser = LUser, lserver = LServer}} = State, Els, Results}) ->
delete_all_msgs(LUser, LServer),
State.
{State, Els, Results}.
-spec handle_offline_query(iq()) -> iq().
handle_offline_query(#iq{from = #jid{luser = U1, lserver = S1},

View File

@ -35,7 +35,7 @@
c2s_handle_send/3, c2s_handle_info/2, c2s_handle_call/3,
c2s_handle_recv/3, c2s_inline_features/2,
c2s_handle_sasl2_inline/1, c2s_handle_sasl2_inline_post/3,
c2s_handle_bind2_inline/2]).
c2s_handle_bind2_inline/1]).
%% adjust pending session timeout / access queue
-export([get_resume_timeout/1, set_resume_timeout/2, queue_find/2]).
@ -125,7 +125,7 @@ c2s_inline_features({Sasl, Bind} = Acc, Host) ->
case gen_mod:is_loaded(Host, ?MODULE) of
true ->
{[#feature_sm{xmlns = ?NS_STREAM_MGMT_3} | Sasl],
[#feature_sm{xmlns = ?NS_STREAM_MGMT_3} | Bind]};
[#bind2_feature{var = ?NS_STREAM_MGMT_3} | Bind]};
false ->
Acc
end.
@ -152,12 +152,13 @@ c2s_handle_sasl2_inline_post(State, _Els, Results) ->
post_resume_tasks(State)
end.
c2s_handle_bind2_inline(State, Els) ->
c2s_handle_bind2_inline({State, Els, Results}) ->
case lists:keyfind(sm_enable, 1, Els) of
#sm_enable{} = Pkt ->
negotiate_stream_mgmt(Pkt, State);
#sm_enable{xmlns = XMLNS} = Pkt ->
{State2, Res} = handle_enable_int(State#{mgmt_xmlns => XMLNS}, Pkt),
{State2, Els, [Res | Results]};
_ ->
State
{State, Els, Results}
end.
c2s_unauthenticated_packet(#{lang := Lang} = State, Pkt) when ?is_sm_packet(Pkt) ->
@ -400,28 +401,28 @@ perform_stream_mgmt(Pkt, #{mgmt_xmlns := Xmlns, lang := Lang} = State) ->
xmlns = Xmlns})
end.
-spec handle_enable(state(), sm_enable()) -> state().
handle_enable(#{mgmt_timeout := DefaultTimeout,
mgmt_queue_type := QueueType,
mgmt_max_timeout := MaxTimeout,
mgmt_xmlns := Xmlns, jid := JID} = State,
#sm_enable{resume = Resume, max = Max}) ->
-spec handle_enable_int(state(), sm_enable()) -> {state(), sm_enabled()}.
handle_enable_int(#{mgmt_timeout := DefaultTimeout,
mgmt_queue_type := QueueType,
mgmt_max_timeout := MaxTimeout,
mgmt_xmlns := Xmlns, jid := JID} = State,
#sm_enable{resume = Resume, max = Max}) ->
State1 = State#{mgmt_id => make_id()},
Timeout = if Resume == false ->
0;
Max /= undefined, Max > 0, Max*1000 =< MaxTimeout ->
0;
Max /= undefined, Max > 0, Max*1000 =< MaxTimeout ->
Max*1000;
true ->
true ->
DefaultTimeout
end,
Res = if Timeout > 0 ->
?DEBUG("Stream management with resumption enabled for ~ts",
[jid:encode(JID)]),
#sm_enabled{xmlns = Xmlns,
id = encode_id(State1),
resume = true,
max = Timeout div 1000};
true ->
?DEBUG("Stream management with resumption enabled for ~ts",
[jid:encode(JID)]),
#sm_enabled{xmlns = Xmlns,
id = encode_id(State1),
resume = true,
max = Timeout div 1000};
true ->
?DEBUG("Stream management without resumption enabled for ~ts",
[jid:encode(JID)]),
#sm_enabled{xmlns = Xmlns}
@ -429,6 +430,11 @@ handle_enable(#{mgmt_timeout := DefaultTimeout,
State2 = State1#{mgmt_state => active,
mgmt_queue => p1_queue:new(QueueType),
mgmt_timeout => Timeout},
{State2, Res}.
-spec handle_enable(state(), sm_enable()) -> state().
handle_enable(State, Enable) ->
{State2, Res} = handle_enable_int(State, Enable),
send(State2, Res).
-spec handle_r(state()) -> state().