25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

port all recent fixes from trunk related to odbc subscriptions

SVN Revision: 2559
This commit is contained in:
Christophe Romain 2009-08-27 23:09:20 +00:00
parent adfca08e43
commit fab29f4cf0
8 changed files with 285 additions and 204 deletions

View File

@ -1434,12 +1434,21 @@ send_pending_auth_events(Host, Node, Owner) ->
?DEBUG("Sending pending auth events for ~s on ~s:~s",
[exmpp_jid:jid_to_string(Owner), Host, node_to_string(Node)]),
Action =
fun (#pubsub_node{id = NodeID, type = Type} = N) ->
fun(#pubsub_node{id = NodeID, type = Type}) ->
case lists:member("get-pending", features(Type)) of
true ->
case node_call(Type, get_affiliation, [NodeID, Owner]) of
{result, owner} ->
broadcast_pending_auth_events(N),
{result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
lists:foreach(fun({J, pending, _SubID}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R));
({J, pending}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R));
(_) ->
ok
end, Subscriptions),
{result, ok};
_ ->
{error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'forbidden')}
@ -1455,16 +1464,6 @@ send_pending_auth_events(Host, Node, Owner) ->
Err
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}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R));
({J, pending}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R))
end, Subscriptions).
%%% authorization handling
send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}}, Subscriber) ->
@ -1795,18 +1794,19 @@ delete_node(_Host, [], _Owner) ->
{error, '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} ->
Removed = tree_call(Host, delete_node, [Host, Node]),
case node_call(Type, delete_node, [Removed]) of
case node_call(Type, get_affiliation, [NodeId, Owner]) of
{result, owner} ->
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}};
Error -> Error
end;
_ ->
%% Entity is not an owner
{error, 'forbidden'}
end
Error -> Error
end;
_ ->
%% Entity is not an owner
{error, 'forbidden'}
end
end,
Reply = [],
case transaction(Host, Node, Action, transaction) of
@ -2559,8 +2559,7 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
end.
write_sub(Subscriber, NodeID, SubID, Options) ->
case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID,
Options) of
case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID, Options) of
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@ -3016,24 +3015,28 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
end.
get_collection_subscriptions(Host, Node) ->
lists:map(fun ({Depth, Nodes}) ->
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_action(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)])).
get_node_subs(#pubsub_node{type = Type,
nodeid = {Host, Node},
id = NodeID}) ->
case node_action(Host, Type, get_node_subscriptions, [NodeID]) of
{result, Subs} ->
get_options_for_subs(Host, Node, NodeID, Subs);
Other ->
Other
Action = fun() ->
{result, lists:map(fun({Depth, Nodes}) ->
{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
{result, CollSubs} -> CollSubs;
_ -> []
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) ->
case pubsub_subscription:get_subscription(JID, NodeID, SubID) of
{result, #pubsub_subscription{options = Options}} -> [{JID, Node, Options} | Acc];
case pubsub_subscription:read_subscription(JID, NodeID, SubID) of
{error, notfound} -> [{JID, SubID, []} | Acc];
#pubsub_subscription{options = Options} -> [{JID, SubID, Options} | Acc];
_ -> Acc
end;
(_, Acc) ->
@ -3063,8 +3066,7 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
From = service_jid(Host),
%% Handles explicit subscriptions
FilteredSubsByDepth = depths_to_deliver(NotifyType, SubsByDepth),
NodesByJID = collate_subs_by_jid(FilteredSubsByDepth),
NodesByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
lists:foreach(fun ({LJID, Nodes}) ->
LJIDs = case BroadcastAll of
true ->
@ -3125,36 +3127,28 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
ok
end.
depths_to_deliver(NotifyType, SubsByDepth) ->
NodesToDeliver =
fun (Depth, Node, Subs, Acc) ->
lists:foldl(fun ({LJID, _Node, SubOptions} = S, Acc2) ->
subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
NodesToDeliver = fun(Depth, Node, Subs, Acc) ->
NodeId = case Node#pubsub_node.nodeid of
{_, N} -> N;
Other -> Other
end,
NodeOptions = Node#pubsub_node.options,
lists:foldl(fun({LJID, _SubID, SubOptions}, Acc2) ->
case is_to_deliver(LJID, NotifyType, Depth,
Node#pubsub_node.options,
SubOptions) of
true -> [S | Acc2];
NodeOptions, SubOptions) of
true -> [{LJID, NodeId}|Acc2];
false -> Acc2
end
end, Acc, Subs)
end,
DepthsToDeliver =
fun ({Depth, SubsByNode}, Acc) ->
lists:foldl(fun ({Node, Subs}, Acc2) ->
DepthsToDeliver = fun({Depth, SubsByNode}, Acc) ->
lists:foldl(fun({Node, Subs}, Acc2) ->
NodesToDeliver(Depth, Node, Subs, Acc2)
end, Acc, SubsByNode)
end,
lists:foldl(DepthsToDeliver, [], SubsByDepth).
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).
JIDSubs = lists:foldl(DepthsToDeliver, [], SubsByDepth),
[{LJID, proplists:append_values(LJID, JIDSubs)} || LJID <- proplists:get_keys(JIDSubs)].
%% If we don't know the resource, just pick first if any
%% If no resource available, check if caps anyway (remote online)

View File

@ -1120,11 +1120,9 @@ iq_pubsub(Host, ServerHost, From, IQType, SubEl, Lang, Access, Plugins) ->
end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
SubEls = exmpp_xml:get_child_elements(SubEl),
NoRSM = lists:filter(fun(#xmlel{name = Name}) ->
Name == 'set'
end, SubEls),
Action = SubEls -- NoRSM, %%pablo why not doing it once on lists:filter?
Action = lists:filter(fun(#xmlel{name = 'set'}) -> false;
(_) -> true
end, exmpp_xml:get_child_elements(SubEl)),
case Action of
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
Node = case Host of
@ -1268,12 +1266,21 @@ send_pending_auth_events(Host, Node, Owner) ->
?DEBUG("Sending pending auth events for ~s on ~s:~s",
[exmpp_jid:jid_to_string(Owner), Host, node_to_string(Node)]),
Action =
fun (#pubsub_node{id = NodeID, type = Type} = N) ->
fun(#pubsub_node{id = NodeID, type = Type}) ->
case lists:member("get-pending", features(Type)) of
true ->
case node_call(Type, get_affiliation, [NodeID, Owner]) of
{result, owner} ->
broadcast_pending_auth_events(N),
{result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
lists:foreach(fun({J, pending, _SubID}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R));
({J, pending}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R));
(_) ->
ok
end, Subscriptions),
{result, ok};
_ ->
{error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'forbidden')}
@ -1289,16 +1296,6 @@ send_pending_auth_events(Host, Node, Owner) ->
Err
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}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R));
({J, pending}) ->
{U, S, R} = J,
send_authorization_request(Node, exmpp_jid:make(U,S,R))
end, Subscriptions).
%%% authorization handling
send_authorization_request(#pubsub_node{nodeid = {Host, Node}, type = Type, id = NodeId}, Subscriber) ->
@ -1629,18 +1626,19 @@ delete_node(_Host, [], _Owner) ->
{error, '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} ->
Removed = tree_call(Host, delete_node, [Host, Node]),
case node_call(Type, delete_node, [Removed]) of
case node_call(Type, get_affiliation, [NodeId, Owner]) of
{result, owner} ->
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}};
Error -> Error
end;
_ ->
%% Entity is not an owner
{error, 'forbidden'}
end
Error -> Error
end;
_ ->
%% Entity is not an owner
{error, 'forbidden'}
end
end,
Reply = [],
case transaction(Host, Node, Action, transaction) of
@ -1693,7 +1691,7 @@ delete_node(Host, Node, Owner) ->
%%<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 = try
jlib:short_prepd_jid(exmpp_jid:parse(JID))
catch
@ -2338,11 +2336,11 @@ get_options_helper(JID, Lang, NodeID, SubID, Type) ->
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, extended_error('not-acceptable', "invalid-subid")};
pubsub_subscription_odbc:get_options_xform(Lang, []);
{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) ->
@ -2369,7 +2367,7 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
_ ->
{"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries
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) ->
@ -2389,8 +2387,7 @@ set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
end.
write_sub(Subscriber, NodeID, SubID, Options) ->
case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID,
Options) of
case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID, Options) of
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@ -2846,24 +2843,28 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
end.
get_collection_subscriptions(Host, Node) ->
lists:map(fun ({Depth, Nodes}) ->
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_action(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)])).
get_node_subs(#pubsub_node{type = Type,
nodeid = {Host, Node},
id = NodeID}) ->
case node_action(Host, Type, get_node_subscriptions, [NodeID]) of
{result, Subs} ->
get_options_for_subs(Host, Node, NodeID, Subs);
Other ->
Other
Action = fun() ->
{result, lists:map(fun({Depth, Nodes}) ->
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
case transaction(Host, Action, sync_dirty) of
{result, CollSubs} -> CollSubs;
_ -> []
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) ->
case pubsub_subscription:get_subscription(JID, NodeID, SubID) of
{result, #pubsub_subscription{options = Options}} -> [{JID, Node, Options} | Acc];
case pubsub_subscription_odbc:get_subscription(JID, NodeID, SubID) of
{error, notfound} -> [{JID, SubID, []} | Acc];
{result, #pubsub_subscription{options = Options}} -> [{JID, SubID, Options} | Acc];
_ -> Acc
end;
(_, Acc) ->
@ -2893,8 +2894,7 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
BroadcastAll = get_option(NodeOptions, broadcast_all_resources), %% XXX this is not standard, but usefull
From = service_jid(Host),
%% Handles explicit subscriptions
FilteredSubsByDepth = depths_to_deliver(NotifyType, SubsByDepth),
NodesByJID = collate_subs_by_jid(FilteredSubsByDepth),
NodesByJID = subscribed_nodes_by_jid(NotifyType, SubsByDepth),
lists:foreach(fun ({LJID, Nodes}) ->
LJIDs = case BroadcastAll of
true ->
@ -2955,36 +2955,28 @@ broadcast_stanza(Host, Node, _NodeId, _Type, NodeOptions, SubsByDepth, NotifyTyp
ok
end.
depths_to_deliver(NotifyType, SubsByDepth) ->
NodesToDeliver =
fun (Depth, Node, Subs, Acc) ->
lists:foldl(fun ({LJID, _Node, SubOptions} = S, Acc2) ->
subscribed_nodes_by_jid(NotifyType, SubsByDepth) ->
NodesToDeliver = fun(Depth, Node, Subs, Acc) ->
NodeId = case Node#pubsub_node.nodeid of
{_, N} -> N;
Other -> Other
end,
NodeOptions = Node#pubsub_node.options,
lists:foldl(fun({LJID, _SubID, SubOptions}, Acc2) ->
case is_to_deliver(LJID, NotifyType, Depth,
Node#pubsub_node.options,
SubOptions) of
true -> [S | Acc2];
NodeOptions, SubOptions) of
true -> [{LJID, NodeId}|Acc2];
false -> Acc2
end
end, Acc, Subs)
end,
DepthsToDeliver =
fun ({Depth, SubsByNode}, Acc) ->
lists:foldl(fun ({Node, Subs}, Acc2) ->
DepthsToDeliver = fun({Depth, SubsByNode}, Acc) ->
lists:foldl(fun({Node, Subs}, Acc2) ->
NodesToDeliver(Depth, Node, Subs, Acc2)
end, Acc, SubsByNode)
end,
lists:foldl(DepthsToDeliver, [], SubsByDepth).
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).
JIDSubs = lists:foldl(DepthsToDeliver, [], SubsByDepth),
[{LJID, proplists:append_values(LJID, JIDSubs)} || LJID <- proplists:get_keys(JIDSubs)].
%% If we don't know the resource, just pick first if any
%% If no resource available, check if caps anyway (remote online)
@ -3067,7 +3059,7 @@ node_options(Type) ->
Result
end.
%% @spec (NodeId) -> [ljid()]
%% @spec (Host, Type, NodeId) -> [ljid()]
%% NodeId = pubsubNodeId()
%% @doc <p>Return list of node owners.</p>
node_owners(Host, Type, NodeId) ->

View File

@ -59,7 +59,8 @@
get_item/7,
get_item/2,
set_item/1,
get_item_name/3
get_item_name/3,
get_last_items/3
]).
@ -181,3 +182,6 @@ set_item(Item) ->
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).

View File

@ -398,8 +398,7 @@ unsubscribe_node(NodeId, Sender, Subscriber, SubId) ->
delete_subscription(SubKey, NodeId, S, Affiliation, Subscriptions),
{result, default};
false ->
{error, ?ERR_EXTENDED('unexpected-request',
"not-subscribed")}
{error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")}
end;
%% No subid supplied, but there's only one matching
%% subscription, so use that.
@ -652,25 +651,33 @@ get_entity_subscriptions(Host, Owner) ->
SJ = encode_jid(SubKey),
GJ = encode_jid(GenKey),
Query = case SubKey of
GenKey ->
["select node, type, i.nodeid, jid, subscriptions "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid "
"and jid like '", GJ, "%' "
"and host='", H, "';"];
_ ->
["select node, type, i.nodeid, jid, subscriptions "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid "
"and jid in ('", SJ, "', '", GJ, "') "
"and host='", H, "';"]
GenKey ->
["select node, type, i.nodeid, jid, subscriptions "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid "
"and jid like '", GJ, "%' "
"and host='", H, "';"];
_ ->
["select node, type, i.nodeid, jid, subscriptions "
"from pubsub_state i, pubsub_node n "
"where i.nodeid = n.nodeid "
"and jid in ('", SJ, "', '", GJ, "') "
"and host='", H, "';"]
end,
Reply = case catch ejabberd_odbc:sql_query_t(Query) of
{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, decode_subscriptions(S), decode_jid(J)}
end, RItems);
Jid = decode_jid(J),
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,
@ -702,10 +709,18 @@ get_entity_subscriptions_for_send_last(Host, Owner) ->
end,
Reply = case catch ejabberd_odbc:sql_query_t(Query) of
{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, decode_subscriptions(S), decode_jid(J)}
end, RItems);
Jid = decode_jid(J),
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,
@ -717,8 +732,17 @@ get_node_subscriptions(NodeId) ->
"from pubsub_state "
"where nodeid='", NodeId, "';"]) of
{selected, ["jid", "subscriptions"], RItems} ->
lists:map(fun({J, S}) -> {decode_jid(J), decode_subscriptions(S)} end, RItems);
% TODO {J, S, SubId}
lists:foldl(fun({J, S}, Acc) ->
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,
@ -732,7 +756,7 @@ get_subscriptions(NodeId, Owner) ->
["select subscriptions from pubsub_state "
"where nodeid='", NodeId, "' and jid='", J, "';"]) of
{selected, ["subscriptions"], [{S}]} -> decode_subscriptions(S);
_ -> none
_ -> []
end,
{result, Reply}.
@ -1224,7 +1248,7 @@ select_affiliation_subscriptions(NodeId, JID) ->
{selected, ["affiliation", "subscriptions"], [{A, S}]} ->
{decode_affiliation(A), decode_subscriptions(S)};
_ ->
{none, none}
{none, []}
end.
select_affiliation_subscriptions(NodeId, JID, JID) ->
select_affiliation_subscriptions(NodeId, JID);

