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
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}) ->
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}) ->
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] ->
string_to_affiliation/1,
extended_error/2,
extended_error/3,
- escape/1
+ escape/1,
+ rename_default_nodeplugin/0
]).
%% API and gen_server callbacks
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}) ->
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}) ->
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] ->
{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
---- 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)
%% 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
]).
-define(PLUGIN_PREFIX, "node_").
-define(TREE_PREFIX, "nodetree_").
-@@ -212,8 +213,6 @@
+@@ -213,8 +214,6 @@
ok
end,
ejabberd_router:register_route(Host),
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) ->
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}) ->
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),
{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
_ ->
{result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"];
_ -> []
-@@ -1030,8 +1028,9 @@
+@@ -1034,8 +1033,9 @@
[];
true ->
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
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}], []}] ++
{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]))};
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}) ->
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),
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)),
{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,
case Action of
[{xmlelement, Name, Attrs, Els}] ->
Node = case Host of
-@@ -1387,7 +1391,8 @@
+@@ -1391,7 +1396,8 @@
_ -> []
end
end,
sync_dirty) of
{result, Res} -> Res;
Err -> Err
-@@ -1431,7 +1436,7 @@
+@@ -1435,7 +1441,7 @@
%%% authorization handling
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}
find_authorization_response(Packet) ->
{xmlelement, _Name, _Attrs, Els} = Packet,
-@@ -1527,8 +1532,8 @@
+@@ -1531,8 +1537,8 @@
"true" -> true;
_ -> false
end,
{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),
[]}]}],
{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,
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
-@@ -1845,9 +1850,13 @@
+@@ -1849,9 +1855,13 @@
{"", "", ""} ->
{false, false};
_ ->
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.
MaxItems =
if
SMaxItems == "" -> ?MAXITEMS;
-@@ -2209,11 +2218,11 @@
+@@ -2213,11 +2223,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
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),
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) ->
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};
_ ->
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.
%% @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,
%% @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]),
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).
{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};
{'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.