From ece563205c2bdeee63c2bde96167d9872bafb83d Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Wed, 27 Oct 2021 12:08:12 +0200 Subject: [PATCH] Remove dynamically compiled modules from mod_http_upload --- src/http_upload/mod_http_upload.erl | 18 +++--------- src/http_upload/mod_http_upload_backend.erl | 31 +++++++++++++++++++++ src/http_upload/mod_http_upload_s3.erl | 2 +- 3 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 src/http_upload/mod_http_upload_backend.erl diff --git a/src/http_upload/mod_http_upload.erl b/src/http_upload/mod_http_upload.erl index 404e6e4001..3548531a87 100644 --- a/src/http_upload/mod_http_upload.erl +++ b/src/http_upload/mod_http_upload.erl @@ -46,17 +46,7 @@ %% mongoose_module_metrics callbacks -export([config_metrics/1]). --ignore_xref([{mod_http_upload_backend, create_slot, 6}, - behaviour_info/1, disco_local_items/1, process_disco_iq/5, process_iq/5]). - -%%-------------------------------------------------------------------- -%% Callbacks -%%-------------------------------------------------------------------- - --callback create_slot(UTCDateTime :: calendar:datetime(), UUID :: binary(), - Filename :: unicode:unicode_binary(), ContentType :: binary() | undefined, - Size :: pos_integer(), Opts :: proplists:proplist()) -> - {PUTURL :: binary(), GETURL :: binary(), Headers :: #{binary() => binary()}}. +-ignore_xref([behaviour_info/1, disco_local_items/1, process_disco_iq/5, process_iq/5]). %%-------------------------------------------------------------------- %% API @@ -72,7 +62,7 @@ start(HostType, Opts) -> [gen_iq_handler:add_iq_handler_for_subdomain(HostType, SubdomainPattern, Namespace, Component, Fn, #{}, IQDisc) || {Component, Namespace, Fn} <- iq_handlers()], - gen_mod:start_backend_module(?MODULE, with_default_backend(Opts), [create_slot]), + mod_http_upload_backend:init(HostType, with_default_backend(Opts)), ejabberd_hooks:add(hooks(HostType)), ok. @@ -157,7 +147,7 @@ process_iq(Acc, _From, _To, IQ = #iq{type = get, sub_el = Request}, _Extra) -> Opts = module_opts(HostType), {PutUrl, GetUrl, Headers} = - mod_http_upload_backend:create_slot(UTCDateTime, Token, Filename, + mod_http_upload_backend:create_slot(HostType, UTCDateTime, Token, Filename, ContentType, Size, Opts), compose_iq_reply(IQ, PutUrl, GetUrl, Headers); @@ -209,7 +199,7 @@ get_urls(HostType, Filename, Size, ContentType, Timeout) -> Token = generate_token(HostType), Opts = module_opts(HostType), NewOpts = gen_mod:set_opt(expiration_time, Opts, Timeout), - mod_http_upload_backend:create_slot(UTCDateTime, Token, Filename, + mod_http_upload_backend:create_slot(HostType, UTCDateTime, Token, Filename, ContentType, Size, NewOpts). %%-------------------------------------------------------------------- diff --git a/src/http_upload/mod_http_upload_backend.erl b/src/http_upload/mod_http_upload_backend.erl new file mode 100644 index 0000000000..848c7d4cef --- /dev/null +++ b/src/http_upload/mod_http_upload_backend.erl @@ -0,0 +1,31 @@ +%% Just a proxy interface module between the main mod_http_upload module and +%% the backend modules (i.e. mod_http_upload_s3). +-module(mod_http_upload_backend). + +-export([init/2, create_slot/7]). + +-define(MAIN_MODULE, mod_http_upload). +%%-------------------------------------------------------------------- +%% Callbacks +%%-------------------------------------------------------------------- + +-callback create_slot(UTCDateTime :: calendar:datetime(), UUID :: binary(), + Filename :: unicode:unicode_binary(), ContentType :: binary() | undefined, + Size :: pos_integer(), Opts :: proplists:proplist()) -> + {PUTURL :: binary(), GETURL :: binary(), Headers :: #{binary() => binary()}}. + +-spec init(HostType :: mongooseim:host_type(), Opts :: gen_mod:module_opts()) -> ok. +init(HostType, Opts) -> + mongoose_backend:init_per_host_type(HostType, ?MAIN_MODULE, [create_slot], Opts). + +-spec create_slot(HostType::mongooseim:host_type(), + UTCDateTime :: calendar:datetime(), + UUID :: binary(), + Filename :: unicode:unicode_binary(), + ContentType :: binary() | undefined, + Size :: pos_integer(), + Opts :: proplists:proplist()) -> + {PUTURL :: binary(), GETURL :: binary(), Headers :: #{binary() => binary()}}. +create_slot(HostType, UTCDateTime, UUID, Filename, ContentType, Size, Opts) -> + Args = [UTCDateTime, UUID, Filename, ContentType, Size, Opts], + mongoose_backend:call_tracked(HostType, ?MAIN_MODULE, ?FUNCTION_NAME, Args). \ No newline at end of file diff --git a/src/http_upload/mod_http_upload_s3.erl b/src/http_upload/mod_http_upload_s3.erl index 7a72c6ea74..ad5a52f8dc 100644 --- a/src/http_upload/mod_http_upload_s3.erl +++ b/src/http_upload/mod_http_upload_s3.erl @@ -16,7 +16,7 @@ -module(mod_http_upload_s3). -author('konrad.zemek@erlang-solutions.com'). --behaviour(mod_http_upload). +-behaviour(mod_http_upload_backend). -export([create_slot/6]).