mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-30 16:36:29 +01:00
avoid calling gen_server on internal events (EJAB-1156)
SVN Revision: 2887
This commit is contained in:
parent
dd159242e3
commit
bb1ab19997
@ -123,6 +123,7 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
-define(PROCNAME, ejabberd_mod_pubsub).
|
-define(PROCNAME, ejabberd_mod_pubsub).
|
||||||
|
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
|
||||||
-define(PLUGIN_PREFIX, "node_").
|
-define(PLUGIN_PREFIX, "node_").
|
||||||
-define(TREE_PREFIX, "nodetree_").
|
-define(TREE_PREFIX, "nodetree_").
|
||||||
|
|
||||||
@ -202,6 +203,7 @@ init([ServerHost, Opts]) ->
|
|||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}),
|
||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}),
|
||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}),
|
||||||
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
|
||||||
ejabberd_hooks:add(disco_sm_identity, ServerHostB, ?MODULE, disco_sm_identity, 75),
|
ejabberd_hooks:add(disco_sm_identity, ServerHostB, ?MODULE, disco_sm_identity, 75),
|
||||||
ejabberd_hooks:add(disco_sm_features, ServerHostB, ?MODULE, disco_sm_features, 75),
|
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(disco_sm_items, ServerHostB, ?MODULE, disco_sm_items, 75),
|
||||||
@ -236,7 +238,8 @@ init([ServerHost, Opts]) ->
|
|||||||
max_items_node = MaxItemsNode,
|
max_items_node = MaxItemsNode,
|
||||||
nodetree = NodeTree,
|
nodetree = NodeTree,
|
||||||
plugins = Plugins},
|
plugins = Plugins},
|
||||||
SendLoop = spawn(?MODULE, send_loop, [State]),
|
SendLoop = spawn(?MODULE, send_loop, [State]), %% TODO put this in supervision
|
||||||
|
register(gen_mod:get_module_proc(ServerHost, ?LOOPNAME), SendLoop),
|
||||||
{ok, State#state{send_loop = SendLoop}}.
|
{ok, State#state{send_loop = SendLoop}}.
|
||||||
|
|
||||||
%% @spec (Host, ServerHost, Opts) -> Plugins
|
%% @spec (Host, ServerHost, Opts) -> Plugins
|
||||||
@ -479,18 +482,6 @@ update_state_database(_Host, _ServerHost) ->
|
|||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
send_queue(State, Msg) ->
|
|
||||||
Pid = State#state.send_loop,
|
|
||||||
case is_process_alive(Pid) of
|
|
||||||
true ->
|
|
||||||
Pid ! Msg,
|
|
||||||
State;
|
|
||||||
false ->
|
|
||||||
SendLoop = spawn(?MODULE, send_loop, [State]),
|
|
||||||
SendLoop ! Msg,
|
|
||||||
State#state{send_loop = SendLoop}
|
|
||||||
end.
|
|
||||||
|
|
||||||
send_loop(State) ->
|
send_loop(State) ->
|
||||||
receive
|
receive
|
||||||
{presence, JID, Pid} ->
|
{presence, JID, Pid} ->
|
||||||
@ -729,25 +720,25 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
|
|||||||
%%
|
%%
|
||||||
presence_probe(Peer, JID, Pid) ->
|
presence_probe(Peer, JID, Pid) ->
|
||||||
case exmpp_jid:full_compare(Peer, JID) of
|
case exmpp_jid:full_compare(Peer, JID) of
|
||||||
true -> %% JID are equals
|
true -> %% JID are equals
|
||||||
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
||||||
Host = exmpp_jid:prep_domain_as_list(JID),
|
presence(Server, {presence, JID, Pid}),
|
||||||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
presence(Server, {presence, User, Server, [Resource], JID});
|
||||||
gen_server:cast(Proc, {presence, JID, Pid}),
|
false ->
|
||||||
gen_server:cast(Proc, {presence, User, Server, [Resource], JID});
|
case exmpp_jid:bare_compare(Peer, JID) of
|
||||||
false ->
|
true ->
|
||||||
case exmpp_jid:bare_compare(Peer, JID) of
|
%% ignore presence_probe from other ressources for the current user
|
||||||
true ->
|
%% this way, we do not send duplicated last items if user already connected with other clients
|
||||||
%% ignore presence_probe from other ressources for the current user
|
ok;
|
||||||
%% this way, we do not send duplicated last items if user already connected with other clients
|
false ->
|
||||||
ok;
|
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
||||||
false ->
|
Host = exmpp_jid:prep_domain_as_list(JID),
|
||||||
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
presence(Host, {presence, User, Server, [Resource], JID})
|
||||||
Host = exmpp_jid:prep_domain_as_list(JID),
|
end
|
||||||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
||||||
gen_server:cast(Proc, {presence, User, Server, [Resource], JID})
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
presence(ServerHost, Presence) ->
|
||||||
|
Proc = gen_mod:get_module_proc(ServerHost, ?LOOPNAME),
|
||||||
|
Proc ! Presence.
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
%% subscription hooks handling functions
|
%% subscription hooks handling functions
|
||||||
@ -760,17 +751,39 @@ out_subscription(User, Server, JID, subscribed) ->
|
|||||||
[] -> user_resources(U, S);
|
[] -> user_resources(U, S);
|
||||||
_ -> [R]
|
_ -> [R]
|
||||||
end,
|
end,
|
||||||
Proc = gen_mod:get_module_proc(Server, ?PROCNAME),
|
presence(Server, {presence, U, S, Rs, Owner});
|
||||||
gen_server:cast(Proc, {presence, U, S, Rs, Owner});
|
|
||||||
out_subscription(_, _, _, _) ->
|
out_subscription(_, _, _, _) ->
|
||||||
ok.
|
ok.
|
||||||
in_subscription(_, User, Server, Owner, unsubscribed, _) ->
|
in_subscription(_, User, Server, Owner, unsubscribed, _) ->
|
||||||
Subscriber = exmpp_jid:make(User, Server, ""),
|
unsubscribe_user(exmpp_jid:make(User, Server, ""), Owner);
|
||||||
Proc = gen_mod:get_module_proc(Server, ?PROCNAME),
|
|
||||||
gen_server:cast(Proc, {unsubscribe, Subscriber, Owner});
|
|
||||||
in_subscription(_, _, _, _, _, _) ->
|
in_subscription(_, _, _, _, _, _) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
unsubscribe_user(Entity, Owner) ->
|
||||||
|
BJID = jlib:short_prepd_bare_jid(Owner),
|
||||||
|
Host = host(element(2, BJID)),
|
||||||
|
spawn(fun() ->
|
||||||
|
lists:foreach(fun(PType) ->
|
||||||
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
||||||
|
lists:foreach(fun
|
||||||
|
({#pubsub_node{options = Options, owners = Owners, id = NodeId}, subscribed, _, JID}) ->
|
||||||
|
case get_option(Options, access_model) of
|
||||||
|
presence ->
|
||||||
|
case lists:member(BJID, Owners) of
|
||||||
|
true ->
|
||||||
|
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
||||||
|
false ->
|
||||||
|
{result, ok}
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
{result, ok}
|
||||||
|
end;
|
||||||
|
(_) ->
|
||||||
|
ok
|
||||||
|
end, Subscriptions)
|
||||||
|
end, plugins(Host))
|
||||||
|
end).
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
%% user remove hook handling function
|
%% user remove hook handling function
|
||||||
%%
|
%%
|
||||||
@ -778,8 +791,23 @@ in_subscription(_, _, _, _, _, _) ->
|
|||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
Proc = gen_mod:get_module_proc(binary_to_list(Server), ?PROCNAME),
|
Entity = exmpp_jid:make(LUser, LServer),
|
||||||
gen_server:cast(Proc, {remove_user, LUser, LServer}).
|
Host = host(LServer),
|
||||||
|
spawn(fun() ->
|
||||||
|
%% remove user's subscriptions
|
||||||
|
lists:foreach(fun(PType) ->
|
||||||
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
||||||
|
lists:foreach(fun
|
||||||
|
({#pubsub_node{id = NodeId}, subscribed, _, JID}) -> node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
||||||
|
(_) -> ok
|
||||||
|
end, Subscriptions),
|
||||||
|
{result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Entity]),
|
||||||
|
lists:foreach(fun
|
||||||
|
({#pubsub_node{nodeid = {H, N}}, owner}) -> delete_node(H, N, Entity);
|
||||||
|
({#pubsub_node{id = NodeId}, _}) -> node_action(Host, PType, set_affiliation, [NodeId, Entity, none])
|
||||||
|
end, Affiliations)
|
||||||
|
end, plugins(Host))
|
||||||
|
end).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Function:
|
%% Function:
|
||||||
@ -810,65 +838,6 @@ handle_call(stop, _From, State) ->
|
|||||||
%% Description: Handling cast messages
|
%% Description: Handling cast messages
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @private
|
%% @private
|
||||||
handle_cast({presence, JID, Pid}, State) ->
|
|
||||||
%% A new resource is available. send last published items
|
|
||||||
{noreply, send_queue(State, {presence, JID, Pid})};
|
|
||||||
|
|
||||||
handle_cast({presence, User, Server, Resources, JID}, State) ->
|
|
||||||
%% A new resource is available. send last published PEP items
|
|
||||||
{noreply, send_queue(State, {presence, User, Server, Resources, JID})};
|
|
||||||
|
|
||||||
handle_cast({remove_user, LUser, LServer}, State) ->
|
|
||||||
spawn(fun() ->
|
|
||||||
Host = State#state.host,
|
|
||||||
Owner = exmpp_jid:make(LUser, LServer),
|
|
||||||
%% remove user's subscriptions
|
|
||||||
lists:foreach(fun(PType) ->
|
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Owner]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{nodeid = {H, N}}, subscribed, _, JID}) ->
|
|
||||||
unsubscribe_node(H, N, Owner, JID, all);
|
|
||||||
(_) ->
|
|
||||||
ok
|
|
||||||
end, Subscriptions),
|
|
||||||
{result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Owner]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{nodeid = {H, N}}, owner}) ->
|
|
||||||
delete_node(H, N, Owner);
|
|
||||||
(_) ->
|
|
||||||
ok
|
|
||||||
end, Affiliations)
|
|
||||||
end, State#state.plugins)
|
|
||||||
end),
|
|
||||||
{noreply, State};
|
|
||||||
|
|
||||||
handle_cast({unsubscribe, Subscriber, Owner}, State) ->
|
|
||||||
spawn(fun() ->
|
|
||||||
Host = State#state.host,
|
|
||||||
BJID = jlib:short_prepd_bare_jid(Owner),
|
|
||||||
lists:foreach(fun(PType) ->
|
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({Node, subscribed, _, JID}) ->
|
|
||||||
#pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId} = Node,
|
|
||||||
case get_option(Options, access_model) of
|
|
||||||
presence ->
|
|
||||||
case lists:member(BJID, Owners) of
|
|
||||||
true ->
|
|
||||||
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
|
|
||||||
false ->
|
|
||||||
{result, ok}
|
|
||||||
end;
|
|
||||||
_ ->
|
|
||||||
{result, ok}
|
|
||||||
end;
|
|
||||||
(_) ->
|
|
||||||
ok
|
|
||||||
end, Subscriptions)
|
|
||||||
end, State#state.plugins)
|
|
||||||
end),
|
|
||||||
{noreply, State};
|
|
||||||
|
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
@ -3649,8 +3618,14 @@ get_cached_item(Host, NodeId) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%%%% plugin handling
|
%%%% plugin handling
|
||||||
|
|
||||||
|
host(ServerHost) ->
|
||||||
|
case catch ets:lookup(gen_mod:get_module_proc(ServerHost, config), host) of
|
||||||
|
[{host, Host}] -> Host;
|
||||||
|
_ -> "pubsub."++ServerHost
|
||||||
|
end.
|
||||||
plugins(Host) when is_binary(Host) ->
|
plugins(Host) when is_binary(Host) ->
|
||||||
plugins(binary_to_list(Host));
|
plugins(binary_to_list(Host));
|
||||||
plugins(Host) when is_list(Host) ->
|
plugins(Host) when is_list(Host) ->
|
||||||
case catch ets:lookup(gen_mod:get_module_proc(Host, config), plugins) of
|
case catch ets:lookup(gen_mod:get_module_proc(Host, config), plugins) of
|
||||||
[{plugins, []}] -> [?STDNODE];
|
[{plugins, []}] -> [?STDNODE];
|
||||||
|
@ -123,6 +123,7 @@
|
|||||||
]).
|
]).
|
||||||
|
|
||||||
-define(PROCNAME, ejabberd_mod_pubsub_odbc).
|
-define(PROCNAME, ejabberd_mod_pubsub_odbc).
|
||||||
|
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
|
||||||
-define(PLUGIN_PREFIX, "node_").
|
-define(PLUGIN_PREFIX, "node_").
|
||||||
-define(TREE_PREFIX, "nodetree_").
|
-define(TREE_PREFIX, "nodetree_").
|
||||||
|
|
||||||
@ -202,6 +203,7 @@ init([ServerHost, Opts]) ->
|
|||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {last_item_cache, LastItemCache}),
|
||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {max_items_node, MaxItemsNode}),
|
||||||
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}),
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}),
|
||||||
|
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
|
||||||
ejabberd_hooks:add(disco_sm_identity, ServerHostB, ?MODULE, disco_sm_identity, 75),
|
ejabberd_hooks:add(disco_sm_identity, ServerHostB, ?MODULE, disco_sm_identity, 75),
|
||||||
ejabberd_hooks:add(disco_sm_features, ServerHostB, ?MODULE, disco_sm_features, 75),
|
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(disco_sm_items, ServerHostB, ?MODULE, disco_sm_items, 75),
|
||||||
@ -234,7 +236,8 @@ init([ServerHost, Opts]) ->
|
|||||||
max_items_node = MaxItemsNode,
|
max_items_node = MaxItemsNode,
|
||||||
nodetree = NodeTree,
|
nodetree = NodeTree,
|
||||||
plugins = Plugins},
|
plugins = Plugins},
|
||||||
SendLoop = spawn(?MODULE, send_loop, [State]),
|
SendLoop = spawn(?MODULE, send_loop, [State]), %% TODO put this in supervision
|
||||||
|
register(gen_mod:get_module_proc(ServerHost, ?LOOPNAME), SendLoop),
|
||||||
{ok, State#state{send_loop = SendLoop}}.
|
{ok, State#state{send_loop = SendLoop}}.
|
||||||
|
|
||||||
%% @spec (Host, ServerHost, Opts) -> Plugins
|
%% @spec (Host, ServerHost, Opts) -> Plugins
|
||||||
@ -286,18 +289,6 @@ init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
send_queue(State, Msg) ->
|
|
||||||
Pid = State#state.send_loop,
|
|
||||||
case is_process_alive(Pid) of
|
|
||||||
true ->
|
|
||||||
Pid ! Msg,
|
|
||||||
State;
|
|
||||||
false ->
|
|
||||||
SendLoop = spawn(?MODULE, send_loop, [State]),
|
|
||||||
SendLoop ! Msg,
|
|
||||||
State#state{send_loop = SendLoop}
|
|
||||||
end.
|
|
||||||
|
|
||||||
send_loop(State) ->
|
send_loop(State) ->
|
||||||
receive
|
receive
|
||||||
{presence, JID, Pid} ->
|
{presence, JID, Pid} ->
|
||||||
@ -534,25 +525,25 @@ disco_sm_items(Acc, From, To, NodeB, _Lang) ->
|
|||||||
|
|
||||||
presence_probe(Peer, JID, Pid) ->
|
presence_probe(Peer, JID, Pid) ->
|
||||||
case exmpp_jid:full_compare(Peer, JID) of
|
case exmpp_jid:full_compare(Peer, JID) of
|
||||||
true -> %% JID are equals
|
true -> %% JID are equals
|
||||||
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
||||||
Host = exmpp_jid:prep_domain_as_list(JID),
|
presence(Server, {presence, JID, Pid}),
|
||||||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
presence(Server, {presence, User, Server, [Resource], JID});
|
||||||
gen_server:cast(Proc, {presence, JID, Pid}),
|
false ->
|
||||||
gen_server:cast(Proc, {presence, User, Server, [Resource], JID});
|
case exmpp_jid:bare_compare(Peer, JID) of
|
||||||
false ->
|
true ->
|
||||||
case exmpp_jid:bare_compare(Peer, JID) of
|
%% ignore presence_probe from other ressources for the current user
|
||||||
true ->
|
%% this way, we do not send duplicated last items if user already connected with other clients
|
||||||
%% ignore presence_probe from other ressources for the current user
|
ok;
|
||||||
%% this way, we do not send duplicated last items if user already connected with other clients
|
false ->
|
||||||
ok;
|
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
||||||
false ->
|
Host = exmpp_jid:prep_domain_as_list(JID),
|
||||||
{User, Server, Resource} = jlib:short_prepd_jid(Peer),
|
presence(Host, {presence, User, Server, [Resource], JID})
|
||||||
Host = exmpp_jid:prep_domain_as_list(JID),
|
end
|
||||||
Proc = gen_mod:get_module_proc(Host, ?PROCNAME),
|
|
||||||
gen_server:cast(Proc, {presence, User, Server, [Resource], JID})
|
|
||||||
end
|
|
||||||
end.
|
end.
|
||||||
|
presence(ServerHost, Presence) ->
|
||||||
|
Proc = gen_mod:get_module_proc(ServerHost, ?LOOPNAME),
|
||||||
|
Proc ! Presence.
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
%% subscription hooks handling functions
|
%% subscription hooks handling functions
|
||||||
@ -565,17 +556,39 @@ out_subscription(User, Server, JID, subscribed) ->
|
|||||||
[] -> user_resources(U, S);
|
[] -> user_resources(U, S);
|
||||||
_ -> [R]
|
_ -> [R]
|
||||||
end,
|
end,
|
||||||
Proc = gen_mod:get_module_proc(Server, ?PROCNAME),
|
presence(Server, {presence, U, S, Rs, Owner});
|
||||||
gen_server:cast(Proc, {presence, U, S, Rs, Owner});
|
|
||||||
out_subscription(_, _, _, _) ->
|
out_subscription(_, _, _, _) ->
|
||||||
ok.
|
ok.
|
||||||
in_subscription(_, User, Server, Owner, unsubscribed, _) ->
|
in_subscription(_, User, Server, Owner, unsubscribed, _) ->
|
||||||
Subscriber = exmpp_jid:make(User, Server, ""),
|
unsubscribe_user(exmpp_jid:make(User, Server, ""), Owner);
|
||||||
Proc = gen_mod:get_module_proc(Server, ?PROCNAME),
|
|
||||||
gen_server:cast(Proc, {unsubscribe, Subscriber, Owner});
|
|
||||||
in_subscription(_, _, _, _, _, _) ->
|
in_subscription(_, _, _, _, _, _) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
unsubscribe_user(Entity, Owner) ->
|
||||||
|
BJID = jlib:short_prepd_bare_jid(Owner),
|
||||||
|
Host = host(element(2, BJID)),
|
||||||
|
spawn(fun() ->
|
||||||
|
lists:foreach(fun(PType) ->
|
||||||
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
||||||
|
lists:foreach(fun
|
||||||
|
({#pubsub_node{options = Options, id = NodeId}, subscribed, _, JID}) ->
|
||||||
|
case get_option(Options, access_model) of
|
||||||
|
presence ->
|
||||||
|
case lists:member(BJID, node_owners(Host, PType, NodeId)) of
|
||||||
|
true ->
|
||||||
|
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
||||||
|
false ->
|
||||||
|
{result, ok}
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
{result, ok}
|
||||||
|
end;
|
||||||
|
(_) ->
|
||||||
|
ok
|
||||||
|
end, Subscriptions)
|
||||||
|
end, plugins(Host))
|
||||||
|
end).
|
||||||
|
|
||||||
%% -------
|
%% -------
|
||||||
%% user remove hook handling function
|
%% user remove hook handling function
|
||||||
%%
|
%%
|
||||||
@ -583,8 +596,23 @@ in_subscription(_, _, _, _, _, _) ->
|
|||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = exmpp_stringprep:nodeprep(User),
|
LUser = exmpp_stringprep:nodeprep(User),
|
||||||
LServer = exmpp_stringprep:nameprep(Server),
|
LServer = exmpp_stringprep:nameprep(Server),
|
||||||
Proc = gen_mod:get_module_proc(binary_to_list(Server), ?PROCNAME),
|
Entity = exmpp_jid:make(LUser, LServer),
|
||||||
gen_server:cast(Proc, {remove_user, LUser, LServer}).
|
Host = host(LServer),
|
||||||
|
spawn(fun() ->
|
||||||
|
%% remove user's subscriptions
|
||||||
|
lists:foreach(fun(PType) ->
|
||||||
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
||||||
|
lists:foreach(fun
|
||||||
|
({#pubsub_node{id = NodeId}, subscribed, _, JID}) -> node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
||||||
|
(_) -> ok
|
||||||
|
end, Subscriptions),
|
||||||
|
{result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Entity]),
|
||||||
|
lists:foreach(fun
|
||||||
|
({#pubsub_node{nodeid = {H, N}}, owner}) -> delete_node(H, N, Entity);
|
||||||
|
({#pubsub_node{id = NodeId}, _}) -> node_action(Host, PType, set_affiliation, [NodeId, Entity, none])
|
||||||
|
end, Affiliations)
|
||||||
|
end, plugins(Host))
|
||||||
|
end).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Function:
|
%% Function:
|
||||||
@ -615,65 +643,6 @@ handle_call(stop, _From, State) ->
|
|||||||
%% Description: Handling cast messages
|
%% Description: Handling cast messages
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% @private
|
%% @private
|
||||||
handle_cast({presence, JID, Pid}, State) ->
|
|
||||||
%% A new resource is available. send last published items
|
|
||||||
{noreply, send_queue(State, {presence, JID, Pid})};
|
|
||||||
|
|
||||||
handle_cast({presence, User, Server, Resources, JID}, State) ->
|
|
||||||
%% A new resource is available. send last published PEP items
|
|
||||||
{noreply, send_queue(State, {presence, User, Server, Resources, JID})};
|
|
||||||
|
|
||||||
handle_cast({remove_user, LUser, LServer}, State) ->
|
|
||||||
spawn(fun() ->
|
|
||||||
Host = State#state.host,
|
|
||||||
Owner = exmpp_jid:make(LUser, LServer),
|
|
||||||
%% remove user's subscriptions
|
|
||||||
lists:foreach(fun(PType) ->
|
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Owner]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{nodeid = {H, N}}, subscribed, _, JID}) ->
|
|
||||||
unsubscribe_node(H, N, Owner, JID, all);
|
|
||||||
(_) ->
|
|
||||||
ok
|
|
||||||
end, Subscriptions),
|
|
||||||
{result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Owner]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{nodeid = {H, N}}, owner}) ->
|
|
||||||
delete_node(H, N, Owner);
|
|
||||||
(_) ->
|
|
||||||
ok
|
|
||||||
end, Affiliations)
|
|
||||||
end, State#state.plugins)
|
|
||||||
end),
|
|
||||||
{noreply, State};
|
|
||||||
|
|
||||||
handle_cast({unsubscribe, Subscriber, Owner}, State) ->
|
|
||||||
spawn(fun() ->
|
|
||||||
Host = State#state.host,
|
|
||||||
BJID = jlib:short_prepd_bare_jid(Owner),
|
|
||||||
lists:foreach(fun(PType) ->
|
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({Node, subscribed, _, JID}) ->
|
|
||||||
#pubsub_node{options = Options, type = Type, id = NodeId} = Node,
|
|
||||||
case get_option(Options, access_model) of
|
|
||||||
presence ->
|
|
||||||
case lists:member(BJID, node_owners(Host, Type, NodeId)) of
|
|
||||||
true ->
|
|
||||||
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
|
|
||||||
false ->
|
|
||||||
{result, ok}
|
|
||||||
end;
|
|
||||||
_ ->
|
|
||||||
{result, ok}
|
|
||||||
end;
|
|
||||||
(_) ->
|
|
||||||
ok
|
|
||||||
end, Subscriptions)
|
|
||||||
end, State#state.plugins)
|
|
||||||
end),
|
|
||||||
{noreply, State};
|
|
||||||
|
|
||||||
handle_cast(_Msg, State) ->
|
handle_cast(_Msg, State) ->
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
@ -3484,8 +3453,14 @@ get_cached_item(Host, NodeId) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%%%% plugin handling
|
%%%% plugin handling
|
||||||
|
|
||||||
|
host(ServerHost) ->
|
||||||
|
case catch ets:lookup(gen_mod:get_module_proc(ServerHost, config), host) of
|
||||||
|
[{host, Host}] -> Host;
|
||||||
|
_ -> "pubsub."++ServerHost
|
||||||
|
end.
|
||||||
plugins(Host) when is_binary(Host) ->
|
plugins(Host) when is_binary(Host) ->
|
||||||
plugins(binary_to_list(Host));
|
plugins(binary_to_list(Host));
|
||||||
plugins(Host) when is_list(Host) ->
|
plugins(Host) when is_list(Host) ->
|
||||||
case catch ets:lookup(gen_mod:get_module_proc(Host, config), plugins) of
|
case catch ets:lookup(gen_mod:get_module_proc(Host, config), plugins) of
|
||||||
[{plugins, []}] -> [?STDNODE];
|
[{plugins, []}] -> [?STDNODE];
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
--- mod_pubsub.erl 2010-01-12 14:30:14.000000000 +0100
|
--- mod_pubsub.erl 2010-01-12 16:08:14.000000000 +0100
|
||||||
+++ mod_pubsub_odbc.erl 2010-01-12 14:30:31.000000000 +0100
|
+++ mod_pubsub_odbc.erl 2010-01-12 16:10:52.000000000 +0100
|
||||||
@@ -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.
|
||||||
@ -37,10 +37,10 @@
|
|||||||
|
|
||||||
--define(PROCNAME, ejabberd_mod_pubsub).
|
--define(PROCNAME, ejabberd_mod_pubsub).
|
||||||
+-define(PROCNAME, ejabberd_mod_pubsub_odbc).
|
+-define(PROCNAME, ejabberd_mod_pubsub_odbc).
|
||||||
|
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
|
||||||
-define(PLUGIN_PREFIX, "node_").
|
-define(PLUGIN_PREFIX, "node_").
|
||||||
-define(TREE_PREFIX, "nodetree_").
|
-define(TREE_PREFIX, "nodetree_").
|
||||||
|
@@ -226,8 +226,6 @@
|
||||||
@@ -224,8 +224,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,
|
||||||
@@ -278,206 +276,15 @@
|
@@ -281,206 +279,15 @@
|
||||||
|
|
||||||
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
|
||||||
@ -258,9 +258,9 @@
|
|||||||
- end.
|
- end.
|
||||||
+
|
+
|
||||||
|
|
||||||
send_queue(State, Msg) ->
|
send_loop(State) ->
|
||||||
Pid = State#state.send_loop,
|
receive
|
||||||
@@ -501,17 +308,15 @@
|
@@ -492,17 +299,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,7 @@
|
|||||||
true ->
|
true ->
|
||||||
% resource not concerned about that subscription
|
% resource not concerned about that subscription
|
||||||
ok
|
ok
|
||||||
@@ -692,8 +497,7 @@
|
@@ -683,8 +488,7 @@
|
||||||
end;
|
end;
|
||||||
|
|
||||||
disco_sm_items(Acc, From, To, NodeB, _Lang) ->
|
disco_sm_items(Acc, From, To, NodeB, _Lang) ->
|
||||||
@ -294,28 +294,28 @@
|
|||||||
%% TODO, use iq_disco_items(Host, Node, From)
|
%% TODO, use iq_disco_items(Host, Node, From)
|
||||||
Host = exmpp_jid:prep_domain_as_list(To),
|
Host = exmpp_jid:prep_domain_as_list(To),
|
||||||
LJID = jlib:short_prepd_bare_jid(To),
|
LJID = jlib:short_prepd_bare_jid(To),
|
||||||
@@ -727,6 +531,7 @@
|
@@ -718,6 +522,7 @@
|
||||||
%% -------
|
%% -------
|
||||||
%% presence hooks handling functions
|
%% presence hooks handling functions
|
||||||
%%
|
%%
|
||||||
+
|
+
|
||||||
presence_probe(Peer, JID, Pid) ->
|
presence_probe(Peer, JID, Pid) ->
|
||||||
case exmpp_jid:full_compare(Peer, JID) of
|
case exmpp_jid:full_compare(Peer, JID) of
|
||||||
true -> %% JID are equals
|
true -> %% JID are equals
|
||||||
@@ -850,10 +655,10 @@
|
@@ -766,10 +571,10 @@
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
|
lists:foreach(fun(PType) ->
|
||||||
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
||||||
lists:foreach(fun
|
lists:foreach(fun
|
||||||
({Node, subscribed, _, JID}) ->
|
- ({#pubsub_node{options = Options, owners = Owners, id = NodeId}, subscribed, _, JID}) ->
|
||||||
- #pubsub_node{options = Options, owners = Owners, type = Type, id = NodeId} = Node,
|
+ ({#pubsub_node{options = Options, id = NodeId}, subscribed, _, JID}) ->
|
||||||
+ #pubsub_node{options = Options, type = Type, id = NodeId} = Node,
|
|
||||||
case get_option(Options, access_model) of
|
case get_option(Options, access_model) of
|
||||||
presence ->
|
presence ->
|
||||||
- case lists:member(BJID, Owners) of
|
- case lists:member(BJID, Owners) of
|
||||||
+ case lists:member(BJID, node_owners(Host, Type, NodeId)) of
|
+ case lists:member(BJID, node_owners(Host, PType, NodeId)) of
|
||||||
true ->
|
true ->
|
||||||
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
|
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
||||||
false ->
|
false ->
|
||||||
@@ -972,11 +777,12 @@
|
@@ -941,11 +746,12 @@
|
||||||
end,
|
end,
|
||||||
ejabberd_router:route(To, From, Res);
|
ejabberd_router:route(To, From, Res);
|
||||||
#iq{type = get, ns = ?NS_DISCO_ITEMS,
|
#iq{type = get, ns = ?NS_DISCO_ITEMS,
|
||||||
@ -330,7 +330,7 @@
|
|||||||
{result, IQRes} ->
|
{result, IQRes} ->
|
||||||
Result = #xmlel{ns = ?NS_DISCO_ITEMS,
|
Result = #xmlel{ns = ?NS_DISCO_ITEMS,
|
||||||
name = 'query', attrs = QAttrs,
|
name = 'query', attrs = QAttrs,
|
||||||
@@ -1094,7 +900,7 @@
|
@@ -1063,7 +869,7 @@
|
||||||
[] ->
|
[] ->
|
||||||
["leaf"]; %% No sub-nodes: it's a leaf node
|
["leaf"]; %% No sub-nodes: it's a leaf node
|
||||||
_ ->
|
_ ->
|
||||||
@ -339,7 +339,7 @@
|
|||||||
{result, []} -> ["collection"];
|
{result, []} -> ["collection"];
|
||||||
{result, _} -> ["leaf", "collection"];
|
{result, _} -> ["leaf", "collection"];
|
||||||
_ -> []
|
_ -> []
|
||||||
@@ -1110,8 +916,9 @@
|
@@ -1079,8 +885,9 @@
|
||||||
[];
|
[];
|
||||||
true ->
|
true ->
|
||||||
[#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} |
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} |
|
||||||
@ -351,7 +351,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)
|
||||||
@@ -1140,8 +947,9 @@
|
@@ -1109,8 +916,9 @@
|
||||||
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]},
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]},
|
||||||
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]},
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]},
|
||||||
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++
|
||||||
@ -363,7 +363,7 @@
|
|||||||
end, features(Host, Node))};
|
end, features(Host, Node))};
|
||||||
?NS_ADHOC_b ->
|
?NS_ADHOC_b ->
|
||||||
command_disco_info(Host, Node, From);
|
command_disco_info(Host, Node, From);
|
||||||
@@ -1151,7 +959,7 @@
|
@@ -1120,7 +928,7 @@
|
||||||
node_disco_info(Host, Node, From)
|
node_disco_info(Host, Node, From)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -372,7 +372,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(
|
||||||
@@ -1164,7 +972,7 @@
|
@@ -1133,7 +941,7 @@
|
||||||
Other ->
|
Other ->
|
||||||
Other
|
Other
|
||||||
end;
|
end;
|
||||||
@ -381,7 +381,7 @@
|
|||||||
%% TODO: support localization of this string
|
%% TODO: support localization of this string
|
||||||
CommandItems = [
|
CommandItems = [
|
||||||
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
|
||||||
@@ -1173,10 +981,10 @@
|
@@ -1142,10 +950,10 @@
|
||||||
?XMLATTR('name', "Get Pending")
|
?XMLATTR('name', "Get Pending")
|
||||||
]}],
|
]}],
|
||||||
{result, CommandItems};
|
{result, CommandItems};
|
||||||
@ -394,7 +394,7 @@
|
|||||||
case string:tokens(Item, "!") of
|
case string:tokens(Item, "!") of
|
||||||
[_SNode, _ItemID] ->
|
[_SNode, _ItemID] ->
|
||||||
{result, []};
|
{result, []};
|
||||||
@@ -1184,10 +992,10 @@
|
@@ -1153,10 +961,10 @@
|
||||||
Node = string_to_node(SNode),
|
Node = string_to_node(SNode),
|
||||||
Action =
|
Action =
|
||||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
@ -408,7 +408,7 @@
|
|||||||
end,
|
end,
|
||||||
Nodes = lists:map(
|
Nodes = lists:map(
|
||||||
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
||||||
@@ -1198,9 +1006,10 @@
|
@@ -1167,9 +975,10 @@
|
||||||
Items = lists:map(
|
Items = lists:map(
|
||||||
fun(#pubsub_item{itemid = {RN, _}}) ->
|
fun(#pubsub_item{itemid = {RN, _}}) ->
|
||||||
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
|
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
|
||||||
@ -421,7 +421,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};
|
||||||
@@ -1331,7 +1140,8 @@
|
@@ -1300,7 +1109,8 @@
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
end, [], exmpp_xml:remove_cdata_from_list(Els)),
|
end, [], exmpp_xml:remove_cdata_from_list(Els)),
|
||||||
@ -431,7 +431,7 @@
|
|||||||
{get, 'subscriptions'} ->
|
{get, 'subscriptions'} ->
|
||||||
get_subscriptions(Host, Node, From, Plugins);
|
get_subscriptions(Host, Node, From, Plugins);
|
||||||
{get, 'affiliations'} ->
|
{get, 'affiliations'} ->
|
||||||
@@ -1353,8 +1163,9 @@
|
@@ -1322,8 +1132,9 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
||||||
@ -443,7 +443,7 @@
|
|||||||
case Action of
|
case Action of
|
||||||
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
|
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
|
||||||
Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")),
|
Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")),
|
||||||
@@ -1488,7 +1299,8 @@
|
@@ -1457,7 +1268,8 @@
|
||||||
_ -> []
|
_ -> []
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
@ -453,7 +453,7 @@
|
|||||||
sync_dirty) of
|
sync_dirty) of
|
||||||
{result, Res} -> Res;
|
{result, Res} -> Res;
|
||||||
Err -> Err
|
Err -> Err
|
||||||
@@ -1532,7 +1344,7 @@
|
@@ -1501,7 +1313,7 @@
|
||||||
|
|
||||||
%%% authorization handling
|
%%% authorization handling
|
||||||
|
|
||||||
@ -462,7 +462,7 @@
|
|||||||
Lang = "en", %% TODO fix
|
Lang = "en", %% TODO fix
|
||||||
{U, S, R} = Subscriber,
|
{U, S, R} = Subscriber,
|
||||||
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
|
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
|
||||||
@@ -1562,7 +1374,7 @@
|
@@ -1531,7 +1343,7 @@
|
||||||
lists:foreach(fun(Owner) ->
|
lists:foreach(fun(Owner) ->
|
||||||
{U, S, R} = Owner,
|
{U, S, R} = Owner,
|
||||||
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
|
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
|
||||||
@ -471,7 +471,7 @@
|
|||||||
|
|
||||||
find_authorization_response(Packet) ->
|
find_authorization_response(Packet) ->
|
||||||
Els = Packet#xmlel.children,
|
Els = Packet#xmlel.children,
|
||||||
@@ -1604,7 +1416,7 @@
|
@@ -1573,7 +1385,7 @@
|
||||||
end,
|
end,
|
||||||
Stanza = event_stanza(
|
Stanza = event_stanza(
|
||||||
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs =
|
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs =
|
||||||
@ -480,7 +480,7 @@
|
|||||||
}]),
|
}]),
|
||||||
ejabberd_router:route(service_jid(Host), JID, Stanza).
|
ejabberd_router:route(service_jid(Host), JID, Stanza).
|
||||||
|
|
||||||
@@ -1615,14 +1427,14 @@
|
@@ -1584,14 +1396,14 @@
|
||||||
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
|
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
|
||||||
{value, {_, [SAllow]}}} ->
|
{value, {_, [SAllow]}}} ->
|
||||||
Node = string_to_node(SNode),
|
Node = string_to_node(SNode),
|
||||||
@ -498,7 +498,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 ->
|
||||||
@@ -1817,7 +1629,7 @@
|
@@ -1786,7 +1598,7 @@
|
||||||
end,
|
end,
|
||||||
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
|
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
|
||||||
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
|
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
|
||||||
@ -507,7 +507,7 @@
|
|||||||
{result, {Result, broadcast}} ->
|
{result, {Result, broadcast}} ->
|
||||||
%%Lang = "en", %% TODO: fix
|
%%Lang = "en", %% TODO: fix
|
||||||
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
|
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
|
||||||
@@ -1926,7 +1738,7 @@
|
@@ -1895,7 +1707,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) ->
|
||||||
@ -516,7 +516,7 @@
|
|||||||
{result, GoodSubOpts} -> GoodSubOpts;
|
{result, GoodSubOpts} -> GoodSubOpts;
|
||||||
_ -> invalid
|
_ -> invalid
|
||||||
end,
|
end,
|
||||||
@@ -1937,7 +1749,7 @@
|
@@ -1906,7 +1718,7 @@
|
||||||
{undefined, undefined, undefined}
|
{undefined, undefined, undefined}
|
||||||
end,
|
end,
|
||||||
SubId = uniqid(),
|
SubId = uniqid(),
|
||||||
@ -525,7 +525,7 @@
|
|||||||
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),
|
||||||
@@ -1956,9 +1768,13 @@
|
@@ -1925,9 +1737,13 @@
|
||||||
{"", "", ""} ->
|
{"", "", ""} ->
|
||||||
{false, false};
|
{false, false};
|
||||||
_ ->
|
_ ->
|
||||||
@ -542,7 +542,7 @@
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
if
|
if
|
||||||
@@ -2291,7 +2107,7 @@
|
@@ -2260,7 +2076,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.
|
||||||
@ -551,7 +551,7 @@
|
|||||||
MaxItems =
|
MaxItems =
|
||||||
if
|
if
|
||||||
SMaxItems == "" -> get_max_items_node(Host);
|
SMaxItems == "" -> get_max_items_node(Host);
|
||||||
@@ -2330,11 +2146,11 @@
|
@@ -2299,11 +2115,11 @@
|
||||||
node_call(Type, get_items,
|
node_call(Type, get_items,
|
||||||
[NodeId, From,
|
[NodeId, From,
|
||||||
AccessModel, PresenceSubscription, RosterGroup,
|
AccessModel, PresenceSubscription, RosterGroup,
|
||||||
@ -565,7 +565,7 @@
|
|||||||
SendItems = case ItemIDs of
|
SendItems = case ItemIDs of
|
||||||
[] ->
|
[] ->
|
||||||
Items;
|
Items;
|
||||||
@@ -2347,7 +2163,7 @@
|
@@ -2316,7 +2132,7 @@
|
||||||
%% number of items sent to MaxItems:
|
%% number of items sent to MaxItems:
|
||||||
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
|
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
|
||||||
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
|
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
|
||||||
@ -574,7 +574,7 @@
|
|||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
@@ -2379,17 +2195,29 @@
|
@@ -2348,17 +2164,29 @@
|
||||||
%% @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) ->
|
||||||
@ -611,7 +611,7 @@
|
|||||||
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
|
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = 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, []} ->
|
||||||
@@ -2518,29 +2346,12 @@
|
@@ -2487,29 +2315,12 @@
|
||||||
error ->
|
error ->
|
||||||
{error, 'bad-request'};
|
{error, 'bad-request'};
|
||||||
_ ->
|
_ ->
|
||||||
@ -644,7 +644,7 @@
|
|||||||
end, Entities),
|
end, Entities),
|
||||||
{result, []};
|
{result, []};
|
||||||
_ ->
|
_ ->
|
||||||
@@ -2595,11 +2406,11 @@
|
@@ -2564,11 +2375,11 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
||||||
@ -658,7 +658,7 @@
|
|||||||
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
|
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
|
||||||
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
|
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
|
||||||
?XMLATTR('Subid', SubID) | nodeAttr(Node)],
|
?XMLATTR('Subid', SubID) | nodeAttr(Node)],
|
||||||
@@ -2626,7 +2437,7 @@
|
@@ -2595,7 +2406,7 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
||||||
@ -667,7 +667,7 @@
|
|||||||
{result, GoodSubOpts} -> GoodSubOpts;
|
{result, GoodSubOpts} -> GoodSubOpts;
|
||||||
_ -> invalid
|
_ -> invalid
|
||||||
end,
|
end,
|
||||||
@@ -2656,7 +2467,7 @@
|
@@ -2625,7 +2436,7 @@
|
||||||
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
|
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
|
||||||
{error, extended_error('bad-request', "invalid-options")};
|
{error, extended_error('bad-request', "invalid-options")};
|
||||||
write_sub(Subscriber, NodeID, SubID, Options) ->
|
write_sub(Subscriber, NodeID, SubID, Options) ->
|
||||||
@ -676,7 +676,7 @@
|
|||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
{error, extended_error('not-acceptable', "invalid-subid")};
|
{error, extended_error('not-acceptable', "invalid-subid")};
|
||||||
{result, _} ->
|
{result, _} ->
|
||||||
@@ -2829,8 +2640,8 @@
|
@@ -2798,8 +2609,8 @@
|
||||||
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
|
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
|
||||||
ejabberd_router:route(service_jid(Host), JID, Stanza)
|
ejabberd_router:route(service_jid(Host), JID, Stanza)
|
||||||
end,
|
end,
|
||||||
@ -687,7 +687,7 @@
|
|||||||
true ->
|
true ->
|
||||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||||
|
|
||||||
@@ -3119,7 +2930,7 @@
|
@@ -3088,7 +2899,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,
|
||||||
@ -696,7 +696,7 @@
|
|||||||
{result, CollSubs} -> CollSubs;
|
{result, CollSubs} -> CollSubs;
|
||||||
_ -> []
|
_ -> []
|
||||||
end.
|
end.
|
||||||
@@ -3133,9 +2944,9 @@
|
@@ -3102,9 +2913,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) ->
|
||||||
@ -708,7 +708,7 @@
|
|||||||
_ -> Acc
|
_ -> Acc
|
||||||
end;
|
end;
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
@@ -3143,7 +2954,7 @@
|
@@ -3112,7 +2923,7 @@
|
||||||
end, [], Subs).
|
end, [], Subs).
|
||||||
|
|
||||||
% TODO: merge broadcast code that way
|
% TODO: merge broadcast code that way
|
||||||
@ -717,7 +717,7 @@
|
|||||||
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
|
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
|
||||||
% case (get_option(NodeOptions, Feature) or Force) of
|
% case (get_option(NodeOptions, Feature) or Force) of
|
||||||
% true ->
|
% true ->
|
||||||
@@ -3364,6 +3175,30 @@
|
@@ -3333,6 +3144,30 @@
|
||||||
Result
|
Result
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -748,7 +748,7 @@
|
|||||||
%% @spec (Host, Options) -> MaxItems
|
%% @spec (Host, Options) -> MaxItems
|
||||||
%% Host = host()
|
%% Host = host()
|
||||||
%% Options = [Option]
|
%% Options = [Option]
|
||||||
@@ -3753,7 +3588,13 @@
|
@@ -3728,7 +3563,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,
|
||||||
@ -763,7 +763,7 @@
|
|||||||
|
|
||||||
%% @doc <p>node plugin call.</p>
|
%% @doc <p>node plugin call.</p>
|
||||||
node_call(Type, Function, Args) ->
|
node_call(Type, Function, Args) ->
|
||||||
@@ -3773,13 +3614,13 @@
|
@@ -3748,13 +3589,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]),
|
||||||
@ -779,7 +779,7 @@
|
|||||||
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
|
||||||
@@ -3792,8 +3633,15 @@
|
@@ -3767,8 +3608,15 @@
|
||||||
end
|
end
|
||||||
end, Trans).
|
end, Trans).
|
||||||
|
|
||||||
@ -797,7 +797,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};
|
||||||
@@ -3801,6 +3649,15 @@
|
@@ -3776,6 +3624,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, 'internal-server-error'};
|
{error, 'internal-server-error'};
|
||||||
@ -813,7 +813,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, 'internal-server-error'};
|
{error, 'internal-server-error'};
|
||||||
@@ -3809,6 +3666,16 @@
|
@@ -3784,6 +3641,16 @@
|
||||||
{error, 'internal-server-error'}
|
{error, 'internal-server-error'}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user