From 8107b2b7dcd95c724b5d2572867173091ab1110f Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Wed, 23 Sep 2009 15:56:06 +0000 Subject: [PATCH] fix EJAB-819 thanks to badlop SVN Revision: 2615 --- doc/guide.tex | 3 + src/mod_pubsub/mod_pubsub.erl | 83 ++++++++++++++++----------- src/mod_pubsub/mod_pubsub_odbc.erl | 83 ++++++++++++++++----------- src/mod_pubsub/node.template | 2 +- src/mod_pubsub/node_buddy.erl | 2 +- src/mod_pubsub/node_club.erl | 2 +- src/mod_pubsub/node_dispatch.erl | 2 +- src/mod_pubsub/node_flat.erl | 2 +- src/mod_pubsub/node_flat_odbc.erl | 2 +- src/mod_pubsub/node_hometree.erl | 2 +- src/mod_pubsub/node_hometree_odbc.erl | 14 ++++- src/mod_pubsub/node_pep.erl | 2 +- src/mod_pubsub/node_pep_odbc.erl | 2 +- src/mod_pubsub/node_private.erl | 2 +- src/mod_pubsub/node_public.erl | 2 +- src/mod_pubsub/pubsub.hrl | 4 +- src/mod_pubsub/pubsub_odbc.patch | 80 +++++++++++++------------- 17 files changed, 165 insertions(+), 124 deletions(-) diff --git a/doc/guide.tex b/doc/guide.tex index 1e99ec763..3aff973ec 100644 --- a/doc/guide.tex +++ b/doc/guide.tex @@ -3538,6 +3538,9 @@ Options: \titem{\{access\_createnode, AccessName\}} \ind{options!access\_createnode} This option restricts which users are allowed to create pubsub nodes using ACL and ACCESS. The default value is \term{pubsub\_createnode}. % Not clear enough + do not use abbreviations. +\titem{\{max\_items\_node, MaxItems\}} \ind{options!max\_items\_node} + Define the maximum number of items that can be stored in a node. + Default value is 10. \titem{\{plugins, [ Plugin, ...]\}} \ind{options!plugins} To specify which pubsub node plugins to use. The first one in the list is used by default. diff --git a/src/mod_pubsub/mod_pubsub.erl b/src/mod_pubsub/mod_pubsub.erl index c2b1b7583..31ffd278e 100644 --- a/src/mod_pubsub/mod_pubsub.erl +++ b/src/mod_pubsub/mod_pubsub.erl @@ -134,6 +134,7 @@ pep_mapping = [], pep_sendlast_offline = false, last_item_cache = false, + max_items_node = ?MAXITEMS, nodetree = ?STDTREE, plugins = [?STDNODE], send_loop}). @@ -179,6 +180,7 @@ init([ServerHost, Opts]) -> PepOffline = gen_mod:get_opt(pep_sendlast_offline, Opts, false), IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue), LastItemCache = gen_mod:get_opt(last_item_cache, Opts, false), + MaxItemsNode = gen_mod:get_opt(max_items_node, Opts, ?MAXITEMS), pubsub_index:init(Host, ServerHost, Opts), ets:new(gen_mod:get_module_proc(Host, config), [set, named_table]), ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]), @@ -189,6 +191,7 @@ init([ServerHost, Opts]) -> ets:insert(gen_mod:get_module_proc(Host, config), {nodetree, NodeTree}), ets:insert(gen_mod:get_module_proc(Host, config), {plugins, Plugins}), ets:insert(gen_mod:get_module_proc(Host, config), {last_item_cache, LastItemCache}), + ets:insert(gen_mod:get_module_proc(Host, config), {max_items_node, MaxItemsNode}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {nodetree, NodeTree}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {plugins, Plugins}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}), @@ -222,6 +225,7 @@ init([ServerHost, Opts]) -> pep_mapping = PepMapping, pep_sendlast_offline = PepOffline, last_item_cache = LastItemCache, + max_items_node = MaxItemsNode, nodetree = NodeTree, plugins = Plugins}, SendLoop = spawn(?MODULE, send_loop, [State]), @@ -1333,7 +1337,7 @@ adhoc_request(Host, _ServerHost, Owner, invalid -> {error, ?ERR_BAD_REQUEST}; XData2 -> - case set_xoption(XData2, []) of + case set_xoption(Host, XData2, []) of NewOpts when is_list(NewOpts) -> {result, NewOpts}; Err -> @@ -1684,7 +1688,7 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -> invalid -> {error, ?ERR_BAD_REQUEST}; XData -> - case set_xoption(XData, node_options(Type)) of + case set_xoption(Host, XData, node_options(Type)) of NewOpts when is_list(NewOpts) -> {result, NewOpts}; Err -> @@ -2176,7 +2180,7 @@ purge_node(Host, Node, Owner) -> get_items(Host, Node, From, SubId, SMaxItems, ItemIDs) -> MaxItems = if - SMaxItems == "" -> ?MAXITEMS; + SMaxItems == "" -> get_max_items_node(Host); true -> case catch list_to_integer(SMaxItems) of {'EXIT', _} -> {error, ?ERR_BAD_REQUEST}; @@ -3307,7 +3311,7 @@ set_configure(Host, Node, From, Els, Lang) -> [] -> node_options(Type); _ -> Options end, - case set_xoption(XData, OldOpts) of + case set_xoption(Host, XData, OldOpts) of NewOpts when is_list(NewOpts) -> case tree_call(Host, set_node, [N#pubsub_node{options = NewOpts}]) of ok -> {result, ok}; @@ -3352,80 +3356,89 @@ add_opt(Key, Value, Opts) -> end, case BoolVal of error -> {error, ?ERR_NOT_ACCEPTABLE}; - _ -> set_xoption(Opts, add_opt(Opt, BoolVal, NewOpts)) + _ -> set_xoption(Host, Opts, add_opt(Opt, BoolVal, NewOpts)) end). -define(SET_STRING_XOPT(Opt, Val), - set_xoption(Opts, add_opt(Opt, Val, NewOpts))). + set_xoption(Host, Opts, add_opt(Opt, Val, NewOpts))). -define(SET_INTEGER_XOPT(Opt, Val, Min, Max), case catch list_to_integer(Val) of IVal when is_integer(IVal), IVal >= Min, IVal =< Max -> - set_xoption(Opts, add_opt(Opt, IVal, NewOpts)); + set_xoption(Host, Opts, add_opt(Opt, IVal, NewOpts)); _ -> {error, ?ERR_NOT_ACCEPTABLE} end). -define(SET_ALIST_XOPT(Opt, Val, Vals), case lists:member(Val, [atom_to_list(V) || V <- Vals]) of - true -> set_xoption(Opts, add_opt(Opt, list_to_atom(Val), NewOpts)); + true -> set_xoption(Host, Opts, add_opt(Opt, list_to_atom(Val), NewOpts)); false -> {error, ?ERR_NOT_ACCEPTABLE} end). -define(SET_LIST_XOPT(Opt, Val), - set_xoption(Opts, add_opt(Opt, Val, NewOpts))). + set_xoption(Host, Opts, add_opt(Opt, Val, NewOpts))). -set_xoption([], NewOpts) -> +set_xoption(_Host, [], NewOpts) -> NewOpts; -set_xoption([{"FORM_TYPE", _} | Opts], NewOpts) -> - set_xoption(Opts, NewOpts); -set_xoption([{"pubsub#roster_groups_allowed", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"FORM_TYPE", _} | Opts], NewOpts) -> + set_xoption(Host, Opts, NewOpts); +set_xoption(Host, [{"pubsub#roster_groups_allowed", Value} | Opts], NewOpts) -> ?SET_LIST_XOPT(roster_groups_allowed, Value); -set_xoption([{"pubsub#deliver_payloads", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#deliver_payloads", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(deliver_payloads, Val); -set_xoption([{"pubsub#deliver_notifications", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#deliver_notifications", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(deliver_notifications, Val); -set_xoption([{"pubsub#notify_config", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#notify_config", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(notify_config, Val); -set_xoption([{"pubsub#notify_delete", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#notify_delete", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(notify_delete, Val); -set_xoption([{"pubsub#notify_retract", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#notify_retract", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(notify_retract, Val); -set_xoption([{"pubsub#persist_items", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#persist_items", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(persist_items, Val); -set_xoption([{"pubsub#max_items", [Val]} | Opts], NewOpts) -> - ?SET_INTEGER_XOPT(max_items, Val, 0, ?MAXITEMS); -set_xoption([{"pubsub#subscribe", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#max_items", [Val]} | Opts], NewOpts) -> + MaxItems = get_max_items_node(Host), + ?SET_INTEGER_XOPT(max_items, Val, 0, MaxItems); +set_xoption(Host, [{"pubsub#subscribe", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(subscribe, Val); -set_xoption([{"pubsub#access_model", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#access_model", [Val]} | Opts], NewOpts) -> ?SET_ALIST_XOPT(access_model, Val, [open, authorize, presence, roster, whitelist]); -set_xoption([{"pubsub#publish_model", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#publish_model", [Val]} | Opts], NewOpts) -> ?SET_ALIST_XOPT(publish_model, Val, [publishers, subscribers, open]); -set_xoption([{"pubsub#node_type", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#node_type", [Val]} | Opts], NewOpts) -> ?SET_ALIST_XOPT(node_type, Val, [leaf, collection]); -set_xoption([{"pubsub#max_payload_size", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#max_payload_size", [Val]} | Opts], NewOpts) -> ?SET_INTEGER_XOPT(max_payload_size, Val, 0, ?MAX_PAYLOAD_SIZE); -set_xoption([{"pubsub#send_last_published_item", [Val]} | Opts], NewOpts) -> +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([{"pubsub#presence_based_delivery", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#presence_based_delivery", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(presence_based_delivery, Val); -set_xoption([{"pubsub#title", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#title", Value} | Opts], NewOpts) -> ?SET_STRING_XOPT(title, Value); -set_xoption([{"pubsub#type", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#type", Value} | Opts], NewOpts) -> ?SET_STRING_XOPT(type, Value); -set_xoption([{"pubsub#body_xslt", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#body_xslt", Value} | Opts], NewOpts) -> ?SET_STRING_XOPT(body_xslt, Value); -set_xoption([{"pubsub#collection", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#collection", Value} | Opts], NewOpts) -> NewValue = [string_to_node(V) || V <- Value], ?SET_LIST_XOPT(collection, NewValue); -set_xoption([{"pubsub#node", [Value]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#node", [Value]} | Opts], NewOpts) -> NewValue = string_to_node(Value), ?SET_LIST_XOPT(node, NewValue); -set_xoption([_ | Opts], NewOpts) -> +set_xoption(Host, [_ | Opts], NewOpts) -> % skip unknown field - set_xoption(Opts, NewOpts). + set_xoption(Host, Opts, NewOpts). + +get_max_items_node({_, ServerHost, _}) -> + get_max_items_node(ServerHost); +get_max_items_node(Host) -> + case catch ets:lookup(gen_mod:get_module_proc(Host, config), max_items_node) of + [{max_items_node, Integer}] -> Integer; + _ -> ?MAXITEMS + end. %%%% last item cache handling diff --git a/src/mod_pubsub/mod_pubsub_odbc.erl b/src/mod_pubsub/mod_pubsub_odbc.erl index 3c4021e3a..6b731f5ed 100644 --- a/src/mod_pubsub/mod_pubsub_odbc.erl +++ b/src/mod_pubsub/mod_pubsub_odbc.erl @@ -134,6 +134,7 @@ pep_mapping = [], pep_sendlast_offline = false, last_item_cache = false, + max_items_node = ?MAXITEMS, nodetree = ?STDTREE, plugins = [?STDNODE], send_loop}). @@ -179,6 +180,7 @@ init([ServerHost, Opts]) -> PepOffline = gen_mod:get_opt(pep_sendlast_offline, Opts, false), IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue), LastItemCache = gen_mod:get_opt(last_item_cache, Opts, false), + MaxItemsNode = gen_mod:get_opt(max_items_node, Opts, ?MAXITEMS), pubsub_index:init(Host, ServerHost, Opts), ets:new(gen_mod:get_module_proc(Host, config), [set, named_table]), ets:new(gen_mod:get_module_proc(ServerHost, config), [set, named_table]), @@ -189,6 +191,7 @@ init([ServerHost, Opts]) -> ets:insert(gen_mod:get_module_proc(Host, config), {nodetree, NodeTree}), ets:insert(gen_mod:get_module_proc(Host, config), {plugins, Plugins}), ets:insert(gen_mod:get_module_proc(Host, config), {last_item_cache, LastItemCache}), + ets:insert(gen_mod:get_module_proc(Host, config), {max_items_node, MaxItemsNode}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {nodetree, NodeTree}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {plugins, Plugins}), ets:insert(gen_mod:get_module_proc(ServerHost, config), {pep_mapping, PepMapping}), @@ -220,6 +223,7 @@ init([ServerHost, Opts]) -> pep_mapping = PepMapping, pep_sendlast_offline = PepOffline, last_item_cache = LastItemCache, + max_items_node = MaxItemsNode, nodetree = NodeTree, plugins = Plugins}, SendLoop = spawn(?MODULE, send_loop, [State]), @@ -1163,7 +1167,7 @@ adhoc_request(Host, _ServerHost, Owner, invalid -> {error, ?ERR_BAD_REQUEST}; XData2 -> - case set_xoption(XData2, []) of + case set_xoption(Host, XData2, []) of NewOpts when is_list(NewOpts) -> {result, NewOpts}; Err -> @@ -1515,7 +1519,7 @@ create_node(Host, ServerHost, Node, Owner, GivenType, Access, Configuration) -> invalid -> {error, ?ERR_BAD_REQUEST}; XData -> - case set_xoption(XData, node_options(Type)) of + case set_xoption(Host, XData, node_options(Type)) of NewOpts when is_list(NewOpts) -> {result, NewOpts}; Err -> @@ -2011,7 +2015,7 @@ purge_node(Host, Node, Owner) -> get_items(Host, Node, From, SubId, SMaxItems, ItemIDs, RSM) -> MaxItems = if - SMaxItems == "" -> ?MAXITEMS; + SMaxItems == "" -> get_max_items_node(Host); true -> case catch list_to_integer(SMaxItems) of {'EXIT', _} -> {error, ?ERR_BAD_REQUEST}; @@ -3161,7 +3165,7 @@ set_configure(Host, Node, From, Els, Lang) -> [] -> node_options(Type); _ -> Options end, - case set_xoption(XData, OldOpts) of + case set_xoption(Host, XData, OldOpts) of NewOpts when is_list(NewOpts) -> case tree_call(Host, set_node, [N#pubsub_node{options = NewOpts}]) of ok -> {result, ok}; @@ -3206,80 +3210,89 @@ add_opt(Key, Value, Opts) -> end, case BoolVal of error -> {error, ?ERR_NOT_ACCEPTABLE}; - _ -> set_xoption(Opts, add_opt(Opt, BoolVal, NewOpts)) + _ -> set_xoption(Host, Opts, add_opt(Opt, BoolVal, NewOpts)) end). -define(SET_STRING_XOPT(Opt, Val), - set_xoption(Opts, add_opt(Opt, Val, NewOpts))). + set_xoption(Host, Opts, add_opt(Opt, Val, NewOpts))). -define(SET_INTEGER_XOPT(Opt, Val, Min, Max), case catch list_to_integer(Val) of IVal when is_integer(IVal), IVal >= Min, IVal =< Max -> - set_xoption(Opts, add_opt(Opt, IVal, NewOpts)); + set_xoption(Host, Opts, add_opt(Opt, IVal, NewOpts)); _ -> {error, ?ERR_NOT_ACCEPTABLE} end). -define(SET_ALIST_XOPT(Opt, Val, Vals), case lists:member(Val, [atom_to_list(V) || V <- Vals]) of - true -> set_xoption(Opts, add_opt(Opt, list_to_atom(Val), NewOpts)); + true -> set_xoption(Host, Opts, add_opt(Opt, list_to_atom(Val), NewOpts)); false -> {error, ?ERR_NOT_ACCEPTABLE} end). -define(SET_LIST_XOPT(Opt, Val), - set_xoption(Opts, add_opt(Opt, Val, NewOpts))). + set_xoption(Host, Opts, add_opt(Opt, Val, NewOpts))). -set_xoption([], NewOpts) -> +set_xoption(_Host, [], NewOpts) -> NewOpts; -set_xoption([{"FORM_TYPE", _} | Opts], NewOpts) -> - set_xoption(Opts, NewOpts); -set_xoption([{"pubsub#roster_groups_allowed", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"FORM_TYPE", _} | Opts], NewOpts) -> + set_xoption(Host, Opts, NewOpts); +set_xoption(Host, [{"pubsub#roster_groups_allowed", Value} | Opts], NewOpts) -> ?SET_LIST_XOPT(roster_groups_allowed, Value); -set_xoption([{"pubsub#deliver_payloads", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#deliver_payloads", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(deliver_payloads, Val); -set_xoption([{"pubsub#deliver_notifications", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#deliver_notifications", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(deliver_notifications, Val); -set_xoption([{"pubsub#notify_config", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#notify_config", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(notify_config, Val); -set_xoption([{"pubsub#notify_delete", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#notify_delete", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(notify_delete, Val); -set_xoption([{"pubsub#notify_retract", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#notify_retract", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(notify_retract, Val); -set_xoption([{"pubsub#persist_items", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#persist_items", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(persist_items, Val); -set_xoption([{"pubsub#max_items", [Val]} | Opts], NewOpts) -> - ?SET_INTEGER_XOPT(max_items, Val, 0, ?MAXITEMS); -set_xoption([{"pubsub#subscribe", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#max_items", [Val]} | Opts], NewOpts) -> + MaxItems = get_max_items_node(Host), + ?SET_INTEGER_XOPT(max_items, Val, 0, MaxItems); +set_xoption(Host, [{"pubsub#subscribe", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(subscribe, Val); -set_xoption([{"pubsub#access_model", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#access_model", [Val]} | Opts], NewOpts) -> ?SET_ALIST_XOPT(access_model, Val, [open, authorize, presence, roster, whitelist]); -set_xoption([{"pubsub#publish_model", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#publish_model", [Val]} | Opts], NewOpts) -> ?SET_ALIST_XOPT(publish_model, Val, [publishers, subscribers, open]); -set_xoption([{"pubsub#node_type", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#node_type", [Val]} | Opts], NewOpts) -> ?SET_ALIST_XOPT(node_type, Val, [leaf, collection]); -set_xoption([{"pubsub#max_payload_size", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#max_payload_size", [Val]} | Opts], NewOpts) -> ?SET_INTEGER_XOPT(max_payload_size, Val, 0, ?MAX_PAYLOAD_SIZE); -set_xoption([{"pubsub#send_last_published_item", [Val]} | Opts], NewOpts) -> +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([{"pubsub#presence_based_delivery", [Val]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#presence_based_delivery", [Val]} | Opts], NewOpts) -> ?SET_BOOL_XOPT(presence_based_delivery, Val); -set_xoption([{"pubsub#title", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#title", Value} | Opts], NewOpts) -> ?SET_STRING_XOPT(title, Value); -set_xoption([{"pubsub#type", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#type", Value} | Opts], NewOpts) -> ?SET_STRING_XOPT(type, Value); -set_xoption([{"pubsub#body_xslt", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#body_xslt", Value} | Opts], NewOpts) -> ?SET_STRING_XOPT(body_xslt, Value); -set_xoption([{"pubsub#collection", Value} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#collection", Value} | Opts], NewOpts) -> NewValue = [string_to_node(V) || V <- Value], ?SET_LIST_XOPT(collection, NewValue); -set_xoption([{"pubsub#node", [Value]} | Opts], NewOpts) -> +set_xoption(Host, [{"pubsub#node", [Value]} | Opts], NewOpts) -> NewValue = string_to_node(Value), ?SET_LIST_XOPT(node, NewValue); -set_xoption([_ | Opts], NewOpts) -> +set_xoption(Host, [_ | Opts], NewOpts) -> % skip unknown field - set_xoption(Opts, NewOpts). + set_xoption(Host, Opts, NewOpts). + +get_max_items_node({_, ServerHost, _}) -> + get_max_items_node(ServerHost); +get_max_items_node(Host) -> + case catch ets:lookup(gen_mod:get_module_proc(Host, config), max_items_node) of + [{max_items_node, Integer}] -> Integer; + _ -> ?MAXITEMS + end. %%%% last item cache handling diff --git a/src/mod_pubsub/node.template b/src/mod_pubsub/node.template index 59de1dcb3..e70febb8c 100644 --- a/src/mod_pubsub/node.template +++ b/src/mod_pubsub/node.template @@ -83,7 +83,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, open}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_buddy.erl b/src/mod_pubsub/node_buddy.erl index 5283ca5f0..ee804b34c 100644 --- a/src/mod_pubsub/node_buddy.erl +++ b/src/mod_pubsub/node_buddy.erl @@ -84,7 +84,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, presence}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_club.erl b/src/mod_pubsub/node_club.erl index a268cb9dc..8f14387c0 100644 --- a/src/mod_pubsub/node_club.erl +++ b/src/mod_pubsub/node_club.erl @@ -84,7 +84,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, authorize}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_dispatch.erl b/src/mod_pubsub/node_dispatch.erl index 59a9dd85f..2ce01b238 100644 --- a/src/mod_pubsub/node_dispatch.erl +++ b/src/mod_pubsub/node_dispatch.erl @@ -82,7 +82,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, open}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_flat.erl b/src/mod_pubsub/node_flat.erl index 05c0f9c3b..0088034d1 100644 --- a/src/mod_pubsub/node_flat.erl +++ b/src/mod_pubsub/node_flat.erl @@ -75,7 +75,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, open}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_flat_odbc.erl b/src/mod_pubsub/node_flat_odbc.erl index 8c9032fe3..6aed3fbc2 100644 --- a/src/mod_pubsub/node_flat_odbc.erl +++ b/src/mod_pubsub/node_flat_odbc.erl @@ -80,7 +80,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, open}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_hometree.erl b/src/mod_pubsub/node_hometree.erl index 289c720ed..38453e4ee 100644 --- a/src/mod_pubsub/node_hometree.erl +++ b/src/mod_pubsub/node_hometree.erl @@ -138,7 +138,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, open}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_hometree_odbc.erl b/src/mod_pubsub/node_hometree_odbc.erl index ca8b33bbb..0d6cefe22 100644 --- a/src/mod_pubsub/node_hometree_odbc.erl +++ b/src/mod_pubsub/node_hometree_odbc.erl @@ -142,7 +142,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, open}, {roster_groups_allowed, []}, @@ -982,7 +982,17 @@ get_items(NodeId, _From) -> {result, []} end. get_items(NodeId, From, none) -> - get_items(NodeId, From, #rsm_in{max=?MAXITEMS div 2}); + MaxItems = case catch ejabberd_odbc:sql_query_t( + ["select val from pubsub_node_option " + "where nodeid='", NodeId, "' " + "and name='max_items';"]) of + {selected, ["val"], [{Value}]} -> + Tokens = element(2, erl_scan:string(Value++".")), + element(2, erl_parse:parse_term(Tokens)); + _ -> + ?MAXITEMS + end, + get_items(NodeId, From, #rsm_in{max=MaxItems}); get_items(NodeId, _From, #rsm_in{max=M, direction=Direction, id=I, index=IncIndex})-> Max = ?PUBSUB:escape(i2l(M)), diff --git a/src/mod_pubsub/node_pep.erl b/src/mod_pubsub/node_pep.erl index 1ef6d0a10..7b7794a8a 100644 --- a/src/mod_pubsub/node_pep.erl +++ b/src/mod_pubsub/node_pep.erl @@ -82,7 +82,7 @@ options() -> {notify_delete, false}, {notify_retract, false}, {persist_items, false}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, presence}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_pep_odbc.erl b/src/mod_pubsub/node_pep_odbc.erl index 526986f4f..819bc1766 100644 --- a/src/mod_pubsub/node_pep_odbc.erl +++ b/src/mod_pubsub/node_pep_odbc.erl @@ -90,7 +90,7 @@ options() -> {notify_delete, false}, {notify_retract, false}, {persist_items, false}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, presence}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_private.erl b/src/mod_pubsub/node_private.erl index ba34bcb2f..610ac7773 100644 --- a/src/mod_pubsub/node_private.erl +++ b/src/mod_pubsub/node_private.erl @@ -84,7 +84,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, whitelist}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/node_public.erl b/src/mod_pubsub/node_public.erl index c2bbe70e6..0797af778 100644 --- a/src/mod_pubsub/node_public.erl +++ b/src/mod_pubsub/node_public.erl @@ -84,7 +84,7 @@ options() -> {notify_delete, false}, {notify_retract, true}, {persist_items, true}, - {max_items, ?MAXITEMS div 2}, + {max_items, ?MAXITEMS}, {subscribe, true}, {access_model, open}, {roster_groups_allowed, []}, diff --git a/src/mod_pubsub/pubsub.hrl b/src/mod_pubsub/pubsub.hrl index c92587e22..c1ce99b5e 100644 --- a/src/mod_pubsub/pubsub.hrl +++ b/src/mod_pubsub/pubsub.hrl @@ -25,9 +25,11 @@ %% Pubsub constants -define(ERR_EXTENDED(E,C), mod_pubsub:extended_error(E,C)). +%% The actual limit can be configured with mod_pubsub's option max_items_node +-define(MAXITEMS, 10). + %% this is currently a hard limit. %% Would be nice to have it configurable. --define(MAXITEMS, 20). -define(MAX_PAYLOAD_SIZE, 60000). %% ------------------------------- diff --git a/src/mod_pubsub/pubsub_odbc.patch b/src/mod_pubsub/pubsub_odbc.patch index c4da735ba..c59ec725d 100644 --- a/src/mod_pubsub/pubsub_odbc.patch +++ b/src/mod_pubsub/pubsub_odbc.patch @@ -1,5 +1,5 @@ ---- mod_pubsub.erl 2009-09-23 11:13:35.000000000 +0200 -+++ mod_pubsub_odbc.erl 2009-09-23 11:25:11.000000000 +0200 +--- mod_pubsub.erl 2009-09-23 17:53:47.000000000 +0200 ++++ mod_pubsub_odbc.erl 2009-09-23 17:54:27.000000000 +0200 @@ -45,7 +45,7 @@ %%% TODO %%% plugin: generate Reply (do not use broadcast atom anymore) @@ -40,7 +40,7 @@ -define(PLUGIN_PREFIX, "node_"). -define(TREE_PREFIX, "nodetree_"). -@@ -213,8 +213,6 @@ +@@ -216,8 +216,6 @@ ok end, ejabberd_router:register_route(Host), @@ -49,7 +49,7 @@ init_nodes(Host, ServerHost), State = #state{host = Host, server_host = ServerHost, -@@ -269,178 +267,6 @@ +@@ -273,178 +271,6 @@ create_node(Host, ServerHost, ["home", ServerHost], service_jid(Host), "hometree"), ok. @@ -228,7 +228,7 @@ send_queue(State, Msg) -> Pid = State#state.send_loop, case is_process_alive(Pid) of -@@ -463,17 +289,15 @@ +@@ -467,17 +293,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) -> @@ -252,7 +252,7 @@ true -> % resource not concerned about that subscription ok -@@ -797,10 +621,10 @@ +@@ -801,10 +625,10 @@ {result, Subscriptions} = node_action(Host, PType, get_entity_subscriptions, [Host, Subscriber]), lists:foreach(fun ({Node, subscribed, _, JID}) -> @@ -265,7 +265,7 @@ true -> node_action(Host, Type, unsubscribe_node, [NodeId, Subscriber, JID, all]); false -> -@@ -914,7 +738,8 @@ +@@ -918,7 +742,8 @@ sub_el = SubEl} = IQ -> {xmlelement, _, QAttrs, _} = SubEl, Node = xml:get_attr_s("node", QAttrs), @@ -275,7 +275,7 @@ {result, IQRes} -> jlib:iq_to_xml( IQ#iq{type = result, -@@ -1019,7 +844,7 @@ +@@ -1023,7 +848,7 @@ [] -> ["leaf"]; %% No sub-nodes: it's a leaf node _ -> @@ -284,7 +284,7 @@ {result, []} -> ["collection"]; {result, _} -> ["leaf", "collection"]; _ -> [] -@@ -1035,8 +860,9 @@ +@@ -1039,8 +864,9 @@ []; true -> [{xmlelement, "feature", [{"var", ?NS_PUBSUB}], []} | @@ -296,7 +296,7 @@ end, features(Type))] end, %% TODO: add meta-data info (spec section 5.4) -@@ -1064,14 +890,15 @@ +@@ -1068,14 +894,15 @@ {xmlelement, "feature", [{"var", ?NS_DISCO_ITEMS}], []}, {xmlelement, "feature", [{"var", ?NS_PUBSUB}], []}, {xmlelement, "feature", [{"var", ?NS_VCARD}], []}] ++ @@ -315,7 +315,7 @@ {result, lists:map( fun(#pubsub_node{nodeid = {_, SubNode}}) -> SN = node_to_string(SubNode), -@@ -1081,7 +908,7 @@ +@@ -1085,7 +912,7 @@ {"node", SN}, {"name", RN}], []} end, tree_action(Host, get_subnodes, [Host, [], From]))}; @@ -324,7 +324,7 @@ case string:tokens(Item, "!") of [_SNode, _ItemID] -> {result, []}; -@@ -1093,10 +920,10 @@ +@@ -1097,10 +924,10 @@ %% TODO That is, remove name attribute (or node?, please check for 2.1) Action = fun(#pubsub_node{type = Type, id = NodeId}) -> @@ -338,7 +338,7 @@ end, Nodes = lists:map( fun(#pubsub_node{nodeid = {_, SubNode}}) -> -@@ -1112,7 +939,7 @@ +@@ -1116,7 +943,7 @@ {xmlelement, "item", [{"jid", Host}, {"node", SN}, {"name", Name}], []} end, NodeItems), @@ -347,7 +347,7 @@ end, case transaction(Host, Node, Action, sync_dirty) of {result, {_, Result}} -> {result, Result}; -@@ -1244,7 +1071,8 @@ +@@ -1248,7 +1075,8 @@ (_, Acc) -> Acc end, [], xml:remove_cdata(Els)), @@ -357,7 +357,7 @@ {get, "subscriptions"} -> get_subscriptions(Host, Node, From, Plugins); {get, "affiliations"} -> -@@ -1267,7 +1095,9 @@ +@@ -1271,7 +1099,9 @@ iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) -> {xmlelement, _, _, SubEls} = SubEl, @@ -368,7 +368,7 @@ case Action of [{xmlelement, Name, Attrs, Els}] -> Node = case Host of -@@ -1393,7 +1223,8 @@ +@@ -1397,7 +1227,8 @@ _ -> [] end end, @@ -378,7 +378,7 @@ sync_dirty) of {result, Res} -> Res; Err -> Err -@@ -1433,7 +1264,7 @@ +@@ -1437,7 +1268,7 @@ %%% authorization handling @@ -387,7 +387,7 @@ Lang = "en", %% TODO fix Stanza = {xmlelement, "message", [], -@@ -1462,7 +1293,7 @@ +@@ -1466,7 +1297,7 @@ [{xmlelement, "value", [], [{xmlcdata, "false"}]}]}]}]}, lists:foreach(fun(Owner) -> ejabberd_router ! {route, service_jid(Host), jlib:make_jid(Owner), Stanza} @@ -396,7 +396,7 @@ find_authorization_response(Packet) -> {xmlelement, _Name, _Attrs, Els} = Packet, -@@ -1529,8 +1360,8 @@ +@@ -1533,8 +1364,8 @@ "true" -> true; _ -> false end, @@ -407,7 +407,7 @@ {result, Subscriptions} = node_call(Type, get_subscriptions, [NodeId, Subscriber]), if not IsApprover -> -@@ -1716,7 +1547,7 @@ +@@ -1720,7 +1551,7 @@ Reply = [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [{xmlelement, "create", nodeAttr(Node), []}]}], @@ -416,7 +416,7 @@ {result, {Result, broadcast}} -> %%Lang = "en", %% TODO: fix %%OwnerKey = jlib:jid_tolower(jlib:jid_remove_resource(Owner)), -@@ -1824,12 +1655,12 @@ +@@ -1828,12 +1659,12 @@ %%
  • The node does not exist.
  • %% subscribe_node(Host, Node, From, JID, Configuration) -> @@ -431,7 +431,7 @@ Features = features(Type), SubscribeFeature = lists:member("subscribe", Features), OptionsFeature = lists:member("subscription-options", Features), -@@ -1848,9 +1679,13 @@ +@@ -1852,9 +1683,13 @@ {"", "", ""} -> {false, false}; _ -> @@ -448,7 +448,7 @@ end end, if -@@ -2173,7 +2008,7 @@ +@@ -2177,7 +2012,7 @@ %%

    The permission are not checked in this function.

    %% @todo We probably need to check that the user doing the query has the right %% to read the items. @@ -456,8 +456,8 @@ +get_items(Host, Node, From, SubId, SMaxItems, ItemIDs, RSM) -> MaxItems = if - SMaxItems == "" -> ?MAXITEMS; -@@ -2212,11 +2047,11 @@ + SMaxItems == "" -> get_max_items_node(Host); +@@ -2216,11 +2051,11 @@ node_call(Type, get_items, [NodeId, From, AccessModel, PresenceSubscription, RosterGroup, @@ -471,7 +471,7 @@ SendItems = case ItemIDs of [] -> Items; -@@ -2229,7 +2064,8 @@ +@@ -2233,7 +2068,8 @@ %% number of items sent to MaxItems: {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB}], [{xmlelement, "items", nodeAttr(Node), @@ -481,7 +481,7 @@ Error -> Error end -@@ -2261,16 +2097,27 @@ +@@ -2265,16 +2101,27 @@ %% @doc

    Resend the items of a node to the user.

    %% @todo use cache-last-item feature send_items(Host, Node, NodeId, Type, LJID, last) -> @@ -515,7 +515,7 @@ send_items(Host, Node, NodeId, Type, LJID, Number) -> ToSend = case node_action(Host, Type, get_items, [NodeId, LJID]) of {result, []} -> -@@ -2396,29 +2243,12 @@ +@@ -2400,29 +2247,12 @@ error -> {error, ?ERR_BAD_REQUEST}; _ -> @@ -548,7 +548,7 @@ end, Entities), {result, []}; _ -> -@@ -2471,11 +2301,11 @@ +@@ -2475,11 +2305,11 @@ end. read_sub(Subscriber, Node, NodeID, SubID, Lang) -> @@ -562,7 +562,7 @@ OptionsEl = {xmlelement, "options", [{"node", node_to_string(Node)}, {"jid", jlib:jid_to_string(Subscriber)}, {"subid", SubID}], -@@ -2506,7 +2336,7 @@ +@@ -2510,7 +2340,7 @@ error -> {"", "", ""}; J -> jlib:jid_tolower(J) end, @@ -571,7 +571,7 @@ {result, Subs} = node_call(Type, get_subscriptions, [NodeID, Subscriber]), SubIDs = lists:foldl(fun({subscribed, SID}, Acc) -> -@@ -2526,7 +2356,7 @@ +@@ -2530,7 +2360,7 @@ end. write_sub(Subscriber, NodeID, SubID, Options) -> @@ -580,7 +580,7 @@ {error, notfound} -> {error, ?ERR_EXTENDED(?ERR_NOT_ACCEPTABLE, "invalid-subid")}; {result, _} -> -@@ -2694,8 +2524,8 @@ +@@ -2698,8 +2528,8 @@ {"subscription", subscription_to_string(Sub)} | nodeAttr(Node)], []}]}]}, ejabberd_router ! {route, service_jid(Host), jlib:make_jid(JID), Stanza} end, @@ -591,7 +591,7 @@ true -> Result = lists:foldl(fun({JID, Subscription, SubId}, Acc) -> -@@ -2985,7 +2815,7 @@ +@@ -2989,7 +2819,7 @@ {Depth, [{N, get_node_subs(N)} || N <- Nodes]} end, tree_call(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)]))} end, @@ -600,7 +600,7 @@ {result, CollSubs} -> CollSubs; _ -> [] end. -@@ -2999,9 +2829,9 @@ +@@ -3003,9 +2833,9 @@ get_options_for_subs(NodeID, Subs) -> lists:foldl(fun({JID, subscribed, SubID}, Acc) -> @@ -612,7 +612,7 @@ _ -> Acc end; (_, Acc) -> -@@ -3195,6 +3025,30 @@ +@@ -3199,6 +3029,30 @@ Result end. @@ -643,7 +643,7 @@ %% @spec (Host, Options) -> MaxItems %% Host = host() %% Options = [Option] -@@ -3568,7 +3422,13 @@ +@@ -3581,7 +3435,13 @@ tree_action(Host, Function, Args) -> ?DEBUG("tree_action ~p ~p ~p",[Host,Function,Args]), Fun = fun() -> tree_call(Host, Function, Args) end, @@ -658,7 +658,7 @@ %% @doc

    node plugin call.

    node_call(Type, Function, Args) -> -@@ -3588,13 +3448,13 @@ +@@ -3601,13 +3461,13 @@ node_action(Host, Type, Function, Args) -> ?DEBUG("node_action ~p ~p ~p ~p",[Host,Type,Function,Args]), @@ -674,7 +674,7 @@ case tree_call(Host, get_node, [Host, Node]) of N when is_record(N, pubsub_node) -> case Action(N) of -@@ -3607,8 +3467,14 @@ +@@ -3620,8 +3480,14 @@ end end, Trans). @@ -691,7 +691,7 @@ {result, Result} -> {result, Result}; {error, Error} -> {error, Error}; {atomic, {result, Result}} -> {result, Result}; -@@ -3616,6 +3482,15 @@ +@@ -3629,6 +3495,15 @@ {aborted, Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{aborted, Reason}]), {error, ?ERR_INTERNAL_SERVER_ERROR}; @@ -707,7 +707,7 @@ {'EXIT', Reason} -> ?ERROR_MSG("transaction return internal error: ~p~n", [{'EXIT', Reason}]), {error, ?ERR_INTERNAL_SERVER_ERROR}; -@@ -3624,6 +3499,17 @@ +@@ -3637,6 +3512,17 @@ {error, ?ERR_INTERNAL_SERVER_ERROR} end.