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

mod_mix, mod_mix_pam: Add handling of IQs with newer MIX namespaces

Supported are mix:core:{0,1} and mix:pam:{0,2}
This commit is contained in:
Jonah Brüchert 2022-06-26 17:25:22 +02:00 committed by badlop
parent d6b72f1c5d
commit 648245e974
3 changed files with 28 additions and 20 deletions

View File

@ -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, "~> 1.5"}, {:xmpp, git: "https://github.com/processone/xmpp.git", ref: "cdda2bea2df0b4ed40fbd854f6f1bf21c6b7a8c5", override: true},
{:yconf, "~> 1.0"}] {:yconf, "~> 1.0"}]
++ cond_deps() ++ cond_deps()
end end

View File

@ -350,7 +350,7 @@ format_status(_Opt, Status) ->
%%%=================================================================== %%%===================================================================
-spec process_mix_create(iq()) -> iq(). -spec process_mix_create(iq()) -> iq().
process_mix_create(#iq{to = To, from = From, process_mix_create(#iq{to = To, from = From,
sub_els = [#mix_create{channel = Chan}]} = IQ) -> sub_els = [#mix_create{channel = Chan, xmlns = XmlNs}]} = IQ) ->
Host = To#jid.lserver, Host = To#jid.lserver,
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
Mod = gen_mod:db_mod(ServerHost, ?MODULE), Mod = gen_mod:db_mod(ServerHost, ?MODULE),
@ -374,7 +374,7 @@ process_mix_create(#iq{to = To, from = From,
end, end,
case Ret of case Ret of
ok -> ok ->
xmpp:make_iq_result(IQ, #mix_create{channel = Chan1}); xmpp:make_iq_result(IQ, #mix_create{channel = Chan1, xmlns = XmlNs});
{error, conflict} -> {error, conflict} ->
xmpp:make_error(IQ, channel_exists_error(IQ)); xmpp:make_error(IQ, channel_exists_error(IQ));
{error, db_failure} -> {error, db_failure} ->
@ -384,7 +384,7 @@ process_mix_create(#iq{to = To, from = From,
-spec process_mix_destroy(iq()) -> iq(). -spec process_mix_destroy(iq()) -> iq().
process_mix_destroy(#iq{to = To, process_mix_destroy(#iq{to = To,
from = #jid{luser = U, lserver = S}, from = #jid{luser = U, lserver = S},
sub_els = [#mix_destroy{channel = Chan}]} = IQ) -> sub_els = [#mix_destroy{channel = Chan, xmlns = XmlNs}]} = IQ) ->
Host = To#jid.lserver, Host = To#jid.lserver,
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
Mod = gen_mod:db_mod(ServerHost, ?MODULE), Mod = gen_mod:db_mod(ServerHost, ?MODULE),
@ -392,7 +392,7 @@ process_mix_destroy(#iq{to = To,
{ok, {#jid{luser = U, lserver = S}, _, _}} -> {ok, {#jid{luser = U, lserver = S}, _, _}} ->
case Mod:del_channel(ServerHost, Chan, Host) of case Mod:del_channel(ServerHost, Chan, Host) of
ok -> ok ->
xmpp:make_iq_result(IQ, #mix_destroy{channel = Chan}); xmpp:make_iq_result(IQ, #mix_destroy{channel = Chan, xmlns = XmlNs});
{error, db_failure} -> {error, db_failure} ->
xmpp:make_error(IQ, db_error(IQ)) xmpp:make_error(IQ, db_error(IQ))
end; end;
@ -406,7 +406,7 @@ process_mix_destroy(#iq{to = To,
-spec process_mix_join(iq()) -> iq(). -spec process_mix_join(iq()) -> iq().
process_mix_join(#iq{to = To, from = From, process_mix_join(#iq{to = To, from = From,
sub_els = [#mix_join{} = JoinReq]} = IQ) -> sub_els = [#mix_join{xmlns = XmlNs} = JoinReq]} = IQ) ->
Chan = To#jid.luser, Chan = To#jid.luser,
Host = To#jid.lserver, Host = To#jid.lserver,
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
@ -423,7 +423,8 @@ process_mix_join(#iq{to = To, from = From,
notify_participant_joined(Mod, ServerHost, To, From, ID, Nick), notify_participant_joined(Mod, ServerHost, To, From, ID, Nick),
xmpp:make_iq_result(IQ, #mix_join{id = ID, xmpp:make_iq_result(IQ, #mix_join{id = ID,
subscribe = Nodes, subscribe = Nodes,
nick = Nick}) nick = Nick,
xmlns = XmlNs})
catch _:{badmatch, {error, db_failure}} -> catch _:{badmatch, {error, db_failure}} ->
xmpp:make_error(IQ, db_error(IQ)) xmpp:make_error(IQ, db_error(IQ))
end; end;
@ -435,7 +436,7 @@ process_mix_join(#iq{to = To, from = From,
-spec process_mix_leave(iq()) -> iq(). -spec process_mix_leave(iq()) -> iq().
process_mix_leave(#iq{to = To, from = From, process_mix_leave(#iq{to = To, from = From,
sub_els = [#mix_leave{}]} = IQ) -> sub_els = [#mix_leave{xmlns = XmlNs}]} = IQ) ->
{Chan, Host, _} = jid:tolower(To), {Chan, Host, _} = jid:tolower(To),
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
Mod = gen_mod:db_mod(ServerHost, ?MODULE), Mod = gen_mod:db_mod(ServerHost, ?MODULE),
@ -453,7 +454,7 @@ process_mix_leave(#iq{to = To, from = From,
xmpp:make_error(IQ, db_error(IQ)) xmpp:make_error(IQ, db_error(IQ))
end; end;
{error, notfound} -> {error, notfound} ->
xmpp:make_iq_result(IQ, #mix_leave{}); xmpp:make_iq_result(IQ, #mix_leave{xmlns = XmlNs});
{error, db_failure} -> {error, db_failure} ->
xmpp:make_error(IQ, db_error(IQ)) xmpp:make_error(IQ, db_error(IQ))
end; end;
@ -465,7 +466,7 @@ process_mix_leave(#iq{to = To, from = From,
-spec process_mix_setnick(iq()) -> iq(). -spec process_mix_setnick(iq()) -> iq().
process_mix_setnick(#iq{to = To, from = From, process_mix_setnick(#iq{to = To, from = From,
sub_els = [#mix_setnick{nick = Nick}]} = IQ) -> sub_els = [#mix_setnick{nick = Nick, xmlns = XmlNs}]} = IQ) ->
{Chan, Host, _} = jid:tolower(To), {Chan, Host, _} = jid:tolower(To),
ServerHost = ejabberd_router:host_of_route(Host), ServerHost = ejabberd_router:host_of_route(Host),
Mod = gen_mod:db_mod(ServerHost, ?MODULE), Mod = gen_mod:db_mod(ServerHost, ?MODULE),
@ -474,12 +475,12 @@ process_mix_setnick(#iq{to = To, from = From,
{ok, _} -> {ok, _} ->
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
{ok, {_, Nick}} -> {ok, {_, Nick}} ->
xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick}); xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick, xmlns = XmlNs});
{ok, {ID, _}} -> {ok, {ID, _}} ->
case Mod:set_participant(ServerHost, Chan, Host, BFrom, ID, Nick) of case Mod:set_participant(ServerHost, Chan, Host, BFrom, ID, Nick) of
ok -> ok ->
notify_participant_joined(Mod, ServerHost, To, From, ID, Nick), notify_participant_joined(Mod, ServerHost, To, From, ID, Nick),
xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick}); xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick, xmlns = XmlNs});
{error, db_failure} -> {error, db_failure} ->
xmpp:make_error(IQ, db_error(IQ)) xmpp:make_error(IQ, db_error(IQ))
end; end;
@ -688,12 +689,16 @@ register_iq_handlers(Host) ->
?MODULE, process_disco_items), ?MODULE, process_disco_items),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_0, gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_0,
?MODULE, process_mix_core), ?MODULE, process_mix_core),
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_1,
?MODULE, process_mix_core),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_DISCO_INFO, gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_DISCO_INFO,
?MODULE, process_disco_info), ?MODULE, process_disco_info),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_DISCO_ITEMS, gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_DISCO_ITEMS,
?MODULE, process_disco_items), ?MODULE, process_disco_items),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_0, gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_0,
?MODULE, process_mix_core), ?MODULE, process_mix_core),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_1,
?MODULE, process_mix_core),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PUBSUB, gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_PUBSUB,
?MODULE, process_pubsub_query), ?MODULE, process_pubsub_query),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_2, gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MAM_2,
@ -704,8 +709,10 @@ unregister_iq_handlers(Host) ->
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO), gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO),
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS), gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS),
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_0), gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_0),
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_1),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_DISCO_INFO), gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_DISCO_INFO),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_DISCO_ITEMS), gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_DISCO_ITEMS),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_0), gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_0),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_1),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PUBSUB), gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PUBSUB),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_2). gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_2).

