mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-02 21:17:12 +02:00
several improvements, and fix odbc subscriptions issues
SVN Revision: 2553
This commit is contained in:
parent
217d3131c8
commit
2fdabe8b5b
|
@ -1409,7 +1409,11 @@ send_pending_auth_events(Host, Node, Owner) ->
|
||||||
true ->
|
true ->
|
||||||
case node_call(Type, get_affiliation, [NodeID, Owner]) of
|
case node_call(Type, get_affiliation, [NodeID, Owner]) of
|
||||||
{result, owner} ->
|
{result, owner} ->
|
||||||
broadcast_pending_auth_events(N),
|
{result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
|
||||||
|
lists:foreach(fun({J, pending, _SubID}) -> send_authorization_request(N, jlib:make_jid(J));
|
||||||
|
({J, pending}) -> send_authorization_request(N, jlib:make_jid(J));
|
||||||
|
(_) -> ok
|
||||||
|
end, Subscriptions),
|
||||||
{result, ok};
|
{result, ok};
|
||||||
_ ->
|
_ ->
|
||||||
{error, ?ERR_FORBIDDEN}
|
{error, ?ERR_FORBIDDEN}
|
||||||
|
@ -1425,14 +1429,6 @@ send_pending_auth_events(Host, Node, Owner) ->
|
||||||
Err
|
Err
|
||||||
end.
|
end.
|
||||||
|
|
||||||
broadcast_pending_auth_events(#pubsub_node{type = Type, id = NodeID} = Node) ->
|
|
||||||
{result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
|
|
||||||
lists:foreach(fun ({J, pending, _SubID}) ->
|
|
||||||
send_authorization_request(Node, jlib:make_jid(J));
|
|
||||||
({J, pending}) ->
|
|
||||||
send_authorization_request(Node, jlib:make_jid(J))
|
|
||||||
end, Subscriptions).
|
|
||||||
|
|
||||||
%%% authorization handling
|
%%% authorization handling
|
||||||
|
|
||||||
send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}}, Subscriber) ->
|
send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}}, Subscriber) ->
|
||||||
|
@ -1762,18 +1758,22 @@ delete_node(_Host, [], _Owner) ->
|
||||||
{error, ?ERR_NOT_ALLOWED};
|
{error, ?ERR_NOT_ALLOWED};
|
||||||
delete_node(Host, Node, Owner) ->
|
delete_node(Host, Node, Owner) ->
|
||||||
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
SubsByDepth = get_collection_subscriptions(Host, Node),
|
SubsByDepth = get_collection_subscriptions(Host, Node),
|
||||||
case node_call(Type, get_affiliation, [NodeId, Owner]) of
|
case node_call(Type, get_affiliation, [NodeId, Owner]) of
|
||||||
{result, owner} ->
|
{result, owner} ->
|
||||||
Removed = tree_call(Host, delete_node, [Host, Node]),
|
SubsByDepth = case tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]) of
|
||||||
case node_call(Type, delete_node, [Removed]) of
|
{result, T} -> [{Depth, [{N, get_node_subs(N)} || N <- Nodes]} || {Depth, Nodes} <- T];
|
||||||
|
_ -> []
|
||||||
|
end,
|
||||||
|
Removed = tree_call(Host, delete_node, [Host, Node]),
|
||||||
|
case node_call(Type, delete_node, [Removed]) of
|
||||||
{result, Res} -> {result, {SubsByDepth, Res}};
|
{result, Res} -> {result, {SubsByDepth, Res}};
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
%% Entity is not an owner
|
%% Entity is not an owner
|
||||||
{error, ?ERR_FORBIDDEN}
|
{error, ?ERR_FORBIDDEN}
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Reply = [],
|
Reply = [],
|
||||||
case transaction(Host, Node, Action, transaction) of
|
case transaction(Host, Node, Action, transaction) of
|
||||||
|
@ -2959,24 +2959,28 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_collection_subscriptions(Host, Node) ->
|
get_collection_subscriptions(Host, Node) ->
|
||||||
lists:map(fun ({Depth, Nodes}) ->
|
Action = fun() ->
|
||||||
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
|
{result, lists:map(fun({Depth, Nodes}) ->
|
||||||
end, tree_action(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)])).
|
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
|
||||||
|
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
|
||||||
get_node_subs(#pubsub_node{type = Type,
|
end,
|
||||||
nodeid = {Host, Node},
|
case transaction(Action, sync_dirty) of
|
||||||
id = NodeID}) ->
|
{result, CollSubs} -> CollSubs;
|
||||||
case node_action(Host, Type, get_node_subscriptions, [NodeID]) of
|
_ -> []
|
||||||
{result, Subs} ->
|
|
||||||
get_options_for_subs(Host, Node, NodeID, Subs);
|
|
||||||
Other ->
|
|
||||||
Other
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_options_for_subs(_Host, Node, NodeID, Subs) ->
|
get_node_subs(#pubsub_node{type = Type,
|
||||||
|
id = NodeID}) ->
|
||||||
|
case node_call(Type, get_node_subscriptions, [NodeID]) of
|
||||||
|
{result, Subs} -> get_options_for_subs(NodeID, Subs);
|
||||||
|
Other -> Other
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_options_for_subs(NodeID, Subs) ->
|
||||||
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
|
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
|
||||||
case pubsub_subscription:get_subscription(JID, NodeID, SubID) of
|
case pubsub_subscription:read_subscription(JID, NodeID, SubID) of
|
||||||
{result, #pubsub_subscription{options = Options}} -> [{JID, Node, Options} | Acc];
|
{error, notfound} -> [{JID, SubID, []} | Acc];
|
||||||
|
#pubsub_subscription{options = Options} -> [{JID, SubID, Options} | Acc];
|
||||||
_ -> Acc
|
_ -> Acc
|
||||||
end;
|
end;
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
|
@ -3006,8 +3010,7 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
|
||||||
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
||||||
From = service_jid(Host),
|
From = service_jid(Host),
|
||||||
%% Handles explicit subscriptions
|
%% Handles explicit subscriptions
|
||||||
FilteredSubsByDepth = depths_to_deliver(NotifyType, SubsByDepth),
|
NodesByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
|
||||||
NodesByJID = collate_subs_by_jid(FilteredSubsByDepth),
|
|
||||||
lists:foreach(fun ({LJID, Nodes}) ->
|
lists:foreach(fun ({LJID, Nodes}) ->
|
||||||
LJIDs = case BroadcastAll of
|
LJIDs = case BroadcastAll of
|
||||||
true ->
|
true ->
|
||||||
|
@ -3068,36 +3071,28 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
depths_to_deliver(NotifyType, SubsByDepth) ->
|
subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
|
||||||
NodesToDeliver =
|
NodesToDeliver = fun(Depth, Node, Subs, Acc) ->
|
||||||
fun (Depth, Node, Subs, Acc) ->
|
NodeId = case Node#pubsub_node.nodeid of
|
||||||
lists:foldl(fun ({LJID, _Node, SubOptions} = S, Acc2) ->
|
{_, N} -> N;
|
||||||
|
Other -> Other
|
||||||
|
end,
|
||||||
|
NodeOptions = Node#pubsub_node.options,
|
||||||
|
lists:foldl(fun({LJID, _SubID, SubOptions}, Acc2) ->
|
||||||
case is_to_deliver(LJID, NotifyType, Depth,
|
case is_to_deliver(LJID, NotifyType, Depth,
|
||||||
Node#pubsub_node.options,
|
NodeOptions, SubOptions) of
|
||||||
SubOptions) of
|
true -> [{LJID, NodeId}|Acc2];
|
||||||
true -> [S | Acc2];
|
|
||||||
false -> Acc2
|
false -> Acc2
|
||||||
end
|
end
|
||||||
end, Acc, Subs)
|
end, Acc, Subs)
|
||||||
end,
|
end,
|
||||||
|
DepthsToDeliver = fun({Depth, SubsByNode}, Acc) ->
|
||||||
DepthsToDeliver =
|
lists:foldl(fun({Node, Subs}, Acc2) ->
|
||||||
fun ({Depth, SubsByNode}, Acc) ->
|
|
||||||
lists:foldl(fun ({Node, Subs}, Acc2) ->
|
|
||||||
NodesToDeliver(Depth, Node, Subs, Acc2)
|
NodesToDeliver(Depth, Node, Subs, Acc2)
|
||||||
end, Acc, SubsByNode)
|
end, Acc, SubsByNode)
|
||||||
end,
|
end,
|
||||||
|
JIDSubs = lists:foldl(DepthsToDeliver, [], SubsByDepth),
|
||||||
lists:foldl(DepthsToDeliver, [], SubsByDepth).
|
[{LJID, proplists:append_values(LJID, JIDSubs)} || LJID <- proplists:get_keys(JIDSubs)].
|
||||||
|
|
||||||
collate_subs_by_jid(SubsByDepth) ->
|
|
||||||
lists:foldl(fun ({JID, Node, _Options}, Acc) ->
|
|
||||||
OldNodes = case lists:keysearch(JID, 1, Acc) of
|
|
||||||
{value, {JID, Nodes}} -> Nodes;
|
|
||||||
false -> []
|
|
||||||
end,
|
|
||||||
lists:keystore(JID, 1, Acc, {JID, [Node | OldNodes]})
|
|
||||||
end, [], SubsByDepth).
|
|
||||||
|
|
||||||
%% If we don't know the resource, just pick first if any
|
%% If we don't know the resource, just pick first if any
|
||||||
%% If no resource available, check if caps anyway (remote online)
|
%% If no resource available, check if caps anyway (remote online)
|
||||||
|
|
|
@ -1093,9 +1093,10 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
|
||||||
|
|
||||||
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
||||||
{xmlelement, _, _, SubEls} = SubEl,
|
{xmlelement, _, _, SubEls} = SubEl,
|
||||||
Action = lists:filter(fun({xmlelement, "set", _, _}) -> false;
|
NoRSM = lists:filter(fun({xmlelement, Name, _, _}) ->
|
||||||
(_) -> true
|
Name == "set"
|
||||||
end, xml:remove_cdata(SubEls)),
|
end, SubEls),
|
||||||
|
Action = xml:remove_cdata(SubEls) -- NoRSM,
|
||||||
case Action of
|
case Action of
|
||||||
[{xmlelement, Name, Attrs, Els}] ->
|
[{xmlelement, Name, Attrs, Els}] ->
|
||||||
Node = case Host of
|
Node = case Host of
|
||||||
|
@ -1240,7 +1241,11 @@ send_pending_auth_events(Host, Node, Owner) ->
|
||||||
true ->
|
true ->
|
||||||
case node_call(Type, get_affiliation, [NodeID, Owner]) of
|
case node_call(Type, get_affiliation, [NodeID, Owner]) of
|
||||||
{result, owner} ->
|
{result, owner} ->
|
||||||
broadcast_pending_auth_events(N),
|
{result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
|
||||||
|
lists:foreach(fun({J, pending, _SubID}) -> send_authorization_request(N, jlib:make_jid(J));
|
||||||
|
({J, pending}) -> send_authorization_request(N, jlib:make_jid(J));
|
||||||
|
(_) -> ok
|
||||||
|
end, Subscriptions),
|
||||||
{result, ok};
|
{result, ok};
|
||||||
_ ->
|
_ ->
|
||||||
{error, ?ERR_FORBIDDEN}
|
{error, ?ERR_FORBIDDEN}
|
||||||
|
@ -1256,14 +1261,6 @@ send_pending_auth_events(Host, Node, Owner) ->
|
||||||
Err
|
Err
|
||||||
end.
|
end.
|
||||||
|
|
||||||
broadcast_pending_auth_events(#pubsub_node{type = Type, id = NodeID} = Node) ->
|
|
||||||
{result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
|
|
||||||
lists:foreach(fun ({J, pending, _SubID}) ->
|
|
||||||
send_authorization_request(Node, jlib:make_jid(J));
|
|
||||||
({J, pending}) ->
|
|
||||||
send_authorization_request(Node, jlib:make_jid(J))
|
|
||||||
end, Subscriptions).
|
|
||||||
|
|
||||||
%%% authorization handling
|
%%% authorization handling
|
||||||
|
|
||||||
send_authorization_request(#pubsub_node{nodeid = {Host, Node}, type = Type, id = NodeId}, Subscriber) ->
|
send_authorization_request(#pubsub_node{nodeid = {Host, Node}, type = Type, id = NodeId}, Subscriber) ->
|
||||||
|
@ -1593,18 +1590,19 @@ delete_node(_Host, [], _Owner) ->
|
||||||
{error, ?ERR_NOT_ALLOWED};
|
{error, ?ERR_NOT_ALLOWED};
|
||||||
delete_node(Host, Node, Owner) ->
|
delete_node(Host, Node, Owner) ->
|
||||||
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
SubsByDepth = get_collection_subscriptions(Host, Node),
|
case node_call(Type, get_affiliation, [NodeId, Owner]) of
|
||||||
case node_call(Type, get_affiliation, [NodeId, Owner]) of
|
{result, owner} ->
|
||||||
{result, owner} ->
|
ParentTree = tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]),
|
||||||
Removed = tree_call(Host, delete_node, [Host, Node]),
|
SubsByDepth = [{Depth, [{N, get_node_subs(N)} || N <- Nodes]} || {Depth, Nodes} <- ParentTree],
|
||||||
case node_call(Type, delete_node, [Removed]) of
|
Removed = tree_call(Host, delete_node, [Host, Node]),
|
||||||
|
case node_call(Type, delete_node, [Removed]) of
|
||||||
{result, Res} -> {result, {SubsByDepth, Res}};
|
{result, Res} -> {result, {SubsByDepth, Res}};
|
||||||
Error -> Error
|
Error -> Error
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
%% Entity is not an owner
|
%% Entity is not an owner
|
||||||
{error, ?ERR_FORBIDDEN}
|
{error, ?ERR_FORBIDDEN}
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
Reply = [],
|
Reply = [],
|
||||||
case transaction(Host, Node, Action, transaction) of
|
case transaction(Host, Node, Action, transaction) of
|
||||||
|
@ -1656,7 +1654,7 @@ delete_node(Host, Node, Owner) ->
|
||||||
%%<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) ->
|
||||||
{result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration),
|
{result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration),
|
||||||
Subscriber = case jlib:string_to_jid(JID) of
|
Subscriber = case jlib:string_to_jid(JID) of
|
||||||
error -> {"", "", ""};
|
error -> {"", "", ""};
|
||||||
J -> jlib:jid_tolower(J)
|
J -> jlib:jid_tolower(J)
|
||||||
|
@ -2289,11 +2287,11 @@ get_options_helper(JID, Lang, NodeID, SubID, Type) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_sub(Subscriber, NodeID, SubID, Lang) ->
|
read_sub(Subscriber, NodeID, SubID, Lang) ->
|
||||||
case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of
|
case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of
|
||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
{result, #pubsub_subscription{options = Options}} ->
|
{result, #pubsub_subscription{options = Options}} ->
|
||||||
pubsub_subscription:get_options_xform(Lang, Options)
|
pubsub_subscription_odbc:get_options_xform(Lang, Options)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_options(Host, Node, JID, SubID, Configuration) ->
|
set_options(Host, Node, JID, SubID, Configuration) ->
|
||||||
|
@ -2318,7 +2316,7 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
||||||
error -> {"", "", ""};
|
error -> {"", "", ""};
|
||||||
J -> jlib:jid_tolower(J)
|
J -> jlib:jid_tolower(J)
|
||||||
end,
|
end,
|
||||||
{result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration),
|
{result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration),
|
||||||
{result, Subs} = node_call(Type, get_subscriptions,
|
{result, Subs} = node_call(Type, get_subscriptions,
|
||||||
[NodeID, Subscriber]),
|
[NodeID, Subscriber]),
|
||||||
SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
|
SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
|
||||||
|
@ -2338,7 +2336,7 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
write_sub(Subscriber, NodeID, SubID, Options) ->
|
write_sub(Subscriber, NodeID, SubID, Options) ->
|
||||||
case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID,
|
case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID,
|
||||||
Options) of
|
Options) of
|
||||||
{error, notfound} ->
|
{error, notfound} ->
|
||||||
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
|
@ -2785,24 +2783,28 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_collection_subscriptions(Host, Node) ->
|
get_collection_subscriptions(Host, Node) ->
|
||||||
lists:map(fun ({Depth, Nodes}) ->
|
Action = fun() ->
|
||||||
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
|
{result, lists:map(fun({Depth, Nodes}) ->
|
||||||
end, tree_action(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)])).
|
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
|
||||||
|
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
|
||||||
get_node_subs(#pubsub_node{type = Type,
|
end,
|
||||||
nodeid = {Host, Node},
|
case transaction(Host, Action, sync_dirty) of
|
||||||
id = NodeID}) ->
|
{result, CollSubs} -> CollSubs;
|
||||||
case node_action(Host, Type, get_node_subscriptions, [NodeID]) of
|
_ -> []
|
||||||
{result, Subs} ->
|
|
||||||
get_options_for_subs(Host, Node, NodeID, Subs);
|
|
||||||
Other ->
|
|
||||||
Other
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_options_for_subs(_Host, Node, NodeID, Subs) ->
|
get_node_subs(#pubsub_node{type = Type,
|
||||||
|
id = NodeID}) ->
|
||||||
|
case node_call(Type, get_node_subscriptions, [NodeID]) of
|
||||||
|
{result, Subs} -> get_options_for_subs(NodeID, Subs);
|
||||||
|
Other -> Other
|
||||||
|
end.
|
||||||
|
|
||||||
|
get_options_for_subs(NodeID, Subs) ->
|
||||||
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
|
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
|
||||||
case pubsub_subscription:get_subscription(JID, NodeID, SubID) of
|
case pubsub_subscription_odbc:get_subscription(JID, NodeID, SubID) of
|
||||||
{result, #pubsub_subscription{options = Options}} -> [{JID, Node, Options} | Acc];
|
{error, notfound} -> [{JID, SubID, []} | Acc];
|
||||||
|
{result, #pubsub_subscription{options = Options}} -> [{JID, SubID, Options} | Acc];
|
||||||
_ -> Acc
|
_ -> Acc
|
||||||
end;
|
end;
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
|
@ -2832,8 +2834,7 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
|
||||||
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
|
||||||
From = service_jid(Host),
|
From = service_jid(Host),
|
||||||
%% Handles explicit subscriptions
|
%% Handles explicit subscriptions
|
||||||
FilteredSubsByDepth = depths_to_deliver(NotifyType, SubsByDepth),
|
NodesByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
|
||||||
NodesByJID = collate_subs_by_jid(FilteredSubsByDepth),
|
|
||||||
lists:foreach(fun ({LJID, Nodes}) ->
|
lists:foreach(fun ({LJID, Nodes}) ->
|
||||||
LJIDs = case BroadcastAll of
|
LJIDs = case BroadcastAll of
|
||||||
true ->
|
true ->
|
||||||
|
@ -2894,36 +2895,28 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
depths_to_deliver(NotifyType, SubsByDepth) ->
|
subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
|
||||||
NodesToDeliver =
|
NodesToDeliver = fun(Depth, Node, Subs, Acc) ->
|
||||||
fun (Depth, Node, Subs, Acc) ->
|
NodeId = case Node#pubsub_node.nodeid of
|
||||||
lists:foldl(fun ({LJID, _Node, SubOptions} = S, Acc2) ->
|
{_, N} -> N;
|
||||||
|
Other -> Other
|
||||||
|
end,
|
||||||
|
NodeOptions = Node#pubsub_node.options,
|
||||||
|
lists:foldl(fun({LJID, _SubID, SubOptions}, Acc2) ->
|
||||||
case is_to_deliver(LJID, NotifyType, Depth,
|
case is_to_deliver(LJID, NotifyType, Depth,
|
||||||
Node#pubsub_node.options,
|
NodeOptions, SubOptions) of
|
||||||
SubOptions) of
|
true -> [{LJID, NodeId}|Acc2];
|
||||||
true -> [S | Acc2];
|
|
||||||
false -> Acc2
|
false -> Acc2
|
||||||
end
|
end
|
||||||
end, Acc, Subs)
|
end, Acc, Subs)
|
||||||
end,
|
end,
|
||||||
|
DepthsToDeliver = fun({Depth, SubsByNode}, Acc) ->
|
||||||
DepthsToDeliver =
|
lists:foldl(fun({Node, Subs}, Acc2) ->
|
||||||
fun ({Depth, SubsByNode}, Acc) ->
|
|
||||||
lists:foldl(fun ({Node, Subs}, Acc2) ->
|
|
||||||
NodesToDeliver(Depth, Node, Subs, Acc2)
|
NodesToDeliver(Depth, Node, Subs, Acc2)
|
||||||
end, Acc, SubsByNode)
|
end, Acc, SubsByNode)
|
||||||
end,
|
end,
|
||||||
|
JIDSubs = lists:foldl(DepthsToDeliver, [], SubsByDepth),
|
||||||
lists:foldl(DepthsToDeliver, [], SubsByDepth).
|
[{LJID, proplists:append_values(LJID, JIDSubs)} || LJID <- proplists:get_keys(JIDSubs)].
|
||||||
|
|
||||||
collate_subs_by_jid(SubsByDepth) ->
|
|
||||||
lists:foldl(fun ({JID, Node, _Options}, Acc) ->
|
|
||||||
OldNodes = case lists:keysearch(JID, 1, Acc) of
|
|
||||||
{value, {JID, Nodes}} -> Nodes;
|
|
||||||
false -> []
|
|
||||||
end,
|
|
||||||
lists:keystore(JID, 1, Acc, {JID, [Node | OldNodes]})
|
|
||||||
end, [], SubsByDepth).
|
|
||||||
|
|
||||||
%% If we don't know the resource, just pick first if any
|
%% If we don't know the resource, just pick first if any
|
||||||
%% If no resource available, check if caps anyway (remote online)
|
%% If no resource available, check if caps anyway (remote online)
|
||||||
|
|
|
@ -62,7 +62,8 @@
|
||||||
get_item/7,
|
get_item/7,
|
||||||
get_item/2,
|
get_item/2,
|
||||||
set_item/1,
|
set_item/1,
|
||||||
get_item_name/3
|
get_item_name/3,
|
||||||
|
get_last_items/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
|
||||||
|
@ -190,3 +191,7 @@ set_item(Item) ->
|
||||||
|
|
||||||
get_item_name(Host, Node, Id) ->
|
get_item_name(Host, Node, Id) ->
|
||||||
node_hometree_odbc:get_item_name(Host, Node, Id).
|
node_hometree_odbc:get_item_name(Host, Node, Id).
|
||||||
|
|
||||||
|
get_last_items(NodeId, From, Count) ->
|
||||||
|
node_hometree_odbc:get_last_items(NodeId, From, Count).
|
||||||
|
|
||||||
|
|
|
@ -392,8 +392,7 @@ unsubscribe_node(NodeId, Sender, Subscriber, SubId) ->
|
||||||
delete_subscription(SubKey, NodeId, S, Affiliation, Subscriptions),
|
delete_subscription(SubKey, NodeId, S, Affiliation, Subscriptions),
|
||||||
{result, default};
|
{result, default};
|
||||||
false ->
|
false ->
|
||||||
{error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST,
|
{error, ?ERR_EXTENDED(?ERR_UNEXPECTED_REQUEST, "not-subscribed")}
|
||||||
"not-subscribed")}
|
|
||||||
end;
|
end;
|
||||||
%% No subid supplied, but there's only one matching
|
%% No subid supplied, but there's only one matching
|
||||||
%% subscription, so use that.
|
%% subscription, so use that.
|
||||||
|
@ -702,10 +701,18 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
|
||||||
end,
|
end,
|
||||||
Reply = case catch ejabberd_odbc:sql_query_t(Query) of
|
Reply = case catch ejabberd_odbc:sql_query_t(Query) of
|
||||||
{selected, ["node", "type", "nodeid", "jid", "subscriptions"], RItems} ->
|
{selected, ["node", "type", "nodeid", "jid", "subscriptions"], RItems} ->
|
||||||
lists:map(fun({N, T, I, J, S}) ->
|
lists:foldl(fun({N, T, I, J, S}, Acc) ->
|
||||||
Node = nodetree_tree_odbc:raw_to_node(Host, {N, "", T, I}),
|
Node = nodetree_tree_odbc:raw_to_node(Host, {N, "", T, I}),
|
||||||
{Node, decode_subscriptions(S), decode_jid(J)}
|
Jid = decode_jid(J),
|
||||||
end, RItems);
|
case decode_subscriptions(S) of
|
||||||
|
[] ->
|
||||||
|
[{Node, none, Jid}|Acc];
|
||||||
|
Subs ->
|
||||||
|
lists:foldl(fun({Sub, SubId}, Acc2) -> [{Node, Sub, SubId, Jid}|Acc2];
|
||||||
|
(Sub, Acc2) -> [{Node, Sub, Jid}|Acc2]
|
||||||
|
end, Acc, Subs)
|
||||||
|
end
|
||||||
|
end, [], RItems);
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
|
@ -717,8 +724,17 @@ get_node_subscriptions(NodeId) ->
|
||||||
"from pubsub_state "
|
"from pubsub_state "
|
||||||
"where nodeid='", NodeId, "';"]) of
|
"where nodeid='", NodeId, "';"]) of
|
||||||
{selected, ["jid", "subscriptions"], RItems} ->
|
{selected, ["jid", "subscriptions"], RItems} ->
|
||||||
lists:map(fun({J, S}) -> {decode_jid(J), decode_subscriptions(S)} end, RItems);
|
lists:foldl(fun({J, S}, Acc) ->
|
||||||
% TODO {J, S, SubId}
|
Jid = decode_jid(J),
|
||||||
|
case decode_subscriptions(S) of
|
||||||
|
[] ->
|
||||||
|
[{Jid, none}|Acc];
|
||||||
|
Subs ->
|
||||||
|
lists:foldl(fun({Sub, SubId}, Acc2) -> [{Jid, Sub, SubId}|Acc2];
|
||||||
|
(Sub, Acc2) -> [{Jid, Sub}|Acc2]
|
||||||
|
end, Acc, Subs)
|
||||||
|
end
|
||||||
|
end, [], RItems);
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
|
@ -731,7 +747,7 @@ get_subscriptions(NodeId, Owner) ->
|
||||||
["select subscriptions from pubsub_state "
|
["select subscriptions from pubsub_state "
|
||||||
"where nodeid='", NodeId, "' and jid='", J, "';"]) of
|
"where nodeid='", NodeId, "' and jid='", J, "';"]) of
|
||||||
{selected, ["subscriptions"], [{S}]} -> decode_subscriptions(S);
|
{selected, ["subscriptions"], [{S}]} -> decode_subscriptions(S);
|
||||||
_ -> none
|
_ -> []
|
||||||
end,
|
end,
|
||||||
{result, Reply}.
|
{result, Reply}.
|
||||||
|
|
||||||
|
@ -1223,7 +1239,7 @@ select_affiliation_subscriptions(NodeId, JID) ->
|
||||||
{selected, ["affiliation", "subscriptions"], [{A, S}]} ->
|
{selected, ["affiliation", "subscriptions"], [{A, S}]} ->
|
||||||
{decode_affiliation(A), decode_subscriptions(S)};
|
{decode_affiliation(A), decode_subscriptions(S)};
|
||||||
_ ->
|
_ ->
|
||||||
{none, none}
|
{none, []}
|
||||||
end.
|
end.
|
||||||
select_affiliation_subscriptions(NodeId, JID, JID) ->
|
select_affiliation_subscriptions(NodeId, JID, JID) ->
|
||||||
select_affiliation_subscriptions(NodeId, JID);
|
select_affiliation_subscriptions(NodeId, JID);
|
||||||
|
|
|
@ -151,7 +151,7 @@ get_parentnodes(_Host, _Node, _From) ->
|
||||||
get_parentnodes_tree(Host, Node, From) ->
|
get_parentnodes_tree(Host, Node, From) ->
|
||||||
case get_node(Host, Node, From) of
|
case get_node(Host, Node, From) of
|
||||||
N when is_record(N, pubsub_node) -> [{0, [N]}];
|
N when is_record(N, pubsub_node) -> [{0, [N]}];
|
||||||
Error -> Error
|
_Error -> []
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @spec (Host, Node, From) -> [pubsubNode()] | {error, Reason}
|
%% @spec (Host, Node, From) -> [pubsubNode()] | {error, Reason}
|
||||||
|
|
|
@ -88,13 +88,11 @@ options() ->
|
||||||
[{virtual_tree, false},
|
[{virtual_tree, false},
|
||||||
{odbc, true}].
|
{odbc, true}].
|
||||||
|
|
||||||
|
|
||||||
get_node(Host, Node, _From) ->
|
|
||||||
get_node(Host, Node).
|
|
||||||
|
|
||||||
%% @spec (Host, Node) -> pubsubNode() | {error, Reason}
|
%% @spec (Host, Node) -> pubsubNode() | {error, Reason}
|
||||||
%% Host = mod_pubsub:host()
|
%% Host = mod_pubsub:host()
|
||||||
%% Node = mod_pubsub:pubsubNode()
|
%% Node = mod_pubsub:pubsubNode()
|
||||||
|
get_node(Host, Node, _From) ->
|
||||||
|
get_node(Host, Node).
|
||||||
get_node(Host, Node) ->
|
get_node(Host, Node) ->
|
||||||
H = ?PUBSUB:escape(Host),
|
H = ?PUBSUB:escape(Host),
|
||||||
N = ?PUBSUB:escape(?PUBSUB:node_to_string(Node)),
|
N = ?PUBSUB:escape(?PUBSUB:node_to_string(Node)),
|
||||||
|
@ -124,10 +122,10 @@ get_node(NodeId) ->
|
||||||
{error, ?ERR_ITEM_NOT_FOUND}
|
{error, ?ERR_ITEM_NOT_FOUND}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_nodes(Host, _From) ->
|
|
||||||
get_nodes(Host).
|
|
||||||
%% @spec (Host) -> [pubsubNode()] | {error, Reason}
|
%% @spec (Host) -> [pubsubNode()] | {error, Reason}
|
||||||
%% Host = mod_pubsub:host() | mod_pubsub:jid()
|
%% Host = mod_pubsub:host() | mod_pubsub:jid()
|
||||||
|
get_nodes(Host, _From) ->
|
||||||
|
get_nodes(Host).
|
||||||
get_nodes(Host) ->
|
get_nodes(Host) ->
|
||||||
H = ?PUBSUB:escape(Host),
|
H = ?PUBSUB:escape(Host),
|
||||||
case catch ejabberd_odbc:sql_query_t(
|
case catch ejabberd_odbc:sql_query_t(
|
||||||
|
@ -162,7 +160,7 @@ get_parentnodes(_Host, _Node, _From) ->
|
||||||
get_parentnodes_tree(Host, Node, From) ->
|
get_parentnodes_tree(Host, Node, From) ->
|
||||||
case get_node(Host, Node, From) of
|
case get_node(Host, Node, From) of
|
||||||
N when is_record(N, pubsub_node) -> [{0, [N]}];
|
N when is_record(N, pubsub_node) -> [{0, [N]}];
|
||||||
Error -> Error
|
_Error -> []
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_subnodes(Host, Node, _From) ->
|
get_subnodes(Host, Node, _From) ->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
--- mod_pubsub.erl 2009-08-25 18:29:16.000000000 +0200
|
--- mod_pubsub.erl 2009-08-27 23:21:24.000000000 +0200
|
||||||
+++ mod_pubsub_odbc.erl 2009-08-27 10:51:06.000000000 +0200
|
+++ mod_pubsub_odbc.erl 2009-08-27 23:36:47.000000000 +0200
|
||||||
@@ -45,7 +45,7 @@
|
@@ -45,7 +45,7 @@
|
||||||
%%% TODO
|
%%% TODO
|
||||||
%%% plugin: generate Reply (do not use broadcast atom anymore)
|
%%% plugin: generate Reply (do not use broadcast atom anymore)
|
||||||
|
@ -377,7 +377,7 @@
|
||||||
sync_dirty) of
|
sync_dirty) of
|
||||||
{result, Res} -> Res;
|
{result, Res} -> Res;
|
||||||
Err -> Err
|
Err -> Err
|
||||||
@@ -1435,7 +1267,7 @@
|
@@ -1431,7 +1263,7 @@
|
||||||
|
|
||||||
%%% authorization handling
|
%%% authorization handling
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@
|
||||||
Lang = "en", %% TODO fix
|
Lang = "en", %% TODO fix
|
||||||
Stanza = {xmlelement, "message",
|
Stanza = {xmlelement, "message",
|
||||||
[],
|
[],
|
||||||
@@ -1464,7 +1296,7 @@
|
@@ -1460,7 +1292,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}
|
||||||
|
@ -395,7 +395,7 @@
|
||||||
|
|
||||||
find_authorization_response(Packet) ->
|
find_authorization_response(Packet) ->
|
||||||
{xmlelement, _Name, _Attrs, Els} = Packet,
|
{xmlelement, _Name, _Attrs, Els} = Packet,
|
||||||
@@ -1531,8 +1363,8 @@
|
@@ -1527,8 +1359,8 @@
|
||||||
"true" -> true;
|
"true" -> true;
|
||||||
_ -> false
|
_ -> false
|
||||||
end,
|
end,
|
||||||
|
@ -406,7 +406,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 ->
|
||||||
@@ -1718,7 +1550,7 @@
|
@@ -1714,7 +1546,7 @@
|
||||||
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||||
[{xmlelement, "create", nodeAttr(Node),
|
[{xmlelement, "create", nodeAttr(Node),
|
||||||
[]}]}],
|
[]}]}],
|
||||||
|
@ -415,7 +415,29 @@
|
||||||
{result, {Result, broadcast}} ->
|
{result, {Result, broadcast}} ->
|
||||||
%%Lang = "en", %% TODO: fix
|
%%Lang = "en", %% TODO: fix
|
||||||
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
|
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
|
||||||
@@ -1830,7 +1662,7 @@
|
@@ -1758,13 +1590,10 @@
|
||||||
|
{error, ?ERR_NOT_ALLOWED};
|
||||||
|
delete_node(Host, Node, Owner) ->
|
||||||
|
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||||
|
- SubsByDepth = get_collection_subscriptions(Host, Node),
|
||||||
|
case node_call(Type, get_affiliation, [NodeId, Owner]) of
|
||||||
|
{result, owner} ->
|
||||||
|
- SubsByDepth = case tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]) of
|
||||||
|
- {result, T} -> [{Depth, [{N, get_node_subs(N)} || N <- Nodes]} || {Depth, Nodes} <- T];
|
||||||
|
- _ -> []
|
||||||
|
- end,
|
||||||
|
+ ParentTree = tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]),
|
||||||
|
+ SubsByDepth = [{Depth, [{N, get_node_subs(N)} || N <- Nodes]} || {Depth, Nodes} <- ParentTree],
|
||||||
|
Removed = tree_call(Host, delete_node, [Host, Node]),
|
||||||
|
case node_call(Type, delete_node, [Removed]) of
|
||||||
|
{result, Res} -> {result, {SubsByDepth, Res}};
|
||||||
|
@@ -1825,12 +1654,12 @@
|
||||||
|
%%<li>The node does not exist.</li>
|
||||||
|
%%</ul>
|
||||||
|
subscribe_node(Host, Node, From, JID, Configuration) ->
|
||||||
|
- {result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration),
|
||||||
|
+ {result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration),
|
||||||
|
Subscriber = case jlib:string_to_jid(JID) of
|
||||||
error -> {"", "", ""};
|
error -> {"", "", ""};
|
||||||
J -> jlib:jid_tolower(J)
|
J -> jlib:jid_tolower(J)
|
||||||
end,
|
end,
|
||||||
|
@ -424,7 +446,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),
|
||||||
@@ -1849,9 +1681,13 @@
|
@@ -1849,9 +1678,13 @@
|
||||||
{"", "", ""} ->
|
{"", "", ""} ->
|
||||||
{false, false};
|
{false, false};
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -441,7 +463,7 @@
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
if
|
if
|
||||||
@@ -2174,7 +2010,7 @@
|
@@ -2174,7 +2007,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.
|
||||||
|
@ -450,7 +472,7 @@
|
||||||
MaxItems =
|
MaxItems =
|
||||||
if
|
if
|
||||||
SMaxItems == "" -> ?MAXITEMS;
|
SMaxItems == "" -> ?MAXITEMS;
|
||||||
@@ -2213,11 +2049,11 @@
|
@@ -2213,11 +2046,11 @@
|
||||||
node_call(Type, get_items,
|
node_call(Type, get_items,
|
||||||
[NodeId, From,
|
[NodeId, From,
|
||||||
AccessModel, PresenceSubscription, RosterGroup,
|
AccessModel, PresenceSubscription, RosterGroup,
|
||||||
|
@ -464,7 +486,7 @@
|
||||||
SendItems = case ItemIDs of
|
SendItems = case ItemIDs of
|
||||||
[] ->
|
[] ->
|
||||||
Items;
|
Items;
|
||||||
@@ -2230,7 +2066,8 @@
|
@@ -2230,7 +2063,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),
|
||||||
|
@ -474,7 +496,7 @@
|
||||||
Error ->
|
Error ->
|
||||||
Error
|
Error
|
||||||
end
|
end
|
||||||
@@ -2262,15 +2099,22 @@
|
@@ -2262,15 +2096,22 @@
|
||||||
%% @doc <p>Resend the items of a node to the user.</p>
|
%% @doc <p>Resend the items of a node to the user.</p>
|
||||||
%% @todo use cache-last-item feature
|
%% @todo use cache-last-item feature
|
||||||
send_items(Host, Node, NodeId, Type, LJID, last) ->
|
send_items(Host, Node, NodeId, Type, LJID, last) ->
|
||||||
|
@ -503,7 +525,7 @@
|
||||||
send_items(Host, Node, NodeId, Type, LJID, Number) ->
|
send_items(Host, Node, NodeId, Type, LJID, Number) ->
|
||||||
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
||||||
{result, []} ->
|
{result, []} ->
|
||||||
@@ -2388,29 +2232,12 @@
|
@@ -2388,29 +2229,12 @@
|
||||||
error ->
|
error ->
|
||||||
{error, ?ERR_BAD_REQUEST};
|
{error, ?ERR_BAD_REQUEST};
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -536,7 +558,39 @@
|
||||||
end, Entities),
|
end, Entities),
|
||||||
{result, []};
|
{result, []};
|
||||||
_ ->
|
_ ->
|
||||||
@@ -2681,8 +2508,8 @@
|
@@ -2463,11 +2287,11 @@
|
||||||
|
end.
|
||||||
|
|
||||||
|
read_sub(Subscriber, NodeID, SubID, Lang) ->
|
||||||
|
- case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of
|
||||||
|
+ case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of
|
||||||
|
{error, notfound} ->
|
||||||
|
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
|
{result, #pubsub_subscription{options = Options}} ->
|
||||||
|
- pubsub_subscription:get_options_xform(Lang, Options)
|
||||||
|
+ pubsub_subscription_odbc:get_options_xform(Lang, Options)
|
||||||
|
end.
|
||||||
|
|
||||||
|
set_options(Host, Node, JID, SubID, Configuration) ->
|
||||||
|
@@ -2492,7 +2316,7 @@
|
||||||
|
error -> {"", "", ""};
|
||||||
|
J -> jlib:jid_tolower(J)
|
||||||
|
end,
|
||||||
|
- {result, SubOpts} = pubsub_subscription:parse_options_xform(Configuration),
|
||||||
|
+ {result, SubOpts} = pubsub_subscription_odbc:parse_options_xform(Configuration),
|
||||||
|
{result, Subs} = node_call(Type, get_subscriptions,
|
||||||
|
[NodeID, Subscriber]),
|
||||||
|
SubIDs = lists:foldl(fun({subscribed, SID}, Acc) ->
|
||||||
|
@@ -2512,7 +2336,7 @@
|
||||||
|
end.
|
||||||
|
|
||||||
|
write_sub(Subscriber, NodeID, SubID, Options) ->
|
||||||
|
- case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID,
|
||||||
|
+ case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID,
|
||||||
|
Options) of
|
||||||
|
{error, notfound} ->
|
||||||
|
{error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
|
||||||
|
@@ -2681,8 +2505,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,
|
||||||
|
@ -547,7 +601,28 @@
|
||||||
true ->
|
true ->
|
||||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||||
|
|
||||||
@@ -3179,6 +3006,30 @@
|
@@ -2964,7 +2788,7 @@
|
||||||
|
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
|
||||||
|
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
|
||||||
|
end,
|
||||||
|
- case transaction(Action, sync_dirty) of
|
||||||
|
+ case transaction(Host, Action, sync_dirty) of
|
||||||
|
{result, CollSubs} -> CollSubs;
|
||||||
|
_ -> []
|
||||||
|
end.
|
||||||
|
@@ -2978,9 +2802,9 @@
|
||||||
|
|
||||||
|
get_options_for_subs(NodeID, Subs) ->
|
||||||
|
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
|
||||||
|
- case pubsub_subscription:read_subscription(JID, NodeID, SubID) of
|
||||||
|
+ case pubsub_subscription_odbc:get_subscription(JID, NodeID, SubID) of
|
||||||
|
{error, notfound} -> [{JID, SubID, []} | Acc];
|
||||||
|
- #pubsub_subscription{options = Options} -> [{JID, SubID, Options} | Acc];
|
||||||
|
+ {result, #pubsub_subscription{options = Options}} -> [{JID, SubID, Options} | Acc];
|
||||||
|
_ -> Acc
|
||||||
|
end;
|
||||||
|
(_, Acc) ->
|
||||||
|
@@ -3174,6 +2998,30 @@
|
||||||
Result
|
Result
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -578,7 +653,7 @@
|
||||||
%% @spec (Host, Options) -> MaxItems
|
%% @spec (Host, Options) -> MaxItems
|
||||||
%% Host = host()
|
%% Host = host()
|
||||||
%% Options = [Option]
|
%% Options = [Option]
|
||||||
@@ -3552,7 +3403,13 @@
|
@@ -3547,7 +3395,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,
|
||||||
|
@ -593,7 +668,7 @@
|
||||||
|
|
||||||
%% @doc <p>node plugin call.</p>
|
%% @doc <p>node plugin call.</p>
|
||||||
node_call(Type, Function, Args) ->
|
node_call(Type, Function, Args) ->
|
||||||
@@ -3572,13 +3429,13 @@
|
@@ -3567,13 +3421,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]),
|
||||||
|
@ -609,7 +684,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
|
||||||
@@ -3591,8 +3448,14 @@
|
@@ -3586,8 +3440,14 @@
|
||||||
end
|
end
|
||||||
end, Trans).
|
end, Trans).
|
||||||
|
|
||||||
|
@ -626,7 +701,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};
|
||||||
@@ -3600,6 +3463,15 @@
|
@@ -3595,6 +3455,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};
|
||||||
|
@ -642,7 +717,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};
|
||||||
@@ -3608,6 +3480,17 @@
|
@@ -3603,6 +3472,17 @@
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
|
@ -88,14 +88,18 @@ init() ->
|
||||||
|
|
||||||
subscribe_node(_JID, _NodeID, Options) ->
|
subscribe_node(_JID, _NodeID, Options) ->
|
||||||
SubId = make_subid(),
|
SubId = make_subid(),
|
||||||
ok = ?DB_MOD:add_subscription(#pubsub_subscription{subid = SubId, options = Options}),
|
?DB_MOD:add_subscription(#pubsub_subscription{subid = SubId, options = Options}),
|
||||||
{result, SubId}.
|
{result, SubId}.
|
||||||
|
|
||||||
|
|
||||||
unsubscribe_node(_JID, _NodeID, SubID) ->
|
unsubscribe_node(_JID, _NodeID, SubID) ->
|
||||||
{ok, Sub} = ?DB_MOD:read_subscription(SubID),
|
case ?DB_MOD:read_subscription(SubID) of
|
||||||
ok = ?DB_MOD:delete_subscription(SubID),
|
{ok, Sub} ->
|
||||||
{result, Sub}.
|
?DB_MOD:delete_subscription(SubID),
|
||||||
|
{result, Sub};
|
||||||
|
notfound ->
|
||||||
|
{error, notfound}
|
||||||
|
end.
|
||||||
|
|
||||||
get_subscription(_JID, _NodeID, SubID) ->
|
get_subscription(_JID, _NodeID, SubID) ->
|
||||||
case ?DB_MOD:read_subscription(SubID) of
|
case ?DB_MOD:read_subscription(SubID) of
|
||||||
|
@ -107,7 +111,7 @@ get_subscription(_JID, _NodeID, SubID) ->
|
||||||
set_subscription(_JID, _NodeID, SubID, Options) ->
|
set_subscription(_JID, _NodeID, SubID, Options) ->
|
||||||
case ?DB_MOD:read_subscription(SubID) of
|
case ?DB_MOD:read_subscription(SubID) of
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
ok = ?DB_MOD:update_subscription(#pubsub_subscription{subid = SubID, options = Options}),
|
?DB_MOD:update_subscription(#pubsub_subscription{subid = SubID, options = Options}),
|
||||||
{result, ok};
|
{result, ok};
|
||||||
notfound ->
|
notfound ->
|
||||||
{error, notfound}
|
{error, notfound}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user