25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

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

SVN Revision: 1980
This commit is contained in:
Christophe Romain 2009-03-10 10:35:57 +00:00
parent d28efabb79
commit 51faa601fa
3 changed files with 43 additions and 66 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

@ -54,7 +54,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,
@ -163,7 +163,7 @@ init([ServerHost, Opts]) ->
ejabberd_hooks:add(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 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(remove_user, ServerHost, ?MODULE, remove_user, 50),
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
lists:foreach(
@ -413,21 +413,29 @@ disco_sm_items(Acc, From, To, Node, _Lang) ->
%% presence hooks handling functions
%%
presence_probe(#jid{lserver = Host} = JID, JID, Pid) ->
presence_probe(#jid{luser = User, lserver = Server, lresource = Resource} = JID, JID, _Pid) ->
Proc = gen_mod:get_module_proc(Server, ?PROCNAME),
gen_server:cast(Proc, {presence, JID}),
gen_server:cast(Proc, {presence, User, Server, [Resource], JID});
presence_probe(#jid{luser = User, lserver = Server, lresource = Resource}, #jid{lserver = Host} = JID, _Pid) ->
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
gen_server:cast(Proc, {presence, JID, Pid});
presence_probe(_, _, _) ->
ok.
gen_server:cast(Proc, {presence, User, Server, [Resource], JID}).
%% -------
%% subscription hooks handling functions
%%
in_subscription(Acc, User, Server, JID, subscribed, _) ->
out_subscription(User, Server, JID, subscribed) ->
Owner = jlib:make_jid(User, Server, ""),
{PUser, PServer, PResource} = jlib:jid_tolower(JID),
PResources = case PResource of
[] -> user_resources(PUser, PServer);
_ -> [PResource]
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, PUser, PServer, PResources, Owner});
out_subscription(_, _, _, _) ->
ok.
%% -------
%% user remove hook handling function
@ -468,11 +476,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:jid_tolower(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) ->
@ -494,64 +500,28 @@ 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, ""},
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
Owner = jlib:jid_tolower(jlib:jid_remove_resource(JID)),
handle_cast({presence, User, Server, Resources, JID}, State) ->
%% A new resource is available. send last published PEP items
Owner = jlib:jid_remove_resource(jlib:jid_tolower(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:jid_tolower(jlib: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
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))
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);
@ -561,11 +531,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) ->
@ -632,7 +602,7 @@ terminate(_Reason, #state{host = Host,
ejabberd_hooks:delete(disco_sm_features, ServerHost, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:delete(disco_sm_items, ServerHost, ?MODULE, disco_sm_items, 75),
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 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(remove_user, ServerHost, ?MODULE, remove_user, 50),
lists:foreach(fun({NS,Mod}) ->
gen_iq_handler:remove_iq_handler(Mod, ServerHost, NS)

View File

@ -305,7 +305,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(?ERR_NOT_ALLOWED, "closed-node")};
(AccessModel == authorize) and (not Whitelisted) ->
(AccessModel == authorize) -> % TODO: to be done
%% Node has authorize access model
{error, ?ERR_FORBIDDEN};
%%MustPay ->
@ -435,7 +435,7 @@ publish_item(Host, Node, Publisher, PublishModel, MaxItems, ItemId, Payload) ->
{error, ?ERR_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,