25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Fix PEP with other domains and s2s (EJAB-825)

SVN Revision: 1982
This commit is contained in:
Christophe Romain 2009-03-10 11:13:46 +00:00
parent 4c08e65fab
commit 5ed381fc58
3 changed files with 40 additions and 60 deletions

View File

@ -1,3 +1,10 @@
2009-03-10 Christophe Romain <christophe.romain@process-one.net>
* src/mod_pubsub/mod_pubsub.erl: Fix PEP with other domains and s2s
(EJAB-825). Also fixes send last published items in subscription.
* src/mod_pubsub/node_default.erl: minor typo fix
2009-03-09 Badlop <badlop@process-one.net>
* src/tls/tls_drv.c: Fix to support OpenSSL older than

View File

@ -55,7 +55,7 @@
%% exports for hooks
-export([presence_probe/3,
in_subscription/6,
out_subscription/4,
remove_user/2,
disco_local_identity/5,
disco_local_features/5,
@ -165,7 +165,7 @@ init([ServerHost, Opts]) ->
ejabberd_hooks:add(disco_sm_features, ServerHostB, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHostB, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:add(presence_probe_hook, ServerHostB, ?MODULE, presence_probe, 50),
ejabberd_hooks:add(roster_in_subscription, ServerHostB, ?MODULE, in_subscription, 50),
ejabberd_hooks:add(roster_out_subscription, ServerHostB, ?MODULE, out_subscription, 50),
ejabberd_hooks:add(remove_user, ServerHostB, ?MODULE, remove_user, 50),
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
lists:foreach(
@ -414,21 +414,33 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
%% presence hooks handling functions
%%
presence_probe(JID, JID, Pid) ->
Proc = gen_mod:get_module_proc(exmpp_jid:ldomain_as_list(JID), ?PROCNAME),
gen_server:cast(Proc, {presence, JID, Pid});
presence_probe(_, _, _) ->
ok.
presence_probe(JID, JID, _Pid) ->
{U, S, R} = jlib:short_prepd_jid(JID),
Host = S, % exmpp_jid:ldomain_as_list(JID),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:cast(Proc, {presence, JID}),
gen_server:cast(Proc, {presence, U, S, [R], JID});
presence_probe(Peer, JID, _Pid) ->
{U, S, R} = jlib:short_prepd_jid(Peer),
Host = exmpp_jid:ldomain_as_list(JID),
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:cast(Proc, {presence, U, S, [R], JID}).
%% -------
%% subscription hooks handling functions
%%
in_subscription(Acc, User, Server, JID, subscribed, _) ->
out_subscription(User, Server, JID, subscribed) ->
Owner = exmpp_jid:make_jid(User, Server, ""),
{U, S, R} = jlib:short_prepd_jid(JID),
Rs = case R of
[] -> user_resources(U, S);
_ -> [R]
end,
Proc = gen_mod:get_module_proc(Server, ?PROCNAME),
gen_server:cast(Proc, {subscribed, User, Server, JID}),
Acc;
in_subscription(Acc, _, _, _, _, _) ->
Acc.
gen_server:cast(Proc, {presence, U, S, Rs, Owner});
out_subscription(_, _, _, _) ->
ok.
%% -------
%% user remove hook handling function
@ -469,11 +481,9 @@ handle_call(stop, _From, State) ->
%% Description: Handling cast messages
%%--------------------------------------------------------------------
%% @private
handle_cast({presence, JID, Pid}, State) ->
handle_cast({presence, JID}, State) ->
%% A new resource is available. send last published items
LJID = jlib:short_prepd_jid(JID),
Host = State#state.host,
ServerHost = State#state.server_host,
%% for each node From is subscribed to
%% and if the node is so configured, send the last published item to From
lists:foreach(fun(Type) ->
@ -495,54 +505,17 @@ handle_cast({presence, JID, Pid}, State) ->
ok
end, Subscriptions)
end, State#state.plugins),
%% and send to From last PEP events published by its contacts
case catch ejabberd_c2s:get_subscribed(Pid) of
Contacts when is_list(Contacts) ->
lists:foreach(
fun({User, Server, _}) ->
Owner = {User, Server, undefined},
lists:foreach(fun(#pubsub_node{nodeid = {_, Node}, options = Options}) ->
case get_option(Options, send_last_published_item) of
on_sub_and_presence ->
case is_caps_notify(ServerHost, Node, LJID) of
true ->
Subscribed = case get_option(Options, access_model) of
open -> true;
presence -> true;
whitelist -> false; % subscribers are added manually
authorize -> false; % likewise
roster ->
Grps = get_option(Options, roster_groups_allowed, []),
element(2, get_roster_info(User, Server, LJID, Grps))
end,
if Subscribed ->
send_last_item(Owner, Node, LJID);
true ->
ok
end;
false ->
ok
end;
_ ->
ok
end
end, tree_action(Host, get_nodes, [Owner, JID]))
end, Contacts);
_ ->
ok
end,
{noreply, State};
handle_cast({subscribed, User, Server, JID}, State) ->
%% and send last PEP events published by JID
handle_cast({presence, User, Server, Resources, JID}, State) ->
%% A new resource is available. send last published PEP items
Owner = jlib:short_prepd_bare_jid(JID),
Host = State#state.host,
ServerHost = State#state.server_host,
lists:foreach(fun(#pubsub_node{nodeid = {_, Node}, options = Options}) ->
case get_option(Options, send_last_published_item) of
on_sub_and_presence ->
lists:foreach(fun(Resource) ->
LJID = jlib:short_prepd_jid(exmpp_jid:make_jid(User, Server, Resource)),
LJID = {User, Server, Resource},
case is_caps_notify(ServerHost, Node, LJID) of
true ->
Subscribed = case get_option(Options, access_model) of
@ -562,11 +535,11 @@ handle_cast({subscribed, User, Server, JID}, State) ->
false ->
ok
end
end, user_resources(User, Server));
end, Resources);
_ ->
ok
end
end, tree_action(Host, get_nodes, [Owner])),
end, tree_action(Host, get_nodes, [Owner, JID]))
{noreply, State};
handle_cast({remove_user, LUser, LServer}, State) ->
@ -634,7 +607,7 @@ terminate(_Reason, #state{host = Host,
ejabberd_hooks:delete(disco_sm_features, ServerHostB, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHostB, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:delete(presence_probe_hook, ServerHostB, ?MODULE, presence_probe, 50),
ejabberd_hooks:delete(roster_in_subscription, ServerHostB, ?MODULE, in_subscription, 50),
ejabberd_hooks:delete(roster_out_subscription, ServerHostB, ?MODULE, out_subscription, 50),
ejabberd_hooks:delete(remove_user, ServerHostB, ?MODULE, remove_user, 50),
lists:foreach(fun({NS,Mod}) ->
gen_iq_handler:remove_iq_handler(Mod, ServerHostB, NS)

View File

@ -307,7 +307,7 @@ subscribe_node(Host, Node, Sender, Subscriber, AccessModel,
(AccessModel == whitelist) and (not Whitelisted) ->
%% Node has whitelist access model and entity lacks required affiliation
{error, ?ERR_EXTENDED('not-allowed', "closed-node")};
(AccessModel == authorize) and (not Whitelisted) ->
(AccessModel == authorize) -> % TODO: to be done
%% Node has authorize access model
{error, 'forbidden'};
%%MustPay ->
@ -437,7 +437,7 @@ publish_item(Host, Node, Publisher, PublishModel, MaxItems, ItemId, Payload) ->
{error, 'forbidden'};
true ->
PubId = {SubKey, now()}, %% TODO, uses {now(),PublisherKey} for sorting (EJAB-824)
%% TODO: check creation, presence, roster (EJAB-663)
%% TODO: check creation, presence, roster
Item = case get_item(Host, Node, ItemId) of
{result, OldItem} ->
OldItem#pubsub_item{modification = PubId,