Add forgotten type specs
This commit is contained in:
parent
7a3092a859
commit
50b3206f06
|
@ -1,10 +1,23 @@
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
%%% @author xram <xram@debian.zinid.ru>
|
%%% Created : 10 Nov 2017 by Evgeny Khramtsov <ekhramtsov@process-one.net>
|
||||||
%%% @copyright (C) 2017, xram
|
%%%
|
||||||
%%% @doc
|
%%%
|
||||||
|
%%% ejabberd, Copyright (C) 2002-2017 ProcessOne
|
||||||
|
%%%
|
||||||
|
%%% This program is free software; you can redistribute it and/or
|
||||||
|
%%% modify it under the terms of the GNU General Public License as
|
||||||
|
%%% published by the Free Software Foundation; either version 2 of the
|
||||||
|
%%% License, or (at your option) any later version.
|
||||||
|
%%%
|
||||||
|
%%% This program is distributed in the hope that it will be useful,
|
||||||
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
%%% General Public License for more details.
|
||||||
|
%%%
|
||||||
|
%%% You should have received a copy of the GNU General Public License along
|
||||||
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
%%%
|
%%%
|
||||||
%%% @end
|
|
||||||
%%% Created : 10 Nov 2017 by xram <xram@debian.zinid.ru>
|
|
||||||
%%%-------------------------------------------------------------------
|
%%%-------------------------------------------------------------------
|
||||||
-module(ejabberd_iq).
|
-module(ejabberd_iq).
|
||||||
|
|
||||||
|
@ -21,6 +34,7 @@
|
||||||
-include("logger.hrl").
|
-include("logger.hrl").
|
||||||
|
|
||||||
-record(state, {expire = infinity :: timeout()}).
|
-record(state, {expire = infinity :: timeout()}).
|
||||||
|
-type state() :: #state{}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
|
@ -28,6 +42,7 @@
|
||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
|
-spec route(iq(), atom() | pid(), term(), non_neg_integer()) -> ok.
|
||||||
route(#iq{type = T} = IQ, Proc, Ctx, Timeout) when T == set; T == get ->
|
route(#iq{type = T} = IQ, Proc, Ctx, Timeout) when T == set; T == get ->
|
||||||
Expire = current_time() + Timeout,
|
Expire = current_time() + Timeout,
|
||||||
Rnd = randoms:get_string(),
|
Rnd = randoms:get_string(),
|
||||||
|
@ -89,9 +104,12 @@ code_change(_OldVsn, State, _Extra) ->
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
-spec current_time() -> non_neg_integer().
|
||||||
current_time() ->
|
current_time() ->
|
||||||
p1_time_compat:system_time(milli_seconds).
|
p1_time_compat:system_time(milli_seconds).
|
||||||
|
|
||||||
|
-spec clean({non_neg_integer(), binary()} | '$end_of_table')
|
||||||
|
-> non_neg_integer() | infinity.
|
||||||
clean({Expire, _} = Key) ->
|
clean({Expire, _} = Key) ->
|
||||||
case current_time() of
|
case current_time() of
|
||||||
Time when Time >= Expire ->
|
Time when Time >= Expire ->
|
||||||
|
@ -109,6 +127,7 @@ clean({Expire, _} = Key) ->
|
||||||
clean('$end_of_table') ->
|
clean('$end_of_table') ->
|
||||||
infinity.
|
infinity.
|
||||||
|
|
||||||
|
-spec noreply(state()) -> {noreply, state()} | {noreply, state(), non_neg_integer()}.
|
||||||
noreply(#state{expire = Expire} = State) ->
|
noreply(#state{expire = Expire} = State) ->
|
||||||
case Expire of
|
case Expire of
|
||||||
infinity ->
|
infinity ->
|
||||||
|
@ -118,12 +137,14 @@ noreply(#state{expire = Expire} = State) ->
|
||||||
{noreply, State, Timeout}
|
{noreply, State, Timeout}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec encode_id(non_neg_integer(), binary()) -> binary().
|
||||||
encode_id(Expire, Rnd) ->
|
encode_id(Expire, Rnd) ->
|
||||||
ExpireBin = integer_to_binary(Expire),
|
ExpireBin = integer_to_binary(Expire),
|
||||||
Node = atom_to_binary(node(), utf8),
|
Node = atom_to_binary(node(), utf8),
|
||||||
CheckSum = calc_checksum(<<ExpireBin/binary, Rnd/binary, Node/binary>>),
|
CheckSum = calc_checksum(<<ExpireBin/binary, Rnd/binary, Node/binary>>),
|
||||||
<<"rr-", ExpireBin/binary, $-, Rnd/binary, $-, CheckSum/binary, $-, Node/binary>>.
|
<<"rr-", ExpireBin/binary, $-, Rnd/binary, $-, CheckSum/binary, $-, Node/binary>>.
|
||||||
|
|
||||||
|
-spec decode_id(binary()) -> {ok, non_neg_integer(), binary(), atom()} | error.
|
||||||
decode_id(<<"rr-", ID/binary>>) ->
|
decode_id(<<"rr-", ID/binary>>) ->
|
||||||
try
|
try
|
||||||
[ExpireBin, Tail] = binary:split(ID, <<"-">>),
|
[ExpireBin, Tail] = binary:split(ID, <<"-">>),
|
||||||
|
@ -139,10 +160,12 @@ decode_id(<<"rr-", ID/binary>>) ->
|
||||||
decode_id(_) ->
|
decode_id(_) ->
|
||||||
error.
|
error.
|
||||||
|
|
||||||
|
-spec calc_checksum(binary()) -> binary().
|
||||||
calc_checksum(Data) ->
|
calc_checksum(Data) ->
|
||||||
Key = ejabberd_config:get_option(shared_key),
|
Key = ejabberd_config:get_option(shared_key),
|
||||||
base64:encode(crypto:hash(sha, <<Data/binary, Key/binary>>)).
|
base64:encode(crypto:hash(sha, <<Data/binary, Key/binary>>)).
|
||||||
|
|
||||||
|
-spec callback(atom() | pid(), #iq{}, term()) -> any().
|
||||||
callback(undefined, IQRes, Fun) ->
|
callback(undefined, IQRes, Fun) ->
|
||||||
Fun(IQRes);
|
Fun(IQRes);
|
||||||
callback(Proc, IQRes, Ctx) ->
|
callback(Proc, IQRes, Ctx) ->
|
||||||
|
|
Loading…
Reference in New Issue