25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-22 17:28:25 +01:00

Fix some dialyzer warnings

This commit is contained in:
Evgeniy Khramtsov 2017-02-18 09:36:27 +03:00
parent b2de1d7438
commit 940ca9311d
53 changed files with 244 additions and 242 deletions

View File

@ -22,5 +22,5 @@
token = <<"">> :: binary() | '_', token = <<"">> :: binary() | '_',
us = {<<"">>, <<"">>} :: {binary(), binary()} | '_', us = {<<"">>, <<"">>} :: {binary(), binary()} | '_',
scope = [] :: [binary()] | '_', scope = [] :: [binary()] | '_',
expire :: integer() | '$1' expire :: integer() | '$1' | '_'
}). }).

View File

@ -1,6 +1,6 @@
-type local_hint() :: undefined | integer() | {apply, atom(), atom()}. -type local_hint() :: integer() | {apply, atom(), atom()}.
-record(route, {domain :: binary(), -record(route, {domain :: binary() | '_',
server_host :: binary(), server_host :: binary() | '_',
pid :: undefined | pid(), pid :: undefined | pid(),
local_hint :: local_hint()}). local_hint :: local_hint() | undefined | '_'}).

View File

@ -27,7 +27,8 @@
-type ip() :: {inet:ip_address(), inet:port_number()} | undefined. -type ip() :: {inet:ip_address(), inet:port_number()} | undefined.
-type info() :: [{conn, atom()} | {ip, ip()} | {node, atom()} -type info() :: [{conn, atom()} | {ip, ip()} | {node, atom()}
| {oor, boolean()} | {auth_module, atom()} | {oor, boolean()} | {auth_module, atom()}
| {num_stanzas_in, non_neg_integer()}]. | {num_stanzas_in, non_neg_integer()}
| offline].
-type prio() :: undefined | integer(). -type prio() :: undefined | integer().
-endif. -endif.

View File

