{get, "subscriptions"} ->
get_subscriptions(Host, Node, From, Plugins);
{get, "affiliations"} ->
- get_affiliations(Host, From, Plugins);
+ get_affiliations(Host, Node, From, Plugins);
{get, "options"} ->
SubID = xml:get_attr_s("subid", Attrs),
JID = xml:get_attr_s("jid", Attrs),
%% Reason = stanzaError()
%% Response = [pubsubIQResponse()]
%% @doc <p>Return the list of affiliations as an XMPP response.</p>
-get_affiliations(Host, JID, Plugins) when is_list(Plugins) ->
+get_affiliations(Host, <<>>, JID, Plugins) when is_list(Plugins) ->
Result = lists:foldl(
fun(Type, {Status, Acc}) ->
Features = features(Type),
{Error, _} ->
Error
end;
+get_affiliations(Host, NodeId, JID, Plugins) when is_list(Plugins) ->
+ Result = lists:foldl(
+ fun(Type, {Status, Acc}) ->
+ Features = features(Type),
+ RetrieveFeature = lists:member("retrieve-affiliations", Features),
+ if
+ not RetrieveFeature ->
+ %% Service does not support retreive affiliatons
+ {{error, extended_error(?ERR_FEATURE_NOT_IMPLEMENTED, unsupported, "retrieve-affiliations")}, Acc};
+ true ->
+ {result, Affiliations} = node_action(Host, Type, get_entity_affiliations, [Host, JID]),
+ {Status, [Affiliations|Acc]}
+ end
+ end, {ok, []}, Plugins),
+ case Result of
+ {ok, Affiliations} ->
+ Entities = lists:flatmap(
+ fun({_, none}) -> [];
+ ({#pubsub_node{nodeid = {_, Node}}, Affiliation})
+ when NodeId == Node ->
+ [{xmlelement, "affiliation",
+ [{"affiliation", affiliation_to_string(Affiliation)}|nodeAttr(Node)],
+ []}];
+ (_) ->
+ []
+ end, lists:usort(lists:flatten(Affiliations))),
+ {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
+ [{xmlelement, "affiliations", [],
+ Entities}]}]};
+ {Error, _} ->
+ Error
+ end.
+
+
get_affiliations(Host, Node, JID) ->
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
Features = features(Type),
{get, "subscriptions"} ->
get_subscriptions(Host, Node, From, Plugins);
{get, "affiliations"} ->
- get_affiliations(Host, From, Plugins);
+ get_affiliations(Host, Node, From, Plugins);
{get, "options"} ->
SubID = xml:get_attr_s("subid", Attrs),
JID = xml:get_attr_s("jid", Attrs),
%% Reason = stanzaError()
%% Response = [pubsubIQResponse()]
%% @doc <p>Return the list of affiliations as an XMPP response.</p>
-get_affiliations(Host, JID, Plugins) when is_list(Plugins) ->
+get_affiliations(Host, <<>>, JID, Plugins) when is_list(Plugins) ->
Result = lists:foldl(
fun(Type, {Status, Acc}) ->
Features = features(Type),
{Error, _} ->
Error
end;
+get_affiliations(Host, NodeId, JID, Plugins) when is_list(Plugins) ->
+ Result = lists:foldl(
+ fun(Type, {Status, Acc}) ->
+ Features = features(Type),
+ RetrieveFeature = lists:member("retrieve-affiliations", Features),
+ if
+ not RetrieveFeature ->
+ %% Service does not support retreive affiliatons
+ {{error, extended_error(?ERR_FEATURE_NOT_IMPLEMENTED, unsupported, "retrieve-affiliations")}, Acc};
+ true ->
+ {result, Affiliations} = node_action(Host, Type, get_entity_affiliations, [Host, JID]),
+ {Status, [Affiliations|Acc]}
+ end
+ end, {ok, []}, Plugins),
+ case Result of
+ {ok, Affiliations} ->
+ Entities = lists:flatmap(
+ fun({_, none}) -> [];
+ ({#pubsub_node{nodeid = {_, Node}}, Affiliation})
+ when NodeId == Node ->
+ [{xmlelement, "affiliation",
+ [{"affiliation", affiliation_to_string(Affiliation)}|nodeAttr(Node)],
+ []}];
+ (_) ->
+ []
+ end, lists:usort(lists:flatten(Affiliations))),
+ {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}],
+ [{xmlelement, "affiliations", [],
+ Entities}]}]};
+ {Error, _} ->
+ Error
+ end.
+
+
get_affiliations(Host, Node, JID) ->
Action = fun(#pubsub_node{type = Type, id = NodeId}) ->
Features = features(Type),
---- mod_pubsub.erl 2011-11-29 14:10:41.000000000 +0100
-+++ mod_pubsub_odbc.erl 2011-11-29 14:12:01.000000000 +0100
+--- mod_pubsub.erl 2012-04-11 16:47:33.620900390 +0200
++++ mod_pubsub_odbc.erl 2012-04-11 16:47:53.390899087 +0200
@@ -42,7 +42,7 @@
%%% 6.2.3.1, 6.2.3.5, and 6.3. For information on subscription leases see
%%% XEP-0060 section 12.18.
%% @spec (Host, JID, Plugins) -> {error, Reason} | {result, Response}
%% Host = host()
-@@ -2506,7 +2311,8 @@
+@@ -2540,7 +2345,8 @@
error ->
{error, ?ERR_BAD_REQUEST};
_ ->
case lists:member(Owner, Owners) of
true ->
OwnerJID = jlib:make_jid(Owner),
-@@ -2516,24 +2322,7 @@
+@@ -2550,24 +2356,7 @@
end,
lists:foreach(
fun({JID, Affiliation}) ->
end, FilteredEntities),
{result, []};
_ ->
-@@ -2586,11 +2375,11 @@
+@@ -2620,11 +2409,11 @@
end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
OptionsEl = {xmlelement, "options", [{"jid", jlib:jid_to_string(Subscriber)},
{"subid", SubID}|nodeAttr(Node)],
[XdataEl]},
-@@ -2616,7 +2405,7 @@
+@@ -2650,7 +2439,7 @@
end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
-@@ -2645,7 +2434,7 @@
+@@ -2679,7 +2468,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error(?ERR_BAD_REQUEST, "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) ->
{error, notfound} ->
{error, extended_error(?ERR_NOT_ACCEPTABLE, "invalid-subid")};
{result, _} ->
-@@ -2813,8 +2602,8 @@
+@@ -2847,8 +2636,8 @@
{"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]},
ejabberd_router:route(service_jid(Host), jlib:make_jid(JID), Stanza)
end,
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
-@@ -3169,7 +2958,7 @@
+@@ -3203,7 +2992,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
{result, CollSubs} -> CollSubs;
_ -> []
end.
-@@ -3183,9 +2972,9 @@
+@@ -3217,9 +3006,9 @@
get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
_ -> Acc
end;
(_, Acc) ->
-@@ -3374,6 +3163,30 @@
+@@ -3408,6 +3197,30 @@
Result
end.
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
-@@ -3770,7 +3583,13 @@
+@@ -3804,7 +3617,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) ->
-@@ -3790,13 +3609,13 @@
+@@ -3824,13 +3643,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
-@@ -3808,13 +3627,19 @@
+@@ -3842,13 +3661,19 @@
Error
end
end, Trans).
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
-@@ -3822,6 +3647,15 @@
+@@ -3856,6 +3681,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};
-@@ -3830,6 +3664,17 @@
+@@ -3864,6 +3698,17 @@
{error, ?ERR_INTERNAL_SERVER_ERROR}
end.