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() | '_',
us = {<<"">>, <<"">>} :: {binary(), 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(),
server_host :: binary(),
-record(route, {domain :: binary() | '_',
server_host :: binary() | '_',
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 info() :: [{conn, atom()} | {ip, ip()} | {node, atom()}
| {oor, boolean()} | {auth_module, atom()}
| {num_stanzas_in, non_neg_integer()}].
| {num_stanzas_in, non_neg_integer()}
| offline].
-type prio() :: undefined | integer().
-endif.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -49,6 +49,10 @@
-include("ejabberd.hrl").
-include("logger.hrl").
-type scrammed_password() :: {binary(), binary(), binary(), non_neg_integer()}.
-type password() :: binary() | scrammed_password().
-export_type([password/0]).
%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------
@ -73,8 +77,8 @@
-callback get_vh_registered_users(binary(), opts()) -> [{binary(), binary()}].
-callback get_vh_registered_users_number(binary()) -> number().
-callback get_vh_registered_users_number(binary(), opts()) -> number().
-callback get_password(binary(), binary()) -> false | binary() | {binary(), binary(), binary(), integer()}.
-callback get_password_s(binary(), binary()) -> binary() | {binary(), binary(), binary(), integer()}.
-callback get_password(binary(), binary()) -> false | password().
-callback get_password_s(binary(), binary()) -> password().
start() ->
%% This is only executed by ejabberd_c2s for non-SASL auth client
@ -270,7 +274,7 @@ get_vh_registered_users_number(Server, Opts) ->
end,
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) ->
lists:foldl(fun (M, false) ->
@ -279,7 +283,7 @@ get_password(User, Server) ->
end,
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) ->
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.
%% @spec (User::string(), Server::string()) ->
%% {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) ->
%% 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()}],
ufilter = <<"">> :: binary(),
sfilter = <<"">> :: binary(),
lfilter :: {any(), any()},
lfilter :: {any(), any()} | undefined,
deref_aliases = never :: never | searching | finding | always,
dn_filter :: binary(),
dn_filter :: binary() | undefined,
dn_filter_attrs = [] :: [binary()]}).
handle_cast(_Request, State) -> {noreply, State}.

View File

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

View File

