From f4950cdc83c634d7032b0779fa1c7602e24e9936 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sun, 23 Aug 2015 17:22:32 +0200 Subject: [PATCH] mod_http_upload: Add "rm_on_unregister" option The new "rm_on_unregister" option allows admins to specify whether files uploaded by a user should be removed when that user is unregistered. --- mod_http_upload/README.txt | 6 +++++ mod_http_upload/src/mod_http_upload.erl | 32 ++++++++++++++++++------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/mod_http_upload/README.txt b/mod_http_upload/README.txt index 766cd50..1395fe2 100644 --- a/mod_http_upload/README.txt +++ b/mod_http_upload/README.txt @@ -132,3 +132,9 @@ The configurable mod_http_upload options are: In any other case, a 'service-unavailable' error stanza is sent to the client. + +- rm_on_unregister (default: 'true') + + This option specifies whether files uploaded by a user should be removed + when that user is unregistered. It must be set to 'false' if this is not + desired. diff --git a/mod_http_upload/src/mod_http_upload.erl b/mod_http_upload/src/mod_http_upload.erl index dd397c1..26366ae 100644 --- a/mod_http_upload/src/mod_http_upload.erl +++ b/mod_http_upload/src/mod_http_upload.erl @@ -100,10 +100,16 @@ start_link(ServerHost, ProcHost, Opts) -> -spec start(binary(), gen_mod:opts()) -> {ok, _} | {ok, _, _} | {error, _}. start(ServerHost, Opts) -> - ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, - remove_user, 50), - ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, - remove_user, 50), + case gen_mod:get_opt(rm_on_unregister, Opts, + fun(B) when is_boolean(B) -> B end, + true) of + true -> + ejabberd_hooks:add(remove_user, ServerHost, ?MODULE, + remove_user, 50), + ejabberd_hooks:add(anonymous_purge_hook, ServerHost, ?MODULE, + remove_user, 50); + false -> ok + end, PutURL = gen_mod:get_opt(put_url, Opts, fun(<<"http://", _/binary>> = URL) -> URL; (<<"https://", _/binary>> = URL) -> URL; @@ -125,10 +131,16 @@ start(ServerHost, Opts) -> -spec stop(binary()) -> ok. stop(ServerHost) -> - ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, - remove_user, 50), - ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, - remove_user, 50), + case gen_mod:get_module_opt(ServerHost, ?MODULE, rm_on_unregister, + fun(B) when is_boolean(B) -> B end, + true) of + true -> + ejabberd_hooks:delete(remove_user, ServerHost, ?MODULE, + remove_user, 50), + ejabberd_hooks:delete(anonymous_purge_hook, ServerHost, ?MODULE, + remove_user, 50); + false -> ok + end, Proc = gen_mod:get_module_proc(ServerHost, ?PROCNAME), ok = supervisor:terminate_child(ejabberd_sup, Proc), ok = supervisor:delete_child(ejabberd_sup, Proc). @@ -165,9 +177,11 @@ mod_opt_type(service_url) -> fun(<<"http://", _/binary>> = URL) -> URL; (<<"https://", _/binary>> = URL) -> URL end; +mod_opt_type(rm_on_unregister) -> + fun(B) when is_boolean(B) -> B end; mod_opt_type(_) -> [host, name, access, max_size, secret_length, jid_in_url, docroot, - put_url, get_url, service_url]. + put_url, get_url, service_url, rm_on_unregister]. %%-------------------------------------------------------------------- %% gen_server callbacks.