24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-24 22:25:47 +02:00

add pubsub#purge_offline (EJAB-1186) (thanks karim)

This commit is contained in:
Christophe Romain 2010-03-05 16:09:06 +01:00
parent 3c36cd64e3
commit fe40651b0d
16 changed files with 210 additions and 58 deletions

View File

@ -63,6 +63,7 @@
-export([presence_probe/3,
in_subscription/6,
out_subscription/4,
on_user_offline/3,
remove_user/2,
feature_check_packet/6,
disco_local_identity/5,
@ -200,6 +201,7 @@ init([ServerHost, Opts]) ->
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
ejabberd_hooks:add(sm_remove_connection_hook, ServerHostB, ?MODULE, on_user_offline, 75),
ejabberd_hooks:add(disco_sm_identity, ServerHostB, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:add(disco_sm_features, ServerHostB, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHostB, ?MODULE, disco_sm_items, 75),
@ -876,6 +878,7 @@ terminate(_Reason, #state{host = Host,
false ->
ok
end,
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHostB, ?MODULE, on_user_offline, 75),
ejabberd_hooks:delete(disco_local_identity, ServerHostB, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:delete(disco_local_features, ServerHostB, ?MODULE, disco_local_features, 75),
ejabberd_hooks:delete(disco_local_items, ServerHostB, ?MODULE, disco_local_items, 75),
@ -3390,6 +3393,7 @@ get_configure_xfields(_Type, Options, Lang, Groups) ->
?LISTM_CONFIG_FIELD("Roster groups allowed to subscribe", roster_groups_allowed, Groups),
?ALIST_CONFIG_FIELD("Specify the publisher model", publish_model,
[publishers, subscribers, open]),
?BOOL_CONFIG_FIELD("Purge all items when the relevant publisher goes offline", purge_offline),
?ALIST_CONFIG_FIELD("Specify the event message type", notification_type,
[headline, normal]),
?INTEGER_CONFIG_FIELD("Max payload size in bytes", max_payload_size),
@ -3533,6 +3537,8 @@ set_xoption(Host, [{"pubsub#send_last_published_item", [Val]} | Opts], NewOpts)
?SET_ALIST_XOPT(send_last_published_item, Val, [never, on_sub, on_sub_and_presence]);
set_xoption(Host, [{"pubsub#presence_based_delivery", [Val]} | Opts], NewOpts) ->
?SET_BOOL_XOPT(presence_based_delivery, Val);
set_xoption(Host, [{"pubsub#purge_offline", [Val]} | Opts], NewOpts) ->
?SET_BOOL_XOPT(purge_offline, Val);
set_xoption(Host, [{"pubsub#title", Value} | Opts], NewOpts) ->
?SET_STRING_XOPT(title, Value);
set_xoption(Host, [{"pubsub#type", Value} | Opts], NewOpts) ->
@ -3866,3 +3872,68 @@ is_feature_supported({xmlelement, "presence", _, Els}, Feature) ->
nothing -> false;
Caps -> lists:member(Feature ++ "+notify", mod_caps:get_features(Caps))
end.
on_user_offline(_, JID, _) ->
{User, Server, Resource} = jlib:short_prepd_jid(JID),
case ejabberd_sm:get_user_resources(User, Server) of
[] -> purge_offline({User, Server, Resource});
_ -> true
end.
purge_offline({User, Server, _} = LJID) ->
Host = host(Server),
Plugins = plugins(Host),
Result = lists:foldl(
fun(Type, {Status, Acc}) ->
case lists:member("retrieve-affiliations", features(Type)) of
false ->
{{error, extended_error('feature-not-implemented', unsupported, "retrieve-affiliations")}, Acc};
true ->
{result, Affiliations} = node_action(Host, Type, get_entity_affiliations, [Host, LJID]),
{Status, [Affiliations|Acc]}
end
end, {ok, []}, Plugins),
case Result of
{ok, Affiliations} ->
lists:foreach(
fun({#pubsub_node{nodeid = {_, NodeId}, options = Options, type = Type}, Affiliation})
when Affiliation == 'owner' orelse Affiliation == 'publisher' ->
Action = fun(#pubsub_node{type = NType, id = NodeIdx}) ->
node_call(NType, get_items, [NodeIdx, service_jid(Host)])
end,
case transaction(Host, NodeId, Action, sync_dirty) of
{result, {_, []}} ->
true;
{result, {_, Items}} ->
Features = features(Type),
case
{lists:member("retract-items", Features),
lists:member("persistent-items", Features),
get_option(Options, persist_items),
get_option(Options, purge_offline)}
of
{true, true, true, true} ->
ForceNotify = get_option(Options, notify_retract),
lists:foreach(
fun(#pubsub_item{itemid = {ItemId, _}, modification = {_, Modification}}) ->
case Modification of
{User, Server, _} ->
delete_item(Host, NodeId, LJID, ItemId, ForceNotify);
_ ->
true
end;
(_) ->
true
end, Items);
_ ->
true
end;
Error ->
Error
end;
(_) ->
true
end, lists:usort(lists:flatten(Affiliations)));
{Error, _} ->
?DEBUG("on_user_offline ~p", [Error])
end.

View File

@ -63,6 +63,7 @@
-export([presence_probe/3,
in_subscription/6,
out_subscription/4,
on_user_offline/3,
remove_user/2,
feature_check_packet/6,
disco_local_identity/5,
@ -200,6 +201,7 @@ init([ServerHost, Opts]) ->
ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {ignore_pep_from_offline, PepOffline}),
ets:insert(gen_mod:get_module_proc(ServerHost, config), {host, Host}),
ejabberd_hooks:add(sm_remove_connection_hook, ServerHostB, ?MODULE, on_user_offline, 75),
ejabberd_hooks:add(disco_sm_identity, ServerHostB, ?MODULE, disco_sm_identity, 75),
ejabberd_hooks:add(disco_sm_features, ServerHostB, ?MODULE, disco_sm_features, 75),
ejabberd_hooks:add(disco_sm_items, ServerHostB, ?MODULE, disco_sm_items, 75),
@ -681,6 +683,7 @@ terminate(_Reason, #state{host = Host,
false ->
ok
end,
ejabberd_hooks:delete(sm_remove_connection_hook, ServerHostB, ?MODULE, on_user_offline, 75),
ejabberd_hooks:delete(disco_local_identity, ServerHostB, ?MODULE, disco_local_identity, 75),
ejabberd_hooks:delete(disco_local_features, ServerHostB, ?MODULE, disco_local_features, 75),
ejabberd_hooks:delete(disco_local_items, ServerHostB, ?MODULE, disco_local_items, 75),
@ -3225,6 +3228,7 @@ get_configure_xfields(_Type, Options, Lang, Groups) ->
?LISTM_CONFIG_FIELD("Roster groups allowed to subscribe", roster_groups_allowed, Groups),
?ALIST_CONFIG_FIELD("Specify the publisher model", publish_model,
[publishers, subscribers, open]),
?BOOL_CONFIG_FIELD("Purge all items when the relevant publisher goes offline", purge_offline),
?ALIST_CONFIG_FIELD("Specify the event message type", notification_type,
[headline, normal]),
?INTEGER_CONFIG_FIELD("Max payload size in bytes", max_payload_size),
@ -3368,6 +3372,8 @@ set_xoption(Host, [{"pubsub#send_last_published_item", [Val]} | Opts], NewOpts)
?SET_ALIST_XOPT(send_last_published_item, Val, [never, on_sub, on_sub_and_presence]);
set_xoption(Host, [{"pubsub#presence_based_delivery", [Val]} | Opts], NewOpts) ->
?SET_BOOL_XOPT(presence_based_delivery, Val);
set_xoption(Host, [{"pubsub#purge_offline", [Val]} | Opts], NewOpts) ->
?SET_BOOL_XOPT(purge_offline, Val);
set_xoption(Host, [{"pubsub#title", Value} | Opts], NewOpts) ->
?SET_STRING_XOPT(title, Value);
set_xoption(Host, [{"pubsub#type", Value} | Opts], NewOpts) ->
@ -3733,3 +3739,68 @@ is_feature_supported({xmlelement, "presence", _, Els}, Feature) ->
nothing -> false;
Caps -> lists:member(Feature ++ "+notify", mod_caps:get_features(Caps))
end.
on_user_offline(_, JID, _) ->
{User, Server, Resource} = jlib:short_prepd_jid(JID),
case ejabberd_sm:get_user_resources(User, Server) of
[] -> purge_offline({User, Server, Resource});
_ -> true
end.
purge_offline({User, Server, _} = LJID) ->
Host = host(Server),
Plugins = plugins(Host),
Result = lists:foldl(
fun(Type, {Status, Acc}) ->
case lists:member("retrieve-affiliations", features(Type)) of
false ->
{{error, extended_error('feature-not-implemented', unsupported, "retrieve-affiliations")}, Acc};
true ->
{result, Affiliations} = node_action(Host, Type, get_entity_affiliations, [Host, LJID]),
{Status, [Affiliations|Acc]}
end
end, {ok, []}, Plugins),
case Result of
{ok, Affiliations} ->
lists:foreach(
fun({#pubsub_node{nodeid = {_, NodeId}, options = Options, type = Type}, Affiliation})
when Affiliation == 'owner' orelse Affiliation == 'publisher' ->
Action = fun(#pubsub_node{type = NType, id = NodeIdx}) ->
node_call(NType, get_items, [NodeIdx, service_jid(Host)])
end,
case transaction(Host, NodeId, Action, sync_dirty) of
{result, {_, []}} ->
true;
{result, {_, Items}} ->
Features = features(Type),
case
{lists:member("retract-items", Features),
lists:member("persistent-items", Features),
get_option(Options, persist_items),
get_option(Options, purge_offline)}
of
{true, true, true, true} ->
ForceNotify = get_option(Options, notify_retract),
lists:foreach(
fun(#pubsub_item{itemid = {ItemId, _}, modification = {_, Modification}}) ->
case Modification of
{User, Server, _} ->
delete_item(Host, NodeId, LJID, ItemId, ForceNotify);
_ ->
true
end;
(_) ->
true
end, Items);
_ ->
true
end;
Error ->
Error
end;
(_) ->
true
end, lists:usort(lists:flatten(Affiliations)));
{Error, _} ->
?DEBUG("on_user_offline ~p", [Error])
end.

View File

@ -80,6 +80,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -86,6 +86,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -85,6 +85,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -83,6 +83,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -76,6 +76,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -77,6 +77,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -139,6 +139,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},
@ -350,9 +351,9 @@ subscribe_node(NodeId, Sender, {U,S,R} = Subscriber, AccessModel,
%% SubId = mod_pubsub:subid()
%% Reason = mod_pubsub:stanzaError()
%% @doc <p>Unsubscribe the <tt>Subscriber</tt> from the <tt>Node</tt>.</p>
unsubscribe_node(NodeId, Sender, {User, Server, Resource} = Subscriber, SubId) ->
SubKey = {User, Server, Resource},
GenKey = {User, Server, undefined},
unsubscribe_node(NodeId, Sender, {U, S, R} = Subscriber, SubId) ->
SubKey = {U, S, R},
GenKey = {U, S, undefined},
Authorized = (jlib:short_prepd_bare_jid(Sender) == GenKey),
GenState = get_state(NodeId, GenKey),
SubState = case SubKey of
@ -382,15 +383,12 @@ unsubscribe_node(NodeId, Sender, {User, Server, Resource} = Subscriber, SubId) -
{error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")};
%% Subid supplied, so use that.
SubIdExists ->
Sub = first_in_list(fun(S) ->
case S of
{_Sub, SubId} -> true;
_ -> false
end
end, SubState#pubsub_state.subscriptions),
Sub = first_in_list(fun({_, Id}) when Id == SubId -> true;
(_) -> false
end, Subscriptions),
case Sub of
{value, S} ->
delete_subscriptions(SubKey, NodeId, [S], SubState),
delete_subscriptions(Subscriber, NodeId, [S], SubState),
{result, default};
false ->
{error, ?ERR_EXTENDED('unexpected-request', "not-subscribed")}

View File

@ -141,6 +141,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -89,6 +89,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, false},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -84,6 +84,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, false},
{purge_offline, false},
{persist_items, false},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -91,6 +91,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, false},
{purge_offline, false},
{persist_items, false},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -86,6 +86,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -87,6 +87,7 @@ options() ->
{notify_config, false},
{notify_delete, false},
{notify_retract, true},
{purge_offline, false},
{persist_items, true},
{max_items, ?MAXITEMS},
{subscribe, true},

View File

@ -1,5 +1,5 @@
--- mod_pubsub.erl 2010-03-05 15:44:11.000000000 +0100
+++ mod_pubsub_odbc.erl 2010-03-05 15:45:00.000000000 +0100
--- mod_pubsub.erl 2010-03-05 16:08:38.000000000 +0100
+++ mod_pubsub_odbc.erl 2010-03-05 16:08:56.000000000 +0100
@@ -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.
@ -22,7 +22,7 @@
%% exports for hooks
-export([presence_probe/3,
@@ -104,7 +104,7 @@
@@ -105,7 +105,7 @@
string_to_affiliation/1,
extended_error/2,
extended_error/3,
@ -31,7 +31,7 @@
]).
%% API and gen_server callbacks
@@ -123,7 +123,7 @@
@@ -124,7 +124,7 @@
-export([send_loop/1
]).
@ -40,7 +40,7 @@
-define(LOOPNAME, ejabberd_mod_pubsub_loop).
-define(PLUGIN_PREFIX, "node_").
-define(TREE_PREFIX, "nodetree_").
@@ -223,8 +223,6 @@
@@ -225,8 +225,6 @@
ok
end,
ejabberd_router:register_route(Host),
@ -49,7 +49,7 @@
init_nodes(Host, ServerHost, NodeTree, Plugins),
State = #state{host = Host,
server_host = ServerHost,
@@ -283,206 +281,15 @@
@@ -285,206 +283,15 @@
init_nodes(Host, ServerHost, _NodeTree, Plugins) ->
%% TODO, this call should be done plugin side
@ -260,7 +260,7 @@
send_loop(State) ->
receive
@@ -494,17 +301,15 @@
@@ -496,17 +303,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) ->
@ -284,7 +284,7 @@
true ->
% resource not concerned about that subscription
ok
@@ -656,8 +461,7 @@
@@ -658,8 +463,7 @@
end;
disco_sm_items(Acc, From, To, NodeB, _Lang) ->
@ -294,7 +294,7 @@
%% TODO, use iq_disco_items(Host, Node, From)
Host = exmpp_jid:prep_domain_as_list(To),
LJID = jlib:short_prepd_bare_jid(To),
@@ -691,6 +495,7 @@
@@ -693,6 +497,7 @@
%% -------
%% presence hooks handling functions
%%
@ -302,7 +302,7 @@
presence_probe(Peer, JID, Pid) ->
case exmpp_jid:full_compare(Peer, JID) of
true -> %% JID are equals
@@ -757,10 +562,10 @@
@@ -759,10 +564,10 @@
lists:foreach(fun(PType) ->
{result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Entity]),
lists:foreach(fun
@ -315,7 +315,7 @@
true ->
node_action(Host, PType, unsubscribe_node, [NodeId, Entity, JID, all]);
false ->
@@ -932,10 +737,11 @@
@@ -935,10 +740,11 @@
end,
ejabberd_router:route(To, From, Res);
#iq{type = get, ns = ?NS_DISCO_ITEMS,
@ -329,7 +329,7 @@
{result, IQRes} ->
Result = #xmlel{ns = ?NS_DISCO_ITEMS,
name = 'query', attrs = QAttrs,
@@ -1055,7 +861,7 @@
@@ -1058,7 +864,7 @@
[] ->
["leaf"]; %% No sub-nodes: it's a leaf node
_ ->
@ -338,7 +338,7 @@
{result, []} -> ["collection"];
{result, _} -> ["leaf", "collection"];
_ -> []
@@ -1071,8 +877,9 @@
@@ -1074,8 +880,9 @@
[];
true ->
[#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]} |
@ -350,7 +350,7 @@
end, features(Type))]
end,
%% TODO: add meta-data info (spec section 5.4)
@@ -1101,8 +908,9 @@
@@ -1104,8 +911,9 @@
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_PUBSUB_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_ADHOC_s)]},
#xmlel{ns = ?NS_DISCO_INFO, name = 'feature', attrs = [?XMLATTR('var', ?NS_VCARD_s)]}] ++
@ -362,7 +362,7 @@
end, features(Host, Node))};
?NS_ADHOC_b ->
command_disco_info(Host, Node, From);
@@ -1112,7 +920,7 @@
@@ -1115,7 +923,7 @@
node_disco_info(Host, Node, From)
end.
@ -371,7 +371,7 @@
case tree_action(Host, get_subnodes, [Host, <<>>, From]) of
Nodes when is_list(Nodes) ->
{result, lists:map(
@@ -1129,7 +937,7 @@
@@ -1132,7 +940,7 @@
Other ->
Other
end;
@ -380,7 +380,7 @@
%% TODO: support localization of this string
CommandItems = [
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item',
@@ -1138,10 +946,10 @@
@@ -1141,10 +949,10 @@
?XMLATTR('name', "Get Pending")
]}],
{result, CommandItems};
@ -393,7 +393,7 @@
case string:tokens(Item, "!") of
[_SNode, _ItemID] ->
{result, []};
@@ -1149,10 +957,10 @@
@@ -1152,10 +960,10 @@
Node = string_to_node(SNode),
Action =
fun(#pubsub_node{type = Type, id = NodeId}) ->
@ -407,7 +407,7 @@
end,
Nodes = lists:map(
fun(#pubsub_node{nodeid = {_, SubNode}, options = Options}) ->
@@ -1168,9 +976,10 @@
@@ -1171,9 +979,10 @@
Items = lists:map(
fun(#pubsub_item{itemid = {RN, _}}) ->
{result, Name} = node_call(Type, get_item_name, [Host, Node, RN]),
@ -420,7 +420,7 @@
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {_, Result}} -> {result, Result};
@@ -1301,7 +1110,8 @@
@@ -1304,7 +1113,8 @@
(_, Acc) ->
Acc
end, [], exmpp_xml:remove_cdata_from_list(Els)),
@ -430,7 +430,7 @@
{get, 'subscriptions'} ->
get_subscriptions(Host, Node, From, Plugins);
{get, 'affiliations'} ->
@@ -1323,8 +1133,9 @@
@@ -1326,8 +1136,9 @@
end.
iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
@ -442,7 +442,7 @@
case Action of
[#xmlel{name = Name, attrs = Attrs, children = Els}] ->
Node = string_to_node(exmpp_xml:get_attribute_from_list_as_list(Attrs, 'node', "")),
@@ -1458,7 +1269,8 @@
@@ -1461,7 +1272,8 @@
_ -> []
end
end,
@ -452,7 +452,7 @@
sync_dirty) of
{result, Res} -> Res;
Err -> Err
@@ -1502,7 +1314,7 @@
@@ -1505,7 +1317,7 @@
%%% authorization handling
@ -461,7 +461,7 @@
Lang = "en", %% TODO fix
{U, S, R} = Subscriber,
Stanza = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', children =
@@ -1532,7 +1344,7 @@
@@ -1535,7 +1347,7 @@
lists:foreach(fun(Owner) ->
{U, S, R} = Owner,
ejabberd_router:route(service_jid(Host), exmpp_jid:make(U, S, R), Stanza)
@ -470,7 +470,7 @@
find_authorization_response(Packet) ->
Els = Packet#xmlel.children,
@@ -1574,7 +1386,7 @@
@@ -1577,7 +1389,7 @@
end,
Stanza = event_stanza(
[#xmlel{ns = ?NS_PUBSUB_EVENT, name = 'subscription', attrs =
@ -479,7 +479,7 @@
}]),
ejabberd_router:route(service_jid(Host), JID, Stanza).
@@ -1585,14 +1397,14 @@
@@ -1588,14 +1400,14 @@
{{value, {_, [SNode]}}, {value, {_, [SSubscriber]}},
{value, {_, [SAllow]}}} ->
Node = string_to_node(SNode),
@ -497,7 +497,7 @@
{result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]),
if
not IsApprover ->
@@ -1787,7 +1599,7 @@
@@ -1790,7 +1602,7 @@
end,
Reply = #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'create', attrs = nodeAttr(Node)}]},
@ -506,7 +506,7 @@
{result, {Result, broadcast}} ->
%%Lang = "en", %% TODO: fix
%%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)),
@@ -1896,7 +1708,7 @@
@@ -1899,7 +1711,7 @@
%%<li>The node does not exist.</li>
%%</ul>
subscribe_node(Host, Node, From, JID, Configuration) ->
@ -515,7 +515,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -1906,7 +1718,7 @@
@@ -1909,7 +1721,7 @@
_:_ ->
{undefined, undefined, undefined}
end,
@ -524,7 +524,7 @@
Features = features(Type),
SubscribeFeature = lists:member("subscribe", Features),
OptionsFeature = lists:member("subscription-options", Features),
@@ -1925,9 +1737,13 @@
@@ -1928,9 +1740,13 @@
{"", "", ""} ->
{false, false};
_ ->
@ -541,7 +541,7 @@
end
end,
if
@@ -2260,7 +2076,7 @@
@@ -2263,7 +2079,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.
@ -550,7 +550,7 @@
MaxItems =
if
SMaxItems == "" -> get_max_items_node(Host);
@@ -2299,11 +2115,11 @@
@@ -2302,11 +2118,11 @@
node_call(Type, get_items,
[NodeId, From,
AccessModel, PresenceSubscription, RosterGroup,
@ -564,7 +564,7 @@
SendItems = case ItemIDs of
[] ->
Items;
@@ -2316,7 +2132,7 @@
@@ -2319,7 +2135,7 @@
%% number of items sent to MaxItems:
{result, #xmlel{ns = ?NS_PUBSUB, name = 'pubsub', children =
[#xmlel{ns = ?NS_PUBSUB, name = 'items', attrs = nodeAttr(Node), children =
@ -573,7 +573,7 @@
Error ->
Error
end
@@ -2348,17 +2164,29 @@
@@ -2351,17 +2167,29 @@
%% @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) ->
@ -610,7 +610,7 @@
send_items(Host, Node, NodeId, Type, {LU, LS, LR} = LJID, Number) ->
ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of
{result, []} ->
@@ -2488,29 +2316,12 @@
@@ -2491,29 +2319,12 @@
error ->
{error, 'bad-request'};
_ ->
@ -643,7 +643,7 @@
end, Entities),
{result, []};
_ ->
@@ -2565,11 +2376,11 @@
@@ -2568,11 +2379,11 @@
end.
read_sub(Subscriber, Node, NodeID, SubID, Lang) ->
@ -657,7 +657,7 @@
OptionsEl = #xmlel{ns = ?NS_PUBSUB, name = 'options',
attrs = [ ?XMLATTR('jid', exmpp_jid:to_binary(Subscriber)),
?XMLATTR('Subid', SubID) | nodeAttr(Node)],
@@ -2596,7 +2407,7 @@
@@ -2599,7 +2410,7 @@
end.
set_options_helper(Configuration, JID, NodeID, SubID, Type) ->
@ -666,7 +666,7 @@
{result, GoodSubOpts} -> GoodSubOpts;
_ -> invalid
end,
@@ -2626,7 +2437,7 @@
@@ -2629,7 +2440,7 @@
write_sub(_Subscriber, _NodeID, _SubID, invalid) ->
{error, extended_error('bad-request', "invalid-options")};
write_sub(Subscriber, NodeID, SubID, Options) ->
@ -675,7 +675,7 @@
{error, notfound} ->
{error, extended_error('not-acceptable', "invalid-subid")};
{result, _} ->
@@ -2799,8 +2610,8 @@
@@ -2802,8 +2613,8 @@
?XMLATTR('subsription', subscription_to_string(Sub)) | nodeAttr(Node)]}]}]},
ejabberd_router:route(service_jid(Host), JID, Stanza)
end,
@ -686,7 +686,7 @@
true ->
Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) ->
@@ -3089,7 +2900,7 @@
@@ -3092,7 +2903,7 @@
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))}
end,
@ -695,7 +695,7 @@
{result, CollSubs} -> CollSubs;
_ -> []
end.
@@ -3103,9 +2914,9 @@
@@ -3106,9 +2917,9 @@
get_options_for_subs(NodeID, Subs) ->
lists:foldl(fun({JID, subscribed, SubID}, Acc) ->
@ -707,7 +707,7 @@
_ -> Acc
end;
(_, Acc) ->
@@ -3113,7 +2924,7 @@
@@ -3116,7 +2927,7 @@
end, [], Subs).
% TODO: merge broadcast code that way
@ -716,7 +716,7 @@
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
% case (get_option(NodeOptions, Feature) or Force) of
% true ->
@@ -3312,6 +3123,30 @@
@@ -3315,6 +3126,30 @@
Result
end.
@ -747,7 +747,7 @@
%% @spec (Host, Options) -> MaxItems
%% Host = host()
%% Options = [Option]
@@ -3707,7 +3542,13 @@
@@ -3713,7 +3548,13 @@
tree_action(Host, Function, Args) ->
?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]),
Fun = fun() -> tree_call(Host, Function, Args) end,
@ -762,7 +762,7 @@
%% @doc <p>node plugin call.</p>
node_call(Type, Function, Args) ->
@@ -3727,13 +3568,13 @@
@@ -3733,13 +3574,13 @@
node_action(Host, Type, Function, Args) ->
?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]),
@ -778,7 +778,7 @@
case tree_call(Host, get_node, [Host, Node]) of
N when is_record(N, pubsub_node) ->
case Action(N) of
@@ -3746,8 +3587,15 @@
@@ -3752,8 +3593,15 @@
end
end, Trans).
@ -796,7 +796,7 @@
{result, Result} -> {result, Result};
{error, Error} -> {error, Error};
{atomic, {result, Result}} -> {result, Result};
@@ -3755,6 +3603,15 @@
@@ -3761,6 +3609,15 @@
{aborted, Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]),
{error, 'internal-server-error'};
@ -812,7 +812,7 @@
{'EXIT', Reason} ->
?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]),
{error, 'internal-server-error'};
@@ -3763,6 +3620,16 @@
@@ -3769,6 +3626,16 @@
{error, 'internal-server-error'}
end.