mirror of
https://github.com/processone/ejabberd.git
synced 2024-07-14 23:44:18 +02:00
added optimizations from BBC
This commit is contained in:
parent
d471be26cf
commit
d1377da151
|
@ -116,7 +116,7 @@ listmech(Host) ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
['$1']}]),
|
['$1']}]),
|
||||||
filter_anonymous(Host, Mechs).
|
filter_anonymous(Host, lists:sort(Mechs)).
|
||||||
|
|
||||||
server_new(Service, ServerFQDN, UserRealm, _SecFlags,
|
server_new(Service, ServerFQDN, UserRealm, _SecFlags,
|
||||||
GetPassword, CheckPassword, CheckPasswordDigest) ->
|
GetPassword, CheckPassword, CheckPasswordDigest) ->
|
||||||
|
|
|
@ -47,6 +47,8 @@
|
||||||
try_register/3,
|
try_register/3,
|
||||||
dirty_get_registered_users/0,
|
dirty_get_registered_users/0,
|
||||||
get_vh_registered_users/1,
|
get_vh_registered_users/1,
|
||||||
|
get_vh_registered_users_number/1,
|
||||||
|
get_vh_registered_users_number/2,
|
||||||
get_password/2,
|
get_password/2,
|
||||||
get_password/3,
|
get_password/3,
|
||||||
is_user_exists/2,
|
is_user_exists/2,
|
||||||
|
@ -126,30 +128,36 @@ allow_multiple_connections(Host) ->
|
||||||
|
|
||||||
%% Check if user exist in the anonymus database
|
%% Check if user exist in the anonymus database
|
||||||
anonymous_user_exist(User, Server) ->
|
anonymous_user_exist(User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
% LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
% LServer = jlib:nameprep(Server),
|
||||||
US = {LUser, LServer},
|
% US = {LUser, LServer},
|
||||||
Ss = case ejabberd_cluster:get_node(US) of
|
% Ss = case ejabberd_cluster:get_node(US) of
|
||||||
Node when Node == node() ->
|
% Node when Node == node() ->
|
||||||
catch mnesia:dirty_read({anonymous, US});
|
% catch mnesia:dirty_read({anonymous, US});
|
||||||
Node ->
|
% Node ->
|
||||||
catch rpc:call(Node, mnesia, dirty_read,
|
% catch rpc:call(Node, mnesia, dirty_read,
|
||||||
[{anonymous, US}], 5000)
|
% [{anonymous, US}], 5000)
|
||||||
end,
|
% end,
|
||||||
case Ss of
|
% case Ss of
|
||||||
[_H|_T] ->
|
% [_H|_T] ->
|
||||||
true;
|
% true;
|
||||||
_ ->
|
% _ ->
|
||||||
false
|
% false
|
||||||
end.
|
% end.
|
||||||
|
%% We hardcode this value for the BBC case, because they are using SASL anonymous: the way
|
||||||
|
%% cyrsasl_anonymous.erl generate username makes collision not possible in normal cases.
|
||||||
|
false.
|
||||||
|
|
||||||
%% Remove connection from Mnesia tables
|
%% Remove connection from Mnesia tables
|
||||||
remove_connection(SID, LUser, LServer) ->
|
remove_connection(SID, LUser, LServer) ->
|
||||||
US = {LUser, LServer},
|
% US = {LUser, LServer},
|
||||||
F = fun() ->
|
% F = fun() ->
|
||||||
mnesia:delete_object({anonymous, US, SID})
|
% mnesia:delete_object({anonymous, US, SID})
|
||||||
end,
|
% end,
|
||||||
mnesia:async_dirty(F).
|
% mnesia:async_dirty(F).
|
||||||
|
%% We do not use anonymous table for the BBC case, because they are using SASL anonymous: the way
|
||||||
|
%% cyrsasl_anonymous.erl generate username makes collision not possible in normal cases.
|
||||||
|
ok.
|
||||||
|
|
||||||
%% Register connection
|
%% Register connection
|
||||||
register_connection(SID, #jid{luser = LUser, lserver = LServer}, Info) ->
|
register_connection(SID, #jid{luser = LUser, lserver = LServer}, Info) ->
|
||||||
|
@ -157,17 +165,21 @@ register_connection(SID, #jid{luser = LUser, lserver = LServer}, Info) ->
|
||||||
case AuthModule == ?MODULE of
|
case AuthModule == ?MODULE of
|
||||||
true ->
|
true ->
|
||||||
ejabberd_hooks:run(register_user, LServer, [LUser, LServer]),
|
ejabberd_hooks:run(register_user, LServer, [LUser, LServer]),
|
||||||
US = {LUser, LServer},
|
% US = {LUser, LServer},
|
||||||
mnesia:async_dirty(
|
% mnesia:async_dirty(
|
||||||
fun() -> mnesia:write(#anonymous{us = US, sid=SID})
|
% fun() -> mnesia:write(#anonymous{us = US, sid=SID})
|
||||||
end);
|
% end);
|
||||||
|
%% We do not use anonymous table for the BBC case, because they are using SASL anonymous: the way
|
||||||
|
%% cyrsasl_anonymous.erl generate username makes collision not possible in normal cases.
|
||||||
|
ok;
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% Remove an anonymous user from the anonymous users table
|
%% Remove an anonymous user from the anonymous users table
|
||||||
unregister_connection(SID, #jid{luser = LUser, lserver = LServer}, _) ->
|
unregister_connection(SID, #jid{luser = LUser, lserver = LServer}, _) ->
|
||||||
purge_hook(anonymous_user_exist(LUser, LServer),
|
%% We consider for BBC case that user always exist if not registered (We force to true to always call the purge hook)
|
||||||
|
purge_hook(not bbc:registered(LUser),
|
||||||
LUser, LServer),
|
LUser, LServer),
|
||||||
remove_connection(SID, LUser, LServer).
|
remove_connection(SID, LUser, LServer).
|
||||||
|
|
||||||
|
@ -192,12 +204,9 @@ check_password(User, Server, Password) ->
|
||||||
check_password(User, Server, _Password, _Digest, _DigestGen) ->
|
check_password(User, Server, _Password, _Digest, _DigestGen) ->
|
||||||
%% We refuse login for registered accounts (They cannot logged but
|
%% We refuse login for registered accounts (They cannot logged but
|
||||||
%% they however are "reserved")
|
%% they however are "reserved")
|
||||||
case ejabberd_auth:is_user_exists_in_other_modules(?MODULE,
|
case bbc:registered(User) of
|
||||||
User, Server) of
|
%% We reject anonnymous authentication for reserved users
|
||||||
%% If user exists in other module, reject anonnymous authentication
|
|
||||||
true -> false;
|
true -> false;
|
||||||
%% If we are not sure whether the user exists in other module, reject anon auth
|
|
||||||
maybe -> false;
|
|
||||||
false -> login(User, Server)
|
false -> login(User, Server)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -236,6 +245,14 @@ dirty_get_registered_users() ->
|
||||||
get_vh_registered_users(Server) ->
|
get_vh_registered_users(Server) ->
|
||||||
[{U, S} || {U, S, _R} <- ejabberd_sm:get_vh_session_list(Server)].
|
[{U, S} || {U, S, _R} <- ejabberd_sm:get_vh_session_list(Server)].
|
||||||
|
|
||||||
|
%% this module never had any registered user.
|
||||||
|
%% Note that this is not consistent with get_vh_registered_users/1,
|
||||||
|
%% that function was modified to improve shared roster support, check commit
|
||||||
|
%% 0874b93e7ca589b51d0250cd7ec511c4b394beb6
|
||||||
|
get_vh_registered_users_number(_Server) ->
|
||||||
|
0.
|
||||||
|
get_vh_registered_users_number(_Server, _Opts) ->
|
||||||
|
0.
|
||||||
|
|
||||||
%% Return password of permanent user or false for anonymous users
|
%% Return password of permanent user or false for anonymous users
|
||||||
get_password(User, Server) ->
|
get_password(User, Server) ->
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
-module(mod_pubsub).
|
-module(mod_pubsub).
|
||||||
-author('christophe.romain@process-one.net').
|
-author('christophe.romain@process-one.net').
|
||||||
-version('1.13-0').
|
-version('1.13-p1pp').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
@ -183,7 +183,7 @@ init([ServerHost, Opts]) ->
|
||||||
ets:new(gen_mod:get_module_proc(Host, config), [set, named_table]),
|
ets:new(gen_mod:get_module_proc(Host, config), [set, named_table]),
|
||||||
ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]),
|
ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]),
|
||||||
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
||||||
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {attributes, record_info(fields, pubsub_last_item)}]),
|
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {local_content, true}, {attributes, record_info(fields, pubsub_last_item)}]),
|
||||||
mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
|
mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
|
||||||
ets:insert(gen_mod:get_module_proc(Host, config), {nodetree, NodeTree}),
|
ets:insert(gen_mod:get_module_proc(Host, config), {nodetree, NodeTree}),
|
||||||
ets:insert(gen_mod:get_module_proc(Host, config), {plugins, Plugins}),
|
ets:insert(gen_mod:get_module_proc(Host, config), {plugins, Plugins}),
|
||||||
|
@ -200,7 +200,7 @@ init([ServerHost, Opts]) ->
|
||||||
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_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), %% BBC don't need last item at connection
|
||||||
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),
|
||||||
|
@ -467,6 +467,7 @@ update_state_database(_Host, _ServerHost) ->
|
||||||
{atomic, ok} = mnesia:delete_table(pubsub_state),
|
{atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||||
{atomic, ok} = mnesia:create_table(pubsub_state,
|
{atomic, ok} = mnesia:create_table(pubsub_state,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
|
{local_content, true},
|
||||||
{attributes, record_info(fields, pubsub_state)}]),
|
{attributes, record_info(fields, pubsub_state)}]),
|
||||||
FNew = fun () ->
|
FNew = fun () ->
|
||||||
lists:foreach(fun mnesia:write/1, NewRecs)
|
lists:foreach(fun mnesia:write/1, NewRecs)
|
||||||
|
@ -494,6 +495,7 @@ update_state_database(_Host, _ServerHost) ->
|
||||||
{atomic, ok} = mnesia:delete_table(pubsub_state),
|
{atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||||
{atomic, ok} = mnesia:create_table(pubsub_state,
|
{atomic, ok} = mnesia:create_table(pubsub_state,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
|
{local_content, true},
|
||||||
{attributes, record_info(fields, pubsub_state)}]),
|
{attributes, record_info(fields, pubsub_state)}]),
|
||||||
FNew = fun () ->
|
FNew = fun () ->
|
||||||
lists:foreach(fun mnesia:write/1, NewRecs)
|
lists:foreach(fun mnesia:write/1, NewRecs)
|
||||||
|
@ -518,6 +520,7 @@ update_state_database(_Host, _ServerHost) ->
|
||||||
{atomic, ok} = mnesia:delete_table(pubsub_item),
|
{atomic, ok} = mnesia:delete_table(pubsub_item),
|
||||||
{atomic, ok} = mnesia:create_table(pubsub_item,
|
{atomic, ok} = mnesia:create_table(pubsub_item,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
|
{local_content, true},
|
||||||
{attributes, record_info(fields, pubsub_item)}]),
|
{attributes, record_info(fields, pubsub_item)}]),
|
||||||
FNew = fun () ->
|
FNew = fun () ->
|
||||||
lists:foreach(fun mnesia:write/1, NewRecs)
|
lists:foreach(fun mnesia:write/1, NewRecs)
|
||||||
|
@ -866,24 +869,11 @@ unsubscribe_user(Entity, Owner) ->
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
Entity = jlib:make_jid(LUser, LServer, ""),
|
% BBC special optimization, no check, just bare unsubscribe
|
||||||
Host = host(LServer),
|
%% dirty_delete_object expect the object to be complete,
|
||||||
HomeTreeBase = string_to_node("/home/"++LServer++"/"++LUser),
|
%% http://stackoverflow.com/questions/650348/mnesia-delete-object-exception
|
||||||
spawn(fun() ->
|
Objs = mnesia:dirty_match_object(#pubsub_state{stateid = {{LUser, LServer, '_'}, '_'}, _ = '_'}),
|
||||||
lists:foreach(fun(PType) ->
|
[mnesia:dirty_delete_object(Obj) || Obj <- Objs].
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{id = NodeId}, _, _, JID}) -> node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all])
|
|
||||||
end, Subscriptions),
|
|
||||||
{result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Entity]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{nodeid = {H, N}, parents = []}, owner}) -> delete_node(H, N, Entity);
|
|
||||||
({#pubsub_node{nodeid = {H, N}, type = "hometree"}, owner}) when N == HomeTreeBase -> delete_node(H, N, Entity);
|
|
||||||
({#pubsub_node{id = NodeId}, publisher}) -> node_action(Host, PType, set_affiliation, [NodeId, Entity, none]);
|
|
||||||
(_) -> ok
|
|
||||||
end, Affiliations)
|
|
||||||
end, plugins(Host))
|
|
||||||
end).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Function:
|
%% Function:
|
||||||
|
@ -964,7 +954,7 @@ terminate(_Reason, #state{host = Host,
|
||||||
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_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), %% BBC don't need last item at connection
|
||||||
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),
|
||||||
|
@ -1295,7 +1285,12 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
||||||
{set, "publish"} ->
|
{set, "publish"} ->
|
||||||
case xml:remove_cdata(Els) of
|
case xml:remove_cdata(Els) of
|
||||||
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
||||||
ItemId = xml:get_attr_s("id", ItemAttrs),
|
ItemId = case xml:get_attr_s("id", ItemAttrs) of
|
||||||
|
"" -> uniqid();
|
||||||
|
Value -> Value
|
||||||
|
end,
|
||||||
|
%% BBC special optimization, multicast publish call
|
||||||
|
[rpc:cast(N, ?MODULE, publish_item, [Host, ServerHost, Node, From, ItemId, Payload]) || N <- ejabberd_cluster:get_nodes(), N /= node()],
|
||||||
publish_item(Host, ServerHost, Node, From, ItemId, Payload);
|
publish_item(Host, ServerHost, Node, From, ItemId, Payload);
|
||||||
[] ->
|
[] ->
|
||||||
%% Publisher attempts to publish to persistent node with no item
|
%% Publisher attempts to publish to persistent node with no item
|
||||||
|
@ -1315,6 +1310,7 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
||||||
case xml:remove_cdata(Els) of
|
case xml:remove_cdata(Els) of
|
||||||
[{xmlelement, "item", ItemAttrs, _}] ->
|
[{xmlelement, "item", ItemAttrs, _}] ->
|
||||||
ItemId = xml:get_attr_s("id", ItemAttrs),
|
ItemId = xml:get_attr_s("id", ItemAttrs),
|
||||||
|
[rpc:cast(N, ?MODULE, delete_item, [Host, Node, From, ItemId]) || N <- nodes(), N /= node()],
|
||||||
delete_item(Host, Node, From, ItemId, ForceNotify);
|
delete_item(Host, Node, From, ItemId, ForceNotify);
|
||||||
_ ->
|
_ ->
|
||||||
%% Request does not specify an item
|
%% Request does not specify an item
|
||||||
|
|
287
src/mod_pubsub/mod_pubsub_minimal.erl
Normal file
287
src/mod_pubsub/mod_pubsub_minimal.erl
Normal file
|
@ -0,0 +1,287 @@
|
||||||
|
-module(mod_pubsub_minimal).
|
||||||
|
|
||||||
|
%% One global mnesia Disc-copies table holding topic names and who can publish
|
||||||
|
%% This way each ejabberd node have the same view of the existing topics
|
||||||
|
%% One process per node listening mnesia events, so if a topic is removed, we can
|
||||||
|
%% cleanup locally.
|
||||||
|
%% One mnesia ram, local_copies table, holding all (allways temporarly) subscribers.
|
||||||
|
%% One mnesia ram, local_copies table, holding last published item.
|
||||||
|
%%
|
||||||
|
%% on publish ->
|
||||||
|
%% 1) check publisher has right
|
||||||
|
%% 2) publish on all ejabberd nodes
|
||||||
|
%%
|
||||||
|
%% on subscribe ->
|
||||||
|
%% 1) check if node exists
|
||||||
|
%% 2) add entry to mnesia
|
||||||
|
%% 3) monitor pid
|
||||||
|
%% 4) retrieve last published item and send
|
||||||
|
%%
|
||||||
|
%% on create node ->
|
||||||
|
%% 1) check if node already exists
|
||||||
|
%% 2) create
|
||||||
|
%%
|
||||||
|
%% on delete node ->
|
||||||
|
%% 1) check rights
|
||||||
|
%% 2) delete from mnesia distributed table
|
||||||
|
|
||||||
|
|
||||||
|
-include("ejabberd.hrl").
|
||||||
|
-include("jlib.hrl").
|
||||||
|
|
||||||
|
-export([start/2, stop/1]).
|
||||||
|
|
||||||
|
%% gen_server callbacks
|
||||||
|
-export([start_link/2, init/1, handle_info/2, handle_cast/2, handle_call/3, terminate/2]).
|
||||||
|
|
||||||
|
%% routing
|
||||||
|
-export([route/3]).
|
||||||
|
|
||||||
|
|
||||||
|
%% rpc api
|
||||||
|
-export([do_local_publish/3]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-record(topic, {name, admins}).
|
||||||
|
-record(topic_subscribers, {key, pid, jid, topic}).
|
||||||
|
|
||||||
|
-record(state, {host, pubsub_host, create_node_acl}).
|
||||||
|
|
||||||
|
start(Host, Opts) ->
|
||||||
|
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||||
|
ChildSpec = {Proc,
|
||||||
|
{?MODULE, start_link, [Host, Opts]},
|
||||||
|
transient, 1000, worker, [?MODULE]},
|
||||||
|
supervisor:start_child(ejabberd_sup, ChildSpec).
|
||||||
|
|
||||||
|
stop(Host) ->
|
||||||
|
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||||
|
gen_server:call(Proc, stop),
|
||||||
|
supervisor:delete_child(ejabberd_sup, Proc).
|
||||||
|
|
||||||
|
|
||||||
|
start_link(Host, Opts) ->
|
||||||
|
Proc = gen_mod:get_module_proc(Host, ?MODULE),
|
||||||
|
gen_server:start_link({local, Proc}, ?MODULE, [Host, Opts], []).
|
||||||
|
|
||||||
|
|
||||||
|
init([Domain, Opts]) ->
|
||||||
|
PubsubHost = gen_mod:get_opt_host(Domain, Opts, "pubsub.@HOST@"),
|
||||||
|
Access = gen_mod:get_opt(access_createnode, Opts, all),
|
||||||
|
mnesia:create_table(topic, [
|
||||||
|
{disc_copies,[node()]},
|
||||||
|
{type,set},
|
||||||
|
{attributes, record_info(fields, topic)}
|
||||||
|
]),
|
||||||
|
mnesia:subscribe({table, topic, simple}),
|
||||||
|
mnesia:add_table_copy(topic, node(), disc_copies),
|
||||||
|
mnesia:create_table(topic_subscribers, [
|
||||||
|
{ram_copies, [node()]},
|
||||||
|
{local_content, true},
|
||||||
|
{type, set},
|
||||||
|
{attributes, record_info(fields, topic_subscribers)}
|
||||||
|
]),
|
||||||
|
mnesia:add_table_index(topic_subscribers, topic),
|
||||||
|
mnesia:add_table_index(topic_subscribers, pid),
|
||||||
|
ejabberd_router:register_route(PubsubHost, {apply, ?MODULE, route}),
|
||||||
|
|
||||||
|
%% in case the module is restarted, monitor again any subscriber, so we can remove them at logout.
|
||||||
|
catch [erlang:monitor(process, Pid) || Pid <-
|
||||||
|
mnesia:dirty_select(topic_subscribers,[{#topic_subscribers{jid='_', topic='_', key='_', pid='$1'}, [], ['$1']}])],
|
||||||
|
{ok, #state{create_node_acl = Access, host = Domain, pubsub_host = PubsubHost}}.
|
||||||
|
|
||||||
|
handle_cast({monitor, Pid}, State) ->
|
||||||
|
_Ref = erlang:monitor(process, Pid),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
handle_call({create_node, From, Topic}, _, State = #state{create_node_acl = Access, host = Host}) ->
|
||||||
|
case acl:match_rule(Host, Access, From) of
|
||||||
|
allow ->
|
||||||
|
{reply, create_node(From, Topic), State};
|
||||||
|
deny ->
|
||||||
|
{reply, {error, ?ERR_NOT_ALLOWED}, State}
|
||||||
|
end;
|
||||||
|
handle_call(stop, _From, State) ->
|
||||||
|
{stop, normal, ok, State}.
|
||||||
|
|
||||||
|
%% a subscriber process die
|
||||||
|
handle_info({'DOWN', _MonitorRef, process, Pid, _Info}, State) ->
|
||||||
|
Objs = mnesia:dirty_index_read(topic_subscribers, Pid, #topic_subscribers.pid),
|
||||||
|
[mnesia:dirty_delete({topic_subscribers, Key}) || #topic_subscribers{key = Key} <- Objs],
|
||||||
|
{noreply, State};
|
||||||
|
|
||||||
|
%% TODO
|
||||||
|
handle_info({mnesia_table_event, {delete_object, #topic{name=Topic}, _ActivityId}}, State) ->
|
||||||
|
Subs = mnesia:dirty_index_read(topic_subscribers, Topic, #topic_subscribers.topic),
|
||||||
|
[mnesia:dirty_delete_object(S) || S <- Subs],
|
||||||
|
{noreply, State};
|
||||||
|
handle_info({mnesia_table_event, {delete, {topic,Topic}, _ActivityId}}, State) ->
|
||||||
|
Subs = mnesia:dirty_index_read(topic_subscribers, Topic, #topic_subscribers.topic),
|
||||||
|
[mnesia:dirty_delete_object(S) || S <- Subs],
|
||||||
|
{noreply, State};
|
||||||
|
handle_info({mnesia_table_event, _}, State) ->
|
||||||
|
{noreply, State};
|
||||||
|
handle_info(Info, State) ->
|
||||||
|
?ERROR_MSG("Unknown info received ~p", [Info]),
|
||||||
|
{noreply, State}.
|
||||||
|
|
||||||
|
|
||||||
|
terminate(_Reason, #state{pubsub_host = PubSubHost}) ->
|
||||||
|
ejabberd_router:unregister_route(PubSubHost),
|
||||||
|
ok.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%% route
|
||||||
|
%% four cases:
|
||||||
|
%% create node
|
||||||
|
%% subscribe
|
||||||
|
%% publish
|
||||||
|
%% delete node
|
||||||
|
|
||||||
|
route(From, #jid{server = PubSubHost} = To, {xmlelement, "iq", _Attrs, _Children} = Packet) ->
|
||||||
|
IQReply = case jlib:iq_query_info(Packet) of
|
||||||
|
#iq{xmlns = ?NS_PUBSUB} = IQ ->
|
||||||
|
case iq_pubsub(From, PubSubHost, IQ) of
|
||||||
|
{ok, Reply} -> jlib:iq_to_xml(IQ#iq{type=result, sub_el = Reply});
|
||||||
|
{error, Error} -> jlib:make_error_reply(Packet, Error)
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
?INFO_MSG("IQ not implemented ~p", [Packet]),
|
||||||
|
jlib:iq_to_xml(jlib:make_error_reply(Packet,?ERR_FEATURE_NOT_IMPLEMENTED))
|
||||||
|
end,
|
||||||
|
ejabberd_router:route(To, From, IQReply);
|
||||||
|
|
||||||
|
route(_, _ , Packet) ->
|
||||||
|
?INFO_MSG("Message to pubsub service (discarded) ~p", [Packet]).
|
||||||
|
|
||||||
|
|
||||||
|
%% create node | publish | subscribe
|
||||||
|
iq_pubsub(From =#jid{server = S}, PubSubHost, #iq{type = 'set', sub_el = SubEl}) ->
|
||||||
|
{xmlelement, _, _, SubEls} = SubEl,
|
||||||
|
Action = xml:remove_cdata(SubEls),
|
||||||
|
case Action of
|
||||||
|
[{xmlelement, "publish", Attrs, Children}] ->
|
||||||
|
Node = xml:get_attr_s("node", Attrs),
|
||||||
|
[Item] = xml:remove_cdata(Children),
|
||||||
|
publish(From, PubSubHost, Node, Item);
|
||||||
|
[{xmlelement, "subscribe", Attrs, _}] ->
|
||||||
|
Node = xml:get_attr_s("node", Attrs),
|
||||||
|
subscribe(From, Node);
|
||||||
|
[{xmlelement, "create", Attrs, _}, {xmlelement, "configure", _, _}] ->
|
||||||
|
Node = xml:get_attr_s("node", Attrs),
|
||||||
|
%% TODO: only local.
|
||||||
|
gen_server:call(gen_mod:get_module_proc(S, ?MODULE), {create_node, From, Node});
|
||||||
|
_ ->
|
||||||
|
?INFO_MSG("Invalid pubsub action: ~p", [Action]),
|
||||||
|
{error, ?ERR_BAD_REQUEST}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%% Publication functions %%%%%%%
|
||||||
|
build_publish_reply(Node, ItemId) ->
|
||||||
|
[{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
|
[{xmlelement, "publish", [{"node", Node}],
|
||||||
|
[{xmlelement, "item", [{"id", ItemId}], []}]}]}].
|
||||||
|
|
||||||
|
complete_id({xmlelement, Name, Attrs, Children}=Item) ->
|
||||||
|
case xml:get_attr("id", Attrs) of
|
||||||
|
{value, ID} ->
|
||||||
|
{Item, ID};
|
||||||
|
false ->
|
||||||
|
ID = uniqid(),
|
||||||
|
{{xmlelement, Name, [{"id", ID} | Attrs], Children}, ID}
|
||||||
|
end.
|
||||||
|
|
||||||
|
%% publish to subscribers on all nodes
|
||||||
|
publish(From, PubSubHost, Topic, Item) ->
|
||||||
|
{NewItem, ItemID} = complete_id(Item),
|
||||||
|
case mnesia:dirty_read({topic, Topic}) of
|
||||||
|
[#topic{admins = Admins}] ->
|
||||||
|
case lists:member(From, Admins) of
|
||||||
|
true ->
|
||||||
|
%%TODO: item tengo que ponerle el id
|
||||||
|
[rpc:cast(N, ?MODULE, do_publish, [PubSubHost, Topic, NewItem]) || N <- nodes(), N /= node()],
|
||||||
|
do_local_publish(PubSubHost, Topic, NewItem),
|
||||||
|
{ok, build_publish_reply(Topic, ItemID)};
|
||||||
|
false ->
|
||||||
|
{error, ?ERR_NOT_AUTHORIZED}
|
||||||
|
end;
|
||||||
|
[] ->
|
||||||
|
{error, ?ERR_ITEM_NOT_FOUND}
|
||||||
|
end.
|
||||||
|
|
||||||
|
%% publish to local subscribers
|
||||||
|
do_local_publish(PubsubHost, Topic, Item) ->
|
||||||
|
Message = {xmlelement, "message", [],
|
||||||
|
[{xmlelement, "event", [{"xmlns", ?NS_PUBSUB_EVENT}],
|
||||||
|
[{xmlelement,"items", [{"node", Topic}],[Item]}]}]},
|
||||||
|
|
||||||
|
Subs = mnesia:dirty_index_read(topic_subscribers, Topic, #topic_subscribers.topic),
|
||||||
|
|
||||||
|
%% don't let the vm do context switch to the reciving process until we multicasted to all.
|
||||||
|
OldPriority = process_flag(priority, high),
|
||||||
|
[ Pid ! {route, jlib:make_jid("",PubsubHost,""), JID, Message} || #topic_subscribers{pid = Pid, jid=JID} <- Subs],
|
||||||
|
process_flag(priority, OldPriority).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%% Subscription functions %%%%%%%
|
||||||
|
build_subscribe_reply(JID, Topic) ->
|
||||||
|
Fields = [{"jid", jlib:jid_to_string(JID)},{"node", Topic}],
|
||||||
|
[{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
|
[{xmlelement, "subscription", Fields, []}]}].
|
||||||
|
|
||||||
|
subscribe(#jid{user=U, server=S, resource=R}=From, Topic) ->
|
||||||
|
case mnesia:dirty_read({topic, Topic}) of
|
||||||
|
[] ->
|
||||||
|
{error, ?ERR_ITEM_NOT_FOUND};
|
||||||
|
[#topic{}] ->
|
||||||
|
case ejabberd_sm:get_session_pid(U, S, R) of
|
||||||
|
none ->
|
||||||
|
%%the client went offline, forget it.
|
||||||
|
ok;
|
||||||
|
Pid ->
|
||||||
|
mnesia:dirty_write(
|
||||||
|
#topic_subscribers{key = {Pid, Topic},
|
||||||
|
topic = Topic,
|
||||||
|
jid = From,
|
||||||
|
pid = Pid}),
|
||||||
|
|
||||||
|
%% TODO: this will only work on local users, and with only 1 domain.
|
||||||
|
%% to fix it we need to know the host at which the subscribe
|
||||||
|
%% packet is directed.
|
||||||
|
gen_server:cast(gen_mod:get_module_proc(S, ?MODULE), {monitor, Pid})
|
||||||
|
end,
|
||||||
|
{ok, build_subscribe_reply(From, Topic)}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
%%%%%%% Topic creation functions %%%%%%%
|
||||||
|
create_node(From, Node) ->
|
||||||
|
case mnesia:dirty_read({topic, Node}) of
|
||||||
|
[] ->
|
||||||
|
%% this is a full transaction, we don't want to have conflict on cluster,
|
||||||
|
%% and we want to be sure than when returning IQ to owner, the node is
|
||||||
|
%% really created
|
||||||
|
case mnesia:transaction(fun() ->
|
||||||
|
mnesia:write(#topic{name = Node, admins = [From]}),
|
||||||
|
ok
|
||||||
|
end) of
|
||||||
|
{atomic,ok} ->
|
||||||
|
{ok, []};
|
||||||
|
Error ->
|
||||||
|
?ERROR_MSG("Error creating topic: ~p", [Error]),
|
||||||
|
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||||
|
end;
|
||||||
|
[_|_] ->
|
||||||
|
{error, ?ERR_CONFLICT}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
uniqid() ->
|
||||||
|
{T1, T2, T3} = now(),
|
||||||
|
lists:flatten(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3])).
|
|
@ -44,7 +44,7 @@
|
||||||
|
|
||||||
-module(mod_pubsub_odbc).
|
-module(mod_pubsub_odbc).
|
||||||
-author('christophe.romain@process-one.net').
|
-author('christophe.romain@process-one.net').
|
||||||
-version('1.13-0').
|
-version('1.13-p1pp').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
@ -183,7 +183,7 @@ init([ServerHost, Opts]) ->
|
||||||
ets:new(gen_mod:get_module_proc(Host, config), [set, named_table]),
|
ets:new(gen_mod:get_module_proc(Host, config), [set, named_table]),
|
||||||
ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]),
|
ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]),
|
||||||
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
||||||
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {attributes, record_info(fields, pubsub_last_item)}]),
|
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {local_content, true}, {attributes, record_info(fields, pubsub_last_item)}]),
|
||||||
mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
|
mod_disco:register_feature(ServerHost, ?NS_PUBSUB),
|
||||||
ets:insert(gen_mod:get_module_proc(Host, config), {nodetree, NodeTree}),
|
ets:insert(gen_mod:get_module_proc(Host, config), {nodetree, NodeTree}),
|
||||||
ets:insert(gen_mod:get_module_proc(Host, config), {plugins, Plugins}),
|
ets:insert(gen_mod:get_module_proc(Host, config), {plugins, Plugins}),
|
||||||
|
@ -200,7 +200,7 @@ init([ServerHost, Opts]) ->
|
||||||
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:add(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:add(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_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), %% BBC don't need last item at connection
|
||||||
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),
|
||||||
|
@ -624,24 +624,11 @@ unsubscribe_user(Entity, Owner) ->
|
||||||
remove_user(User, Server) ->
|
remove_user(User, Server) ->
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
Entity = jlib:make_jid(LUser, LServer, ""),
|
% BBC special optimization, no check, just bare unsubscribe
|
||||||
Host = host(LServer),
|
%% dirty_delete_object expect the object to be complete,
|
||||||
HomeTreeBase = string_to_node("/home/"++LServer++"/"++LUser),
|
%% http://stackoverflow.com/questions/650348/mnesia-delete-object-exception
|
||||||
spawn(fun() ->
|
Objs = mnesia:dirty_match_object(#pubsub_state{stateid = {{LUser, LServer, '_'}, '_'}, _ = '_'}),
|
||||||
lists:foreach(fun(PType) ->
|
[mnesia:dirty_delete_object(Obj) || Obj <- Objs].
|
||||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{id = NodeId}, _, _, JID}) -> node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all])
|
|
||||||
end, Subscriptions),
|
|
||||||
{result, Affiliations} = node_action(Host, PType, get_entity_affiliations, [Host, Entity]),
|
|
||||||
lists:foreach(fun
|
|
||||||
({#pubsub_node{nodeid = {H, N}, parents = []}, owner}) -> delete_node(H, N, Entity);
|
|
||||||
({#pubsub_node{nodeid = {H, N}, type = "hometree"}, owner}) when N == HomeTreeBase -> delete_node(H, N, Entity);
|
|
||||||
({#pubsub_node{id = NodeId}, publisher}) -> node_action(Host, PType, set_affiliation, [NodeId, Entity, none]);
|
|
||||||
(_) -> ok
|
|
||||||
end, Affiliations)
|
|
||||||
end, plugins(Host))
|
|
||||||
end).
|
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Function:
|
%% Function:
|
||||||
|
@ -722,7 +709,7 @@ terminate(_Reason, #state{host = Host,
|
||||||
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
ejabberd_hooks:delete(disco_local_identity, ServerHost, ?MODULE, disco_local_identity, 75),
|
||||||
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
ejabberd_hooks:delete(disco_local_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||||
ejabberd_hooks:delete(disco_local_items, ServerHost, ?MODULE, disco_local_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), %% BBC don't need last item at connection
|
||||||
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),
|
||||||
|
@ -1057,7 +1044,12 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
||||||
{set, "publish"} ->
|
{set, "publish"} ->
|
||||||
case xml:remove_cdata(Els) of
|
case xml:remove_cdata(Els) of
|
||||||
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
||||||
ItemId = xml:get_attr_s("id", ItemAttrs),
|
ItemId = case xml:get_attr_s("id", ItemAttrs) of
|
||||||
|
"" -> uniqid();
|
||||||
|
Value -> Value
|
||||||
|
end,
|
||||||
|
%% BBC special optimization, multicast publish call
|
||||||
|
[rpc:cast(N, ?MODULE, publish_item, [Host, ServerHost, Node, From, ItemId, Payload]) || N <- ejabberd_cluster:get_nodes(), N /= node()],
|
||||||
publish_item(Host, ServerHost, Node, From, ItemId, Payload);
|
publish_item(Host, ServerHost, Node, From, ItemId, Payload);
|
||||||
[] ->
|
[] ->
|
||||||
%% Publisher attempts to publish to persistent node with no item
|
%% Publisher attempts to publish to persistent node with no item
|
||||||
|
@ -1077,6 +1069,7 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
||||||
case xml:remove_cdata(Els) of
|
case xml:remove_cdata(Els) of
|
||||||
[{xmlelement, "item", ItemAttrs, _}] ->
|
[{xmlelement, "item", ItemAttrs, _}] ->
|
||||||
ItemId = xml:get_attr_s("id", ItemAttrs),
|
ItemId = xml:get_attr_s("id", ItemAttrs),
|
||||||
|
[rpc:cast(N, ?MODULE, delete_item, [Host, Node, From, ItemId]) || N <- nodes(), N /= node()],
|
||||||
delete_item(Host, Node, From, ItemId, ForceNotify);
|
delete_item(Host, Node, From, ItemId, ForceNotify);
|
||||||
_ ->
|
_ ->
|
||||||
%% Request does not specify an item
|
%% Request does not specify an item
|
||||||
|
|
|
@ -97,10 +97,12 @@ init(_Host, _ServerHost, _Options) ->
|
||||||
pubsub_subscription:init(),
|
pubsub_subscription:init(),
|
||||||
mnesia:create_table(pubsub_state,
|
mnesia:create_table(pubsub_state,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
|
{local_content, true},
|
||||||
{index, [nodeidx]},
|
{index, [nodeidx]},
|
||||||
{attributes, record_info(fields, pubsub_state)}]),
|
{attributes, record_info(fields, pubsub_state)}]),
|
||||||
mnesia:create_table(pubsub_item,
|
mnesia:create_table(pubsub_item,
|
||||||
[{disc_only_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
|
{local_content, true},
|
||||||
{index, [nodeidx]},
|
{index, [nodeidx]},
|
||||||
{attributes, record_info(fields, pubsub_item)}]),
|
{attributes, record_info(fields, pubsub_item)}]),
|
||||||
ItemsFields = record_info(fields, pubsub_item),
|
ItemsFields = record_info(fields, pubsub_item),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--- mod_pubsub.erl 2011-09-30 13:59:23.000000000 +0200
|
--- mod_pubsub.erl 2011-11-23 15:02:18.000000000 +0100
|
||||||
+++ mod_pubsub_odbc.erl 2011-09-30 14:04:34.000000000 +0200
|
+++ mod_pubsub_odbc.erl 2011-11-23 15:02:18.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.
|
||||||
|
@ -7,7 +7,7 @@
|
||||||
--module(mod_pubsub).
|
--module(mod_pubsub).
|
||||||
+-module(mod_pubsub_odbc).
|
+-module(mod_pubsub_odbc).
|
||||||
-author('christophe.romain@process-one.net').
|
-author('christophe.romain@process-one.net').
|
||||||
-version('1.13-0').
|
-version('1.13-p1pp').
|
||||||
|
|
||||||
@@ -54,9 +54,9 @@
|
@@ -54,9 +54,9 @@
|
||||||
-include("jlib.hrl").
|
-include("jlib.hrl").
|
||||||
|
@ -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,
|
||||||
@@ -282,256 +280,14 @@
|
@@ -282,259 +280,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
|
||||||
|
@ -241,6 +241,7 @@
|
||||||
- {atomic, ok} = mnesia:delete_table(pubsub_state),
|
- {atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||||
- {atomic, ok} = mnesia:create_table(pubsub_state,
|
- {atomic, ok} = mnesia:create_table(pubsub_state,
|
||||||
- [{disc_copies, [node()]},
|
- [{disc_copies, [node()]},
|
||||||
|
- {local_content, true},
|
||||||
- {attributes, record_info(fields, pubsub_state)}]),
|
- {attributes, record_info(fields, pubsub_state)}]),
|
||||||
- FNew = fun () ->
|
- FNew = fun () ->
|
||||||
- lists:foreach(fun mnesia:write/1, NewRecs)
|
- lists:foreach(fun mnesia:write/1, NewRecs)
|
||||||
|
@ -268,6 +269,7 @@
|
||||||
- {atomic, ok} = mnesia:delete_table(pubsub_state),
|
- {atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||||
- {atomic, ok} = mnesia:create_table(pubsub_state,
|
- {atomic, ok} = mnesia:create_table(pubsub_state,
|
||||||
- [{disc_copies, [node()]},
|
- [{disc_copies, [node()]},
|
||||||
|
- {local_content, true},
|
||||||
- {attributes, record_info(fields, pubsub_state)}]),
|
- {attributes, record_info(fields, pubsub_state)}]),
|
||||||
- FNew = fun () ->
|
- FNew = fun () ->
|
||||||
- lists:foreach(fun mnesia:write/1, NewRecs)
|
- lists:foreach(fun mnesia:write/1, NewRecs)
|
||||||
|
@ -292,6 +294,7 @@
|
||||||
- {atomic, ok} = mnesia:delete_table(pubsub_item),
|
- {atomic, ok} = mnesia:delete_table(pubsub_item),
|
||||||
- {atomic, ok} = mnesia:create_table(pubsub_item,
|
- {atomic, ok} = mnesia:create_table(pubsub_item,
|
||||||
- [{disc_copies, [node()]},
|
- [{disc_copies, [node()]},
|
||||||
|
- {local_content, true},
|
||||||
- {attributes, record_info(fields, pubsub_item)}]),
|
- {attributes, record_info(fields, pubsub_item)}]),
|
||||||
- FNew = fun () ->
|
- FNew = fun () ->
|
||||||
- lists:foreach(fun mnesia:write/1, NewRecs)
|
- lists:foreach(fun mnesia:write/1, NewRecs)
|
||||||
|
@ -309,7 +312,7 @@
|
||||||
send_loop(State) ->
|
send_loop(State) ->
|
||||||
receive
|
receive
|
||||||
{presence, JID, Pid} ->
|
{presence, JID, Pid} ->
|
||||||
@@ -542,17 +298,15 @@
|
@@ -545,17 +298,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) ->
|
||||||
|
@ -333,7 +336,7 @@
|
||||||
true ->
|
true ->
|
||||||
% resource not concerned about that subscription
|
% resource not concerned about that subscription
|
||||||
ok
|
ok
|
||||||
@@ -671,7 +425,8 @@
|
@@ -674,7 +425,8 @@
|
||||||
disco_identity(_Host, <<>>, _From) ->
|
disco_identity(_Host, <<>>, _From) ->
|
||||||
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
|
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
|
||||||
disco_identity(Host, Node, From) ->
|
disco_identity(Host, Node, From) ->
|
||||||
|
@ -343,7 +346,7 @@
|
||||||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
{result, _} ->
|
{result, _} ->
|
||||||
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
|
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
|
||||||
@@ -706,7 +461,8 @@
|
@@ -709,7 +461,8 @@
|
||||||
[?NS_PUBSUB
|
[?NS_PUBSUB
|
||||||
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
|
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
|
||||||
disco_features(Host, Node, From) ->
|
disco_features(Host, Node, From) ->
|
||||||
|
@ -353,7 +356,7 @@
|
||||||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
{result, _} ->
|
{result, _} ->
|
||||||
{result, [?NS_PUBSUB
|
{result, [?NS_PUBSUB
|
||||||
@@ -731,7 +487,8 @@
|
@@ -734,7 +487,8 @@
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
disco_items(Host, <<>>, From) ->
|
disco_items(Host, <<>>, From) ->
|
||||||
|
@ -363,7 +366,7 @@
|
||||||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
{result, _} ->
|
{result, _} ->
|
||||||
[{xmlelement, "item",
|
[{xmlelement, "item",
|
||||||
@@ -749,13 +506,14 @@
|
@@ -752,13 +506,14 @@
|
||||||
_ -> Acc
|
_ -> Acc
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -380,7 +383,7 @@
|
||||||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||||
{result, Items} ->
|
{result, Items} ->
|
||||||
{result, [{xmlelement, "item",
|
{result, [{xmlelement, "item",
|
||||||
@@ -841,10 +599,10 @@
|
@@ -844,10 +599,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
|
||||||
|
@ -393,7 +396,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 ->
|
||||||
@@ -1012,7 +770,8 @@
|
@@ -1002,7 +757,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),
|
||||||
|
@ -403,7 +406,7 @@
|
||||||
{result, IQRes} ->
|
{result, IQRes} ->
|
||||||
jlib:iq_to_xml(
|
jlib:iq_to_xml(
|
||||||
IQ#iq{type = result,
|
IQ#iq{type = result,
|
||||||
@@ -1125,7 +884,7 @@
|
@@ -1115,7 +871,7 @@
|
||||||
[] ->
|
[] ->
|
||||||
["leaf"]; %% No sub-nodes: it's a leaf node
|
["leaf"]; %% No sub-nodes: it's a leaf node
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -412,7 +415,7 @@
|
||||||
{result, []} -> ["collection"];
|
{result, []} -> ["collection"];
|
||||||
{result, _} -> ["leaf", "collection"];
|
{result, _} -> ["leaf", "collection"];
|
||||||
_ -> []
|
_ -> []
|
||||||
@@ -1141,8 +900,9 @@
|
@@ -1131,8 +887,9 @@
|
||||||
[];
|
[];
|
||||||
true ->
|
true ->
|
||||||
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
||||||
|
@ -424,7 +427,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)
|
||||||
@@ -1171,8 +931,9 @@
|
@@ -1161,8 +918,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}], []}] ++
|
||||||
|
@ -436,7 +439,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);
|
||||||
@@ -1182,7 +943,7 @@
|
@@ -1172,7 +930,7 @@
|
||||||
node_disco_info(Host, Node, From)
|
node_disco_info(Host, Node, From)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -445,7 +448,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(
|
||||||
@@ -1199,23 +960,24 @@
|
@@ -1189,23 +947,24 @@
|
||||||
Other ->
|
Other ->
|
||||||
Other
|
Other
|
||||||
end;
|
end;
|
||||||
|
@ -476,7 +479,7 @@
|
||||||
end,
|
end,
|
||||||
Nodes = lists:map(
|
Nodes = lists:map(
|
||||||
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
|
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
|
||||||
@@ -1233,7 +995,7 @@
|
@@ -1223,7 +982,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),
|
||||||
|
@ -485,7 +488,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};
|
||||||
@@ -1344,7 +1106,8 @@
|
@@ -1340,7 +1099,8 @@
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
end, [], xml:remove_cdata(Els)),
|
end, [], xml:remove_cdata(Els)),
|
||||||
|
@ -495,7 +498,7 @@
|
||||||
{get, "subscriptions"} ->
|
{get, "subscriptions"} ->
|
||||||
get_subscriptions(Host, Node, From, Plugins);
|
get_subscriptions(Host, Node, From, Plugins);
|
||||||
{get, "affiliations"} ->
|
{get, "affiliations"} ->
|
||||||
@@ -1367,7 +1130,9 @@
|
@@ -1363,7 +1123,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,
|
||||||
|
@ -506,7 +509,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)),
|
||||||
@@ -1497,7 +1262,8 @@
|
@@ -1493,7 +1255,8 @@
|
||||||
_ -> []
|
_ -> []
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -516,7 +519,7 @@
|
||||||
sync_dirty) of
|
sync_dirty) of
|
||||||
{result, Res} -> Res;
|
{result, Res} -> Res;
|
||||||
Err -> Err
|
Err -> Err
|
||||||
@@ -1536,7 +1302,7 @@
|
@@ -1532,7 +1295,7 @@
|
||||||
|
|
||||||
%%% authorization handling
|
%%% authorization handling
|
||||||
|
|
||||||
|
@ -525,7 +528,7 @@
|
||||||
Lang = "en", %% TODO fix
|
Lang = "en", %% TODO fix
|
||||||
Stanza = {xmlelement, "message",
|
Stanza = {xmlelement, "message",
|
||||||
[],
|
[],
|
||||||
@@ -1565,7 +1331,7 @@
|
@@ -1561,7 +1324,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)
|
||||||
|
@ -534,7 +537,7 @@
|
||||||
|
|
||||||
find_authorization_response(Packet) ->
|
find_authorization_response(Packet) ->
|
||||||
{xmlelement, _Name, _Attrs, Els} = Packet,
|
{xmlelement, _Name, _Attrs, Els} = Packet,
|
||||||
@@ -1629,8 +1395,8 @@
|
@@ -1625,8 +1388,8 @@
|
||||||
"true" -> true;
|
"true" -> true;
|
||||||
_ -> false
|
_ -> false
|
||||||
end,
|
end,
|
||||||
|
@ -545,7 +548,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 ->
|
||||||
@@ -1827,7 +1593,7 @@
|
@@ -1823,7 +1586,7 @@
|
||||||
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
[{xmlelement, "create", nodeAttr(Node),
|
[{xmlelement, "create", nodeAttr(Node),
|
||||||
[]}]}],
|
[]}]}],
|
||||||
|
@ -554,7 +557,7 @@
|
||||||
{result, {NodeId, {Result, broadcast}}} ->
|
{result, {NodeId, {Result, broadcast}}} ->
|
||||||
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions),
|
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions),
|
||||||
case Result of
|
case Result of
|
||||||
@@ -1928,7 +1694,7 @@
|
@@ -1924,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) ->
|
||||||
|
@ -563,7 +566,7 @@
|
||||||
{result, GoodSubOpts} -> GoodSubOpts;
|
{result, GoodSubOpts} -> GoodSubOpts;
|
||||||
_ -> invalid
|
_ -> invalid
|
||||||
end,
|
end,
|
||||||
@@ -1936,7 +1702,7 @@
|
@@ -1932,7 +1695,7 @@
|
||||||
error -> {"", "", ""};
|
error -> {"", "", ""};
|
||||||
J -> jlib:jid_tolower(J)
|
J -> jlib:jid_tolower(J)
|
||||||
end,
|
end,
|
||||||
|
@ -572,7 +575,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),
|
||||||
@@ -1945,6 +1711,7 @@
|
@@ -1941,6 +1704,7 @@
|
||||||
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, []),
|
||||||
|
@ -580,7 +583,7 @@
|
||||||
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
|
||||||
if
|
if
|
||||||
not SubscribeFeature ->
|
not SubscribeFeature ->
|
||||||
@@ -2283,7 +2050,7 @@
|
@@ -2279,7 +2043,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.
|
||||||
|
@ -589,7 +592,7 @@
|
||||||
MaxItems =
|
MaxItems =
|
||||||
if
|
if
|
||||||
SMaxItems == "" -> get_max_items_node(Host);
|
SMaxItems == "" -> get_max_items_node(Host);
|
||||||
@@ -2297,12 +2064,13 @@
|
@@ -2293,12 +2057,13 @@
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
{error, Error};
|
{error, Error};
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -604,7 +607,7 @@
|
||||||
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||||
if
|
if
|
||||||
not RetreiveFeature ->
|
not RetreiveFeature ->
|
||||||
@@ -2315,11 +2083,11 @@
|
@@ -2311,11 +2076,11 @@
|
||||||
node_call(Type, get_items,
|
node_call(Type, get_items,
|
||||||
[NodeId, From,
|
[NodeId, From,
|
||||||
AccessModel, PresenceSubscription, RosterGroup,
|
AccessModel, PresenceSubscription, RosterGroup,
|
||||||
|
@ -618,7 +621,7 @@
|
||||||
SendItems = case ItemIDs of
|
SendItems = case ItemIDs of
|
||||||
[] ->
|
[] ->
|
||||||
Items;
|
Items;
|
||||||
@@ -2332,7 +2100,8 @@
|
@@ -2328,7 +2093,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),
|
||||||
|
@ -628,7 +631,7 @@
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
@@ -2354,10 +2123,15 @@
|
@@ -2350,10 +2116,15 @@
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end.
|
end.
|
||||||
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
|
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
|
||||||
|
@ -645,7 +648,7 @@
|
||||||
|
|
||||||
|
|
||||||
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
||||||
@@ -2370,27 +2144,27 @@
|
@@ -2366,27 +2137,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, {U,S,R} = LJID, last) ->
|
send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, last) ->
|
||||||
|
@ -689,7 +692,7 @@
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, Number) ->
|
send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, Number) ->
|
||||||
@@ -2531,7 +2305,8 @@
|
@@ -2527,7 +2298,8 @@
|
||||||
error ->
|
error ->
|
||||||
{error, ?ERR_BAD_REQUEST};
|
{error, ?ERR_BAD_REQUEST};
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -699,7 +702,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),
|
||||||
@@ -2541,24 +2316,7 @@
|
@@ -2537,24 +2309,7 @@
|
||||||
end,
|
end,
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({JID, Affiliation}) ->
|
fun({JID, Affiliation}) ->
|
||||||
|
@ -725,7 +728,7 @@
|
||||||
end, FilteredEntities),
|
end, FilteredEntities),
|
||||||
{result, []};
|
{result, []};
|
||||||
_ ->
|
_ ->
|
||||||
@@ -2611,9 +2369,9 @@
|
@@ -2607,9 +2362,9 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
||||||
|
@ -737,7 +740,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]},
|
||||||
@@ -2645,7 +2403,7 @@
|
@@ -2641,7 +2396,7 @@
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
||||||
|
@ -746,7 +749,7 @@
|
||||||
{result, GoodSubOpts} -> GoodSubOpts;
|
{result, GoodSubOpts} -> GoodSubOpts;
|
||||||
_ -> invalid
|
_ -> invalid
|
||||||
end,
|
end,
|
||||||
@@ -2844,8 +2602,8 @@
|
@@ -2840,8 +2595,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,
|
||||||
|
@ -757,7 +760,7 @@
|
||||||
true ->
|
true ->
|
||||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||||
|
|
||||||
@@ -3208,7 +2966,7 @@
|
@@ -3204,7 +2959,7 @@
|
||||||
Collection = tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]),
|
Collection = tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]),
|
||||||
{result, [{Depth, [{N, sub_with_options(N)} || N <- Nodes]} || {Depth, Nodes} <- Collection]}
|
{result, [{Depth, [{N, sub_with_options(N)} || N <- Nodes]} || {Depth, Nodes} <- Collection]}
|
||||||
end,
|
end,
|
||||||
|
@ -766,7 +769,7 @@
|
||||||
{result, CollSubs} -> subscribed_nodes_by_jid(NotifyType, CollSubs);
|
{result, CollSubs} -> subscribed_nodes_by_jid(NotifyType, CollSubs);
|
||||||
_ -> []
|
_ -> []
|
||||||
end.
|
end.
|
||||||
@@ -3277,8 +3035,8 @@
|
@@ -3273,8 +3028,8 @@
|
||||||
[]
|
[]
|
||||||
end.
|
end.
|
||||||
sub_with_options(JID, NodeId, SubId) ->
|
sub_with_options(JID, NodeId, SubId) ->
|
||||||
|
@ -777,7 +780,7 @@
|
||||||
_ -> {JID, SubId, []}
|
_ -> {JID, SubId, []}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@@ -3354,6 +3112,30 @@
|
@@ -3350,6 +3105,30 @@
|
||||||
Result
|
Result
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -808,7 +811,7 @@
|
||||||
%% @spec (Host, Options) -> MaxItems
|
%% @spec (Host, Options) -> MaxItems
|
||||||
%% Host = host()
|
%% Host = host()
|
||||||
%% Options = [Option]
|
%% Options = [Option]
|
||||||
@@ -3484,7 +3266,7 @@
|
@@ -3480,7 +3259,7 @@
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
case transaction(Host, Node, Action, transaction) of
|
case transaction(Host, Node, Action, transaction) of
|
||||||
|
@ -817,7 +820,7 @@
|
||||||
NodeId = TNode#pubsub_node.id,
|
NodeId = TNode#pubsub_node.id,
|
||||||
Type = TNode#pubsub_node.type,
|
Type = TNode#pubsub_node.type,
|
||||||
Options = TNode#pubsub_node.options,
|
Options = TNode#pubsub_node.options,
|
||||||
@@ -3750,7 +3532,13 @@
|
@@ -3746,7 +3525,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,
|
||||||
|
@ -832,7 +835,7 @@
|
||||||
|
|
||||||
%% @doc <p>node plugin call.</p>
|
%% @doc <p>node plugin call.</p>
|
||||||
node_call(Type, Function, Args) ->
|
node_call(Type, Function, Args) ->
|
||||||
@@ -3770,13 +3558,13 @@
|
@@ -3766,13 +3551,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]),
|
||||||
|
@ -848,7 +851,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
|
||||||
@@ -3788,13 +3576,19 @@
|
@@ -3784,13 +3569,19 @@
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
end, Trans).
|
end, Trans).
|
||||||
|
@ -872,7 +875,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};
|
||||||
@@ -3802,6 +3596,15 @@
|
@@ -3798,6 +3589,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};
|
||||||
|
@ -888,7 +891,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};
|
||||||
@@ -3810,6 +3613,17 @@
|
@@ -3806,6 +3606,17 @@
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -153,6 +153,7 @@ parse_options_xform(XFields) ->
|
||||||
create_table() ->
|
create_table() ->
|
||||||
case mnesia:create_table(pubsub_subscription,
|
case mnesia:create_table(pubsub_subscription,
|
||||||
[{disc_copies, [node()]},
|
[{disc_copies, [node()]},
|
||||||
|
{local_content, true},
|
||||||
{attributes, record_info(fields, pubsub_subscription)},
|
{attributes, record_info(fields, pubsub_subscription)},
|
||||||
{type, set}]) of
|
{type, set}]) of
|
||||||
{atomic, ok} -> ok;
|
{atomic, ok} -> ok;
|
||||||
|
|
359
src/mod_roster_dummy.erl
Normal file
359
src/mod_roster_dummy.erl
Normal file
|
@ -0,0 +1,359 @@
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
%%% File : mod_roster_dummy.erl
|
||||||
|
%%% Author : Jerome Sautret
|
||||||
|
%%% Purpose : Dummy roster management, where rosters are always empty
|
||||||
|
%%% Created : 11 Dec 2002 by Alexey Shchepin <alexey@process-one.net>
|
||||||
|
%%%
|
||||||
|
%%%
|
||||||
|
%%% ejabberd, Copyright (C) 2002-2010 ProcessOne
|
||||||
|
%%%
|
||||||
|
%%% This program is free software; you can redistribute it and/or
|
||||||
|
%%% modify it under the terms of the GNU General Public License as
|
||||||
|
%%% published by the Free Software Foundation; either version 2 of the
|
||||||
|
%%% License, or (at your option) any later version.
|
||||||
|
%%%
|
||||||
|
%%% This program is distributed in the hope that it will be useful,
|
||||||
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
%%% General Public License for more details.
|
||||||
|
%%%
|
||||||
|
%%% You should have received a copy of the GNU General Public License
|
||||||
|
%%% along with this program; if not, write to the Free Software
|
||||||
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||||
|
%%% 02111-1307 USA
|
||||||
|
%%%
|
||||||
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
|
%%% @doc Roster management (Dummy).
|
||||||
|
%%%
|
||||||
|
%%% Includes support for XEP-0237: Roster Versioning.
|
||||||
|
%%% The roster versioning follows an all-or-nothing strategy:
|
||||||
|
%%% - If the version supplied by the client is the latest, return an empty response.
|
||||||
|
%%% - If not, return the entire new roster (with updated version string).
|
||||||
|
%%% Roster version is a hash digest of the entire roster.
|
||||||
|
%%% No additional data is stored in DB.
|
||||||
|
|
||||||
|
-module(mod_roster_dummy).
|
||||||
|
-author('jerome.sautret@process-one.net').
|
||||||
|
|
||||||
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
|
-export([start/2, stop/1,
|
||||||
|
process_iq/3,
|
||||||
|
process_local_iq/3,
|
||||||
|
get_user_roster/2,
|
||||||
|
get_subscription_lists/3,
|
||||||
|
get_in_pending_subscriptions/3,
|
||||||
|
in_subscription/6,
|
||||||
|
out_subscription/4,
|
||||||
|
set_items/3,
|
||||||
|
remove_user/2,
|
||||||
|
get_jid_info/4,
|
||||||
|
item_to_xml/1,
|
||||||
|
webadmin_page/3,
|
||||||
|
webadmin_user/4,
|
||||||
|
get_versioning_feature/2,
|
||||||
|
roster_versioning_enabled/1,
|
||||||
|
roster_version/2]).
|
||||||
|
|
||||||
|
-include("ejabberd.hrl").
|
||||||
|
-include("jlib.hrl").
|
||||||
|
-include("mod_roster.hrl").
|
||||||
|
-include("web/ejabberd_http.hrl").
|
||||||
|
-include("web/ejabberd_web_admin.hrl").
|
||||||
|
|
||||||
|
|
||||||
|
start(Host, Opts) ->
|
||||||
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
|
ejabberd_hooks:add(roster_get, Host,
|
||||||
|
?MODULE, get_user_roster, 50),
|
||||||
|
ejabberd_hooks:add(roster_in_subscription, Host,
|
||||||
|
?MODULE, in_subscription, 50),
|
||||||
|
ejabberd_hooks:add(roster_out_subscription, Host,
|
||||||
|
?MODULE, out_subscription, 50),
|
||||||
|
ejabberd_hooks:add(roster_get_subscription_lists, Host,
|
||||||
|
?MODULE, get_subscription_lists, 50),
|
||||||
|
ejabberd_hooks:add(roster_get_jid_info, Host,
|
||||||
|
?MODULE, get_jid_info, 50),
|
||||||
|
ejabberd_hooks:add(remove_user, Host,
|
||||||
|
?MODULE, remove_user, 50),
|
||||||
|
ejabberd_hooks:add(anonymous_purge_hook, Host,
|
||||||
|
?MODULE, remove_user, 50),
|
||||||
|
ejabberd_hooks:add(resend_subscription_requests_hook, Host,
|
||||||
|
?MODULE, get_in_pending_subscriptions, 50),
|
||||||
|
ejabberd_hooks:add(roster_get_versioning_feature, Host,
|
||||||
|
?MODULE, get_versioning_feature, 50),
|
||||||
|
ejabberd_hooks:add(webadmin_page_host, Host,
|
||||||
|
?MODULE, webadmin_page, 50),
|
||||||
|
ejabberd_hooks:add(webadmin_user, Host,
|
||||||
|
?MODULE, webadmin_user, 50),
|
||||||
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ROSTER,
|
||||||
|
?MODULE, process_iq, IQDisc).
|
||||||
|
|
||||||
|
stop(Host) ->
|
||||||
|
ejabberd_hooks:delete(roster_get, Host,
|
||||||
|
?MODULE, get_user_roster, 50),
|
||||||
|
ejabberd_hooks:delete(roster_in_subscription, Host,
|
||||||
|
?MODULE, in_subscription, 50),
|
||||||
|
ejabberd_hooks:delete(roster_out_subscription, Host,
|
||||||
|
?MODULE, out_subscription, 50),
|
||||||
|
ejabberd_hooks:delete(roster_get_subscription_lists, Host,
|
||||||
|
?MODULE, get_subscription_lists, 50),
|
||||||
|
ejabberd_hooks:delete(roster_get_jid_info, Host,
|
||||||
|
?MODULE, get_jid_info, 50),
|
||||||
|
ejabberd_hooks:delete(remove_user, Host,
|
||||||
|
?MODULE, remove_user, 50),
|
||||||
|
ejabberd_hooks:delete(anonymous_purge_hook, Host,
|
||||||
|
?MODULE, remove_user, 50),
|
||||||
|
ejabberd_hooks:delete(resend_subscription_requests_hook, Host,
|
||||||
|
?MODULE, get_in_pending_subscriptions, 50),
|
||||||
|
ejabberd_hooks:delete(roster_get_versioning_feature, Host,
|
||||||
|
?MODULE, get_versioning_feature, 50),
|
||||||
|
ejabberd_hooks:delete(webadmin_page_host, Host,
|
||||||
|
?MODULE, webadmin_page, 50),
|
||||||
|
ejabberd_hooks:delete(webadmin_user, Host,
|
||||||
|
?MODULE, webadmin_user, 50),
|
||||||
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ROSTER).
|
||||||
|
|
||||||
|
|
||||||
|
process_iq(From, To, IQ) ->
|
||||||
|
#iq{sub_el = SubEl} = IQ,
|
||||||
|
#jid{lserver = LServer} = From,
|
||||||
|
case lists:member(LServer, ?MYHOSTS) of
|
||||||
|
true ->
|
||||||
|
process_local_iq(From, To, IQ);
|
||||||
|
_ ->
|
||||||
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]}
|
||||||
|
end.
|
||||||
|
|
||||||
|
process_local_iq(From, To, #iq{type = Type} = IQ) ->
|
||||||
|
case Type of
|
||||||
|
set ->
|
||||||
|
process_iq_set(From, To, IQ);
|
||||||
|
get ->
|
||||||
|
process_iq_get(From, To, IQ)
|
||||||
|
end.
|
||||||
|
|
||||||
|
roster_hash(Items) ->
|
||||||
|
sha:sha(term_to_binary(
|
||||||
|
lists:sort(
|
||||||
|
[R#roster{groups = lists:sort(Grs)} ||
|
||||||
|
R = #roster{groups = Grs} <- Items]))).
|
||||||
|
|
||||||
|
roster_versioning_enabled(_Host) ->
|
||||||
|
false.
|
||||||
|
|
||||||
|
%% Returns a list that may contain an xmlelement with the XEP-237 feature if it's enabled.
|
||||||
|
get_versioning_feature(_Acc, _Host) ->
|
||||||
|
[].
|
||||||
|
|
||||||
|
roster_version(LServer ,LUser) ->
|
||||||
|
US = {LUser, LServer},
|
||||||
|
roster_hash(ejabberd_hooks:run_fold(roster_get, LServer, [], [US])).
|
||||||
|
|
||||||
|
%% Load roster from DB only if neccesary.
|
||||||
|
%% It is neccesary if
|
||||||
|
%% - roster versioning is disabled in server OR
|
||||||
|
%% - roster versioning is not used by the client OR
|
||||||
|
%% - roster versioning is used by server and client, BUT the server isn't storing versions on db OR
|
||||||
|
%% - the roster version from client don't match current version.
|
||||||
|
process_iq_get(_From, _To, #iq{} = IQ) ->
|
||||||
|
IQ#iq{type = result, sub_el = []}.
|
||||||
|
|
||||||
|
|
||||||
|
get_user_roster(Acc, _US) ->
|
||||||
|
Acc.
|
||||||
|
|
||||||
|
item_to_xml(Item) ->
|
||||||
|
Attrs1 = [{"jid", jlib:jid_to_string(Item#roster.jid)}],
|
||||||
|
Attrs2 = case Item#roster.name of
|
||||||
|
"" ->
|
||||||
|
Attrs1;
|
||||||
|
Name ->
|
||||||
|
[{"name", Name} | Attrs1]
|
||||||
|
end,
|
||||||
|
Attrs3 = case Item#roster.subscription of
|
||||||
|
none ->
|
||||||
|
[{"subscription", "none"} | Attrs2];
|
||||||
|
from ->
|
||||||
|
[{"subscription", "from"} | Attrs2];
|
||||||
|
to ->
|
||||||
|
[{"subscription", "to"} | Attrs2];
|
||||||
|
both ->
|
||||||
|
[{"subscription", "both"} | Attrs2];
|
||||||
|
remove ->
|
||||||
|
[{"subscription", "remove"} | Attrs2]
|
||||||
|
end,
|
||||||
|
Attrs4 = case ask_to_pending(Item#roster.ask) of
|
||||||
|
out ->
|
||||||
|
[{"ask", "subscribe"} | Attrs3];
|
||||||
|
both ->
|
||||||
|
[{"ask", "subscribe"} | Attrs3];
|
||||||
|
_ ->
|
||||||
|
Attrs3
|
||||||
|
end,
|
||||||
|
SubEls1 = lists:map(fun(G) ->
|
||||||
|
{xmlelement, "group", [], [{xmlcdata, G}]}
|
||||||
|
end, Item#roster.groups),
|
||||||
|
SubEls = SubEls1 ++ Item#roster.xs,
|
||||||
|
{xmlelement, "item", Attrs4, SubEls}.
|
||||||
|
|
||||||
|
|
||||||
|
process_iq_set(_From, _To, #iq{} = IQ) ->
|
||||||
|
IQ#iq{type = result, sub_el = []}.
|
||||||
|
|
||||||
|
get_subscription_lists(_, _User, _Server) ->
|
||||||
|
{[], []}.
|
||||||
|
|
||||||
|
ask_to_pending(subscribe) -> out;
|
||||||
|
ask_to_pending(unsubscribe) -> none;
|
||||||
|
ask_to_pending(Ask) -> Ask.
|
||||||
|
|
||||||
|
|
||||||
|
in_subscription(_, User, Server, JID, Type, Reason) ->
|
||||||
|
process_subscription(in, User, Server, JID, Type, Reason).
|
||||||
|
|
||||||
|
out_subscription(User, Server, JID, Type) ->
|
||||||
|
process_subscription(out, User, Server, JID, Type, []).
|
||||||
|
|
||||||
|
process_subscription(_Direction, _User, _Server, _JID1, _Type, _Reason) ->
|
||||||
|
false.
|
||||||
|
|
||||||
|
%% in_state_change(Subscription, Pending, Type) -> NewState
|
||||||
|
%% NewState = none | {NewSubscription, NewPending}
|
||||||
|
-ifdef(ROSTER_GATEWAY_WORKAROUND).
|
||||||
|
-define(NNSD, {to, none}).
|
||||||
|
-define(NISD, {to, in}).
|
||||||
|
-else.
|
||||||
|
-define(NNSD, none).
|
||||||
|
-define(NISD, none).
|
||||||
|
-endif.
|
||||||
|
|
||||||
|
remove_user(_User, _Server) ->
|
||||||
|
{atomic, ok}.
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
set_items(_User, _Server, _SubEl) ->
|
||||||
|
{atomic, ok}.
|
||||||
|
|
||||||
|
get_in_pending_subscriptions(Ls, _User, _Server) ->
|
||||||
|
Ls.
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
get_jid_info(_, _User, _Server, _JID) ->
|
||||||
|
{none, []}.
|
||||||
|
|
||||||
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
webadmin_page(_, Host,
|
||||||
|
#request{us = _US,
|
||||||
|
path = ["user", U, "roster"],
|
||||||
|
q = Query,
|
||||||
|
lang = Lang} = _Request) ->
|
||||||
|
Res = user_roster(U, Host, Query, Lang),
|
||||||
|
{stop, Res};
|
||||||
|
|
||||||
|
webadmin_page(Acc, _, _) -> Acc.
|
||||||
|
|
||||||
|
user_roster(User, Server, Query, Lang) ->
|
||||||
|
US = {jlib:nodeprep(User), jlib:nameprep(Server)},
|
||||||
|
Items1 = [],
|
||||||
|
Res = user_roster_parse_query(User, Server, Items1, Query),
|
||||||
|
FItems = [?CT("None")],
|
||||||
|
[?XC("h1", ?T("Roster of ") ++ us_to_list(US))] ++
|
||||||
|
case Res of
|
||||||
|
ok -> [?XREST("Submitted")];
|
||||||
|
error -> [?XREST("Bad format")];
|
||||||
|
nothing -> []
|
||||||
|
end ++
|
||||||
|
[?XAE("form", [{"action", ""}, {"method", "post"}],
|
||||||
|
FItems ++
|
||||||
|
[?P,
|
||||||
|
?INPUT("text", "newjid", ""), ?C(" "),
|
||||||
|
?INPUTT("submit", "addjid", "Add Jabber ID")
|
||||||
|
])].
|
||||||
|
|
||||||
|
user_roster_parse_query(User, Server, Items, Query) ->
|
||||||
|
case lists:keysearch("addjid", 1, Query) of
|
||||||
|
{value, _} ->
|
||||||
|
case lists:keysearch("newjid", 1, Query) of
|
||||||
|
{value, {_, undefined}} ->
|
||||||
|
error;
|
||||||
|
{value, {_, SJID}} ->
|
||||||
|
case jlib:string_to_jid(SJID) of
|
||||||
|
JID when is_record(JID, jid) ->
|
||||||
|
user_roster_subscribe_jid(User, Server, JID),
|
||||||
|
ok;
|
||||||
|
error ->
|
||||||
|
error
|
||||||
|
end;
|
||||||
|
false ->
|
||||||
|
error
|
||||||
|
end;
|
||||||
|
false ->
|
||||||
|
case catch user_roster_item_parse_query(
|
||||||
|
User, Server, Items, Query) of
|
||||||
|
submitted ->
|
||||||
|
ok;
|
||||||
|
{'EXIT', _Reason} ->
|
||||||
|
error;
|
||||||
|
_ ->
|
||||||
|
nothing
|
||||||
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
user_roster_subscribe_jid(User, Server, JID) ->
|
||||||
|
out_subscription(User, Server, JID, subscribe),
|
||||||
|
UJID = jlib:make_jid(User, Server, ""),
|
||||||
|
ejabberd_router:route(
|
||||||
|
UJID, JID, {xmlelement, "presence", [{"type", "subscribe"}], []}).
|
||||||
|
|
||||||
|
user_roster_item_parse_query(User, Server, Items, Query) ->
|
||||||
|
lists:foreach(
|
||||||
|
fun(R) ->
|
||||||
|
JID = R#roster.jid,
|
||||||
|
case lists:keysearch(
|
||||||
|
"validate" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of
|
||||||
|
{value, _} ->
|
||||||
|
JID1 = jlib:make_jid(JID),
|
||||||
|
out_subscription(
|
||||||
|
User, Server, JID1, subscribed),
|
||||||
|
UJID = jlib:make_jid(User, Server, ""),
|
||||||
|
ejabberd_router:route(
|
||||||
|
UJID, JID1, {xmlelement, "presence",
|
||||||
|
[{"type", "subscribed"}], []}),
|
||||||
|
throw(submitted);
|
||||||
|
false ->
|
||||||
|
case lists:keysearch(
|
||||||
|
"remove" ++ ejabberd_web_admin:term_to_id(JID), 1, Query) of
|
||||||
|
{value, _} ->
|
||||||
|
UJID = jlib:make_jid(User, Server, ""),
|
||||||
|
process_iq(
|
||||||
|
UJID, UJID,
|
||||||
|
#iq{type = set,
|
||||||
|
sub_el = {xmlelement, "query",
|
||||||
|
[{"xmlns", ?NS_ROSTER}],
|
||||||
|
[{xmlelement, "item",
|
||||||
|
[{"jid", jlib:jid_to_string(JID)},
|
||||||
|
{"subscription", "remove"}],
|
||||||
|
[]}]}}),
|
||||||
|
throw(submitted);
|
||||||
|
false ->
|
||||||
|
ok
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end, Items),
|
||||||
|
nothing.
|
||||||
|
|
||||||
|
us_to_list({User, Server}) ->
|
||||||
|
jlib:jid_to_string({User, Server, ""}).
|
||||||
|
|
||||||
|
webadmin_user(Acc, _User, _Server, Lang) ->
|
||||||
|
Acc ++ [?XE("h3", [?ACT("roster/", "Roster")])].
|
Loading…
Reference in New Issue
Block a user