From a205ebad2bd139c0d413a3aa85de045847c5228f Mon Sep 17 00:00:00 2001 From: Evgeny Khramtsov Date: Sat, 15 Jun 2019 12:53:16 +0300 Subject: [PATCH] Get rid of "well-known" type --- src/econf.erl | 26 ++++++-------------------- src/ejabberd_auth.erl | 5 +---- src/ejabberd_oauth.erl | 5 +---- src/ejabberd_options.erl | 12 ++++++------ src/ejabberd_router.erl | 5 +---- src/ejabberd_sm.erl | 5 +---- src/mod_announce.erl | 15 ++++++--------- src/mod_bosh.erl | 17 +++++++---------- src/mod_caps.erl | 15 ++++++--------- src/mod_http_upload.erl | 4 ++-- src/mod_last.erl | 15 ++++++--------- src/mod_mam.erl | 15 ++++++--------- src/mod_mix.erl | 6 +++--- src/mod_mix_pam.erl | 15 ++++++--------- src/mod_mqtt.erl | 19 ++++++++----------- src/mod_muc.erl | 10 +++++----- src/mod_multicast.erl | 4 ++-- src/mod_offline.erl | 11 ++++------- src/mod_privacy.erl | 19 ++++++++----------- src/mod_private.erl | 15 ++++++--------- src/mod_proxy65.erl | 8 ++++---- src/mod_pubsub.erl | 6 +++--- src/mod_push.erl | 15 ++++++--------- src/mod_roster.erl | 15 ++++++--------- src/mod_shared_roster.erl | 2 +- src/mod_shared_roster_ldap.erl | 13 +++++-------- src/mod_stream_mgmt.erl | 4 ++-- src/mod_vcard.erl | 19 ++++++++----------- src/mod_vcard_xupdate.erl | 13 +++++-------- tools/opt_types.sh | 16 ++++------------ 30 files changed, 135 insertions(+), 214 deletions(-) diff --git a/src/econf.erl b/src/econf.erl index ac8b9ca6d..822e22d6f 100644 --- a/src/econf.erl +++ b/src/econf.erl @@ -49,7 +49,8 @@ -export([acl/0, shaper/0, url_or_file/0, lang/0]). -export([pem/0, queue_type/0]). -export([jid/0, user/0, domain/0, resource/0]). --export([db_type/1, ldap_filter/0, well_known/2]). +-export([db_type/1, ldap_filter/0]). +-export([host/0, hosts/0]). -ifdef(SIP). -export([sip_uri/0]). -endif. @@ -462,25 +463,6 @@ ldap_filter() -> end end). -well_known(queue_type, _) -> - queue_type(); -well_known(db_type, M) -> - db_type(M); -well_known(ram_db_type, M) -> - db_type(M); -well_known(cache_life_time, _) -> - pos_int(infinity); -well_known(cache_size, _) -> - pos_int(infinity); -well_known(use_cache, _) -> - bool(); -well_known(cache_missed, _) -> - bool(); -well_known(host, _) -> - host(); -well_known(hosts, _) -> - list(host(), [unique]). - -ifdef(SIP). sip_uri() -> and_then( @@ -507,6 +489,10 @@ host() -> end end. +-spec hosts() -> yconf:validator([binary()]). +hosts() -> + list(host(), [unique]). + %%%=================================================================== %%% Internal functions %%%=================================================================== diff --git a/src/ejabberd_auth.erl b/src/ejabberd_auth.erl index 82ec5393e..389e65d85 100644 --- a/src/ejabberd_auth.erl +++ b/src/ejabberd_auth.erl @@ -768,10 +768,7 @@ init_cache(HostModules) -> cache_opts() -> MaxSize = ejabberd_option:auth_cache_size(), CacheMissed = ejabberd_option:auth_cache_missed(), - LifeTime = case ejabberd_option:auth_cache_life_time() of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = ejabberd_option:auth_cache_life_time(), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(map()) -> {True :: [module()], False :: [module()]}. diff --git a/src/ejabberd_oauth.erl b/src/ejabberd_oauth.erl index 3e1a0cf1c..5a18f02f8 100644 --- a/src/ejabberd_oauth.erl +++ b/src/ejabberd_oauth.erl @@ -366,10 +366,7 @@ use_cache(DBMod) -> cache_opts() -> MaxSize = ejabberd_option:oauth_cache_size(), CacheMissed = ejabberd_option:oauth_cache_missed(), - LifeTime = case ejabberd_option:oauth_cache_life_time() of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = ejabberd_option:oauth_cache_life_time(), [{max_size, MaxSize}, {life_time, LifeTime}, {cache_missed, CacheMissed}]. expire() -> diff --git a/src/ejabberd_options.erl b/src/ejabberd_options.erl index 013c2155c..e47ca6711 100644 --- a/src/ejabberd_options.erl +++ b/src/ejabberd_options.erl @@ -57,7 +57,7 @@ opt_type(append_host_config) -> econf:enum(ejabberd_option:hosts())), validator()); opt_type(auth_cache_life_time) -> - econf:pos_int(infinity); + econf:timeout(second, infinity); opt_type(auth_cache_missed) -> econf:bool(); opt_type(auth_cache_size) -> @@ -83,7 +83,7 @@ opt_type(c2s_tls_compression) -> opt_type(ca_file) -> econf:pem(); opt_type(cache_life_time) -> - econf:pos_int(infinity); + econf:timeout(second, infinity); opt_type(cache_missed) -> econf:bool(); opt_type(cache_size) -> @@ -219,7 +219,7 @@ opt_type(new_sql_schema) -> opt_type(oauth_access) -> econf:acl(); opt_type(oauth_cache_life_time) -> - econf:pos_int(infinity); + econf:timeout(second, infinity); opt_type(oauth_cache_missed) -> econf:bool(); opt_type(oauth_cache_size) -> @@ -295,7 +295,7 @@ opt_type(riak_username) -> opt_type(route_subdomains) -> econf:enum([s2s, local]); opt_type(router_cache_life_time) -> - econf:pos_int(infinity); + econf:timeout(second, infinity); opt_type(router_cache_missed) -> econf:bool(); opt_type(router_cache_size) -> @@ -347,7 +347,7 @@ opt_type(shaper) -> opt_type(shaper_rules) -> ejabberd_shaper:validator(shaper_rules); opt_type(sm_cache_life_time) -> - econf:pos_int(infinity); + econf:timeout(second, infinity); opt_type(sm_cache_missed) -> econf:bool(); opt_type(sm_cache_size) -> @@ -435,7 +435,7 @@ options() -> [%% Top-priority options hosts, {loglevel, 4}, - {cache_life_time, 3600}, + {cache_life_time, timer:seconds(3600)}, {cache_missed, true}, {cache_size, 1000}, {use_cache, true}, diff --git a/src/ejabberd_router.erl b/src/ejabberd_router.erl index 6f75944c4..4a2a6bd30 100644 --- a/src/ejabberd_router.erl +++ b/src/ejabberd_router.erl @@ -468,10 +468,7 @@ init_cache(Mod) -> cache_opts() -> MaxSize = ejabberd_option:router_cache_size(), CacheMissed = ejabberd_option:router_cache_missed(), - LifeTime = case ejabberd_option:router_cache_life_time() of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = ejabberd_option:router_cache_life_time(), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec clean_cache(node()) -> non_neg_integer(). diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index b85dbd9cc..f0c705aae 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -912,10 +912,7 @@ init_cache() -> cache_opts() -> MaxSize = ejabberd_option:sm_cache_size(), CacheMissed = ejabberd_option:sm_cache_missed(), - LifeTime = case ejabberd_option:sm_cache_life_time() of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = ejabberd_option:sm_cache_life_time(), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec clean_cache(node()) -> non_neg_integer(). diff --git a/src/mod_announce.erl b/src/mod_announce.erl index cee9384d6..4176af95c 100644 --- a/src/mod_announce.erl +++ b/src/mod_announce.erl @@ -855,10 +855,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_announce_opt:cache_size(Opts), CacheMissed = mod_announce_opt:cache_missed(Opts), - LifeTime = case mod_announce_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_announce_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). @@ -900,15 +897,15 @@ import(LServer, {sql, _}, DBType, Tab, List) -> mod_opt_type(access) -> econf:acl(); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{access, none}, diff --git a/src/mod_bosh.erl b/src/mod_bosh.erl index d8268e2be..5ed3d5e8d 100644 --- a/src/mod_bosh.erl +++ b/src/mod_bosh.erl @@ -170,17 +170,17 @@ mod_opt_type(max_pause) -> mod_opt_type(prebind) -> econf:bool(); mod_opt_type(queue_type) -> - econf:well_known(queue_type, ?MODULE); + econf:queue_type(); mod_opt_type(ram_db_type) -> - econf:well_known(ram_db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). -spec mod_options(binary()) -> [{json, boolean()} | {atom(), term()}]. @@ -240,10 +240,7 @@ delete_cache(Mod, SID) -> cache_opts(Host) -> MaxSize = mod_bosh_opt:cache_size(Host), CacheMissed = mod_bosh_opt:cache_missed(Host), - LifeTime = case mod_bosh_opt:cache_life_time(Host) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_bosh_opt:cache_life_time(Host), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec clean_cache(node()) -> non_neg_integer(). diff --git a/src/mod_caps.erl b/src/mod_caps.erl index 75c4d6356..21f18f10c 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -503,10 +503,7 @@ use_cache(Mod, Host) -> cache_opts(Opts) -> MaxSize = mod_caps_opt:cache_size(Opts), CacheMissed = mod_caps_opt:cache_missed(Opts), - LifeTime = case mod_caps_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_caps_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. export(LServer) -> @@ -545,15 +542,15 @@ import_next(LServer, DBType, NodePair) -> import_next(LServer, DBType, ets:next(caps_features_tmp, NodePair)). mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{db_type, ejabberd_config:default_db(Host, ?MODULE)}, diff --git a/src/mod_http_upload.erl b/src/mod_http_upload.erl index 92185e30f..7d10430be 100644 --- a/src/mod_http_upload.erl +++ b/src/mod_http_upload.erl @@ -193,9 +193,9 @@ mod_opt_type(thumbnail) -> mod_opt_type(external_secret) -> econf:binary(); mod_opt_type(host) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(hosts) -> - econf:well_known(hosts, ?MODULE). + econf:hosts(). -spec mod_options(binary()) -> [{thumbnail, boolean()} | {atom(), any()}]. diff --git a/src/mod_last.erl b/src/mod_last.erl index 17db7fabb..558c105bf 100644 --- a/src/mod_last.erl +++ b/src/mod_last.erl @@ -270,10 +270,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_last_opt:cache_size(Opts), CacheMissed = mod_last_opt:cache_missed(Opts), - LifeTime = case mod_last_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_last_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). @@ -316,15 +313,15 @@ depends(_Host, _Opts) -> []. mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{db_type, ejabberd_config:default_db(Host, ?MODULE)}, diff --git a/src/mod_mam.erl b/src/mod_mam.erl index ba8a9bcfc..1e90689d0 100644 --- a/src/mod_mam.erl +++ b/src/mod_mam.erl @@ -176,10 +176,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_mam_opt:cache_size(Opts), CacheMissed = mod_mam_opt:cache_missed(Opts), - LifeTime = case mod_mam_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_mam_opt:cache_life_time(Opts), [{max_size, MaxSize}, {life_time, LifeTime}, {cache_missed, CacheMissed}]. stop(Host) -> @@ -1404,15 +1401,15 @@ mod_opt_type(user_mucsub_from_muc_archive) -> mod_opt_type(access_preferences) -> econf:acl(); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{assume_mam_usage, false}, diff --git a/src/mod_mix.erl b/src/mod_mix.erl index 01446314b..3bf387ced 100644 --- a/src/mod_mix.erl +++ b/src/mod_mix.erl @@ -82,11 +82,11 @@ mod_opt_type(access_create) -> mod_opt_type(name) -> econf:binary(); mod_opt_type(host) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(hosts) -> - econf:well_known(hosts, ?MODULE); + econf:hosts(); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE). + econf:db_type(?MODULE). mod_options(Host) -> [{access_create, all}, diff --git a/src/mod_mix_pam.erl b/src/mod_mix_pam.erl index b9eba337e..4516568c0 100644 --- a/src/mod_mix_pam.erl +++ b/src/mod_mix_pam.erl @@ -85,15 +85,15 @@ depends(_Host, _Opts) -> []. mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{db_type, ejabberd_config:default_db(Host, ?MODULE)}, @@ -334,10 +334,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_mix_pam_opt:cache_size(Opts), CacheMissed = mod_mix_pam_opt:cache_missed(Opts), - LifeTime = case mod_mix_pam_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_mix_pam_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). diff --git a/src/mod_mqtt.erl b/src/mod_mqtt.erl index 196b6efbe..1649ef50d 100644 --- a/src/mod_mqtt.erl +++ b/src/mod_mqtt.erl @@ -229,19 +229,19 @@ mod_opt_type(access_subscribe) -> mod_opt_type(access_publish) -> topic_access_validator(); mod_opt_type(queue_type) -> - econf:well_known(queue_type, ?MODULE); + econf:queue_type(); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(ram_db_type) -> - econf:well_known(ram_db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). listen_opt_type(tls_verify) -> econf:bool(); @@ -541,10 +541,7 @@ init_payload_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_mqtt_opt:cache_size(Opts), CacheMissed = mod_mqtt_opt:cache_missed(Opts), - LifeTime = case mod_mqtt_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_mqtt_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). diff --git a/src/mod_muc.erl b/src/mod_muc.erl index fb4595c94..c04996a1f 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -1016,15 +1016,15 @@ mod_opt_type(default_room_options) -> public_list => econf:bool(), title => econf:binary()}); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(ram_db_type) -> - econf:well_known(ram_db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(host) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(hosts) -> - econf:well_known(hosts, ?MODULE); + econf:hosts(); mod_opt_type(queue_type) -> - econf:well_known(queue_type, ?MODULE). + econf:queue_type(). mod_options(Host) -> [{access, all}, diff --git a/src/mod_multicast.erl b/src/mod_multicast.erl index e8513bac2..9c5272996 100644 --- a/src/mod_multicast.erl +++ b/src/mod_multicast.erl @@ -1140,9 +1140,9 @@ mod_opt_type(limits) -> #{message => econf:non_neg_int(infinite), presence => econf:non_neg_int(infinite)})}); mod_opt_type(host) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(hosts) -> - econf:well_known(hosts, ?MODULE). + econf:hosts(). mod_options(Host) -> [{access, all}, diff --git a/src/mod_offline.erl b/src/mod_offline.erl index 1c1b22663..d2468e975 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -172,10 +172,7 @@ init_cache(Opts) -> case mod_offline_opt:use_mam_for_storage(Opts) of true -> MaxSize = mod_offline_opt:cache_size(Opts), - LifeTime = case mod_offline_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_offline_opt:cache_life_time(Opts), COpts = [{max_size, MaxSize}, {cache_missed, false}, {life_time, LifeTime}], ets_cache:new(?EMPTY_SPOOL_CACHE, COpts); false -> @@ -1107,11 +1104,11 @@ mod_opt_type(store_empty_body) -> unless_chat_state, econf:bool()); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{db_type, ejabberd_config:default_db(Host, ?MODULE)}, diff --git a/src/mod_privacy.erl b/src/mod_privacy.erl index 988333f4f..1d06e83fb 100644 --- a/src/mod_privacy.erl +++ b/src/mod_privacy.erl @@ -419,7 +419,7 @@ update_c2s_state_with_privacy_list(#iq{ State#{privacy_active_list => none}; _ -> case get_user_list(U, S, Active) of - {ok, _} -> + {ok, _} -> ?DEBUG("Setting active privacy list ~p for user ~p", [Active, jid:encode(To)]), State#{privacy_active_list => Active}; _ -> State % unknown privacy list name @@ -444,7 +444,7 @@ user_send_packet({#iq{type = Type, end, {NewIQ, update_c2s_state_with_privacy_list(IQ, State)}; -% for client with no active privacy list, see if there is +% for client with no active privacy list, see if there is % one about to be activated in this packet and update client state user_send_packet({Packet, State}) -> {Packet, update_c2s_state_with_privacy_list(Packet, State)}. @@ -706,10 +706,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_privacy_opt:cache_size(Opts), CacheMissed = mod_privacy_opt:cache_missed(Opts), - LifeTime = case mod_privacy_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_privacy_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). @@ -849,15 +846,15 @@ depends(_Host, _Opts) -> []. mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{db_type, ejabberd_config:default_db(Host, ?MODULE)}, diff --git a/src/mod_private.erl b/src/mod_private.erl index 350817eea..bd2e6b623 100644 --- a/src/mod_private.erl +++ b/src/mod_private.erl @@ -93,15 +93,15 @@ depends(_Host, _Opts) -> [{mod_pubsub, soft}]. mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{db_type, ejabberd_config:default_db(Host, ?MODULE)}, @@ -353,10 +353,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_private_opt:cache_size(Opts), CacheMissed = mod_private_opt:cache_missed(Opts), - LifeTime = case mod_private_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_private_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). diff --git a/src/mod_proxy65.erl b/src/mod_proxy65.erl index 4d8d06b43..bd8cdde66 100644 --- a/src/mod_proxy65.erl +++ b/src/mod_proxy65.erl @@ -97,7 +97,7 @@ depends(_Host, _Opts) -> mod_opt_type(access) -> econf:acl(); mod_opt_type(hostname) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(ip) -> econf:ip(); mod_opt_type(name) -> @@ -107,11 +107,11 @@ mod_opt_type(port) -> mod_opt_type(max_connections) -> econf:pos_int(infinity); mod_opt_type(host) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(hosts) -> - econf:well_known(hosts, ?MODULE); + econf:hosts(); mod_opt_type(ram_db_type) -> - econf:well_known(ram_db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(server_host) -> econf:binary(); mod_opt_type(auth_type) -> diff --git a/src/mod_pubsub.erl b/src/mod_pubsub.erl index 1656a7cbd..e80887551 100644 --- a/src/mod_pubsub.erl +++ b/src/mod_pubsub.erl @@ -3894,11 +3894,11 @@ mod_opt_type(pep_mapping) -> mod_opt_type(plugins) -> econf:list(econf:binary()); mod_opt_type(host) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(hosts) -> - econf:well_known(hosts, ?MODULE); + econf:hosts(); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE). + econf:db_type(?MODULE). mod_options(Host) -> [{access_createnode, all}, diff --git a/src/mod_push.erl b/src/mod_push.erl index 5dc924884..8ba3d7e72 100644 --- a/src/mod_push.erl +++ b/src/mod_push.erl @@ -132,15 +132,15 @@ mod_opt_type(include_body) -> econf:bool(), econf:binary()); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). -spec mod_options(binary()) -> [{atom(), any()}]. mod_options(Host) -> @@ -718,10 +718,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_push_opt:cache_size(Opts), CacheMissed = mod_push_opt:cache_missed(Opts), - LifeTime = case mod_push_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_push_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). diff --git a/src/mod_roster.erl b/src/mod_roster.erl index a29259c57..eed03a0e6 100644 --- a/src/mod_roster.erl +++ b/src/mod_roster.erl @@ -1130,10 +1130,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_roster_opt:cache_size(Opts), CacheMissed = mod_roster_opt:cache_missed(Opts), - LifeTime = case mod_roster_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_roster_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary(), roster | roster_version) -> boolean(). @@ -1220,15 +1217,15 @@ mod_opt_type(store_current_id) -> mod_opt_type(versioning) -> econf:bool(); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{access, all}, diff --git a/src/mod_shared_roster.erl b/src/mod_shared_roster.erl index 7e17e2005..c3de2903b 100644 --- a/src/mod_shared_roster.erl +++ b/src/mod_shared_roster.erl @@ -1008,7 +1008,7 @@ import(LServer, {sql, _}, DBType, Tab, L) -> Mod:import(LServer, Tab, L). mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE). + econf:db_type(?MODULE). mod_options(Host) -> [{db_type, ejabberd_config:default_db(Host, ?MODULE)}]. diff --git a/src/mod_shared_roster_ldap.erl b/src/mod_shared_roster_ldap.erl index 524f65113..c48715718 100644 --- a/src/mod_shared_roster_ldap.erl +++ b/src/mod_shared_roster_ldap.erl @@ -519,10 +519,7 @@ use_cache(_Host, Opts) -> cache_opts(_Host, Opts) -> MaxSize = mod_shared_roster_ldap_opt:cache_size(Opts), CacheMissed = mod_shared_roster_ldap_opt:cache_missed(Opts), - LifeTime = case mod_shared_roster_ldap_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_shared_roster_ldap_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. mod_opt_type(ldap_auth_check) -> @@ -581,13 +578,13 @@ mod_opt_type(ldap_uids) -> fun(U) -> {U, <<"%u">>} end)), econf:map(econf:binary(), econf:binary(), [unique])); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). -spec mod_options(binary()) -> [{ldap_uids, [{binary(), binary()}]} | {atom(), any()}]. diff --git a/src/mod_stream_mgmt.erl b/src/mod_stream_mgmt.erl index 58b2c4395..15a735c85 100644 --- a/src/mod_stream_mgmt.erl +++ b/src/mod_stream_mgmt.erl @@ -784,9 +784,9 @@ mod_opt_type(resend_on_timeout) -> if_offline, econf:bool()); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(queue_type) -> - econf:well_known(queue_type, ?MODULE). + econf:queue_type(). mod_options(Host) -> [{max_ack_queue, 5000}, diff --git a/src/mod_vcard.erl b/src/mod_vcard.erl index dc8e83879..a050a372e 100644 --- a/src/mod_vcard.erl +++ b/src/mod_vcard.erl @@ -497,10 +497,7 @@ init_cache(Mod, Host, Opts) -> cache_opts(_Host, Opts) -> MaxSize = mod_vcard_opt:cache_size(Opts), CacheMissed = mod_vcard_opt:cache_missed(Opts), - LifeTime = case mod_vcard_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_vcard_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(module(), binary()) -> boolean(). @@ -544,19 +541,19 @@ mod_opt_type(matches) -> mod_opt_type(search) -> econf:bool(); mod_opt_type(host) -> - econf:well_known(host, ?MODULE); + econf:host(); mod_opt_type(hosts) -> - econf:well_known(hosts, ?MODULE); + econf:hosts(); mod_opt_type(db_type) -> - econf:well_known(db_type, ?MODULE); + econf:db_type(?MODULE); mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{allow_return_all, false}, diff --git a/src/mod_vcard_xupdate.erl b/src/mod_vcard_xupdate.erl index 1cdfcff32..927ea9594 100644 --- a/src/mod_vcard_xupdate.erl +++ b/src/mod_vcard_xupdate.erl @@ -160,10 +160,7 @@ init_cache(Host, Opts) -> cache_opts(Opts) -> MaxSize = mod_vcard_xupdate_opt:cache_size(Opts), CacheMissed = mod_vcard_xupdate_opt:cache_missed(Opts), - LifeTime = case mod_vcard_xupdate_opt:cache_life_time(Opts) of - infinity -> infinity; - I -> timer:seconds(I) - end, + LifeTime = mod_vcard_xupdate_opt:cache_life_time(Opts), [{max_size, MaxSize}, {cache_missed, CacheMissed}, {life_time, LifeTime}]. -spec use_cache(binary()) -> boolean(). @@ -192,13 +189,13 @@ compute_hash(VCard) -> %% Options %%==================================================================== mod_opt_type(use_cache) -> - econf:well_known(use_cache, ?MODULE); + econf:bool(); mod_opt_type(cache_size) -> - econf:well_known(cache_size, ?MODULE); + econf:pos_int(infinity); mod_opt_type(cache_missed) -> - econf:well_known(cache_missed, ?MODULE); + econf:bool(); mod_opt_type(cache_life_time) -> - econf:well_known(cache_life_time, ?MODULE). + econf:timeout(second, infinity). mod_options(Host) -> [{use_cache, ejabberd_option:use_cache(Host)}, diff --git a/tools/opt_types.sh b/tools/opt_types.sh index 6dd46c336..516def304 100755 --- a/tools/opt_types.sh +++ b/tools/opt_types.sh @@ -389,18 +389,10 @@ spec(either, 2, [F1, F2], Mod) -> erl_types:t_sup([Spec1, Spec2]); spec(and_then, 2, [_, F], Mod) -> spec(Mod, F); -spec(well_known, 2, [Form, _], Mod) -> - case erl_syntax:atom_value(Form) of - queue_type -> spec(queue_type, 0, [], Mod); - db_type -> erl_types:t_atom(); - ram_db_type -> erl_types:t_atom(); - cache_life_time -> spec(pos_int, 1, [erl_syntax:atom(infinity)], Mod); - cache_size -> spec(pos_int, 1, [erl_syntax:atom(infinity)], Mod); - use_cache -> spec(bool, 0, [], Mod); - cache_missed -> spec(bool, 0, [], Mod); - host -> erl_types:t_binary(); - hosts -> erl_types:t_list(erl_types:t_binary()) - end; +spec(host, 0, _, _) -> + erl_types:t_binary(); +spec(hosts, 0, _, _) -> + erl_types:t_list(erl_types:t_binary()); spec(options, A, [Form|OForm], Mod) when A == 1; A == 2 -> case erl_syntax:type(Form) of map_expr ->