24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-02 21:17:12 +02:00

mod_http_upload*: Remove empty lines after specs

Remove blank lines following function specifications in mod_http_upload
and mod_http_upload_quota for consistency with other modules.
This commit is contained in:
Holger Weiss 2018-04-16 18:22:54 +02:00
parent b2855d63a7
commit 48c5ab59f1
2 changed files with 0 additions and 65 deletions

View File

@ -125,7 +125,6 @@
%% gen_mod/supervisor callbacks. %% gen_mod/supervisor callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> {ok, pid()}. -spec start(binary(), gen_mod:opts()) -> {ok, pid()}.
start(ServerHost, Opts) -> start(ServerHost, Opts) ->
case gen_mod:get_opt(rm_on_unregister, Opts) of case gen_mod:get_opt(rm_on_unregister, Opts) of
true -> true ->
@ -138,7 +137,6 @@ start(ServerHost, Opts) ->
gen_mod:start_child(?MODULE, ServerHost, Opts, Proc). gen_mod:start_child(?MODULE, ServerHost, Opts, Proc).
-spec stop(binary()) -> ok | {error, any()}. -spec stop(binary()) -> ok | {error, any()}.
stop(ServerHost) -> stop(ServerHost) ->
case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister) of case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister) of
true -> true ->
@ -151,7 +149,6 @@ stop(ServerHost) ->
gen_mod:stop_child(Proc). gen_mod:stop_child(Proc).
-spec mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()]. -spec mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
mod_opt_type(host) -> mod_opt_type(host) ->
fun iolist_to_binary/1; fun iolist_to_binary/1;
mod_opt_type(hosts) -> mod_opt_type(hosts) ->
@ -218,7 +215,6 @@ mod_opt_type(thumbnail) ->
end. end.
-spec mod_options(binary()) -> [{atom(), any()}]. -spec mod_options(binary()) -> [{atom(), any()}].
mod_options(_Host) -> mod_options(_Host) ->
[{host, <<"upload.@HOST@">>}, [{host, <<"upload.@HOST@">>},
{hosts, []}, {hosts, []},
@ -238,16 +234,13 @@ mod_options(_Host) ->
{thumbnail, true}]. {thumbnail, true}].
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}]. -spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].
depends(_Host, _Opts) -> depends(_Host, _Opts) ->
[]. [].
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% gen_server callbacks. %% gen_server callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec init(list()) -> {ok, state()}. -spec init(list()) -> {ok, state()}.
init([ServerHost, Opts]) -> init([ServerHost, Opts]) ->
process_flag(trap_exit, true), process_flag(trap_exit, true),
Hosts = gen_mod:get_opt_hosts(ServerHost, Opts), Hosts = gen_mod:get_opt_hosts(ServerHost, Opts),
@ -295,7 +288,6 @@ init([ServerHost, Opts]) ->
pos_integer() | undefined, pos_integer() | undefined,
pos_integer() | undefined}, state()} | pos_integer() | undefined}, state()} |
{reply, {error, atom()}, state()} | {noreply, state()}. {reply, {error, atom()}, state()} | {noreply, state()}.
handle_call({use_slot, Slot, Size}, _From, handle_call({use_slot, Slot, Size}, _From,
#state{file_mode = FileMode, #state{file_mode = FileMode,
dir_mode = DirMode, dir_mode = DirMode,
@ -325,13 +317,11 @@ handle_call(Request, From, State) ->
{noreply, State}. {noreply, State}.
-spec handle_cast(_, state()) -> {noreply, state()}. -spec handle_cast(_, state()) -> {noreply, state()}.
handle_cast(Request, State) -> handle_cast(Request, State) ->
?ERROR_MSG("Got unexpected request: ~p", [Request]), ?ERROR_MSG("Got unexpected request: ~p", [Request]),
{noreply, State}. {noreply, State}.
-spec handle_info(timeout | _, state()) -> {noreply, state()}. -spec handle_info(timeout | _, state()) -> {noreply, state()}.
handle_info({route, #iq{lang = Lang} = Packet}, State) -> handle_info({route, #iq{lang = Lang} = Packet}, State) ->
try xmpp:decode_els(Packet) of try xmpp:decode_els(Packet) of
IQ -> IQ ->
@ -363,13 +353,11 @@ handle_info(Info, State) ->
{noreply, State}. {noreply, State}.
-spec terminate(normal | shutdown | {shutdown, _} | _, state()) -> ok. -spec terminate(normal | shutdown | {shutdown, _} | _, state()) -> ok.
terminate(Reason, #state{server_host = ServerHost, hosts = Hosts}) -> terminate(Reason, #state{server_host = ServerHost, hosts = Hosts}) ->
?DEBUG("Stopping HTTP upload process for ~s: ~p", [ServerHost, Reason]), ?DEBUG("Stopping HTTP upload process for ~s: ~p", [ServerHost, Reason]),
lists:foreach(fun ejabberd_router:unregister_route/1, Hosts). lists:foreach(fun ejabberd_router:unregister_route/1, Hosts).
-spec code_change({down, _} | _, state(), _) -> {ok, state()}. -spec code_change({down, _} | _, state(), _) -> {ok, state()}.
code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) -> code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) ->
?DEBUG("Updating HTTP upload process for ~s", [ServerHost]), ?DEBUG("Updating HTTP upload process for ~s", [ServerHost]),
{ok, State}. {ok, State}.
@ -377,10 +365,8 @@ code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% ejabberd_http callback. %% ejabberd_http callback.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec process([binary()], #request{}) -spec process([binary()], #request{})
-> {pos_integer(), [{binary(), binary()}], binary()}. -> {pos_integer(), [{binary(), binary()}], binary()}.
process(LocalPath, #request{method = Method, host = Host, ip = IP}) process(LocalPath, #request{method = Method, host = Host, ip = IP})
when length(LocalPath) < 3, when length(LocalPath) < 3,
Method == 'PUT' orelse Method == 'PUT' orelse
@ -485,9 +471,7 @@ process(_LocalPath, #request{method = Method, host = Host, ip = IP}) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Exported utility functions. %% Exported utility functions.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec get_proc_name(binary(), atom()) -> atom(). -spec get_proc_name(binary(), atom()) -> atom().
get_proc_name(ServerHost, ModuleName) -> get_proc_name(ServerHost, ModuleName) ->
PutURL = gen_mod:get_module_opt(ServerHost, ?MODULE, put_url), PutURL = gen_mod:get_module_opt(ServerHost, ?MODULE, put_url),
{ok, {_Scheme, _UserInfo, Host, _Port, Path, _Query}} = {ok, {_Scheme, _UserInfo, Host, _Port, Path, _Query}} =
@ -496,13 +480,11 @@ get_proc_name(ServerHost, ModuleName) ->
gen_mod:get_module_proc(ProcPrefix, ModuleName). gen_mod:get_module_proc(ProcPrefix, ModuleName).
-spec expand_home(binary()) -> binary(). -spec expand_home(binary()) -> binary().
expand_home(Input) -> expand_home(Input) ->
{ok, [[Home]]} = init:get_argument(home), {ok, [[Home]]} = init:get_argument(home),
misc:expand_keyword(<<"@HOME@">>, Input, Home). misc:expand_keyword(<<"@HOME@">>, Input, Home).
-spec expand_host(binary(), binary()) -> binary(). -spec expand_host(binary(), binary()) -> binary().
expand_host(Input, Host) -> expand_host(Input, Host) ->
misc:expand_keyword(<<"@HOST@">>, Input, Host). misc:expand_keyword(<<"@HOST@">>, Input, Host).
@ -513,7 +495,6 @@ expand_host(Input, Host) ->
%% XMPP request handling. %% XMPP request handling.
-spec process_iq(iq(), state()) -> {iq(), state()} | iq() | not_request. -spec process_iq(iq(), state()) -> {iq(), state()} | iq() | not_request.
process_iq(#iq{type = get, lang = Lang, sub_els = [#disco_info{}]} = IQ, process_iq(#iq{type = get, lang = Lang, sub_els = [#disco_info{}]} = IQ,
#state{server_host = ServerHost, name = Name}) -> #state{server_host = ServerHost, name = Name}) ->
AddInfo = ejabberd_hooks:run_fold(disco_info, ServerHost, [], AddInfo = ejabberd_hooks:run_fold(disco_info, ServerHost, [],
@ -541,7 +522,6 @@ process_iq(#iq{}, _State) ->
-spec process_slot_request(iq(), binary(), pos_integer(), binary(), binary(), -spec process_slot_request(iq(), binary(), pos_integer(), binary(), binary(),
state()) -> {iq(), state()} | iq(). state()) -> {iq(), state()} | iq().
process_slot_request(#iq{lang = Lang, from = From} = IQ, process_slot_request(#iq{lang = Lang, from = From} = IQ,
File, Size, CType, XMLNS, File, Size, CType, XMLNS,
#state{server_host = ServerHost, #state{server_host = ServerHost,
@ -572,7 +552,6 @@ process_slot_request(#iq{lang = Lang, from = From} = IQ,
-spec create_slot(state(), jid(), binary(), pos_integer(), binary(), binary()) -spec create_slot(state(), jid(), binary(), pos_integer(), binary(), binary())
-> {ok, slot()} | {ok, binary(), binary()} | {error, xmlel()}. -> {ok, slot()} | {ok, binary(), binary()} | {error, xmlel()}.
create_slot(#state{service_url = undefined, max_size = MaxSize}, create_slot(#state{service_url = undefined, max_size = MaxSize},
JID, File, Size, _ContentType, Lang) when MaxSize /= infinity, JID, File, Size, _ContentType, Lang) when MaxSize /= infinity,
Size > MaxSize -> Size > MaxSize ->
@ -649,25 +628,21 @@ create_slot(#state{service_url = ServiceURL},
end. end.
-spec add_slot(slot(), pos_integer(), timer:tref(), state()) -> state(). -spec add_slot(slot(), pos_integer(), timer:tref(), state()) -> state().
add_slot(Slot, Size, Timer, #state{slots = Slots} = State) -> add_slot(Slot, Size, Timer, #state{slots = Slots} = State) ->
NewSlots = maps:put(Slot, {Size, Timer}, Slots), NewSlots = maps:put(Slot, {Size, Timer}, Slots),
State#state{slots = NewSlots}. State#state{slots = NewSlots}.
-spec get_slot(slot(), state()) -> {ok, {pos_integer(), timer:tref()}} | error. -spec get_slot(slot(), state()) -> {ok, {pos_integer(), timer:tref()}} | error.
get_slot(Slot, #state{slots = Slots}) -> get_slot(Slot, #state{slots = Slots}) ->
maps:find(Slot, Slots). maps:find(Slot, Slots).
-spec del_slot(slot(), state()) -> state(). -spec del_slot(slot(), state()) -> state().
del_slot(Slot, #state{slots = Slots} = State) -> del_slot(Slot, #state{slots = Slots} = State) ->
NewSlots = maps:remove(Slot, Slots), NewSlots = maps:remove(Slot, Slots),
State#state{slots = NewSlots}. State#state{slots = NewSlots}.
-spec mk_slot(slot(), state(), binary()) -> upload_slot(); -spec mk_slot(slot(), state(), binary()) -> upload_slot();
(binary(), binary(), binary()) -> upload_slot(). (binary(), binary(), binary()) -> upload_slot().
mk_slot(Slot, #state{put_url = PutPrefix, get_url = GetPrefix}, XMLNS) -> mk_slot(Slot, #state{put_url = PutPrefix, get_url = GetPrefix}, XMLNS) ->
PutURL = str:join([PutPrefix | Slot], <<$/>>), PutURL = str:join([PutPrefix | Slot], <<$/>>),
GetURL = str:join([GetPrefix | Slot], <<$/>>), GetURL = str:join([GetPrefix | Slot], <<$/>>),
@ -682,30 +657,25 @@ mk_slot(PutURL, GetURL, XMLNS) ->
xmlns = XMLNS}. xmlns = XMLNS}.
-spec make_user_string(jid(), sha1 | node) -> binary(). -spec make_user_string(jid(), sha1 | node) -> binary().
make_user_string(#jid{luser = U, lserver = S}, sha1) -> make_user_string(#jid{luser = U, lserver = S}, sha1) ->
str:sha(<<U/binary, $@, S/binary>>); str:sha(<<U/binary, $@, S/binary>>);
make_user_string(#jid{luser = U}, node) -> make_user_string(#jid{luser = U}, node) ->
replace_special_chars(U). replace_special_chars(U).
-spec make_file_string(binary()) -> binary(). -spec make_file_string(binary()) -> binary().
make_file_string(File) -> make_file_string(File) ->
replace_special_chars(File). replace_special_chars(File).
-spec replace_special_chars(binary()) -> binary(). -spec replace_special_chars(binary()) -> binary().
replace_special_chars(S) -> replace_special_chars(S) ->
re:replace(S, <<"[^\\p{Xan}_.-]">>, <<$_>>, re:replace(S, <<"[^\\p{Xan}_.-]">>, <<$_>>,
[unicode, global, {return, binary}]). [unicode, global, {return, binary}]).
-spec yield_content_type(binary()) -> binary(). -spec yield_content_type(binary()) -> binary().
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()]) -> disco_info(). -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) of Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size) of
infinity -> infinity ->
@ -738,7 +708,6 @@ iq_disco_info(Host, Lang, Name, AddInfo) ->
%% HTTP request handling. %% HTTP request handling.
-spec parse_http_request(#request{}) -> {atom(), slot()}. -spec parse_http_request(#request{}) -> {atom(), slot()}.
parse_http_request(#request{host = Host, path = Path}) -> parse_http_request(#request{host = Host, path = Path}) ->
PrefixLength = length(Path) - 3, PrefixLength = length(Path) - 3,
{ProcURL, Slot} = if PrefixLength > 0 -> {ProcURL, Slot} = if PrefixLength > 0 ->
@ -755,7 +724,6 @@ parse_http_request(#request{host = Host, path = Path}) ->
integer() | undefined, integer() | undefined,
binary(), slot(), boolean()) binary(), slot(), boolean())
-> ok | {ok, [{binary(), binary()}], binary()} | {error, term()}. -> ok | {ok, [{binary(), binary()}], binary()} | {error, term()}.
store_file(Path, Data, FileMode, DirMode, GetPrefix, Slot, Thumbnail) -> store_file(Path, Data, FileMode, DirMode, GetPrefix, Slot, Thumbnail) ->
case do_store_file(Path, Data, FileMode, DirMode) of case do_store_file(Path, Data, FileMode, DirMode) of
ok when Thumbnail -> ok when Thumbnail ->
@ -788,7 +756,6 @@ store_file(Path, Data, FileMode, DirMode, GetPrefix, Slot, Thumbnail) ->
integer() | undefined, integer() | undefined,
integer() | undefined) integer() | undefined)
-> ok | {error, term()}. -> ok | {error, term()}.
do_store_file(Path, Data, FileMode, DirMode) -> do_store_file(Path, Data, FileMode, DirMode) ->
try try
ok = filelib:ensure_dir(Path), ok = filelib:ensure_dir(Path),
@ -817,7 +784,6 @@ do_store_file(Path, Data, FileMode, DirMode) ->
end. end.
-spec guess_content_type(binary()) -> binary(). -spec guess_content_type(binary()) -> binary().
guess_content_type(FileName) -> guess_content_type(FileName) ->
mod_http_fileserver:content_type(FileName, mod_http_fileserver:content_type(FileName,
?DEFAULT_CONTENT_TYPE, ?DEFAULT_CONTENT_TYPE,
@ -825,20 +791,17 @@ guess_content_type(FileName) ->
-spec http_response(100..599) -spec http_response(100..599)
-> {pos_integer(), [{binary(), binary()}], binary()}. -> {pos_integer(), [{binary(), binary()}], binary()}.
http_response(Code) -> http_response(Code) ->
http_response(Code, []). http_response(Code, []).
-spec http_response(100..599, [{binary(), binary()}]) -spec http_response(100..599, [{binary(), binary()}])
-> {pos_integer(), [{binary(), binary()}], binary()}. -> {pos_integer(), [{binary(), binary()}], binary()}.
http_response(Code, ExtraHeaders) -> http_response(Code, ExtraHeaders) ->
Message = <<(code_to_message(Code))/binary, $\n>>, Message = <<(code_to_message(Code))/binary, $\n>>,
http_response(Code, ExtraHeaders, Message). http_response(Code, ExtraHeaders, Message).
-spec http_response(100..599, [{binary(), binary()}], binary()) -spec http_response(100..599, [{binary(), binary()}], binary())
-> {pos_integer(), [{binary(), binary()}], binary()}. -> {pos_integer(), [{binary(), binary()}], binary()}.
http_response(Code, ExtraHeaders, Body) -> http_response(Code, ExtraHeaders, Body) ->
Headers = case proplists:is_defined(<<"Content-Type">>, ExtraHeaders) of Headers = case proplists:is_defined(<<"Content-Type">>, ExtraHeaders) of
true -> true ->
@ -849,7 +812,6 @@ http_response(Code, ExtraHeaders, Body) ->
{Code, Headers, Body}. {Code, Headers, Body}.
-spec code_to_message(100..599) -> binary(). -spec code_to_message(100..599) -> binary().
code_to_message(201) -> <<"Upload successful.">>; code_to_message(201) -> <<"Upload successful.">>;
code_to_message(403) -> <<"Forbidden.">>; code_to_message(403) -> <<"Forbidden.">>;
code_to_message(404) -> <<"Not found.">>; code_to_message(404) -> <<"Not found.">>;
@ -861,9 +823,7 @@ code_to_message(_Code) -> <<"">>.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Image manipulation stuff. %% Image manipulation stuff.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec identify(binary(), binary()) -> {ok, media_info()} | pass. -spec identify(binary(), binary()) -> {ok, media_info()} | pass.
identify(Path, Data) -> identify(Path, Data) ->
case eimp:identify(Data) of case eimp:identify(Data) of
{ok, Info} -> {ok, Info} ->
@ -878,7 +838,6 @@ identify(Path, Data) ->
end. end.
-spec convert(binary(), binary(), media_info()) -> {ok, binary(), media_info()} | pass. -spec convert(binary(), binary(), media_info()) -> {ok, binary(), media_info()} | pass.
convert(Path, Data, #media_info{type = T, width = W, height = H} = Info) -> convert(Path, Data, #media_info{type = T, width = W, height = H} = Info) ->
if W * H >= 25000000 -> if W * H >= 25000000 ->
?DEBUG("The image ~s is more than 25 Mpix", [Path]), ?DEBUG("The image ~s is more than 25 Mpix", [Path]),
@ -913,7 +872,6 @@ convert(Path, Data, #media_info{type = T, width = W, height = H} = Info) ->
end. end.
-spec thumb_el(media_info(), binary()) -> xmlel(). -spec thumb_el(media_info(), binary()) -> xmlel().
thumb_el(#media_info{type = T, height = H, width = W}, URI) -> thumb_el(#media_info{type = T, height = H, width = W}, URI) ->
MimeType = <<"image/", (atom_to_binary(T, latin1))/binary>>, MimeType = <<"image/", (atom_to_binary(T, latin1))/binary>>,
Thumb = #thumbnail{'media-type' = MimeType, uri = URI, Thumb = #thumbnail{'media-type' = MimeType, uri = URI,
@ -923,9 +881,7 @@ thumb_el(#media_info{type = T, height = H, width = W}, URI) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Remove user. %% Remove user.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec remove_user(binary(), binary()) -> ok. -spec remove_user(binary(), binary()) -> ok.
remove_user(User, Server) -> remove_user(User, Server) ->
ServerHost = jid:nameprep(Server), ServerHost = jid:nameprep(Server),
DocRoot = gen_mod:get_module_opt(ServerHost, ?MODULE, docroot), DocRoot = gen_mod:get_module_opt(ServerHost, ?MODULE, docroot),
@ -945,7 +901,6 @@ remove_user(User, Server) ->
ok. ok.
-spec del_tree(file:filename_all()) -> ok | {error, term()}. -spec del_tree(file:filename_all()) -> ok | {error, term()}.
del_tree(Dir) when is_binary(Dir) -> del_tree(Dir) when is_binary(Dir) ->
del_tree(binary_to_list(Dir)); del_tree(binary_to_list(Dir));
del_tree(Dir) -> del_tree(Dir) ->

View File

@ -70,19 +70,16 @@
%% gen_mod/supervisor callbacks. %% gen_mod/supervisor callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec start(binary(), gen_mod:opts()) -> {ok, pid()}. -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 | {error, any()}. -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),
gen_mod:stop_child(Proc). gen_mod:stop_child(Proc).
-spec mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()]. -spec mod_opt_type(atom()) -> fun((term()) -> term()) | [atom()].
mod_opt_type(access_soft_quota) -> mod_opt_type(access_soft_quota) ->
fun acl:shaper_rules_validator/1; fun acl:shaper_rules_validator/1;
mod_opt_type(access_hard_quota) -> mod_opt_type(access_hard_quota) ->
@ -93,23 +90,19 @@ mod_opt_type(max_days) ->
end. end.
-spec mod_options(binary()) -> [{atom(), any()}]. -spec mod_options(binary()) -> [{atom(), any()}].
mod_options(_) -> mod_options(_) ->
[{access_soft_quota, soft_upload_quota}, [{access_soft_quota, soft_upload_quota},
{access_hard_quota, hard_upload_quota}, {access_hard_quota, hard_upload_quota},
{max_days, infinity}]. {max_days, infinity}].
-spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}]. -spec depends(binary(), gen_mod:opts()) -> [{module(), hard | soft}].
depends(_Host, _Opts) -> depends(_Host, _Opts) ->
[{mod_http_upload, hard}]. [{mod_http_upload, hard}].
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% gen_server callbacks. %% gen_server callbacks.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec init(list()) -> {ok, state()}. -spec init(list()) -> {ok, state()}.
init([ServerHost, Opts]) -> init([ServerHost, Opts]) ->
process_flag(trap_exit, true), process_flag(trap_exit, true),
AccessSoftQuota = gen_mod:get_opt(access_soft_quota, Opts), AccessSoftQuota = gen_mod:get_opt(access_soft_quota, Opts),
@ -134,13 +127,11 @@ init([ServerHost, Opts]) ->
timers = Timers}}. timers = Timers}}.
-spec handle_call(_, {pid(), _}, state()) -> {noreply, state()}. -spec handle_call(_, {pid(), _}, state()) -> {noreply, state()}.
handle_call(Request, From, State) -> handle_call(Request, From, State) ->
?ERROR_MSG("Got unexpected request from ~p: ~p", [From, Request]), ?ERROR_MSG("Got unexpected request from ~p: ~p", [From, Request]),
{noreply, State}. {noreply, State}.
-spec handle_cast(_, state()) -> {noreply, state()}. -spec handle_cast(_, state()) -> {noreply, state()}.
handle_cast({handle_slot_request, #jid{user = U, server = S} = JID, Path, Size}, handle_cast({handle_slot_request, #jid{user = U, server = S} = JID, Path, Size},
#state{server_host = ServerHost, #state{server_host = ServerHost,
access_soft_quota = AccessSoftQuota, access_soft_quota = AccessSoftQuota,
@ -198,7 +189,6 @@ handle_cast(Request, State) ->
{noreply, State}. {noreply, State}.
-spec handle_info(_, state()) -> {noreply, state()}. -spec handle_info(_, state()) -> {noreply, state()}.
handle_info(sweep, #state{server_host = ServerHost, handle_info(sweep, #state{server_host = ServerHost,
docroot = DocRoot, docroot = DocRoot,
max_days = MaxDays} = State) max_days = MaxDays} = State)
@ -225,7 +215,6 @@ handle_info(Info, State) ->
{noreply, State}. {noreply, State}.
-spec terminate(normal | shutdown | {shutdown, _} | _, state()) -> ok. -spec terminate(normal | shutdown | {shutdown, _} | _, state()) -> ok.
terminate(Reason, #state{server_host = ServerHost, timers = Timers}) -> terminate(Reason, #state{server_host = ServerHost, timers = Timers}) ->
?DEBUG("Stopping upload quota process for ~s: ~p", [ServerHost, Reason]), ?DEBUG("Stopping upload quota process for ~s: ~p", [ServerHost, Reason]),
ejabberd_hooks:delete(http_upload_slot_request, ServerHost, ?MODULE, ejabberd_hooks:delete(http_upload_slot_request, ServerHost, ?MODULE,
@ -233,7 +222,6 @@ terminate(Reason, #state{server_host = ServerHost, timers = Timers}) ->
lists:foreach(fun timer:cancel/1, Timers). lists:foreach(fun timer:cancel/1, Timers).
-spec code_change({down, _} | _, state(), _) -> {ok, state()}. -spec code_change({down, _} | _, state(), _) -> {ok, state()}.
code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) -> code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) ->
?DEBUG("Updating upload quota process for ~s", [ServerHost]), ?DEBUG("Updating upload quota process for ~s", [ServerHost]),
{ok, State}. {ok, State}.
@ -241,10 +229,8 @@ code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% ejabberd_hooks callback. %% ejabberd_hooks callback.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec handle_slot_request(allow | deny, jid(), binary(), -spec handle_slot_request(allow | deny, jid(), binary(),
non_neg_integer(), binary()) -> allow | deny. non_neg_integer(), binary()) -> allow | deny.
handle_slot_request(allow, #jid{lserver = ServerHost} = JID, Path, Size, handle_slot_request(allow, #jid{lserver = ServerHost} = JID, Path, Size,
_Lang) -> _Lang) ->
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE), Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),
@ -255,12 +241,10 @@ handle_slot_request(Acc, _JID, _Path, _Size, _Lang) -> Acc.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% Internal functions. %% Internal functions.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec enforce_quota(file:filename_all(), non_neg_integer(), -spec enforce_quota(file:filename_all(), non_neg_integer(),
non_neg_integer() | undefined, non_neg_integer(), non_neg_integer() | undefined, non_neg_integer(),
non_neg_integer()) non_neg_integer())
-> non_neg_integer(). -> non_neg_integer().
enforce_quota(_UserDir, SlotSize, OldSize, _MinSize, MaxSize) enforce_quota(_UserDir, SlotSize, OldSize, _MinSize, MaxSize)
when is_integer(OldSize), OldSize + SlotSize =< MaxSize -> when is_integer(OldSize), OldSize + SlotSize =< MaxSize ->
OldSize + SlotSize; OldSize + SlotSize;
@ -286,7 +270,6 @@ enforce_quota(UserDir, SlotSize, _OldSize, MinSize, MaxSize) ->
end. end.
-spec delete_old_files(file:filename_all(), integer()) -> ok. -spec delete_old_files(file:filename_all(), integer()) -> ok.
delete_old_files(UserDir, CutOff) -> delete_old_files(UserDir, CutOff) ->
FileInfo = gather_file_info(UserDir), FileInfo = gather_file_info(UserDir),
case [Path || {Path, _Size, Time} <- FileInfo, Time < CutOff] of case [Path || {Path, _Size, Time} <- FileInfo, Time < CutOff] of
@ -299,7 +282,6 @@ delete_old_files(UserDir, CutOff) ->
-spec gather_file_info(file:filename_all()) -spec gather_file_info(file:filename_all())
-> [{binary(), non_neg_integer(), non_neg_integer()}]. -> [{binary(), non_neg_integer(), non_neg_integer()}].
gather_file_info(Dir) when is_binary(Dir) -> gather_file_info(Dir) when is_binary(Dir) ->
gather_file_info(binary_to_list(Dir)); gather_file_info(binary_to_list(Dir));
gather_file_info(Dir) -> gather_file_info(Dir) ->
@ -334,7 +316,6 @@ gather_file_info(Dir) ->
end. end.
-spec del_file_and_dir(file:name_all()) -> ok. -spec del_file_and_dir(file:name_all()) -> ok.
del_file_and_dir(File) -> del_file_and_dir(File) ->
case file:delete(File) of case file:delete(File) of
ok -> ok ->
@ -351,7 +332,6 @@ del_file_and_dir(File) ->
end. end.
-spec secs_since_epoch() -> non_neg_integer(). -spec secs_since_epoch() -> non_neg_integer().
secs_since_epoch() -> secs_since_epoch() ->
{MegaSecs, Secs, _MicroSecs} = os:timestamp(), {MegaSecs, Secs, _MicroSecs} = os:timestamp(),
MegaSecs * 1000000 + Secs. MegaSecs * 1000000 + Secs.