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

View File

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