mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
added function to rename old default nodes to hometree
SVN Revision: 2529
This commit is contained in:
parent
ca403c25e7
commit
3909f95ac1
@ -104,7 +104,8 @@
|
||||
string_to_subscription/1,
|
||||
string_to_affiliation/1,
|
||||
extended_error/2,
|
||||
extended_error/3
|
||||
extended_error/3,
|
||||
rename_default_nodeplugin/0
|
||||
]).
|
||||
|
||||
%% API and gen_server callbacks
|
||||
@ -334,11 +335,9 @@ update_node_database(Host, ServerHost) ->
|
||||
end,
|
||||
case mnesia:transaction(FNew) of
|
||||
{atomic, Result} ->
|
||||
?INFO_MSG("Pubsub node tables updated correctly: ~p",
|
||||
[Result]);
|
||||
?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
|
||||
{aborted, Reason} ->
|
||||
?ERROR_MSG("Problem updating Pubsub node tables:~n~p",
|
||||
[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}) ->
|
||||
@ -377,11 +376,10 @@ update_node_database(Host, ServerHost) ->
|
||||
end,
|
||||
case mnesia:transaction(FNew) of
|
||||
{atomic, Result} ->
|
||||
?INFO_MSG("Pubsub node tables updated correctly: ~p",
|
||||
[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])
|
||||
?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}) ->
|
||||
@ -393,11 +391,17 @@ update_node_database(Host, ServerHost) ->
|
||||
owners = Owners,
|
||||
options = Options}
|
||||
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]),
|
||||
rename_default_nodeplugin();
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
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] ->
|
||||
|
@ -105,7 +105,8 @@
|
||||
string_to_affiliation/1,
|
||||
extended_error/2,
|
||||
extended_error/3,
|
||||
escape/1
|
||||
escape/1,
|
||||
rename_default_nodeplugin/0
|
||||
]).
|
||||
|
||||
%% API and gen_server callbacks
|
||||
@ -333,11 +334,9 @@ update_node_database(Host, ServerHost) ->
|
||||
end,
|
||||
case mnesia:transaction(FNew) of
|
||||
{atomic, Result} ->
|
||||
?INFO_MSG("Pubsub node tables updated correctly: ~p",
|
||||
[Result]);
|
||||
?INFO_MSG("Pubsub node tables updated correctly: ~p", [Result]);
|
||||
{aborted, Reason} ->
|
||||
?ERROR_MSG("Problem updating Pubsub node tables:~n~p",
|
||||
[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}) ->
|
||||
@ -376,11 +375,10 @@ update_node_database(Host, ServerHost) ->
|
||||
end,
|
||||
case mnesia:transaction(FNew) of
|
||||
{atomic, Result} ->
|
||||
?INFO_MSG("Pubsub node tables updated correctly: ~p",
|
||||
[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])
|
||||
?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}) ->
|
||||
@ -392,11 +390,18 @@ update_node_database(Host, ServerHost) ->
|
||||
owners = Owners,
|
||||
options = Options}
|
||||
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]),
|
||||
rename_default_nodeplugin();
|
||||
_ ->
|
||||
ok
|
||||
end.
|
||||
|
||||
rename_default_nodeplugin() ->
|
||||
% lists:foreach(fun(Node) ->
|
||||
% mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
|
||||
% end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
|
||||
ok.
|
||||
|
||||
update_state_database(_Host, _ServerHost) ->
|
||||
case catch mnesia:table_info(pubsub_state, attributes) of
|
||||
[stateid, items, affiliation, subscription] ->
|
||||
@ -2669,16 +2674,23 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
|
||||
{error, ?ERR_BAD_REQUEST};
|
||||
_ ->
|
||||
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||
case lists:member(Owner, node_owners_call(Type, NodeId)) of
|
||||
true ->
|
||||
lists:foreach(fun({JID, Subscription, SubId}) ->
|
||||
node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
|
||||
end, Entities),
|
||||
{result, []};
|
||||
_ ->
|
||||
{error, ?ERR_FORBIDDEN}
|
||||
end
|
||||
end,
|
||||
case lists:member(Owner, node_owners_call(Type, NodeId)) of
|
||||
true ->
|
||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||
|
||||
case node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) of
|
||||
{error, Err} -> [{error, Err} | Acc];
|
||||
_ -> Acc
|
||||
end
|
||||
end, [], Entities),
|
||||
case Result of
|
||||
[] -> {result, []};
|
||||
_ -> {error, ?ERR_NOT_ACCEPTABLE}
|
||||
end;
|
||||
_ ->
|
||||
{error, ?ERR_FORBIDDEN}
|
||||
end
|
||||
end,
|
||||
case transaction(Host, Node, Action, sync_dirty) of
|
||||
{result, {_, Result}} -> {result, Result};
|
||||
Other -> Other
|
||||
|
@ -1,5 +1,5 @@
|
||||
--- mod_pubsub.erl 2009-08-20 17:49:22.000000000 +0200
|
||||
+++ mod_pubsub_odbc.erl 2009-08-21 13:53:33.000000000 +0200
|
||||
--- mod_pubsub.erl 2009-08-25 16:10:58.000000000 +0200
|
||||
+++ mod_pubsub_odbc.erl 2009-08-25 16:12:30.000000000 +0200
|
||||
@@ -45,7 +45,7 @@
|
||||
%%% TODO
|
||||
%%% plugin: generate Reply (do not use broadcast atom anymore)
|
||||
@ -22,17 +22,15 @@
|
||||
|
||||
%% exports for hooks
|
||||
-export([presence_probe/3,
|
||||
@@ -104,7 +104,8 @@
|
||||
string_to_subscription/1,
|
||||
@@ -105,6 +105,7 @@
|
||||
string_to_affiliation/1,
|
||||
extended_error/2,
|
||||
- extended_error/3
|
||||
+ extended_error/3,
|
||||
+ escape/1
|
||||
extended_error/3,
|
||||
+ escape/1,
|
||||
rename_default_nodeplugin/0
|
||||
]).
|
||||
|
||||
%% API and gen_server callbacks
|
||||
@@ -123,7 +124,7 @@
|
||||
@@ -124,7 +125,7 @@
|
||||
-export([send_loop/1
|
||||
]).
|
||||
|
||||
@ -41,7 +39,7 @@
|
||||
-define(PLUGIN_PREFIX, "node_").
|
||||
-define(TREE_PREFIX, "nodetree_").
|
||||
|
||||
@@ -212,8 +213,6 @@
|
||||
@@ -213,8 +214,6 @@
|
||||
ok
|
||||
end,
|
||||
ejabberd_router:register_route(Host),
|
||||
@ -50,7 +48,21 @@
|
||||
init_nodes(Host, ServerHost),
|
||||
State = #state{host = Host,
|
||||
server_host = ServerHost,
|
||||
@@ -459,17 +458,15 @@
|
||||
@@ -398,9 +397,10 @@
|
||||
end.
|
||||
|
||||
rename_default_nodeplugin() ->
|
||||
- lists:foreach(fun(Node) ->
|
||||
- mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
|
||||
- end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
|
||||
+% lists:foreach(fun(Node) ->
|
||||
+% mnesia:dirty_write(Node#pubsub_node{type = "hometree"})
|
||||
+% end, mnesia:dirty_match_object(#pubsub_node{type = "default", _ = '_'})).
|
||||
+ ok.
|
||||
|
||||
update_state_database(_Host, _ServerHost) ->
|
||||
case catch mnesia:table_info(pubsub_state, attributes) of
|
||||
@@ -463,17 +463,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 +86,7 @@
|
||||
true ->
|
||||
% resource not concerned about that subscription
|
||||
ok
|
||||
@@ -792,10 +789,10 @@
|
||||
@@ -796,10 +794,10 @@
|
||||
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]),
|
||||
lists:foreach(fun
|
||||
({Node, subscribed, _, JID}) ->
|
||||
@ -87,7 +99,7 @@
|
||||
true ->
|
||||
node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]);
|
||||
false ->
|
||||
@@ -909,7 +906,8 @@
|
||||
@@ -913,7 +911,8 @@
|
||||
sub_el = SubEl} = IQ ->
|
||||
{xmlelement, _, QAttrs, _} = SubEl,
|
||||
Node = xml:get_attr_s("node", QAttrs),
|
||||
@ -97,7 +109,7 @@
|
||||
{result, IQRes} ->
|
||||
jlib:iq_to_xml(
|
||||
IQ#iq{type = result,
|
||||
@@ -1014,7 +1012,7 @@
|
||||
@@ -1018,7 +1017,7 @@
|
||||
[] ->
|
||||
["leaf"]; %% No sub-nodes: it's a leaf node
|
||||
_ ->
|
||||
@ -106,7 +118,7 @@
|
||||
{result, []} -> ["collection"];
|
||||
{result, _} -> ["leaf", "collection"];
|
||||
_ -> []
|
||||
@@ -1030,8 +1028,9 @@
|
||||
@@ -1034,8 +1033,9 @@
|
||||
[];
|
||||
true ->
|
||||
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
|
||||
@ -118,7 +130,7 @@
|
||||
end, features(Type))]
|
||||
end,
|
||||
%% TODO: add meta-data info (spec section 5.4)
|
||||
@@ -1059,14 +1058,15 @@
|
||||
@@ -1063,14 +1063,15 @@
|
||||
{xmlelement, "feature", [{"var", ?NS_DISCO_ITEMS}], []},
|
||||
{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []},
|
||||
{xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++
|
||||
@ -137,7 +149,7 @@
|
||||
{result, lists:map(
|
||||
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
||||
SN = node_to_string(SubNode),
|
||||
@@ -1076,7 +1076,7 @@
|
||||
@@ -1080,7 +1081,7 @@
|
||||
{"node", SN},
|
||||
{"name", RN}], []}
|
||||
end, tree_action(Host, get_subnodes, [Host, [], From]))};
|
||||
@ -146,7 +158,7 @@
|
||||
case string:tokens(Item, "!") of
|
||||
[_SNode, _ItemID] ->
|
||||
{result, []};
|
||||
@@ -1088,9 +1088,9 @@
|
||||
@@ -1092,9 +1093,9 @@
|
||||
%% TODO That is, remove name attribute (or node?, please check for 2.1)
|
||||
Action =
|
||||
fun(#pubsub_node{type = Type, id = NodeId}) ->
|
||||
@ -158,7 +170,7 @@
|
||||
end,
|
||||
Nodes = lists:map(
|
||||
fun(#pubsub_node{nodeid = {_, SubNode}}) ->
|
||||
@@ -1106,7 +1106,7 @@
|
||||
@@ -1110,7 +1111,7 @@
|
||||
{xmlelement, "item", [{"jid", Host}, {"node", SN},
|
||||
{"name", Name}], []}
|
||||
end, NodeItems),
|
||||
@ -167,7 +179,7 @@
|
||||
end,
|
||||
case transaction(Host, Node, Action, sync_dirty) of
|
||||
{result, {_, Result}} -> {result, Result};
|
||||
@@ -1238,7 +1238,8 @@
|
||||
@@ -1242,7 +1243,8 @@
|
||||
(_, Acc) ->
|
||||
Acc
|
||||
end, [], xml:remove_cdata(Els)),
|
||||
@ -177,7 +189,7 @@
|
||||
{get, "subscriptions"} ->
|
||||
get_subscriptions(Host, Node, From, Plugins);
|
||||
{get, "affiliations"} ->
|
||||
@@ -1261,7 +1262,10 @@
|
||||
@@ -1265,7 +1267,10 @@
|
||||
|
||||
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
|
||||
{xmlelement, _, _, SubEls} = SubEl,
|
||||
@ -189,7 +201,7 @@
|
||||
case Action of
|
||||
[{xmlelement, Name, Attrs, Els}] ->
|
||||
Node = case Host of
|
||||
@@ -1387,7 +1391,8 @@
|
||||
@@ -1391,7 +1396,8 @@
|
||||
_ -> []
|
||||
end
|
||||
end,
|
||||
@ -199,7 +211,7 @@
|
||||
sync_dirty) of
|
||||
{result, Res} -> Res;
|
||||
Err -> Err
|
||||
@@ -1431,7 +1436,7 @@
|
||||
@@ -1435,7 +1441,7 @@
|
||||
|
||||
%%% authorization handling
|
||||
|
||||
@ -208,7 +220,7 @@
|
||||
Lang = "en", %% TODO fix
|
||||
Stanza = {xmlelement, "message",
|
||||
[],
|
||||
@@ -1460,7 +1465,7 @@
|
||||
@@ -1464,7 +1470,7 @@
|
||||
[{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]},
|
||||
lists:foreach(fun(Owner) ->
|
||||
ejabberd_router ! {route, service_jid(Host), jlib:make_jid(Owner), Stanza}
|
||||
@ -217,7 +229,7 @@
|
||||
|
||||
find_authorization_response(Packet) ->
|
||||
{xmlelement, _Name, _Attrs, Els} = Packet,
|
||||
@@ -1527,8 +1532,8 @@
|
||||
@@ -1531,8 +1537,8 @@
|
||||
"true" -> true;
|
||||
_ -> false
|
||||
end,
|
||||
@ -228,7 +240,7 @@
|
||||
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
|
||||
if
|
||||
not IsApprover ->
|
||||
@@ -1714,7 +1719,7 @@
|
||||
@@ -1718,7 +1724,7 @@
|
||||
Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||
[{xmlelement, "create", nodeAttr(Node),
|
||||
[]}]}],
|
||||
@ -237,7 +249,7 @@
|
||||
{result, {Result, broadcast}} ->
|
||||
%%Lang = "en", %% TODO: fix
|
||||
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
|
||||
@@ -1826,7 +1831,7 @@
|
||||
@@ -1830,7 +1836,7 @@
|
||||
error -> {"", "", ""};
|
||||
J -> jlib:jid_tolower(J)
|
||||
end,
|
||||
@ -246,7 +258,7 @@
|
||||
Features = features(Type),
|
||||
SubscribeFeature = lists:member("subscribe", Features),
|
||||
OptionsFeature = lists:member("subscription-options", Features),
|
||||
@@ -1845,9 +1850,13 @@
|
||||
@@ -1849,9 +1855,13 @@
|
||||
{"", "", ""} ->
|
||||
{false, false};
|
||||
_ ->
|
||||
@ -263,7 +275,7 @@
|
||||
end
|
||||
end,
|
||||
if
|
||||
@@ -2170,7 +2179,7 @@
|
||||
@@ -2174,7 +2184,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 +284,7 @@
|
||||
MaxItems =
|
||||
if
|
||||
SMaxItems == "" -> ?MAXITEMS;
|
||||
@@ -2209,11 +2218,11 @@
|
||||
@@ -2213,11 +2223,11 @@
|
||||
node_call(Type, get_items,
|
||||
[NodeId, From,
|
||||
AccessModel, PresenceSubscription, RosterGroup,
|
||||
@ -286,7 +298,7 @@
|
||||
SendItems = case ItemIDs of
|
||||
[] ->
|
||||
Items;
|
||||
@@ -2226,7 +2235,8 @@
|
||||
@@ -2230,7 +2240,8 @@
|
||||
%% number of items sent to MaxItems:
|
||||
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
|
||||
[{xmlelement, "items", nodeAttr(Node),
|
||||
@ -296,7 +308,7 @@
|
||||
Error ->
|
||||
Error
|
||||
end
|
||||
@@ -2258,15 +2268,22 @@
|
||||
@@ -2262,15 +2273,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 +337,7 @@
|
||||
send_items(Host, Node, NodeId, Type, LJID, Number) ->
|
||||
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
|
||||
{result, []} ->
|
||||
@@ -2384,29 +2401,12 @@
|
||||
@@ -2388,29 +2406,12 @@
|
||||
error ->
|
||||
{error, ?ERR_BAD_REQUEST};
|
||||
_ ->
|
||||
@ -358,18 +370,18 @@
|
||||
end, Entities),
|
||||
{result, []};
|
||||
_ ->
|
||||
@@ -2668,8 +2668,8 @@
|
||||
@@ -2672,8 +2673,8 @@
|
||||
error ->
|
||||
{error, ?ERR_BAD_REQUEST};
|
||||
_ ->
|
||||
- Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
|
||||
- case lists:member(Owner, Owners) of
|
||||
- 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, Subscription, SubId}) ->
|
||||
node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
|
||||
@@ -3159,6 +3159,30 @@
|
||||
+ case lists:member(Owner, node_owners_call(Type, NodeId)) of
|
||||
true ->
|
||||
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
|
||||
|
||||
@@ -3170,6 +3171,30 @@
|
||||
Result
|
||||
end.
|
||||
|
||||
@ -400,7 +412,7 @@
|
||||
%% @spec (Host, Options) -> MaxItems
|
||||
%% Host = host()
|
||||
%% Options = [Option]
|
||||
@@ -3532,7 +3556,13 @@
|
||||
@@ -3543,7 +3568,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 +427,7 @@
|
||||
|
||||
%% @doc <p>node plugin call.</p>
|
||||
node_call(Type, Function, Args) ->
|
||||
@@ -3552,13 +3582,13 @@
|
||||
@@ -3563,13 +3594,13 @@
|
||||
|
||||
node_action(Host, Type, Function, Args) ->
|
||||
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
|
||||
@ -431,7 +443,7 @@
|
||||
case tree_call(Host, get_node, [Host, Node]) of
|
||||
N when is_record(N, pubsub_node) ->
|
||||
case Action(N) of
|
||||
@@ -3571,8 +3601,14 @@
|
||||
@@ -3582,8 +3613,14 @@
|
||||
end
|
||||
end, Trans).
|
||||
|
||||
@ -448,7 +460,7 @@
|
||||
{result, Result} -> {result, Result};
|
||||
{error, Error} -> {error, Error};
|
||||
{atomic, {result, Result}} -> {result, Result};
|
||||
@@ -3580,6 +3616,15 @@
|
||||
@@ -3591,6 +3628,15 @@
|
||||
{aborted, Reason} ->
|
||||
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
@ -464,7 +476,7 @@
|
||||
{'EXIT', Reason} ->
|
||||
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
||||
@@ -3588,6 +3633,17 @@
|
||||
@@ -3599,6 +3645,17 @@
|
||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user