mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Update xmpp and make opening bind2 session close other sessions with same tag
This commit is contained in:
parent
91e74204b2
commit
9c7e91a1e9
2
mix.exs
2
mix.exs
@ -114,7 +114,7 @@ defmodule Ejabberd.MixProject do
|
|||||||
{:p1_utils, "~> 1.0"},
|
{:p1_utils, "~> 1.0"},
|
||||||
{:pkix, "~> 1.0"},
|
{:pkix, "~> 1.0"},
|
||||||
{:stringprep, ">= 1.0.26"},
|
{:stringprep, ">= 1.0.26"},
|
||||||
{:xmpp, git: "https://github.com/processone/xmpp.git", ref: "add2a3dd773afa2dcf5cd5db66fb6ad90669a9d9", override: true},
|
{:xmpp, git: "https://github.com/processone/xmpp.git", ref: "dcb701e6800d827f8806c0d049aaf103cd724e2b", override: true},
|
||||||
{:yconf, "~> 1.0"}]
|
{:yconf, "~> 1.0"}]
|
||||||
++ cond_deps()
|
++ cond_deps()
|
||||||
end
|
end
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.29"}}},
|
{stringprep, ".*", {git, "https://github.com/processone/stringprep", {tag, "1.0.29"}}},
|
||||||
{if_var_true, stun,
|
{if_var_true, stun,
|
||||||
{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.2.10"}}}},
|
{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.2.10"}}}},
|
||||||
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "add2a3dd773afa2dcf5cd5db66fb6ad90669a9d9"}},
|
{xmpp, ".*", {git, "https://github.com/processone/xmpp", "dcb701e6800d827f8806c0d049aaf103cd724e2b"}},
|
||||||
{yconf, ".*", {git, "https://github.com/processone/yconf", {tag, "1.0.15"}}}
|
{yconf, ".*", {git, "https://github.com/processone/yconf", {tag, "1.0.15"}}}
|
||||||
]}.
|
]}.
|
||||||
|
|
||||||
|
@ -215,7 +215,12 @@ open_session(#{user := U, server := S, resource := R,
|
|||||||
Pres -> get_priority_from_presence(Pres)
|
Pres -> get_priority_from_presence(Pres)
|
||||||
end,
|
end,
|
||||||
Info = [{ip, IP}, {conn, Conn}, {auth_module, AuthModule}],
|
Info = [{ip, IP}, {conn, Conn}, {auth_module, AuthModule}],
|
||||||
ejabberd_sm:open_session(SID, U, S, R, Prio, Info),
|
case State of
|
||||||
|
#{bind2_tag := Tag} ->
|
||||||
|
ejabberd_sm:open_session(SID, U, S, R, Prio, Info, Tag);
|
||||||
|
_ ->
|
||||||
|
ejabberd_sm:open_session(SID, U, S, R, Prio, Info)
|
||||||
|
end,
|
||||||
xmpp_stream_in:establish(State2).
|
xmpp_stream_in:establish(State2).
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
route/2,
|
route/2,
|
||||||
open_session/5,
|
open_session/5,
|
||||||
open_session/6,
|
open_session/6,
|
||||||
|
open_session/7,
|
||||||
close_session/4,
|
close_session/4,
|
||||||
check_in_subscription/2,
|
check_in_subscription/2,
|
||||||
bounce_offline_message/1,
|
bounce_offline_message/1,
|
||||||
@ -147,15 +148,21 @@ route(Packet) ->
|
|||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec open_session(sid(), binary(), binary(), binary(), prio(), info()) -> ok.
|
|
||||||
|
|
||||||
open_session(SID, User, Server, Resource, Priority, Info) ->
|
-spec open_session(sid(), binary(), binary(), binary(), prio(), info(), binary() | undefined) -> ok.
|
||||||
|
|
||||||
|
open_session(SID, User, Server, Resource, Priority, Info, Bind2Tag) ->
|
||||||
set_session(SID, User, Server, Resource, Priority, Info),
|
set_session(SID, User, Server, Resource, Priority, Info),
|
||||||
check_for_sessions_to_replace(User, Server, Resource),
|
check_for_sessions_to_replace(User, Server, Resource, Bind2Tag),
|
||||||
JID = jid:make(User, Server, Resource),
|
JID = jid:make(User, Server, Resource),
|
||||||
ejabberd_hooks:run(sm_register_connection_hook,
|
ejabberd_hooks:run(sm_register_connection_hook,
|
||||||
JID#jid.lserver, [SID, JID, Info]).
|
JID#jid.lserver, [SID, JID, Info]).
|
||||||
|
|
||||||
|
-spec open_session(sid(), binary(), binary(), binary(), prio(), info()) -> ok.
|
||||||
|
|
||||||
|
open_session(SID, User, Server, Resource, Priority, Info) ->
|
||||||
|
open_session(SID, User, Server, Resource, Priority, Info, undefined).
|
||||||
|
|
||||||
-spec open_session(sid(), binary(), binary(), binary(), info()) -> ok.
|
-spec open_session(sid(), binary(), binary(), binary(), info()) -> ok.
|
||||||
|
|
||||||
open_session(SID, User, Server, Resource, Info) ->
|
open_session(SID, User, Server, Resource, Info) ->
|
||||||
@ -452,6 +459,13 @@ c2s_handle_info(#{lang := Lang} = State, replaced) ->
|
|||||||
State1 = State#{replaced => true},
|
State1 = State#{replaced => true},
|
||||||
Err = xmpp:serr_conflict(?T("Replaced by new connection"), Lang),
|
Err = xmpp:serr_conflict(?T("Replaced by new connection"), Lang),
|
||||||
{stop, ejabberd_c2s:send(State1, Err)};
|
{stop, ejabberd_c2s:send(State1, Err)};
|
||||||
|
c2s_handle_info(#{lang := Lang, bind2_tag := Tag} = State,
|
||||||
|
{replaced_with_bind_tag, Bind2Tag}) when Tag == Bind2Tag ->
|
||||||
|
State1 = State#{replaced => true},
|
||||||
|
Err = xmpp:serr_conflict(?T("Replaced by new connection"), Lang),
|
||||||
|
{stop, ejabberd_c2s:send(State1, Err)};
|
||||||
|
c2s_handle_info(State, {replaced_with_bind_tag, _}) ->
|
||||||
|
State;
|
||||||
c2s_handle_info(#{lang := Lang} = State, kick) ->
|
c2s_handle_info(#{lang := Lang} = State, kick) ->
|
||||||
Err = xmpp:serr_policy_violation(?T("has been kicked"), Lang),
|
Err = xmpp:serr_policy_violation(?T("has been kicked"), Lang),
|
||||||
{stop, ejabberd_c2s:send(State, Err)};
|
{stop, ejabberd_c2s:send(State, Err)};
|
||||||
@ -826,16 +840,17 @@ clean_session_list([S1, S2 | Rest], Res) ->
|
|||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
%% On new session, check if some existing connections need to be replace
|
%% On new session, check if some existing connections need to be replace
|
||||||
-spec check_for_sessions_to_replace(binary(), binary(), binary()) -> ok | replaced.
|
-spec check_for_sessions_to_replace(binary(), binary(), binary(), binary() | undefined)
|
||||||
check_for_sessions_to_replace(User, Server, Resource) ->
|
-> ok | replaced.
|
||||||
|
check_for_sessions_to_replace(User, Server, Resource, Bind2Tag) ->
|
||||||
LUser = jid:nodeprep(User),
|
LUser = jid:nodeprep(User),
|
||||||
LServer = jid:nameprep(Server),
|
LServer = jid:nameprep(Server),
|
||||||
LResource = jid:resourceprep(Resource),
|
LResource = jid:resourceprep(Resource),
|
||||||
check_existing_resources(LUser, LServer, LResource),
|
check_existing_resources(LUser, LServer, LResource, Bind2Tag),
|
||||||
check_max_sessions(LUser, LServer).
|
check_max_sessions(LUser, LServer).
|
||||||
|
|
||||||
-spec check_existing_resources(binary(), binary(), binary()) -> ok.
|
-spec check_existing_resources(binary(), binary(), binary(), binary() | undefined) -> ok.
|
||||||
check_existing_resources(LUser, LServer, LResource) ->
|
check_existing_resources(LUser, LServer, LResource, undefined) ->
|
||||||
Mod = get_sm_backend(LServer),
|
Mod = get_sm_backend(LServer),
|
||||||
Ss = get_sessions(Mod, LUser, LServer, LResource),
|
Ss = get_sessions(Mod, LUser, LServer, LResource),
|
||||||
if Ss == [] -> ok;
|
if Ss == [] -> ok;
|
||||||
@ -847,7 +862,18 @@ check_existing_resources(LUser, LServer, LResource) ->
|
|||||||
(_) -> ok
|
(_) -> ok
|
||||||
end,
|
end,
|
||||||
SIDs)
|
SIDs)
|
||||||
end.
|
end;
|
||||||
|
check_existing_resources(LUser, LServer, _LResource, Bind2Tag) ->
|
||||||
|
Mod = get_sm_backend(LServer),
|
||||||
|
Ss = get_sessions(Mod, LUser, LServer),
|
||||||
|
Len = size(Bind2Tag),
|
||||||
|
lists:foreach(
|
||||||
|
fun(#session{sid = {_, Pid}, usr = {_, _, <<Tag:Len/binary, ".", _/binary>>}})
|
||||||
|
when Pid /= self(), Tag == Bind2Tag ->
|
||||||
|
ejabberd_c2s:route(Pid, {replaced_with_bind_tag, Bind2Tag});
|
||||||
|
(_) ->
|
||||||
|
ok
|
||||||
|
end, Ss).
|
||||||
|
|
||||||
-spec is_existing_resource(binary(), binary(), binary()) -> boolean().
|
-spec is_existing_resource(binary(), binary(), binary()) -> boolean().
|
||||||
|
|
||||||
|
@ -467,9 +467,9 @@ has_resume_data(#{lang := Lang} = State,
|
|||||||
{ok, InheritedState} ->
|
{ok, InheritedState} ->
|
||||||
State1 = check_h_attribute(InheritedState, H),
|
State1 = check_h_attribute(InheritedState, H),
|
||||||
#{mgmt_xmlns := AttrXmlns, mgmt_stanzas_in := AttrH} = State1,
|
#{mgmt_xmlns := AttrXmlns, mgmt_stanzas_in := AttrH} = State1,
|
||||||
{ok, InheritedState, #sm_resumed{xmlns = AttrXmlns,
|
{ok, State1, #sm_resumed{xmlns = AttrXmlns,
|
||||||
h = AttrH,
|
h = AttrH,
|
||||||
previd = PrevID}};
|
previd = PrevID}};
|
||||||
{error, Err, InH} ->
|
{error, Err, InH} ->
|
||||||
{error, #sm_failed{reason = 'item-not-found',
|
{error, #sm_failed{reason = 'item-not-found',
|
||||||
text = xmpp:mk_text(format_error(Err), Lang),
|
text = xmpp:mk_text(format_error(Err), Lang),
|
||||||
|
Loading…
Reference in New Issue
Block a user