@ -27,7 +27,7 @@
-record(eldap_search, -record(eldap_search,
{scope = wholeSubtree :: scope(), {scope = wholeSubtree :: scope(),
base = <<"">> :: binary(), base = <<"">> :: binary(),
filter :: eldap:filter(), filter :: eldap:filter() | undefined,
limit = 0 :: non_neg_integer(), limit = 0 :: non_neg_integer(),
attributes = [] :: [binary()], attributes = [] :: [binary()],
types_only = false :: boolean(), types_only = false :: boolean(),

View File

@ -471,15 +471,15 @@
-type(iq() :: iq_request() | iq_reply()). -type(iq() :: iq_request() | iq_reply()).
-record(rsm_in, {max :: integer() | error, -record(rsm_in, {max :: integer() | error | undefined,
direction :: before | aft, direction :: before | aft | undefined,
id :: binary(), id :: binary() | undefined,
index :: integer() | error}). index :: integer() | error | undefined}).
-record(rsm_out, {count :: integer(), -record(rsm_out, {count :: integer() | undefined,
index :: integer(), index :: integer() | undefined,
first :: binary(), first :: binary() | undefined,
last :: binary()}). last :: binary() | undefined}).
-type(rsm_in() :: #rsm_in{}). -type(rsm_in() :: #rsm_in{}).

View File

@ -28,9 +28,9 @@
-record(lqueue, -record(lqueue,
{ {
queue :: ?TQUEUE, queue = queue:new() :: ?TQUEUE,
len :: integer(), len = 0 :: integer(),
max :: integer() max = 0 :: integer()
}). }).
-type lqueue() :: #lqueue{}. -type lqueue() :: #lqueue{}.
@ -80,7 +80,7 @@
role :: role(), role :: role(),
%%is_subscriber = false :: boolean(), %%is_subscriber = false :: boolean(),
%%subscriptions = [] :: [binary()], %%subscriptions = [] :: [binary()],
last_presence :: xmlel() last_presence :: presence() | undefined
}). }).
-record(subscriber, {jid :: jid(), -record(subscriber, {jid :: jid(),
@ -91,10 +91,10 @@
{ {
message_time = 0 :: integer(), message_time = 0 :: integer(),
presence_time = 0 :: integer(), presence_time = 0 :: integer(),
message_shaper :: shaper:shaper(), message_shaper = none :: shaper:shaper(),
presence_shaper :: shaper:shaper(), presence_shaper = none :: shaper:shaper(),
message :: xmlel(), message :: message() | undefined,
presence :: {binary(), xmlel()} presence :: {binary(), presence()} | undefined
}). }).
-record(state, -record(state,
@ -112,7 +112,7 @@
robots = (?DICT):new() :: ?TDICT, robots = (?DICT):new() :: ?TDICT,
nicks = (?DICT):new() :: ?TDICT, nicks = (?DICT):new() :: ?TDICT,
affiliations = (?DICT):new() :: ?TDICT, affiliations = (?DICT):new() :: ?TDICT,
history :: lqueue(), history = #lqueue{} :: lqueue(),
subject = <<"">> :: binary(), subject = <<"">> :: binary(),
subject_author = <<"">> :: binary(), subject_author = <<"">> :: binary(),
just_created = false :: boolean(), just_created = false :: boolean(),

View File

@ -20,11 +20,11 @@
-record(offline_msg, -record(offline_msg,
{us = {<<"">>, <<"">>} :: {binary(), binary()}, {us = {<<"">>, <<"">>} :: {binary(), binary()},
timestamp = p1_time_compat:timestamp() :: erlang:timestamp() | '_', timestamp :: erlang:timestamp() | '_' | undefined,
expire = p1_time_compat:timestamp() :: erlang:timestamp() | never | '_', expire :: erlang:timestamp() | never | undefined | '_',
from = #jid{} :: jid() | '_', from = #jid{} :: jid() | '_',
to = #jid{} :: jid() | '_', to = #jid{} :: jid() | '_',
packet = #xmlel{} :: xmlel() | '_'}). packet = #xmlel{} :: xmlel() | message() | '_'}).
-record(state, -record(state,
{host = <<"">> :: binary(), {host = <<"">> :: binary(),

View File

@ -271,7 +271,7 @@ normalize_spec(Spec) ->
end end
end. end.
-spec any_rules_allowed(global | binary(), access_name(), -spec any_rules_allowed(global | binary(), [access_name()],
jid() | ljid() | inet:ip_address()) -> boolean(). jid() | ljid() | inet:ip_address()) -> boolean().
any_rules_allowed(Host, Access, Entity) -> any_rules_allowed(Host, Access, Entity) ->

View File

@ -42,8 +42,8 @@
server_key = <<"">> :: binary(), server_key = <<"">> :: binary(),
username = <<"">> :: binary(), username = <<"">> :: binary(),
auth_module :: module(), auth_module :: module(),
get_password :: fun(), get_password :: fun((binary()) ->
check_password :: fun(), {false | ejabberd_auth:password(), module()}),
auth_message = <<"">> :: binary(), auth_message = <<"">> :: binary(),
client_nonce = <<"">> :: binary(), client_nonce = <<"">> :: binary(),
server_nonce = <<"">> :: binary()}). server_nonce = <<"">> :: binary()}).
@ -101,18 +101,22 @@ mech_step(#state{step = 2} = State, ClientIn) ->
UserName -> UserName ->
case parse_attribute(ClientNonceAttribute) of case parse_attribute(ClientNonceAttribute) of
{$r, ClientNonce} -> {$r, ClientNonce} ->
{Ret, AuthModule} = (State#state.get_password)(UserName), {Pass, AuthModule} = (State#state.get_password)(UserName),
case {Ret, jid:resourceprep(Ret)} of LPass = if is_binary(Pass) -> jid:resourceprep(Pass);
{false, _} -> {error, not_authorized, UserName}; true -> Pass
{_, error} when is_binary(Ret) -> {error, saslprep_failed, UserName}; end,
{Ret, _} -> if Pass == false ->
{error, not_authorized, UserName};
LPass == error ->
{error, saslprep_failed, UserName};
true ->
{StoredKey, ServerKey, Salt, IterationCount} = {StoredKey, ServerKey, Salt, IterationCount} =
if is_tuple(Ret) -> Ret; if is_tuple(Pass) -> Pass;
true -> true ->
TempSalt = TempSalt =
randoms:bytes(?SALT_LENGTH), randoms:bytes(?SALT_LENGTH),
SaltedPassword = SaltedPassword =
scram:salted_password(Ret, scram:salted_password(Pass,
TempSalt, TempSalt,
?SCRAM_DEFAULT_ITERATION_COUNT), ?SCRAM_DEFAULT_ITERATION_COUNT),
{scram:stored_key(scram:client_key(SaltedPassword)), {scram:stored_key(scram:client_key(SaltedPassword)),

View File

@ -49,6 +49,10 @@
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("logger.hrl"). -include("logger.hrl").
-type scrammed_password() :: {binary(), binary(), binary(), non_neg_integer()}.
-type password() :: binary() | scrammed_password().
-export_type([password/0]).
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% API %%% API
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -73,8 +77,8 @@
-callback get_vh_registered_users(binary(), opts()) -> [{binary(), binary()}]. -callback get_vh_registered_users(binary(), opts()) -> [{binary(), binary()}].
-callback get_vh_registered_users_number(binary()) -> number(). -callback get_vh_registered_users_number(binary()) -> number().
-callback get_vh_registered_users_number(binary(), opts()) -> number(). -callback get_vh_registered_users_number(binary(), opts()) -> number().
-callback get_password(binary(), binary()) -> false | binary() | {binary(), binary(), binary(), integer()}. -callback get_password(binary(), binary()) -> false | password().
-callback get_password_s(binary(), binary()) -> binary() | {binary(), binary(), binary(), integer()}. -callback get_password_s(binary(), binary()) -> password().
start() -> start() ->
%% This is only executed by ejabberd_c2s for non-SASL auth client %% This is only executed by ejabberd_c2s for non-SASL auth client
@ -270,7 +274,7 @@ get_vh_registered_users_number(Server, Opts) ->
end, end,
auth_modules(Server))). auth_modules(Server))).
-spec get_password(binary(), binary()) -> false | binary() | {binary(), binary(), binary(), integer()}. -spec get_password(binary(), binary()) -> false | password().
get_password(User, Server) -> get_password(User, Server) ->
lists:foldl(fun (M, false) -> lists:foldl(fun (M, false) ->
@ -279,7 +283,7 @@ get_password(User, Server) ->
end, end,
false, auth_modules(Server)). false, auth_modules(Server)).
-spec get_password_s(binary(), binary()) -> binary() | {binary(), binary(), binary(), integer()}. -spec get_password_s(binary(), binary()) -> password().
get_password_s(User, Server) -> get_password_s(User, Server) ->
case get_password(User, Server) of case get_password(User, Server) of
@ -290,7 +294,7 @@ get_password_s(User, Server) ->
%% @doc Get the password of the user and the auth module. %% @doc Get the password of the user and the auth module.
%% @spec (User::string(), Server::string()) -> %% @spec (User::string(), Server::string()) ->
%% {Password::string(), AuthModule::atom()} | {false, none} %% {Password::string(), AuthModule::atom()} | {false, none}
-spec get_password_with_authmodule(binary(), binary()) -> {false | binary(), atom()}. -spec get_password_with_authmodule(binary(), binary()) -> {false | password(), module()}.
get_password_with_authmodule(User, Server) -> get_password_with_authmodule(User, Server) ->
%% Returns true if the user exists in the DB or if an anonymous user is logged %% Returns true if the user exists in the DB or if an anonymous user is logged

View File

@ -65,9 +65,9 @@
uids = [] :: [{binary()} | {binary(), binary()}], uids = [] :: [{binary()} | {binary(), binary()}],
ufilter = <<"">> :: binary(), ufilter = <<"">> :: binary(),
sfilter = <<"">> :: binary(), sfilter = <<"">> :: binary(),
lfilter :: {any(), any()}, lfilter :: {any(), any()} | undefined,
deref_aliases = never :: never | searching | finding | always, deref_aliases = never :: never | searching | finding | always,
dn_filter :: binary(), dn_filter :: binary() | undefined,
dn_filter_attrs = [] :: [binary()]}). dn_filter_attrs = [] :: [binary()]}).
handle_cast(_Request, State) -> {noreply, State}. handle_cast(_Request, State) -> {noreply, State}.

View File

@ -99,15 +99,15 @@
el_ibuf = buf_new() :: ?TQUEUE, el_ibuf = buf_new() :: ?TQUEUE,
el_obuf = buf_new() :: ?TQUEUE, el_obuf = buf_new() :: ?TQUEUE,
shaper_state = none :: shaper:shaper(), shaper_state = none :: shaper:shaper(),
c2s_pid :: pid(), c2s_pid :: pid() | undefined,
xmpp_ver = <<"">> :: binary(), xmpp_ver = <<"">> :: binary(),
inactivity_timer :: reference(), inactivity_timer :: reference() | undefined,
wait_timer :: reference(), wait_timer :: reference() | undefined,
wait_timeout = ?DEFAULT_WAIT :: timeout(), wait_timeout = ?DEFAULT_WAIT :: timeout(),
inactivity_timeout = ?DEFAULT_INACTIVITY :: timeout(), inactivity_timeout = ?DEFAULT_INACTIVITY :: timeout(),
prev_rid = 0 :: non_neg_integer(), prev_rid = 0 :: non_neg_integer(),
prev_key = <<"">> :: binary(), prev_key = <<"">> :: binary(),
prev_poll :: erlang:timestamp(), prev_poll :: erlang:timestamp() | undefined,
max_concat = unlimited :: unlimited | non_neg_integer(), max_concat = unlimited :: unlimited | non_neg_integer(),
responses = gb_trees:empty() :: ?TGB_TREE, responses = gb_trees:empty() :: ?TGB_TREE,
receivers = gb_trees:empty() :: ?TGB_TREE, receivers = gb_trees:empty() :: ?TGB_TREE,

View File

@ -48,7 +48,7 @@
%% API %% API
-export([get_presence/1, get_subscription/2, get_subscribed/1, -export([get_presence/1, get_subscription/2, get_subscribed/1,
open_session/1, call/3, send/2, close/1, close/2, stop/1, open_session/1, call/3, send/2, close/1, close/2, stop/1,
reply/2, copy_state/2, set_timeout/2, add_hooks/1]). reply/2, copy_state/2, set_timeout/2, route/2, add_hooks/1]).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("xmpp.hrl"). -include("xmpp.hrl").
@ -110,12 +110,18 @@ get_subscription(LFrom, #{pres_f := PresF, pres_t := PresT}) ->
get_subscribed(Ref) -> get_subscribed(Ref) ->
call(Ref, get_subscribed, 1000). call(Ref, get_subscribed, 1000).
-spec close(pid()) -> ok;
(state()) -> state().
close(Ref) -> close(Ref) ->
xmpp_stream_in:close(Ref). xmpp_stream_in:close(Ref).
-spec close(pid(), boolean()) -> ok;
(state(), boolean()) -> state().
close(Ref, SendTrailer) -> close(Ref, SendTrailer) ->
xmpp_stream_in:close(Ref, SendTrailer). xmpp_stream_in:close(Ref, SendTrailer).
-spec stop(pid()) -> ok;
(state()) -> no_return().
stop(Ref) -> stop(Ref) ->
xmpp_stream_in:stop(Ref). xmpp_stream_in:stop(Ref).
@ -130,6 +136,11 @@ send(#{lserver := LServer} = State, Pkt) ->
{Pkt2, State1} -> xmpp_stream_in:send(State1, Pkt2) {Pkt2, State1} -> xmpp_stream_in:send(State1, Pkt2)
end. end.
-spec route(pid(), term()) -> ok.
route(Pid, Term) ->
Pid ! Term,
ok.
-spec set_timeout(state(), timeout()) -> state(). -spec set_timeout(state(), timeout()) -> state().
set_timeout(State, Timeout) -> set_timeout(State, Timeout) ->
xmpp_stream_in:set_timeout(State, Timeout). xmpp_stream_in:set_timeout(State, Timeout).
@ -579,8 +590,6 @@ process_presence_in(#{lserver := LServer, pres_a := PresA} = State0,
{true, State#{pres_a => A}}; {true, State#{pres_a => A}};
_ -> _ ->
case privacy_check_packet(State, Pres, in) of case privacy_check_packet(State, Pres, in) of
allow when T == error ->
{true, State};
allow -> allow ->
NewState = add_to_pres_a(State, From), NewState = add_to_pres_a(State, From),
{true, NewState}; {true, NewState};

View File

@ -918,7 +918,7 @@ v_dbs_mods(Mod) ->
default_db(Module) -> default_db(Module) ->
default_db(global, Module). default_db(global, Module).
-spec default_db(binary(), module()) -> atom(). -spec default_db(binary() | global, module()) -> atom().
default_db(Host, Module) -> default_db(Host, Module) ->
default_db(default_db, Host, Module). default_db(default_db, Host, Module).
@ -926,14 +926,13 @@ default_db(Host, Module) ->
default_ram_db(Module) -> default_ram_db(Module) ->
default_ram_db(global, Module). default_ram_db(global, Module).
-spec default_ram_db(binary(), module()) -> atom(). -spec default_ram_db(binary() | global, module()) -> atom().
default_ram_db(Host, Module) -> default_ram_db(Host, Module) ->
default_db(default_ram_db, Host, Module). default_db(default_ram_db, Host, Module).
-spec default_db(default_db | default_ram_db, binary(), module()) -> atom(). -spec default_db(default_db | default_ram_db, binary() | global, module()) -> atom().
default_db(Opt, Host, Module) -> default_db(Opt, Host, Module) ->
case ejabberd_config:get_option( case get_option({Opt, Host}, fun(T) when is_atom(T) -> T end) of
{Opt, Host}, fun(T) when is_atom(T) -> T end) of
undefined -> undefined ->
mnesia; mnesia;
DBType -> DBType ->
@ -1438,9 +1437,7 @@ opt_type(_) ->
[hide_sensitive_log_data, hosts, language, [hide_sensitive_log_data, hosts, language,
default_db, default_ram_db]. default_db, default_ram_db].
-spec may_hide_data(string()) -> string(); -spec may_hide_data(any()) -> any().
(binary()) -> binary().
may_hide_data(Data) -> may_hide_data(Data) ->
case ejabberd_config:get_option( case ejabberd_config:get_option(
hide_sensitive_log_data, hide_sensitive_log_data,

View File

@ -50,12 +50,12 @@
{socket :: ws_socket(), {socket :: ws_socket(),
ping_interval = ?PING_INTERVAL :: non_neg_integer(), ping_interval = ?PING_INTERVAL :: non_neg_integer(),
ping_timer = make_ref() :: reference(), ping_timer = make_ref() :: reference(),
pong_expected :: boolean(), pong_expected = false :: boolean(),
timeout = ?WEBSOCKET_TIMEOUT :: non_neg_integer(), timeout = ?WEBSOCKET_TIMEOUT :: non_neg_integer(),
timer = make_ref() :: reference(), timer = make_ref() :: reference(),
input = [] :: list(), input = [] :: list(),
waiting_input = false :: false | pid(), waiting_input = false :: false | pid(),
last_receiver :: pid(), last_receiver = self() :: pid(),
ws :: {#ws{}, pid()}, ws :: {#ws{}, pid()},
rfc_compilant = undefined :: boolean() | undefined}). rfc_compilant = undefined :: boolean() | undefined}).

View File

@ -61,10 +61,10 @@
-define(NS_PIEFXIS, <<"http://www.xmpp.org/extensions/xep-0227.html#ns">>). -define(NS_PIEFXIS, <<"http://www.xmpp.org/extensions/xep-0227.html#ns">>).
-define(NS_XI, <<"http://www.w3.org/2001/XInclude">>). -define(NS_XI, <<"http://www.w3.org/2001/XInclude">>).
-record(state, {xml_stream_state :: fxml_stream:xml_stream_state(), -record(state, {xml_stream_state :: fxml_stream:xml_stream_state() | undefined,
user = <<"">> :: binary(), user = <<"">> :: binary(),
server = <<"">> :: binary(), server = <<"">> :: binary(),
fd :: file:io_device(), fd = self() :: file:io_device(),
dir = <<"">> :: binary()}). dir = <<"">> :: binary()}).
-type state() :: #state{}. -type state() :: #state{}.

View File

@ -54,9 +54,9 @@
{socket :: inet:socket() | fast_tls:tls_socket() | ezlib:zlib_socket(), {socket :: inet:socket() | fast_tls:tls_socket() | ezlib:zlib_socket(),
sock_mod = gen_tcp :: gen_tcp | fast_tls | ezlib, sock_mod = gen_tcp :: gen_tcp | fast_tls | ezlib,
shaper_state = none :: shaper:shaper(), shaper_state = none :: shaper:shaper(),
c2s_pid :: pid(), c2s_pid :: pid() | undefined,
max_stanza_size = infinity :: non_neg_integer() | infinity, max_stanza_size = infinity :: non_neg_integer() | infinity,
xml_stream_state :: fxml_stream:xml_stream_state(), xml_stream_state :: fxml_stream:xml_stream_state() | undefined,
timeout = infinity:: timeout()}). timeout = infinity:: timeout()}).
-define(HIBERNATE_TIMEOUT, ejabberd_config:get_option(receiver_hibernate, fun(X) when is_integer(X); X == hibernate-> X end, 90000)). -define(HIBERNATE_TIMEOUT, ejabberd_config:get_option(receiver_hibernate, fun(X) when is_integer(X); X == hibernate-> X end, 90000)).

View File

@ -61,7 +61,7 @@
%% the first element of the record is assumed as a primary index, %% the first element of the record is assumed as a primary index,
%% i.e. `i' = element(2, Record). %% i.e. `i' = element(2, Record).
-export_types([index_info/0]). -export_type([index_info/0]).
%%%=================================================================== %%%===================================================================
%%% API %%% API

View File

@ -144,7 +144,7 @@ route_error(From, To, Packet, #stanza_error{} = Err) ->
register_route(Domain, ServerHost) -> register_route(Domain, ServerHost) ->
register_route(Domain, ServerHost, undefined). register_route(Domain, ServerHost, undefined).
-spec register_route(binary(), binary(), local_hint()) -> ok. -spec register_route(binary(), binary(), local_hint() | undefined) -> ok.
register_route(Domain, ServerHost, LocalHint) -> register_route(Domain, ServerHost, LocalHint) ->
case {jid:nameprep(Domain), jid:nameprep(ServerHost)} of case {jid:nameprep(Domain), jid:nameprep(ServerHost)} of
{error, _} -> {error, _} ->

View File

@ -66,12 +66,17 @@ start_link(From, To, Opts) ->
xmpp_stream_out:start_link(?MODULE, [ejabberd_socket, From, To, Opts], xmpp_stream_out:start_link(?MODULE, [ejabberd_socket, From, To, Opts],
ejabberd_config:fsm_limit_opts([])). ejabberd_config:fsm_limit_opts([])).
-spec connect(pid()) -> ok.
connect(Ref) -> connect(Ref) ->
xmpp_stream_out:connect(Ref). xmpp_stream_out:connect(Ref).
-spec close(pid()) -> ok;
(state()) -> state().
close(Ref) -> close(Ref) ->
xmpp_stream_out:close(Ref). xmpp_stream_out:close(Ref).
-spec stop(pid()) -> ok;
(state()) -> no_return().
stop(Ref) -> stop(Ref) ->
xmpp_stream_out:stop(Ref). xmpp_stream_out:stop(Ref).
@ -82,7 +87,8 @@ send(Stream, Pkt) ->
-spec route(pid(), xmpp_element()) -> ok. -spec route(pid(), xmpp_element()) -> ok.
route(Ref, Pkt) -> route(Ref, Pkt) ->
Ref ! {route, Pkt}. Ref ! {route, Pkt},
ok.
-spec establish(state()) -> state(). -spec establish(state()) -> state().
establish(State) -> establish(State) ->

View File

@ -494,7 +494,7 @@ do_route(To, Term) ->
Session = lists:max(Ss), Session = lists:max(Ss),
Pid = element(2, Session#session.sid), Pid = element(2, Session#session.sid),
?DEBUG("sending to process ~p: ~p", [Pid, Term]), ?DEBUG("sending to process ~p: ~p", [Pid, Term]),
Pid ! Term ejabberd_c2s:route(Pid, Term)
end. end.
-spec do_route(stanza()) -> any(). -spec do_route(stanza()) -> any().
@ -520,7 +520,7 @@ do_route(#presence{from = From, to = To, type = T, status = Status} = Packet)
Packet1 = Packet#presence{to = jid:replace_resource(To, R)}, Packet1 = Packet#presence{to = jid:replace_resource(To, R)},
?DEBUG("sending to process ~p:~n~s", ?DEBUG("sending to process ~p:~n~s",
[Pid, xmpp:pp(Packet1)]), [Pid, xmpp:pp(Packet1)]),
Pid ! {route, Packet1}; ejabberd_c2s:route(Pid, {route, Packet1});
(_) -> (_) ->
ok ok
end, online(Mod:get_sessions(LUser, LServer))); end, online(Mod:get_sessions(LUser, LServer)));
@ -571,7 +571,7 @@ do_route(Packet) ->
Session = lists:max(Ss), Session = lists:max(Ss),
Pid = element(2, Session#session.sid), Pid = element(2, Session#session.sid),
?DEBUG("sending to process ~p:~n~s", [Pid, xmpp:pp(Packet)]), ?DEBUG("sending to process ~p:~n~s", [Pid, xmpp:pp(Packet)]),
Pid ! {route, Packet} ejabberd_c2s:route(Pid, {route, Packet})
end. end.
%% The default list applies to the user as a whole, %% The default list applies to the user as a whole,
@ -611,7 +611,7 @@ route_message(#message{to = To, type = Type} = Packet) ->
LResource, LResource,
LMaxRes, LMaxRes,
P, MaxPrio), P, MaxPrio),
Pid ! {route, Packet1} ejabberd_c2s:route(Pid, {route, Packet1})
end; end;
%% Ignore other priority: %% Ignore other priority:
({_Prio, _Res}) -> ok ({_Prio, _Res}) -> ok
@ -680,7 +680,7 @@ check_existing_resources(LUser, LServer, LResource) ->
SIDs = [SID || #session{sid = SID} <- OnlineSs], SIDs = [SID || #session{sid = SID} <- OnlineSs],
MaxSID = lists:max(SIDs), MaxSID = lists:max(SIDs),
lists:foreach(fun ({_, Pid} = S) when S /= MaxSID -> lists:foreach(fun ({_, Pid} = S) when S /= MaxSID ->
Pid ! replaced; ejabberd_c2s:route(Pid, replaced);
(_) -> ok (_) -> ok
end, end,
SIDs) SIDs)
@ -708,7 +708,7 @@ check_max_sessions(LUser, LServer) ->
if length(OnlineSs) =< MaxSessions -> ok; if length(OnlineSs) =< MaxSessions -> ok;
true -> true ->
#session{sid = {_, Pid}} = lists:min(OnlineSs), #session{sid = {_, Pid}} = lists:min(OnlineSs),
Pid ! replaced ejabberd_c2s:route(Pid, replaced)
end, end,
if length(OfflineSs) =< MaxSessions -> ok; if length(OfflineSs) =< MaxSessions -> ok;
true -> true ->
@ -762,7 +762,7 @@ force_update_presence({LUser, LServer}) ->
Mod = get_sm_backend(LServer), Mod = get_sm_backend(LServer),
Ss = online(Mod:get_sessions(LUser, LServer)), Ss = online(Mod:get_sessions(LUser, LServer)),
lists:foreach(fun (#session{sid = {_, Pid}}) -> lists:foreach(fun (#session{sid = {_, Pid}}) ->
Pid ! force_update_presence ejabberd_c2s:route(Pid, force_update_presence)
end, end,
Ss). Ss).
@ -842,7 +842,7 @@ kick_user(User, Server) ->
lists:foreach( lists:foreach(
fun(Resource) -> fun(Resource) ->
PID = get_session_pid(User, Server, Resource), PID = get_session_pid(User, Server, Resource),
PID ! kick ejabberd_c2s:route(PID, kick)
end, Resources), end, Resources),
length(Resources). length(Resources).

View File

@ -62,7 +62,8 @@
-type socket() :: pid() | inet:socket() | -type socket() :: pid() | inet:socket() |
fast_tls:tls_socket() | fast_tls:tls_socket() |
ezlib:zlib_socket() | ezlib:zlib_socket() |
ejabberd_bosh:bind_socket(). ejabberd_bosh:bosh_socket() |
ejabberd_http_ws:ws_socket().
-record(socket_state, {sockmod = gen_tcp :: sockmod(), -record(socket_state, {sockmod = gen_tcp :: sockmod(),
socket = self() :: socket(), socket = self() :: socket(),
@ -85,7 +86,7 @@
%%==================================================================== %%====================================================================
%% API %% API
%%==================================================================== %%====================================================================
-spec start(atom(), sockmod(), socket(), [proplists:propery()]) -spec start(atom(), sockmod(), socket(), [proplists:property()])
-> {ok, pid() | independent} | {error, inet:posix() | any()}. -> {ok, pid() | independent} | {error, inet:posix() | any()}.
start(Module, SockMod, Socket, Opts) -> start(Module, SockMod, Socket, Opts) ->
case Module:socket_type() of case Module:socket_type() of

View File

@ -46,7 +46,7 @@
-record(state, -record(state,
{access_commands = [] :: list(), {access_commands = [] :: list(),
auth = noauth :: noauth | {binary(), binary(), binary()}, auth = noauth :: noauth | map(),
get_auth = true :: boolean(), get_auth = true :: boolean(),
ip :: inet:ip_address()}). ip :: inet:ip_address()}).

View File

@ -126,14 +126,14 @@
-record(eldap, -record(eldap,
{version = ?LDAP_VERSION :: non_neg_integer(), {version = ?LDAP_VERSION :: non_neg_integer(),
hosts = [] :: [binary()], hosts = [] :: [binary()],
host :: binary(), host = undefined :: binary() | undefined,
port = 389 :: inet:port_number(), port = 389 :: inet:port_number(),
sockmod = gen_tcp :: ssl | gen_tcp, sockmod = gen_tcp :: ssl | gen_tcp,
tls = none :: none | tls, tls = none :: none | tls,
tls_options = [] :: [{cacertfile, string()} | tls_options = [] :: [{cacertfile, string()} |
{depth, non_neg_integer()} | {depth, non_neg_integer()} |
{verify, non_neg_integer()}], {verify, non_neg_integer()}],
fd, fd :: gen_tcp:socket() | undefined,
rootdn = <<"">> :: binary(), rootdn = <<"">> :: binary(),
passwd = <<"">> :: binary(), passwd = <<"">> :: binary(),
id = 0 :: non_neg_integer(), id = 0 :: non_neg_integer(),

View File

@ -91,7 +91,7 @@ start_child(Mod, Host, Opts, Proc) ->
transient, 2000, worker, [Mod]}, transient, 2000, worker, [Mod]},
supervisor:start_child(ejabberd_gen_mod_sup, Spec). supervisor:start_child(ejabberd_gen_mod_sup, Spec).
-spec stop_child(module(), binary() | global) -> ok. -spec stop_child(module(), binary() | global) -> ok | {error, any()}.
stop_child(Mod, Host) -> stop_child(Mod, Host) ->
stop_child(get_module_proc(Host, Mod)). stop_child(get_module_proc(Host, Mod)).
@ -437,7 +437,7 @@ db_type(Host, Module) when is_atom(Module) ->
undefined undefined
end. end.
-spec db_type(binary(), opts(), module()) -> db_type(). -spec db_type(binary() | global, opts(), module()) -> db_type().
db_type(Host, Opts, Module) -> db_type(Host, Opts, Module) ->
case catch Module:mod_opt_type(db_type) of case catch Module:mod_opt_type(db_type) of
@ -477,7 +477,7 @@ ram_db_type(Host, Module) when is_atom(Module) ->
undefined undefined
end. end.
-spec ram_db_type(binary(), opts(), module()) -> db_type(). -spec ram_db_type(binary() | global, opts(), module()) -> db_type().
ram_db_type(Host, Opts, Module) -> ram_db_type(Host, Opts, Module) ->
case catch Module:mod_opt_type(ram_db_type) of case catch Module:mod_opt_type(ram_db_type) of
F when is_function(F) -> F when is_function(F) ->

View File

@ -83,7 +83,7 @@
-callback purge_node(NodeIdx :: nodeIdx(), -callback purge_node(NodeIdx :: nodeIdx(),
Owner :: jid()) -> Owner :: jid()) ->
{result, {default, broadcast}} | {result, {default, broadcast}} |
{error, xmlel()}. {error, stanza_error()}.
-callback subscribe_node(NodeIdx :: nodeIdx(), -callback subscribe_node(NodeIdx :: nodeIdx(),
Sender :: jid(), Sender :: jid(),
@ -96,14 +96,14 @@
{result, {default, subscribed, subId()}} | {result, {default, subscribed, subId()}} |
{result, {default, subscribed, subId(), send_last}} | {result, {default, subscribed, subId(), send_last}} |
{result, {default, pending, subId()}} | {result, {default, pending, subId()}} |
{error, xmlel()}. {error, stanza_error()}.
-callback unsubscribe_node(NodeIdx :: nodeIdx(), -callback unsubscribe_node(NodeIdx :: nodeIdx(),
Sender :: jid(), Sender :: jid(),
Subscriber :: jid(), Subscriber :: jid(),
SubId :: subId()) -> SubId :: subId()) ->
{result, default} | {result, []} |
{error, xmlel()}. {error, stanza_error()}.
-callback publish_item(NodeId :: nodeIdx(), -callback publish_item(NodeId :: nodeIdx(),
Publisher :: jid(), Publisher :: jid(),
@ -113,14 +113,14 @@
Payload :: payload(), Payload :: payload(),
Options :: pubOptions()) -> Options :: pubOptions()) ->
{result, {default, broadcast, [itemId()]}} | {result, {default, broadcast, [itemId()]}} |
{error, xmlel()}. {error, stanza_error()}.
-callback delete_item(NodeIdx :: nodeIdx(), -callback delete_item(NodeIdx :: nodeIdx(),
Publisher :: jid(), Publisher :: jid(),
PublishModel :: publishModel(), PublishModel :: publishModel(),
ItemId :: <<>> | itemId()) -> ItemId :: <<>> | itemId()) ->
{result, {default, broadcast}} | {result, {default, broadcast}} |
{error, xmlel()}. {error, stanza_error()}.
-callback remove_extra_items(NodeIdx :: nodeIdx(), -callback remove_extra_items(NodeIdx :: nodeIdx(),
Max_Items :: unlimited | non_neg_integer(), Max_Items :: unlimited | non_neg_integer(),
@ -143,7 +143,7 @@
Owner :: jid(), Owner :: jid(),
Affiliation :: affiliation()) -> Affiliation :: affiliation()) ->
ok | ok |
{error, xmlel()}. {error, stanza_error()}.
-callback get_node_subscriptions(NodeIdx :: nodeIdx()) -> -callback get_node_subscriptions(NodeIdx :: nodeIdx()) ->
{result, {result,
@ -173,7 +173,7 @@
-callback set_state(State::pubsubState()) -> -callback set_state(State::pubsubState()) ->
ok | ok |
{error, xmlel()}. {error, stanza_error()}.
-callback get_items(nodeIdx(), jid(), accessModel(), -callback get_items(nodeIdx(), jid(), accessModel(),
boolean(), boolean(), binary(), boolean(), boolean(), binary(),
@ -191,12 +191,12 @@
RosterGroup :: boolean(), RosterGroup :: boolean(),
SubId :: subId()) -> SubId :: subId()) ->
{result, pubsubItem()} | {result, pubsubItem()} |
{error, xmlel()}. {error, stanza_error()}.
-callback get_item(NodeIdx :: nodeIdx(), -callback get_item(NodeIdx :: nodeIdx(),
ItemId :: itemId()) -> ItemId :: itemId()) ->
{result, pubsubItem()} | {result, pubsubItem()} |
{error, xmlel()}. {error, stanza_error()}.
-callback set_item(Item :: pubsubItem()) -> -callback set_item(Item :: pubsubItem()) ->
ok. ok.

View File

@ -36,27 +36,29 @@
ServerHost :: binary(), ServerHost :: binary(),
Opts :: [any()]) -> atom(). Opts :: [any()]) -> atom().
-include("xmpp.hrl").
-callback terminate(Host :: host(), ServerHost :: binary()) -> atom(). -callback terminate(Host :: host(), ServerHost :: binary()) -> atom().
-callback options() -> nodeOptions(). -callback options() -> nodeOptions().
-callback set_node(PubsubNode :: pubsubNode()) -> -callback set_node(PubsubNode :: pubsubNode()) ->
ok | {result, NodeIdx::nodeIdx()} | {error, fxml:xmlel()}. ok | {result, NodeIdx::nodeIdx()} | {error, stanza_error()}.
-callback get_node(Host :: host(), -callback get_node(Host :: host(),
NodeId :: nodeId(), NodeId :: nodeId(),
From :: jid:jid()) -> From :: jid:jid()) ->
pubsubNode() | pubsubNode() |
{error, fxml:xmlel()}. {error, stanza_error()}.
-callback get_node(Host :: host(), -callback get_node(Host :: host(),
NodeId :: nodeId()) -> NodeId :: nodeId()) ->
pubsubNode() | pubsubNode() |
{error, fxml:xmlel()}. {error, stanza_error()}.
-callback get_node(NodeIdx :: nodeIdx()) -> -callback get_node(NodeIdx :: nodeIdx()) ->
pubsubNode() | pubsubNode() |
{error, fxml:xmlel()}. {error, stanza_error()}.
-callback get_nodes(Host :: host(), -callback get_nodes(Host :: host(),
From :: jid:jid())-> From :: jid:jid())->
@ -69,7 +71,7 @@
NodeId :: nodeId(), NodeId :: nodeId(),
From :: jid:jid()) -> From :: jid:jid()) ->
[pubsubNode()] | [pubsubNode()] |
{error, fxml:xmlel()}. {error, stanza_error()}.
-callback get_parentnodes_tree(Host :: host(), -callback get_parentnodes_tree(Host :: host(),
NodeId :: nodeId(), NodeId :: nodeId(),
@ -93,7 +95,7 @@
Options :: nodeOptions(), Options :: nodeOptions(),
Parents :: [nodeId()]) -> Parents :: [nodeId()]) ->
{ok, NodeIdx::nodeIdx()} | {ok, NodeIdx::nodeIdx()} |
{error, fxml:xmlel()} | {error, stanza_error()} |
{error, {virtual, {host(), nodeId()}}}. {error, {virtual, {host(), nodeId()}}}.
-callback delete_node(Host :: host(), -callback delete_node(Host :: host(),

View File

@ -41,7 +41,7 @@
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("logger.hrl"). -include("logger.hrl").
-include_lib("stdlib/include/ms_transform.hrl"). -include_lib("stdlib/include/ms_transform.hrl").
-include("jlib.hrl"). -include("xmpp.hrl").
-include("ejabberd_http.hrl"). -include("ejabberd_http.hrl").
-include("bosh.hrl"). -include("bosh.hrl").

View File

@ -88,7 +88,6 @@ c2s_auth_result(#{ip := {Addr, _}} = State, true, _User) ->
-spec c2s_stream_started(ejabberd_c2s:state(), stream_start()) -spec c2s_stream_started(ejabberd_c2s:state(), stream_start())
-> ejabberd_c2s:state() | {stop, ejabberd_c2s:state()}. -> ejabberd_c2s:state() | {stop, ejabberd_c2s:state()}.
c2s_stream_started(#{ip := {Addr, _}} = State, _) -> c2s_stream_started(#{ip := {Addr, _}} = State, _) ->
ets:tab2list(failed_auth),
case ets:lookup(failed_auth, Addr) of case ets:lookup(failed_auth, Addr) of
[{Addr, N, TS, MaxFailures}] when N >= MaxFailures -> [{Addr, N, TS, MaxFailures}] when N >= MaxFailures ->
case TS > p1_time_compat:system_time(seconds) of case TS > p1_time_compat:system_time(seconds) of
@ -161,7 +160,7 @@ code_change(_OldVsn, State, _Extra) ->
%%%=================================================================== %%%===================================================================
%%% Internal functions %%% Internal functions
%%%=================================================================== %%%===================================================================
-spec log_and_disconnect(ejabberd_c2s:state(), pos_integer(), erlang:timestamp()) -spec log_and_disconnect(ejabberd_c2s:state(), pos_integer(), non_neg_integer())
-> {stop, ejabberd_c2s:state()}. -> {stop, ejabberd_c2s:state()}.
log_and_disconnect(#{ip := {Addr, _}, lang := Lang} = State, Attempts, UnbanTS) -> log_and_disconnect(#{ip := {Addr, _}, lang := Lang} = State, Attempts, UnbanTS) ->
IP = jlib:ip_to_list(Addr), IP = jlib:ip_to_list(Addr),

View File

@ -121,7 +121,7 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% gen_mod/supervisor callbacks. %% gen_mod/supervisor callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}. -spec start(binary(), gen_mod:opts()) -> {ok, pid()}.
start(ServerHost, Opts) -> start(ServerHost, Opts) ->
case gen_mod:get_opt(rm_on_unregister, Opts, case gen_mod:get_opt(rm_on_unregister, Opts,
@ -136,7 +136,7 @@ start(ServerHost, Opts) ->
Proc = get_proc_name(ServerHost, ?MODULE), Proc = get_proc_name(ServerHost, ?MODULE),
gen_mod:start_child(?MODULE, ServerHost, Opts, Proc). gen_mod:start_child(?MODULE, ServerHost, Opts, Proc).
-spec stop(binary()) -> ok. -spec stop(binary()) -> ok | {error, any()}.
stop(ServerHost) -> stop(ServerHost) ->
case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister, case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister,
@ -211,7 +211,7 @@ depends(_Host, _Opts) ->
%% gen_server callbacks. %% gen_server callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec init({binary(), gen_mod:opts()}) -> {ok, state()}. -spec init(list()) -> {ok, state()}.
init([ServerHost, Opts]) -> init([ServerHost, Opts]) ->
process_flag(trap_exit, true), process_flag(trap_exit, true),
@ -694,7 +694,7 @@ map_int_to_char(N) when N =< 61 -> N + 61. % Lower-case character.
yield_content_type(<<"">>) -> ?DEFAULT_CONTENT_TYPE; yield_content_type(<<"">>) -> ?DEFAULT_CONTENT_TYPE;
yield_content_type(Type) -> Type. yield_content_type(Type) -> Type.
-spec iq_disco_info(binary(), binary(), binary(), [xdata()]) -> [xmlel()]. -spec iq_disco_info(binary(), binary(), binary(), [xdata()]) -> disco_info().
iq_disco_info(Host, Lang, Name, AddInfo) -> iq_disco_info(Host, Lang, Name, AddInfo) ->
Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size, Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size,

View File

@ -68,13 +68,13 @@
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% gen_mod/supervisor callbacks. %% gen_mod/supervisor callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}. -spec start(binary(), gen_mod:opts()) -> {ok, pid()}.
start(ServerHost, Opts) -> start(ServerHost, Opts) ->
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE), Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),
gen_mod:start_child(?MODULE, ServerHost, Opts, Proc). gen_mod:start_child(?MODULE, ServerHost, Opts, Proc).
-spec stop(binary()) -> ok. -spec stop(binary()) -> ok | {error, any()}.
stop(ServerHost) -> stop(ServerHost) ->
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE), Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),

View File

@ -46,7 +46,7 @@
-define(SETS, gb_sets). -define(SETS, gb_sets).
-record(state, -record(state,
{socket :: inet:socket(), {socket :: inet:socket() | undefined,
encoding = <<"">> :: binary(), encoding = <<"">> :: binary(),
port = 0 :: inet:port_number(), port = 0 :: inet:port_number(),
password = <<"">> :: binary(), password = <<"">> :: binary(),
@ -59,7 +59,7 @@
realname = <<"">> :: binary(), realname = <<"">> :: binary(),
nick = <<"">> :: binary(), nick = <<"">> :: binary(),
channels = dict:new() :: ?TDICT, channels = dict:new() :: ?TDICT,
nickchannel :: binary(), nickchannel :: binary() | undefined,
webirc_password :: binary(), webirc_password :: binary(),
mod = mod_irc :: atom(), mod = mod_irc :: atom(),
inbuf = <<"">> :: binary(), inbuf = <<"">> :: binary(),

View File

@ -51,9 +51,8 @@
-callback import(binary(), #last_activity{}) -> ok | pass. -callback import(binary(), #last_activity{}) -> ok | pass.
-callback get_last(binary(), binary()) -> -callback get_last(binary(), binary()) ->
{ok, non_neg_integer(), binary()} | not_found | {error, any()}. {ok, non_neg_integer(), binary()} | not_found | {error, any()}.
-callback store_last_info(binary(), binary(), non_neg_integer(), binary()) -> -callback store_last_info(binary(), binary(), non_neg_integer(), binary()) -> any().
{atomic, any()}. -callback remove_user(binary(), binary()) -> any().
-callback remove_user(binary(), binary()) -> {atomic, any()}.
start(Host, Opts) -> start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1, IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
@ -197,7 +196,7 @@ get_last_iq(#iq{lang = Lang} = IQ, LUser, LServer) ->
xmpp:make_iq_result(IQ, #last{seconds = 0}) xmpp:make_iq_result(IQ, #last{seconds = 0})
end. end.
-spec register_user(binary(), binary()) -> {atomic, any()}. -spec register_user(binary(), binary()) -> any().
register_user(User, Server) -> register_user(User, Server) ->
on_presence_update( on_presence_update(
User, User,
@ -205,13 +204,12 @@ register_user(User, Server) ->
<<"RegisterResource">>, <<"RegisterResource">>,
<<"Registered but didn't login">>). <<"Registered but didn't login">>).
-spec on_presence_update(binary(), binary(), binary(), binary()) -> {atomic, any()}. -spec on_presence_update(binary(), binary(), binary(), binary()) -> any().
on_presence_update(User, Server, _Resource, Status) -> on_presence_update(User, Server, _Resource, Status) ->
TimeStamp = p1_time_compat:system_time(seconds), TimeStamp = p1_time_compat:system_time(seconds),
store_last_info(User, Server, TimeStamp, Status). store_last_info(User, Server, TimeStamp, Status).
-spec store_last_info(binary(), binary(), non_neg_integer(), binary()) -> -spec store_last_info(binary(), binary(), non_neg_integer(), binary()) -> any().
{atomic, any()}.
store_last_info(User, Server, TimeStamp, Status) -> store_last_info(User, Server, TimeStamp, Status) ->
LUser = jid:nodeprep(User), LUser = jid:nodeprep(User),
LServer = jid:nameprep(Server), LServer = jid:nameprep(Server),

View File

@ -146,7 +146,7 @@ open_session(State, IQ, R) ->
ejabberd_c2s:send(State1, Res) ejabberd_c2s:send(State1, Res)
end. end.
-spec process_auth_failure(c2s_state(), binary(), stanza_error(), atom()) -> c2s_state(). -spec process_auth_failure(c2s_state(), binary(), iq(), atom()) -> c2s_state().
process_auth_failure(State, User, StanzaErr, Reason) -> process_auth_failure(State, User, StanzaErr, Reason) ->
State1 = ejabberd_c2s:send(State, StanzaErr), State1 = ejabberd_c2s:send(State, StanzaErr),
ejabberd_c2s:handle_auth_failure(User, <<"legacy">>, Reason, State1). ejabberd_c2s:handle_auth_failure(User, <<"legacy">>, Reason, State1).

View File

@ -648,7 +648,7 @@ has_no_store_hint(Message) ->
-spec is_resent(message(), binary()) -> boolean(). -spec is_resent(message(), binary()) -> boolean().
is_resent(Pkt, LServer) -> is_resent(Pkt, LServer) ->
case xmpp:get_subtag(Pkt, #stanza_id{}) of case xmpp:get_subtag(Pkt, #stanza_id{by = #jid{}}) of
#stanza_id{by = #jid{lserver = LServer}} -> #stanza_id{by = #jid{lserver = LServer}} ->
true; true;
_ -> _ ->

View File

@ -781,7 +781,7 @@ process_iq_register_set(ServerHost, Host, From,
{error, xmpp:err_not_acceptable(ErrText, Lang)} {error, xmpp:err_not_acceptable(ErrText, Lang)}
end. end.
-spec broadcast_service_message(binary(), binary(), message()) -> ok. -spec broadcast_service_message(binary(), binary(), binary()) -> ok.
broadcast_service_message(ServerHost, Host, Msg) -> broadcast_service_message(ServerHost, Host, Msg) ->
lists:foreach( lists:foreach(
fun({_, _, Pid}) -> fun({_, _, Pid}) ->

View File

@ -232,7 +232,7 @@ get_online_rooms(Action, Key, Host, Count, Max, Items) ->
{ok, Pid} -> {ok, Pid} ->
get_online_rooms(NewAction, NewKey, Host, get_online_rooms(NewAction, NewKey, Host,
Count + 1, Max, [{Room, Host, Pid}|Items]); Count + 1, Max, [{Room, Host, Pid}|Items]);
{error, _} -> error ->
get_online_rooms(NewAction, NewKey, Host, get_online_rooms(NewAction, NewKey, Host,
Count, Max, Items) Count, Max, Items)
end; end;

View File

@ -305,8 +305,6 @@ normal_state({route, <<"">>,
{xmpp:make_iq_result(IQ, Res), StateData}; {xmpp:make_iq_result(IQ, Res), StateData};
{ignore, SD} -> {ignore, SD} ->
{ignore, SD}; {ignore, SD};
{error, Error, ResStateData} ->
{xmpp:make_error(IQ0, Error), ResStateData};
{error, Error} -> {error, Error} ->
{xmpp:make_error(IQ0, Error), StateData} {xmpp:make_error(IQ0, Error), StateData}
end, end,
@ -559,13 +557,7 @@ handle_sync_event({muc_subscribe, From, Nick, Nodes}, _From,
NewConfig = (NewState#state.config)#config{ NewConfig = (NewState#state.config)#config{
captcha_protected = CaptchaRequired, captcha_protected = CaptchaRequired,
password_protected = PasswordProtected}, password_protected = PasswordProtected},
{reply, {error, <<"Requrest is ignored">>}, {reply, {error, <<"Request is ignored">>},
NewState#state{config = NewConfig}};
{error, Err, NewState} ->
NewConfig = (NewState#state.config)#config{
captcha_protected = CaptchaRequired,
password_protected = PasswordProtected},
{reply, {error, get_error_text(Err)}, StateName,
NewState#state{config = NewConfig}}; NewState#state{config = NewConfig}};
{error, Err} -> {error, Err} ->
{reply, {error, get_error_text(Err)}, StateName, StateData} {reply, {error, get_error_text(Err)}, StateName, StateData}
@ -577,9 +569,7 @@ handle_sync_event({muc_unsubscribe, From}, _From, StateName, StateData) ->
{result, _, NewState} -> {result, _, NewState} ->
{reply, ok, StateName, NewState}; {reply, ok, StateName, NewState};
{ignore, NewState} -> {ignore, NewState} ->
{reply, {error, <<"Requrest is ignored">>}, NewState}; {reply, {error, <<"Request is ignored">>}, NewState};
{error, Err, NewState} ->
{reply, {error, get_error_text(Err)}, StateName, NewState};
{error, Err} -> {error, Err} ->
{reply, {error, get_error_text(Err)}, StateName, StateData} {reply, {error, get_error_text(Err)}, StateName, StateData}
end; end;
@ -984,8 +974,7 @@ process_presence(From, Nick, #presence{type = Type0} = Packet0, StateData) ->
{next_state, normal_state, StateData} {next_state, normal_state, StateData}
end. end.
-spec do_process_presence(jid(), binary(), presence(), state()) -> -spec do_process_presence(jid(), binary(), presence(), state()) -> state().
state().
do_process_presence(From, Nick, #presence{type = available, lang = Lang} = Packet, do_process_presence(From, Nick, #presence{type = available, lang = Lang} = Packet,
StateData) -> StateData) ->
case is_user_online(From, StateData) of case is_user_online(From, StateData) of
@ -1077,6 +1066,7 @@ close_room_if_temporary_and_empty(StateData1) ->
_ -> {next_state, normal_state, StateData1} _ -> {next_state, normal_state, StateData1}
end. end.
-spec get_users_and_subscribers(state()) -> ?TDICT.
get_users_and_subscribers(StateData) -> get_users_and_subscribers(StateData) ->
OnlineSubscribers = ?DICT:fold( OnlineSubscribers = ?DICT:fold(
fun(LJID, _, Acc) -> fun(LJID, _, Acc) ->
@ -1236,8 +1226,9 @@ get_error_condition(#stanza_error{reason = Reason}) ->
get_error_condition(undefined) -> get_error_condition(undefined) ->
"undefined". "undefined".
get_error_text(Error) -> -spec get_error_text(stanza_error()) -> binary().
(Error#stanza_error.text)#text.data. get_error_text(#stanza_error{text = Txt}) ->
xmpp:get_text([Txt]).
-spec make_reason(stanza(), jid(), state(), binary()) -> binary(). -spec make_reason(stanza(), jid(), state(), binary()) -> binary().
make_reason(Packet, From, StateData, Reason1) -> make_reason(Packet, From, StateData, Reason1) ->
@ -1514,7 +1505,7 @@ store_user_activity(JID, UserActivity, StateData) ->
end, end,
StateData1. StateData1.
-spec clean_treap(treap:treap(), integer()) -> treap:treap(). -spec clean_treap(treap:treap(), integer() | {1, integer()}) -> treap:treap().
clean_treap(Treap, CleanPriority) -> clean_treap(Treap, CleanPriority) ->
case treap:is_empty(Treap) of case treap:is_empty(Treap) of
true -> Treap; true -> Treap;
@ -1750,11 +1741,10 @@ nick_collision(User, Nick, StateData) ->
jid:remove_resource(jid:tolower(UserOfNick)) jid:remove_resource(jid:tolower(UserOfNick))
/= jid:remove_resource(jid:tolower(User))). /= jid:remove_resource(jid:tolower(User))).
-spec add_new_user(jid(), binary(), presence() | iq(), state()) -> -spec add_new_user(jid(), binary(), presence(), state()) -> state();
state() | (jid(), binary(), iq(), state()) -> {error, stanza_error()} |
{error, stanza_error()} |
{ignore, state()} | {ignore, state()} |
{result, xmpp_element(), state()}. {result, muc_subscribe(), state()}.
add_new_user(From, Nick, Packet, StateData) -> add_new_user(From, Nick, Packet, StateData) ->
Lang = xmpp:get_lang(Packet), Lang = xmpp:get_lang(Packet),
MaxUsers = get_max_users(StateData), MaxUsers = get_max_users(StateData),
@ -1874,7 +1864,7 @@ add_new_user(From, Nick, Packet, StateData) ->
if not IsSubscribeRequest -> ResultState; if not IsSubscribeRequest -> ResultState;
true -> {result, subscribe_result(Packet), ResultState} true -> {result, subscribe_result(Packet), ResultState}
end; end;
nopass -> need_password ->
ErrText = <<"A password is required to enter this room">>, ErrText = <<"A password is required to enter this room">>,
Err = xmpp:err_not_authorized(ErrText, Lang), Err = xmpp:err_not_authorized(ErrText, Lang),
if not IsSubscribeRequest -> if not IsSubscribeRequest ->
@ -1937,7 +1927,8 @@ add_new_user(From, Nick, Packet, StateData) ->
end. end.
-spec check_password(affiliation(), affiliation(), -spec check_password(affiliation(), affiliation(),
stanza(), jid(), state()) -> boolean() | nopass. presence() | iq(), jid(), state()) ->
boolean() | need_password | captcha_required.
check_password(owner, _Affiliation, _Packet, _From, check_password(owner, _Affiliation, _Packet, _From,
_StateData) -> _StateData) ->
%% Don't check pass if user is owner in MUC service (access_admin option) %% Don't check pass if user is owner in MUC service (access_admin option)
@ -1950,7 +1941,7 @@ check_password(_ServiceAffiliation, Affiliation, Packet,
true -> true ->
Pass = extract_password(Packet), Pass = extract_password(Packet),
case Pass of case Pass of
false -> nopass; false -> need_password;
_ -> _ ->
case (StateData#state.config)#config.password of case (StateData#state.config)#config.password of
Pass -> true; Pass -> true;
@ -1988,13 +1979,17 @@ check_captcha(Affiliation, From, StateData) ->
_ -> true _ -> true
end. end.
-spec extract_password(stanza()) -> binary() | false. -spec extract_password(presence() | iq()) -> binary() | false.
extract_password(Packet) -> extract_password(#presence{} = Pres) ->
case {xmpp:get_subtag(Packet, #muc{}), case xmpp:get_subtag(Pres, #muc{}) of
xmpp:get_subtag(Packet, #muc_subscribe{})} of #muc{password = Password} when is_binary(Password) ->
{#muc{password = Password}, _} when is_binary(Password) ->
Password; Password;
{_, #muc_subscribe{password = Password}} when is_binary(Password) -> _ ->
false
end;
extract_password(#iq{} = IQ) ->
case xmpp:get_subtag(IQ, #muc_subscribe{}) of
#muc_subscribe{password = Password} when Password /= <<"">> ->
Password; Password;
_ -> _ ->
false false
@ -2107,17 +2102,13 @@ send_new_presence(NJID, Reason, IsInitialPresence, StateData, OldStateData) ->
OldStateData) OldStateData)
end. end.
-spec is_ra_changed(jid() | ljid(), boolean(), state(), state()) -> boolean(). -spec is_ra_changed(jid(), boolean(), state(), state()) -> boolean().
is_ra_changed(_, _IsInitialPresence = true, _, _) -> is_ra_changed(_, _IsInitialPresence = true, _, _) ->
false; false;
is_ra_changed(LJID, _IsInitialPresence = false, NewStateData, OldStateData) -> is_ra_changed(JID, _IsInitialPresence = false, NewStateData, OldStateData) ->
JID = case LJID of NewRole = get_role(JID, NewStateData),
#jid{} -> LJID;
_ -> jid:make(LJID)
end,
NewRole = get_role(LJID, NewStateData),
NewAff = get_affiliation(JID, NewStateData), NewAff = get_affiliation(JID, NewStateData),
OldRole = get_role(LJID, OldStateData), OldRole = get_role(JID, OldStateData),
OldAff = get_affiliation(JID, OldStateData), OldAff = get_affiliation(JID, OldStateData),
if (NewRole == none) and (NewAff == OldAff) -> if (NewRole == none) and (NewAff == OldAff) ->
%% A user is leaving the room; %% A user is leaving the room;
@ -2449,7 +2440,7 @@ add_message_to_history(FromNick, FromJID, Packet, StateData) ->
StateData StateData
end. end.
-spec send_history(jid(), lqueue(), state()) -> boolean(). -spec send_history(jid(), lqueue(), state()) -> ok.
send_history(JID, History, StateData) -> send_history(JID, History, StateData) ->
lists:foreach( lists:foreach(
fun({Nick, Packet, _HaveSubject, _TimeStamp, _Size}) -> fun({Nick, Packet, _HaveSubject, _TimeStamp, _Size}) ->
@ -2675,7 +2666,7 @@ find_changed_items(_UJID, _UAffiliation, _URole, [],
_Lang, _StateData, Res) -> _Lang, _StateData, Res) ->
{result, Res}; {result, Res};
find_changed_items(_UJID, _UAffiliation, _URole, find_changed_items(_UJID, _UAffiliation, _URole,
[#muc_item{jid = undefined, nick = undefined}|_], [#muc_item{jid = undefined, nick = <<"">>}|_],
Lang, _StateData, _Res) -> Lang, _StateData, _Res) ->
Txt = <<"Neither 'jid' nor 'nick' attribute found">>, Txt = <<"Neither 'jid' nor 'nick' attribute found">>,
throw({error, xmpp:err_bad_request(Txt, Lang)}); throw({error, xmpp:err_bad_request(Txt, Lang)});
@ -2743,16 +2734,16 @@ find_changed_items(UJID, UAffiliation, URole,
end, end,
find_changed_items(UJID, UAffiliation, URole, find_changed_items(UJID, UAffiliation, URole,
Items, Lang, StateData, Items, Lang, StateData,
[MoreRes | Res]); MoreRes ++ Res);
false -> false ->
Txt = <<"Changing role/affiliation is not allowed">>, Txt = <<"Changing role/affiliation is not allowed">>,
throw({error, xmpp:err_not_allowed(Txt, Lang)}) throw({error, xmpp:err_not_allowed(Txt, Lang)})
end. end.
-spec can_change_ra(affiliation(), role(), affiliation(), role(), -spec can_change_ra(affiliation(), role(), affiliation(), role(),
affiliation, affiliation(), affiliation()) -> boolean(); affiliation, affiliation(), affiliation()) -> boolean() | nothing | check_owner;
(affiliation(), role(), affiliation(), role(), (affiliation(), role(), affiliation(), role(),
role, role(), affiliation()) -> boolean(). role, role(), affiliation()) -> boolean() | nothing | check_owner.
can_change_ra(_FAffiliation, _FRole, owner, _TRole, can_change_ra(_FAffiliation, _FRole, owner, _TRole,
affiliation, owner, owner) -> affiliation, owner, owner) ->
%% A room owner tries to add as persistent owner a %% A room owner tries to add as persistent owner a
@ -2877,14 +2868,14 @@ can_change_ra(_FAffiliation, _FRole, _TAffiliation,
_TRole, role, _Value, _ServiceAf) -> _TRole, role, _Value, _ServiceAf) ->
false. false.
-spec send_kickban_presence(jid(), jid(), binary(), -spec send_kickban_presence(undefined | jid(), jid(), binary(),
pos_integer(), state()) -> ok. pos_integer(), state()) -> ok.
send_kickban_presence(UJID, JID, Reason, Code, StateData) -> send_kickban_presence(UJID, JID, Reason, Code, StateData) ->
NewAffiliation = get_affiliation(JID, StateData), NewAffiliation = get_affiliation(JID, StateData),
send_kickban_presence(UJID, JID, Reason, Code, NewAffiliation, send_kickban_presence(UJID, JID, Reason, Code, NewAffiliation,
StateData). StateData).
-spec send_kickban_presence(jid(), jid(), binary(), pos_integer(), -spec send_kickban_presence(undefined | jid(), jid(), binary(), pos_integer(),
affiliation(), state()) -> ok. affiliation(), state()) -> ok.
send_kickban_presence(UJID, JID, Reason, Code, NewAffiliation, send_kickban_presence(UJID, JID, Reason, Code, NewAffiliation,
StateData) -> StateData) ->
@ -2914,7 +2905,7 @@ send_kickban_presence(UJID, JID, Reason, Code, NewAffiliation,
end, end,
LJIDs). LJIDs).
-spec send_kickban_presence1(jid(), jid(), binary(), pos_integer(), -spec send_kickban_presence1(undefined | jid(), jid(), binary(), pos_integer(),
affiliation(), state()) -> ok. affiliation(), state()) -> ok.
send_kickban_presence1(MJID, UJID, Reason, Code, Affiliation, send_kickban_presence1(MJID, UJID, Reason, Code, Affiliation,
StateData) -> StateData) ->
@ -2958,8 +2949,8 @@ send_kickban_presence1(MJID, UJID, Reason, Code, Affiliation,
end, end,
(?DICT):to_list(get_users_and_subscribers(StateData))). (?DICT):to_list(get_users_and_subscribers(StateData))).
-spec get_actor_nick(binary() | jid(), state()) -> binary(). -spec get_actor_nick(undefined | jid(), state()) -> binary().
get_actor_nick(<<"">>, _StateData) -> get_actor_nick(undefined, _StateData) ->
<<"">>; <<"">>;
get_actor_nick(MJID, StateData) -> get_actor_nick(MJID, StateData) ->
case (?DICT):find(jid:tolower(MJID), StateData#state.users) of case (?DICT):find(jid:tolower(MJID), StateData#state.users) of
@ -3150,12 +3141,7 @@ get_config(Lang, StateData, From) ->
ServiceMaxUsers = get_service_max_users(StateData), ServiceMaxUsers = get_service_max_users(StateData),
DefaultRoomMaxUsers = get_default_room_maxusers(StateData), DefaultRoomMaxUsers = get_default_room_maxusers(StateData),
Config = StateData#state.config, Config = StateData#state.config,
{MaxUsersRoomInteger, MaxUsersRoomString} = MaxUsersRoom = get_max_users(StateData),
case get_max_users(StateData) of
N when is_integer(N) ->
{N, N};
_ -> {0, none}
end,
Title = str:format( Title = str:format(
translate:translate(Lang, <<"Configuration of room ~s">>), translate:translate(Lang, <<"Configuration of room ~s">>),
[jid:to_string(StateData#state.jid)]), [jid:to_string(StateData#state.jid)]),
@ -3172,13 +3158,13 @@ get_config(Lang, StateData, From) ->
true -> Config#config.password; true -> Config#config.password;
false -> <<"">> false -> <<"">>
end}, end},
{maxusers, MaxUsersRoomString, {maxusers, MaxUsersRoom,
[if is_integer(ServiceMaxUsers) -> []; [if is_integer(ServiceMaxUsers) -> [];
true -> [{<<"No limit">>, <<"none">>}] true -> [{<<"No limit">>, <<"none">>}]
end] ++ [{integer_to_binary(N), N} end] ++ [{integer_to_binary(N), N}
|| N <- lists:usort([ServiceMaxUsers, || N <- lists:usort([ServiceMaxUsers,
DefaultRoomMaxUsers, DefaultRoomMaxUsers,
MaxUsersRoomInteger MaxUsersRoom
| ?MAX_USERS_DEFAULT_LIST]), | ?MAX_USERS_DEFAULT_LIST]),
N =< ServiceMaxUsers]}, N =< ServiceMaxUsers]},
{whois, if Config#config.anonymous -> moderators; {whois, if Config#config.anonymous -> moderators;
@ -3362,7 +3348,7 @@ remove_nonmembers(StateData) ->
Affiliation = get_affiliation(JID, SD), Affiliation = get_affiliation(JID, SD),
case Affiliation of case Affiliation of
none -> none ->
catch send_kickban_presence(<<"">>, JID, <<"">>, catch send_kickban_presence(undefined, JID, <<"">>,
322, SD), 322, SD),
set_role(JID, none, SD); set_role(JID, none, SD);
_ -> SD _ -> SD
@ -3699,7 +3685,7 @@ process_iq_vcard(From, #iq{type = set, lang = Lang, sub_els = [SubEl]},
-spec process_iq_mucsub(jid(), iq(), state()) -> -spec process_iq_mucsub(jid(), iq(), state()) ->
{error, stanza_error()} | {error, stanza_error()} |
{result, undefined | muc_subscribe(), state()} | {result, undefined | muc_subscribe() | muc_subscriptions(), state()} |
{ignore, state()}. {ignore, state()}.
process_iq_mucsub(_From, #iq{type = set, lang = Lang, process_iq_mucsub(_From, #iq{type = set, lang = Lang,
sub_els = [#muc_subscribe{}]}, sub_els = [#muc_subscribe{}]},
@ -3780,7 +3766,7 @@ remove_subscriptions(StateData) ->
StateData StateData
end. end.
-spec get_subscription_nodes(iq()) -> [binary()]. -spec get_subscription_nodes(stanza()) -> [binary()].
get_subscription_nodes(#iq{sub_els = [#muc_subscribe{events = Nodes}]}) -> get_subscription_nodes(#iq{sub_els = [#muc_subscribe{events = Nodes}]}) ->
lists:filter( lists:filter(
fun(Node) -> fun(Node) ->
@ -4059,7 +4045,7 @@ wrap(From, To, Packet, Node) ->
%% JIDs = [ User#user.jid || {_, User} <- ?DICT:to_list(Users)], %% JIDs = [ User#user.jid || {_, User} <- ?DICT:to_list(Users)],
%% ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet). %% ejabberd_router_multicast:route_multicast(From, Server, JIDs, Packet).
-spec send_wrapped_multiple(jid(), [#user{}], stanza(), binary(), state()) -> ok. -spec send_wrapped_multiple(jid(), ?TDICT, stanza(), binary(), state()) -> ok.
send_wrapped_multiple(From, Users, Packet, Node, State) -> send_wrapped_multiple(From, Users, Packet, Node, State) ->
lists:foreach( lists:foreach(
fun({_, #user{jid = To}}) -> fun({_, #user{jid = To}}) ->

View File

@ -94,10 +94,10 @@
non_neg_integer(), non_neg_integer()) -> non_neg_integer(), non_neg_integer()) ->
{atomic, any()}. {atomic, any()}.
-callback pop_messages(binary(), binary()) -> -callback pop_messages(binary(), binary()) ->
{atomic, [#offline_msg{}]} | {aborted, any()}. {ok, [#offline_msg{}]} | {error, any()}.
-callback remove_expired_messages(binary()) -> {atomic, any()}. -callback remove_expired_messages(binary()) -> {atomic, any()}.
-callback remove_old_messages(non_neg_integer(), binary()) -> {atomic, any()}. -callback remove_old_messages(non_neg_integer(), binary()) -> {atomic, any()}.
-callback remove_user(binary(), binary()) -> {atomic, any()}. -callback remove_user(binary(), binary()) -> any().
-callback read_message_headers(binary(), binary()) -> -callback read_message_headers(binary(), binary()) ->
[{non_neg_integer(), jid(), jid(), undefined | erlang:timestamp(), xmlel()}]. [{non_neg_integer(), jid(), jid(), undefined | erlang:timestamp(), xmlel()}].
-callback read_message(binary(), binary(), non_neg_integer()) -> -callback read_message(binary(), binary(), non_neg_integer()) ->
@ -517,7 +517,7 @@ check_event(#message{from = From, to = To, id = ID} = Msg) ->
-spec find_x_expire(erlang:timestamp(), message()) -> erlang:timestamp() | never. -spec find_x_expire(erlang:timestamp(), message()) -> erlang:timestamp() | never.
find_x_expire(TimeStamp, Msg) -> find_x_expire(TimeStamp, Msg) ->
case xmpp:get_subtag(Msg, #expire{}) of case xmpp:get_subtag(Msg, #expire{seconds = 0}) of
#expire{seconds = Int} -> #expire{seconds = Int} ->
{MegaSecs, Secs, MicroSecs} = TimeStamp, {MegaSecs, Secs, MicroSecs} = TimeStamp,
S = MegaSecs * 1000000 + Secs + Int, S = MegaSecs * 1000000 + Secs + Int,
@ -571,7 +571,7 @@ route_offline_message(#{lserver := LServer} = State,
false -> false ->
case privacy_check_packet(State, Msg, in) of case privacy_check_packet(State, Msg, in) of
allow -> ejabberd_router:route(Msg); allow -> ejabberd_router:route(Msg);
false -> ok deny -> ok
end end
end end
end. end.
@ -813,14 +813,14 @@ delete_all_msgs(User, Server) ->
webadmin_user_parse_query(_, <<"removealloffline">>, webadmin_user_parse_query(_, <<"removealloffline">>,
User, Server, _Query) -> User, Server, _Query) ->
case delete_all_msgs(User, Server) of case delete_all_msgs(User, Server) of
{aborted, Reason} ->
?ERROR_MSG("Failed to remove offline messages: ~p",
[Reason]),
{stop, error};
{atomic, ok} -> {atomic, ok} ->
?INFO_MSG("Removed all offline messages for ~s@~s", ?INFO_MSG("Removed all offline messages for ~s@~s",
[User, Server]), [User, Server]),
{stop, ok} {stop, ok};
Err ->
?ERROR_MSG("Failed to remove offline messages: ~p",
[Err]),
{stop, error}
end; end;
webadmin_user_parse_query(Acc, _Action, _User, _Server, webadmin_user_parse_query(Acc, _Action, _User, _Server,
_Query) -> _Query) ->
@ -866,25 +866,20 @@ import_start(LServer, DBType) ->
import(LServer, {sql, _}, DBType, <<"spool">>, import(LServer, {sql, _}, DBType, <<"spool">>,
[LUser, XML, _Seq, _TimeStamp]) -> [LUser, XML, _Seq, _TimeStamp]) ->
El = fxml_stream:parse_element(XML), El = fxml_stream:parse_element(XML),
From = #jid{} = jid:from_string( #message{from = From, to = To} = Msg = xmpp:decode(El, ?NS_CLIENT, [ignore_els]),
fxml:get_attr_s(<<"from">>, El#xmlel.attrs)), TS = case xmpp:get_subtag(Msg, #delay{stamp = {0,0,0}}) of
To = #jid{} = jid:from_string( #delay{stamp = {MegaSecs, Secs, _}} ->
fxml:get_attr_s(<<"to">>, El#xmlel.attrs)), {MegaSecs, Secs, 0};
Stamp = fxml:get_path_s(El, [{elem, <<"delay">>}, false ->
{attr, <<"stamp">>}]),
TS = try xmpp_util:decode_timestamp(Stamp) of
{MegaSecs, Secs, _} ->
{MegaSecs, Secs, 0}
catch _:_ ->
p1_time_compat:timestamp() p1_time_compat:timestamp()
end, end,
US = {LUser, LServer}, US = {LUser, LServer},
Expire = find_x_expire(TS, El#xmlel.children), Expire = find_x_expire(TS, Msg),
Msg = #offline_msg{us = US, packet = El, OffMsg = #offline_msg{us = US, packet = El,
from = From, to = To, from = From, to = To,
timestamp = TS, expire = Expire}, timestamp = TS, expire = Expire},
Mod = gen_mod:db_mod(DBType, ?MODULE), Mod = gen_mod:db_mod(DBType, ?MODULE),
Mod:import(Msg). Mod:import(OffMsg).
mod_opt_type(access_max_user_messages) -> mod_opt_type(access_max_user_messages) ->
fun acl:shaper_rules_validator/1; fun acl:shaper_rules_validator/1;

View File

@ -239,7 +239,5 @@ el_to_offline_msg(El) ->
{ok, #offline_msg{us = {To#jid.luser, To#jid.lserver}, {ok, #offline_msg{us = {To#jid.luser, To#jid.lserver},
from = From, from = From,
to = To, to = To,
timestamp = undefined,
expire = undefined,
packet = El}} packet = El}}
end. end.

View File

@ -57,7 +57,7 @@
-callback set_privacy_list(binary(), binary(), binary(), [listitem()]) -> {atomic, any()}. -callback set_privacy_list(binary(), binary(), binary(), [listitem()]) -> {atomic, any()}.
-callback get_user_list(binary(), binary()) -> {none | binary(), [listitem()]}. -callback get_user_list(binary(), binary()) -> {none | binary(), [listitem()]}.
-callback get_user_lists(binary(), binary()) -> {ok, #privacy{}} | error. -callback get_user_lists(binary(), binary()) -> {ok, #privacy{}} | error.
-callback remove_user(binary(), binary()) -> {atomic, any()}. -callback remove_user(binary(), binary()) -> any().
start(Host, Opts) -> start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1, IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,

View File

@ -46,7 +46,7 @@
-callback set_data(binary(), binary(), [{binary(), xmlel()}]) -> {atomic, any()}. -callback set_data(binary(), binary(), [{binary(), xmlel()}]) -> {atomic, any()}.
-callback get_data(binary(), binary(), binary()) -> {ok, xmlel()} | error. -callback get_data(binary(), binary(), binary()) -> {ok, xmlel()} | error.
-callback get_all_data(binary(), binary()) -> [xmlel()]. -callback get_all_data(binary(), binary()) -> [xmlel()].
-callback remove_user(binary(), binary()) -> {atomic, any()}. -callback remove_user(binary(), binary()) -> any().
start(Host, Opts) -> start(Host, Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1, IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,

View File

@ -35,7 +35,7 @@
-record(bytestream, -record(bytestream,
{sha1 = <<"">> :: binary() | '$1', {sha1 = <<"">> :: binary() | '$1',
target :: pid() | '_', target :: pid() | '_',
initiator :: pid() | '_', initiator :: pid() | '_' | undefined,
active = false :: boolean() | '_', active = false :: boolean() | '_',
jid_i :: undefined | binary() | '_'}). jid_i :: undefined | binary() | '_'}).

View File

@ -158,7 +158,7 @@ process_bytestreams(#iq{type = get, from = JID, to = To, lang = Lang} = IQ) ->
end; end;
process_bytestreams(#iq{type = set, lang = Lang, process_bytestreams(#iq{type = set, lang = Lang,
sub_els = [#bytestreams{sid = SID}]} = IQ) sub_els = [#bytestreams{sid = SID}]} = IQ)
when SID == <<"">> orelse length(SID) > 128 -> when SID == <<"">> orelse size(SID) > 128 ->
Why = {bad_attr_value, <<"sid">>, <<"query">>, ?NS_BYTESTREAMS}, Why = {bad_attr_value, <<"sid">>, <<"query">>, ?NS_BYTESTREAMS},
Txt = xmpp:format_error(Why), Txt = xmpp:format_error(Why),
xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang)); xmpp:make_error(IQ, xmpp:err_bad_request(Txt, Lang));

View File

@ -1473,7 +1473,7 @@ send_authorization_request(#pubsub_node{nodeid = {Host, Node},
pubsub_subscribe_authorization:result() | pubsub_subscribe_authorization:result() |
{error, stanza_error()}. {error, stanza_error()}.
find_authorization_response(Packet) -> find_authorization_response(Packet) ->
case xmpp:get_subtag(Packet, #xdata{}) of case xmpp:get_subtag(Packet, #xdata{type = form}) of
#xdata{type = cancel} -> #xdata{type = cancel} ->
undefined; undefined;
#xdata{type = submit, fields = Fs} -> #xdata{type = submit, fields = Fs} ->
@ -1798,11 +1798,11 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
Reply = fun (Subscription) -> Reply = fun (Subscription) ->
Sub = case Subscription of Sub = case Subscription of
{subscribed, SubId} -> {subscribed, SubId} ->
#ps_subscription{type = subscribed, subid = SubId}; #ps_subscription{jid = JID, type = subscribed, subid = SubId};
Other -> Other ->
#ps_subscription{type = Other} #ps_subscription{jid = JID, type = Other}
end, end,
#pubsub{subscription = Sub#ps_subscription{jid = Subscriber, node = Node}} #pubsub{subscription = Sub#ps_subscription{node = Node}}
end, end,
case transaction(Host, Node, Action, sync_dirty) of case transaction(Host, Node, Action, sync_dirty) of
{result, {TNode, {Result, subscribed, SubId, send_last}}} -> {result, {TNode, {Result, subscribed, SubId, send_last}}} ->

View File

@ -865,7 +865,8 @@ resend_pending_subscriptions(#{jid := JID} = State, Mod) ->
Status = if is_binary(Message) -> (Message); Status = if is_binary(Message) -> (Message);
true -> <<"">> true -> <<"">>
end, end,
Sub = #presence{from = R#roster.jid, to = BareJID, Sub = #presence{from = jid:make(R#roster.jid),
to = BareJID,
type = subscribe, type = subscribe,
status = xmpp:mk_text(Status)}, status = xmpp:mk_text(Status)},
ejabberd_c2s:send(AccState, Sub); ejabberd_c2s:send(AccState, Sub);

View File

@ -70,7 +70,7 @@
-callback get_user_displayed_groups(binary(), binary(), group_options()) -> -callback get_user_displayed_groups(binary(), binary(), group_options()) ->
[{binary(), group_options()}]. [{binary(), group_options()}].
-callback is_user_in_group({binary(), binary()}, binary(), binary()) -> boolean(). -callback is_user_in_group({binary(), binary()}, binary(), binary()) -> boolean().
-callback add_user_to_group(binary(), {binary(), binary()}, binary()) -> {atomic, any()}. -callback add_user_to_group(binary(), {binary(), binary()}, binary()) -> any().
-callback remove_user_from_group(binary(), {binary(), binary()}, binary()) -> {atomic, any()}. -callback remove_user_from_group(binary(), {binary(), binary()}, binary()) -> {atomic, any()}.
start(Host, Opts) -> start(Host, Opts) ->
@ -235,7 +235,7 @@ process_item(RosterItem, Host) ->
jid:make(UserFrom, ServerFrom, jid:make(UserFrom, ServerFrom,
<<"">>), <<"">>),
unsubscribe), unsubscribe),
mod_roster:in_subscription(aaaa, UserFrom, ServerFrom, mod_roster:in_subscription(false, UserFrom, ServerFrom,
jid:make(UserTo, ServerTo, jid:make(UserTo, ServerTo,
<<"">>), <<"">>),
unsubscribe, <<"">>), unsubscribe, <<"">>),
@ -268,19 +268,19 @@ set_new_rosteritems(UserFrom, ServerFrom, UserTo,
set_item(UserTo, ServerTo, <<"">>, RITo), set_item(UserTo, ServerTo, <<"">>, RITo),
mod_roster:out_subscription(UserFrom, ServerFrom, JIDTo, mod_roster:out_subscription(UserFrom, ServerFrom, JIDTo,
subscribe), subscribe),
mod_roster:in_subscription(aaa, UserTo, ServerTo, mod_roster:in_subscription(false, UserTo, ServerTo,
JIDFrom, subscribe, <<"">>), JIDFrom, subscribe, <<"">>),
mod_roster:out_subscription(UserTo, ServerTo, JIDFrom, mod_roster:out_subscription(UserTo, ServerTo, JIDFrom,
subscribed), subscribed),
mod_roster:in_subscription(aaa, UserFrom, ServerFrom, mod_roster:in_subscription(false, UserFrom, ServerFrom,
JIDTo, subscribed, <<"">>), JIDTo, subscribed, <<"">>),
mod_roster:out_subscription(UserTo, ServerTo, JIDFrom, mod_roster:out_subscription(UserTo, ServerTo, JIDFrom,
subscribe), subscribe),
mod_roster:in_subscription(aaa, UserFrom, ServerFrom, mod_roster:in_subscription(false, UserFrom, ServerFrom,
JIDTo, subscribe, <<"">>), JIDTo, subscribe, <<"">>),
mod_roster:out_subscription(UserFrom, ServerFrom, JIDTo, mod_roster:out_subscription(UserFrom, ServerFrom, JIDTo,
subscribed), subscribed),
mod_roster:in_subscription(aaa, UserTo, ServerTo, mod_roster:in_subscription(false, UserTo, ServerTo,
JIDFrom, subscribed, <<"">>), JIDFrom, subscribed, <<"">>),
RIFrom. RIFrom.
@ -355,7 +355,7 @@ out_subscription(UserFrom, ServerFrom, JIDTo,
JIDFrom = jid:make(UserFrom, ServerFrom, <<"">>), JIDFrom = jid:make(UserFrom, ServerFrom, <<"">>),
mod_roster:out_subscription(UserTo, ServerTo, JIDFrom, mod_roster:out_subscription(UserTo, ServerTo, JIDFrom,
unsubscribe), unsubscribe),
mod_roster:in_subscription(aaaa, UserFrom, ServerFrom, mod_roster:in_subscription(false, UserFrom, ServerFrom,
JIDTo, unsubscribe, <<"">>), JIDTo, unsubscribe, <<"">>),
process_subscription(out, UserFrom, ServerFrom, JIDTo, process_subscription(out, UserFrom, ServerFrom, JIDTo,
unsubscribed, false); unsubscribed, false);

View File

@ -48,7 +48,7 @@
orig_trid, orig_trid,
responses = [] :: [#sip{}], responses = [] :: [#sip{}],
tr_ids = [] :: list(), tr_ids = [] :: list(),
orig_req :: #sip{}}). orig_req = #sip{} :: #sip{}}).
%%%=================================================================== %%%===================================================================
%%% API %%% API

View File

@ -51,7 +51,7 @@
cseq = 0 :: non_neg_integer(), cseq = 0 :: non_neg_integer(),
timestamp = p1_time_compat:timestamp() :: erlang:timestamp(), timestamp = p1_time_compat:timestamp() :: erlang:timestamp(),
contact :: {binary(), #uri{}, [{binary(), binary()}]}, contact :: {binary(), #uri{}, [{binary(), binary()}]},
flow_tref :: reference(), flow_tref :: reference() | undefined,
reg_tref = make_ref() :: reference(), reg_tref = make_ref() :: reference(),
conn_mref = make_ref() :: reference(), conn_mref = make_ref() :: reference(),
expires = 0 :: non_neg_integer()}). expires = 0 :: non_neg_integer()}).

View File

@ -599,7 +599,7 @@ inherit_session_state(#{user := U, server := S} = State, ResumeID) ->
{error, <<"Invalid 'previd' value">>} {error, <<"Invalid 'previd' value">>}
end. end.
-spec resume_session({integer(), pid()}, state()) -> {resume, state()} | -spec resume_session({erlang:timestamp(), pid()}, state()) -> {resume, state()} |
{error, binary()}. {error, binary()}.
resume_session({Time, Pid}, _State) -> resume_session({Time, Pid}, _State) ->
ejabberd_c2s:call(Pid, {resume_session, Time}, timer:seconds(15)). ejabberd_c2s:call(Pid, {resume_session, Time}, timer:seconds(15)).

View File

@ -180,7 +180,7 @@ remove_user(_User, _Server) ->
{atomic, not_implemented}. {atomic, not_implemented}.
import(_, _, _) -> import(_, _, _) ->
pass. ok.
%%%=================================================================== %%%===================================================================
%%% gen_server callbacks %%% gen_server callbacks

View File

@ -48,7 +48,7 @@
{tls, inet:posix() | atom() | binary()} | {tls, inet:posix() | atom() | binary()} |
{socket, inet:posix() | closed | timeout} | {socket, inet:posix() | closed | timeout} |
internal_failure. internal_failure.
-export_type([state/0, stop_reason/0]).
-callback init(list()) -> {ok, state()} | {error, term()} | ignore. -callback init(list()) -> {ok, state()} | {error, term()} | ignore.
-callback handle_cast(term(), state()) -> state(). -callback handle_cast(term(), state()) -> state().
-callback handle_call(term(), term(), state()) -> state(). -callback handle_call(term(), term(), state()) -> state().
@ -619,7 +619,7 @@ process_bind(#iq{type = set, sub_els = [_]} = Pkt,
Reply = #bind{jid = jid:make(U, S, NewR)}, Reply = #bind{jid = jid:make(U, S, NewR)},
State2 = send_pkt(State1, xmpp:make_iq_result(Pkt, Reply)), State2 = send_pkt(State1, xmpp:make_iq_result(Pkt, Reply)),
process_stream_established(State2); process_stream_established(State2);
{error, #stanza_error{}, State1} = Err -> {error, #stanza_error{} = Err, State1} ->
send_error(State1, Pkt, Err) send_error(State1, Pkt, Err)
end end
end; end;

View File

@ -59,7 +59,7 @@
{auth, atom() | binary() | string()} | {auth, atom() | binary() | string()} |
{socket, inet:posix() | closed | timeout} | {socket, inet:posix() | closed | timeout} |
internal_failure. internal_failure.
-export_type([state/0, stop_reason/0]).
-callback init(list()) -> {ok, state()} | {error, term()} | ignore. -callback init(list()) -> {ok, state()} | {error, term()} | ignore.
-callback handle_cast(term(), state()) -> state(). -callback handle_cast(term(), state()) -> state().
-callback handle_call(term(), term(), state()) -> state(). -callback handle_call(term(), term(), state()) -> state().
@ -794,6 +794,7 @@ format(Fmt, Args) ->
%%%=================================================================== %%%===================================================================
%%% Connection stuff %%% Connection stuff
%%%=================================================================== %%%===================================================================
-spec idna_to_ascii(binary()) -> binary() | false.
idna_to_ascii(<<$[, _/binary>> = Host) -> idna_to_ascii(<<$[, _/binary>> = Host) ->
%% This is an IPv6 address in 'IP-literal' format (as per RFC7622) %% This is an IPv6 address in 'IP-literal' format (as per RFC7622)
%% We remove brackets here %% We remove brackets here
@ -813,7 +814,7 @@ idna_to_ascii(Host) ->
{error, _} -> ejabberd_idna:domain_utf8_to_ascii(Host) {error, _} -> ejabberd_idna:domain_utf8_to_ascii(Host)
end. end.
-spec resolve(string(), state()) -> {ok, [host_port()]} | network_error(). -spec resolve(string(), state()) -> {ok, [ip_port()]} | network_error().
resolve(Host, State) -> resolve(Host, State) ->
case srv_lookup(Host, State) of case srv_lookup(Host, State) of
{error, _Reason} -> {error, _Reason} ->