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) ->
[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(
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),
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,
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} ->
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).
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) ->
---- 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)
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) ->
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}) ->
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),
{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
_ ->
{result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"];
_ -> []
-@@ -1027,8 +1025,9 @@
+@@ -1030,8 +1028,9 @@
[];
true ->
[{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} |
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}], []}] ++
{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]))};
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}) ->
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),
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)),
{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,
case Action of
[{xmlelement, Name, Attrs, Els}] ->
Node = case Host of
-@@ -1384,7 +1388,8 @@
+@@ -1387,7 +1391,8 @@
_ -> []
end
end,
sync_dirty) of
{result, Res} -> Res;
Err -> Err
-@@ -1428,7 +1433,7 @@
+@@ -1431,7 +1436,7 @@
%%% authorization handling
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}
find_authorization_response(Packet) ->
{xmlelement, _Name, _Attrs, Els} = Packet,
-@@ -1524,8 +1529,8 @@
+@@ -1527,8 +1532,8 @@
"true" -> true;
_ -> false
end,
{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),
[]}]}],
{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,
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
-@@ -1842,9 +1847,13 @@
+@@ -1845,9 +1850,13 @@
{"", "", ""} ->
{false, false};
_ ->
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.
MaxItems =
if
SMaxItems == "" -> ?MAXITEMS;
-@@ -2206,11 +2215,11 @@
+@@ -2209,11 +2218,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
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),
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) ->
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};
_ ->
end, Entities),
{result, []};
_ ->
-@@ -2665,8 +2665,8 @@
+@@ -2668,8 +2668,8 @@
error ->
{error, ?ERR_BAD_REQUEST};
_ ->
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.
+ []
+ 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,
%% @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]),
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).
{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};
{'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.