mirror of
https://github.com/processone/ejabberd.git
synced 2024-07-06 23:22:36 +02:00
Revert "added optimizations from BBC" (wrong upstream)
This reverts commit d1377da151
.
This commit is contained in:
parent
d1377da151
commit
f3d24b6a07
|
@ -116,7 +116,7 @@ listmech(Host) ->
|
|||
[]
|
||||
end,
|
||||
['$1']}]),
|
||||
filter_anonymous(Host, lists:sort(Mechs)).
|
||||
filter_anonymous(Host, Mechs).
|
||||
|
||||
server_new(Service, ServerFQDN, UserRealm, _SecFlags,
|
||||
GetPassword, CheckPassword, CheckPasswordDigest) ->
|
||||
|
|
|
@ -47,8 +47,6 @@
|
|||
try_register/3,
|
||||
dirty_get_registered_users/0,
|
||||
get_vh_registered_users/1,
|
||||
get_vh_registered_users_number/1,
|
||||
get_vh_registered_users_number/2,
|
||||
get_password/2,
|
||||
get_password/3,
|
||||
is_user_exists/2,
|
||||
|
@ -128,36 +126,30 @@ allow_multiple_connections(Host) ->
|
|||
|
||||
%% Check if user exist in the anonymus database
|
||||
anonymous_user_exist(User, Server) ->
|
||||
% LUser = jlib:nodeprep(User),
|
||||
% LServer = jlib:nameprep(Server),
|
||||
% US = {LUser, LServer},
|
||||
% Ss = case ejabberd_cluster:get_node(US) of
|
||||
% Node when Node == node() ->
|
||||
% catch mnesia:dirty_read({anonymous, US});
|
||||
% Node ->
|
||||
% catch rpc:call(Node, mnesia, dirty_read,
|
||||
% [{anonymous, US}], 5000)
|
||||
% end,
|
||||
% case Ss of
|
||||
% [_H|_T] ->
|
||||
% true;
|
||||
% _ ->
|
||||
% false
|
||||
% 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.
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
US = {LUser, LServer},
|
||||
Ss = case ejabberd_cluster:get_node(US) of
|
||||
Node when Node == node() ->
|
||||
catch mnesia:dirty_read({anonymous, US});
|
||||
Node ->
|
||||
catch rpc:call(Node, mnesia, dirty_read,
|
||||
[{anonymous, US}], 5000)
|
||||
end,
|
||||
case Ss of
|
||||
[_H|_T] ->
|
||||
true;
|
||||
_ ->
|
||||
false
|
||||
end.
|
||||
|
||||
%% Remove connection from Mnesia tables
|
||||
remove_connection(SID, LUser, LServer) ->
|
||||
% US = {LUser, LServer},
|
||||
% F = fun() ->
|
||||
% mnesia:delete_object({anonymous, US, SID})
|
||||
% end,
|
||||
% 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.
|
||||
US = {LUser, LServer},
|
||||
F = fun() ->
|
||||
mnesia:delete_object({anonymous, US, SID})
|
||||
end,
|
||||
mnesia:async_dirty(F).
|
||||
|
||||
%% Register connection
|
||||
register_connection(SID, #jid{luser = LUser, lserver = LServer}, Info) ->
|
||||
|
@ -165,21 +157,17 @@ register_connection(SID, #jid{luser = LUser, lserver = LServer}, Info) ->
|
|||
case AuthModule == ?MODULE of
|
||||
true ->
|
||||
ejabberd_hooks:run(register_user, LServer, [LUser, LServer]),
|
||||
% US = {LUser, LServer},
|
||||
% mnesia:async_dirty(
|
||||
% fun() -> mnesia:write(#anonymous{us = US, sid=SID})
|
||||
% 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;
|
||||
US = {LUser, LServer},
|
||||
mnesia:async_dirty(
|
||||
fun() -> mnesia:write(#anonymous{us = US, sid=SID})
|
||||
end);
|
||||
false ->
|
||||
ok
|
||||
end.
|
||||
|
||||
%% Remove an anonymous user from the anonymous users table
|
||||
unregister_connection(SID, #jid{luser = LUser, lserver = 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),
|
||||
purge_hook(anonymous_user_exist(LUser, LServer),
|
||||
LUser, LServer),
|
||||
remove_connection(SID, LUser, LServer).
|
||||
|
||||
|
@ -204,10 +192,13 @@ check_password(User, Server, Password) ->
|
|||
check_password(User, Server, _Password, _Digest, _DigestGen) ->
|
||||
%% We refuse login for registered accounts (They cannot logged but
|
||||
%% they however are "reserved")
|
||||
case bbc:registered(User) of
|
||||
%% We reject anonnymous authentication for reserved users
|
||||
true -> false;
|
||||
false -> login(User, Server)
|
||||
case ejabberd_auth:is_user_exists_in_other_modules(?MODULE,
|
||||
User, Server) of
|
||||
%% If user exists in other module, reject anonnymous authentication
|
||||
true -> false;
|
||||
%% If we are not sure whether the user exists in other module, reject anon auth
|
||||
maybe -> false;
|
||||
false -> login(User, Server)
|
||||
end.
|
||||
|
||||
login(User, Server) ->
|
||||
|
@ -245,14 +236,6 @@ dirty_get_registered_users() ->
|
|||
get_vh_registered_users(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
|
||||
get_password(User, Server) ->
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
|
||||
-module(mod_pubsub).
|
||||
-author('christophe.romain@process-one.net').
|
||||
-version('1.13-p1pp').
|
||||
-version('1.13-0').
|
||||
|
||||
-behaviour(gen_server).
|
||||
-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(ServerHost, config), [set, named_table]),
|
||||
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
||||
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {local_content, true}, {attributes, record_info(fields, pubsub_last_item)}]),
|
||||
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {attributes, record_info(fields, pubsub_last_item)}]),
|
||||
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), {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_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||
% ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80), %% BBC don't need last item at connection
|
||||
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||
|
@ -467,7 +467,6 @@ update_state_database(_Host, _ServerHost) ->
|
|||
{atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||
{atomic, ok} = mnesia:create_table(pubsub_state,
|
||||
[{disc_copies, [node()]},
|
||||
{local_content, true},
|
||||
{attributes, record_info(fields, pubsub_state)}]),
|
||||
FNew = fun () ->
|
||||
lists:foreach(fun mnesia:write/1, NewRecs)
|
||||
|
@ -495,7 +494,6 @@ update_state_database(_Host, _ServerHost) ->
|
|||
{atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||
{atomic, ok} = mnesia:create_table(pubsub_state,
|
||||
[{disc_copies, [node()]},
|
||||
{local_content, true},
|
||||
{attributes, record_info(fields, pubsub_state)}]),
|
||||
FNew = fun () ->
|
||||
lists:foreach(fun mnesia:write/1, NewRecs)
|
||||
|
@ -520,7 +518,6 @@ update_state_database(_Host, _ServerHost) ->
|
|||
{atomic, ok} = mnesia:delete_table(pubsub_item),
|
||||
{atomic, ok} = mnesia:create_table(pubsub_item,
|
||||
[{disc_copies, [node()]},
|
||||
{local_content, true},
|
||||
{attributes, record_info(fields, pubsub_item)}]),
|
||||
FNew = fun () ->
|
||||
lists:foreach(fun mnesia:write/1, NewRecs)
|
||||
|
@ -869,11 +866,24 @@ unsubscribe_user(Entity, Owner) ->
|
|||
remove_user(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
% BBC special optimization, no check, just bare unsubscribe
|
||||
%% dirty_delete_object expect the object to be complete,
|
||||
%% http://stackoverflow.com/questions/650348/mnesia-delete-object-exception
|
||||
Objs = mnesia:dirty_match_object(#pubsub_state{stateid = {{LUser, LServer, '_'}, '_'}, _ = '_'}),
|
||||
[mnesia:dirty_delete_object(Obj) || Obj <- Objs].
|
||||
Entity = jlib:make_jid(LUser, LServer, ""),
|
||||
Host = host(LServer),
|
||||
HomeTreeBase = string_to_node("/home/"++LServer++"/"++LUser),
|
||||
spawn(fun() ->
|
||||
lists:foreach(fun(PType) ->
|
||||
{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:
|
||||
|
@ -954,7 +964,7 @@ terminate(_Reason, #state{host = Host,
|
|||
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_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||
%ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80), %% BBC don't need last item at connection
|
||||
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||
|
@ -1285,12 +1295,7 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
|||
{set, "publish"} ->
|
||||
case xml:remove_cdata(Els) of
|
||||
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
||||
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()],
|
||||
ItemId = xml:get_attr_s("id", ItemAttrs),
|
||||
publish_item(Host, ServerHost, Node, From, ItemId, Payload);
|
||||
[] ->
|
||||
%% Publisher attempts to publish to persistent node with no item
|
||||
|
@ -1310,7 +1315,6 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
|||
case xml:remove_cdata(Els) of
|
||||
[{xmlelement, "item", 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);
|
||||
_ ->
|
||||
%% Request does not specify an item
|
||||
|
|
|
@ -1,287 +0,0 @@
|
|||
-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).
|
||||
-author('christophe.romain@process-one.net').
|
||||
-version('1.13-p1pp').
|
||||
-version('1.13-0').
|
||||
|
||||
-behaviour(gen_server).
|
||||
-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(ServerHost, config), [set, named_table]),
|
||||
{Plugins, NodeTree, PepMapping} = init_plugins(Host, ServerHost, Opts),
|
||||
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {local_content, true}, {attributes, record_info(fields, pubsub_last_item)}]),
|
||||
mnesia:create_table(pubsub_last_item, [{ram_copies, [node()]}, {attributes, record_info(fields, pubsub_last_item)}]),
|
||||
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), {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_features, ServerHost, ?MODULE, disco_local_features, 75),
|
||||
ejabberd_hooks:add(disco_local_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||
% ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80), %% BBC don't need last item at connection
|
||||
ejabberd_hooks:add(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||
ejabberd_hooks:add(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||
ejabberd_hooks:add(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||
ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||
|
@ -624,11 +624,24 @@ unsubscribe_user(Entity, Owner) ->
|
|||
remove_user(User, Server) ->
|
||||
LUser = jlib:nodeprep(User),
|
||||
LServer = jlib:nameprep(Server),
|
||||
% BBC special optimization, no check, just bare unsubscribe
|
||||
%% dirty_delete_object expect the object to be complete,
|
||||
%% http://stackoverflow.com/questions/650348/mnesia-delete-object-exception
|
||||
Objs = mnesia:dirty_match_object(#pubsub_state{stateid = {{LUser, LServer, '_'}, '_'}, _ = '_'}),
|
||||
[mnesia:dirty_delete_object(Obj) || Obj <- Objs].
|
||||
Entity = jlib:make_jid(LUser, LServer, ""),
|
||||
Host = host(LServer),
|
||||
HomeTreeBase = string_to_node("/home/"++LServer++"/"++LUser),
|
||||
spawn(fun() ->
|
||||
lists:foreach(fun(PType) ->
|
||||
{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:
|
||||
|
@ -709,7 +722,7 @@ terminate(_Reason, #state{host = Host,
|
|||
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_items, ServerHost, ?MODULE, disco_local_items, 75),
|
||||
%ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80), %% BBC don't need last item at connection
|
||||
ejabberd_hooks:delete(presence_probe_hook, ServerHost, ?MODULE, presence_probe, 80),
|
||||
ejabberd_hooks:delete(roster_in_subscription, ServerHost, ?MODULE, in_subscription, 50),
|
||||
ejabberd_hooks:delete(roster_out_subscription, ServerHost, ?MODULE, out_subscription, 50),
|
||||
ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, remove_user, 50),
|
||||
|
@ -1044,12 +1057,7 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
|||
{set, "publish"} ->
|
||||
case xml:remove_cdata(Els) of
|
||||
[{xmlelement, "item", ItemAttrs, Payload}] ->
|
||||
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()],
|
||||
ItemId = xml:get_attr_s("id", ItemAttrs),
|
||||
publish_item(Host, ServerHost, Node, From, ItemId, Payload);
|
||||
[] ->
|
||||
%% Publisher attempts to publish to persistent node with no item
|
||||
|
@ -1069,7 +1077,6 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
|||
case xml:remove_cdata(Els) of
|
||||
[{xmlelement, "item", 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);
|
||||
_ ->
|
||||
%% Request does not specify an item
|
||||
|
|
|
@ -97,12 +97,10 @@ init(_Host, _ServerHost, _Options) ->
|
|||
pubsub_subscription:init(),
|
||||
mnesia:create_table(pubsub_state,
|
||||
[{disc_copies, [node()]},
|
||||
{local_content, true},
|
||||
{index, [nodeidx]},
|
||||
{attributes, record_info(fields, pubsub_state)}]),
|
||||
mnesia:create_table(pubsub_item,
|
||||
[{disc_copies, [node()]},
|
||||
{local_content, true},
|
||||
[{disc_only_copies, [node()]},
|
||||
{index, [nodeidx]},
|
||||
{attributes, record_info(fields, pubsub_item)}]),
|
||||
ItemsFields = record_info(fields, pubsub_item),
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
--- mod_pubsub.erl 2011-11-23 15:02:18.000000000 +0100
|
||||
+++ mod_pubsub_odbc.erl 2011-11-23 15:02:18.000000000 +0100
|
||||
--- mod_pubsub.erl 2011-09-30 13:59:23.000000000 +0200
|
||||
+++ mod_pubsub_odbc.erl 2011-09-30 14:04:34.000000000 +0200
|
||||
@@ -42,7 +42,7 @@
|
||||
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
|
||||
%%% XEP-0060 section 12.18.
|
||||
|
@ -7,7 +7,7 @@
|
|||
--module(mod_pubsub).
|
||||
+-module(mod_pubsub_odbc).
|
||||
-author('christophe.romain@process-one.net').
|
||||
-version('1.13-p1pp').
|
||||
-version('1.13-0').
|
||||
|
||||
@@ -54,9 +54,9 @@
|
||||
-include("jlib.hrl").
|
||||
|
@ -49,7 +49,7 @@
|
|||
init_nodes(Host, ServerHost, NodeTree, Plugins),
|
||||
State = #state{host = Host,
|
||||
server_host = ServerHost,
|
||||
@@ -282,259 +280,14 @@
|
||||
@@ -282,256 +280,14 @@
|
||||
|
||||
init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
|
||||
%% TODO, this call should be done plugin side
|
||||
|
@ -241,7 +241,6 @@
|
|||
- {atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||
- {atomic, ok} = mnesia:create_table(pubsub_state,
|
||||
- [{disc_copies, [node()]},
|
||||
- {local_content, true},
|
||||
- {attributes, record_info(fields, pubsub_state)}]),
|
||||
- FNew = fun () ->
|
||||
- lists:foreach(fun mnesia:write/1, NewRecs)
|
||||
|
@ -269,7 +268,6 @@
|
|||
- {atomic, ok} = mnesia:delete_table(pubsub_state),
|
||||
- {atomic, ok} = mnesia:create_table(pubsub_state,
|
||||
- [{disc_copies, [node()]},
|
||||
- {local_content, true},
|
||||
- {attributes, record_info(fields, pubsub_state)}]),
|
||||
- FNew = fun () ->
|
||||
- lists:foreach(fun mnesia:write/1, NewRecs)
|
||||
|
@ -294,7 +292,6 @@
|
|||
- {atomic, ok} = mnesia:delete_table(pubsub_item),
|
||||
- {atomic, ok} = mnesia:create_table(pubsub_item,
|
||||
- [{disc_copies, [node()]},
|
||||
- {local_content, true},
|
||||
- {attributes, record_info(fields, pubsub_item)}]),
|
||||
- FNew = fun () ->
|
||||
- lists:foreach(fun mnesia:write/1, NewRecs)
|
||||
|
@ -312,7 +309,7 @@
|
|||
send_loop(State) ->
|
||||
receive
|
||||
{presence, JID, Pid} ->
|
||||
@@ -545,17 +298,15 @@
|
||||
@@ -542,17 +298,15 @@
|
||||
%% for each node From is subscribed to
|
||||
%% and if the node is so configured, send the last published item to From
|
||||
lists:foreach(fun(PType) ->
|
||||
|
@ -336,7 +333,7 @@
|
|||
true ->
|
||||
% resource not concerned about that subscription
|
||||
ok
|
||||
@@ -674,7 +425,8 @@
|
||||
@@ -671,7 +425,8 @@
|
||||
disco_identity(_Host, <<>>, _From) ->
|
||||
[{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []}];
|
||||
disco_identity(Host, Node, From) ->
|
||||
|
@ -346,7 +343,7 @@
|
|||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||
{result, _} ->
|
||||
{result, [{xmlelement, "identity", [{"category", "pubsub"}, {"type", "pep"}], []},
|
||||
@@ -709,7 +461,8 @@
|
||||
@@ -706,7 +461,8 @@
|
||||
[?NS_PUBSUB
|
||||
| [?NS_PUBSUB++"#"++Feature || Feature <- features("pep")]];
|
||||
disco_features(Host, Node, From) ->
|
||||
|
@ -356,7 +353,7 @@
|
|||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||
{result, _} ->
|
||||
{result, [?NS_PUBSUB
|
||||
@@ -734,7 +487,8 @@
|
||||
@@ -731,7 +487,8 @@
|
||||
Acc.
|
||||
|
||||
disco_items(Host, <<>>, From) ->
|
||||
|
@ -366,7 +363,7 @@
|
|||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||
{result, _} ->
|
||||
[{xmlelement, "item",
|
||||
@@ -752,13 +506,14 @@
|
||||
@@ -749,13 +506,14 @@
|
||||
_ -> Acc
|
||||
end
|
||||
end,
|
||||
|
@ -383,7 +380,7 @@
|
|||
case get_allowed_items_call(Host, Idx, From, Type, Options, Owners) of
|
||||
{result, Items} ->
|
||||
{result, [{xmlelement, "item",
|
||||
@@ -844,10 +599,10 @@
|
||||
@@ -841,10 +599,10 @@
|
||||
lists:foreach(fun(PType) ->
|
||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
||||
lists:foreach(fun
|
||||
|
@ -396,7 +393,7 @@
|
|||
true ->
|
||||
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
||||
false ->
|
||||
@@ -1002,7 +757,8 @@
|
||||
@@ -1012,7 +770,8 @@
|
||||
sub_el = SubEl} = IQ ->
|
||||
{xmlelement, _, QAttrs, _} = SubEl,
|
||||
Node = xml:get_attr_s("node", QAttrs),
|
||||
|
@ -406,7 +403,7 @@
|
|||
{result, IQRes} ->
|
||||
jlib:iq_to_xml(
|
||||
IQ#iq{type = result,
|
||||
@@ -1115,7 +871,7 @@
|
||||
@@ -1125,7 +884,7 @@
|
||||
[] ->
|
||||
["leaf"]; %% No sub-nodes: it's a leaf node
|
||||
_ ->
|
||||
|
@ -415,7 +412,7 @@
|
|||
{result, []} -> ["collection"];
|
||||
{result, _} -> ["leaf", "collection"];
|
||||
_ -> []
|
||||
@@ -1131,8 +887,9 @@
|
||||
@@ -1141,8 +900,9 @@
|
||||
[];
|
||||
true ->
|
||||
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
||||
|
@ -427,7 +424,7 @@
|
|||
end, features(Type))]
|
||||
end,
|
||||
%% TODO: add meta-data info (spec section 5.4)
|
||||
@@ -1161,8 +918,9 @@
|
||||
@@ -1171,8 +931,9 @@
|
||||
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
|
||||
{xmlelement, "feature", [{"var", ?NS_COMMANDS}], []},
|
||||
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
|
||||
|
@ -439,7 +436,7 @@
|
|||
end, features(Host, Node))};
|
||||
<<?NS_COMMANDS>> ->
|
||||
command_disco_info(Host, Node, From);
|
||||
@@ -1172,7 +930,7 @@
|
||||
@@ -1182,7 +943,7 @@
|
||||
node_disco_info(Host, Node, From)
|
||||
end.
|
||||
|
||||
|
@ -448,7 +445,7 @@
|
|||
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
|
||||
Nodes when is_list(Nodes) ->
|
||||
{result, lists:map(
|
||||
@@ -1189,23 +947,24 @@
|
||||
@@ -1199,23 +960,24 @@
|
||||
Other ->
|
||||
Other
|
||||
end;
|
||||
|
@ -479,7 +476,7 @@
|
|||
end,
|
||||
Nodes = lists:map(
|
||||
fun(#pubsub_node{nodeid = {_, SubNode}, options = SubOptions}) ->
|
||||
@@ -1223,7 +982,7 @@
|
||||
@@ -1233,7 +995,7 @@
|
||||
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
|
||||
{xmlelement, "item", [{"jid", Host}, {"name", Name}], []}
|
||||
end, NodeItems),
|
||||
|
@ -488,7 +485,7 @@
|
|||
end,
|
||||
case transaction(Host, Node, Action, sync_dirty) of
|
||||
{result, {_, Result}} -> {result, Result};
|
||||
@@ -1340,7 +1099,8 @@
|
||||
@@ -1344,7 +1106,8 @@
|
||||
(_, Acc) ->
|
||||
Acc
|
||||
end, [], xml:remove_cdata(Els)),
|
||||
|
@ -498,7 +495,7 @@
|
|||
{get, "subscriptions"} ->
|
||||
get_subscriptions(Host, Node, From, Plugins);
|
||||
{get, "affiliations"} ->
|
||||
@@ -1363,7 +1123,9 @@
|
||||
@@ -1367,7 +1130,9 @@
|
||||
|
||||
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
||||
{xmlelement, _, _, SubEls} = SubEl,
|
||||
|
@ -509,7 +506,7 @@
|
|||
case Action of
|
||||
[{xmlelement, Name, Attrs, Els}] ->
|
||||
Node = string_to_node(xml:get_attr_s("node", Attrs)),
|
||||
@@ -1493,7 +1255,8 @@
|
||||
@@ -1497,7 +1262,8 @@
|
||||
_ -> []
|
||||
end
|
||||
end,
|
||||
|
@ -519,7 +516,7 @@
|
|||
sync_dirty) of
|
||||
{result, Res} -> Res;
|
||||
Err -> Err
|
||||
@@ -1532,7 +1295,7 @@
|
||||
@@ -1536,7 +1302,7 @@
|
||||
|
||||
%%% authorization handling
|
||||
|
||||
|
@ -528,7 +525,7 @@
|
|||
Lang = "en", %% TODO fix
|
||||
Stanza = {xmlelement, "message",
|
||||
[],
|
||||
@@ -1561,7 +1324,7 @@
|
||||
@@ -1565,7 +1331,7 @@
|
||||
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
|
||||
lists:foreach(fun(Owner) ->
|
||||
ejabberd_router:route(service_jid(Host), jlib:make_jid(Owner), Stanza)
|
||||
|
@ -537,7 +534,7 @@
|
|||
|
||||
find_authorization_response(Packet) ->
|
||||
{xmlelement, _Name, _Attrs, Els} = Packet,
|
||||
@@ -1625,8 +1388,8 @@
|
||||
@@ -1629,8 +1395,8 @@
|
||||
"true" -> true;
|
||||
_ -> false
|
||||
end,
|
||||
|
@ -548,7 +545,7 @@
|
|||
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
|
||||
if
|
||||
not IsApprover ->
|
||||
@@ -1823,7 +1586,7 @@
|
||||
@@ -1827,7 +1593,7 @@
|
||||
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||
[{xmlelement, "create", nodeAttr(Node),
|
||||
[]}]}],
|
||||
|
@ -557,7 +554,7 @@
|
|||
{result, {NodeId, {Result, broadcast}}} ->
|
||||
broadcast_created_node(Host, Node, NodeId, Type, NodeOptions),
|
||||
case Result of
|
||||
@@ -1924,7 +1687,7 @@
|
||||
@@ -1928,7 +1694,7 @@
|
||||
%%<li>The node does not exist.</li>
|
||||
%%</ul>
|
||||
subscribe_node(Host, Node, From, JID, Configuration) ->
|
||||
|
@ -566,7 +563,7 @@
|
|||
{result, GoodSubOpts} -> GoodSubOpts;
|
||||
_ -> invalid
|
||||
end,
|
||||
@@ -1932,7 +1695,7 @@
|
||||
@@ -1936,7 +1702,7 @@
|
||||
error -> {"", "", ""};
|
||||
J -> jlib:jid_tolower(J)
|
||||
end,
|
||||
|
@ -575,7 +572,7 @@
|
|||
Features = features(Type),
|
||||
SubscribeFeature = lists:member("subscribe", Features),
|
||||
OptionsFeature = lists:member("subscription-options", Features),
|
||||
@@ -1941,6 +1704,7 @@
|
||||
@@ -1945,6 +1711,7 @@
|
||||
AccessModel = get_option(Options, access_model),
|
||||
SendLast = get_option(Options, send_last_published_item),
|
||||
AllowedGroups = get_option(Options, roster_groups_allowed, []),
|
||||
|
@ -583,7 +580,7 @@
|
|||
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, Subscriber, Owners, AccessModel, AllowedGroups),
|
||||
if
|
||||
not SubscribeFeature ->
|
||||
@@ -2279,7 +2043,7 @@
|
||||
@@ -2283,7 +2050,7 @@
|
||||
%% <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
|
||||
%% to read the items.
|
||||
|
@ -592,7 +589,7 @@
|
|||
MaxItems =
|
||||
if
|
||||
SMaxItems == "" -> get_max_items_node(Host);
|
||||
@@ -2293,12 +2057,13 @@
|
||||
@@ -2297,12 +2064,13 @@
|
||||
{error, Error} ->
|
||||
{error, Error};
|
||||
_ ->
|
||||
|
@ -607,7 +604,7 @@
|
|||
{PresenceSubscription, RosterGroup} = get_presence_and_roster_permissions(Host, From, Owners, AccessModel, AllowedGroups),
|
||||
if
|
||||
not RetreiveFeature ->
|
||||
@@ -2311,11 +2076,11 @@
|
||||
@@ -2315,11 +2083,11 @@
|
||||
node_call(Type, get_items,
|
||||
[NodeId, From,
|
||||
AccessModel, PresenceSubscription, RosterGroup,
|
||||
|
@ -621,7 +618,7 @@
|
|||
SendItems = case ItemIDs of
|
||||
[] ->
|
||||
Items;
|
||||
@@ -2328,7 +2093,8 @@
|
||||
@@ -2332,7 +2100,8 @@
|
||||
%% number of items sent to MaxItems:
|
||||
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||
[{xmlelement, "items", nodeAttr(Node),
|
||||
|
@ -631,7 +628,7 @@
|
|||
Error ->
|
||||
Error
|
||||
end
|
||||
@@ -2350,10 +2116,15 @@
|
||||
@@ -2354,10 +2123,15 @@
|
||||
Error -> Error
|
||||
end.
|
||||
get_allowed_items_call(Host, NodeIdx, From, Type, Options, Owners) ->
|
||||
|
@ -648,7 +645,7 @@
|
|||
|
||||
|
||||
%% @spec (Host, Node, NodeId, Type, LJID, Number) -> any()
|
||||
@@ -2366,27 +2137,27 @@
|
||||
@@ -2370,27 +2144,27 @@
|
||||
%% @doc <p>Resend the items of a node to the user.</p>
|
||||
%% @todo use cache-last-item feature
|
||||
send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, last) ->
|
||||
|
@ -692,7 +689,7 @@
|
|||
end
|
||||
end;
|
||||
send_items(Host, Node, NodeId, Type, {U,S,R} = LJID, Number) ->
|
||||
@@ -2527,7 +2298,8 @@
|
||||
@@ -2531,7 +2305,8 @@
|
||||
error ->
|
||||
{error, ?ERR_BAD_REQUEST};
|
||||
_ ->
|
||||
|
@ -702,7 +699,7 @@
|
|||
case lists:member(Owner, Owners) of
|
||||
true ->
|
||||
OwnerJID = jlib:make_jid(Owner),
|
||||
@@ -2537,24 +2309,7 @@
|
||||
@@ -2541,24 +2316,7 @@
|
||||
end,
|
||||
lists:foreach(
|
||||
fun({JID, Affiliation}) ->
|
||||
|
@ -728,7 +725,7 @@
|
|||
end, FilteredEntities),
|
||||
{result, []};
|
||||
_ ->
|
||||
@@ -2607,9 +2362,9 @@
|
||||
@@ -2611,9 +2369,9 @@
|
||||
end.
|
||||
|
||||
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
||||
|
@ -740,7 +737,7 @@
|
|||
OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)},
|
||||
{"subid", SubID}|nodeAttr(Node)],
|
||||
[XdataEl]},
|
||||
@@ -2641,7 +2396,7 @@
|
||||
@@ -2645,7 +2403,7 @@
|
||||
end.
|
||||
|
||||
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
||||
|
@ -749,7 +746,7 @@
|
|||
{result, GoodSubOpts} -> GoodSubOpts;
|
||||
_ -> invalid
|
||||
end,
|
||||
@@ -2840,8 +2595,8 @@
|
||||
@@ -2844,8 +2602,8 @@
|
||||
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
|
||||
ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza)
|
||||
end,
|
||||
|
@ -760,7 +757,7 @@
|
|||
true ->
|
||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||
|
||||
@@ -3204,7 +2959,7 @@
|
||||
@@ -3208,7 +2966,7 @@
|
||||
Collection = tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]),
|
||||
{result, [{Depth, [{N, sub_with_options(N)} || N <- Nodes]} || {Depth, Nodes} <- Collection]}
|
||||
end,
|
||||
|
@ -769,7 +766,7 @@
|
|||
{result, CollSubs} -> subscribed_nodes_by_jid(NotifyType, CollSubs);
|
||||
_ -> []
|
||||
end.
|
||||
@@ -3273,8 +3028,8 @@
|
||||
@@ -3277,8 +3035,8 @@
|
||||
[]
|
||||
end.
|
||||
sub_with_options(JID, NodeId, SubId) ->
|
||||
|
@ -780,7 +777,7 @@
|
|||
_ -> {JID, SubId, []}
|
||||
end.
|
||||
|
||||
@@ -3350,6 +3105,30 @@
|
||||
@@ -3354,6 +3112,30 @@
|
||||
Result
|
||||
end.
|
||||
|
||||
|
@ -811,7 +808,7 @@
|
|||
%% @spec (Host, Options) -> MaxItems
|
||||
%% Host = host()
|
||||
%% Options = [Option]
|
||||
@@ -3480,7 +3259,7 @@
|
||||
@@ -3484,7 +3266,7 @@
|
||||
end
|
||||
end,
|
||||
case transaction(Host, Node, Action, transaction) of
|
||||
|
@ -820,7 +817,7 @@
|
|||
NodeId = TNode#pubsub_node.id,
|
||||
Type = TNode#pubsub_node.type,
|
||||
Options = TNode#pubsub_node.options,
|
||||
@@ -3746,7 +3525,13 @@
|
||||
@@ -3750,7 +3532,13 @@
|
||||
tree_action(Host, Function, Args) ->
|
||||
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
|
||||
Fun = fun() -> tree_call(Host, Function, Args) end,
|
||||
|
@ -835,7 +832,7 @@
|
|||
|
||||
%% @doc <p>node plugin call.</p>
|
||||
node_call(Type, Function, Args) ->
|
||||
@@ -3766,13 +3551,13 @@
|
||||
@@ -3770,13 +3558,13 @@
|
||||
|
||||
node_action(Host, Type, Function, Args) ->
|
||||
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
|
||||
|
@ -851,7 +848,7 @@
|
|||
case tree_call(Host, get_node, [Host, Node]) of
|
||||
N when is_record(N, pubsub_node) ->
|
||||
case Action(N) of
|
||||
@@ -3784,13 +3569,19 @@
|
||||
@@ -3788,13 +3576,19 @@
|
||||
Error
|
||||
end
|
||||
end, Trans).
|
||||
|
@ -875,7 +872,7 @@
|
|||
{result, Result} -> {result, Result};
|
||||
{error, Error} -> {error, Error};
|
||||
{atomic, {result, Result}} -> {result, Result};
|
||||
@@ -3798,6 +3589,15 @@
|
||||
@@ -3802,6 +3596,15 @@
|
||||
{aborted, Reason} ->
|
||||
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
|
@ -891,7 +888,7 @@
|
|||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
@@ -3806,6 +3606,17 @@
|
||||
@@ -3810,6 +3613,17 @@
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||
end.
|
||||
|
||||
|
|
|
@ -153,7 +153,6 @@ parse_options_xform(XFields) ->
|
|||
create_table() ->
|
||||
case mnesia:create_table(pubsub_subscription,
|
||||
[{disc_copies, [node()]},
|
||||
{local_content, true},
|
||||
{attributes, record_info(fields, pubsub_subscription)},
|
||||
{type, set}]) of
|
||||
{atomic, ok} -> ok;
|
||||
|
|
|
@ -1,359 +0,0 @@
|
|||
%%%----------------------------------------------------------------------
|
||||
%%% 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