mirror of
https://github.com/processone/ejabberd.git
synced 2025-01-03 18:02:28 +01:00
Don't call gen_mod:get_opt() outside of modules
This commit is contained in:
parent
01a2c9fe12
commit
8368a0850a
@ -490,8 +490,8 @@ handle_send(Pkt, Result, #{lserver := LServer} = State) ->
|
|||||||
ejabberd_hooks:run_fold(c2s_handle_send, LServer, State, [Pkt, Result]).
|
ejabberd_hooks:run_fold(c2s_handle_send, LServer, State, [Pkt, Result]).
|
||||||
|
|
||||||
init([State, Opts]) ->
|
init([State, Opts]) ->
|
||||||
Access = gen_mod:get_opt(access, Opts, all),
|
Access = proplists:get_value(access, Opts, all),
|
||||||
Shaper = gen_mod:get_opt(shaper, Opts, none),
|
Shaper = proplists:get_value(shaper, Opts, none),
|
||||||
TLSOpts1 = lists:filter(
|
TLSOpts1 = lists:filter(
|
||||||
fun({certfile, _}) -> true;
|
fun({certfile, _}) -> true;
|
||||||
({ciphers, _}) -> true;
|
({ciphers, _}) -> true;
|
||||||
|
@ -136,15 +136,15 @@ init({SockMod, Socket}, Opts) ->
|
|||||||
true -> [{[], ejabberd_xmlrpc}];
|
true -> [{[], ejabberd_xmlrpc}];
|
||||||
false -> []
|
false -> []
|
||||||
end,
|
end,
|
||||||
DefinedHandlers = gen_mod:get_opt(request_handlers, Opts, []),
|
DefinedHandlers = proplists:get_value(request_handlers, Opts, []),
|
||||||
RequestHandlers = DefinedHandlers ++ Captcha ++ Register ++
|
RequestHandlers = DefinedHandlers ++ Captcha ++ Register ++
|
||||||
Admin ++ Bind ++ XMLRPC,
|
Admin ++ Bind ++ XMLRPC,
|
||||||
?DEBUG("S: ~p~n", [RequestHandlers]),
|
?DEBUG("S: ~p~n", [RequestHandlers]),
|
||||||
|
|
||||||
DefaultHost = gen_mod:get_opt(default_host, Opts, undefined),
|
DefaultHost = proplists:get_value(default_host, Opts),
|
||||||
{ok, RE} = re:compile(<<"^(?:\\[(.*?)\\]|(.*?))(?::(\\d+))?$">>),
|
{ok, RE} = re:compile(<<"^(?:\\[(.*?)\\]|(.*?))(?::(\\d+))?$">>),
|
||||||
|
|
||||||
CustomHeaders = gen_mod:get_opt(custom_headers, Opts, []),
|
CustomHeaders = proplists:get_value(custom_headers, Opts, []),
|
||||||
|
|
||||||
?INFO_MSG("started: ~p", [{SockMod1, Socket1}]),
|
?INFO_MSG("started: ~p", [{SockMod1, Socket1}]),
|
||||||
State = #state{sockmod = SockMod1,
|
State = #state{sockmod = SockMod1,
|
||||||
|
@ -244,7 +244,7 @@ handle_send(Pkt, Result, #{server_host := LServer} = State) ->
|
|||||||
State, [Pkt, Result]).
|
State, [Pkt, Result]).
|
||||||
|
|
||||||
init([State, Opts]) ->
|
init([State, Opts]) ->
|
||||||
Shaper = gen_mod:get_opt(shaper, Opts, none),
|
Shaper = proplists:get_value(shaper, Opts, none),
|
||||||
TLSOpts1 = lists:filter(
|
TLSOpts1 = lists:filter(
|
||||||
fun({certfile, _}) -> true;
|
fun({certfile, _}) -> true;
|
||||||
({ciphers, _}) -> true;
|
({ciphers, _}) -> true;
|
||||||
|
@ -79,15 +79,15 @@ tls_options(#{tls_options := TLSOptions}) ->
|
|||||||
TLSOptions.
|
TLSOptions.
|
||||||
|
|
||||||
init([State, Opts]) ->
|
init([State, Opts]) ->
|
||||||
Access = gen_mod:get_opt(access, Opts, all),
|
Access = proplists:get_value(access, Opts, all),
|
||||||
Shaper = gen_mod:get_opt(shaper_rule, Opts, none),
|
Shaper = proplists:get_value(shaper_rule, Opts, none),
|
||||||
GlobalPassword = gen_mod:get_opt(password, Opts, random_password()),
|
GlobalPassword = proplists:get_value(password, Opts, random_password()),
|
||||||
HostOpts = gen_mod:get_opt(hosts, Opts, [{global, GlobalPassword}]),
|
HostOpts = proplists:get_value(hosts, Opts, [{global, GlobalPassword}]),
|
||||||
HostOpts1 = lists:map(
|
HostOpts1 = lists:map(
|
||||||
fun({Host, undefined}) -> {Host, GlobalPassword};
|
fun({Host, undefined}) -> {Host, GlobalPassword};
|
||||||
({Host, Password}) -> {Host, Password}
|
({Host, Password}) -> {Host, Password}
|
||||||
end, HostOpts),
|
end, HostOpts),
|
||||||
CheckFrom = gen_mod:get_opt(check_from, Opts, true),
|
CheckFrom = proplists:get_value(check_from, Opts, true),
|
||||||
TLSOpts1 = lists:filter(
|
TLSOpts1 = lists:filter(
|
||||||
fun({certfile, _}) -> true;
|
fun({certfile, _}) -> true;
|
||||||
({ciphers, _}) -> true;
|
({ciphers, _}) -> true;
|
||||||
|
@ -73,9 +73,9 @@ prepare_turn_opts(Opts, _UseTurn = true) ->
|
|||||||
ok
|
ok
|
||||||
end,
|
end,
|
||||||
AuthFun = fun ejabberd_auth:get_password_s/2,
|
AuthFun = fun ejabberd_auth:get_password_s/2,
|
||||||
Shaper = gen_mod:get_opt(shaper, Opts, none),
|
Shaper = proplists:get_value(shaper, Opts, none),
|
||||||
AuthType = gen_mod:get_opt(auth_type, Opts, user),
|
AuthType = proplists:get_value(auth_type, Opts, user),
|
||||||
Realm = case gen_mod:get_opt(auth_realm, Opts) of
|
Realm = case proplists:get_value(auth_realm, Opts) of
|
||||||
undefined when AuthType == user ->
|
undefined when AuthType == user ->
|
||||||
if NumberOfMyHosts > 1 ->
|
if NumberOfMyHosts > 1 ->
|
||||||
?WARNING_MSG("you have several virtual "
|
?WARNING_MSG("you have several virtual "
|
||||||
|
@ -197,7 +197,7 @@ socket_type() -> raw.
|
|||||||
%% HTTP interface
|
%% HTTP interface
|
||||||
%% -----------------------------
|
%% -----------------------------
|
||||||
process(_, #request{method = 'POST', data = Data, opts = Opts, ip = {IP, _}}) ->
|
process(_, #request{method = 'POST', data = Data, opts = Opts, ip = {IP, _}}) ->
|
||||||
AccessCommands = gen_mod:get_opt(access_commands, Opts),
|
AccessCommands = proplists:get_value(access_commands, Opts),
|
||||||
GetAuth = true,
|
GetAuth = true,
|
||||||
State = #state{access_commands = AccessCommands, get_auth = GetAuth, ip = IP},
|
State = #state{access_commands = AccessCommands, get_auth = GetAuth, ip = IP},
|
||||||
case fxml_stream:parse_element(Data) of
|
case fxml_stream:parse_element(Data) of
|
||||||
|
@ -565,7 +565,7 @@ get_handle(Name) when is_binary(Name) ->
|
|||||||
%% process.
|
%% process.
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
init([Hosts, Port, Rootdn, Passwd, Opts]) ->
|
init([Hosts, Port, Rootdn, Passwd, Opts]) ->
|
||||||
Encrypt = case gen_mod:get_opt(encrypt, Opts) of
|
Encrypt = case proplists:get_value(encrypt, Opts) of
|
||||||
tls -> tls;
|
tls -> tls;
|
||||||
_ -> none
|
_ -> none
|
||||||
end,
|
end,
|
||||||
@ -577,19 +577,19 @@ init([Hosts, Port, Rootdn, Passwd, Opts]) ->
|
|||||||
end;
|
end;
|
||||||
PT -> PT
|
PT -> PT
|
||||||
end,
|
end,
|
||||||
CacertOpts = case gen_mod:get_opt(tls_cacertfile, Opts) of
|
CacertOpts = case proplists:get_value(tls_cacertfile, Opts) of
|
||||||
undefined ->
|
undefined ->
|
||||||
[];
|
[];
|
||||||
Path ->
|
Path ->
|
||||||
[{cacertfile, Path}]
|
[{cacertfile, Path}]
|
||||||
end,
|
end,
|
||||||
DepthOpts = case gen_mod:get_opt(tls_depth, Opts) of
|
DepthOpts = case proplists:get_value(tls_depth, Opts) of
|
||||||
undefined ->
|
undefined ->
|
||||||
[];
|
[];
|
||||||
Depth ->
|
Depth ->
|
||||||
[{depth, Depth}]
|
[{depth, Depth}]
|
||||||
end,
|
end,
|
||||||
Verify = gen_mod:get_opt(tls_verify, Opts, false),
|
Verify = proplists:get_value(tls_verify, Opts, false),
|
||||||
TLSOpts = if (Verify == hard orelse Verify == soft)
|
TLSOpts = if (Verify == hard orelse Verify == soft)
|
||||||
andalso CacertOpts == [] ->
|
andalso CacertOpts == [] ->
|
||||||
?WARNING_MSG("TLS verification is enabled but no CA "
|
?WARNING_MSG("TLS verification is enabled but no CA "
|
||||||
|
@ -173,25 +173,25 @@ uids_domain_subst(Host, UIDs) ->
|
|||||||
-spec get_config(binary(), list()) -> eldap_config().
|
-spec get_config(binary(), list()) -> eldap_config().
|
||||||
|
|
||||||
get_config(Host, Opts) ->
|
get_config(Host, Opts) ->
|
||||||
Servers = gen_mod:get_opt({ldap_servers, Host}, Opts, [<<"localhost">>]),
|
Servers = get_opt(ldap_servers, Host, Opts, [<<"localhost">>]),
|
||||||
Backups = gen_mod:get_opt({ldap_backups, Host}, Opts, []),
|
Backups = get_opt(ldap_backups, Host, Opts, []),
|
||||||
Encrypt = gen_mod:get_opt({ldap_encrypt, Host}, Opts, none),
|
Encrypt = get_opt(ldap_encrypt, Host, Opts, none),
|
||||||
TLSVerify = gen_mod:get_opt({ldap_tls_verify, Host}, Opts, false),
|
TLSVerify = get_opt(ldap_tls_verify, Host, Opts, false),
|
||||||
TLSCAFile = gen_mod:get_opt({ldap_tls_cacertfile, Host}, Opts),
|
TLSCAFile = get_opt(ldap_tls_cacertfile, Host, Opts),
|
||||||
TLSDepth = gen_mod:get_opt({ldap_tls_depth, Host}, Opts),
|
TLSDepth = get_opt(ldap_tls_depth, Host, Opts),
|
||||||
Port = gen_mod:get_opt({ldap_port, Host}, Opts,
|
Port = get_opt(ldap_port, Host, Opts,
|
||||||
case Encrypt of
|
case Encrypt of
|
||||||
tls -> ?LDAPS_PORT;
|
tls -> ?LDAPS_PORT;
|
||||||
starttls -> ?LDAP_PORT;
|
starttls -> ?LDAP_PORT;
|
||||||
_ -> ?LDAP_PORT
|
_ -> ?LDAP_PORT
|
||||||
end),
|
end),
|
||||||
RootDN = gen_mod:get_opt({ldap_rootdn, Host}, Opts, <<"">>),
|
RootDN = get_opt(ldap_rootdn, Host, Opts, <<"">>),
|
||||||
Password = gen_mod:get_opt({ldap_password, Host}, Opts, <<"">>),
|
Password = get_opt(ldap_password, Host, Opts, <<"">>),
|
||||||
Base = gen_mod:get_opt({ldap_base, Host}, Opts, <<"">>),
|
Base = get_opt(ldap_base, Host, Opts, <<"">>),
|
||||||
OldDerefAliases = gen_mod:get_opt({deref_aliases, Host}, Opts, unspecified),
|
OldDerefAliases = get_opt(deref_aliases, Host, Opts, unspecified),
|
||||||
DerefAliases =
|
DerefAliases =
|
||||||
if OldDerefAliases == unspecified ->
|
if OldDerefAliases == unspecified ->
|
||||||
gen_mod:get_opt({ldap_deref_aliases, Host}, Opts, never);
|
get_opt(ldap_deref_aliases, Host, Opts, never);
|
||||||
true ->
|
true ->
|
||||||
?WARNING_MSG("Option 'deref_aliases' is deprecated. "
|
?WARNING_MSG("Option 'deref_aliases' is deprecated. "
|
||||||
"The option is still supported "
|
"The option is still supported "
|
||||||
@ -211,6 +211,15 @@ get_config(Host, Opts) ->
|
|||||||
base = Base,
|
base = Base,
|
||||||
deref_aliases = DerefAliases}.
|
deref_aliases = DerefAliases}.
|
||||||
|
|
||||||
|
get_opt(Opt, Host, Opts) ->
|
||||||
|
get_opt(Opt, Host, Opts, undefined).
|
||||||
|
|
||||||
|
get_opt(Opt, Host, Opts, Default) ->
|
||||||
|
case proplists:get_value(Opt, Opts) of
|
||||||
|
undefined -> ejabberd_config:get_option({Opt, Host}, Default);
|
||||||
|
Value -> Value
|
||||||
|
end.
|
||||||
|
|
||||||
%%----------------------------------------
|
%%----------------------------------------
|
||||||
%% Borrowed from asn1rt_ber_bin_v2.erl
|
%% Borrowed from asn1rt_ber_bin_v2.erl
|
||||||
%%----------------------------------------
|
%%----------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user