mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-24 17:29:28 +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:
parent
d6b72f1c5d
commit
648245e974
2
mix.exs
2
mix.exs
@ -114,7 +114,7 @@ defmodule Ejabberd.MixProject do
|
||||
{:p1_utils, "~> 1.0"},
|
||||
{:pkix, "~> 1.0"},
|
||||
{:stringprep, ">= 1.0.26"},
|
||||
{:xmpp, "~> 1.5"},
|
||||
{:xmpp, git: "https://github.com/processone/xmpp.git", ref: "cdda2bea2df0b4ed40fbd854f6f1bf21c6b7a8c5", override: true},
|
||||
{:yconf, "~> 1.0"}]
|
||||
++ cond_deps()
|
||||
end
|
||||
|
@ -350,7 +350,7 @@ format_status(_Opt, Status) ->
|
||||
%%%===================================================================
|
||||
-spec process_mix_create(iq()) -> iq().
|
||||
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,
|
||||
ServerHost = ejabberd_router:host_of_route(Host),
|
||||
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
||||
@ -374,7 +374,7 @@ process_mix_create(#iq{to = To, from = From,
|
||||
end,
|
||||
case Ret of
|
||||
ok ->
|
||||
xmpp:make_iq_result(IQ, #mix_create{channel = Chan1});
|
||||
xmpp:make_iq_result(IQ, #mix_create{channel = Chan1, xmlns = XmlNs});
|
||||
{error, conflict} ->
|
||||
xmpp:make_error(IQ, channel_exists_error(IQ));
|
||||
{error, db_failure} ->
|
||||
@ -384,7 +384,7 @@ process_mix_create(#iq{to = To, from = From,
|
||||
-spec process_mix_destroy(iq()) -> iq().
|
||||
process_mix_destroy(#iq{to = To,
|
||||
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,
|
||||
ServerHost = ejabberd_router:host_of_route(Host),
|
||||
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
||||
@ -392,7 +392,7 @@ process_mix_destroy(#iq{to = To,
|
||||
{ok, {#jid{luser = U, lserver = S}, _, _}} ->
|
||||
case Mod:del_channel(ServerHost, Chan, Host) of
|
||||
ok ->
|
||||
xmpp:make_iq_result(IQ, #mix_destroy{channel = Chan});
|
||||
xmpp:make_iq_result(IQ, #mix_destroy{channel = Chan, xmlns = XmlNs});
|
||||
{error, db_failure} ->
|
||||
xmpp:make_error(IQ, db_error(IQ))
|
||||
end;
|
||||
@ -406,7 +406,7 @@ process_mix_destroy(#iq{to = To,
|
||||
|
||||
-spec process_mix_join(iq()) -> iq().
|
||||
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,
|
||||
Host = To#jid.lserver,
|
||||
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),
|
||||
xmpp:make_iq_result(IQ, #mix_join{id = ID,
|
||||
subscribe = Nodes,
|
||||
nick = Nick})
|
||||
nick = Nick,
|
||||
xmlns = XmlNs})
|
||||
catch _:{badmatch, {error, db_failure}} ->
|
||||
xmpp:make_error(IQ, db_error(IQ))
|
||||
end;
|
||||
@ -435,7 +436,7 @@ process_mix_join(#iq{to = To, from = From,
|
||||
|
||||
-spec process_mix_leave(iq()) -> iq().
|
||||
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),
|
||||
ServerHost = ejabberd_router:host_of_route(Host),
|
||||
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))
|
||||
end;
|
||||
{error, notfound} ->
|
||||
xmpp:make_iq_result(IQ, #mix_leave{});
|
||||
xmpp:make_iq_result(IQ, #mix_leave{xmlns = XmlNs});
|
||||
{error, db_failure} ->
|
||||
xmpp:make_error(IQ, db_error(IQ))
|
||||
end;
|
||||
@ -465,7 +466,7 @@ process_mix_leave(#iq{to = To, from = From,
|
||||
|
||||
-spec process_mix_setnick(iq()) -> iq().
|
||||
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),
|
||||
ServerHost = ejabberd_router:host_of_route(Host),
|
||||
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
||||
@ -474,12 +475,12 @@ process_mix_setnick(#iq{to = To, from = From,
|
||||
{ok, _} ->
|
||||
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
||||
{ok, {_, Nick}} ->
|
||||
xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick});
|
||||
xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick, xmlns = XmlNs});
|
||||
{ok, {ID, _}} ->
|
||||
case Mod:set_participant(ServerHost, Chan, Host, BFrom, ID, Nick) of
|
||||
ok ->
|
||||
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} ->
|
||||
xmpp:make_error(IQ, db_error(IQ))
|
||||
end;
|
||||
@ -688,12 +689,16 @@ register_iq_handlers(Host) ->
|
||||
?MODULE, process_disco_items),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_0,
|
||||
?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,
|
||||
?MODULE, process_disco_info),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_DISCO_ITEMS,
|
||||
?MODULE, process_disco_items),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_0,
|
||||
?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,
|
||||
?MODULE, process_pubsub_query),
|
||||
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_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_1),
|
||||
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_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_MAM_2).
|
||||
|
@ -70,8 +70,8 @@ start(Host, Opts) ->
|
||||
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_page_host, Host, ?MODULE, webadmin_page, 50),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0,
|
||||
?MODULE, process_iq);
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_0, ?MODULE, process_iq),
|
||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_PAM_2, ?MODULE, process_iq);
|
||||
Err ->
|
||||
Err
|
||||
end.
|
||||
@ -83,7 +83,8 @@ stop(Host) ->
|
||||
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_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) ->
|
||||
NewMod = gen_mod:db_mod(NewOpts, ?MODULE),
|
||||
@ -263,7 +264,7 @@ remove_user(LUser, LServer) ->
|
||||
-spec process_join(iq()) -> ignore.
|
||||
process_join(#iq{from = From,
|
||||
sub_els = [#mix_client_join{channel = Channel,
|
||||
join = Join}]} = IQ) ->
|
||||
join = Join}]} = IQ) ->
|
||||
ejabberd_router:route_iq(
|
||||
#iq{from = jid:remove_resource(From),
|
||||
to = Channel, type = set, sub_els = [Join]},
|
||||
@ -287,7 +288,7 @@ process_leave(#iq{from = From,
|
||||
|
||||
-spec process_join_result(iq(), iq()) -> ok.
|
||||
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) ->
|
||||
case add_channel(To, Channel, ID) of
|
||||
ok ->
|
||||
@ -303,7 +304,7 @@ process_join_result(#iq{from = #jid{} = Channel,
|
||||
% send IQ result
|
||||
ChanID = make_channel_id(Channel, ID),
|
||||
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);
|
||||
{error, db_failure} ->
|
||||
ejabberd_router:route_error(IQ, db_error(IQ))
|
||||
@ -312,14 +313,14 @@ process_join_result(Err, IQ) ->
|
||||
process_iq_error(Err, IQ).
|
||||
|
||||
-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) ->
|
||||
% Do roster push
|
||||
mod_roster:push_item(User,
|
||||
#roster_item{jid = Channel, subscription = none},
|
||||
#roster_item{jid = Channel, subscription = remove}),
|
||||
% 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);
|
||||
process_leave_result(Err, IQ) ->
|
||||
process_iq_error(Err, IQ).
|
||||
|
Loading…
Reference in New Issue
Block a user