2016-03-08 18:04:29 +01:00
|
|
|
%%%-------------------------------------------------------------------
|
2016-12-27 10:44:07 +01:00
|
|
|
%%% File : mod_mix.erl
|
|
|
|
%%% Author : Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2016-03-08 18:04:29 +01:00
|
|
|
%%% Created : 2 Mar 2016 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
2016-12-27 10:44:07 +01:00
|
|
|
%%%
|
|
|
|
%%%
|
2018-01-05 21:18:58 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2018 ProcessOne
|
2016-12-27 10:44:07 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
%%%
|
|
|
|
%%%----------------------------------------------------------------------
|
2016-03-08 18:04:29 +01:00
|
|
|
-module(mod_mix).
|
|
|
|
-behaviour(gen_mod).
|
2018-12-05 11:14:29 +01:00
|
|
|
-behaviour(gen_server).
|
2022-11-07 12:32:38 +01:00
|
|
|
-protocol({xep, 369, '0.14.1', '16.03', "", ""}).
|
2016-03-08 18:04:29 +01:00
|
|
|
|
|
|
|
%% API
|
2018-12-05 11:14:29 +01:00
|
|
|
-export([route/1]).
|
|
|
|
%% gen_mod callbacks
|
|
|
|
-export([start/2, stop/1, reload/3, depends/2, mod_opt_type/1, mod_options/1]).
|
2020-01-08 10:24:51 +01:00
|
|
|
-export([mod_doc/0]).
|
2016-03-08 18:04:29 +01:00
|
|
|
%% gen_server callbacks
|
|
|
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
2024-04-30 13:47:40 +02:00
|
|
|
terminate/2, code_change/3]).
|
2018-12-05 11:14:29 +01:00
|
|
|
%% Hooks
|
|
|
|
-export([process_disco_info/1,
|
|
|
|
process_disco_items/1,
|
|
|
|
process_mix_core/1,
|
|
|
|
process_mam_query/1,
|
|
|
|
process_pubsub_query/1]).
|
2016-03-08 18:04:29 +01:00
|
|
|
|
2020-09-03 13:45:57 +02:00
|
|
|
-include_lib("xmpp/include/xmpp.hrl").
|
2018-12-05 11:14:29 +01:00
|
|
|
-include("logger.hrl").
|
|
|
|
-include("translate.hrl").
|
2019-07-06 11:30:57 +02:00
|
|
|
-include("ejabberd_stacktrace.hrl").
|
2018-12-05 11:14:29 +01:00
|
|
|
|
|
|
|
-callback init(binary(), gen_mod:opts()) -> ok | {error, db_failure}.
|
|
|
|
-callback set_channel(binary(), binary(), binary(),
|
2019-06-14 11:33:26 +02:00
|
|
|
jid:jid(), boolean(), binary()) ->
|
2018-12-05 11:14:29 +01:00
|
|
|
ok | {error, db_failure}.
|
|
|
|
-callback get_channels(binary(), binary()) ->
|
|
|
|
{ok, [binary()]} | {error, db_failure}.
|
|
|
|
-callback get_channel(binary(), binary(), binary()) ->
|
|
|
|
{ok, {jid(), boolean(), binary()}} |
|
|
|
|
{error, notfound | db_failure}.
|
|
|
|
-callback set_participant(binary(), binary(), binary(), jid(), binary(), binary()) ->
|
|
|
|
ok | {error, db_failure}.
|
|
|
|
-callback get_participant(binary(), binary(), binary(), jid()) ->
|
|
|
|
{ok, {binary(), binary()}} | {error, notfound | db_failure}.
|
|
|
|
|
|
|
|
-record(state, {hosts :: [binary()],
|
|
|
|
server_host :: binary()}).
|
2016-03-08 18:04:29 +01:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% API
|
|
|
|
%%%===================================================================
|
|
|
|
start(Host, Opts) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:start_child(?MODULE, Host, Opts).
|
2016-03-08 18:04:29 +01:00
|
|
|
|
|
|
|
stop(Host) ->
|
2017-02-14 10:39:26 +01:00
|
|
|
gen_mod:stop_child(?MODULE, Host).
|
2016-03-08 18:04:29 +01:00
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
reload(Host, NewOpts, OldOpts) ->
|
|
|
|
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
|
|
|
gen_server:cast(Proc, {reload, Host, NewOpts, OldOpts}).
|
|
|
|
|
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[{mod_mam, hard}].
|
|
|
|
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(access_create) ->
|
|
|
|
econf:acl();
|
|
|
|
mod_opt_type(name) ->
|
|
|
|
econf:binary();
|
|
|
|
mod_opt_type(host) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:host();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(hosts) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:hosts();
|
2019-06-14 11:33:26 +02:00
|
|
|
mod_opt_type(db_type) ->
|
2019-06-15 11:53:16 +02:00
|
|
|
econf:db_type(?MODULE).
|
2018-12-05 11:14:29 +01:00
|
|
|
|
|
|
|
mod_options(Host) ->
|
|
|
|
[{access_create, all},
|
2019-06-14 11:33:26 +02:00
|
|
|
{host, <<"mix.", Host/binary>>},
|
2018-12-05 11:14:29 +01:00
|
|
|
{hosts, []},
|
|
|
|
{name, ?T("Channels")},
|
|
|
|
{db_type, ejabberd_config:default_db(Host, ?MODULE)}].
|
|
|
|
|
2020-01-08 10:24:51 +01:00
|
|
|
mod_doc() ->
|
|
|
|
#{desc =>
|
|
|
|
[?T("This module is an experimental implementation of "
|
|
|
|
"https://xmpp.org/extensions/xep-0369.html"
|
|
|
|
"[XEP-0369: Mediated Information eXchange (MIX)]. "
|
2024-03-28 03:24:28 +01:00
|
|
|
"It's asserted that "
|
2020-01-08 10:24:51 +01:00
|
|
|
"the MIX protocol is going to replace the MUC protocol "
|
2021-08-21 18:31:21 +02:00
|
|
|
"in the future (see _`mod_muc`_)."), "",
|
2020-04-08 18:49:41 +02:00
|
|
|
?T("To learn more about how to use that feature, you can refer to "
|
2024-03-14 12:38:03 +01:00
|
|
|
"our tutorial: _`../../tutorials/mix-010.md|Getting started with MIX`_"), "",
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("The module depends on _`mod_mam`_.")],
|
2024-03-28 03:24:28 +01:00
|
|
|
note => "added in 16.03 and improved in 19.02",
|
2020-01-08 10:24:51 +01:00
|
|
|
opts =>
|
|
|
|
[{access_create,
|
|
|
|
#{value => ?T("AccessName"),
|
|
|
|
desc =>
|
|
|
|
?T("An access rule to control MIX channels creations. "
|
|
|
|
"The default value is 'all'.")}},
|
|
|
|
{host,
|
|
|
|
#{desc => ?T("Deprecated. Use 'hosts' instead.")}},
|
|
|
|
{hosts,
|
|
|
|
#{value => ?T("[Host, ...]"),
|
|
|
|
desc =>
|
|
|
|
?T("This option defines the Jabber IDs of the service. "
|
|
|
|
"If the 'hosts' option is not specified, the only Jabber ID will "
|
|
|
|
"be the hostname of the virtual host with the prefix \"mix.\". "
|
|
|
|
"The keyword '@HOST@' is replaced with the real virtual host name.")}},
|
|
|
|
{name,
|
|
|
|
#{value => ?T("Name"),
|
|
|
|
desc =>
|
|
|
|
?T("A name of the service in the Service Discovery. "
|
|
|
|
"This will only be displayed by special XMPP clients. "
|
|
|
|
"The default value is 'Channels'.")}},
|
|
|
|
{db_type,
|
|
|
|
#{value => "mnesia | sql",
|
|
|
|
desc =>
|
2021-08-21 18:31:21 +02:00
|
|
|
?T("Same as top-level _`default_db`_ option, but applied to this module only.")}}]}.
|
2020-01-08 10:24:51 +01:00
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
-spec route(stanza()) -> ok.
|
|
|
|
route(#iq{} = IQ) ->
|
|
|
|
ejabberd_router:process_iq(IQ);
|
|
|
|
route(#message{type = groupchat, id = ID, lang = Lang,
|
|
|
|
to = #jid{luser = <<_, _/binary>>}} = Msg) ->
|
|
|
|
case ID of
|
|
|
|
<<>> ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Attribute 'id' is mandatory for MIX messages"),
|
2018-12-05 11:14:29 +01:00
|
|
|
Err = xmpp:err_bad_request(Txt, Lang),
|
|
|
|
ejabberd_router:route_error(Msg, Err);
|
|
|
|
_ ->
|
|
|
|
process_mix_message(Msg)
|
2016-03-08 18:04:29 +01:00
|
|
|
end;
|
2018-12-05 11:14:29 +01:00
|
|
|
route(Pkt) ->
|
2019-09-23 14:17:20 +02:00
|
|
|
?DEBUG("Dropping packet:~n~ts", [xmpp:pp(Pkt)]).
|
2018-12-05 11:14:29 +01:00
|
|
|
|
|
|
|
-spec process_disco_info(iq()) -> iq().
|
|
|
|
process_disco_info(#iq{type = set, lang = Lang} = IQ) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_disco_info(#iq{type = get, to = #jid{luser = <<>>} = To,
|
|
|
|
from = _From, lang = Lang,
|
|
|
|
sub_els = [#disco_info{node = <<>>}]} = IQ) ->
|
|
|
|
ServerHost = ejabberd_router:host_of_route(To#jid.lserver),
|
|
|
|
X = ejabberd_hooks:run_fold(disco_info, ServerHost, [],
|
|
|
|
[ServerHost, ?MODULE, <<"">>, Lang]),
|
2019-06-14 11:33:26 +02:00
|
|
|
Name = mod_mix_opt:name(ServerHost),
|
2018-12-05 11:14:29 +01:00
|
|
|
Identity = #identity{category = <<"conference">>,
|
2021-06-27 00:50:50 +02:00
|
|
|
type = <<"mix">>,
|
2018-12-05 11:14:29 +01:00
|
|
|
name = translate:translate(Lang, Name)},
|
2022-07-10 21:00:09 +02:00
|
|
|
Features = [?NS_DISCO_INFO, ?NS_DISCO_ITEMS, ?NS_MIX_CORE_0,
|
|
|
|
?NS_MIX_CORE_SEARCHABLE_0, ?NS_MIX_CORE_CREATE_CHANNEL_0,
|
|
|
|
?NS_MIX_CORE_1, ?NS_MIX_CORE_SEARCHABLE_1,
|
|
|
|
?NS_MIX_CORE_CREATE_CHANNEL_1],
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:make_iq_result(
|
|
|
|
IQ, #disco_info{features = Features,
|
|
|
|
identities = [Identity],
|
|
|
|
xdata = X});
|
|
|
|
process_disco_info(#iq{type = get, to = #jid{luser = <<_, _/binary>>} = To,
|
2018-12-07 09:06:26 +01:00
|
|
|
sub_els = [#disco_info{node = Node}]} = IQ)
|
|
|
|
when Node == <<"mix">>; Node == <<>> ->
|
2018-12-05 11:14:29 +01:00
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, _} ->
|
|
|
|
Identity = #identity{category = <<"conference">>,
|
|
|
|
type = <<"mix">>},
|
|
|
|
Features = [?NS_DISCO_INFO, ?NS_DISCO_ITEMS,
|
2022-07-10 21:00:09 +02:00
|
|
|
?NS_MIX_CORE_0, ?NS_MIX_CORE_1, ?NS_MAM_2],
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:make_iq_result(
|
2018-12-07 09:06:26 +01:00
|
|
|
IQ, #disco_info{node = Node,
|
2018-12-05 11:14:29 +01:00
|
|
|
features = Features,
|
|
|
|
identities = [Identity]});
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
process_disco_info(#iq{type = get, sub_els = [#disco_info{node = Node}]} = IQ) ->
|
|
|
|
xmpp:make_iq_result(IQ, #disco_info{node = Node, features = [?NS_DISCO_INFO]});
|
|
|
|
process_disco_info(IQ) ->
|
|
|
|
xmpp:make_error(IQ, unsupported_error(IQ)).
|
|
|
|
|
|
|
|
-spec process_disco_items(iq()) -> iq().
|
|
|
|
process_disco_items(#iq{type = set, lang = Lang} = IQ) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_disco_items(#iq{type = get, to = #jid{luser = <<>>} = To,
|
|
|
|
sub_els = [#disco_items{node = <<>>}]} = IQ) ->
|
|
|
|
Host = To#jid.lserver,
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channels(ServerHost, Host) of
|
|
|
|
{ok, Channels} ->
|
|
|
|
Items = [#disco_item{jid = jid:make(Channel, Host)}
|
|
|
|
|| Channel <- Channels],
|
|
|
|
xmpp:make_iq_result(IQ, #disco_items{items = Items});
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
process_disco_items(#iq{type = get, to = #jid{luser = <<_, _/binary>>} = To,
|
2018-12-07 09:06:26 +01:00
|
|
|
sub_els = [#disco_items{node = Node}]} = IQ)
|
|
|
|
when Node == <<"mix">>; Node == <<>> ->
|
2018-12-05 11:14:29 +01:00
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, _} ->
|
|
|
|
BTo = jid:remove_resource(To),
|
2018-12-07 09:06:26 +01:00
|
|
|
Items = [#disco_item{jid = BTo, node = N} || N <- known_nodes()],
|
|
|
|
xmpp:make_iq_result(IQ, #disco_items{node = Node, items = Items});
|
2018-12-05 11:14:29 +01:00
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
process_disco_items(#iq{type = get, sub_els = [#disco_items{node = Node}]} = IQ) ->
|
|
|
|
xmpp:make_iq_result(IQ, #disco_items{node = Node});
|
|
|
|
process_disco_items(IQ) ->
|
|
|
|
xmpp:make_error(IQ, unsupported_error(IQ)).
|
|
|
|
|
|
|
|
-spec process_mix_core(iq()) -> iq().
|
|
|
|
process_mix_core(#iq{type = set, to = #jid{luser = <<>>},
|
|
|
|
sub_els = [#mix_create{}]} = IQ) ->
|
|
|
|
process_mix_create(IQ);
|
|
|
|
process_mix_core(#iq{type = set, to = #jid{luser = <<>>},
|
|
|
|
sub_els = [#mix_destroy{}]} = IQ) ->
|
|
|
|
process_mix_destroy(IQ);
|
|
|
|
process_mix_core(#iq{type = set, to = #jid{luser = <<_, _/binary>>},
|
|
|
|
sub_els = [#mix_join{}]} = IQ) ->
|
|
|
|
process_mix_join(IQ);
|
|
|
|
process_mix_core(#iq{type = set, to = #jid{luser = <<_, _/binary>>},
|
|
|
|
sub_els = [#mix_leave{}]} = IQ) ->
|
|
|
|
process_mix_leave(IQ);
|
|
|
|
process_mix_core(#iq{type = set, to = #jid{luser = <<_, _/binary>>},
|
|
|
|
sub_els = [#mix_setnick{}]} = IQ) ->
|
|
|
|
process_mix_setnick(IQ);
|
|
|
|
process_mix_core(IQ) ->
|
|
|
|
xmpp:make_error(IQ, unsupported_error(IQ)).
|
|
|
|
|
|
|
|
process_pubsub_query(#iq{type = get,
|
|
|
|
sub_els = [#pubsub{items = #ps_items{node = Node}}]} = IQ)
|
|
|
|
when Node == ?NS_MIX_NODES_PARTICIPANTS ->
|
|
|
|
process_participants_list(IQ);
|
|
|
|
process_pubsub_query(IQ) ->
|
|
|
|
xmpp:make_error(IQ, unsupported_error(IQ)).
|
|
|
|
|
|
|
|
process_mam_query(#iq{from = From, to = To, type = T,
|
|
|
|
sub_els = [#mam_query{}]} = IQ)
|
|
|
|
when T == get; T == set ->
|
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, _} ->
|
|
|
|
BFrom = jid:remove_resource(From),
|
|
|
|
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
|
|
|
{ok, _} ->
|
|
|
|
mod_mam:process_iq(ServerHost, IQ, mix);
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, not_joined_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
2016-03-08 18:04:29 +01:00
|
|
|
end;
|
2018-12-05 11:14:29 +01:00
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
2016-03-08 18:04:29 +01:00
|
|
|
end;
|
2018-12-05 11:14:29 +01:00
|
|
|
process_mam_query(IQ) ->
|
|
|
|
xmpp:make_error(IQ, unsupported_error(IQ)).
|
2016-03-08 18:04:29 +01:00
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% gen_server callbacks
|
|
|
|
%%%===================================================================
|
2019-08-04 20:46:18 +02:00
|
|
|
init([Host|_]) ->
|
2017-02-14 08:25:08 +01:00
|
|
|
process_flag(trap_exit, true),
|
2019-08-04 20:46:18 +02:00
|
|
|
Opts = gen_mod:get_module_opts(Host, ?MODULE),
|
2019-06-14 11:33:26 +02:00
|
|
|
Mod = gen_mod:db_mod(Opts, ?MODULE),
|
|
|
|
MyHosts = gen_mod:get_opt_hosts(Opts),
|
|
|
|
case Mod:init(Host, gen_mod:set_opt(hosts, MyHosts, Opts)) of
|
2018-12-05 11:14:29 +01:00
|
|
|
ok ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(MyHost) ->
|
|
|
|
ejabberd_router:register_route(
|
|
|
|
MyHost, Host, {apply, ?MODULE, route}),
|
|
|
|
register_iq_handlers(MyHost)
|
|
|
|
end, MyHosts),
|
|
|
|
{ok, #state{hosts = MyHosts, server_host = Host}};
|
|
|
|
{error, db_failure} ->
|
|
|
|
{stop, db_failure}
|
|
|
|
end.
|
|
|
|
|
2019-07-12 10:55:36 +02:00
|
|
|
handle_call(Request, From, State) ->
|
|
|
|
?WARNING_MSG("Unexpected call from ~p: ~p", [From, Request]),
|
2016-03-08 18:04:29 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
handle_cast(Request, State) ->
|
|
|
|
?WARNING_MSG("Unexpected cast: ~p", [Request]),
|
2016-03-08 18:04:29 +01:00
|
|
|
{noreply, State}.
|
|
|
|
|
2019-07-06 11:30:57 +02:00
|
|
|
handle_info({route, Packet}, State) ->
|
|
|
|
try route(Packet)
|
|
|
|
catch ?EX_RULE(Class, Reason, St) ->
|
|
|
|
StackTrace = ?EX_STACK(St),
|
2019-09-23 14:17:20 +02:00
|
|
|
?ERROR_MSG("Failed to route packet:~n~ts~n** ~ts",
|
2019-07-06 11:30:57 +02:00
|
|
|
[xmpp:pp(Packet),
|
|
|
|
misc:format_exception(2, Class, Reason, StackTrace)])
|
|
|
|
end,
|
|
|
|
{noreply, State};
|
2018-12-05 11:14:29 +01:00
|
|
|
handle_info(Info, State) ->
|
|
|
|
?WARNING_MSG("Unexpected info: ~p", [Info]),
|
|
|
|
{noreply, State}.
|
|
|
|
|
|
|
|
terminate(_Reason, State) ->
|
2017-08-08 16:46:26 +02:00
|
|
|
lists:foreach(
|
2018-12-05 11:14:29 +01:00
|
|
|
fun(MyHost) ->
|
|
|
|
unregister_iq_handlers(MyHost),
|
|
|
|
ejabberd_router:unregister_route(MyHost)
|
|
|
|
end, State#state.hosts).
|
2016-03-08 18:04:29 +01:00
|
|
|
|
|
|
|
code_change(_OldVsn, State, _Extra) ->
|
|
|
|
{ok, State}.
|
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% Internal functions
|
|
|
|
%%%===================================================================
|
2018-12-05 11:14:29 +01:00
|
|
|
-spec process_mix_create(iq()) -> iq().
|
|
|
|
process_mix_create(#iq{to = To, from = From,
|
2022-06-26 17:25:22 +02:00
|
|
|
sub_els = [#mix_create{channel = Chan, xmlns = XmlNs}]} = IQ) ->
|
2018-12-05 11:14:29 +01:00
|
|
|
Host = To#jid.lserver,
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
Creator = jid:remove_resource(From),
|
|
|
|
Chan1 = case Chan of
|
|
|
|
<<>> -> p1_rand:get_string();
|
|
|
|
_ -> Chan
|
|
|
|
end,
|
|
|
|
Ret = case Mod:get_channel(ServerHost, Chan1, Host) of
|
|
|
|
{ok, {#jid{luser = U, lserver = S}, _, _}} ->
|
|
|
|
case {From#jid.luser, From#jid.lserver} of
|
|
|
|
{U, S} -> ok;
|
|
|
|
_ -> {error, conflict}
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
Key = xmpp_util:hex(p1_rand:bytes(20)),
|
|
|
|
Mod:set_channel(ServerHost, Chan1, Host,
|
|
|
|
Creator, Chan == <<>>, Key);
|
|
|
|
{error, db_failure} = Err ->
|
|
|
|
Err
|
|
|
|
end,
|
|
|
|
case Ret of
|
|
|
|
ok ->
|
2022-06-26 17:25:22 +02:00
|
|
|
xmpp:make_iq_result(IQ, #mix_create{channel = Chan1, xmlns = XmlNs});
|
2018-12-05 11:14:29 +01:00
|
|
|
{error, conflict} ->
|
|
|
|
xmpp:make_error(IQ, channel_exists_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
2016-03-08 18:04:29 +01:00
|
|
|
end.
|
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
-spec process_mix_destroy(iq()) -> iq().
|
|
|
|
process_mix_destroy(#iq{to = To,
|
|
|
|
from = #jid{luser = U, lserver = S},
|
2022-06-26 17:25:22 +02:00
|
|
|
sub_els = [#mix_destroy{channel = Chan, xmlns = XmlNs}]} = IQ) ->
|
2018-12-05 11:14:29 +01:00
|
|
|
Host = To#jid.lserver,
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, {#jid{luser = U, lserver = S}, _, _}} ->
|
|
|
|
case Mod:del_channel(ServerHost, Chan, Host) of
|
|
|
|
ok ->
|
2022-06-26 17:25:22 +02:00
|
|
|
xmpp:make_iq_result(IQ, #mix_destroy{channel = Chan, xmlns = XmlNs});
|
2018-12-05 11:14:29 +01:00
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{ok, _} ->
|
|
|
|
xmpp:make_error(IQ, ownership_error(IQ));
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
2016-03-08 18:04:29 +01:00
|
|
|
end.
|
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
-spec process_mix_join(iq()) -> iq().
|
|
|
|
process_mix_join(#iq{to = To, from = From,
|
2022-06-26 17:25:22 +02:00
|
|
|
sub_els = [#mix_join{xmlns = XmlNs} = JoinReq]} = IQ) ->
|
2018-12-05 11:14:29 +01:00
|
|
|
Chan = To#jid.luser,
|
|
|
|
Host = To#jid.lserver,
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, {_, _, Key}} ->
|
|
|
|
ID = make_id(From, Key),
|
|
|
|
Nick = JoinReq#mix_join.nick,
|
|
|
|
BFrom = jid:remove_resource(From),
|
|
|
|
Nodes = filter_nodes(JoinReq#mix_join.subscribe),
|
|
|
|
try
|
|
|
|
ok = Mod:set_participant(ServerHost, Chan, Host, BFrom, ID, Nick),
|
|
|
|
ok = Mod:subscribe(ServerHost, Chan, Host, BFrom, Nodes),
|
|
|
|
notify_participant_joined(Mod, ServerHost, To, From, ID, Nick),
|
|
|
|
xmpp:make_iq_result(IQ, #mix_join{id = ID,
|
|
|
|
subscribe = Nodes,
|
2022-06-27 10:48:38 +02:00
|
|
|
jid = make_channel_id(To, ID),
|
2022-06-26 17:25:22 +02:00
|
|
|
nick = Nick,
|
|
|
|
xmlns = XmlNs})
|
2018-12-05 11:14:29 +01:00
|
|
|
catch _:{badmatch, {error, db_failure}} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end.
|
2016-03-08 18:04:29 +01:00
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
-spec process_mix_leave(iq()) -> iq().
|
|
|
|
process_mix_leave(#iq{to = To, from = From,
|
2022-06-26 17:25:22 +02:00
|
|
|
sub_els = [#mix_leave{xmlns = XmlNs}]} = IQ) ->
|
2018-12-05 11:14:29 +01:00
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
BFrom = jid:remove_resource(From),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, _} ->
|
|
|
|
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
|
|
|
{ok, {ID, _}} ->
|
|
|
|
try
|
|
|
|
ok = Mod:unsubscribe(ServerHost, Chan, Host, BFrom),
|
|
|
|
ok = Mod:del_participant(ServerHost, Chan, Host, BFrom),
|
|
|
|
notify_participant_left(Mod, ServerHost, To, ID),
|
|
|
|
xmpp:make_iq_result(IQ, #mix_leave{})
|
|
|
|
catch _:{badmatch, {error, db_failure}} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
2022-06-26 17:25:22 +02:00
|
|
|
xmpp:make_iq_result(IQ, #mix_leave{xmlns = XmlNs});
|
2018-12-05 11:14:29 +01:00
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_iq_result(IQ, #mix_leave{});
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end.
|
2016-03-09 09:19:15 +01:00
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
-spec process_mix_setnick(iq()) -> iq().
|
|
|
|
process_mix_setnick(#iq{to = To, from = From,
|
2022-06-26 17:25:22 +02:00
|
|
|
sub_els = [#mix_setnick{nick = Nick, xmlns = XmlNs}]} = IQ) ->
|
2018-12-05 11:14:29 +01:00
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
BFrom = jid:remove_resource(From),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, _} ->
|
|
|
|
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
|
|
|
{ok, {_, Nick}} ->
|
2022-06-26 17:25:22 +02:00
|
|
|
xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick, xmlns = XmlNs});
|
2018-12-05 11:14:29 +01:00
|
|
|
{ok, {ID, _}} ->
|
|
|
|
case Mod:set_participant(ServerHost, Chan, Host, BFrom, ID, Nick) of
|
|
|
|
ok ->
|
|
|
|
notify_participant_joined(Mod, ServerHost, To, From, ID, Nick),
|
2022-06-26 17:25:22 +02:00
|
|
|
xmpp:make_iq_result(IQ, #mix_setnick{nick = Nick, xmlns = XmlNs});
|
2018-12-05 11:14:29 +01:00
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, not_joined_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end.
|
2016-07-06 13:58:48 +02:00
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
-spec process_mix_message(message()) -> ok.
|
|
|
|
process_mix_message(#message{from = From, to = To,
|
|
|
|
id = SubmissionID} = Msg) ->
|
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
2018-12-07 09:06:26 +01:00
|
|
|
{FUser, FServer, _} = jid:tolower(From),
|
2018-12-05 11:14:29 +01:00
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, _} ->
|
|
|
|
BFrom = jid:remove_resource(From),
|
|
|
|
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
2018-12-07 09:06:26 +01:00
|
|
|
{ok, {StableID, Nick}} ->
|
2018-12-05 11:14:29 +01:00
|
|
|
MamID = mod_mam:make_id(),
|
2018-12-07 09:06:26 +01:00
|
|
|
Msg1 = xmpp:set_subtag(
|
|
|
|
Msg#message{from = jid:replace_resource(To, StableID),
|
|
|
|
to = undefined,
|
|
|
|
id = integer_to_binary(MamID)},
|
|
|
|
#mix{jid = BFrom, nick = Nick}),
|
|
|
|
Msg2 = xmpp:put_meta(Msg1, stanza_id, MamID),
|
2018-12-05 11:14:29 +01:00
|
|
|
case ejabberd_hooks:run_fold(
|
2018-12-07 09:06:26 +01:00
|
|
|
store_mam_message, ServerHost, Msg2,
|
2018-12-05 11:14:29 +01:00
|
|
|
[Chan, Host, BFrom, Nick, groupchat, recv]) of
|
2018-12-07 09:06:26 +01:00
|
|
|
#message{} ->
|
2018-12-05 11:14:29 +01:00
|
|
|
multicast(Mod, ServerHost, Chan, Host,
|
2018-12-07 09:06:26 +01:00
|
|
|
?NS_MIX_NODES_MESSAGES,
|
|
|
|
fun(#jid{luser = U, lserver = S})
|
|
|
|
when U == FUser, S == FServer ->
|
|
|
|
xmpp:set_subtag(
|
|
|
|
Msg1, #mix{jid = BFrom,
|
|
|
|
nick = Nick,
|
|
|
|
submission_id = SubmissionID});
|
|
|
|
(_) ->
|
|
|
|
Msg1
|
|
|
|
end);
|
2018-12-05 11:14:29 +01:00
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
ejabberd_router:route_error(Msg, not_joined_error(Msg));
|
|
|
|
{error, db_failure} ->
|
|
|
|
ejabberd_router:route_error(Msg, db_error(Msg))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
ejabberd_router:route_error(Msg, no_channel_error(Msg));
|
|
|
|
{error, db_failure} ->
|
|
|
|
ejabberd_router:route_error(Msg, db_error(Msg))
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec process_participants_list(iq()) -> iq().
|
|
|
|
process_participants_list(#iq{from = From, to = To} = IQ) ->
|
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
ServerHost = ejabberd_router:host_of_route(Host),
|
|
|
|
Mod = gen_mod:db_mod(ServerHost, ?MODULE),
|
|
|
|
case Mod:get_channel(ServerHost, Chan, Host) of
|
|
|
|
{ok, _} ->
|
|
|
|
BFrom = jid:remove_resource(From),
|
|
|
|
case Mod:get_participant(ServerHost, Chan, Host, BFrom) of
|
|
|
|
{ok, _} ->
|
|
|
|
case Mod:get_participants(ServerHost, Chan, Host) of
|
|
|
|
{ok, Participants} ->
|
|
|
|
Items = items_of_participants(Participants),
|
|
|
|
Pubsub = #pubsub{
|
|
|
|
items = #ps_items{
|
|
|
|
node = ?NS_MIX_NODES_PARTICIPANTS,
|
|
|
|
items = Items}},
|
|
|
|
xmpp:make_iq_result(IQ, Pubsub);
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, not_joined_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end;
|
|
|
|
{error, notfound} ->
|
|
|
|
xmpp:make_error(IQ, no_channel_error(IQ));
|
|
|
|
{error, db_failure} ->
|
|
|
|
xmpp:make_error(IQ, db_error(IQ))
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec items_of_participants([{jid(), binary(), binary()}]) -> [ps_item()].
|
|
|
|
items_of_participants(Participants) ->
|
|
|
|
lists:map(
|
|
|
|
fun({JID, ID, Nick}) ->
|
|
|
|
Participant = #mix_participant{jid = JID, nick = Nick},
|
|
|
|
#ps_item{id = ID,
|
|
|
|
sub_els = [xmpp:encode(Participant)]}
|
|
|
|
end, Participants).
|
|
|
|
|
|
|
|
-spec known_nodes() -> [binary()].
|
|
|
|
known_nodes() ->
|
|
|
|
[?NS_MIX_NODES_MESSAGES,
|
|
|
|
?NS_MIX_NODES_PARTICIPANTS].
|
|
|
|
|
2019-06-14 11:33:26 +02:00
|
|
|
-spec filter_nodes([binary()]) -> [binary()].
|
2018-12-05 11:14:29 +01:00
|
|
|
filter_nodes(Nodes) ->
|
2022-07-02 20:20:24 +02:00
|
|
|
KnownNodes = known_nodes(),
|
|
|
|
[Node || KnownNode <- KnownNodes, Node <- Nodes, KnownNode == Node].
|
2018-12-05 11:14:29 +01:00
|
|
|
|
|
|
|
-spec multicast(module(), binary(), binary(),
|
2018-12-07 09:06:26 +01:00
|
|
|
binary(), binary(), fun((jid()) -> message())) -> ok.
|
|
|
|
multicast(Mod, LServer, Chan, Service, Node, F) ->
|
2018-12-05 11:14:29 +01:00
|
|
|
case Mod:get_subscribed(LServer, Chan, Service, Node) of
|
|
|
|
{ok, Subscribers} ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(To) ->
|
2018-12-07 09:06:26 +01:00
|
|
|
Msg = xmpp:set_to(F(To), To),
|
|
|
|
ejabberd_router:route(Msg)
|
2018-12-05 11:14:29 +01:00
|
|
|
end, Subscribers);
|
|
|
|
{error, db_failure} ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
|
|
|
-spec notify_participant_joined(module(), binary(),
|
|
|
|
jid(), jid(), binary(), binary()) -> ok.
|
|
|
|
notify_participant_joined(Mod, LServer, To, From, ID, Nick) ->
|
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
Participant = #mix_participant{jid = jid:remove_resource(From),
|
|
|
|
nick = Nick},
|
|
|
|
Item = #ps_item{id = ID,
|
|
|
|
sub_els = [xmpp:encode(Participant)]},
|
|
|
|
Items = #ps_items{node = ?NS_MIX_NODES_PARTICIPANTS,
|
|
|
|
items = [Item]},
|
|
|
|
Event = #ps_event{items = Items},
|
|
|
|
Msg = #message{from = jid:remove_resource(To),
|
|
|
|
id = p1_rand:get_string(),
|
|
|
|
sub_els = [Event]},
|
2018-12-07 09:06:26 +01:00
|
|
|
multicast(Mod, LServer, Chan, Host,
|
|
|
|
?NS_MIX_NODES_PARTICIPANTS,
|
|
|
|
fun(_) -> Msg end).
|
2018-12-05 11:14:29 +01:00
|
|
|
|
|
|
|
-spec notify_participant_left(module(), binary(), jid(), binary()) -> ok.
|
|
|
|
notify_participant_left(Mod, LServer, To, ID) ->
|
|
|
|
{Chan, Host, _} = jid:tolower(To),
|
|
|
|
Items = #ps_items{node = ?NS_MIX_NODES_PARTICIPANTS,
|
|
|
|
retract = ID},
|
|
|
|
Event = #ps_event{items = Items},
|
|
|
|
Msg = #message{from = jid:remove_resource(To),
|
|
|
|
id = p1_rand:get_string(),
|
|
|
|
sub_els = [Event]},
|
2018-12-07 19:34:49 +01:00
|
|
|
multicast(Mod, LServer, Chan, Host, ?NS_MIX_NODES_PARTICIPANTS,
|
|
|
|
fun(_) -> Msg end).
|
2018-12-05 11:14:29 +01:00
|
|
|
|
|
|
|
-spec make_id(jid(), binary()) -> binary().
|
|
|
|
make_id(JID, Key) ->
|
|
|
|
Data = jid:encode(jid:tolower(jid:remove_resource(JID))),
|
2020-06-01 10:35:28 +02:00
|
|
|
xmpp_util:hex(misc:crypto_hmac(sha256, Data, Key, 10)).
|
2018-01-23 08:54:52 +01:00
|
|
|
|
2022-06-27 10:48:38 +02:00
|
|
|
-spec make_channel_id(jid(), binary()) -> jid().
|
|
|
|
make_channel_id(JID, ID) ->
|
|
|
|
{U, S, R} = jid:split(JID),
|
|
|
|
jid:make(<<ID/binary, $#, U/binary>>, S, R).
|
|
|
|
|
2018-12-05 11:14:29 +01:00
|
|
|
%%%===================================================================
|
|
|
|
%%% Error generators
|
|
|
|
%%%===================================================================
|
|
|
|
-spec db_error(stanza()) -> stanza_error().
|
|
|
|
db_error(Pkt) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Database failure"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:err_internal_server_error(Txt, xmpp:get_lang(Pkt)).
|
|
|
|
|
|
|
|
-spec channel_exists_error(stanza()) -> stanza_error().
|
|
|
|
channel_exists_error(Pkt) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Channel already exists"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:err_conflict(Txt, xmpp:get_lang(Pkt)).
|
|
|
|
|
|
|
|
-spec no_channel_error(stanza()) -> stanza_error().
|
|
|
|
no_channel_error(Pkt) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Channel does not exist"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:err_item_not_found(Txt, xmpp:get_lang(Pkt)).
|
|
|
|
|
|
|
|
-spec not_joined_error(stanza()) -> stanza_error().
|
|
|
|
not_joined_error(Pkt) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("You are not joined to the channel"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:err_forbidden(Txt, xmpp:get_lang(Pkt)).
|
|
|
|
|
|
|
|
-spec unsupported_error(stanza()) -> stanza_error().
|
|
|
|
unsupported_error(Pkt) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("No module is handling this query"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:err_service_unavailable(Txt, xmpp:get_lang(Pkt)).
|
|
|
|
|
|
|
|
-spec ownership_error(stanza()) -> stanza_error().
|
|
|
|
ownership_error(Pkt) ->
|
2019-06-22 16:08:45 +02:00
|
|
|
Txt = ?T("Owner privileges required"),
|
2018-12-05 11:14:29 +01:00
|
|
|
xmpp:err_forbidden(Txt, xmpp:get_lang(Pkt)).
|
|
|
|
|
|
|
|
%%%===================================================================
|
|
|
|
%%% IQ handlers
|
|
|
|
%%%===================================================================
|
|
|
|
-spec register_iq_handlers(binary()) -> ok.
|
|
|
|
register_iq_handlers(Host) ->
|
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_INFO,
|
|
|
|
?MODULE, process_disco_info),
|
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_DISCO_ITEMS,
|
|
|
|
?MODULE, process_disco_items),
|
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_0,
|
|
|
|
?MODULE, process_mix_core),
|
2022-06-26 17:25:22 +02:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_1,
|
|
|
|
?MODULE, process_mix_core),
|
2018-12-05 11:14:29 +01:00
|
|
|
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),
|
2022-06-26 17:25:22 +02:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_1,
|
|
|
|
?MODULE, process_mix_core),
|
2018-12-05 11:14:29 +01:00
|
|
|
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,
|
|
|
|
?MODULE, process_mam_query).
|
|
|
|
|
|
|
|
-spec unregister_iq_handlers(binary()) -> ok.
|
|
|
|
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),
|
2022-06-26 17:25:22 +02:00
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_MIX_CORE_1),
|
2018-12-05 11:14:29 +01:00
|
|
|
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),
|
2022-06-26 17:25:22 +02:00
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MIX_CORE_1),
|
2018-12-05 11:14:29 +01:00
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_PUBSUB),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_MAM_2).
|