View File

@ -149,8 +149,9 @@ get_parentnodes(_Host, _Node, _From) ->
get_parentnodes_tree(Host, Node, From) ->
case get_node(Host, Node, From) of
N when is_record(N, pubsub_node) -> [{0, [N]}];
Error -> Error
_Error -> []
end.
%% @spec (Host, Node, From) -> [pubsubNode()] | {error, Reason}
%% Host = mod_pubsub:host()
%% Node = mod_pubsub:pubsubNode()

View File

@ -163,7 +163,7 @@ get_parentnodes(_Host, _Node, _From) ->
get_parentnodes_tree(Host, Node, From) ->
case get_node(Host, Node, From) of
N when is_record(N, pubsub_node) -> [{0, [N]}];
Error -> Error
_Error -> []
end.
get_subnodes(Host, Node, _From) ->

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2009-08-27 10:43:45.000000000 +0200
+++ mod_pubsub_odbc.erl 2009-08-27 10:47:31.000000000 +0200
--- mod_pubsub.erl 2009-08-28 01:07:30.000000000 +0200
+++ mod_pubsub_odbc.erl 2009-08-28 01:08:15.000000000 +0200
@@ -45,7 +45,7 @@
%%% TODO
%%% plugin: generate Reply (do not use broadcast atom anymore)
@ -359,21 +359,19 @@
{get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} ->
@@ -1290,8 +1120,11 @@
@@ -1290,8 +1120,9 @@
end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
- SubEls = SubEl#xmlel.children,
- Action = exmpp_xml:remove_cdata_from_list(SubEls),
+ SubEls = exmpp_xml:get_child_elements(SubEl),
+ NoRSM = lists:filter(fun(#xmlel{name = Name}) ->
+ Name == 'set'
+ end, SubEls),
+ Action = SubEls -- NoRSM, %%pablo why not doing it once on lists:filter?
+ Action = lists:filter(fun(#xmlel{name = 'set'}) -> false;
+ (_) -> true
+ end, exmpp_xml:get_child_elements(SubEl)),
case Action of
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
Node = case Host of
@@ -1421,7 +1254,8 @@
@@ -1421,7 +1252,8 @@
_ -> []
end
end,
@ -383,7 +381,7 @@
sync_dirty) of
{result, Res} -> Res;
Err -> Err
@@ -1467,7 +1301,7 @@
@@ -1466,7 +1298,7 @@
%%% authorization handling
@ -392,7 +390,7 @@
Lang = "en", %% TODO fix
{U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
@@ -1497,7 +1331,7 @@
@@ -1496,7 +1328,7 @@
lists:foreach(fun(Owner) ->
{U, S, R} = Owner,
ejabberd_router ! {route, service_jid(Host), exmpp_jid:make(U, S, R), Stanza}
@ -401,7 +399,7 @@
find_authorization_response(Packet) ->
Els = Packet#xmlel.children,
@@ -1560,8 +1394,8 @@
@@ -1559,8 +1391,8 @@
"true" -> true;
_ -> false
end,
@ -412,7 +410,7 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if
not IsApprover ->
@@ -1751,7 +1585,7 @@
@@ -1750,7 +1582,7 @@
end,
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
@ -421,7 +419,16 @@
{result, {Result, broadcast}} ->
%%Lang = "en", %% TODO: fix
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
@@ -1867,7 +1701,7 @@
@@ -1859,7 +1691,7 @@
%%<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 = try
jlib:short_prepd_jid(exmpp_jid:parse(JID))
catch
@@ -1867,7 +1699,7 @@
{undefined, undefined, undefined}
end,
SubId = uniqid(),
@ -430,7 +437,7 @@
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
@@ -1886,9 +1720,13 @@
@@ -1886,9 +1718,13 @@
{"", "", ""} ->
{false, false};
_ ->
@ -447,7 +454,7 @@
end
end,
if
@@ -2213,7 +2051,7 @@
@@ -2213,7 +2049,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.
@ -456,7 +463,7 @@
MaxItems =
if
SMaxItems == "" -> ?MAXITEMS;
@@ -2252,11 +2090,11 @@
@@ -2252,11 +2088,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
@ -470,7 +477,7 @@
SendItems = case ItemIDs of
[] ->
Items;
@@ -2269,7 +2107,7 @@
@@ -2269,7 +2105,7 @@
%% number of items sent to MaxItems:
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
@ -479,7 +486,7 @@
Error ->
Error
end
@@ -2301,16 +2139,25 @@
@@ -2301,16 +2137,25 @@
%% @doc <p>Resend the items of a node to the user.</p>
%% @todo use cache-last-item feature
send_items(Host, Node, NodeId, Type, LJID, last) ->
@ -512,7 +519,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
@@ -2431,29 +2278,12 @@
@@ -2431,29 +2276,12 @@
error ->
{error, 'bad-request'};
_ ->
@ -545,7 +552,40 @@
end, Entities),
{result, []};
_ ->
@@ -2733,8 +2563,8 @@
@@ -2508,11 +2336,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, extended_error('not-acceptable', "invalid-subid")};
+ pubsub_subscription_odbc:get_options_xform(Lang, []);
{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) ->
@@ -2539,7 +2367,7 @@
_ ->
{"", "", ""} %%pablo TODO: "" or <<>> ?. short_jid uses exmpp_jid:node/1, etc. that returns binaries
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) ->
@@ -2559,7 +2387,7 @@
end.
write_sub(Subscriber, NodeID, SubID, Options) ->
- case pubsub_subscription:set_subscription(Subscriber, NodeID, SubID, Options) of
+ case pubsub_subscription_odbc:set_subscription(Subscriber, NodeID, SubID, Options) of
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@@ -2732,8 +2560,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router ! {route, service_jid(Host), JID, Stanza}
end,
@ -556,11 +596,32 @@
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3237,6 +3067,30 @@
@@ -3020,7 +2848,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.
@@ -3034,9 +2862,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) ->
@@ -3231,6 +3059,30 @@
Result
end.
+%% @spec (NodeId) -> [ljid()]
+%% @spec (Host, Type, NodeId) -> [ljid()]
+%% NodeId = pubsubNodeId()
+%% @doc <p>Return list of node owners.</p>
+node_owners(Host, Type, NodeId) ->
@ -587,7 +648,7 @@
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
@@ -3613,7 +3467,13 @@
@@ -3607,7 +3459,13 @@
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
@ -602,7 +663,7 @@
%% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) ->
@@ -3633,13 +3493,13 @@
@@ -3627,13 +3485,13 @@
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -618,7 +679,7 @@
case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) ->
case Action(N) of
@@ -3652,8 +3512,15 @@
@@ -3646,8 +3504,15 @@
end
end, Trans).
@ -636,7 +697,7 @@
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
@@ -3661,6 +3528,15 @@
@@ -3655,6 +3520,15 @@
{aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'};
@ -652,7 +713,7 @@
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'};
@@ -3669,6 +3545,16 @@
@@ -3663,6 +3537,16 @@
{error, 'internal-server-error'}
end.

View File

@ -90,14 +90,18 @@ init() ->
ok = create_table().
subscribe_node(_JID, _NodeID, Options) ->
SubId = make_subid(),
ok = ?DB_MOD:add_subscription(#pubsub_subscription{subid = SubId, options = Options}),
{result, SubId}.
SubID = make_subid(),
?DB_MOD:add_subscription(#pubsub_subscription{subid = SubID, options = Options}),
{result, SubID}.
unsubscribe_node(_JID, _NodeID, SubID) ->
{ok, Sub} = ?DB_MOD:read_subscription(SubID),
ok = ?DB_MOD:delete_subscription(SubID),
{result, Sub}.
case ?DB_MOD:read_subscription(SubID) of
{ok, Sub} ->
?DB_MOD:delete_subscription(SubID),
{result, Sub};
notfound ->
{error, notfound}
end.
get_subscription(_JID, _NodeID, SubID) ->
case ?DB_MOD:read_subscription(SubID) of
@ -108,10 +112,11 @@ get_subscription(_JID, _NodeID, SubID) ->
set_subscription(_JID, _NodeID, SubID, Options) ->
case ?DB_MOD:read_subscription(SubID) of
{ok, _} ->
ok = ?DB_MOD:update_subscription(#pubsub_subscription{subid = SubID, options = Options}),
{result, ok};
?DB_MOD:update_subscription(#pubsub_subscription{subid = SubID, options = Options}),
{result, ok};
notfound ->
{error, notfound}
?DB_MOD:add_subscription(#pubsub_subscription{subid = SubID, options = Options}),
{result, ok}
end.
get_options_xform(Lang, Options) ->