View File

@ -70,8 +70,8 @@ start(Host, Opts) ->
ejabberd_hooks:add(roster_get, Host, ?MODULE, get_mix_roster_items, 50), ejabberd_hooks:add(roster_get, Host, ?MODULE, get_mix_roster_items, 50),
ejabberd_hooks:add(webadmin_user, Host, ?MODULE, webadmin_user, 50), ejabberd_hooks:add(webadmin_user, Host, ?MODULE, webadmin_user, 50),
ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, webadmin_page, 50), ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, webadmin_page, 50),
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0, gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0, ?MODULE, process_iq),
?MODULE, process_iq); gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_2, ?MODULE, process_iq);
Err -> Err ->
Err Err
end. end.
@ -83,7 +83,8 @@ stop(Host) ->
ejabberd_hooks:delete(roster_get, Host, ?MODULE, get_mix_roster_items, 50), ejabberd_hooks:delete(roster_get, Host, ?MODULE, get_mix_roster_items, 50),
ejabberd_hooks:delete(webadmin_user, Host, ?MODULE, webadmin_user, 50), ejabberd_hooks:delete(webadmin_user, Host, ?MODULE, webadmin_user, 50),
ejabberd_hooks:delete(webadmin_page_host, Host, ?MODULE, webadmin_page, 50), ejabberd_hooks:delete(webadmin_page_host, Host, ?MODULE, webadmin_page, 50),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0). gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0),
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_2).
reload(Host, NewOpts, OldOpts) -> reload(Host, NewOpts, OldOpts) ->
NewMod = gen_mod:db_mod(NewOpts, ?MODULE), NewMod = gen_mod:db_mod(NewOpts, ?MODULE),
@ -263,7 +264,7 @@ remove_user(LUser, LServer) ->
-spec process_join(iq()) -> ignore. -spec process_join(iq()) -> ignore.
process_join(#iq{from = From, process_join(#iq{from = From,
sub_els = [#mix_client_join{channel = Channel, sub_els = [#mix_client_join{channel = Channel,
join = Join}]} = IQ) -> join = Join}]} = IQ) ->
ejabberd_router:route_iq( ejabberd_router:route_iq(
#iq{from = jid:remove_resource(From), #iq{from = jid:remove_resource(From),
to = Channel, type = set, sub_els = [Join]}, to = Channel, type = set, sub_els = [Join]},
@ -287,7 +288,7 @@ process_leave(#iq{from = From,
-spec process_join_result(iq(), iq()) -> ok. -spec process_join_result(iq(), iq()) -> ok.
process_join_result(#iq{from = #jid{} = Channel, process_join_result(#iq{from = #jid{} = Channel,
type = result, sub_els = [#mix_join{id = ID} = Join]}, type = result, sub_els = [#mix_join{id = ID, xmlns = XmlNs} = Join]},
#iq{to = To} = IQ) -> #iq{to = To} = IQ) ->
case add_channel(To, Channel, ID) of case add_channel(To, Channel, ID) of
ok -> ok ->
@ -303,7 +304,7 @@ process_join_result(#iq{from = #jid{} = Channel,
% send IQ result % send IQ result
ChanID = make_channel_id(Channel, ID), ChanID = make_channel_id(Channel, ID),
Join1 = Join#mix_join{id = <<"">>, jid = ChanID}, Join1 = Join#mix_join{id = <<"">>, jid = ChanID},
ResIQ = xmpp:make_iq_result(IQ, #mix_client_join{join = Join1}), ResIQ = xmpp:make_iq_result(IQ, #mix_client_join{join = Join1, xmlns = XmlNs}),
ejabberd_router:route(ResIQ); ejabberd_router:route(ResIQ);
{error, db_failure} -> {error, db_failure} ->
ejabberd_router:route_error(IQ, db_error(IQ)) ejabberd_router:route_error(IQ, db_error(IQ))
@ -312,14 +313,14 @@ process_join_result(Err, IQ) ->
process_iq_error(Err, IQ). process_iq_error(Err, IQ).
-spec process_leave_result(iq(), iq()) -> ok. -spec process_leave_result(iq(), iq()) -> ok.
process_leave_result(#iq{from = Channel, type = result, sub_els = [#mix_leave{} = Leave]}, process_leave_result(#iq{from = Channel, type = result, sub_els = [#mix_leave{xmlns = XmlNs} = Leave]},
#iq{to = User} = IQ) -> #iq{to = User} = IQ) ->
% Do roster push % Do roster push
mod_roster:push_item(User, mod_roster:push_item(User,
#roster_item{jid = Channel, subscription = none}, #roster_item{jid = Channel, subscription = none},
#roster_item{jid = Channel, subscription = remove}), #roster_item{jid = Channel, subscription = remove}),
% send iq result % send iq result
ResIQ = xmpp:make_iq_result(IQ, #mix_client_leave{leave = Leave}), ResIQ = xmpp:make_iq_result(IQ, #mix_client_leave{leave = Leave, xmlns = XmlNs}),
ejabberd_router:route(ResIQ); ejabberd_router:route(ResIQ);
process_leave_result(Err, IQ) -> process_leave_result(Err, IQ) ->
process_iq_error(Err, IQ). process_iq_error(Err, IQ).