mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
enforce disco features results (thanks to Karim)(EJAB-1033, EJAB-1228, EJAB-1238)
This commit is contained in:
parent
550363cd52
commit
8a251ccafe
@ -73,8 +73,7 @@
|
|||||||
disco_sm_items/5
|
disco_sm_items/5
|
||||||
]).
|
]).
|
||||||
%% exported iq handlers
|
%% exported iq handlers
|
||||||
-export([iq_local/3,
|
-export([iq_sm/3
|
||||||
iq_sm/3
|
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% exports for console debug manual use
|
%% exports for console debug manual use
|
||||||
@ -198,24 +197,22 @@ init([ServerHost, Opts]) ->
|
|||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
|
||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
|
||||||
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
||||||
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||||
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||||
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||||
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||||
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
|
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc),
|
|
||||||
case lists:member(?PEPNODE, Plugins) of
|
case lists:member(?PEPNODE, Plugins) of
|
||||||
true ->
|
true ->
|
||||||
ejabberd_hooks:add(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
ejabberd_hooks:add(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
||||||
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
||||||
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
||||||
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB, ?MODULE, iq_local, IQDisc),
|
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_local, IQDisc);
|
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc);
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
@ -584,15 +581,12 @@ send_loop(State) ->
|
|||||||
%% disco hooks handling functions
|
%% disco hooks handling functions
|
||||||
%%
|
%%
|
||||||
|
|
||||||
identity(Host) ->
|
|
||||||
Identity = case lists:member(?PEPNODE, plugins(Host)) of
|
|
||||||
true -> [{"category", "pubsub"}, {"type", "pep"}];
|
|
||||||
false -> [{"category", "pubsub"}, {"type", "service"}]
|
|
||||||
end,
|
|
||||||
{xmlelement, "identity", Identity, []}.
|
|
||||||
|
|
||||||
disco_local_identity(Acc, _From, To, [], _Lang) ->
|
disco_local_identity(Acc, _From, To, [], _Lang) ->
|
||||||
Acc ++ [identity(To#jid.lserver)];
|
case lists:member(?PEPNODE, plugins(To#jid.lserver)) of
|
||||||
|
true ->
|
||||||
|
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []} | Acc];
|
||||||
|
false -> Acc
|
||||||
|
end;
|
||||||
disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
@ -613,76 +607,116 @@ disco_local_items(Acc, _From, _To, [], _Lang) ->
|
|||||||
disco_local_items(Acc, _From, _To, _Node, _Lang) ->
|
disco_local_items(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
disco_sm_identity(Acc, _From, To, [], _Lang) ->
|
disco_sm_identity(Acc, From, To, Node, Lang) when is_list(Node) ->
|
||||||
Acc ++ [identity(To#jid.lserver)];
|
disco_sm_identity(Acc, From, To, list_to_binary(Node), Lang);
|
||||||
|
disco_sm_identity(empty, From, To, Node, Lang) ->
|
||||||
|
disco_sm_identity([], From, To, Node, Lang);
|
||||||
disco_sm_identity(Acc, From, To, Node, _Lang) ->
|
disco_sm_identity(Acc, From, To, Node, _Lang) ->
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
disco_identity(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From) ++ Acc.
|
||||||
Acc ++ case node_disco_identity(LOwner, From, Node) of
|
|
||||||
{result, I} -> I;
|
|
||||||
_ -> []
|
|
||||||
end.
|
|
||||||
|
|
||||||
disco_sm_features(Acc, _From, _To, [], _Lang) ->
|
disco_identity(_Host, <<>>, _From) ->
|
||||||
Acc;
|
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
|
||||||
disco_sm_features(Acc, From, To, Node, _Lang) ->
|
disco_identity(Host, Node, From) ->
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
Features = node_disco_features(LOwner, From, Node),
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
case {Acc, Features} of
|
{result, _} ->
|
||||||
{{result, AccFeatures}, {result, AddFeatures}} ->
|
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
|
||||||
{result, AccFeatures++AddFeatures};
|
{xmlelement, "identity",
|
||||||
{_, {result, AddFeatures}} ->
|
[{"category", "pubsub"},
|
||||||
{result, AddFeatures};
|
{"type", "leaf"}
|
||||||
{_, _} ->
|
| case get_option(Options, title) of
|
||||||
Acc
|
false -> [];
|
||||||
|
[Title] -> [{"name", Title}]
|
||||||
|
end],
|
||||||
|
[]}]};
|
||||||
|
_ -> {result, []}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
|
{result, {_, Result}} -> Result;
|
||||||
|
_ -> []
|
||||||
end.
|
end.
|
||||||
|
|
||||||
disco_sm_items(Acc, From, To, [], _Lang) ->
|
disco_sm_features(Acc, From, To, Node, Lang) when is_list(Node) ->
|
||||||
Host = To#jid.lserver,
|
disco_sm_features(Acc, From, To, list_to_binary(Node), Lang);
|
||||||
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
|
disco_sm_features(empty, From, To, Node, Lang) ->
|
||||||
[] ->
|
disco_sm_features({result, []}, From, To, Node, Lang);
|
||||||
Acc;
|
disco_sm_features({result, OtherFeatures} = _Acc, From, To, Node, _Lang) ->
|
||||||
Nodes ->
|
{result,
|
||||||
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
|
OtherFeatures ++
|
||||||
Items = case Acc of
|
disco_features(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From)};
|
||||||
{result, I} -> I;
|
disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
|
||||||
_ -> []
|
Acc.
|
||||||
end,
|
|
||||||
NodeItems = lists:map(
|
disco_features(_Host, <<>>, _From) ->
|
||||||
fun(#pubsub_node{nodeid = {_, Node}}) ->
|
[?NS_PUBSUB
|
||||||
{xmlelement, "item",
|
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
|
||||||
[{"jid", SBJID}|nodeAttr(Node)],
|
disco_features(Host, Node, From) ->
|
||||||
[]}
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
end, Nodes),
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
{result, NodeItems ++ Items}
|
{result, _} ->
|
||||||
|
{result, [?NS_PUBSUB
|
||||||
|
| [?NS_PUBSUB ++ "#" ++ Feature || Feature <- features("pep")]]};
|
||||||
|
_ -> {result, []}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
|
{result, {_, Result}} -> Result;
|
||||||
|
_ -> []
|
||||||
|
end.
|
||||||
|
|
||||||
|
disco_sm_items(Acc, From, To, Node, Lang) when is_list(Node) ->
|
||||||
|
disco_sm_items(Acc, From, To, list_to_binary(Node), Lang);
|
||||||
|
disco_sm_items(empty, From, To, Node, Lang) ->
|
||||||
|
disco_sm_items({result, []}, From, To, Node, Lang);
|
||||||
|
disco_sm_items({result, OtherItems}, From, To, Node, _Lang) ->
|
||||||
|
{result,
|
||||||
|
lists:usort(OtherItems ++
|
||||||
|
disco_items(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From))};
|
||||||
|
disco_sm_items(Acc, _From, _To, _Node, _Lang) ->
|
||||||
|
Acc.
|
||||||
|
|
||||||
|
disco_items(Host, <<>>, From) ->
|
||||||
|
Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx, owners = Owners}, Acc) ->
|
||||||
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
|
{result, _} ->
|
||||||
|
[{xmlelement, "item",
|
||||||
|
[{"node", binary_to_list(NodeID)},
|
||||||
|
{"jid", case Host of
|
||||||
|
{_,_,_} -> jlib:jid_to_string(Host);
|
||||||
|
_Host -> Host
|
||||||
|
end}
|
||||||
|
| case get_option(Options, title) of
|
||||||
|
false -> [];
|
||||||
|
[Title] -> [{"name", Title}]
|
||||||
|
end],
|
||||||
|
[]}
|
||||||
|
| Acc];
|
||||||
|
_ -> Acc
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
case transaction(Host, Action, sync_dirty) of
|
||||||
|
{result, Items} -> Items;
|
||||||
|
_ -> []
|
||||||
end;
|
end;
|
||||||
|
|
||||||
disco_sm_items(Acc, From, To, SNode, _Lang) ->
|
disco_items(Host, Node, From) ->
|
||||||
Host = To#jid.lserver,
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
Node = string_to_node(SNode),
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
{result, Items} ->
|
||||||
% TODO call get_items/6 instead for access control (EJAB-1033)
|
{result, [{xmlelement, "item",
|
||||||
case node_call(Type, get_items, [NodeId, From]) of
|
[{"jid", case Host of
|
||||||
{result, []} ->
|
{_,_,_} -> jlib:jid_to_string(Host);
|
||||||
none;
|
_Host -> Host
|
||||||
{result, AllItems} ->
|
end},
|
||||||
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
|
{"name", ItemID}], []}
|
||||||
Items = case Acc of
|
|| #pubsub_item{itemid = {ItemID,_}} <- Items]};
|
||||||
{result, I} -> I;
|
_ -> {result, []}
|
||||||
_ -> []
|
end
|
||||||
end,
|
end,
|
||||||
NodeItems = lists:map(
|
|
||||||
fun(#pubsub_item{itemid = {Id, _}}) ->
|
|
||||||
{result, Name} = node_call(Type, get_item_name, [Host, Node, Id]),
|
|
||||||
{xmlelement, "item", [{"jid", SBJID}, {"name", Name}], []}
|
|
||||||
end, AllItems),
|
|
||||||
{result, NodeItems ++ Items};
|
|
||||||
_ ->
|
|
||||||
none
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
case transaction(Host, Node, Action, sync_dirty) of
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
{result, {_, Items}} -> {result, Items};
|
{result, {_, Result}} -> Result;
|
||||||
_ -> Acc
|
_ -> []
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
@ -858,25 +892,23 @@ terminate(_Reason, #state{host = Host,
|
|||||||
case lists:member(?PEPNODE, Plugins) of
|
case lists:member(?PEPNODE, Plugins) of
|
||||||
true ->
|
true ->
|
||||||
ejabberd_hooks:delete(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
ejabberd_hooks:delete(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
||||||
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
||||||
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
||||||
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER);
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER);
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
||||||
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||||
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||||
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||||
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||||
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
|
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER),
|
|
||||||
mod_disco:unregister_feature(ServerHost, ?NS_PUBSUB),
|
mod_disco:unregister_feature(ServerHost, ?NS_PUBSUB),
|
||||||
gen_mod:get_module_proc(ServerHost, ?LOOPNAME) ! stop,
|
gen_mod:get_module_proc(ServerHost, ?LOOPNAME) ! stop,
|
||||||
terminate_plugins(Host, ServerHost, Plugins, TreePlugin).
|
terminate_plugins(Host, ServerHost, Plugins, TreePlugin).
|
||||||
@ -1017,10 +1049,10 @@ command_disco_info(_Host, <<?NS_PUBSUB_GET_PENDING>>, _From) ->
|
|||||||
|
|
||||||
node_disco_info(Host, Node, From) ->
|
node_disco_info(Host, Node, From) ->
|
||||||
node_disco_info(Host, Node, From, true, true).
|
node_disco_info(Host, Node, From, true, true).
|
||||||
node_disco_identity(Host, Node, From) ->
|
%node_disco_identity(Host, Node, From) ->
|
||||||
node_disco_info(Host, Node, From, true, false).
|
% node_disco_info(Host, Node, From, true, false).
|
||||||
node_disco_features(Host, Node, From) ->
|
%node_disco_features(Host, Node, From) ->
|
||||||
node_disco_info(Host, Node, From, false, true).
|
% node_disco_info(Host, Node, From, false, true).
|
||||||
node_disco_info(Host, Node, From, Identity, Features) ->
|
node_disco_info(Host, Node, From, Identity, Features) ->
|
||||||
Action =
|
Action =
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
@ -1120,17 +1152,15 @@ iq_disco_items(Host, Item, From) ->
|
|||||||
{result, []};
|
{result, []};
|
||||||
[SNode] ->
|
[SNode] ->
|
||||||
Node = string_to_node(SNode),
|
Node = string_to_node(SNode),
|
||||||
Action =
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
NodeItems = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
% TODO call get_items/6 instead for access control (EJAB-1033)
|
{result, R} -> R;
|
||||||
NodeItems = case node_call(Type, get_items, [NodeId, From]) of
|
_ -> []
|
||||||
{result, I} -> I;
|
end,
|
||||||
_ -> []
|
|
||||||
end,
|
|
||||||
Nodes = lists:map(
|
Nodes = lists:map(
|
||||||
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
|
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
|
||||||
Attrs =
|
Attrs =
|
||||||
case get_option(Options, title) of
|
case get_option(SubOptions, title) of
|
||||||
false ->
|
false ->
|
||||||
[{"jid", Host} |nodeAttr(SubNode)];
|
[{"jid", Host} |nodeAttr(SubNode)];
|
||||||
Title ->
|
Title ->
|
||||||
@ -1151,24 +1181,6 @@ iq_disco_items(Host, Item, From) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
iq_local(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
|
|
||||||
ServerHost = To#jid.lserver,
|
|
||||||
%% Accept IQs to server only from our own users.
|
|
||||||
if
|
|
||||||
From#jid.lserver /= ServerHost ->
|
|
||||||
IQ#iq{type = error, sub_el = [?ERR_FORBIDDEN, SubEl]};
|
|
||||||
true ->
|
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(From)),
|
|
||||||
Res = case XMLNS of
|
|
||||||
?NS_PUBSUB -> iq_pubsub(LOwner, ServerHost, From, Type, SubEl, Lang);
|
|
||||||
?NS_PUBSUB_OWNER -> iq_pubsub_owner(LOwner, ServerHost, From, Type, SubEl, Lang)
|
|
||||||
end,
|
|
||||||
case Res of
|
|
||||||
{result, IQRes} -> IQ#iq{type = result, sub_el = IQRes};
|
|
||||||
{error, Error} -> IQ#iq{type = error, sub_el = [Error, SubEl]}
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
|
iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
|
||||||
ServerHost = To#jid.lserver,
|
ServerHost = To#jid.lserver,
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
||||||
@ -1868,7 +1880,7 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
|
|||||||
error -> {"", "", ""};
|
error -> {"", "", ""};
|
||||||
J -> jlib:jid_tolower(J)
|
J -> jlib:jid_tolower(J)
|
||||||
end,
|
end,
|
||||||
Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) ->
|
Action = fun(#pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId}) ->
|
||||||
Features = features(Type),
|
Features = features(Type),
|
||||||
SubscribeFeature = lists:member("subscribe", Features),
|
SubscribeFeature = lists:member("subscribe", Features),
|
||||||
OptionsFeature = lists:member("subscription-options", Features),
|
OptionsFeature = lists:member("subscription-options", Features),
|
||||||
@ -1877,21 +1889,7 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
|
|||||||
AccessModel = get_option(Options, access_model),
|
AccessModel = get_option(Options, access_model),
|
||||||
SendLast = get_option(Options, send_last_published_item),
|
SendLast = get_option(Options, send_last_published_item),
|
||||||
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
{PresenceSubscription, RosterGroup} =
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
|
||||||
case Host of
|
|
||||||
{OUser, OServer, _} ->
|
|
||||||
get_roster_info(OUser, OServer,
|
|
||||||
Subscriber, AllowedGroups);
|
|
||||||
_ ->
|
|
||||||
case Subscriber of
|
|
||||||
{"", "", ""} ->
|
|
||||||
{false, false};
|
|
||||||
_ ->
|
|
||||||
{OU, OS, _} = Owner,
|
|
||||||
get_roster_info(OU, OS,
|
|
||||||
Subscriber, AllowedGroups)
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
if
|
if
|
||||||
not SubscribeFeature ->
|
not SubscribeFeature ->
|
||||||
%% Node does not support subscriptions
|
%% Node does not support subscriptions
|
||||||
@ -2234,20 +2232,13 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) ->
|
|||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
{error, Error};
|
{error, Error};
|
||||||
_ ->
|
_ ->
|
||||||
Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
|
Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId, owners = Owners}) ->
|
||||||
Features = features(Type),
|
Features = features(Type),
|
||||||
RetreiveFeature = lists:member("retrieve-items", Features),
|
RetreiveFeature = lists:member("retrieve-items", Features),
|
||||||
PersistentFeature = lists:member("persistent-items", Features),
|
PersistentFeature = lists:member("persistent-items", Features),
|
||||||
AccessModel = get_option(Options, access_model),
|
AccessModel = get_option(Options, access_model),
|
||||||
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
{PresenceSubscription, RosterGroup} =
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
case Host of
|
|
||||||
{OUser, OServer, _} ->
|
|
||||||
get_roster_info(OUser, OServer,
|
|
||||||
jlib:jid_tolower(From), AllowedGroups);
|
|
||||||
_ ->
|
|
||||||
{true, true}
|
|
||||||
end,
|
|
||||||
if
|
if
|
||||||
not RetreiveFeature ->
|
not RetreiveFeature ->
|
||||||
%% Item Retrieval Not Supported
|
%% Item Retrieval Not Supported
|
||||||
@ -2297,6 +2288,12 @@ get_item(Host, Node, ItemId) ->
|
|||||||
{result, {_, Items}} -> Items;
|
{result, {_, Items}} -> Items;
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
|
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
|
||||||
|
AccessModel = get_option(Options, access_model),
|
||||||
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
|
node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined]).
|
||||||
|
|
||||||
|
|
||||||
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
||||||
%% Host = pubsubHost()
|
%% Host = pubsubHost()
|
||||||
@ -2774,8 +2771,24 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups) ->
|
||||||
|
if (AccessModel == presence) or (AccessModel == roster) ->
|
||||||
|
case Host of
|
||||||
|
{User, Server, _} ->
|
||||||
|
get_roster_info(User, Server, From, AllowedGroups);
|
||||||
|
_ ->
|
||||||
|
[{OUser, OServer, _}|_] = Owners,
|
||||||
|
get_roster_info(OUser, OServer, From, AllowedGroups)
|
||||||
|
end;
|
||||||
|
true ->
|
||||||
|
{true, true}
|
||||||
|
end.
|
||||||
|
|
||||||
%% @spec (OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, SubscriberResource}, AllowedGroups)
|
%% @spec (OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, SubscriberResource}, AllowedGroups)
|
||||||
%% -> {PresenceSubscription, RosterGroup}
|
%% -> {PresenceSubscription, RosterGroup}
|
||||||
|
get_roster_info(_, _, {"", "", _}, _) ->
|
||||||
|
{false, false};
|
||||||
get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) ->
|
get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) ->
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
ejabberd_hooks:run_fold(
|
||||||
@ -2787,7 +2800,9 @@ get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, A
|
|||||||
RosterGroup = lists:any(fun(Group) ->
|
RosterGroup = lists:any(fun(Group) ->
|
||||||
lists:member(Group, AllowedGroups)
|
lists:member(Group, AllowedGroups)
|
||||||
end, Groups),
|
end, Groups),
|
||||||
{PresenceSubscription, RosterGroup}.
|
{PresenceSubscription, RosterGroup};
|
||||||
|
get_roster_info(OwnerUser, OwnerServer, JID, AllowedGroups) ->
|
||||||
|
get_roster_info(OwnerUser, OwnerServer, jlib:jid_tolower(JID), AllowedGroups).
|
||||||
|
|
||||||
%% @spec (AffiliationStr) -> Affiliation
|
%% @spec (AffiliationStr) -> Affiliation
|
||||||
%% AffiliationStr = string()
|
%% AffiliationStr = string()
|
||||||
@ -3742,6 +3757,10 @@ transaction(Host, Node, Action, Trans) ->
|
|||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
end, Trans).
|
end, Trans).
|
||||||
|
transaction(Host, Action, Trans) ->
|
||||||
|
transaction(fun() ->
|
||||||
|
{result, lists:foldl(Action, [], tree_call(Host, get_nodes, [Host]))}
|
||||||
|
end, Trans).
|
||||||
|
|
||||||
transaction(Fun, Trans) ->
|
transaction(Fun, Trans) ->
|
||||||
case catch mnesia:Trans(Fun) of
|
case catch mnesia:Trans(Fun) of
|
||||||
|
@ -73,8 +73,7 @@
|
|||||||
disco_sm_items/5
|
disco_sm_items/5
|
||||||
]).
|
]).
|
||||||
%% exported iq handlers
|
%% exported iq handlers
|
||||||
-export([iq_local/3,
|
-export([iq_sm/3
|
||||||
iq_sm/3
|
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% exports for console debug manual use
|
%% exports for console debug manual use
|
||||||
@ -198,24 +197,22 @@ init([ServerHost, Opts]) ->
|
|||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
|
||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
|
||||||
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
ejabberd_hooks:add(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
||||||
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||||
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||||
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||||
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||||
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
|
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc),
|
|
||||||
case lists:member(?PEPNODE, Plugins) of
|
case lists:member(?PEPNODE, Plugins) of
|
||||||
true ->
|
true ->
|
||||||
ejabberd_hooks:add(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
ejabberd_hooks:add(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
||||||
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:add(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
||||||
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
||||||
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB, ?MODULE, iq_local, IQDisc),
|
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB, ?MODULE, iq_sm, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_local, IQDisc);
|
gen_iq_handler:add_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER, ?MODULE, iq_sm, IQDisc);
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
@ -387,15 +384,12 @@ send_loop(State) ->
|
|||||||
%% disco hooks handling functions
|
%% disco hooks handling functions
|
||||||
%%
|
%%
|
||||||
|
|
||||||
identity(Host) ->
|
|
||||||
Identity = case lists:member(?PEPNODE, plugins(Host)) of
|
|
||||||
true -> [{"category", "pubsub"}, {"type", "pep"}];
|
|
||||||
false -> [{"category", "pubsub"}, {"type", "service"}]
|
|
||||||
end,
|
|
||||||
{xmlelement, "identity", Identity, []}.
|
|
||||||
|
|
||||||
disco_local_identity(Acc, _From, To, [], _Lang) ->
|
disco_local_identity(Acc, _From, To, [], _Lang) ->
|
||||||
Acc ++ [identity(To#jid.lserver)];
|
case lists:member(?PEPNODE, plugins(To#jid.lserver)) of
|
||||||
|
true ->
|
||||||
|
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []} | Acc];
|
||||||
|
false -> Acc
|
||||||
|
end;
|
||||||
disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
disco_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
@ -416,76 +410,120 @@ disco_local_items(Acc, _From, _To, [], _Lang) ->
|
|||||||
disco_local_items(Acc, _From, _To, _Node, _Lang) ->
|
disco_local_items(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
disco_sm_identity(Acc, _From, To, [], _Lang) ->
|
disco_sm_identity(Acc, From, To, Node, Lang) when is_list(Node) ->
|
||||||
Acc ++ [identity(To#jid.lserver)];
|
disco_sm_identity(Acc, From, To, list_to_binary(Node), Lang);
|
||||||
|
disco_sm_identity(empty, From, To, Node, Lang) ->
|
||||||
|
disco_sm_identity([], From, To, Node, Lang);
|
||||||
disco_sm_identity(Acc, From, To, Node, _Lang) ->
|
disco_sm_identity(Acc, From, To, Node, _Lang) ->
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
disco_identity(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From) ++ Acc.
|
||||||
Acc ++ case node_disco_identity(LOwner, From, Node) of
|
|
||||||
{result, I} -> I;
|
|
||||||
_ -> []
|
|
||||||
end.
|
|
||||||
|
|
||||||
disco_sm_features(Acc, _From, _To, [], _Lang) ->
|
disco_identity(_Host, <<>>, _From) ->
|
||||||
Acc;
|
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
|
||||||
disco_sm_features(Acc, From, To, Node, _Lang) ->
|
disco_identity(Host, Node, From) ->
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
Features = node_disco_features(LOwner, From, Node),
|
Owners = node_owners_call(Type, Idx),
|
||||||
case {Acc, Features} of
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
{{result, AccFeatures}, {result, AddFeatures}} ->
|
{result, _} ->
|
||||||
{result, AccFeatures++AddFeatures};
|
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
|
||||||
{_, {result, AddFeatures}} ->
|
{xmlelement, "identity",
|
||||||
{result, AddFeatures};
|
[{"category", "pubsub"},
|
||||||
{_, _} ->
|
{"type", "leaf"}
|
||||||
Acc
|
| case get_option(Options, title) of
|
||||||
|
false -> [];
|
||||||
|
[Title] -> [{"name", Title}]
|
||||||
|
end],
|
||||||
|
[]}]};
|
||||||
|
_ -> {result, []}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
|
{result, {_, Result}} -> Result;
|
||||||
|
_ -> []
|
||||||
end.
|
end.
|
||||||
|
|
||||||
disco_sm_items(Acc, From, To, [], _Lang) ->
|
disco_sm_features(Acc, From, To, Node, Lang) when is_list(Node) ->
|
||||||
Host = To#jid.lserver,
|
disco_sm_features(Acc, From, To, list_to_binary(Node), Lang);
|
||||||
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
|
disco_sm_features(empty, From, To, Node, Lang) ->
|
||||||
[] ->
|
disco_sm_features({result, []}, From, To, Node, Lang);
|
||||||
Acc;
|
disco_sm_features({result, OtherFeatures} = _Acc, From, To, Node, _Lang) ->
|
||||||
Nodes ->
|
{result,
|
||||||
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
|
OtherFeatures ++
|
||||||
Items = case Acc of
|
disco_features(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From)};
|
||||||
{result, I} -> I;
|
disco_sm_features(Acc, _From, _To, _Node, _Lang) ->
|
||||||
_ -> []
|
Acc.
|
||||||
end,
|
|
||||||
NodeItems = lists:map(
|
disco_features(_Host, <<>>, _From) ->
|
||||||
fun(#pubsub_node{nodeid = {_, Node}}) ->
|
[?NS_PUBSUB
|
||||||
{xmlelement, "item",
|
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
|
||||||
[{"jid", SBJID}|nodeAttr(Node)],
|
disco_features(Host, Node, From) ->
|
||||||
[]}
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
end, Nodes),
|
Owners = node_owners_call(Type, Idx),
|
||||||
{result, NodeItems ++ Items}
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
|
{result, _} ->
|
||||||
|
{result, [?NS_PUBSUB
|
||||||
|
| [?NS_PUBSUB ++ "#" ++ Feature || Feature <- features("pep")]]};
|
||||||
|
_ -> {result, []}
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
|
{result, {_, Result}} -> Result;
|
||||||
|
_ -> []
|
||||||
|
end.
|
||||||
|
|
||||||
|
disco_sm_items(Acc, From, To, Node, Lang) when is_list(Node) ->
|
||||||
|
disco_sm_items(Acc, From, To, list_to_binary(Node), Lang);
|
||||||
|
disco_sm_items(empty, From, To, Node, Lang) ->
|
||||||
|
disco_sm_items({result, []}, From, To, Node, Lang);
|
||||||
|
disco_sm_items({result, OtherItems}, From, To, Node, _Lang) ->
|
||||||
|
{result,
|
||||||
|
lists:usort(OtherItems ++
|
||||||
|
disco_items(jlib:jid_tolower(jlib:jid_remove_resource(To)), Node, From))};
|
||||||
|
disco_sm_items(Acc, _From, _To, _Node, _Lang) ->
|
||||||
|
Acc.
|
||||||
|
|
||||||
|
disco_items(Host, <<>>, From) ->
|
||||||
|
Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx}, Acc) ->
|
||||||
|
Owners = node_owners_call(Type, Idx),
|
||||||
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
|
{result, _} ->
|
||||||
|
[{xmlelement, "item",
|
||||||
|
[{"node", binary_to_list(NodeID)},
|
||||||
|
{"jid", case Host of
|
||||||
|
{_,_,_} -> jlib:jid_to_string(Host);
|
||||||
|
_Host -> Host
|
||||||
|
end}
|
||||||
|
| case get_option(Options, title) of
|
||||||
|
false -> [];
|
||||||
|
[Title] -> [{"name", Title}]
|
||||||
|
end],
|
||||||
|
[]}
|
||||||
|
| Acc];
|
||||||
|
_ -> Acc
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
case transaction_on_nodes(Host, Action, sync_dirty) of
|
||||||
|
{result, Items} -> Items;
|
||||||
|
_ -> []
|
||||||
end;
|
end;
|
||||||
|
|
||||||
disco_sm_items(Acc, From, To, SNode, _Lang) ->
|
disco_items(Host, Node, From) ->
|
||||||
Host = To#jid.lserver,
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
Node = string_to_node(SNode),
|
Owners = node_owners_call(Type, Idx),
|
||||||
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
% TODO call get_items/6 instead for access control (EJAB-1033)
|
{result, Items} ->
|
||||||
case node_call(Type, get_items, [NodeId, From]) of
|
{result, [{xmlelement, "item",
|
||||||
{result, []} ->
|
[{"jid", case Host of
|
||||||
none;
|
{_,_,_} -> jlib:jid_to_string(Host);
|
||||||
{result, AllItems} ->
|
_Host -> Host
|
||||||
SBJID = jlib:jid_to_string(jlib:jid_remove_resource(To)),
|
end},
|
||||||
Items = case Acc of
|
{"name", ItemID}], []}
|
||||||
{result, I} -> I;
|
|| #pubsub_item{itemid = {ItemID,_}} <- Items]};
|
||||||
_ -> []
|
_ -> {result, []}
|
||||||
end,
|
end
|
||||||
NodeItems = lists:map(
|
end,
|
||||||
fun(#pubsub_item{itemid = {Id, _}}) ->
|
|
||||||
{result, Name} = node_call(Type, get_item_name, [Host, Node, Id]),
|
|
||||||
{xmlelement, "item", [{"jid", SBJID}, {"name", Name}], []}
|
|
||||||
end, AllItems),
|
|
||||||
{result, NodeItems ++ Items};
|
|
||||||
_ ->
|
|
||||||
none
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
case transaction(Host, Node, Action, sync_dirty) of
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
{result, {_, Items}} -> {result, Items};
|
{result, {_, Result}} -> Result;
|
||||||
_ -> Acc
|
_ -> []
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
@ -661,25 +699,23 @@ terminate(_Reason, #state{host = Host,
|
|||||||
case lists:member(?PEPNODE, Plugins) of
|
case lists:member(?PEPNODE, Plugins) of
|
||||||
true ->
|
true ->
|
||||||
ejabberd_hooks:delete(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
ejabberd_hooks:delete(feature_check_packet, ServerHost, ?MODULE, feature_check_packet, 75),
|
||||||
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
||||||
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
||||||
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, ServerHost, ?NS_PUBSUB_OWNER);
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER);
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHost, ?MODULE, on_user_offline, 75),
|
||||||
ejabberd_hooks:delete(disco_sm_identity, ServerHost, ?MODULE, disco_sm_identity, 75),
|
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
|
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
|
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||||
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||||
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||||
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||||
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||||
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, remove_user, 50),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB),
|
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, ServerHost, ?NS_PUBSUB_OWNER),
|
|
||||||
mod_disco:unregister_feature(ServerHost, ?NS_PUBSUB),
|
mod_disco:unregister_feature(ServerHost, ?NS_PUBSUB),
|
||||||
gen_mod:get_module_proc(ServerHost, ?LOOPNAME) ! stop,
|
gen_mod:get_module_proc(ServerHost, ?LOOPNAME) ! stop,
|
||||||
terminate_plugins(Host, ServerHost, Plugins, TreePlugin).
|
terminate_plugins(Host, ServerHost, Plugins, TreePlugin).
|
||||||
@ -821,10 +857,10 @@ command_disco_info(_Host, <<?NS_PUBSUB_GET_PENDING>>, _From) ->
|
|||||||
|
|
||||||
node_disco_info(Host, Node, From) ->
|
node_disco_info(Host, Node, From) ->
|
||||||
node_disco_info(Host, Node, From, true, true).
|
node_disco_info(Host, Node, From, true, true).
|
||||||
node_disco_identity(Host, Node, From) ->
|
%node_disco_identity(Host, Node, From) ->
|
||||||
node_disco_info(Host, Node, From, true, false).
|
% node_disco_info(Host, Node, From, true, false).
|
||||||
node_disco_features(Host, Node, From) ->
|
%node_disco_features(Host, Node, From) ->
|
||||||
node_disco_info(Host, Node, From, false, true).
|
% node_disco_info(Host, Node, From, false, true).
|
||||||
node_disco_info(Host, Node, From, Identity, Features) ->
|
node_disco_info(Host, Node, From, Identity, Features) ->
|
||||||
Action =
|
Action =
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
@ -926,17 +962,16 @@ iq_disco_items(Host, Item, From, RSM) ->
|
|||||||
{result, []};
|
{result, []};
|
||||||
[SNode] ->
|
[SNode] ->
|
||||||
Node = string_to_node(SNode),
|
Node = string_to_node(SNode),
|
||||||
Action =
|
Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
Owners = node_owners_call(Type, Idx),
|
||||||
%% TODO call get_items/6 instead for access control (EJAB-1033)
|
{NodeItems, RsmOut} = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners, RSM) of
|
||||||
{NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
|
{result, R} -> R;
|
||||||
{result, I} -> I;
|
_ -> {[], none}
|
||||||
_ -> {[], none}
|
end,
|
||||||
end,
|
|
||||||
Nodes = lists:map(
|
Nodes = lists:map(
|
||||||
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
|
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
|
||||||
Attrs =
|
Attrs =
|
||||||
case get_option(Options, title) of
|
case get_option(SubOptions, title) of
|
||||||
false ->
|
false ->
|
||||||
[{"jid", Host} |nodeAttr(SubNode)];
|
[{"jid", Host} |nodeAttr(SubNode)];
|
||||||
Title ->
|
Title ->
|
||||||
@ -957,24 +992,6 @@ iq_disco_items(Host, Item, From, RSM) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
iq_local(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
|
|
||||||
ServerHost = To#jid.lserver,
|
|
||||||
%% Accept IQs to server only from our own users.
|
|
||||||
if
|
|
||||||
From#jid.lserver /= ServerHost ->
|
|
||||||
IQ#iq{type = error, sub_el = [?ERR_FORBIDDEN, SubEl]};
|
|
||||||
true ->
|
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(From)),
|
|
||||||
Res = case XMLNS of
|
|
||||||
?NS_PUBSUB -> iq_pubsub(LOwner, ServerHost, From, Type, SubEl, Lang);
|
|
||||||
?NS_PUBSUB_OWNER -> iq_pubsub_owner(LOwner, ServerHost, From, Type, SubEl, Lang)
|
|
||||||
end,
|
|
||||||
case Res of
|
|
||||||
{result, IQRes} -> IQ#iq{type = result, sub_el = IQRes};
|
|
||||||
{error, Error} -> IQ#iq{type = error, sub_el = [Error, SubEl]}
|
|
||||||
end
|
|
||||||
end.
|
|
||||||
|
|
||||||
iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
|
iq_sm(From, To, #iq{type = Type, sub_el = SubEl, xmlns = XMLNS, lang = Lang} = IQ) ->
|
||||||
ServerHost = To#jid.lserver,
|
ServerHost = To#jid.lserver,
|
||||||
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
LOwner = jlib:jid_tolower(jlib:jid_remove_resource(To)),
|
||||||
@ -1687,25 +1704,8 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
|
|||||||
AccessModel = get_option(Options, access_model),
|
AccessModel = get_option(Options, access_model),
|
||||||
SendLast = get_option(Options, send_last_published_item),
|
SendLast = get_option(Options, send_last_published_item),
|
||||||
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
{PresenceSubscription, RosterGroup} =
|
Owners = node_owners_call(Type, NodeId),
|
||||||
case Host of
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
|
||||||
{OUser, OServer, _} ->
|
|
||||||
get_roster_info(OUser, OServer,
|
|
||||||
Subscriber, AllowedGroups);
|
|
||||||
_ ->
|
|
||||||
case Subscriber of
|
|
||||||
{"", "", ""} ->
|
|
||||||
{false, false};
|
|
||||||
_ ->
|
|
||||||
case node_owners_call(Type, NodeId) of
|
|
||||||
[{OU, OS, _}|_] ->
|
|
||||||
get_roster_info(OU, OS,
|
|
||||||
Subscriber, AllowedGroups);
|
|
||||||
_ ->
|
|
||||||
{false, false}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
if
|
if
|
||||||
not SubscribeFeature ->
|
not SubscribeFeature ->
|
||||||
%% Node does not support subscriptions
|
%% Node does not support subscriptions
|
||||||
@ -2054,14 +2054,8 @@ get_items(Host, Node, From, SubId, SMaxItems, ItemIDs, RSM) ->
|
|||||||
PersistentFeature = lists:member("persistent-items", Features),
|
PersistentFeature = lists:member("persistent-items", Features),
|
||||||
AccessModel = get_option(Options, access_model),
|
AccessModel = get_option(Options, access_model),
|
||||||
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
{PresenceSubscription, RosterGroup} =
|
Owners = node_owners_call(Type, NodeId),
|
||||||
case Host of
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
{OUser, OServer, _} ->
|
|
||||||
get_roster_info(OUser, OServer,
|
|
||||||
jlib:jid_tolower(From), AllowedGroups);
|
|
||||||
_ ->
|
|
||||||
{true, true}
|
|
||||||
end,
|
|
||||||
if
|
if
|
||||||
not RetreiveFeature ->
|
not RetreiveFeature ->
|
||||||
%% Item Retrieval Not Supported
|
%% Item Retrieval Not Supported
|
||||||
@ -2112,6 +2106,17 @@ get_item(Host, Node, ItemId) ->
|
|||||||
{result, {_, Items}} -> Items;
|
{result, {_, Items}} -> Items;
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
|
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
|
||||||
|
case get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, none) of
|
||||||
|
{result, {I, _}} -> {result, I};
|
||||||
|
Error -> Error
|
||||||
|
end.
|
||||||
|
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, RSM) ->
|
||||||
|
AccessModel = get_option(Options, access_model),
|
||||||
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
|
node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined, RSM]).
|
||||||
|
|
||||||
|
|
||||||
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
||||||
%% Host = pubsubHost()
|
%% Host = pubsubHost()
|
||||||
@ -2584,8 +2589,24 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups) ->
|
||||||
|
if (AccessModel == presence) or (AccessModel == roster) ->
|
||||||
|
case Host of
|
||||||
|
{User, Server, _} ->
|
||||||
|
get_roster_info(User, Server, From, AllowedGroups);
|
||||||
|
_ ->
|
||||||
|
[{OUser, OServer, _}|_] = Owners,
|
||||||
|
get_roster_info(OUser, OServer, From, AllowedGroups)
|
||||||
|
end;
|
||||||
|
true ->
|
||||||
|
{true, true}
|
||||||
|
end.
|
||||||
|
|
||||||
%% @spec (OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, SubscriberResource}, AllowedGroups)
|
%% @spec (OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, SubscriberResource}, AllowedGroups)
|
||||||
%% -> {PresenceSubscription, RosterGroup}
|
%% -> {PresenceSubscription, RosterGroup}
|
||||||
|
get_roster_info(_, _, {"", "", _}, _) ->
|
||||||
|
{false, false};
|
||||||
get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) ->
|
get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, AllowedGroups) ->
|
||||||
{Subscription, Groups} =
|
{Subscription, Groups} =
|
||||||
ejabberd_hooks:run_fold(
|
ejabberd_hooks:run_fold(
|
||||||
@ -2597,7 +2618,9 @@ get_roster_info(OwnerUser, OwnerServer, {SubscriberUser, SubscriberServer, _}, A
|
|||||||
RosterGroup = lists:any(fun(Group) ->
|
RosterGroup = lists:any(fun(Group) ->
|
||||||
lists:member(Group, AllowedGroups)
|
lists:member(Group, AllowedGroups)
|
||||||
end, Groups),
|
end, Groups),
|
||||||
{PresenceSubscription, RosterGroup}.
|
{PresenceSubscription, RosterGroup};
|
||||||
|
get_roster_info(OwnerUser, OwnerServer, JID, AllowedGroups) ->
|
||||||
|
get_roster_info(OwnerUser, OwnerServer, jlib:jid_tolower(JID), AllowedGroups).
|
||||||
|
|
||||||
%% @spec (AffiliationStr) -> Affiliation
|
%% @spec (AffiliationStr) -> Affiliation
|
||||||
%% AffiliationStr = string()
|
%% AffiliationStr = string()
|
||||||
@ -3582,6 +3605,10 @@ transaction(Host, Node, Action, Trans) ->
|
|||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
end, Trans).
|
end, Trans).
|
||||||
|
transaction_on_nodes(Host, Action, Trans) ->
|
||||||
|
transaction(Host, fun() ->
|
||||||
|
{result, lists:foldl(Action, [], tree_call(Host, get_nodes, [Host]))}
|
||||||
|
end, Trans).
|
||||||
|
|
||||||
transaction(Host, Fun, Trans) ->
|
transaction(Host, Fun, Trans) ->
|
||||||
transaction_retry(Host, Fun, Trans, 2).
|
transaction_retry(Host, Fun, Trans, 2).
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--- mod_pubsub.erl 2010-06-02 15:03:48.000000000 +0200
|
--- mod_pubsub.erl 2010-08-02 16:07:28.000000000 +0200
|
||||||
+++ mod_pubsub_odbc.erl 2010-06-02 16:45:38.000000000 +0200
|
+++ mod_pubsub_odbc.erl 2010-08-02 17:04:37.000000000 +0200
|
||||||
@@ -42,7 +42,7 @@
|
@@ -42,7 +42,7 @@
|
||||||
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
|
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
|
||||||
%%% XEP-0060 section 12.18.
|
%%% XEP-0060 section 12.18.
|
||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
%% exports for hooks
|
%% exports for hooks
|
||||||
-export([presence_probe/3,
|
-export([presence_probe/3,
|
||||||
@@ -104,7 +104,7 @@
|
@@ -103,7 +103,7 @@
|
||||||
string_to_affiliation/1,
|
string_to_affiliation/1,
|
||||||
extended_error/2,
|
extended_error/2,
|
||||||
extended_error/3,
|
extended_error/3,
|
||||||
@ -31,7 +31,7 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
%% API and gen_server callbacks
|
%% API and gen_server callbacks
|
||||||
@@ -123,7 +123,7 @@
|
@@ -122,7 +122,7 @@
|
||||||
-export([send_loop/1
|
-export([send_loop/1
|
||||||
]).
|
]).
|
||||||
|
|
||||||
@ -40,7 +40,7 @@
|
|||||||
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
|
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
|
||||||
-define(PLUGIN_PREFIX, "node_").
|
-define(PLUGIN_PREFIX, "node_").
|
||||||
-define(TREE_PREFIX, "nodetree_").
|
-define(TREE_PREFIX, "nodetree_").
|
||||||
@@ -220,8 +220,6 @@
|
@@ -217,8 +217,6 @@
|
||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
ejabberd_router:register_route(Host),
|
ejabberd_router:register_route(Host),
|
||||||
@ -49,7 +49,7 @@
|
|||||||
init_nodes(Host, ServerHost, NodeTree, Plugins),
|
init_nodes(Host, ServerHost, NodeTree, Plugins),
|
||||||
State = #state{host = Host,
|
State = #state{host = Host,
|
||||||
server_host = ServerHost,
|
server_host = ServerHost,
|
||||||
@@ -280,207 +278,14 @@
|
@@ -277,207 +275,14 @@
|
||||||
|
|
||||||
init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
|
init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
|
||||||
%% TODO, this call should be done plugin side
|
%% TODO, this call should be done plugin side
|
||||||
@ -260,7 +260,7 @@
|
|||||||
send_loop(State) ->
|
send_loop(State) ->
|
||||||
receive
|
receive
|
||||||
{presence, JID, Pid} ->
|
{presence, JID, Pid} ->
|
||||||
@@ -491,17 +296,15 @@
|
@@ -488,17 +293,15 @@
|
||||||
%% for each node From is subscribed to
|
%% for each node From is subscribed to
|
||||||
%% and if the node is so configured, send the last published item to From
|
%% and if the node is so configured, send the last published item to From
|
||||||
lists:foreach(fun(PType) ->
|
lists:foreach(fun(PType) ->
|
||||||
@ -284,7 +284,54 @@
|
|||||||
true ->
|
true ->
|
||||||
% resource not concerned about that subscription
|
% resource not concerned about that subscription
|
||||||
ok
|
ok
|
||||||
@@ -747,10 +550,10 @@
|
@@ -617,7 +420,8 @@
|
||||||
|
disco_identity(_Host, <<>>, _From) ->
|
||||||
|
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
|
||||||
|
disco_identity(Host, Node, From) ->
|
||||||
|
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
|
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
|
+ Owners = node_owners_call(Type, Idx),
|
||||||
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
|
{result, _} ->
|
||||||
|
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
|
||||||
|
@@ -652,7 +456,8 @@
|
||||||
|
[?NS_PUBSUB
|
||||||
|
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
|
||||||
|
disco_features(Host, Node, From) ->
|
||||||
|
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
|
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
|
+ Owners = node_owners_call(Type, Idx),
|
||||||
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
|
{result, _} ->
|
||||||
|
{result, [?NS_PUBSUB
|
||||||
|
@@ -677,7 +482,8 @@
|
||||||
|
Acc.
|
||||||
|
|
||||||
|
disco_items(Host, <<>>, From) ->
|
||||||
|
- Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx, owners = Owners}, Acc) ->
|
||||||
|
+ Action = fun(#pubsub_node{nodeid ={_, NodeID}, options = Options, type = Type, id = Idx}, Acc) ->
|
||||||
|
+ Owners = node_owners_call(Type, Idx),
|
||||||
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
|
{result, _} ->
|
||||||
|
[{xmlelement, "item",
|
||||||
|
@@ -695,13 +501,14 @@
|
||||||
|
_ -> Acc
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
- case transaction(Host, Action, sync_dirty) of
|
||||||
|
+ case transaction_on_nodes(Host, Action, sync_dirty) of
|
||||||
|
{result, Items} -> Items;
|
||||||
|
_ -> []
|
||||||
|
end;
|
||||||
|
|
||||||
|
disco_items(Host, Node, From) ->
|
||||||
|
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
|
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
|
+ Owners = node_owners_call(Type, Idx),
|
||||||
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
|
{result, Items} ->
|
||||||
|
{result, [{xmlelement, "item",
|
||||||
|
@@ -781,10 +588,10 @@
|
||||||
lists:foreach(fun(PType) ->
|
lists:foreach(fun(PType) ->
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
||||||
lists:foreach(fun
|
lists:foreach(fun
|
||||||
@ -297,7 +344,7 @@
|
|||||||
true ->
|
true ->
|
||||||
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
||||||
false ->
|
false ->
|
||||||
@@ -920,7 +723,8 @@
|
@@ -952,7 +759,8 @@
|
||||||
sub_el = SubEl} = IQ ->
|
sub_el = SubEl} = IQ ->
|
||||||
{xmlelement, _, QAttrs, _} = SubEl,
|
{xmlelement, _, QAttrs, _} = SubEl,
|
||||||
Node = xml:get_attr_s("node", QAttrs),
|
Node = xml:get_attr_s("node", QAttrs),
|
||||||
@ -307,7 +354,7 @@
|
|||||||
{result, IQRes} ->
|
{result, IQRes} ->
|
||||||
jlib:iq_to_xml(
|
jlib:iq_to_xml(
|
||||||
IQ#iq{type = result,
|
IQ#iq{type = result,
|
||||||
@@ -1033,7 +837,7 @@
|
@@ -1065,7 +873,7 @@
|
||||||
[] ->
|
[] ->
|
||||||
["leaf"]; %% No sub-nodes: it's a leaf node
|
["leaf"]; %% No sub-nodes: it's a leaf node
|
||||||
_ ->
|
_ ->
|
||||||
@ -316,7 +363,7 @@
|
|||||||
{result, []} -> ["collection"];
|
{result, []} -> ["collection"];
|
||||||
{result, _} -> ["leaf", "collection"];
|
{result, _} -> ["leaf", "collection"];
|
||||||
_ -> []
|
_ -> []
|
||||||
@@ -1049,8 +853,9 @@
|
@@ -1081,8 +889,9 @@
|
||||||
[];
|
[];
|
||||||
true ->
|
true ->
|
||||||
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
||||||
@ -328,7 +375,7 @@
|
|||||||
end, features(Type))]
|
end, features(Type))]
|
||||||
end,
|
end,
|
||||||
%% TODO: add meta-data info (spec section 5.4)
|
%% TODO: add meta-data info (spec section 5.4)
|
||||||
@@ -1079,8 +884,9 @@
|
@@ -1111,8 +920,9 @@
|
||||||
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
|
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
|
||||||
{xmlelement, "feature", [{"var", ?NS_COMMANDS}], []},
|
{xmlelement, "feature", [{"var", ?NS_COMMANDS}], []},
|
||||||
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
|
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
|
||||||
@ -340,7 +387,7 @@
|
|||||||
end, features(Host, Node))};
|
end, features(Host, Node))};
|
||||||
<<?NS_COMMANDS>> ->
|
<<?NS_COMMANDS>> ->
|
||||||
command_disco_info(Host, Node, From);
|
command_disco_info(Host, Node, From);
|
||||||
@@ -1090,7 +896,7 @@
|
@@ -1122,7 +932,7 @@
|
||||||
node_disco_info(Host, Node, From)
|
node_disco_info(Host, Node, From)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -349,7 +396,7 @@
|
|||||||
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
|
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
|
||||||
Nodes when is_list(Nodes) ->
|
Nodes when is_list(Nodes) ->
|
||||||
{result, lists:map(
|
{result, lists:map(
|
||||||
@@ -1107,14 +913,14 @@
|
@@ -1139,23 +949,24 @@
|
||||||
Other ->
|
Other ->
|
||||||
Other
|
Other
|
||||||
end;
|
end;
|
||||||
@ -367,21 +414,20 @@
|
|||||||
case string:tokens(Item, "!") of
|
case string:tokens(Item, "!") of
|
||||||
[_SNode, _ItemID] ->
|
[_SNode, _ItemID] ->
|
||||||
{result, []};
|
{result, []};
|
||||||
@@ -1122,10 +928,10 @@
|
[SNode] ->
|
||||||
Node = string_to_node(SNode),
|
Node = string_to_node(SNode),
|
||||||
Action =
|
- Action = fun(#pubsub_node{id = Idx, type = Type, options = Options, owners = Owners}) ->
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
- NodeItems = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
- % TODO call get_items/6 instead for access control (EJAB-1033)
|
+ Action = fun(#pubsub_node{id = Idx, type = Type, options = Options}) ->
|
||||||
- NodeItems = case node_call(Type, get_items, [NodeId, From]) of
|
+ Owners = node_owners_call(Type, Idx),
|
||||||
+ %% TODO call get_items/6 instead for access control (EJAB-1033)
|
+ {NodeItems, RsmOut} = case get_allowed_items_call(Host, Idx, From, Type, Options, Owners, RSM) of
|
||||||
+ {NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
|
{result, R} -> R;
|
||||||
{result, I} -> I;
|
- _ -> []
|
||||||
- _ -> []
|
+ _ -> {[], none}
|
||||||
+ _ -> {[], none}
|
end,
|
||||||
end,
|
|
||||||
Nodes = lists:map(
|
Nodes = lists:map(
|
||||||
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
|
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
|
||||||
@@ -1143,7 +949,7 @@
|
@@ -1173,7 +984,7 @@
|
||||||
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
|
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
|
||||||
{xmlelement, "item", [{"jid", Host}, {"name", Name}], []}
|
{xmlelement, "item", [{"jid", Host}, {"name", Name}], []}
|
||||||
end, NodeItems),
|
end, NodeItems),
|
||||||
@ -390,7 +436,7 @@
|
|||||||
end,
|
end,
|
||||||
case transaction(Host, Node, Action, sync_dirty) of
|
case transaction(Host, Node, Action, sync_dirty) of
|
||||||
{result, {_, Result}} -> {result, Result};
|
{result, {_, Result}} -> {result, Result};
|
||||||
@@ -1272,7 +1078,8 @@
|
@@ -1284,7 +1095,8 @@
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
end, [], xml:remove_cdata(Els)),
|
end, [], xml:remove_cdata(Els)),
|
||||||
@ -400,7 +446,7 @@
|
|||||||
{get, "subscriptions"} ->
|
{get, "subscriptions"} ->
|
||||||
get_subscriptions(Host, Node, From, Plugins);
|
get_subscriptions(Host, Node, From, Plugins);
|
||||||
{get, "affiliations"} ->
|
{get, "affiliations"} ->
|
||||||
@@ -1295,7 +1102,9 @@
|
@@ -1307,7 +1119,9 @@
|
||||||
|
|
||||||
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
||||||
{xmlelement, _, _, SubEls} = SubEl,
|
{xmlelement, _, _, SubEls} = SubEl,
|
||||||
@ -411,7 +457,7 @@
|
|||||||
case Action of
|
case Action of
|
||||||
[{xmlelement, Name, Attrs, Els}] ->
|
[{xmlelement, Name, Attrs, Els}] ->
|
||||||
Node = string_to_node(xml:get_attr_s("node", Attrs)),
|
Node = string_to_node(xml:get_attr_s("node", Attrs)),
|
||||||
@@ -1425,7 +1234,8 @@
|
@@ -1437,7 +1251,8 @@
|
||||||
_ -> []
|
_ -> []
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@ -421,7 +467,7 @@
|
|||||||
sync_dirty) of
|
sync_dirty) of
|
||||||
{result, Res} -> Res;
|
{result, Res} -> Res;
|
||||||
Err -> Err
|
Err -> Err
|
||||||
@@ -1464,7 +1274,7 @@
|
@@ -1476,7 +1291,7 @@
|
||||||
|
|
||||||
%%% authorization handling
|
%%% authorization handling
|
||||||
|
|
||||||
@ -430,7 +476,7 @@
|
|||||||
Lang = "en", %% TODO fix
|
Lang = "en", %% TODO fix
|
||||||
Stanza = {xmlelement, "message",
|
Stanza = {xmlelement, "message",
|
||||||
[],
|
[],
|
||||||
@@ -1493,7 +1303,7 @@
|
@@ -1505,7 +1320,7 @@
|
||||||
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
|
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
|
||||||
lists:foreach(fun(Owner) ->
|
lists:foreach(fun(Owner) ->
|
||||||
ejabberd_router:route(service_jid(Host), jlib:make_jid(Owner), Stanza)
|
ejabberd_router:route(service_jid(Host), jlib:make_jid(Owner), Stanza)
|
||||||
@ -439,7 +485,7 @@
|
|||||||
|
|
||||||
find_authorization_response(Packet) ->
|
find_authorization_response(Packet) ->
|
||||||
{xmlelement, _Name, _Attrs, Els} = Packet,
|
{xmlelement, _Name, _Attrs, Els} = Packet,
|
||||||
@@ -1557,8 +1367,8 @@
|
@@ -1569,8 +1384,8 @@
|
||||||
"true" -> true;
|
"true" -> true;
|
||||||
_ -> false
|
_ -> false
|
||||||
end,
|
end,
|
||||||
@ -450,7 +496,7 @@
|
|||||||
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
|
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
|
||||||
if
|
if
|
||||||
not IsApprover ->
|
not IsApprover ->
|
||||||
@@ -1757,7 +1567,7 @@
|
@@ -1769,7 +1584,7 @@
|
||||||
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
[{xmlelement, "create", nodeAttr(Node),
|
[{xmlelement, "create", nodeAttr(Node),
|
||||||
[]}]}],
|
[]}]}],
|
||||||
@ -459,7 +505,7 @@
|
|||||||
{result, {NodeId, SubsByDepth, {Result, broadcast}}} ->
|
{result, {NodeId, SubsByDepth, {Result, broadcast}}} ->
|
||||||
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth),
|
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions, SubsByDepth),
|
||||||
case Result of
|
case Result of
|
||||||
@@ -1860,7 +1670,7 @@
|
@@ -1872,7 +1687,7 @@
|
||||||
%%<li>The node does not exist.</li>
|
%%<li>The node does not exist.</li>
|
||||||
%%</ul>
|
%%</ul>
|
||||||
subscribe_node(Host, Node, From, JID, Configuration) ->
|
subscribe_node(Host, Node, From, JID, Configuration) ->
|
||||||
@ -468,33 +514,24 @@
|
|||||||
{result, GoodSubOpts} -> GoodSubOpts;
|
{result, GoodSubOpts} -> GoodSubOpts;
|
||||||
_ -> invalid
|
_ -> invalid
|
||||||
end,
|
end,
|
||||||
@@ -1868,7 +1678,7 @@
|
@@ -1880,7 +1695,7 @@
|
||||||
error -> {"", "", ""};
|
error -> {"", "", ""};
|
||||||
J -> jlib:jid_tolower(J)
|
J -> jlib:jid_tolower(J)
|
||||||
end,
|
end,
|
||||||
- Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) ->
|
- Action = fun(#pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId}) ->
|
||||||
+ Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
|
+ Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
|
||||||
Features = features(Type),
|
Features = features(Type),
|
||||||
SubscribeFeature = lists:member("subscribe", Features),
|
SubscribeFeature = lists:member("subscribe", Features),
|
||||||
OptionsFeature = lists:member("subscription-options", Features),
|
OptionsFeature = lists:member("subscription-options", Features),
|
||||||
@@ -1887,9 +1697,13 @@
|
@@ -1889,6 +1704,7 @@
|
||||||
{"", "", ""} ->
|
AccessModel = get_option(Options, access_model),
|
||||||
{false, false};
|
SendLast = get_option(Options, send_last_published_item),
|
||||||
_ ->
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
- {OU, OS, _} = Owner,
|
+ Owners = node_owners_call(Type, NodeId),
|
||||||
- get_roster_info(OU, OS,
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
|
||||||
- Subscriber, AllowedGroups)
|
|
||||||
+ case node_owners_call(Type, NodeId) of
|
|
||||||
+ [{OU, OS, _}|_] ->
|
|
||||||
+ get_roster_info(OU, OS,
|
|
||||||
+ Subscriber, AllowedGroups);
|
|
||||||
+ _ ->
|
|
||||||
+ {false, false}
|
|
||||||
+ end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
if
|
if
|
||||||
@@ -2220,7 +2034,7 @@
|
not SubscribeFeature ->
|
||||||
|
@@ -2218,7 +2034,7 @@
|
||||||
%% <p>The permission are not checked in this function.</p>
|
%% <p>The permission are not checked in this function.</p>
|
||||||
%% @todo We probably need to check that the user doing the query has the right
|
%% @todo We probably need to check that the user doing the query has the right
|
||||||
%% to read the items.
|
%% to read the items.
|
||||||
@ -503,7 +540,22 @@
|
|||||||
MaxItems =
|
MaxItems =
|
||||||
if
|
if
|
||||||
SMaxItems == "" -> get_max_items_node(Host);
|
SMaxItems == "" -> get_max_items_node(Host);
|
||||||
@@ -2259,11 +2073,11 @@
|
@@ -2232,12 +2048,13 @@
|
||||||
|
{error, Error} ->
|
||||||
|
{error, Error};
|
||||||
|
_ ->
|
||||||
|
- Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId, owners = Owners}) ->
|
||||||
|
+ Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
|
||||||
|
Features = features(Type),
|
||||||
|
RetreiveFeature = lists:member("retrieve-items", Features),
|
||||||
|
PersistentFeature = lists:member("persistent-items", Features),
|
||||||
|
AccessModel = get_option(Options, access_model),
|
||||||
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
|
+ Owners = node_owners_call(Type, NodeId),
|
||||||
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
|
if
|
||||||
|
not RetreiveFeature ->
|
||||||
|
@@ -2250,11 +2067,11 @@
|
||||||
node_call(Type, get_items,
|
node_call(Type, get_items,
|
||||||
[NodeId, From,
|
[NodeId, From,
|
||||||
AccessModel, PresenceSubscription, RosterGroup,
|
AccessModel, PresenceSubscription, RosterGroup,
|
||||||
@ -517,7 +569,7 @@
|
|||||||
SendItems = case ItemIDs of
|
SendItems = case ItemIDs of
|
||||||
[] ->
|
[] ->
|
||||||
Items;
|
Items;
|
||||||
@@ -2276,7 +2090,8 @@
|
@@ -2267,7 +2084,8 @@
|
||||||
%% number of items sent to MaxItems:
|
%% number of items sent to MaxItems:
|
||||||
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
[{xmlelement, "items", nodeAttr(Node),
|
[{xmlelement, "items", nodeAttr(Node),
|
||||||
@ -527,7 +579,24 @@
|
|||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
@@ -2308,16 +2123,27 @@
|
@@ -2289,10 +2107,15 @@
|
||||||
|
Error -> Error
|
||||||
|
end.
|
||||||
|
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
|
||||||
|
+ case get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, none) of
|
||||||
|
+ {result, {I, _}} -> {result, I};
|
||||||
|
+ Error -> Error
|
||||||
|
+ end.
|
||||||
|
+get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners, RSM) ->
|
||||||
|
AccessModel = get_option(Options, access_model),
|
||||||
|
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||||
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
|
- node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined]).
|
||||||
|
+ node_call(Type, get_items, [NodeIdx, From, AccessModel, PresenceSubscription, RosterGroup, undefined, RSM]).
|
||||||
|
|
||||||
|
|
||||||
|
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
||||||
|
@@ -2305,16 +2128,27 @@
|
||||||
%% @doc <p>Resend the items of a node to the user.</p>
|
%% @doc <p>Resend the items of a node to the user.</p>
|
||||||
%% @todo use cache-last-item feature
|
%% @todo use cache-last-item feature
|
||||||
send_items(Host, Node, NodeId, Type, LJID, last) ->
|
send_items(Host, Node, NodeId, Type, LJID, last) ->
|
||||||
@ -561,7 +630,7 @@
|
|||||||
send_items(Host, Node, NodeId, Type, LJID, Number) ->
|
send_items(Host, Node, NodeId, Type, LJID, Number) ->
|
||||||
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
||||||
{result, []} ->
|
{result, []} ->
|
||||||
@@ -2443,7 +2269,8 @@
|
@@ -2440,7 +2274,8 @@
|
||||||
error ->
|
error ->
|
||||||
{error, ?ERR_BAD_REQUEST};
|
{error, ?ERR_BAD_REQUEST};
|
||||||
_ ->
|
_ ->
|
||||||
@ -571,7 +640,7 @@
|
|||||||
case lists:member(Owner, Owners) of
|
case lists:member(Owner, Owners) of
|
||||||
true ->
|
true ->
|
||||||
OwnerJID = jlib:make_jid(Owner),
|
OwnerJID = jlib:make_jid(Owner),
|
||||||
@@ -2453,24 +2280,7 @@
|
@@ -2450,24 +2285,7 @@
|
||||||
end,
|
end,
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({JID, Affiliation}) ->
|
fun({JID, Affiliation}) ->
|
||||||
@ -597,7 +666,7 @@
|
|||||||
end, FilteredEntities),
|
end, FilteredEntities),
|
||||||
{result, []};
|
{result, []};
|
||||||
_ ->
|
_ ->
|
||||||
@@ -2523,11 +2333,11 @@
|
@@ -2520,11 +2338,11 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
||||||
@ -611,7 +680,7 @@
|
|||||||
OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)},
|
OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)},
|
||||||
{"subid", SubID}|nodeAttr(Node)],
|
{"subid", SubID}|nodeAttr(Node)],
|
||||||
[XdataEl]},
|
[XdataEl]},
|
||||||
@@ -2553,7 +2363,7 @@
|
@@ -2550,7 +2368,7 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
||||||
@ -620,7 +689,7 @@
|
|||||||
{result, GoodSubOpts} -> GoodSubOpts;
|
{result, GoodSubOpts} -> GoodSubOpts;
|
||||||
_ -> invalid
|
_ -> invalid
|
||||||
end,
|
end,
|
||||||
@@ -2582,7 +2392,7 @@
|
@@ -2579,7 +2397,7 @@
|
||||||
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
|
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
|
||||||
{error, extended_error(?ERR_BAD_REQUEST, "invalid-options")};
|
{error, extended_error(?ERR_BAD_REQUEST, "invalid-options")};
|
||||||
write_sub(Subscriber, NodeID, SubID, Options) ->
|
write_sub(Subscriber, NodeID, SubID, Options) ->
|
||||||
@ -629,7 +698,7 @@
|
|||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
{error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
{error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
{result, _} ->
|
{result, _} ->
|
||||||
@@ -2750,8 +2560,8 @@
|
@@ -2747,8 +2565,8 @@
|
||||||
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
|
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
|
||||||
ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza)
|
ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza)
|
||||||
end,
|
end,
|
||||||
@ -640,7 +709,7 @@
|
|||||||
true ->
|
true ->
|
||||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||||
|
|
||||||
@@ -3088,7 +2898,7 @@
|
@@ -3103,7 +2921,7 @@
|
||||||
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
|
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
|
||||||
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
|
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
|
||||||
end,
|
end,
|
||||||
@ -649,7 +718,7 @@
|
|||||||
{result, CollSubs} -> CollSubs;
|
{result, CollSubs} -> CollSubs;
|
||||||
_ -> []
|
_ -> []
|
||||||
end.
|
end.
|
||||||
@@ -3102,9 +2912,9 @@
|
@@ -3117,9 +2935,9 @@
|
||||||
|
|
||||||
get_options_for_subs(NodeID, Subs) ->
|
get_options_for_subs(NodeID, Subs) ->
|
||||||
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
|
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
|
||||||
@ -661,7 +730,7 @@
|
|||||||
_ -> Acc
|
_ -> Acc
|
||||||
end;
|
end;
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
@@ -3308,6 +3118,30 @@
|
@@ -3323,6 +3141,30 @@
|
||||||
Result
|
Result
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -692,7 +761,7 @@
|
|||||||
%% @spec (Host, Options) -> MaxItems
|
%% @spec (Host, Options) -> MaxItems
|
||||||
%% Host = host()
|
%% Host = host()
|
||||||
%% Options = [Option]
|
%% Options = [Option]
|
||||||
@@ -3704,7 +3538,13 @@
|
@@ -3719,7 +3561,13 @@
|
||||||
tree_action(Host, Function, Args) ->
|
tree_action(Host, Function, Args) ->
|
||||||
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
|
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
|
||||||
Fun = fun() -> tree_call(Host, Function, Args) end,
|
Fun = fun() -> tree_call(Host, Function, Args) end,
|
||||||
@ -707,7 +776,7 @@
|
|||||||
|
|
||||||
%% @doc <p>node plugin call.</p>
|
%% @doc <p>node plugin call.</p>
|
||||||
node_call(Type, Function, Args) ->
|
node_call(Type, Function, Args) ->
|
||||||
@@ -3724,13 +3564,13 @@
|
@@ -3739,13 +3587,13 @@
|
||||||
|
|
||||||
node_action(Host, Type, Function, Args) ->
|
node_action(Host, Type, Function, Args) ->
|
||||||
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
|
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
|
||||||
@ -723,9 +792,16 @@
|
|||||||
case tree_call(Host, get_node, [Host, Node]) of
|
case tree_call(Host, get_node, [Host, Node]) of
|
||||||
N when is_record(N, pubsub_node) ->
|
N when is_record(N, pubsub_node) ->
|
||||||
case Action(N) of
|
case Action(N) of
|
||||||
@@ -3743,8 +3583,14 @@
|
@@ -3757,13 +3605,19 @@
|
||||||
|
Error
|
||||||
end
|
end
|
||||||
end, Trans).
|
end, Trans).
|
||||||
|
-transaction(Host, Action, Trans) ->
|
||||||
|
- transaction(fun() ->
|
||||||
|
+transaction_on_nodes(Host, Action, Trans) ->
|
||||||
|
+ transaction(Host, fun() ->
|
||||||
|
{result, lists:foldl(Action, [], tree_call(Host, get_nodes, [Host]))}
|
||||||
|
end, Trans).
|
||||||
|
|
||||||
-transaction(Fun, Trans) ->
|
-transaction(Fun, Trans) ->
|
||||||
- case catch mnesia:Trans(Fun) of
|
- case catch mnesia:Trans(Fun) of
|
||||||
@ -740,7 +816,7 @@
|
|||||||
{result, Result} -> {result, Result};
|
{result, Result} -> {result, Result};
|
||||||
{error, Error} -> {error, Error};
|
{error, Error} -> {error, Error};
|
||||||
{atomic, {result, Result}} -> {result, Result};
|
{atomic, {result, Result}} -> {result, Result};
|
||||||
@@ -3752,6 +3598,15 @@
|
@@ -3771,6 +3625,15 @@
|
||||||
{aborted, Reason} ->
|
{aborted, Reason} ->
|
||||||
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
|
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||||
@ -756,7 +832,7 @@
|
|||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
|
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||||
@@ -3760,6 +3615,17 @@
|
@@ -3779,6 +3642,17 @@
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user