24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

update pubsub_odbc.patch

SVN Revision: 2518
This commit is contained in:
Christophe Romain 2009-08-21 11:54:22 +00:00
parent dabea295aa
commit e6b05199a8
2 changed files with 47 additions and 42 deletions

View File

@ -263,8 +263,8 @@ terminate_plugins(Host, ServerHost, Plugins, TreePlugin) ->
ok. ok.
init_nodes(Host, ServerHost) -> init_nodes(Host, ServerHost) ->
create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree_odbc"), create_node(Host, ServerHost, ["home"], service_jid(Host), "hometree"),
create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree_odbc"), create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"),
ok. ok.
update_node_database(Host, ServerHost) -> update_node_database(Host, ServerHost) ->
@ -274,7 +274,7 @@ update_node_database(Host, ServerHost) ->
[host_node, host_parent, info] -> [host_node, host_parent, info] ->
?INFO_MSG("upgrade node pubsub tables",[]), ?INFO_MSG("upgrade node pubsub tables",[]),
F = fun() -> F = fun() ->
lists:foldl( {Result, LastIdx} = lists:foldl(
fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, {RecList, NodeIdx}) -> fun({pubsub_node, NodeId, ParentId, {nodeinfo, Items, Options, Entities}}, {RecList, NodeIdx}) ->
ItemsList = ItemsList =
lists:foldl( lists:foldl(
@ -318,7 +318,9 @@ update_node_database(Host, ServerHost) ->
RecList], NodeIdx + 1} RecList], NodeIdx + 1}
end, {[], 1}, end, {[], 1},
mnesia:match_object( mnesia:match_object(
{pubsub_node, {Host, '_'}, '_', '_'})) {pubsub_node, {Host, '_'}, '_', '_'})),
mnesia:write(#pubsub_index{index = node, last = LastIdx, free = []}),
Result
end, end,
{atomic, NewRecords} = mnesia:transaction(F), {atomic, NewRecords} = mnesia:transaction(F),
{atomic, ok} = mnesia:delete_table(pubsub_node), {atomic, ok} = mnesia:delete_table(pubsub_node),
@ -349,7 +351,7 @@ update_node_database(Host, ServerHost) ->
end, end,
mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]), mnesia:transform_table(pubsub_node, F, [nodeid, id, parents, type, owners, options]),
FNew = fun() -> FNew = fun() ->
lists:foldl(fun(#pubsub_node{nodeid = NodeId} = PubsubNode, NodeIdx) -> LastIdx = lists:foldl(fun(#pubsub_node{nodeid = NodeId} = PubsubNode, NodeIdx) ->
mnesia:write(PubsubNode#pubsub_node{id = NodeIdx}), mnesia:write(PubsubNode#pubsub_node{id = NodeIdx}),
lists:foreach(fun(#pubsub_state{stateid = StateId} = State) -> lists:foreach(fun(#pubsub_state{stateid = StateId} = State) ->
{JID, _} = StateId, {JID, _} = StateId,
@ -369,7 +371,8 @@ update_node_database(Host, ServerHost) ->
end, 1, mnesia:match_object( end, 1, mnesia:match_object(
{pubsub_node, {Host, '_'}, '_', '_', '_', '_', '_'}) {pubsub_node, {Host, '_'}, '_', '_', '_', '_', '_'})
++ mnesia:match_object( ++ mnesia:match_object(
{pubsub_node, {{'_', ServerHost, '_'}, '_'}, '_', '_', '_', '_', '_'})) {pubsub_node, {{'_', ServerHost, '_'}, '_'}, '_', '_', '_', '_', '_'})),
mnesia:write(#pubsub_index{index = node, last = LastIdx, free = []})
end, end,
case mnesia:transaction(FNew) of case mnesia:transaction(FNew) of
{atomic, Result} -> {atomic, Result} ->
@ -2952,8 +2955,10 @@ get_node_subs(#pubsub_node{type = Type,
get_options_for_subs(_Host, Node, NodeID, Subs) -> get_options_for_subs(_Host, Node, NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
{result, #pubsub_subscription{options = Options}} = pubsub_subscription:get_subscription(JID, NodeID, SubID), case pubsub_subscription:get_subscription(JID, NodeID, SubID) of
[{JID, Node, Options} | Acc]; {result, #pubsub_subscription{options = Options}} -> [{JID, Node, Options} | Acc];
_ -> Acc
end;
(_, Acc) -> (_, Acc) ->
Acc Acc
end, [], Subs). end, [], Subs).
@ -3154,7 +3159,7 @@ node_options(Type) ->
Result Result
end. end.
%% @spec (Host, Type, NodeId) -> [ljid()] %% @spec (NodeId) -> [ljid()]
%% NodeId = pubsubNodeId() %% NodeId = pubsubNodeId()
%% @doc <p>Return list of node owners.</p> %% @doc <p>Return list of node owners.</p>
node_owners(Host, Type, NodeId) -> node_owners(Host, Type, NodeId) ->

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2009-07-31 16:53:48.000000000 +0200 --- mod_pubsub.erl 2009-08-20 17:49:22.000000000 +0200
+++ mod_pubsub_odbc.erl 2009-07-31 17:07:00.000000000 +0200 +++ mod_pubsub_odbc.erl 2009-08-21 13:53:33.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)
@ -50,7 +50,7 @@
init_nodes(Host, ServerHost), init_nodes(Host, ServerHost),
State = #state{host = Host, State = #state{host = Host,
server_host = ServerHost, server_host = ServerHost,
@@ -456,17 +455,15 @@ @@ -459,17 +458,15 @@
%% for each node From is subscribed to %% for each node From is subscribed to
%% and if the node is so configured, send the last published item to From %% and if the node is so configured, send the last published item to From
lists:foreach(fun(PType) -> lists:foreach(fun(PType) ->
@ -74,7 +74,7 @@
true -> true ->
% resource not concerned about that subscription % resource not concerned about that subscription
ok ok
@@ -789,10 +786,10 @@ @@ -792,10 +789,10 @@
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]), {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
lists:foreach(fun lists:foreach(fun
({Node, subscribed, _, JID}) -> ({Node, subscribed, _, JID}) ->
@ -87,7 +87,7 @@
true -> true ->
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]); node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
false -> false ->
@@ -906,7 +903,8 @@ @@ -909,7 +906,8 @@
sub_el = SubEl} = IQ -> sub_el = SubEl} = IQ ->
{xmlelement, _, QAttrs, _} = SubEl, {xmlelement, _, QAttrs, _} = SubEl,
Node = xml:get_attr_s("node", QAttrs), Node = xml:get_attr_s("node", QAttrs),
@ -97,7 +97,7 @@
{result, IQRes} -> {result, IQRes} ->
jlib:iq_to_xml( jlib:iq_to_xml(
IQ#iq{type = result, IQ#iq{type = result,
@@ -1011,7 +1009,7 @@ @@ -1014,7 +1012,7 @@
[] -> [] ->
["leaf"]; %% No sub-nodes: it's a leaf node ["leaf"]; %% No sub-nodes: it's a leaf node
_ -> _ ->
@ -106,7 +106,7 @@
{result, []} -> ["collection"]; {result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"]; {result, _} -> ["leaf", "collection"];
_ -> [] _ -> []
@@ -1027,8 +1025,9 @@ @@ -1030,8 +1028,9 @@
[]; [];
true -> true ->
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} | [{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
@ -118,7 +118,7 @@
end, features(Type))] end, features(Type))]
end, end,
%% TODO: add meta-data info (spec section 5.4) %% TODO: add meta-data info (spec section 5.4)
@@ -1056,14 +1055,15 @@ @@ -1059,14 +1058,15 @@
{xmlelement, "feature", [{"var", ?NS_DISCO_ITEMS}], []}, {xmlelement, "feature", [{"var", ?NS_DISCO_ITEMS}], []},
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []}, {xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++ {xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
@ -137,7 +137,7 @@
{result, lists:map( {result, lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) -> fun(#pubsub_node{nodeid = {_, SubNode}}) ->
SN = node_to_string(SubNode), SN = node_to_string(SubNode),
@@ -1073,7 +1073,7 @@ @@ -1076,7 +1076,7 @@
{"node", SN}, {"node", SN},
{"name", RN}], []} {"name", RN}], []}
end, tree_action(Host, get_subnodes, [Host, [], From]))}; end, tree_action(Host, get_subnodes, [Host, [], From]))};
@ -146,7 +146,7 @@
case string:tokens(Item, "!") of case string:tokens(Item, "!") of
[_SNode, _ItemID] -> [_SNode, _ItemID] ->
{result, []}; {result, []};
@@ -1085,9 +1085,9 @@ @@ -1088,9 +1088,9 @@
%% TODO That is, remove name attribute (or node?, please check for 2.1) %% TODO That is, remove name attribute (or node?, please check for 2.1)
Action = Action =
fun(#pubsub_node{type = Type, id = NodeId}) -> fun(#pubsub_node{type = Type, id = NodeId}) ->
@ -158,7 +158,7 @@
end, end,
Nodes = lists:map( Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}}) -> fun(#pubsub_node{nodeid = {_, SubNode}}) ->
@@ -1103,7 +1103,7 @@ @@ -1106,7 +1106,7 @@
{xmlelement, "item", [{"jid", Host}, {"node", SN}, {xmlelement, "item", [{"jid", Host}, {"node", SN},
{"name", Name}], []} {"name", Name}], []}
end, NodeItems), end, NodeItems),
@ -167,7 +167,7 @@
end, end,
case transaction(Host, Node, Action, sync_dirty) of case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> {result, Result}; {result, {_, Result}} -> {result, Result};
@@ -1235,7 +1235,8 @@ @@ -1238,7 +1238,8 @@
(_, Acc) -> (_, Acc) ->
Acc Acc
end, [], xml:remove_cdata(Els)), end, [], xml:remove_cdata(Els)),
@ -177,7 +177,7 @@
{get, "subscriptions"} -> {get, "subscriptions"} ->
get_subscriptions(Host, Node, From, Plugins); get_subscriptions(Host, Node, From, Plugins);
{get, "affiliations"} -> {get, "affiliations"} ->
@@ -1258,7 +1259,10 @@ @@ -1261,7 +1262,10 @@
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
{xmlelement, _, _, SubEls} = SubEl, {xmlelement, _, _, SubEls} = SubEl,
@ -189,7 +189,7 @@
case Action of case Action of
[{xmlelement, Name, Attrs, Els}] -> [{xmlelement, Name, Attrs, Els}] ->
Node = case Host of Node = case Host of
@@ -1384,7 +1388,8 @@ @@ -1387,7 +1391,8 @@
_ -> [] _ -> []
end end
end, end,
@ -199,7 +199,7 @@
sync_dirty) of sync_dirty) of
{result, Res} -> Res; {result, Res} -> Res;
Err -> Err Err -> Err
@@ -1428,7 +1433,7 @@ @@ -1431,7 +1436,7 @@
%%% authorization handling %%% authorization handling
@ -208,7 +208,7 @@
Lang = "en", %% TODO fix Lang = "en", %% TODO fix
Stanza = {xmlelement, "message", Stanza = {xmlelement, "message",
[], [],
@@ -1457,7 +1462,7 @@ @@ -1460,7 +1465,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}
@ -217,7 +217,7 @@
find_authorization_response(Packet) -> find_authorization_response(Packet) ->
{xmlelement, _Name, _Attrs, Els} = Packet, {xmlelement, _Name, _Attrs, Els} = Packet,
@@ -1524,8 +1529,8 @@ @@ -1527,8 +1532,8 @@
"true" -> true; "true" -> true;
_ -> false _ -> false
end, end,
@ -228,7 +228,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 ->
@@ -1711,7 +1716,7 @@ @@ -1714,7 +1719,7 @@
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
[{xmlelement, "create", nodeAttr(Node), [{xmlelement, "create", nodeAttr(Node),
[]}]}], []}]}],
@ -237,7 +237,7 @@
{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)),
@@ -1823,7 +1828,7 @@ @@ -1826,7 +1831,7 @@
error -> {"", "", ""}; error -> {"", "", ""};
J -> jlib:jid_tolower(J) J -> jlib:jid_tolower(J)
end, end,
@ -246,7 +246,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),
@@ -1842,9 +1847,13 @@ @@ -1845,9 +1850,13 @@
{"", "", ""} -> {"", "", ""} ->
{false, false}; {false, false};
_ -> _ ->
@ -263,7 +263,7 @@
end end
end, end,
if if
@@ -2167,7 +2176,7 @@ @@ -2170,7 +2179,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.
@ -272,7 +272,7 @@
MaxItems = MaxItems =
if if
SMaxItems == "" -> ?MAXITEMS; SMaxItems == "" -> ?MAXITEMS;
@@ -2206,11 +2215,11 @@ @@ -2209,11 +2218,11 @@
node_call(Type, get_items, node_call(Type, get_items,
[NodeId, From, [NodeId, From,
AccessModel, PresenceSubscription, RosterGroup, AccessModel, PresenceSubscription, RosterGroup,
@ -286,7 +286,7 @@
SendItems = case ItemIDs of SendItems = case ItemIDs of
[] -> [] ->
Items; Items;
@@ -2223,7 +2232,8 @@ @@ -2226,7 +2235,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),
@ -296,7 +296,7 @@
Error -> Error ->
Error Error
end end
@@ -2255,15 +2265,22 @@ @@ -2258,15 +2268,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) ->
@ -325,7 +325,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, []} ->
@@ -2381,29 +2398,12 @@ @@ -2384,29 +2401,12 @@
error -> error ->
{error, ?ERR_BAD_REQUEST}; {error, ?ERR_BAD_REQUEST};
_ -> _ ->
@ -358,7 +358,7 @@
end, Entities), end, Entities),
{result, []}; {result, []};
_ -> _ ->
@@ -2665,8 +2665,8 @@ @@ -2668,8 +2668,8 @@
error -> error ->
{error, ?ERR_BAD_REQUEST}; {error, ?ERR_BAD_REQUEST};
_ -> _ ->
@ -369,7 +369,7 @@
true -> true ->
lists:foreach(fun({JID, Subscription, SubId}) -> lists:foreach(fun({JID, Subscription, SubId}) ->
node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
@@ -3154,6 +3154,30 @@ @@ -3159,6 +3159,30 @@
Result Result
end. end.
@ -397,10 +397,10 @@
+ [] + []
+ end. + end.
+ +
%% @spec (Options) -> MaxItems %% @spec (Host, Options) -> MaxItems
%% Host = host() %% Host = host()
%% Options = [Option] %% Options = [Option]
@@ -3527,7 +3551,13 @@ @@ -3532,7 +3556,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,
@ -415,7 +415,7 @@
%% @doc <p>node plugin call.</p> %% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) -> node_call(Type, Function, Args) ->
@@ -3547,13 +3577,13 @@ @@ -3552,13 +3582,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]),
@ -431,7 +431,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
@@ -3566,8 +3596,14 @@ @@ -3571,8 +3601,14 @@
end end
end, Trans). end, Trans).
@ -448,7 +448,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};
@@ -3575,6 +3611,15 @@ @@ -3580,6 +3616,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};
@ -464,7 +464,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};
@@ -3583,6 +3628,17 @@ @@ -3588,6 +3633,17 @@
{error, ?ERR_INTERNAL_SERVER_ERROR} {error, ?ERR_INTERNAL_SERVER_ERROR}
end. end.