25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

fix is_last_item_cache_enabled issue with PEP, and fix indentation

SVN Revision: 2416
This commit is contained in:
Christophe Romain 2009-07-31 14:55:05 +00:00
parent fc0209fec9
commit 9fbef39193

View File

@ -166,9 +166,9 @@ stop(Host) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Function: init(Args) -> {ok, State} | %% Function: init(Args) -> {ok, State} |
%% {ok, State, Timeout} | %% {ok, State, Timeout} |
%% ignore | %% ignore |
%% {stop, Reason} %% {stop, Reason}
%% Description: Initiates the server %% Description: Initiates the server
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
init([ServerHost, Opts]) -> init([ServerHost, Opts]) ->
@ -726,11 +726,11 @@ remove_user(User, Server) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Function: %% Function:
%% handle_call(Request, From, State) -> {reply, Reply, State} | %% handle_call(Request, From, State) -> {reply, Reply, State} |
%% {reply, Reply, State, Timeout} | %% {reply, Reply, State, Timeout} |
%% {noreply, State} | %% {noreply, State} |
%% {noreply, State, Timeout} | %% {noreply, State, Timeout} |
%% {stop, Reason, Reply, State} | %% {stop, Reason, Reply, State} |
%% {stop, Reason, State} %% {stop, Reason, State}
%% Description: Handling call messages %% Description: Handling call messages
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @private %% @private
@ -747,8 +747,8 @@ handle_call(stop, _From, State) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Function: handle_cast(Msg, State) -> {noreply, State} | %% Function: handle_cast(Msg, State) -> {noreply, State} |
%% {noreply, State, Timeout} | %% {noreply, State, Timeout} |
%% {stop, Reason, State} %% {stop, Reason, State}
%% Description: Handling cast messages %% Description: Handling cast messages
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @private %% @private
@ -812,8 +812,8 @@ handle_cast(_Msg, State) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Function: handle_info(Info, State) -> {noreply, State} | %% Function: handle_info(Info, State) -> {noreply, State} |
%% {noreply, State, Timeout} | %% {noreply, State, Timeout} |
%% {stop, Reason, State} %% {stop, Reason, State}
%% Description: Handling all non call/cast messages %% Description: Handling all non call/cast messages
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @private %% @private
@ -946,15 +946,15 @@ do_route(ServerHost, Access, Plugins, Host, From, To, Packet) ->
sub_el = [{xmlelement, "vCard", [{"xmlns", XMLNS}], sub_el = [{xmlelement, "vCard", [{"xmlns", XMLNS}],
iq_get_vcard(Lang)}]}, iq_get_vcard(Lang)}]},
ejabberd_router:route(To, From, jlib:iq_to_xml(Res)); ejabberd_router:route(To, From, jlib:iq_to_xml(Res));
#iq{type = set, xmlns = ?NS_COMMANDS} = IQ -> #iq{type = set, xmlns = ?NS_COMMANDS} = IQ ->
Res = case iq_command(Host, ServerHost, From, IQ, Access, Plugins) of Res = case iq_command(Host, ServerHost, From, IQ, Access, Plugins) of
{error, Error} -> {error, Error} ->
jlib:make_error_reply(Packet, Error); jlib:make_error_reply(Packet, Error);
{result, IQRes} -> {result, IQRes} ->
jlib:iq_to_xml(IQ#iq{type = result, jlib:iq_to_xml(IQ#iq{type = result,
sub_el = IQRes}) sub_el = IQRes})
end, end,
ejabberd_router:route(To, From, Res); ejabberd_router:route(To, From, Res);
#iq{} -> #iq{} ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, Packet,
@ -1294,30 +1294,30 @@ iq_pubsub_owner(Host, ServerHost, From, IQType, SubEl, Lang) ->
iq_command(Host, ServerHost, From, IQ, Access, Plugins) -> iq_command(Host, ServerHost, From, IQ, Access, Plugins) ->
case adhoc:parse_request(IQ) of case adhoc:parse_request(IQ) of
Req when is_record(Req, adhoc_request) -> Req when is_record(Req, adhoc_request) ->
case adhoc_request(Host, ServerHost, From, Req, Access, Plugins) of case adhoc_request(Host, ServerHost, From, Req, Access, Plugins) of
Resp when is_record(Resp, adhoc_response) -> Resp when is_record(Resp, adhoc_response) ->
{result, [adhoc:produce_response(Req, Resp)]}; {result, [adhoc:produce_response(Req, Resp)]};
Error -> Error ->
Error Error
end; end;
Err -> Err ->
Err Err
end. end.
%% @doc <p>Processes an Ad Hoc Command.</p> %% @doc <p>Processes an Ad Hoc Command.</p>
adhoc_request(Host, _ServerHost, Owner, adhoc_request(Host, _ServerHost, Owner,
#adhoc_request{node = ?NS_PUBSUB_GET_PENDING, #adhoc_request{node = ?NS_PUBSUB_GET_PENDING,
lang = Lang, lang = Lang,
action = "execute", action = "execute",
xdata = false}, xdata = false},
_Access, Plugins) -> _Access, Plugins) ->
send_pending_node_form(Host, Owner, Lang, Plugins); send_pending_node_form(Host, Owner, Lang, Plugins);
adhoc_request(Host, _ServerHost, Owner, adhoc_request(Host, _ServerHost, Owner,
#adhoc_request{node = ?NS_PUBSUB_GET_PENDING, #adhoc_request{node = ?NS_PUBSUB_GET_PENDING,
action = "execute", action = "execute",
xdata = XData}, xdata = XData},
_Access, _Plugins) -> _Access, _Plugins) ->
ParseOptions = case XData of ParseOptions = case XData of
{xmlelement, "x", _Attrs, _SubEls} = XEl -> {xmlelement, "x", _Attrs, _SubEls} = XEl ->
case jlib:parse_xdata_submit(XEl) of case jlib:parse_xdata_submit(XEl) of
@ -1336,15 +1336,15 @@ adhoc_request(Host, _ServerHost, Owner,
{error, ?ERR_BAD_REQUEST} {error, ?ERR_BAD_REQUEST}
end, end,
case ParseOptions of case ParseOptions of
{result, XForm} -> {result, XForm} ->
case lists:keysearch(node, 1, XForm) of case lists:keysearch(node, 1, XForm) of
{value, {_, Node}} -> {value, {_, Node}} ->
send_pending_auth_events(Host, Node, Owner); send_pending_auth_events(Host, Node, Owner);
false -> false ->
{error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "bad-payload")} {error, ?ERR_EXTENDED(?ERR_BAD_REQUEST, "bad-payload")}
end; end;
Error -> Error ->
Error Error
end; end;
adhoc_request(_Host, _ServerHost, _Owner, Other, _Access, _Plugins) -> adhoc_request(_Host, _ServerHost, _Owner, Other, _Access, _Plugins) ->
?DEBUG("Couldn't process ad hoc command:~n~p", [Other]), ?DEBUG("Couldn't process ad hoc command:~n~p", [Other]),
@ -1355,39 +1355,39 @@ adhoc_request(_Host, _ServerHost, _Owner, Other, _Access, _Plugins) ->
%% Owner.</p> %% Owner.</p>
send_pending_node_form(Host, Owner, _Lang, Plugins) -> send_pending_node_form(Host, Owner, _Lang, Plugins) ->
Filter = Filter =
fun (Plugin) -> fun (Plugin) ->
lists:member("get-pending", features(Plugin)) lists:member("get-pending", features(Plugin))
end, end,
case lists:filter(Filter, Plugins) of case lists:filter(Filter, Plugins) of
[] -> [] ->
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}; {error, ?ERR_FEATURE_NOT_IMPLEMENTED};
Ps -> Ps ->
XOpts = lists:map(fun (Node) -> XOpts = lists:map(fun (Node) ->
{xmlelement, "option", [], {xmlelement, "option", [],
[{xmlelement, "value", [], [{xmlelement, "value", [],
[{xmlcdata, node_to_string(Node)}]}]} [{xmlcdata, node_to_string(Node)}]}]}
end, get_pending_nodes(Host, Owner, Ps)), end, get_pending_nodes(Host, Owner, Ps)),
XForm = {xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}], XForm = {xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
[{xmlelement, "field", [{xmlelement, "field",
[{"type", "list-single"}, {"var", "pubsub#node"}], [{"type", "list-single"}, {"var", "pubsub#node"}],
lists:usort(XOpts)}]}, lists:usort(XOpts)}]},
#adhoc_response{status = executing, #adhoc_response{status = executing,
defaultaction = "execute", defaultaction = "execute",
elements = [XForm]} elements = [XForm]}
end. end.
get_pending_nodes(Host, Owner, Plugins) -> get_pending_nodes(Host, Owner, Plugins) ->
Tr = Tr =
fun (Type) -> fun (Type) ->
case node_call(Type, get_pending_nodes, [Host, Owner]) of case node_call(Type, get_pending_nodes, [Host, Owner]) of
{result, Nodes} -> Nodes; {result, Nodes} -> Nodes;
_ -> [] _ -> []
end end
end, end,
case transaction(fun () -> {result, lists:flatmap(Tr, Plugins)} end, case transaction(fun () -> {result, lists:flatmap(Tr, Plugins)} end,
sync_dirty) of sync_dirty) of
{result, Res} -> Res; {result, Res} -> Res;
Err -> Err Err -> Err
end. end.
%% @spec (Host, Node, Owner) -> iqRes() %% @spec (Host, Node, Owner) -> iqRes()
@ -1395,36 +1395,36 @@ get_pending_nodes(Host, Owner, Plugins) ->
%% subscriptions on Host and Node.</p> %% subscriptions on Host and Node.</p>
send_pending_auth_events(Host, Node, Owner) -> send_pending_auth_events(Host, Node, Owner) ->
?DEBUG("Sending pending auth events for ~s on ~s:~s", ?DEBUG("Sending pending auth events for ~s on ~s:~s",
[jlib:jid_to_string(Owner), Host, node_to_string(Node)]), [jlib:jid_to_string(Owner), Host, node_to_string(Node)]),
Action = Action =
fun (#pubsub_node{id = NodeID, type = Type} = N) -> fun (#pubsub_node{id = NodeID, type = Type} = N) ->
case lists:member("get-pending", features(Type)) of case lists:member("get-pending", features(Type)) of
true -> true ->
case node_call(Type, get_affiliation, [NodeID, Owner]) of case node_call(Type, get_affiliation, [NodeID, Owner]) of
{result, owner} -> {result, owner} ->
broadcast_pending_auth_events(N), broadcast_pending_auth_events(N),
{result, ok}; {result, ok};
_ -> _ ->
{error, ?ERR_FORBIDDEN} {error, ?ERR_FORBIDDEN}
end; end;
false -> false ->
{error, ?ERR_FEATURE_NOT_IMPLEMENTED} {error, ?ERR_FEATURE_NOT_IMPLEMENTED}
end end
end, end,
case transaction(Host, Node, Action, sync_dirty) of case transaction(Host, Node, Action, sync_dirty) of
{result, _} -> {result, _} ->
#adhoc_response{}; #adhoc_response{};
Err -> Err ->
Err Err
end. end.
broadcast_pending_auth_events(#pubsub_node{type = Type, id = NodeID} = Node) -> broadcast_pending_auth_events(#pubsub_node{type = Type, id = NodeID} = Node) ->
{result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]), {result, Subscriptions} = node_call(Type, get_node_subscriptions, [NodeID]),
lists:foreach(fun ({J, pending, _SubID}) -> lists:foreach(fun ({J, pending, _SubID}) ->
send_authorization_request(Node, jlib:make_jid(J)); send_authorization_request(Node, jlib:make_jid(J));
({J, pending}) -> ({J, pending}) ->
send_authorization_request(Node, jlib:make_jid(J)) send_authorization_request(Node, jlib:make_jid(J))
end, Subscriptions). end, Subscriptions).
%%% authorization handling %%% authorization handling
@ -1566,8 +1566,8 @@ update_auth(Host, Node, Type, NodeId, Subscriber,
true -> subscribed; true -> subscribed;
false -> none false -> none
end, end,
node_call(Type, set_subscriptions, node_call(Type, set_subscriptions,
[NodeId, Subscriber, NewSubscription, SubID]), [NodeId, Subscriber, NewSubscription, SubID]),
send_authorization_approval(Host, Subscriber, Node, send_authorization_approval(Host, Subscriber, Node,
NewSubscription), NewSubscription),
{result, ok}; {result, ok};
@ -2615,7 +2615,7 @@ get_subscriptions(Host, Node, JID) ->
{result, {_, Subscriptions}} -> {result, {_, Subscriptions}} ->
Entities = lists:flatmap( Entities = lists:flatmap(
fun({_, none}) -> []; fun({_, none}) -> [];
({_, pending, _}) -> []; ({_, pending, _}) -> [];
({AJID, Subscription}) -> ({AJID, Subscription}) ->
[{xmlelement, "subscription", [{xmlelement, "subscription",
[{"jid", jlib:jid_to_string(AJID)}, [{"jid", jlib:jid_to_string(AJID)},
@ -2650,7 +2650,7 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
xml:get_attr_s("jid", Attrs)), xml:get_attr_s("jid", Attrs)),
Subscription = string_to_subscription( Subscription = string_to_subscription(
xml:get_attr_s("subscription", Attrs)), xml:get_attr_s("subscription", Attrs)),
SubId = xml:get_attr_s("subid", Attrs), SubId = xml:get_attr_s("subid", Attrs),
if if
(JID == error) or (JID == error) or
(Subscription == false) -> (Subscription == false) ->
@ -2668,10 +2668,10 @@ set_subscriptions(Host, Node, From, EntitiesEls) ->
Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) -> Action = fun(#pubsub_node{owners = Owners, type = Type, id = NodeId}) ->
case lists:member(Owner, Owners) of case lists:member(Owner, Owners) of
true -> true ->
lists:foreach(fun({JID, Subscription, SubId}) -> lists:foreach(fun({JID, Subscription, SubId}) ->
node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId]) node_call(Type, set_subscriptions, [NodeId, JID, Subscription, SubId])
end, Entities), end, Entities),
{result, []}; {result, []};
_ -> _ ->
{error, ?ERR_FORBIDDEN} {error, ?ERR_FORBIDDEN}
end end
@ -2794,7 +2794,7 @@ presence_can_deliver({User, Server, _}, true) ->
[] -> false; [] -> false;
Ss -> Ss ->
lists:foldl(fun({session, _, _, _, undefined, _}, Acc) -> Acc; lists:foldl(fun({session, _, _, _, undefined, _}, Acc) -> Acc;
({session, _, _, _, _Priority, _}, _Acc) -> true ({session, _, _, _, _Priority, _}, _Acc) -> true
end, false, Ss) end, false, Ss)
end. end.
@ -2936,16 +2936,9 @@ broadcast_config_notification(Host, Node, NodeId, Type, NodeOptions, Lang) ->
end. end.
get_collection_subscriptions(Host, Node) -> get_collection_subscriptions(Host, Node) ->
case mnesia:transaction(fun tree_call/3, lists:map(fun ({Depth, Nodes}) ->
[Host, get_parentnodes_tree, {Depth, [{N, get_node_subs(N)} || N <- Nodes]}
[Host, Node, service_jid(Host)]]) of end, tree_action(Host, get_parentnodes_tree, [Host, Node, service_jid(Host)])).
{atomic, NodesByDepth} when is_list(NodesByDepth) ->
lists:map(fun ({Depth, Nodes}) ->
{Depth, [{N, get_node_subs(N)} || N <- Nodes]}
end, NodesByDepth);
Other ->
Other
end.
get_node_subs(#pubsub_node{type = Type, get_node_subs(#pubsub_node{type = Type,
nodeid = {Host, Node}, nodeid = {Host, Node},
@ -2957,6 +2950,14 @@ get_node_subs(#pubsub_node{type = Type,
Other Other
end. end.
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];
(_, Acc) ->
Acc
end, [], Subs).
% TODO: merge broadcast code that way % TODO: merge broadcast code that way
%broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) -> %broadcast(Host, Node, NodeId, Type, NodeOptions, Feature, Force, ElName, SubEls) ->
% case (get_option(NodeOptions, Feature) or Force) of % case (get_option(NodeOptions, Feature) or Force) of
@ -3128,7 +3129,7 @@ get_default(Host, Node, _From, Lang) ->
{result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB_OWNER}], {result, [{xmlelement, "pubsub", [{"xmlns", ?NS_PUBSUB_OWNER}],
[{xmlelement, "default", [], [{xmlelement, "default", [],
[{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}], [{xmlelement, "x", [{"xmlns", ?NS_XDATA}, {"type", "form"}],
get_configure_xfields(Type, Options, Lang, []) get_configure_xfields(Type, Options, Lang, [])
}]}]}]}. }]}]}]}.
%% Get node option %% Get node option
@ -3296,14 +3297,6 @@ set_configure(Host, Node, From, Els, Lang) ->
{error, ?ERR_BAD_REQUEST} {error, ?ERR_BAD_REQUEST}
end. end.
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];
(_, Acc) ->
Acc
end, [], Subs).
add_opt(Key, Value, Opts) -> add_opt(Key, Value, Opts) ->
Opts1 = lists:keydelete(Key, 1, Opts), Opts1 = lists:keydelete(Key, 1, Opts),
[{Key, Value} | Opts1]. [{Key, Value} | Opts1].
@ -3395,6 +3388,8 @@ set_xoption([_ | Opts], NewOpts) ->
%%%% last item cache handling %%%% last item cache handling
is_last_item_cache_enabled({_, ServerHost, _}) ->
is_last_item_cache_enabled(ServerHost);
is_last_item_cache_enabled(Host) -> is_last_item_cache_enabled(Host) ->
case ets:lookup(gen_mod:get_module_proc(Host, config), last_item_cache) of case ets:lookup(gen_mod:get_module_proc(Host, config), last_item_cache) of
[{last_item_cache, true}] -> true; [{last_item_cache, true}] -> true;