2010-01-12 16:14:57 +01:00
|
|
|
--- mod_pubsub.erl 2010-01-12 16:08:14.000000000 +0100
|
|
|
|
+++ mod_pubsub_odbc.erl 2010-01-12 16:10:52.000000000 +0100
|
2009-10-13 18:42:13 +02:00
|
|
|
@@ -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.
|
2009-08-26 22:27:57 +02:00
|
|
|
|
|
|
|
--module(mod_pubsub).
|
|
|
|
+-module(mod_pubsub_odbc).
|
|
|
|
-author('christophe.romain@process-one.net').
|
2009-09-24 21:47:01 +02:00
|
|
|
-version('1.13-0').
|
2009-08-26 22:27:57 +02:00
|
|
|
|
2009-10-13 18:42:13 +02:00
|
|
|
@@ -55,9 +55,9 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
-include("adhoc.hrl").
|
|
|
|
-include("pubsub.hrl").
|
|
|
|
|
|
|
|
--define(STDTREE, "tree").
|
|
|
|
--define(STDNODE, "flat").
|
|
|
|
--define(PEPNODE, "pep").
|
|
|
|
+-define(STDTREE, "tree_odbc").
|
|
|
|
+-define(STDNODE, "flat_odbc").
|
|
|
|
+-define(PEPNODE, "pep_odbc").
|
|
|
|
|
|
|
|
%% exports for hooks
|
|
|
|
-export([presence_probe/3,
|
2009-10-13 18:42:13 +02:00
|
|
|
@@ -103,7 +103,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
string_to_affiliation/1,
|
|
|
|
extended_error/2,
|
2009-08-27 10:48:21 +02:00
|
|
|
extended_error/3,
|
|
|
|
- rename_default_nodeplugin/0
|
2009-08-26 22:27:57 +02:00
|
|
|
+ escape/1
|
|
|
|
]).
|
|
|
|
|
|
|
|
%% API and gen_server callbacks
|
2009-10-13 18:42:13 +02:00
|
|
|
@@ -122,7 +122,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
-export([send_loop/1
|
|
|
|
]).
|
|
|
|
|
|
|
|
--define(PROCNAME, ejabberd_mod_pubsub).
|
|
|
|
+-define(PROCNAME, ejabberd_mod_pubsub_odbc).
|
2010-01-12 16:14:57 +01:00
|
|
|
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
|
2009-08-26 22:27:57 +02:00
|
|
|
-define(PLUGIN_PREFIX, "node_").
|
|
|
|
-define(TREE_PREFIX, "nodetree_").
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -226,8 +226,6 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
ok
|
|
|
|
end,
|
|
|
|
ejabberd_router:register_route(Host),
|
|
|
|
- update_node_database(Host, ServerHost),
|
|
|
|
- update_state_database(Host, ServerHost),
|
2009-09-25 15:14:59 +02:00
|
|
|
init_nodes(Host, ServerHost, NodeTree, Plugins),
|
2009-08-26 22:27:57 +02:00
|
|
|
State = #state{host = Host,
|
|
|
|
server_host = ServerHost,
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -281,206 +279,15 @@
|
2009-10-21 10:31:51 +02:00
|
|
|
|
|
|
|
init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
|
|
|
|
%% TODO, this call should be done plugin side
|
|
|
|
- case lists:member("hometree", Plugins) of
|
|
|
|
+ case lists:member("hometree_odbc", Plugins) of
|
|
|
|
true ->
|
|
|
|
- create_node(Host, ServerHost, string_to_node("/home"), service_jid(Host), "hometree"),
|
|
|
|
- create_node(Host, ServerHost, string_to_node("/home" ++ ServerHost), service_jid(Host), "hometree");
|
|
|
|
+ create_node(Host, ServerHost, string_to_node("/home"), service_jid(Host), "hometree_odbc"),
|
|
|
|
+ create_node(Host, ServerHost, string_to_node("/home/" ++ ServerHost), service_jid(Host), "hometree_odbc");
|
|
|
|
false ->
|
2009-09-25 15:14:59 +02:00
|
|
|
ok
|
|
|
|
end.
|
2009-08-26 22:27:57 +02:00
|
|
|
|
|
|
|
-update_node_database(Host, ServerHost) ->
|
|
|
|
- mnesia:del_table_index(pubsub_node, type),
|
|
|
|
- mnesia:del_table_index(pubsub_node, parentid),
|
|
|
|
- case catch mnesia:table_info(pubsub_node, attributes) of
|
|
|
|
- [host_node, host_parent, info] ->
|
|
|
|
- ?INFO_MSG("upgrade node pubsub tables",[]),
|
|
|
|
- F = fun() ->
|
|
|
|
- {Result, LastIdx} = lists:foldl(
|
|
|
|
- fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, {RecList, NodeIdx}) ->
|
|
|
|
- ItemsList =
|
|
|
|
- lists:foldl(
|
|
|
|
- fun({item, IID, Publisher, Payload}, Acc) ->
|
|
|
|
- C = {unknown, Publisher},
|
|
|
|
- M = {now(), Publisher},
|
|
|
|
- mnesia:write(
|
|
|
|
- #pubsub_item{itemid = {IID, NodeIdx},
|
|
|
|
- creation = C,
|
|
|
|
- modification = M,
|
|
|
|
- payload = Payload}),
|
|
|
|
- [{Publisher, IID} | Acc]
|
|
|
|
- end, [], Items),
|
|
|
|
- Owners =
|
|
|
|
- dict:fold(
|
|
|
|
- fun(JID, {entity, Aff, Sub}, Acc) ->
|
|
|
|
- UsrItems =
|
|
|
|
- lists:foldl(
|
|
|
|
- fun({P, I}, IAcc) ->
|
|
|
|
- case P of
|
|
|
|
- JID -> [I | IAcc];
|
|
|
|
- _ -> IAcc
|
|
|
|
- end
|
|
|
|
- end, [], ItemsList),
|
|
|
|
- mnesia:write({pubsub_state,
|
|
|
|
- {JID, NodeIdx},
|
|
|
|
- UsrItems,
|
|
|
|
- Aff,
|
|
|
|
- Sub}),
|
|
|
|
- case Aff of
|
|
|
|
- owner -> [JID | Acc];
|
|
|
|
- _ -> Acc
|
|
|
|
- end
|
|
|
|
- end, [], Entities),
|
|
|
|
- mnesia:delete({pubsub_node, NodeId}),
|
|
|
|
- {[#pubsub_node{nodeid = NodeId,
|
|
|
|
- id = NodeIdx,
|
|
|
|
- parents = [element(2, ParentId)],
|
|
|
|
- owners = Owners,
|
|
|
|
- options = Options} |
|
|
|
|
- RecList], NodeIdx + 1}
|
|
|
|
- end, {[], 1},
|
|
|
|
- mnesia:match_object(
|
|
|
|
- {pubsub_node, {Host, '_'}, '_', '_'})),
|
|
|
|
- mnesia:write(#pubsub_index{index = node, last = LastIdx, free = []}),
|
|
|
|
- Result
|
|
|
|
- end,
|
|
|
|
- {atomic, NewRecords} = mnesia:transaction(F),
|
|
|
|
- {atomic, ok} = mnesia:delete_table(pubsub_node),
|
|
|
|
- {atomic, ok} = mnesia:create_table(pubsub_node,
|
|
|
|
- [{disc_copies, [node()]},
|
|
|
|
- {attributes, record_info(fields, pubsub_node)}]),
|
|
|
|
- FNew = fun() -> lists:foreach(fun(Record) ->
|
|
|
|
- mnesia:write(Record)
|
|
|
|
- end, NewRecords)
|
|
|
|
- end,
|
|
|
|
- case mnesia:transaction(FNew) of
|
|
|
|
- {atomic, Result} ->
|
|
|
|
- ?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
|
|
|
|
- {aborted, Reason} ->
|
|
|
|
- ?ERROR_MSG("Problem updating Pubsub node tables:~n~p", [Reason])
|
|
|
|
- end;
|
|
|
|
- [nodeid, parentid, type, owners, options] ->
|
|
|
|
- F = fun({pubsub_node, NodeId, {_, Parent}, Type, Owners, Options}) ->
|
|
|
|
- #pubsub_node{
|
|
|
|
- nodeid = NodeId,
|
|
|
|
- id = 0,
|
|
|
|
- parents = [Parent],
|
|
|
|
- type = Type,
|
|
|
|
- owners = Owners,
|
|
|
|
- options = Options}
|
|
|
|
- end,
|
|
|
|
- mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]),
|
|
|
|
- FNew = fun() ->
|
|
|
|
- LastIdx = lists:foldl(fun(#pubsub_node{nodeid = NodeId} = PubsubNode, NodeIdx) ->
|
|
|
|
- mnesia:write(PubsubNode#pubsub_node{id = NodeIdx}),
|
|
|
|
- lists:foreach(fun(#pubsub_state{stateid = StateId} = State) ->
|
|
|
|
- {JID, _} = StateId,
|
|
|
|
- mnesia:delete({pubsub_state, StateId}),
|
|
|
|
- mnesia:write(State#pubsub_state{stateid = {JID, NodeIdx}})
|
|
|
|
- end, mnesia:match_object(#pubsub_state{stateid = {'_', NodeId}, _ = '_'})),
|
|
|
|
- lists:foreach(fun(#pubsub_item{itemid = ItemId} = Item) ->
|
|
|
|
- {IID, _} = ItemId,
|
|
|
|
- {M1, M2} = Item#pubsub_item.modification,
|
|
|
|
- {C1, C2} = Item#pubsub_item.creation,
|
|
|
|
- mnesia:delete({pubsub_item, ItemId}),
|
|
|
|
- mnesia:write(Item#pubsub_item{itemid = {IID, NodeIdx},
|
|
|
|
- modification = {M2, M1},
|
|
|
|
- creation = {C2, C1}})
|
|
|
|
- end, mnesia:match_object(#pubsub_item{itemid = {'_', NodeId}, _ = '_'})),
|
|
|
|
- NodeIdx + 1
|
|
|
|
- end, 1, mnesia:match_object(
|
|
|
|
- {pubsub_node, {Host, '_'}, '_', '_', '_', '_', '_'})
|
|
|
|
- ++ mnesia:match_object(
|
|
|
|
- {pubsub_node, {{'_', ServerHost, '_'}, '_'}, '_', '_', '_', '_', '_'})),
|
|
|
|
- mnesia:write(#pubsub_index{index = node, last = LastIdx, free = []})
|
|
|
|
- end,
|
|
|
|
- case mnesia:transaction(FNew) of
|
|
|
|
- {atomic, Result} ->
|
|
|
|
- rename_default_nodeplugin(),
|
|
|
|
- ?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
|
|
|
|
- {aborted, Reason} ->
|
|
|
|
- ?ERROR_MSG("Problem updating Pubsub node tables:~n~p", [Reason])
|
|
|
|
- end;
|
|
|
|
- [nodeid, id, parent, type, owners, options] ->
|
|
|
|
- F = fun({pubsub_node, NodeId, Id, Parent, Type, Owners, Options}) ->
|
|
|
|
- #pubsub_node{
|
|
|
|
- nodeid = NodeId,
|
|
|
|
- id = Id,
|
|
|
|
- parents = [Parent],
|
|
|
|
- type = Type,
|
|
|
|
- owners = Owners,
|
|
|
|
- options = Options}
|
|
|
|
- end,
|
|
|
|
- mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]),
|
|
|
|
- rename_default_nodeplugin();
|
|
|
|
- _ ->
|
|
|
|
- ok
|
2009-10-21 10:31:51 +02:00
|
|
|
- end,
|
|
|
|
- mnesia:transaction(fun() ->
|
|
|
|
- case catch mnesia:first(pubsub_node) of
|
|
|
|
- {_, L} when is_list(L) ->
|
|
|
|
- lists:foreach(
|
|
|
|
- fun({H, N}) when is_list(N) ->
|
|
|
|
- [Node] = mnesia:read({pubsub_node, {H, N}}),
|
|
|
|
- Type = Node#pubsub_node.type,
|
|
|
|
- BN = element(2, node_call(Type, path_to_node, [N])),
|
|
|
|
- BP = case [element(2, node_call(Type, path_to_node, [P])) || P <- Node#pubsub_node.parents] of
|
|
|
|
- [<<>>] -> [];
|
|
|
|
- Parents -> Parents
|
|
|
|
- end,
|
|
|
|
- mnesia:write(Node#pubsub_node{nodeid={H, BN}, parents=BP}),
|
|
|
|
- mnesia:delete({pubsub_node, {H, N}});
|
|
|
|
- (_) ->
|
|
|
|
- ok
|
|
|
|
- end, mnesia:all_keys(pubsub_node));
|
|
|
|
- _ ->
|
|
|
|
- ok
|
|
|
|
- end
|
|
|
|
- end).
|
|
|
|
-
|
2009-08-26 22:27:57 +02:00
|
|
|
-rename_default_nodeplugin() ->
|
|
|
|
- lists:foreach(fun(Node) ->
|
|
|
|
- mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
|
|
|
|
- end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
|
|
|
|
-
|
|
|
|
-update_state_database(_Host, _ServerHost) ->
|
|
|
|
- case catch mnesia:table_info(pubsub_state, attributes) of
|
|
|
|
- [stateid, items, affiliation, subscription] ->
|
|
|
|
- ?INFO_MSG("upgrade state pubsub tables", []),
|
|
|
|
- F = fun ({pubsub_state, {JID, NodeID}, Items, Aff, Sub}, Acc) ->
|
|
|
|
- Subs = case Sub of
|
|
|
|
- none ->
|
|
|
|
- [];
|
|
|
|
- _ ->
|
|
|
|
- {result, SubID} = pubsub_subscription:subscribe_node(JID, NodeID, []),
|
|
|
|
- [{Sub, SubID}]
|
|
|
|
- end,
|
|
|
|
- NewState = #pubsub_state{stateid = {JID, NodeID},
|
|
|
|
- items = Items,
|
|
|
|
- affiliation = Aff,
|
|
|
|
- subscriptions = Subs},
|
|
|
|
- [NewState | Acc]
|
|
|
|
- end,
|
|
|
|
- {atomic, NewRecs} = mnesia:transaction(fun mnesia:foldl/3,
|
|
|
|
- [F, [], pubsub_state]),
|
|
|
|
- {atomic, ok} = mnesia:delete_table(pubsub_state),
|
|
|
|
- {atomic, ok} = mnesia:create_table(pubsub_state,
|
|
|
|
- [{disc_copies, [node()]},
|
|
|
|
- {attributes, record_info(fields, pubsub_state)}]),
|
|
|
|
- FNew = fun () ->
|
|
|
|
- lists:foreach(fun mnesia:write/1, NewRecs)
|
|
|
|
- end,
|
|
|
|
- case mnesia:transaction(FNew) of
|
|
|
|
- {atomic, Result} ->
|
|
|
|
- ?INFO_MSG("Pubsub state tables updated correctly: ~p",
|
|
|
|
- [Result]);
|
|
|
|
- {aborted, Reason} ->
|
|
|
|
- ?ERROR_MSG("Problem updating Pubsub state tables:~n~p",
|
|
|
|
- [Reason])
|
|
|
|
- end;
|
|
|
|
- _ ->
|
|
|
|
- ok
|
|
|
|
- end.
|
2009-10-21 10:31:51 +02:00
|
|
|
+
|
2009-08-26 22:27:57 +02:00
|
|
|
|
2010-01-12 16:14:57 +01:00
|
|
|
send_loop(State) ->
|
|
|
|
receive
|
|
|
|
@@ -492,17 +299,15 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
%% 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) ->
|
|
|
|
- {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, JID]),
|
|
|
|
+ Subscriptions = case catch node_action(Host, PType, get_entity_subscriptions_for_send_last, [Host, JID]) of
|
2009-09-24 21:47:01 +02:00
|
|
|
+ {result, S} -> S;
|
|
|
|
+ _ -> []
|
|
|
|
+ end,
|
2009-08-26 22:27:57 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun({Node, subscribed, _, SubJID}) ->
|
|
|
|
if (SubJID == LJID) or (SubJID == BJID) ->
|
2009-08-28 02:09:21 +02:00
|
|
|
- #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId, options = Options} = Node,
|
2009-08-26 22:27:57 +02:00
|
|
|
- case get_option(Options, send_last_published_item) of
|
|
|
|
- on_sub_and_presence ->
|
2009-09-24 21:47:01 +02:00
|
|
|
- send_items(H, N, NodeId, Type, LJID, last);
|
2009-08-26 22:27:57 +02:00
|
|
|
- _ ->
|
|
|
|
- ok
|
|
|
|
- end;
|
2009-09-24 21:47:01 +02:00
|
|
|
+ #pubsub_node{nodeid = {H, N}, type = Type, id = NodeId} = Node,
|
|
|
|
+ send_items(H, N, NodeId, Type, LJID, last);
|
2009-08-26 22:27:57 +02:00
|
|
|
true ->
|
|
|
|
% resource not concerned about that subscription
|
|
|
|
ok
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -683,8 +488,7 @@
|
2009-10-21 10:31:51 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
disco_sm_items(Acc, From, To, NodeB, _Lang) ->
|
|
|
|
- SNode = binary_to_list(NodeB),
|
|
|
|
- Node = string_to_node(SNode),
|
|
|
|
+ Node = string_to_node(binary_to_list(NodeB)),
|
|
|
|
%% TODO, use iq_disco_items(Host, Node, From)
|
|
|
|
Host = exmpp_jid:prep_domain_as_list(To),
|
|
|
|
LJID = jlib:short_prepd_bare_jid(To),
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -718,6 +522,7 @@
|
2009-12-08 19:59:00 +01:00
|
|
|
%% -------
|
|
|
|
%% presence hooks handling functions
|
|
|
|
%%
|
|
|
|
+
|
|
|
|
presence_probe(Peer, JID, Pid) ->
|
|
|
|
case exmpp_jid:full_compare(Peer, JID) of
|
2010-01-12 16:14:57 +01:00
|
|
|
true -> %% JID are equals
|
|
|
|
@@ -766,10 +571,10 @@
|
|
|
|
lists:foreach(fun(PType) ->
|
|
|
|
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
|
2009-10-13 18:42:13 +02:00
|
|
|
lists:foreach(fun
|
2010-01-12 16:14:57 +01:00
|
|
|
- ({#pubsub_node{options = Options, owners = Owners, id = NodeId}, subscribed, _, JID}) ->
|
|
|
|
+ ({#pubsub_node{options = Options, id = NodeId}, subscribed, _, JID}) ->
|
2009-10-13 18:42:13 +02:00
|
|
|
case get_option(Options, access_model) of
|
|
|
|
presence ->
|
|
|
|
- case lists:member(BJID, Owners) of
|
2010-01-12 16:14:57 +01:00
|
|
|
+ case lists:member(BJID, node_owners(Host, PType, NodeId)) of
|
2009-10-13 18:42:13 +02:00
|
|
|
true ->
|
2010-01-12 16:14:57 +01:00
|
|
|
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
|
2009-10-13 18:42:13 +02:00
|
|
|
false ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -941,11 +746,12 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
end,
|
|
|
|
ejabberd_router:route(To, From, Res);
|
|
|
|
#iq{type = get, ns = ?NS_DISCO_ITEMS,
|
|
|
|
- payload = SubEl} ->
|
|
|
|
+ payload = SubEl} = IQ ->
|
|
|
|
QAttrs = SubEl#xmlel.attrs,
|
|
|
|
Node = exmpp_xml:get_attribute_from_list_as_list(QAttrs,
|
|
|
|
'node', ""),
|
|
|
|
- Res = case iq_disco_items(Host, Node, From) of
|
|
|
|
+ Rsm = jlib:rsm_decode(IQ),
|
|
|
|
+ Res = case iq_disco_items(Host, Node, From, Rsm) of
|
|
|
|
{result, IQRes} ->
|
|
|
|
Result = #xmlel{ns = ?NS_DISCO_ITEMS,
|
|
|
|
name = 'query', attrs = QAttrs,
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1063,7 +869,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
[] ->
|
|
|
|
["leaf"]; %% No sub-nodes: it's a leaf node
|
|
|
|
_ ->
|
|
|
|
- case node_call(Type, get_items, [NodeId, From]) of
|
|
|
|
+ case node_call(Type, get_items, [NodeId, From, none]) of
|
|
|
|
{result, []} -> ["collection"];
|
|
|
|
{result, _} -> ["leaf", "collection"];
|
|
|
|
_ -> []
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1079,8 +885,9 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
[];
|
|
|
|
true ->
|
|
|
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} |
|
|
|
|
- lists:map(fun(T) ->
|
|
|
|
- #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s++"#"++T)]}
|
|
|
|
+ lists:map(fun
|
|
|
|
+ ("rsm") -> #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_RSM_s)]};
|
|
|
|
+ (T) -> #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s++"#"++T)]}
|
|
|
|
end, features(Type))]
|
|
|
|
end,
|
|
|
|
%% TODO: add meta-data info (spec section 5.4)
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1109,8 +916,9 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]},
|
2009-11-04 21:17:08 +01:00
|
|
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]},
|
2009-08-26 22:27:57 +02:00
|
|
|
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++
|
|
|
|
- lists:map(fun(Feature) ->
|
|
|
|
- #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s++"#"++Feature)]}
|
|
|
|
+ lists:map(fun
|
2009-10-27 15:24:33 +01:00
|
|
|
+ ("rsm") -> #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_RSM_s)]};
|
|
|
|
+ (Feature) -> #xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s++"#"++Feature)]}
|
2009-08-26 22:27:57 +02:00
|
|
|
end, features(Host, Node))};
|
2009-11-04 21:17:08 +01:00
|
|
|
?NS_ADHOC_b ->
|
|
|
|
command_disco_info(Host, Node, From);
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1120,7 +928,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
node_disco_info(Host, Node, From)
|
|
|
|
end.
|
|
|
|
|
|
|
|
-iq_disco_items(Host, [], From) ->
|
2009-10-29 13:41:51 +01:00
|
|
|
+iq_disco_items(Host, [], From, _RSM) ->
|
2009-10-27 15:24:33 +01:00
|
|
|
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
|
|
|
|
Nodes when is_list(Nodes) ->
|
|
|
|
{result, lists:map(
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1133,7 +941,7 @@
|
2009-10-27 15:24:33 +01:00
|
|
|
Other ->
|
|
|
|
Other
|
|
|
|
end;
|
2009-11-04 21:17:08 +01:00
|
|
|
-iq_disco_items(Host, ?NS_ADHOC_s, _From) ->
|
|
|
|
+iq_disco_items(Host, ?NS_ADHOC_s, _From, _RSM) ->
|
|
|
|
%% TODO: support localization of this string
|
|
|
|
CommandItems = [
|
|
|
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1142,10 +950,10 @@
|
2009-11-04 21:17:08 +01:00
|
|
|
?XMLATTR('name', "Get Pending")
|
|
|
|
]}],
|
|
|
|
{result, CommandItems};
|
|
|
|
-iq_disco_items(_Host, ?NS_PUBSUB_GET_PENDING, _From) ->
|
|
|
|
+iq_disco_items(_Host, ?NS_PUBSUB_GET_PENDING, _From, _RSM) ->
|
|
|
|
CommandItems = [],
|
|
|
|
{result, CommandItems};
|
2009-08-26 22:27:57 +02:00
|
|
|
-iq_disco_items(Host, Item, From) ->
|
|
|
|
+iq_disco_items(Host, Item, From, RSM) ->
|
|
|
|
case string:tokens(Item, "!") of
|
|
|
|
[_SNode, _ItemID] ->
|
|
|
|
{result, []};
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1153,10 +961,10 @@
|
2009-10-21 10:31:51 +02:00
|
|
|
Node = string_to_node(SNode),
|
2009-08-26 22:27:57 +02:00
|
|
|
Action =
|
|
|
|
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
2009-09-09 23:49:23 +02:00
|
|
|
- % TODO call get_items/6 instead for access control (EJAB-1033)
|
2009-08-26 22:27:57 +02:00
|
|
|
- NodeItems = case node_call(Type, get_items, [NodeId, From]) of
|
2009-09-09 23:49:23 +02:00
|
|
|
+ %% TODO call get_items/6 instead for access control (EJAB-1033)
|
2009-08-26 22:27:57 +02:00
|
|
|
+ {NodeItems, RsmOut} = case node_call(Type, get_items, [NodeId, From, RSM]) of
|
|
|
|
{result, I} -> I;
|
|
|
|
- _ -> []
|
|
|
|
+ _ -> {[], none}
|
|
|
|
end,
|
|
|
|
Nodes = lists:map(
|
|
|
|
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1167,9 +975,10 @@
|
2009-10-21 10:31:51 +02:00
|
|
|
Items = lists:map(
|
|
|
|
fun(#pubsub_item{itemid = {RN, _}}) ->
|
|
|
|
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
|
|
|
|
- #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host), ?XMLATTR('name', Name)]}
|
|
|
|
+ #xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs = [?XMLATTR('jid', Host),
|
|
|
|
+ ?XMLATTR('name', Name)]}
|
2009-08-26 22:27:57 +02:00
|
|
|
end, NodeItems),
|
|
|
|
- {result, Nodes ++ Items}
|
|
|
|
+ {result, Nodes ++ Items ++ jlib:rsm_encode(RsmOut)}
|
|
|
|
end,
|
|
|
|
case transaction(Host, Node, Action, sync_dirty) of
|
|
|
|
{result, {_, Result}} -> {result, Result};
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1300,7 +1109,8 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
(_, Acc) ->
|
|
|
|
Acc
|
|
|
|
end, [], exmpp_xml:remove_cdata_from_list(Els)),
|
|
|
|
- get_items(Host, Node, From, SubId, MaxItems, ItemIDs);
|
|
|
|
+ RSM = jlib:rsm_decode(SubEl),
|
|
|
|
+ get_items(Host, Node, From, SubId, MaxItems, ItemIDs, RSM);
|
|
|
|
{get, 'subscriptions'} ->
|
|
|
|
get_subscriptions(Host, Node, From, Plugins);
|
|
|
|
{get, 'affiliations'} ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1322,8 +1132,9 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
end.
|
|
|
|
|
|
|
|
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
|
|
|
- SubEls = SubEl#xmlel.children,
|
|
|
|
- Action = exmpp_xml:remove_cdata_from_list(SubEls),
|
2009-08-28 01:09:20 +02:00
|
|
|
+ Action = lists:filter(fun(#xmlel{name = 'set'}) -> false;
|
|
|
|
+ (_) -> true
|
|
|
|
+ end, exmpp_xml:get_child_elements(SubEl)),
|
2009-08-26 22:27:57 +02:00
|
|
|
case Action of
|
|
|
|
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
|
2009-10-21 10:31:51 +02:00
|
|
|
Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")),
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1457,7 +1268,8 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
_ -> []
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
- case transaction(fun () -> {result, lists:flatmap(Tr, Plugins)} end,
|
|
|
|
+ case transaction(Host,
|
|
|
|
+ fun () -> {result, lists:flatmap(Tr, Plugins)} end,
|
|
|
|
sync_dirty) of
|
|
|
|
{result, Res} -> Res;
|
|
|
|
Err -> Err
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1501,7 +1313,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
|
|
|
|
%%% authorization handling
|
|
|
|
|
|
|
|
-send_authorization_request(#pubsub_node{owners = Owners, nodeid = {Host, Node}}, Subscriber) ->
|
|
|
|
+send_authorization_request(#pubsub_node{nodeid = {Host, Node}, type = Type, id = NodeId}, Subscriber) ->
|
|
|
|
Lang = "en", %% TODO fix
|
|
|
|
{U, S, R} = Subscriber,
|
|
|
|
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1531,7 +1343,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
lists:foreach(fun(Owner) ->
|
|
|
|
{U, S, R} = Owner,
|
2009-12-04 17:32:20 +01:00
|
|
|
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
|
2009-08-26 22:27:57 +02:00
|
|
|
- end, Owners).
|
|
|
|
+ end, node_owners(Host, Type, NodeId)).
|
|
|
|
|
|
|
|
find_authorization_response(Packet) ->
|
|
|
|
Els = Packet#xmlel.children,
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1573,7 +1385,7 @@
|
2009-10-21 10:31:51 +02:00
|
|
|
end,
|
|
|
|
Stanza = event_stanza(
|
|
|
|
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs =
|
|
|
|
- [ ?XMLATTR('jid', exmpp_jid:to_binary(JID)) | nodeAttr(SNode)] ++ SubAttrs
|
|
|
|
+ [?XMLATTR('jid', exmpp_jid:to_binary(JID)) | nodeAttr(SNode)] ++ SubAttrs
|
|
|
|
}]),
|
2009-12-04 17:32:20 +01:00
|
|
|
ejabberd_router:route(service_jid(Host), JID, Stanza).
|
2009-10-21 10:31:51 +02:00
|
|
|
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1584,14 +1396,14 @@
|
2009-10-21 10:31:51 +02:00
|
|
|
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
|
|
|
|
{value, {_, [SAllow]}}} ->
|
|
|
|
Node = string_to_node(SNode),
|
|
|
|
- Subscriber = exmpp_jid:parse(SSubscriber),
|
|
|
|
+ Subscriber = exmpp_jid:parse(SSubscriber),
|
|
|
|
Allow = case SAllow of
|
|
|
|
"1" -> true;
|
2009-08-26 22:27:57 +02:00
|
|
|
"true" -> true;
|
|
|
|
_ -> false
|
|
|
|
end,
|
|
|
|
- Action = fun(#pubsub_node{type = Type, owners = Owners, id = NodeId}) ->
|
|
|
|
- IsApprover = lists:member(jlib:short_prepd_bare_jid(From), Owners),
|
|
|
|
+ Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
|
|
|
+ IsApprover = lists:member(jlib:short_prepd_bare_jid(From), node_owners_call(Type, NodeId)),
|
|
|
|
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
|
|
|
|
if
|
|
|
|
not IsApprover ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1786,7 +1598,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
end,
|
|
|
|
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
|
|
|
|
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
|
|
|
|
- case transaction(CreateNode, transaction) of
|
|
|
|
+ case transaction(Host, CreateNode, transaction) of
|
|
|
|
{result, {Result, broadcast}} ->
|
|
|
|
%%Lang = "en", %% TODO: fix
|
|
|
|
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1895,7 +1707,7 @@
|
2009-08-28 01:09:20 +02:00
|
|
|
%%<li>The node does not exist.</li>
|
|
|
|
%%</ul>
|
|
|
|
subscribe_node(Host, Node, From, JID, Configuration) ->
|
2009-10-12 12:23:51 +02:00
|
|
|
- SubOpts = case pubsub_subscription:parse_options_xform(Configuration) of
|
|
|
|
+ SubOpts = case pubsub_subscription_odbc:parse_options_xform(Configuration) of
|
|
|
|
{result, GoodSubOpts} -> GoodSubOpts;
|
|
|
|
_ -> invalid
|
|
|
|
end,
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1906,7 +1718,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
{undefined, undefined, undefined}
|
|
|
|
end,
|
|
|
|
SubId = uniqid(),
|
|
|
|
- Action = fun(#pubsub_node{options = Options, owners = [Owner|_], type = Type, id = NodeId}) ->
|
|
|
|
+ Action = fun(#pubsub_node{options = Options, type = Type, id = NodeId}) ->
|
|
|
|
Features = features(Type),
|
|
|
|
SubscribeFeature = lists:member("subscribe", Features),
|
|
|
|
OptionsFeature = lists:member("subscription-options", Features),
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -1925,9 +1737,13 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
{"", "", ""} ->
|
|
|
|
{false, false};
|
|
|
|
_ ->
|
|
|
|
- {OU, OS, _} = Owner,
|
|
|
|
- get_roster_info(OU, OS,
|
|
|
|
- Subscriber, AllowedGroups)
|
|
|
|
+ case node_owners_call(Type, NodeId) of
|
|
|
|
+ [{OU, OS, _} | _] ->
|
|
|
|
+ get_roster_info(OU, OS,
|
|
|
|
+ Subscriber, AllowedGroups);
|
|
|
|
+ _ ->
|
|
|
|
+ {false, false}
|
|
|
|
+ end
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
if
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2260,7 +2076,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
%% <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.
|
|
|
|
-get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) ->
|
|
|
|
+get_items(Host, Node, From, SubId, SMaxItems, ItemIDs, RSM) ->
|
|
|
|
MaxItems =
|
|
|
|
if
|
2009-09-23 18:32:06 +02:00
|
|
|
SMaxItems == "" -> get_max_items_node(Host);
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2299,11 +2115,11 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
node_call(Type, get_items,
|
|
|
|
[NodeId, From,
|
|
|
|
AccessModel, PresenceSubscription, RosterGroup,
|
|
|
|
- SubId])
|
|
|
|
+ SubId, RSM])
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
case transaction(Host, Node, Action, sync_dirty) of
|
|
|
|
- {result, {_, Items}} ->
|
|
|
|
+ {result, {_, Items, RSMOut}} ->
|
|
|
|
SendItems = case ItemIDs of
|
|
|
|
[] ->
|
|
|
|
Items;
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2316,7 +2132,7 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
%% number of items sent to MaxItems:
|
|
|
|
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
|
|
|
|
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
|
|
|
|
- itemsEls(lists:sublist(SendItems, MaxItems))}]}};
|
|
|
|
+ itemsEls(lists:sublist(SendItems, MaxItems))} | jlib:rsm_encode(RSMOut)]}};
|
|
|
|
Error ->
|
|
|
|
Error
|
|
|
|
end
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2348,17 +2164,29 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
%% @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) ->
|
|
|
|
- case get_cached_item(Host, NodeId) of
|
|
|
|
+ Stanza = case get_cached_item(Host, NodeId) of
|
|
|
|
undefined ->
|
|
|
|
- send_items(Host, Node, NodeId, Type, LJID, 1);
|
|
|
|
+ % special ODBC optimization, works only with node_hometree_odbc, node_flat_odbc and node_pep_odbc
|
2009-09-23 18:32:06 +02:00
|
|
|
+ case node_action(Host, Type, get_last_items, [NodeId, LJID, 1]) of
|
|
|
|
+ {result, [LastItem]} ->
|
|
|
|
+ {ModifNow, ModifLjid} = LastItem#pubsub_item.modification,
|
|
|
|
+ event_stanza_with_delay([#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items',
|
|
|
|
+ attrs = nodeAttr(Node),
|
|
|
|
+ children = itemsEls([])}],
|
|
|
|
+ ModifNow, ModifLjid);
|
|
|
|
+ _ ->
|
|
|
|
+ event_stanza([#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items',
|
|
|
|
+ attrs = nodeAttr(Node),
|
|
|
|
+ children = itemsEls([])}])
|
|
|
|
+ end;
|
2009-08-26 22:27:57 +02:00
|
|
|
LastItem ->
|
2009-09-23 18:32:06 +02:00
|
|
|
{ModifNow, ModifLjid} = LastItem#pubsub_item.modification,
|
|
|
|
- Stanza = event_stanza_with_delay(
|
|
|
|
+ event_stanza_with_delay(
|
2009-08-26 22:27:57 +02:00
|
|
|
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'items', attrs = nodeAttr(Node),
|
2009-09-23 18:32:06 +02:00
|
|
|
- children = itemsEls(LastItem)}], ModifNow, ModifLjid),
|
2009-08-26 22:27:57 +02:00
|
|
|
- {U, S, R} = LJID,
|
2009-12-04 17:32:20 +01:00
|
|
|
- ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
|
2009-08-26 22:27:57 +02:00
|
|
|
- end;
|
2009-09-23 18:32:06 +02:00
|
|
|
+ children = itemsEls(LastItem)}], ModifNow, ModifLjid)
|
2009-08-26 22:27:57 +02:00
|
|
|
+ end,
|
|
|
|
+ {U, S, R} = LJID,
|
2009-12-04 17:32:20 +01:00
|
|
|
+ ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza);
|
2009-08-26 22:27:57 +02:00
|
|
|
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
|
|
|
|
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
|
|
|
{result, []} ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2487,29 +2315,12 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
error ->
|
|
|
|
{error, 'bad-request'};
|
|
|
|
_ ->
|
|
|
|
- Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}=N) ->
|
|
|
|
- case lists:member(Owner, Owners) of
|
|
|
|
+ Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
|
|
|
+ case lists:member(Owner, node_owners_call(Type, NodeId)) of
|
|
|
|
true ->
|
|
|
|
lists:foreach(
|
|
|
|
fun({JID, Affiliation}) ->
|
|
|
|
- {result, _} = node_call(Type, set_affiliation, [NodeId, JID, Affiliation]),
|
|
|
|
- case Affiliation of
|
|
|
|
- owner ->
|
|
|
|
- NewOwner = jlib:short_prepd_bare_jid(JID),
|
|
|
|
- NewOwners = [NewOwner|Owners],
|
|
|
|
- tree_call(Host, set_node, [N#pubsub_node{owners = NewOwners}]);
|
|
|
|
- none ->
|
|
|
|
- OldOwner = jlib:short_prepd_bare_jid(JID),
|
|
|
|
- case lists:member(OldOwner, Owners) of
|
|
|
|
- true ->
|
|
|
|
- NewOwners = Owners--[OldOwner],
|
|
|
|
- tree_call(Host, set_node, [N#pubsub_node{owners = NewOwners}]);
|
|
|
|
- _ ->
|
|
|
|
- ok
|
|
|
|
- end;
|
|
|
|
- _ ->
|
|
|
|
- ok
|
|
|
|
- end
|
|
|
|
+ node_call(Type, set_affiliation, [NodeId, JID, Affiliation])
|
|
|
|
end, Entities),
|
|
|
|
{result, []};
|
|
|
|
_ ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2564,11 +2375,11 @@
|
2009-08-28 01:09:20 +02:00
|
|
|
end.
|
|
|
|
|
2009-09-01 15:23:19 +02:00
|
|
|
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
|
2009-08-28 01:09:20 +02:00
|
|
|
- case pubsub_subscription:get_subscription(Subscriber, NodeID, SubID) of
|
|
|
|
+ case pubsub_subscription_odbc:get_subscription(Subscriber, NodeID, SubID) of
|
|
|
|
{error, notfound} ->
|
2009-09-01 15:23:19 +02:00
|
|
|
{error, extended_error('not-acceptable', "invalid-subid")};
|
2009-08-28 01:09:20 +02:00
|
|
|
{result, #pubsub_subscription{options = Options}} ->
|
2009-09-01 15:23:19 +02:00
|
|
|
- {result, XdataEl} = pubsub_subscription:get_options_xform(Lang, Options),
|
|
|
|
+ {result, XdataEl} = pubsub_subscription_odbc:get_options_xform(Lang, Options),
|
|
|
|
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
|
2009-10-21 10:31:51 +02:00
|
|
|
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
|
|
|
|
?XMLATTR('Subid', SubID) | nodeAttr(Node)],
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2595,7 +2406,7 @@
|
2009-08-28 01:09:20 +02:00
|
|
|
end.
|
|
|
|
|
2009-10-12 12:23:51 +02:00
|
|
|
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
|
|
|
|
- SubOpts = case pubsub_subscription:parse_options_xform(Configuration) of
|
|
|
|
+ SubOpts = case pubsub_subscription_odbc:parse_options_xform(Configuration) of
|
|
|
|
{result, GoodSubOpts} -> GoodSubOpts;
|
|
|
|
_ -> invalid
|
|
|
|
end,
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2625,7 +2436,7 @@
|
2009-10-12 12:23:51 +02:00
|
|
|
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
|
|
|
|
{error, extended_error('bad-request', "invalid-options")};
|
2009-08-28 01:09:20 +02:00
|
|
|
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, _} ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -2798,8 +2609,8 @@
|
2009-08-27 10:48:21 +02:00
|
|
|
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
|
2009-12-04 17:32:20 +01:00
|
|
|
ejabberd_router:route(service_jid(Host), JID, Stanza)
|
2009-08-26 22:27:57 +02:00
|
|
|
end,
|
|
|
|
- Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
|
|
|
|
- case lists:member(Owner, Owners) of
|
|
|
|
+ Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
|
|
|
+ case lists:member(Owner, node_owners_call(Type, NodeId)) of
|
|
|
|
true ->
|
|
|
|
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
|
|
|
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3088,7 +2899,7 @@
|
2009-08-28 01:09:20 +02:00
|
|
|
{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.
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3102,9 +2913,9 @@
|
2009-08-28 01:09:20 +02:00
|
|
|
|
|
|
|
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) ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3112,7 +2923,7 @@
|
2009-10-21 10:31:51 +02:00
|
|
|
end, [], Subs).
|
|
|
|
|
|
|
|
% TODO: merge broadcast code that way
|
|
|
|
-% TODO: pablo: Why is this commented? Seems to be present on trunk.
|
|
|
|
+% TODO: pablo: why is this commented?
|
|
|
|
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
|
|
|
|
% case (get_option(NodeOptions, Feature) or Force) of
|
|
|
|
% true ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3333,6 +3144,30 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
Result
|
|
|
|
end.
|
|
|
|
|
2009-08-28 01:09:20 +02:00
|
|
|
+%% @spec (Host, Type, NodeId) -> [ljid()]
|
2009-08-26 22:27:57 +02:00
|
|
|
+%% NodeId = pubsubNodeId()
|
|
|
|
+%% @doc <p>Return list of node owners.</p>
|
|
|
|
+node_owners(Host, Type, NodeId) ->
|
|
|
|
+ case node_action(Host, Type, get_node_affiliations, [NodeId]) of
|
|
|
|
+ {result, Affiliations} ->
|
|
|
|
+ lists:foldl(
|
|
|
|
+ fun({LJID, owner}, Acc) -> [LJID|Acc];
|
|
|
|
+ (_, Acc) -> Acc
|
|
|
|
+ end, [], Affiliations);
|
|
|
|
+ _ ->
|
|
|
|
+ []
|
|
|
|
+ end.
|
|
|
|
+node_owners_call(Type, NodeId) ->
|
|
|
|
+ case node_call(Type, get_node_affiliations, [NodeId]) of
|
|
|
|
+ {result, Affiliations} ->
|
|
|
|
+ lists:foldl(
|
|
|
|
+ fun({LJID, owner}, Acc) -> [LJID|Acc];
|
|
|
|
+ (_, Acc) -> Acc
|
|
|
|
+ end, [], Affiliations);
|
|
|
|
+ _ ->
|
|
|
|
+ []
|
|
|
|
+ end.
|
|
|
|
+
|
|
|
|
%% @spec (Host, Options) -> MaxItems
|
|
|
|
%% Host = host()
|
|
|
|
%% Options = [Option]
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3728,7 +3563,13 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
tree_action(Host, Function, Args) ->
|
|
|
|
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
|
|
|
|
Fun = fun() -> tree_call(Host, Function, Args) end,
|
|
|
|
- catch mnesia:sync_dirty(Fun).
|
|
|
|
+ case catch ejabberd_odbc:sql_bloc(odbc_conn(Host), Fun) of
|
|
|
|
+ {atomic, Result} ->
|
|
|
|
+ Result;
|
|
|
|
+ {aborted, Reason} ->
|
|
|
|
+ ?ERROR_MSG("transaction return internal error: ~p~n",[{aborted, Reason}]),
|
|
|
|
+ {error, 'internal-server-error'}
|
|
|
|
+ end.
|
|
|
|
|
|
|
|
%% @doc <p>node plugin call.</p>
|
|
|
|
node_call(Type, Function, Args) ->
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3748,13 +3589,13 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
|
|
|
|
node_action(Host, Type, Function, Args) ->
|
|
|
|
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
|
|
|
|
- transaction(fun() ->
|
|
|
|
+ transaction(Host, fun() ->
|
|
|
|
node_call(Type, Function, Args)
|
|
|
|
end, sync_dirty).
|
|
|
|
|
|
|
|
%% @doc <p>plugin transaction handling.</p>
|
|
|
|
transaction(Host, Node, Action, Trans) ->
|
|
|
|
- transaction(fun() ->
|
|
|
|
+ transaction(Host, fun() ->
|
|
|
|
case tree_call(Host, get_node, [Host, Node]) of
|
|
|
|
N when is_record(N, pubsub_node) ->
|
|
|
|
case Action(N) of
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3767,8 +3608,15 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
end
|
|
|
|
end, Trans).
|
|
|
|
|
|
|
|
-transaction(Fun, Trans) ->
|
|
|
|
- case catch mnesia:Trans(Fun) of
|
|
|
|
+transaction(Host, Fun, Trans) ->
|
|
|
|
+ transaction_retry(Host, Fun, Trans, 2).
|
|
|
|
+
|
|
|
|
+transaction_retry(Host, Fun, Trans, Count) ->
|
|
|
|
+ SqlFun = case Trans of
|
|
|
|
+ transaction -> sql_transaction;
|
|
|
|
+ _ -> sql_bloc
|
|
|
|
+ end,
|
|
|
|
+ case catch ejabberd_odbc:SqlFun(odbc_conn(Host), Fun) of
|
|
|
|
{result, Result} -> {result, Result};
|
|
|
|
{error, Error} -> {error, Error};
|
|
|
|
{atomic, {result, Result}} -> {result, Result};
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3776,6 +3624,15 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
{aborted, Reason} ->
|
|
|
|
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
|
|
|
|
{error, 'internal-server-error'};
|
|
|
|
+ {'EXIT', {timeout, _} = Reason} ->
|
|
|
|
+ case Count of
|
|
|
|
+ 0 ->
|
|
|
|
+ ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
|
|
|
|
+ {error, 'internal-server-error'};
|
|
|
|
+ N ->
|
|
|
|
+ erlang:yield(),
|
|
|
|
+ transaction_retry(Host, Fun, Trans, N-1)
|
|
|
|
+ end;
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
|
|
|
|
{error, 'internal-server-error'};
|
2010-01-12 16:14:57 +01:00
|
|
|
@@ -3784,6 +3641,16 @@
|
2009-08-26 22:27:57 +02:00
|
|
|
{error, 'internal-server-error'}
|
|
|
|
end.
|
|
|
|
|
|
|
|
+odbc_conn({_U, Host, _R})->
|
|
|
|
+ Host;
|
|
|
|
+odbc_conn(Host) ->
|
2009-12-04 17:07:43 +01:00
|
|
|
+ lists:dropwhile(fun(A) -> A/=$. end, Host) -- ".".
|
2009-08-26 22:27:57 +02:00
|
|
|
+
|
|
|
|
+%% escape value for database storage
|
|
|
|
+escape({_U, _H, _R}=JID)->
|
|
|
|
+ ejabberd_odbc:escape(exmpp_jid:to_list(JID));
|
|
|
|
+escape(Value)->
|
|
|
|
+ ejabberd_odbc:escape(Value).
|
|
|
|
%%%% helpers
|
|
|
|
|
|
|
|
%% Add pubsub-specific error element
|