@ -48,7 +48,7 @@
%% API
-export([get_presence/1, get_subscription/2, get_subscribed/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("xmpp.hrl").
@ -110,12 +110,18 @@ get_subscription(LFrom, #{pres_f := PresF, pres_t := PresT}) ->
get_subscribed(Ref) ->
call(Ref, get_subscribed, 1000).
-spec close(pid()) -> ok;
(state()) -> state().
close(Ref) ->
xmpp_stream_in:close(Ref).
-spec close(pid(), boolean()) -> ok;
(state(), boolean()) -> state().
close(Ref, SendTrailer) ->
xmpp_stream_in:close(Ref, SendTrailer).
-spec stop(pid()) -> ok;
(state()) -> no_return().
stop(Ref) ->
xmpp_stream_in:stop(Ref).
@ -130,6 +136,11 @@ send(#{lserver := LServer} = State, Pkt) ->
{Pkt2, State1} -> xmpp_stream_in:send(State1, Pkt2)
end.
-spec route(pid(), term()) -> ok.
route(Pid, Term) ->
Pid ! Term,
ok.
-spec set_timeout(state(), timeout()) -> state().
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}};
_ ->
case privacy_check_packet(State, Pres, in) of
allow when T == error ->
{true, State};
allow ->
NewState = add_to_pres_a(State, From),
{true, NewState};

View File

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

View File

@ -50,12 +50,12 @@
{socket :: ws_socket(),
ping_interval = ?PING_INTERVAL :: non_neg_integer(),
ping_timer = make_ref() :: reference(),
pong_expected :: boolean(),
pong_expected = false :: boolean(),
timeout = ?WEBSOCKET_TIMEOUT :: non_neg_integer(),
timer = make_ref() :: reference(),
input = [] :: list(),
waiting_input = false :: false | pid(),
last_receiver :: pid(),
last_receiver = self() :: pid(),
ws :: {#ws{}, pid()},
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_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(),
server = <<"">> :: binary(),
fd :: file:io_device(),
fd = self() :: file:io_device(),
dir = <<"">> :: binary()}).
-type state() :: #state{}.

View File

@ -54,9 +54,9 @@
{socket :: inet:socket() | fast_tls:tls_socket() | ezlib:zlib_socket(),
sock_mod = gen_tcp :: gen_tcp | fast_tls | ezlib,
shaper_state = none :: shaper:shaper(),
c2s_pid :: pid(),
c2s_pid :: pid() | undefined,
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()}).
-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,
%% i.e. `i' = element(2, Record).
-export_types([index_info/0]).
-export_type([index_info/0]).
%%%===================================================================
%%% API

View File

@ -144,7 +144,7 @@ route_error(From, To, Packet, #stanza_error{} = Err) ->
register_route(Domain, ServerHost) ->
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) ->
case {jid:nameprep(Domain), jid:nameprep(ServerHost)} of
{error, _} ->

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -91,7 +91,7 @@ start_child(Mod, Host, Opts, Proc) ->
transient, 2000, worker, [Mod]},
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(get_module_proc(Host, Mod)).
@ -437,7 +437,7 @@ db_type(Host, Module) when is_atom(Module) ->
undefined
end.
-spec db_type(binary(), opts(), module()) -> db_type().
-spec db_type(binary() | global, opts(), module()) -> db_type().
db_type(Host, Opts, Module) ->
case catch Module:mod_opt_type(db_type) of
@ -477,7 +477,7 @@ ram_db_type(Host, Module) when is_atom(Module) ->
undefined
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) ->
case catch Module:mod_opt_type(ram_db_type) of
F when is_function(F) ->

View File

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

View File

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

View File

@ -41,7 +41,7 @@
-include("ejabberd.hrl").
-include("logger.hrl").
-include_lib("stdlib/include/ms_transform.hrl").
-include("jlib.hrl").
-include("xmpp.hrl").
-include("ejabberd_http.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())
-> ejabberd_c2s:state() | {stop, ejabberd_c2s:state()}.
c2s_stream_started(#{ip := {Addr, _}} = State, _) ->
ets:tab2list(failed_auth),
case ets:lookup(failed_auth, Addr) of
[{Addr, N, TS, MaxFailures}] when N >= MaxFailures ->
case TS > p1_time_compat:system_time(seconds) of
@ -161,7 +160,7 @@ code_change(_OldVsn, State, _Extra) ->
%%%===================================================================
%%% 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()}.
log_and_disconnect(#{ip := {Addr, _}, lang := Lang} = State, Attempts, UnbanTS) ->
IP = jlib:ip_to_list(Addr),

View File

@ -121,7 +121,7 @@
%%--------------------------------------------------------------------
%% gen_mod/supervisor callbacks.
%%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}.
-spec start(binary(), gen_mod:opts()) -> {ok, pid()}.
start(ServerHost, Opts) ->
case gen_mod:get_opt(rm_on_unregister, Opts,
@ -136,7 +136,7 @@ start(ServerHost, Opts) ->
Proc = get_proc_name(ServerHost, ?MODULE),
gen_mod:start_child(?MODULE, ServerHost, Opts, Proc).
-spec stop(binary()) -> ok.
-spec stop(binary()) -> ok | {error, any()}.
stop(ServerHost) ->
case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister,
@ -211,7 +211,7 @@ depends(_Host, _Opts) ->
%% gen_server callbacks.
%%--------------------------------------------------------------------
-spec init({binary(), gen_mod:opts()}) -> {ok, state()}.
-spec init(list()) -> {ok, state()}.
init([ServerHost, Opts]) ->
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(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) ->
Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size,

View File

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

View File

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

View File

@ -51,9 +51,8 @@
-callback import(binary(), #last_activity{}) -> ok | pass.
-callback get_last(binary(), binary()) ->
{ok, non_neg_integer(), binary()} | not_found | {error, any()}.
-callback store_last_info(binary(), binary(), non_neg_integer(), binary()) ->
{atomic, any()}.
-callback remove_user(binary(), binary()) -> {atomic, any()}.
-callback store_last_info(binary(), binary(), non_neg_integer(), binary()) -> any().
-callback remove_user(binary(), binary()) -> any().
start(Host, Opts) ->
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})
end.
-spec register_user(binary(), binary()) -> {atomic, any()}.
-spec register_user(binary(), binary()) -> any().
register_user(User, Server) ->
on_presence_update(
User,
@ -205,13 +204,12 @@ register_user(User, Server) ->
<<"RegisterResource">>,
<<"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) ->
TimeStamp = p1_time_compat:system_time(seconds),
store_last_info(User, Server, TimeStamp, Status).
-spec store_last_info(binary(), binary(), non_neg_integer(), binary()) ->
{atomic, any()}.
-spec store_last_info(binary(), binary(), non_neg_integer(), binary()) -> any().
store_last_info(User, Server, TimeStamp, Status) ->
LUser = jid:nodeprep(User),
LServer = jid:nameprep(Server),

View File

@ -146,7 +146,7 @@ open_session(State, IQ, R) ->
ejabberd_c2s:send(State1, Res)
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) ->
State1 = ejabberd_c2s:send(State, StanzaErr),
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().
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}} ->
true;
_ ->

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -158,7 +158,7 @@ process_bytestreams(#iq{type = get, from = JID, to = To, lang = Lang} = IQ) ->
end;
process_bytestreams(#iq{type = set, lang = Lang,
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},
Txt = xmpp:format_error(Why),
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() |
{error, stanza_error()}.
find_authorization_response(Packet) ->
case xmpp:get_subtag(Packet, #xdata{}) of
case xmpp:get_subtag(Packet, #xdata{type = form}) of
#xdata{type = cancel} ->
undefined;
#xdata{type = submit, fields = Fs} ->
@ -1798,11 +1798,11 @@ subscribe_node(Host, Node, From, JID, Configuration) ->
Reply = fun (Subscription) ->
Sub = case Subscription of
{subscribed, SubId} ->
#ps_subscription{type = subscribed, subid = SubId};
#ps_subscription{jid = JID, type = subscribed, subid = SubId};
Other ->
#ps_subscription{type = Other}
#ps_subscription{jid = JID, type = Other}
end,
#pubsub{subscription = Sub#ps_subscription{jid = Subscriber, node = Node}}
#pubsub{subscription = Sub#ps_subscription{node = Node}}
end,
case transaction(Host, Node, Action, sync_dirty) of
{result, {TNode, {Result, subscribed, SubId, send_last}}} ->

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -48,7 +48,7 @@
{tls, inet:posix() | atom() | binary()} |
{socket, inet:posix() | closed | timeout} |
internal_failure.
-export_type([state/0, stop_reason/0]).
-callback init(list()) -> {ok, state()} | {error, term()} | ignore.
-callback handle_cast(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)},
State2 = send_pkt(State1, xmpp:make_iq_result(Pkt, Reply)),
process_stream_established(State2);
{error, #stanza_error{}, State1} = Err ->
{error, #stanza_error{} = Err, State1} ->
send_error(State1, Pkt, Err)
end
end;

View File

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