2003-01-01 20:54:44 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_disco.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2009-07-17 22:45:44 +02:00
|
|
|
%%% Purpose : Service Discovery (XEP-0030) support
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 1 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2018-01-05 21:18:58 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2018 ProcessOne
|
2007-12-24 12:41:41 +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.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +01:00
|
|
|
%%% 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.
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
2003-01-01 20:54:44 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_disco).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2015-05-21 17:02:36 +02:00
|
|
|
-protocol({xep, 30, '2.4'}).
|
|
|
|
-protocol({xep, 157, '1.0'}).
|
|
|
|
|
2003-01-24 21:18:33 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
-export([start/2, stop/1, reload/3, process_local_iq_items/1,
|
2016-07-18 14:01:32 +02:00
|
|
|
process_local_iq_info/1, get_local_identity/5,
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_features/5, get_local_services/5,
|
2016-07-18 14:01:32 +02:00
|
|
|
process_sm_iq_items/1, process_sm_iq_info/1,
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_identity/5, get_sm_features/5, get_sm_items/5,
|
2018-01-23 08:54:52 +01:00
|
|
|
get_info/5, transform_module_options/1, mod_opt_type/1,
|
|
|
|
mod_options/1, depends/2]).
|
2003-01-01 20:54:44 +01:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2018-01-08 09:29:17 +01:00
|
|
|
-include("translate.hrl").
|
2016-07-18 14:01:32 +02:00
|
|
|
-include("xmpp.hrl").
|
|
|
|
-include_lib("stdlib/include/ms_transform.hrl").
|
2011-07-13 17:06:17 +02:00
|
|
|
-include("mod_roster.hrl").
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2017-01-09 15:02:17 +01:00
|
|
|
-type features_acc() :: {error, stanza_error()} | {result, [binary()]} | empty.
|
|
|
|
-type items_acc() :: {error, stanza_error()} | {result, [disco_item()]} | empty.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, Opts) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
|
|
|
|
?NS_DISCO_ITEMS, ?MODULE,
|
2018-02-11 10:54:15 +01:00
|
|
|
process_local_iq_items),
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
|
|
|
|
?NS_DISCO_INFO, ?MODULE,
|
2018-02-11 10:54:15 +01:00
|
|
|
process_local_iq_info),
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
|
2018-02-11 10:54:15 +01:00
|
|
|
?NS_DISCO_ITEMS, ?MODULE, process_sm_iq_items),
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host,
|
2018-02-11 10:54:15 +01:00
|
|
|
?NS_DISCO_INFO, ?MODULE, process_sm_iq_info),
|
2013-03-14 10:33:02 +01:00
|
|
|
catch ets:new(disco_extra_domains,
|
2017-01-09 15:02:17 +01:00
|
|
|
[named_table, ordered_set, public,
|
|
|
|
{heir, erlang:group_leader(), none}]),
|
2018-01-23 08:54:52 +01:00
|
|
|
ExtraDomains = gen_mod:get_opt(extra_domains, Opts),
|
2013-03-14 10:33:02 +01:00
|
|
|
lists:foreach(fun (Domain) ->
|
|
|
|
register_extra_domain(Host, Domain)
|
|
|
|
end,
|
2005-07-15 01:12:20 +02:00
|
|
|
ExtraDomains),
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:add(disco_local_items, Host, ?MODULE,
|
|
|
|
get_local_services, 100),
|
|
|
|
ejabberd_hooks:add(disco_local_features, Host, ?MODULE,
|
|
|
|
get_local_features, 100),
|
|
|
|
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE,
|
|
|
|
get_local_identity, 100),
|
|
|
|
ejabberd_hooks:add(disco_sm_items, Host, ?MODULE,
|
|
|
|
get_sm_items, 100),
|
|
|
|
ejabberd_hooks:add(disco_sm_features, Host, ?MODULE,
|
|
|
|
get_sm_features, 100),
|
|
|
|
ejabberd_hooks:add(disco_sm_identity, Host, ?MODULE,
|
|
|
|
get_sm_identity, 100),
|
|
|
|
ejabberd_hooks:add(disco_info, Host, ?MODULE, get_info,
|
|
|
|
100),
|
2003-01-01 20:54:44 +01:00
|
|
|
ok.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
ejabberd_hooks:delete(disco_sm_identity, Host, ?MODULE,
|
|
|
|
get_sm_identity, 100),
|
|
|
|
ejabberd_hooks:delete(disco_sm_features, Host, ?MODULE,
|
|
|
|
get_sm_features, 100),
|
|
|
|
ejabberd_hooks:delete(disco_sm_items, Host, ?MODULE,
|
|
|
|
get_sm_items, 100),
|
|
|
|
ejabberd_hooks:delete(disco_local_identity, Host,
|
|
|
|
?MODULE, get_local_identity, 100),
|
|
|
|
ejabberd_hooks:delete(disco_local_features, Host,
|
|
|
|
?MODULE, get_local_features, 100),
|
|
|
|
ejabberd_hooks:delete(disco_local_items, Host, ?MODULE,
|
|
|
|
get_local_services, 100),
|
|
|
|
ejabberd_hooks:delete(disco_info, Host, ?MODULE,
|
|
|
|
get_info, 100),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
|
|
|
|
?NS_DISCO_ITEMS),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, 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_INFO),
|
|
|
|
catch ets:match_delete(disco_extra_domains,
|
|
|
|
{{'_', Host}}),
|
2004-07-10 00:34:26 +02:00
|
|
|
ok.
|
2003-01-29 18:12:23 +01:00
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
reload(Host, NewOpts, OldOpts) ->
|
2018-01-23 08:54:52 +01:00
|
|
|
case gen_mod:is_equal_opt(extra_domains, NewOpts, OldOpts) of
|
2017-02-22 17:46:47 +01:00
|
|
|
{false, NewDomains, OldDomains} ->
|
|
|
|
lists:foreach(
|
|
|
|
fun(Domain) ->
|
|
|
|
register_extra_domain(Host, Domain)
|
|
|
|
end, NewDomains -- OldDomains),
|
|
|
|
lists:foreach(
|
|
|
|
fun(Domain) ->
|
|
|
|
unregister_extra_domain(Host, Domain)
|
|
|
|
end, OldDomains -- NewDomains);
|
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec register_extra_domain(binary(), binary()) -> true.
|
2005-07-15 01:12:20 +02:00
|
|
|
register_extra_domain(Host, Domain) ->
|
|
|
|
ets:insert(disco_extra_domains, {{Domain, Host}}).
|
2003-10-09 20:09:05 +02:00
|
|
|
|
2017-02-22 17:46:47 +01:00
|
|
|
-spec unregister_extra_domain(binary(), binary()) -> true.
|
|
|
|
unregister_extra_domain(Host, Domain) ->
|
|
|
|
ets:delete_object(disco_extra_domains, {{Domain, Host}}).
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_local_iq_items(iq()) -> iq().
|
|
|
|
process_local_iq_items(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_local_iq_items(#iq{type = get, lang = Lang,
|
|
|
|
from = From, to = To,
|
|
|
|
sub_els = [#disco_items{node = Node}]} = IQ) ->
|
|
|
|
Host = To#jid.lserver,
|
|
|
|
case ejabberd_hooks:run_fold(disco_local_items, Host,
|
|
|
|
empty, [From, To, Node, Lang]) of
|
|
|
|
{result, Items} ->
|
|
|
|
xmpp:make_iq_result(IQ, #disco_items{node = Node, items = Items});
|
|
|
|
{error, Error} ->
|
|
|
|
xmpp:make_error(IQ, Error)
|
2003-01-01 20:54:44 +01:00
|
|
|
end.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_local_iq_info(iq()) -> iq().
|
|
|
|
process_local_iq_info(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_local_iq_info(#iq{type = get, lang = Lang,
|
|
|
|
from = From, to = To,
|
|
|
|
sub_els = [#disco_info{node = Node}]} = IQ) ->
|
|
|
|
Host = To#jid.lserver,
|
|
|
|
Identity = ejabberd_hooks:run_fold(disco_local_identity,
|
|
|
|
Host, [], [From, To, Node, Lang]),
|
|
|
|
Info = ejabberd_hooks:run_fold(disco_info, Host, [],
|
|
|
|
[Host, ?MODULE, Node, Lang]),
|
|
|
|
case ejabberd_hooks:run_fold(disco_local_features, Host,
|
|
|
|
empty, [From, To, Node, Lang]) of
|
|
|
|
{result, Features} ->
|
|
|
|
xmpp:make_iq_result(IQ, #disco_info{node = Node,
|
|
|
|
identities = Identity,
|
|
|
|
xdata = Info,
|
|
|
|
features = Features});
|
|
|
|
{error, Error} ->
|
|
|
|
xmpp:make_error(IQ, Error)
|
2003-01-01 20:54:44 +01:00
|
|
|
end.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_local_identity([identity()], jid(), jid(),
|
2016-08-05 07:41:08 +02:00
|
|
|
binary(), binary()) -> [identity()].
|
2018-01-08 09:29:17 +01:00
|
|
|
get_local_identity(Acc, _From, To, <<"">>, _Lang) ->
|
|
|
|
Host = To#jid.lserver,
|
2018-01-23 08:54:52 +01:00
|
|
|
Name = gen_mod:get_module_opt(Host, ?MODULE, name),
|
2016-07-18 14:01:32 +02:00
|
|
|
Acc ++ [#identity{category = <<"server">>,
|
|
|
|
type = <<"im">>,
|
2018-01-08 09:29:17 +01:00
|
|
|
name = Name}];
|
2005-09-04 03:58:47 +02:00
|
|
|
get_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
|
|
|
Acc.
|
|
|
|
|
2017-01-09 15:02:17 +01:00
|
|
|
-spec get_local_features(features_acc(), jid(), jid(), binary(), binary()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
{error, stanza_error()} | {result, [binary()]}.
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_features({error, _Error} = Acc, _From, _To,
|
|
|
|
_Node, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Acc;
|
2017-01-23 11:51:05 +01:00
|
|
|
get_local_features(Acc, _From, To, <<"">>, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Feats = case Acc of
|
2016-07-18 14:01:32 +02:00
|
|
|
{result, Features} -> Features;
|
|
|
|
empty -> []
|
2005-09-04 03:58:47 +02:00
|
|
|
end,
|
2017-01-23 11:51:05 +01:00
|
|
|
{result, lists:usort(
|
|
|
|
lists:flatten(
|
|
|
|
[<<"iq">>, <<"presence">>,
|
|
|
|
?NS_DISCO_INFO, ?NS_DISCO_ITEMS, Feats,
|
|
|
|
ejabberd_local:get_features(To#jid.lserver)]))};
|
2016-04-05 12:09:44 +02:00
|
|
|
get_local_features(Acc, _From, _To, _Node, Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
case Acc of
|
2013-03-14 10:33:02 +01:00
|
|
|
{result, _Features} -> Acc;
|
2016-04-05 12:09:44 +02:00
|
|
|
empty ->
|
|
|
|
Txt = <<"No features available">>,
|
2016-07-18 14:01:32 +02:00
|
|
|
{error, xmpp:err_item_not_found(Txt, Lang)}
|
2005-09-04 03:58:47 +02:00
|
|
|
end.
|
|
|
|
|
2017-01-09 15:02:17 +01:00
|
|
|
-spec get_local_services(items_acc(), jid(), jid(), binary(), binary()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
{error, stanza_error()} | {result, [disco_item()]}.
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_services({error, _Error} = Acc, _From, _To,
|
|
|
|
_Node, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Acc;
|
2016-08-05 07:41:08 +02:00
|
|
|
get_local_services(Acc, _From, To, <<"">>, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Items = case Acc of
|
2013-03-14 10:33:02 +01:00
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
2005-09-04 03:58:47 +02:00
|
|
|
end,
|
|
|
|
Host = To#jid.lserver,
|
2003-02-04 21:45:23 +01:00
|
|
|
{result,
|
2016-07-18 14:01:32 +02:00
|
|
|
lists:usort(
|
|
|
|
lists:map(
|
|
|
|
fun(Domain) -> #disco_item{jid = jid:make(Domain)} end,
|
|
|
|
get_vh_services(Host) ++
|
|
|
|
ets:select(disco_extra_domains,
|
|
|
|
ets:fun2ms(
|
|
|
|
fun({{D, H}}) when H == Host -> D end))))
|
|
|
|
++ Items};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_local_services({result, _} = Acc, _From, _To, _Node,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Acc;
|
2016-04-05 12:09:44 +02:00
|
|
|
get_local_services(empty, _From, _To, _Node, Lang) ->
|
2016-07-18 14:01:32 +02:00
|
|
|
{error, xmpp:err_item_not_found(<<"No services available">>, Lang)}.
|
2003-01-18 20:42:48 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_vh_services(binary()) -> [binary()].
|
2005-04-17 20:08:34 +02:00
|
|
|
get_vh_services(Host) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Hosts = lists:sort(fun (H1, H2) ->
|
|
|
|
byte_size(H1) >= byte_size(H2)
|
|
|
|
end,
|
|
|
|
?MYHOSTS),
|
|
|
|
lists:filter(fun (H) ->
|
|
|
|
case lists:dropwhile(fun (VH) ->
|
|
|
|
not
|
|
|
|
str:suffix(
|
|
|
|
<<".", VH/binary>>,
|
|
|
|
H)
|
|
|
|
end,
|
|
|
|
Hosts)
|
|
|
|
of
|
|
|
|
[] -> false;
|
|
|
|
[VH | _] -> VH == Host
|
2005-04-20 00:19:22 +02:00
|
|
|
end
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
2017-01-11 14:25:43 +01:00
|
|
|
ejabberd_router:get_all_routes()).
|
2003-01-18 20:42:48 +01:00
|
|
|
|
2005-09-04 03:58:47 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_sm_iq_items(iq()) -> iq().
|
|
|
|
process_sm_iq_items(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_sm_iq_items(#iq{type = get, lang = Lang,
|
|
|
|
from = From, to = To,
|
|
|
|
sub_els = [#disco_items{node = Node}]} = IQ) ->
|
|
|
|
case is_presence_subscribed(From, To) of
|
|
|
|
true ->
|
|
|
|
Host = To#jid.lserver,
|
|
|
|
case ejabberd_hooks:run_fold(disco_sm_items, Host,
|
|
|
|
empty, [From, To, Node, Lang]) of
|
|
|
|
{result, Items} ->
|
|
|
|
xmpp:make_iq_result(
|
|
|
|
IQ, #disco_items{node = Node, items = Items});
|
|
|
|
{error, Error} ->
|
|
|
|
xmpp:make_error(IQ, Error)
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
Txt = <<"Not subscribed">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_subscription_required(Txt, Lang))
|
2003-01-01 20:54:44 +01:00
|
|
|
end.
|
|
|
|
|
2017-01-09 15:02:17 +01:00
|
|
|
-spec get_sm_items(items_acc(), jid(), jid(), binary(), binary()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
{error, stanza_error()} | {result, [disco_item()]}.
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_items({error, _Error} = Acc, _From, _To, _Node,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Acc;
|
2010-04-22 15:29:20 +02:00
|
|
|
get_sm_items(Acc, From,
|
2016-08-05 07:41:08 +02:00
|
|
|
#jid{user = User, server = Server} = To, <<"">>, _Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Items = case Acc of
|
2013-03-14 10:33:02 +01:00
|
|
|
{result, Its} -> Its;
|
|
|
|
empty -> []
|
2005-09-04 03:58:47 +02:00
|
|
|
end,
|
2010-04-22 15:29:20 +02:00
|
|
|
Items1 = case is_presence_subscribed(From, To) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true -> get_user_resources(User, Server);
|
|
|
|
_ -> []
|
|
|
|
end,
|
2005-09-04 03:58:47 +02:00
|
|
|
{result, Items ++ Items1};
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_items({result, _} = Acc, _From, _To, _Node,
|
|
|
|
_Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
Acc;
|
2016-04-05 12:09:44 +02:00
|
|
|
get_sm_items(empty, From, To, _Node, Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
#jid{luser = LFrom, lserver = LSFrom} = From,
|
|
|
|
#jid{luser = LTo, lserver = LSTo} = To,
|
|
|
|
case {LFrom, LSFrom} of
|
2016-07-18 14:01:32 +02:00
|
|
|
{LTo, LSTo} -> {error, xmpp:err_item_not_found()};
|
2016-04-05 12:09:44 +02:00
|
|
|
_ ->
|
|
|
|
Txt = <<"Query to another users is forbidden">>,
|
2016-07-18 14:01:32 +02:00
|
|
|
{error, xmpp:err_not_allowed(Txt, Lang)}
|
2003-01-18 20:42:48 +01:00
|
|
|
end.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec is_presence_subscribed(jid(), jid()) -> boolean().
|
2015-04-26 16:36:17 +02:00
|
|
|
is_presence_subscribed(#jid{luser = User, lserver = Server},
|
2015-04-26 16:32:03 +02:00
|
|
|
#jid{luser = User, lserver = Server}) -> true;
|
2015-04-26 16:36:17 +02:00
|
|
|
is_presence_subscribed(#jid{luser = FromUser, lserver = FromServer},
|
|
|
|
#jid{luser = ToUser, lserver = ToServer}) ->
|
|
|
|
lists:any(fun (#roster{jid = {SubUser, SubServer, _}, subscription = Sub})
|
|
|
|
when FromUser == SubUser, FromServer == SubServer,
|
|
|
|
Sub /= none ->
|
|
|
|
true;
|
|
|
|
(_RosterEntry) ->
|
|
|
|
false
|
2013-03-14 10:33:02 +01:00
|
|
|
end,
|
2015-04-26 16:36:17 +02:00
|
|
|
ejabberd_hooks:run_fold(roster_get, ToServer, [],
|
|
|
|
[{ToUser, ToServer}])).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec process_sm_iq_info(iq()) -> iq().
|
|
|
|
process_sm_iq_info(#iq{type = set, lang = Lang} = IQ) ->
|
|
|
|
Txt = <<"Value 'set' of 'type' attribute is not allowed">>,
|
|
|
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
|
|
|
process_sm_iq_info(#iq{type = get, lang = Lang,
|
|
|
|
from = From, to = To,
|
|
|
|
sub_els = [#disco_info{node = Node}]} = IQ) ->
|
|
|
|
case is_presence_subscribed(From, To) of
|
|
|
|
true ->
|
|
|
|
Host = To#jid.lserver,
|
|
|
|
Identity = ejabberd_hooks:run_fold(disco_sm_identity,
|
|
|
|
Host, [],
|
2016-02-09 15:59:54 +01:00
|
|
|
[From, To, Node, Lang]),
|
2016-07-18 14:01:32 +02:00
|
|
|
Info = ejabberd_hooks:run_fold(disco_info, Host, [],
|
|
|
|
[From, To, Node, Lang]),
|
|
|
|
case ejabberd_hooks:run_fold(disco_sm_features, Host,
|
|
|
|
empty, [From, To, Node, Lang]) of
|
|
|
|
{result, Features} ->
|
|
|
|
xmpp:make_iq_result(IQ, #disco_info{node = Node,
|
|
|
|
identities = Identity,
|
|
|
|
xdata = Info,
|
|
|
|
features = Features});
|
|
|
|
{error, Error} ->
|
|
|
|
xmpp:make_error(IQ, Error)
|
|
|
|
end;
|
|
|
|
false ->
|
|
|
|
Txt = <<"Not subscribed">>,
|
2016-07-25 12:50:30 +02:00
|
|
|
xmpp:make_error(IQ, xmpp:err_subscription_required(Txt, Lang))
|
2003-01-01 20:54:44 +01:00
|
|
|
end.
|
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_sm_identity([identity()], jid(), jid(),
|
2016-08-05 07:41:08 +02:00
|
|
|
binary(), binary()) -> [identity()].
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_identity(Acc, _From,
|
|
|
|
#jid{luser = LUser, lserver = LServer}, _Node, _Lang) ->
|
|
|
|
Acc ++
|
2017-05-11 14:49:06 +02:00
|
|
|
case ejabberd_auth:user_exists(LUser, LServer) of
|
2013-03-14 10:33:02 +01:00
|
|
|
true ->
|
2016-07-18 14:01:32 +02:00
|
|
|
[#identity{category = <<"account">>, type = <<"registered">>}];
|
2013-03-14 10:33:02 +01:00
|
|
|
_ -> []
|
|
|
|
end.
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2017-01-09 15:02:17 +01:00
|
|
|
-spec get_sm_features(features_acc(), jid(), jid(), binary(), binary()) ->
|
2016-09-08 16:08:48 +02:00
|
|
|
{error, stanza_error()} | {result, [binary()]}.
|
2016-04-05 12:09:44 +02:00
|
|
|
get_sm_features(empty, From, To, _Node, Lang) ->
|
2005-09-04 03:58:47 +02:00
|
|
|
#jid{luser = LFrom, lserver = LSFrom} = From,
|
|
|
|
#jid{luser = LTo, lserver = LSTo} = To,
|
|
|
|
case {LFrom, LSFrom} of
|
2016-07-18 14:01:32 +02:00
|
|
|
{LTo, LSTo} -> {error, xmpp:err_item_not_found()};
|
2016-04-05 12:09:44 +02:00
|
|
|
_ ->
|
|
|
|
Txt = <<"Query to another users is forbidden">>,
|
2016-07-18 14:01:32 +02:00
|
|
|
{error, xmpp:err_not_allowed(Txt, Lang)}
|
2005-09-04 03:58:47 +02:00
|
|
|
end;
|
2013-03-14 10:33:02 +01:00
|
|
|
get_sm_features(Acc, _From, _To, _Node, _Lang) -> Acc.
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_user_resources(binary(), binary()) -> [disco_item()].
|
2005-09-04 03:58:47 +02:00
|
|
|
get_user_resources(User, Server) ->
|
|
|
|
Rs = ejabberd_sm:get_user_resources(User, Server),
|
2016-07-18 14:01:32 +02:00
|
|
|
[#disco_item{jid = jid:make(User, Server, Resource), name = User}
|
|
|
|
|| Resource <- lists:sort(Rs)].
|
2009-07-17 22:45:44 +02:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec transform_module_options(gen_mod:opts()) -> gen_mod:opts().
|
2013-08-12 14:25:05 +02:00
|
|
|
transform_module_options(Opts) ->
|
|
|
|
lists:map(
|
|
|
|
fun({server_info, Infos}) ->
|
|
|
|
NewInfos = lists:map(
|
|
|
|
fun({Modules, Name, URLs}) ->
|
|
|
|
[[{modules, Modules},
|
|
|
|
{name, Name},
|
|
|
|
{urls, URLs}]];
|
|
|
|
(Opt) ->
|
|
|
|
Opt
|
|
|
|
end, Infos),
|
|
|
|
{server_info, NewInfos};
|
|
|
|
(Opt) ->
|
|
|
|
Opt
|
|
|
|
end, Opts).
|
|
|
|
|
2009-07-17 22:45:44 +02:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
%%% Support for: XEP-0157 Contact Addresses for XMPP Services
|
|
|
|
|
2016-08-09 09:56:32 +02:00
|
|
|
-spec get_info([xdata()], binary(), module(), binary(), binary()) -> [xdata()];
|
|
|
|
([xdata()], jid(), jid(), binary(), binary()) -> [xdata()].
|
|
|
|
get_info(_A, Host, Mod, Node, _Lang) when is_atom(Mod), Node == <<"">> ->
|
2010-05-07 18:32:57 +02:00
|
|
|
Module = case Mod of
|
2013-03-14 10:33:02 +01:00
|
|
|
undefined -> ?MODULE;
|
|
|
|
_ -> Mod
|
2010-05-07 18:32:57 +02:00
|
|
|
end,
|
2016-07-18 14:01:32 +02:00
|
|
|
[#xdata{type = result,
|
|
|
|
fields = [#xdata_field{type = hidden,
|
|
|
|
var = <<"FORM_TYPE">>,
|
|
|
|
values = [?NS_SERVERINFO]}
|
|
|
|
| get_fields(Host, Module)]}];
|
2013-03-14 10:33:02 +01:00
|
|
|
get_info(Acc, _, _, _Node, _) -> Acc.
|
2009-07-17 22:45:44 +02:00
|
|
|
|
2016-07-18 14:01:32 +02:00
|
|
|
-spec get_fields(binary(), module()) -> [xdata_field()].
|
|
|
|
get_fields(Host, Module) ->
|
2018-01-23 08:54:52 +01:00
|
|
|
Fields = gen_mod:get_module_opt(Host, ?MODULE, server_info),
|
2016-07-18 14:01:32 +02:00
|
|
|
Fields1 = lists:filter(fun ({Modules, _, _}) ->
|
|
|
|
case Modules of
|
|
|
|
all -> true;
|
|
|
|
Modules ->
|
|
|
|
lists:member(Module, Modules)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
Fields),
|
|
|
|
[#xdata_field{var = Var, values = Values} || {_, Var, Values} <- Fields1].
|
|
|
|
|
|
|
|
-spec depends(binary(), gen_mod:opts()) -> [].
|
2016-07-06 13:58:48 +02:00
|
|
|
depends(_Host, _Opts) ->
|
|
|
|
[].
|
|
|
|
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(extra_domains) ->
|
|
|
|
fun (Hs) -> [iolist_to_binary(H) || H <- Hs] end;
|
2018-01-08 09:29:17 +01:00
|
|
|
mod_opt_type(name) -> fun iolist_to_binary/1;
|
2015-06-01 14:38:27 +02:00
|
|
|
mod_opt_type(server_info) ->
|
|
|
|
fun (L) ->
|
|
|
|
lists:map(fun (Opts) ->
|
|
|
|
Mods = proplists:get_value(modules, Opts, all),
|
|
|
|
Name = proplists:get_value(name, Opts, <<>>),
|
|
|
|
URLs = proplists:get_value(urls, Opts, []),
|
|
|
|
{Mods, Name, URLs}
|
|
|
|
end,
|
|
|
|
L)
|
2018-01-23 08:54:52 +01:00
|
|
|
end.
|
|
|
|
|
2018-02-11 10:54:15 +01:00
|
|
|
mod_options(_Host) ->
|
2018-01-23 08:54:52 +01:00
|
|
|
[{extra_domains, []},
|
|
|
|
{server_info, []},
|
|
|
|
{name, ?T("ejabberd")}].
|