mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
Add/improve type specs
This commit is contained in:
parent
691f9e0bf7
commit
722864666d
@ -52,6 +52,7 @@
|
|||||||
|
|
||||||
-type image_error() :: efbig | enodata | limit | malformed_image | timeout.
|
-type image_error() :: efbig | enodata | limit | malformed_image | timeout.
|
||||||
-type priority() :: neg_integer().
|
-type priority() :: neg_integer().
|
||||||
|
-type callback() :: fun((captcha_succeed | captcha_failed) -> any()).
|
||||||
|
|
||||||
-record(state, {limits = treap:empty() :: treap:treap(),
|
-record(state, {limits = treap:empty() :: treap:treap(),
|
||||||
enabled = false :: boolean()}).
|
enabled = false :: boolean()}).
|
||||||
@ -84,8 +85,9 @@ mk_field(Type, Var, Value) ->
|
|||||||
#xdata_field{type = Type, var = Var, values = [Value]}.
|
#xdata_field{type = Type, var = Var, values = [Value]}.
|
||||||
|
|
||||||
-spec create_captcha(binary(), jid(), jid(),
|
-spec create_captcha(binary(), jid(), jid(),
|
||||||
binary(), any(), any()) -> {error, image_error()} |
|
binary(), any(),
|
||||||
{ok, binary(), [text()], [xmpp_element()]}.
|
callback() | term()) -> {error, image_error()} |
|
||||||
|
{ok, binary(), [text()], [xmpp_element()]}.
|
||||||
create_captcha(SID, From, To, Lang, Limiter, Args) ->
|
create_captcha(SID, From, To, Lang, Limiter, Args) ->
|
||||||
case create_image(Limiter) of
|
case create_image(Limiter) of
|
||||||
{ok, Type, Key, Image} ->
|
{ok, Type, Key, Image} ->
|
||||||
@ -607,7 +609,9 @@ clean_treap(Treap, CleanPriority) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec callback(captcha_succeed | captcha_failed, pid(), term()) -> any().
|
-spec callback(captcha_succeed | captcha_failed,
|
||||||
|
pid() | undefined,
|
||||||
|
callback() | term()) -> any().
|
||||||
callback(Result, _Pid, F) when is_function(F) ->
|
callback(Result, _Pid, F) when is_function(F) ->
|
||||||
F(Result);
|
F(Result);
|
||||||
callback(Result, Pid, Args) when is_pid(Pid) ->
|
callback(Result, Pid, Args) when is_pid(Pid) ->
|
||||||
|
@ -68,6 +68,7 @@ depends(_Host, _Opts) ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Hooks
|
%%% Hooks
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
-spec pubsub_publish_item(binary(), binary(), jid(), jid(), binary(), [xmlel()]) -> ok.
|
||||||
pubsub_publish_item(LServer, ?NS_AVATAR_METADATA,
|
pubsub_publish_item(LServer, ?NS_AVATAR_METADATA,
|
||||||
#jid{luser = LUser, lserver = LServer} = From,
|
#jid{luser = LUser, lserver = LServer} = From,
|
||||||
#jid{luser = LUser, lserver = LServer} = Host,
|
#jid{luser = LUser, lserver = LServer} = Host,
|
||||||
|
@ -40,6 +40,8 @@
|
|||||||
|
|
||||||
-define(SETS, gb_sets).
|
-define(SETS, gb_sets).
|
||||||
|
|
||||||
|
-type c2s_state() :: ejabberd_c2s:state().
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Callbacks and hooks
|
%%% Callbacks and hooks
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
@ -62,6 +64,8 @@ stop(Host) ->
|
|||||||
reload(_Host, _NewOpts, _OldOpts) ->
|
reload(_Host, _NewOpts, _OldOpts) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec filter_packet({stanza(), c2s_state()}) -> {stanza(), c2s_state()} |
|
||||||
|
{stop, {drop, c2s_state()}}.
|
||||||
filter_packet({#message{from = From} = Msg, State} = Acc) ->
|
filter_packet({#message{from = From} = Msg, State} = Acc) ->
|
||||||
LFrom = jid:tolower(From),
|
LFrom = jid:tolower(From),
|
||||||
LBFrom = jid:remove_resource(LFrom),
|
LBFrom = jid:remove_resource(LFrom),
|
||||||
@ -80,12 +84,14 @@ filter_packet({#message{from = From} = Msg, State} = Acc) ->
|
|||||||
filter_packet(Acc) ->
|
filter_packet(Acc) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
|
-spec filter_offline_msg({_, message()}) -> {_, message()} | {stop, {drop, message()}}.
|
||||||
filter_offline_msg({_Action, #message{} = Msg} = Acc) ->
|
filter_offline_msg({_Action, #message{} = Msg} = Acc) ->
|
||||||
case check_message(Msg) of
|
case check_message(Msg) of
|
||||||
allow -> Acc;
|
allow -> Acc;
|
||||||
deny -> {stop, {drop, Msg}}
|
deny -> {stop, {drop, Msg}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec filter_subscription(boolean(), presence()) -> boolean() | {stop, false}.
|
||||||
filter_subscription(Acc, #presence{meta = #{captcha := passed}}) ->
|
filter_subscription(Acc, #presence{meta = #{captcha := passed}}) ->
|
||||||
Acc;
|
Acc;
|
||||||
filter_subscription(Acc, #presence{from = From, to = To, lang = Lang,
|
filter_subscription(Acc, #presence{from = From, to = To, lang = Lang,
|
||||||
@ -136,6 +142,7 @@ filter_subscription(Acc, #presence{from = From, to = To, lang = Lang,
|
|||||||
filter_subscription(Acc, _) ->
|
filter_subscription(Acc, _) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
|
-spec handle_captcha_result(captcha_succeed | captcha_failed, presence()) -> ok.
|
||||||
handle_captcha_result(captcha_succeed, Pres) ->
|
handle_captcha_result(captcha_succeed, Pres) ->
|
||||||
Pres1 = xmpp:put_meta(Pres, captcha, passed),
|
Pres1 = xmpp:put_meta(Pres, captcha, passed),
|
||||||
ejabberd_router:route(Pres1);
|
ejabberd_router:route(Pres1);
|
||||||
@ -146,6 +153,7 @@ handle_captcha_result(captcha_failed, #presence{lang = Lang} = Pres) ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
-spec check_message(message()) -> allow | deny.
|
||||||
check_message(#message{from = From, to = To, lang = Lang} = Msg) ->
|
check_message(#message{from = From, to = To, lang = Lang} = Msg) ->
|
||||||
LServer = To#jid.lserver,
|
LServer = To#jid.lserver,
|
||||||
case need_check(Msg) of
|
case need_check(Msg) of
|
||||||
@ -222,6 +230,7 @@ check_subscription(From, To) ->
|
|||||||
true
|
true
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec sets_bare_member(ljid(), ?SETS:set()) -> boolean().
|
||||||
sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
|
sets_bare_member({U, S, <<"">>} = LBJID, Set) ->
|
||||||
case ?SETS:next(?SETS:iterator_from(LBJID, Set)) of
|
case ?SETS:next(?SETS:iterator_from(LBJID, Set)) of
|
||||||
{{U, S, _}, _} -> true;
|
{{U, S, _}, _} -> true;
|
||||||
|
@ -258,6 +258,7 @@ process_get(#iq{from = #jid{luser = LUser, lserver = LServer}} = IQ) ->
|
|||||||
err_db_failure(IQ)
|
err_db_failure(IQ)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec err_db_failure(iq()) -> iq().
|
||||||
err_db_failure(#iq{lang = Lang} = IQ) ->
|
err_db_failure(#iq{lang = Lang} = IQ) ->
|
||||||
Txt = ?T("Database failure"),
|
Txt = ?T("Database failure"),
|
||||||
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang)).
|
xmpp:make_error(IQ, xmpp:err_internal_server_error(Txt, Lang)).
|
||||||
|
@ -60,6 +60,8 @@
|
|||||||
|
|
||||||
-record(state, {host = <<"">> :: binary()}).
|
-record(state, {host = <<"">> :: binary()}).
|
||||||
|
|
||||||
|
-type digest_type() :: md5 | sha | sha224 | sha256 | sha384 | sha512.
|
||||||
|
|
||||||
-callback init(binary(), gen_mod:opts()) -> any().
|
-callback init(binary(), gen_mod:opts()) -> any().
|
||||||
-callback import(binary(), {binary(), binary()}, [binary() | pos_integer()]) -> ok.
|
-callback import(binary(), {binary(), binary()}, [binary() | pos_integer()]) -> ok.
|
||||||
-callback caps_read(binary(), {binary(), binary()}) ->
|
-callback caps_read(binary(), {binary(), binary()}) ->
|
||||||
@ -416,19 +418,18 @@ make_my_disco_hash(Host) ->
|
|||||||
_Err -> <<"">>
|
_Err -> <<"">>
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-type digest_type() :: md5 | sha | sha224 | sha256 | sha384 | sha512.
|
|
||||||
-spec compute_disco_hash(disco_info(), digest_type()) -> binary().
|
-spec compute_disco_hash(disco_info(), digest_type()) -> binary().
|
||||||
compute_disco_hash(DiscoInfo, Algo) ->
|
compute_disco_hash(DiscoInfo, Algo) ->
|
||||||
Concat = list_to_binary([concat_identities(DiscoInfo),
|
Concat = list_to_binary([concat_identities(DiscoInfo),
|
||||||
concat_features(DiscoInfo), concat_info(DiscoInfo)]),
|
concat_features(DiscoInfo), concat_info(DiscoInfo)]),
|
||||||
base64:encode(case Algo of
|
base64:encode(case Algo of
|
||||||
md5 -> erlang:md5(Concat);
|
md5 -> erlang:md5(Concat);
|
||||||
sha -> crypto:hash(sha, Concat);
|
sha -> crypto:hash(sha, Concat);
|
||||||
sha224 -> crypto:hash(sha224, Concat);
|
sha224 -> crypto:hash(sha224, Concat);
|
||||||
sha256 -> crypto:hash(sha256, Concat);
|
sha256 -> crypto:hash(sha256, Concat);
|
||||||
sha384 -> crypto:hash(sha384, Concat);
|
sha384 -> crypto:hash(sha384, Concat);
|
||||||
sha512 -> crypto:hash(sha512, Concat)
|
sha512 -> crypto:hash(sha512, Concat)
|
||||||
end).
|
end).
|
||||||
|
|
||||||
-spec check_hash(caps(), disco_info()) -> boolean().
|
-spec check_hash(caps(), disco_info()) -> boolean().
|
||||||
check_hash(Caps, DiscoInfo) ->
|
check_hash(Caps, DiscoInfo) ->
|
||||||
|
@ -119,8 +119,10 @@ depends(_Host, _Opts) ->
|
|||||||
[<<"http:">>, <<"jabber.org">>, <<"protocol">>,
|
[<<"http:">>, <<"jabber.org">>, <<"protocol">>,
|
||||||
<<"admin">>, Sub]).
|
<<"admin">>, Sub]).
|
||||||
|
|
||||||
|
-spec tokenize(binary()) -> [binary()].
|
||||||
tokenize(Node) -> str:tokens(Node, <<"/#">>).
|
tokenize(Node) -> str:tokens(Node, <<"/#">>).
|
||||||
|
|
||||||
|
-spec get_sm_identity([identity()], jid(), jid(), binary(), binary()) -> [identity()].
|
||||||
get_sm_identity(Acc, _From, _To, Node, Lang) ->
|
get_sm_identity(Acc, _From, _To, Node, Lang) ->
|
||||||
case Node of
|
case Node of
|
||||||
<<"config">> ->
|
<<"config">> ->
|
||||||
@ -128,6 +130,7 @@ get_sm_identity(Acc, _From, _To, Node, Lang) ->
|
|||||||
_ -> Acc
|
_ -> Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_local_identity([identity()], jid(), jid(), binary(), binary()) -> [identity()].
|
||||||
get_local_identity(Acc, _From, _To, Node, Lang) ->
|
get_local_identity(Acc, _From, _To, Node, Lang) ->
|
||||||
LNode = tokenize(Node),
|
LNode = tokenize(Node),
|
||||||
case LNode of
|
case LNode of
|
||||||
@ -190,6 +193,8 @@ get_local_identity(Acc, _From, _To, Node, Lang) ->
|
|||||||
allow -> {result, Feats}
|
allow -> {result, Feats}
|
||||||
end).
|
end).
|
||||||
|
|
||||||
|
-spec get_sm_features(mod_disco:features_acc(), jid(), jid(),
|
||||||
|
binary(), binary()) -> mod_disco:features_acc().
|
||||||
get_sm_features(Acc, From,
|
get_sm_features(Acc, From,
|
||||||
#jid{lserver = LServer} = _To, Node, Lang) ->
|
#jid{lserver = LServer} = _To, Node, Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
@ -202,6 +207,8 @@ get_sm_features(Acc, From,
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_local_features(mod_disco:features_acc(), jid(), jid(),
|
||||||
|
binary(), binary()) -> mod_disco:features_acc().
|
||||||
get_local_features(Acc, From,
|
get_local_features(Acc, From,
|
||||||
#jid{lserver = LServer} = _To, Node, Lang) ->
|
#jid{lserver = LServer} = _To, Node, Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
@ -264,10 +271,8 @@ get_local_features(Acc, From,
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------
|
||||||
-spec adhoc_sm_items(empty | {error, stanza_error()} | {result, [disco_item()]},
|
-spec adhoc_sm_items(mod_disco:items_acc(),
|
||||||
jid(), jid(), binary()) -> {error, stanza_error()} |
|
jid(), jid(), binary()) -> mod_disco:items_acc().
|
||||||
{result, [disco_item()]} |
|
|
||||||
empty.
|
|
||||||
adhoc_sm_items(Acc, From, #jid{lserver = LServer} = To,
|
adhoc_sm_items(Acc, From, #jid{lserver = LServer} = To,
|
||||||
Lang) ->
|
Lang) ->
|
||||||
case acl:match_rule(LServer, configure, From) of
|
case acl:match_rule(LServer, configure, From) of
|
||||||
@ -283,7 +288,8 @@ adhoc_sm_items(Acc, From, #jid{lserver = LServer} = To,
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------
|
||||||
|
-spec get_sm_items(mod_disco:items_acc(), jid(), jid(),
|
||||||
|
binary(), binary()) -> mod_disco:items_acc().
|
||||||
get_sm_items(Acc, From,
|
get_sm_items(Acc, From,
|
||||||
#jid{user = User, server = Server, lserver = LServer} =
|
#jid{user = User, server = Server, lserver = LServer} =
|
||||||
To,
|
To,
|
||||||
@ -309,6 +315,7 @@ get_sm_items(Acc, From,
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_user_resources(binary(), binary()) -> [disco_item()].
|
||||||
get_user_resources(User, Server) ->
|
get_user_resources(User, Server) ->
|
||||||
Rs = ejabberd_sm:get_user_resources(User, Server),
|
Rs = ejabberd_sm:get_user_resources(User, Server),
|
||||||
lists:map(fun (R) ->
|
lists:map(fun (R) ->
|
||||||
@ -319,10 +326,8 @@ get_user_resources(User, Server) ->
|
|||||||
|
|
||||||
%%%-----------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------
|
||||||
|
|
||||||
-spec adhoc_local_items(empty | {error, stanza_error()} | {result, [disco_item()]},
|
-spec adhoc_local_items(mod_disco:items_acc(),
|
||||||
jid(), jid(), binary()) -> {error, stanza_error()} |
|
jid(), jid(), binary()) -> mod_disco:items_acc().
|
||||||
{result, [disco_item()]} |
|
|
||||||
empty.
|
|
||||||
adhoc_local_items(Acc, From,
|
adhoc_local_items(Acc, From,
|
||||||
#jid{lserver = LServer, server = Server} = To, Lang) ->
|
#jid{lserver = LServer, server = Server} = To, Lang) ->
|
||||||
case acl:match_rule(LServer, configure, From) of
|
case acl:match_rule(LServer, configure, From) of
|
||||||
@ -336,7 +341,7 @@ adhoc_local_items(Acc, From,
|
|||||||
<<"">>, Server, Lang),
|
<<"">>, Server, Lang),
|
||||||
Nodes1 = lists:filter(
|
Nodes1 = lists:filter(
|
||||||
fun (#disco_item{node = Nd}) ->
|
fun (#disco_item{node = Nd}) ->
|
||||||
F = get_local_features([], From, To, Nd, Lang),
|
F = get_local_features(empty, From, To, Nd, Lang),
|
||||||
case F of
|
case F of
|
||||||
{result, [?NS_COMMANDS]} -> true;
|
{result, [?NS_COMMANDS]} -> true;
|
||||||
_ -> false
|
_ -> false
|
||||||
@ -347,6 +352,8 @@ adhoc_local_items(Acc, From,
|
|||||||
_ -> Acc
|
_ -> Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec recursively_get_local_items(global | vhost, binary(), binary(),
|
||||||
|
binary(), binary()) -> [disco_item()].
|
||||||
recursively_get_local_items(_PermLev, _LServer,
|
recursively_get_local_items(_PermLev, _LServer,
|
||||||
<<"online users">>, _Server, _Lang) ->
|
<<"online users">>, _Server, _Lang) ->
|
||||||
[];
|
[];
|
||||||
@ -376,6 +383,7 @@ recursively_get_local_items(PermLev, LServer, Node,
|
|||||||
end,
|
end,
|
||||||
Items)).
|
Items)).
|
||||||
|
|
||||||
|
-spec get_permission_level(jid()) -> global | vhost.
|
||||||
get_permission_level(JID) ->
|
get_permission_level(JID) ->
|
||||||
case acl:match_rule(global, configure, JID) of
|
case acl:match_rule(global, configure, JID) of
|
||||||
allow -> global;
|
allow -> global;
|
||||||
@ -397,6 +405,8 @@ get_permission_level(JID) ->
|
|||||||
end
|
end
|
||||||
end).
|
end).
|
||||||
|
|
||||||
|
-spec get_local_items(mod_disco:items_acc(), jid(), jid(),
|
||||||
|
binary(), binary()) -> mod_disco:items_acc().
|
||||||
get_local_items(Acc, From, #jid{lserver = LServer} = To,
|
get_local_items(Acc, From, #jid{lserver = LServer} = To,
|
||||||
<<"">>, Lang) ->
|
<<"">>, Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
@ -489,10 +499,8 @@ get_local_items(Acc, From, #jid{lserver = LServer} = To,
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%%%-----------------------------------------------------------------------
|
%%%-----------------------------------------------------------------------
|
||||||
|
-spec get_local_items({global | vhost, binary()}, [binary()],
|
||||||
%% @spec ({PermissionLevel, Host}, [string()], Server::string(), Lang)
|
binary(), binary()) -> {result, [disco_item()]} | {error, stanza_error()}.
|
||||||
%% -> {result, [xmlelement()]}
|
|
||||||
%% PermissionLevel = global | vhost
|
|
||||||
get_local_items(_Host, [], Server, Lang) ->
|
get_local_items(_Host, [], Server, Lang) ->
|
||||||
{result,
|
{result,
|
||||||
[?NODE(?T("Configuration"), <<"config">>),
|
[?NODE(?T("Configuration"), <<"config">>),
|
||||||
@ -550,7 +558,7 @@ get_local_items({_, Host},
|
|||||||
name = <<U/binary, $@, S/binary>>}
|
name = <<U/binary, $@, S/binary>>}
|
||||||
end, Sub)}
|
end, Sub)}
|
||||||
catch _:_ ->
|
catch _:_ ->
|
||||||
xmpp:err_not_acceptable()
|
{error, xmpp:err_not_acceptable()}
|
||||||
end;
|
end;
|
||||||
get_local_items({_, Host}, [<<"outgoing s2s">>],
|
get_local_items({_, Host}, [<<"outgoing s2s">>],
|
||||||
_Server, Lang) ->
|
_Server, Lang) ->
|
||||||
@ -638,6 +646,7 @@ get_local_items(_Host,
|
|||||||
get_local_items(_Host, _, _Server, _Lang) ->
|
get_local_items(_Host, _, _Server, _Lang) ->
|
||||||
{error, xmpp:err_item_not_found()}.
|
{error, xmpp:err_item_not_found()}.
|
||||||
|
|
||||||
|
-spec get_online_vh_users(binary()) -> [disco_item()].
|
||||||
get_online_vh_users(Host) ->
|
get_online_vh_users(Host) ->
|
||||||
case catch ejabberd_sm:get_vh_session_list(Host) of
|
case catch ejabberd_sm:get_vh_session_list(Host) of
|
||||||
{'EXIT', _Reason} -> [];
|
{'EXIT', _Reason} -> [];
|
||||||
@ -650,6 +659,7 @@ get_online_vh_users(Host) ->
|
|||||||
end, SURs)
|
end, SURs)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_all_vh_users(binary()) -> [disco_item()].
|
||||||
get_all_vh_users(Host) ->
|
get_all_vh_users(Host) ->
|
||||||
case catch ejabberd_auth:get_users(Host)
|
case catch ejabberd_auth:get_users(Host)
|
||||||
of
|
of
|
||||||
@ -686,6 +696,7 @@ get_all_vh_users(Host) ->
|
|||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_outgoing_s2s(binary(), binary()) -> [disco_item()].
|
||||||
get_outgoing_s2s(Host, Lang) ->
|
get_outgoing_s2s(Host, Lang) ->
|
||||||
case catch ejabberd_s2s:dirty_get_connections() of
|
case catch ejabberd_s2s:dirty_get_connections() of
|
||||||
{'EXIT', _Reason} -> [];
|
{'EXIT', _Reason} -> [];
|
||||||
@ -703,6 +714,7 @@ get_outgoing_s2s(Host, Lang) ->
|
|||||||
end, lists:usort(TConns))
|
end, lists:usort(TConns))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_outgoing_s2s(binary(), binary(), binary()) -> [disco_item()].
|
||||||
get_outgoing_s2s(Host, Lang, To) ->
|
get_outgoing_s2s(Host, Lang, To) ->
|
||||||
case catch ejabberd_s2s:dirty_get_connections() of
|
case catch ejabberd_s2s:dirty_get_connections() of
|
||||||
{'EXIT', _Reason} -> [];
|
{'EXIT', _Reason} -> [];
|
||||||
@ -719,6 +731,7 @@ get_outgoing_s2s(Host, Lang, To) ->
|
|||||||
Connections)))
|
Connections)))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_running_nodes(binary(), binary()) -> [disco_item()].
|
||||||
get_running_nodes(Server, _Lang) ->
|
get_running_nodes(Server, _Lang) ->
|
||||||
case catch mnesia:system_info(running_db_nodes) of
|
case catch mnesia:system_info(running_db_nodes) of
|
||||||
{'EXIT', _Reason} -> [];
|
{'EXIT', _Reason} -> [];
|
||||||
@ -733,6 +746,7 @@ get_running_nodes(Server, _Lang) ->
|
|||||||
lists:sort(DBNodes))
|
lists:sort(DBNodes))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_stopped_nodes(binary()) -> [disco_item()].
|
||||||
get_stopped_nodes(_Lang) ->
|
get_stopped_nodes(_Lang) ->
|
||||||
case catch lists:usort(mnesia:system_info(db_nodes) ++
|
case catch lists:usort(mnesia:system_info(db_nodes) ++
|
||||||
mnesia:system_info(extra_db_nodes))
|
mnesia:system_info(extra_db_nodes))
|
||||||
@ -785,6 +799,7 @@ adhoc_local_commands(Acc, From,
|
|||||||
_ -> Acc
|
_ -> Acc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec adhoc_local_commands(jid(), jid(), adhoc_command()) -> adhoc_command() | {error, stanza_error()}.
|
||||||
adhoc_local_commands(From,
|
adhoc_local_commands(From,
|
||||||
#jid{lserver = LServer} = _To,
|
#jid{lserver = LServer} = _To,
|
||||||
#adhoc_command{lang = Lang, node = Node,
|
#adhoc_command{lang = Lang, node = Node,
|
||||||
@ -852,6 +867,9 @@ adhoc_local_commands(From,
|
|||||||
#xdata_option{label = tr(Lang, ?T("Remote copy")),
|
#xdata_option{label = tr(Lang, ?T("Remote copy")),
|
||||||
value = <<"unknown">>}]}).
|
value = <<"unknown">>}]}).
|
||||||
|
|
||||||
|
-spec get_form(binary(), [binary()], binary()) -> {result, xdata()} |
|
||||||
|
{result, completed, xdata()} |
|
||||||
|
{error, stanza_error()}.
|
||||||
get_form(_Host, [<<"running nodes">>, ENode, <<"DB">>],
|
get_form(_Host, [<<"running nodes">>, ENode, <<"DB">>],
|
||||||
Lang) ->
|
Lang) ->
|
||||||
case search_running_node(ENode) of
|
case search_running_node(ENode) of
|
||||||
@ -1169,6 +1187,8 @@ get_form(Host, ?NS_ADMINL(<<"get-online-users-num">>),
|
|||||||
get_form(_Host, _, _Lang) ->
|
get_form(_Host, _, _Lang) ->
|
||||||
{error, xmpp:err_service_unavailable()}.
|
{error, xmpp:err_service_unavailable()}.
|
||||||
|
|
||||||
|
-spec set_form(jid(), binary(), [binary()], binary(), xdata()) -> {result, xdata() | undefined} |
|
||||||
|
{error, stanza_error()}.
|
||||||
set_form(_From, _Host,
|
set_form(_From, _Host,
|
||||||
[<<"running nodes">>, ENode, <<"DB">>], Lang, XData) ->
|
[<<"running nodes">>, ENode, <<"DB">>], Lang, XData) ->
|
||||||
case search_running_node(ENode) of
|
case search_running_node(ENode) of
|
||||||
@ -1543,22 +1563,28 @@ set_form(From, Host, ?NS_ADMINL(<<"user-stats">>), Lang,
|
|||||||
set_form(_From, _Host, _, _Lang, _XData) ->
|
set_form(_From, _Host, _, _Lang, _XData) ->
|
||||||
{error, xmpp:err_service_unavailable()}.
|
{error, xmpp:err_service_unavailable()}.
|
||||||
|
|
||||||
get_value(Field, XData) -> hd(get_values(Field, XData)).
|
-spec get_value(binary(), xdata()) -> binary().
|
||||||
|
get_value(Field, XData) ->
|
||||||
|
hd(get_values(Field, XData)).
|
||||||
|
|
||||||
|
-spec get_values(binary(), xdata()) -> [binary()].
|
||||||
get_values(Field, XData) ->
|
get_values(Field, XData) ->
|
||||||
xmpp_util:get_xdata_values(Field, XData).
|
xmpp_util:get_xdata_values(Field, XData).
|
||||||
|
|
||||||
|
-spec search_running_node(binary()) -> false | node().
|
||||||
search_running_node(SNode) ->
|
search_running_node(SNode) ->
|
||||||
search_running_node(SNode,
|
search_running_node(SNode,
|
||||||
mnesia:system_info(running_db_nodes)).
|
mnesia:system_info(running_db_nodes)).
|
||||||
|
|
||||||
|
-spec search_running_node(binary(), [node()]) -> false | node().
|
||||||
search_running_node(_, []) -> false;
|
search_running_node(_, []) -> false;
|
||||||
search_running_node(SNode, [Node | Nodes]) ->
|
search_running_node(SNode, [Node | Nodes]) ->
|
||||||
case iolist_to_binary(atom_to_list(Node)) of
|
case atom_to_binary(Node, utf8) of
|
||||||
SNode -> Node;
|
SNode -> Node;
|
||||||
_ -> search_running_node(SNode, Nodes)
|
_ -> search_running_node(SNode, Nodes)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec stop_node(jid(), binary(), binary(), restart | stop, xdata()) -> {result, undefined}.
|
||||||
stop_node(From, Host, ENode, Action, XData) ->
|
stop_node(From, Host, ENode, Action, XData) ->
|
||||||
Delay = binary_to_integer(get_value(<<"delay">>, XData)),
|
Delay = binary_to_integer(get_value(<<"delay">>, XData)),
|
||||||
Subject = case get_value(<<"subject">>, XData) of
|
Subject = case get_value(<<"subject">>, XData) of
|
||||||
@ -1586,9 +1612,10 @@ stop_node(From, Host, ENode, Action, XData) ->
|
|||||||
end,
|
end,
|
||||||
Time = timer:seconds(Delay),
|
Time = timer:seconds(Delay),
|
||||||
Node = misc:binary_to_atom(ENode),
|
Node = misc:binary_to_atom(ENode),
|
||||||
{ok, _} = timer:apply_after(Time, rpc, call, [Node, init, Action, []]),
|
{ok, _} = timer:apply_after(Time, ejabberd_cluster, call, [Node, init, Action, []]),
|
||||||
{result, undefined}.
|
{result, undefined}.
|
||||||
|
|
||||||
|
-spec get_last_info(binary(), binary()) -> {ok, non_neg_integer(), binary()} | not_found.
|
||||||
get_last_info(User, Server) ->
|
get_last_info(User, Server) ->
|
||||||
case gen_mod:is_loaded(Server, mod_last) of
|
case gen_mod:is_loaded(Server, mod_last) of
|
||||||
true -> mod_last:get_last_info(User, Server);
|
true -> mod_last:get_last_info(User, Server);
|
||||||
@ -1596,7 +1623,8 @@ get_last_info(User, Server) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
-spec adhoc_sm_commands(adhoc_command(), jid(), jid(), adhoc_command()) -> adhoc_command().
|
-spec adhoc_sm_commands(adhoc_command(), jid(), jid(), adhoc_command()) -> adhoc_command() |
|
||||||
|
{error, stanza_error()}.
|
||||||
adhoc_sm_commands(_Acc, From,
|
adhoc_sm_commands(_Acc, From,
|
||||||
#jid{user = User, server = Server, lserver = LServer},
|
#jid{user = User, server = Server, lserver = LServer},
|
||||||
#adhoc_command{lang = Lang, node = <<"config">>,
|
#adhoc_command{lang = Lang, node = <<"config">>,
|
||||||
@ -1627,6 +1655,8 @@ adhoc_sm_commands(_Acc, From,
|
|||||||
end;
|
end;
|
||||||
adhoc_sm_commands(Acc, _From, _To, _Request) -> Acc.
|
adhoc_sm_commands(Acc, _From, _To, _Request) -> Acc.
|
||||||
|
|
||||||
|
-spec get_sm_form(binary(), binary(), binary(), binary()) -> {result, xdata()} |
|
||||||
|
{error, stanza_error()}.
|
||||||
get_sm_form(User, Server, <<"config">>, Lang) ->
|
get_sm_form(User, Server, <<"config">>, Lang) ->
|
||||||
{result,
|
{result,
|
||||||
#xdata{type = form,
|
#xdata{type = form,
|
||||||
@ -1650,6 +1680,8 @@ get_sm_form(User, Server, <<"config">>, Lang) ->
|
|||||||
get_sm_form(_User, _Server, _Node, _Lang) ->
|
get_sm_form(_User, _Server, _Node, _Lang) ->
|
||||||
{error, xmpp:err_service_unavailable()}.
|
{error, xmpp:err_service_unavailable()}.
|
||||||
|
|
||||||
|
-spec set_sm_form(binary(), binary(), binary(), adhoc_command()) -> adhoc_command() |
|
||||||
|
{error, stanza_error()}.
|
||||||
set_sm_form(User, Server, <<"config">>,
|
set_sm_form(User, Server, <<"config">>,
|
||||||
#adhoc_command{lang = Lang, node = Node,
|
#adhoc_command{lang = Lang, node = Node,
|
||||||
sid = SessionID, xdata = XData}) ->
|
sid = SessionID, xdata = XData}) ->
|
||||||
|
@ -44,7 +44,6 @@
|
|||||||
-include("xmpp.hrl").
|
-include("xmpp.hrl").
|
||||||
-include("translate.hrl").
|
-include("translate.hrl").
|
||||||
|
|
||||||
-type disco_acc() :: {error, stanza_error()} | {result, [binary()]} | empty.
|
|
||||||
-type route_type() :: ejabberd_sm | ejabberd_local.
|
-type route_type() :: ejabberd_sm | ejabberd_local.
|
||||||
-type delegations() :: #{{binary(), route_type()} => {binary(), disco_info()}}.
|
-type delegations() :: #{{binary(), route_type()} => {binary(), disco_info()}}.
|
||||||
-record(state, {server_host = <<"">> :: binary()}).
|
-record(state, {server_host = <<"">> :: binary()}).
|
||||||
@ -115,19 +114,21 @@ ejabberd_local(IQ) ->
|
|||||||
ejabberd_sm(IQ) ->
|
ejabberd_sm(IQ) ->
|
||||||
process_iq(IQ, ejabberd_sm).
|
process_iq(IQ, ejabberd_sm).
|
||||||
|
|
||||||
-spec disco_local_features(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
|
-spec disco_local_features(mod_disco:features_acc(), jid(), jid(),
|
||||||
|
binary(), binary()) -> mod_disco:features_acc().
|
||||||
disco_local_features(Acc, From, To, Node, Lang) ->
|
disco_local_features(Acc, From, To, Node, Lang) ->
|
||||||
disco_features(Acc, From, To, Node, Lang, ejabberd_local).
|
disco_features(Acc, From, To, Node, Lang, ejabberd_local).
|
||||||
|
|
||||||
-spec disco_sm_features(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
|
-spec disco_sm_features(mod_disco:features_acc(), jid(), jid(),
|
||||||
|
binary(), binary()) -> mod_disco:features_acc().
|
||||||
disco_sm_features(Acc, From, To, Node, Lang) ->
|
disco_sm_features(Acc, From, To, Node, Lang) ->
|
||||||
disco_features(Acc, From, To, Node, Lang, ejabberd_sm).
|
disco_features(Acc, From, To, Node, Lang, ejabberd_sm).
|
||||||
|
|
||||||
-spec disco_local_identity(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
|
-spec disco_local_identity([identity()], jid(), jid(), binary(), binary()) -> [identity()].
|
||||||
disco_local_identity(Acc, From, To, Node, Lang) ->
|
disco_local_identity(Acc, From, To, Node, Lang) ->
|
||||||
disco_identity(Acc, From, To, Node, Lang, ejabberd_local).
|
disco_identity(Acc, From, To, Node, Lang, ejabberd_local).
|
||||||
|
|
||||||
-spec disco_sm_identity(disco_acc(), jid(), jid(), binary(), binary()) -> disco_acc().
|
-spec disco_sm_identity([identity()], jid(), jid(), binary(), binary()) -> [identity()].
|
||||||
disco_sm_identity(Acc, From, To, Node, Lang) ->
|
disco_sm_identity(Acc, From, To, Node, Lang) ->
|
||||||
disco_identity(Acc, From, To, Node, Lang, ejabberd_sm).
|
disco_identity(Acc, From, To, Node, Lang, ejabberd_sm).
|
||||||
|
|
||||||
@ -335,8 +336,8 @@ send_disco_queries(LServer, Host, NS) ->
|
|||||||
end, [{ejabberd_local, <<(?NS_DELEGATION)/binary, "::", NS/binary>>},
|
end, [{ejabberd_local, <<(?NS_DELEGATION)/binary, "::", NS/binary>>},
|
||||||
{ejabberd_sm, <<(?NS_DELEGATION)/binary, ":bare:", NS/binary>>}]).
|
{ejabberd_sm, <<(?NS_DELEGATION)/binary, ":bare:", NS/binary>>}]).
|
||||||
|
|
||||||
-spec disco_features(disco_acc(), jid(), jid(), binary(), binary(),
|
-spec disco_features(mod_disco:features_acc(), jid(), jid(), binary(), binary(),
|
||||||
route_type()) -> disco_acc().
|
route_type()) -> mod_disco:features_acc().
|
||||||
disco_features(Acc, _From, To, <<"">>, _Lang, Type) ->
|
disco_features(Acc, _From, To, <<"">>, _Lang, Type) ->
|
||||||
Delegations = get_delegations(To#jid.lserver),
|
Delegations = get_delegations(To#jid.lserver),
|
||||||
Features = my_features(Type) ++
|
Features = my_features(Type) ++
|
||||||
@ -354,8 +355,8 @@ disco_features(Acc, _From, To, <<"">>, _Lang, Type) ->
|
|||||||
disco_features(Acc, _, _, _, _, _) ->
|
disco_features(Acc, _, _, _, _, _) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
-spec disco_identity(disco_acc(), jid(), jid(), binary(), binary(),
|
-spec disco_identity([identity()], jid(), jid(), binary(), binary(),
|
||||||
route_type()) -> disco_acc().
|
route_type()) -> [identity()].
|
||||||
disco_identity(Acc, _From, To, <<"">>, _Lang, Type) ->
|
disco_identity(Acc, _From, To, <<"">>, _Lang, Type) ->
|
||||||
Delegations = get_delegations(To#jid.lserver),
|
Delegations = get_delegations(To#jid.lserver),
|
||||||
Identities = lists:flatmap(
|
Identities = lists:flatmap(
|
||||||
@ -364,11 +365,7 @@ disco_identity(Acc, _From, To, <<"">>, _Lang, Type) ->
|
|||||||
(_) ->
|
(_) ->
|
||||||
[]
|
[]
|
||||||
end, maps:to_list(Delegations)),
|
end, maps:to_list(Delegations)),
|
||||||
case Acc of
|
Acc ++ Identities;
|
||||||
empty when Identities /= [] -> {result, Identities};
|
|
||||||
{result, Ids} -> {result, Ids ++ Identities};
|
|
||||||
Acc -> Acc
|
|
||||||
end;
|
|
||||||
disco_identity(Acc, _From, _To, _Node, _Lang, _Type) ->
|
disco_identity(Acc, _From, _To, _Node, _Lang, _Type) ->
|
||||||
Acc.
|
Acc.
|
||||||
|
|
||||||
|
@ -225,13 +225,16 @@ log_and_disconnect(#{ip := {Addr, _}, lang := Lang} = State, Attempts, UnbanTS)
|
|||||||
Err = xmpp:serr_policy_violation({Format, Args}, Lang),
|
Err = xmpp:serr_policy_violation({Format, Args}, Lang),
|
||||||
{stop, ejabberd_c2s:send(State, Err)}.
|
{stop, ejabberd_c2s:send(State, Err)}.
|
||||||
|
|
||||||
|
-spec is_whitelisted(binary(), inet:ip_address()) -> boolean().
|
||||||
is_whitelisted(Host, Addr) ->
|
is_whitelisted(Host, Addr) ->
|
||||||
Access = mod_fail2ban_opt:access(Host),
|
Access = mod_fail2ban_opt:access(Host),
|
||||||
acl:match_rule(Host, Access, Addr) == allow.
|
acl:match_rule(Host, Access, Addr) == allow.
|
||||||
|
|
||||||
|
-spec seconds_to_now(non_neg_integer()) -> erlang:timestamp().
|
||||||
seconds_to_now(Secs) ->
|
seconds_to_now(Secs) ->
|
||||||
{Secs div 1000000, Secs rem 1000000, 0}.
|
{Secs div 1000000, Secs rem 1000000, 0}.
|
||||||
|
|
||||||
|
-spec format_date(calendar:datetime()) -> iolist().
|
||||||
format_date({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
format_date({{Year, Month, Day}, {Hour, Minute, Second}}) ->
|
||||||
io_lib:format("~2..0w:~2..0w:~2..0w ~2..0w.~2..0w.~4..0w",
|
io_lib:format("~2..0w:~2..0w:~2..0w ~2..0w.~2..0w.~4..0w",
|
||||||
[Hour, Minute, Second, Day, Month, Year]).
|
[Hour, Minute, Second, Day, Month, Year]).
|
||||||
|
@ -45,6 +45,8 @@
|
|||||||
|
|
||||||
-define(LAST_CACHE, last_activity_cache).
|
-define(LAST_CACHE, last_activity_cache).
|
||||||
|
|
||||||
|
-type c2s_state() :: ejabberd_c2s:state().
|
||||||
|
|
||||||
-callback init(binary(), gen_mod:opts()) -> any().
|
-callback init(binary(), gen_mod:opts()) -> any().
|
||||||
-callback import(binary(), #last_activity{}) -> ok | pass.
|
-callback import(binary(), #last_activity{}) -> ok | pass.
|
||||||
-callback get_last(binary(), binary()) ->
|
-callback get_last(binary(), binary()) ->
|
||||||
@ -144,6 +146,7 @@ process_sm_iq(#iq{from = From, to = To, lang = Lang} = IQ) ->
|
|||||||
xmpp:make_error(IQ, xmpp:err_subscription_required(Txt, Lang))
|
xmpp:make_error(IQ, xmpp:err_subscription_required(Txt, Lang))
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec privacy_check_packet(allow | deny, c2s_state(), stanza(), in | out) -> allow | deny | {stop, deny}.
|
||||||
privacy_check_packet(allow, C2SState,
|
privacy_check_packet(allow, C2SState,
|
||||||
#iq{from = From, to = To, type = T} = IQ, in)
|
#iq{from = From, to = To, type = T} = IQ, in)
|
||||||
when T == get; T == set ->
|
when T == get; T == set ->
|
||||||
|
@ -50,6 +50,7 @@ stop(Host) ->
|
|||||||
reload(_Host, _NewOpts, _OldOpts) ->
|
reload(_Host, _NewOpts, _OldOpts) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec process_local_iq(iq()) -> iq().
|
||||||
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
|
process_local_iq(#iq{type = set, lang = Lang} = IQ) ->
|
||||||
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
|
Txt = ?T("Value 'set' of 'type' attribute is not allowed"),
|
||||||
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
xmpp:make_error(IQ, xmpp:err_not_allowed(Txt, Lang));
|
||||||
|
@ -132,7 +132,8 @@ init([Host, Opts]) ->
|
|||||||
end,
|
end,
|
||||||
{ok, #state{hosts = MyHosts, server_host = Host}}.
|
{ok, #state{hosts = MyHosts, server_host = Host}}.
|
||||||
|
|
||||||
handle_call(_Call, _From, State) ->
|
handle_call(Call, From, State) ->
|
||||||
|
?WARNING_MSG("Unexpected call from ~p: ~p", [From, Call]),
|
||||||
{noreply, State}.
|
{noreply, State}.
|
||||||
|
|
||||||
handle_cast(Cast, State) ->
|
handle_cast(Cast, State) ->
|
||||||
@ -443,6 +444,7 @@ mk_search_form(JID, ServerHost, Lang) ->
|
|||||||
Lang, ?T("You need an x:data capable client to search")),
|
Lang, ?T("You need an x:data capable client to search")),
|
||||||
xdata = X}.
|
xdata = X}.
|
||||||
|
|
||||||
|
-spec make_instructions(module(), binary()) -> binary().
|
||||||
make_instructions(Mod, Lang) ->
|
make_instructions(Mod, Lang) ->
|
||||||
Fill = translate:translate(
|
Fill = translate:translate(
|
||||||
Lang,
|
Lang,
|
||||||
|
Loading…
Reference in New Issue
Block a user