orber_env.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 1,444 行 · 第 1/4 页
ERL
1,444 行
%%--------------------------------------------------------------------%% ``The contents of this file are subject to the Erlang Public License,%% Version 1.1, (the "License"); you may not use this file except in%% compliance with the License. You should have received a copy of the%% Erlang Public License along with this software. If not, it can be%% retrieved via the world wide web at http://www.erlang.org/.%% %% Software distributed under the License is distributed on an "AS IS"%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See%% the License for the specific language governing rights and limitations%% under the License.%% %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.%% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings%% AB. All Rights Reserved.''%% %% $Id$%%%%-----------------------------------------------------------------%% File: orber_env.erl%% %% Description:%% Handling environment parameters for Orber.%%%% Creation date: 040723%%%%------------------------------------------------------------------module(orber_env).-behaviour(gen_server).-include_lib("orber/include/corba.hrl").-include_lib("orber/src/orber_iiop.hrl").%%-----------------------------------------------------------------%% External exports%%------------------------------------------------------------------export([start/1, configure/2, configure/3, configure_override/2, multi_configure/1, get_env/1, set_env/2, get_keys/0, env/1, info/0, info/1]).-export([iiop_acl/0, iiop_port/0, nat_iiop_port/0, nat_iiop_port/1, iiop_out_ports/0, domain/0, ip_address_variable_defined/0, nat_host/0, nat_host/1, host/0, ip_address/0, ip_address/1, giop_version/0, iiop_timeout/0, iiop_connection_timeout/0, iiop_setup_connection_timeout/0, iiop_in_connection_timeout/0, iiop_max_fragments/0, iiop_max_in_requests/0, iiop_max_in_connections/0, iiop_backlog/0, objectkeys_gc_time/0, get_ORBInitRef/0, get_ORBDefaultInitRef/0, get_interceptors/0, get_local_interceptors/0, get_cached_interceptors/0, set_interceptors/1, is_lightweight/0, get_lightweight_nodes/0, secure/0, iiop_ssl_backlog/0, iiop_ssl_port/0, nat_iiop_ssl_port/0, nat_iiop_ssl_port/1, ssl_server_certfile/0, ssl_client_certfile/0, set_ssl_client_certfile/1, ssl_server_verify/0, ssl_client_verify/0, set_ssl_client_verify/1, ssl_server_depth/0, ssl_client_depth/0, set_ssl_client_depth/1, ssl_server_cacertfile/0, ssl_client_cacertfile/0, set_ssl_client_cacertfile/1, ssl_client_password/0, ssl_server_password/0, ssl_client_keyfile/0, ssl_server_keyfile/0, ssl_client_ciphers/0, ssl_server_ciphers/0, ssl_client_cachetimeout/0, ssl_server_cachetimeout/0, get_flags/0, typechecking/0, exclude_codeset_ctx/0, exclude_codeset_component/0, partial_security/0, use_CSIv2/0, use_FT/0, ip_version/0, light_ifr/0, bidir_context/0, get_debug_level/0, getaddrstr/2, addr2str/1, iiop_packet_size/0, iiop_ssl_ip_address_local/0, ip_address_local/0, iiop_in_keepalive/0, iiop_out_keepalive/0, iiop_ssl_in_keepalive/0, iiop_ssl_out_keepalive/0, iiop_ssl_accept_timeout/0]).%%-----------------------------------------------------------------%% Internal exports%%------------------------------------------------------------------export([init/1, terminate/2, handle_call/3]).-export([handle_cast/2, handle_info/2, code_change/3]).%%-----------------------------------------------------------------%% Record Definitions Etc.%%------------------------------------------------------------------define(DEBUG_LEVEL, 5).-define(FORMAT(_F, _A), {error, lists:flatten(io_lib:format(_F, _A))}).-define(EFORMAT(_F, _A), exit(lists:flatten(io_lib:format(_F, _A)))).-define(ENV_DB, orber_env_db).-define(ENV_KEYS, [flags, iiop_port, nat_iiop_port, iiop_out_ports, domain, ip_address, nat_ip_address, giop_version, iiop_timeout, iiop_connection_timeout, iiop_setup_connection_timeout, iiop_in_connection_timeout, iiop_acl, iiop_max_fragments, iiop_max_in_requests, iiop_max_in_connections, iiop_backlog, objectkeys_gc_time, orbInitRef, orbDefaultInitRef, interceptors, local_interceptors, lightweight, ip_address_local, secure, iiop_ssl_ip_address_local, iiop_ssl_backlog, iiop_ssl_port, nat_iiop_ssl_port, ssl_server_certfile, ssl_client_certfile, ssl_server_verify, ssl_client_verify, ssl_server_depth, ssl_client_depth, ssl_server_cacertfile, ssl_client_cacertfile, ssl_client_password, ssl_server_password, ssl_client_keyfile, ssl_server_keyfile, ssl_client_ciphers, ssl_server_ciphers, ssl_client_cachetimeout, ssl_server_cachetimeout, orber_debug_level, iiop_packet_size, iiop_in_keepalive, iiop_out_keepalive, iiop_ssl_in_keepalive, iiop_ssl_out_keepalive, iiop_ssl_accept_timeout]).%% The 'flags' parameter must be first in the list.%-define(ENV_KEYS,% [{flags, ?ORB_ENV_INIT_FLAGS}, {iiop_port, 4001}, nat_iiop_port, % {iiop_out_ports, 0}, {domain, "ORBER"}, ip_address, nat_ip_address, % {giop_version, {1, 1}}, {iiop_timeout, infinity}, % {iiop_connection_timeout, infinity}, {iiop_setup_connection_timeout, infinity}, % {iiop_in_connection_timeout, infinity}, {iiop_acl, []},% {iiop_max_fragments, infinity}, {iiop_max_in_requests, infinity}, % {iiop_max_in_connections, infinity}, {iiop_backlog, 5}, % {objectkeys_gc_time, infinity}, % {orbInitRef, undefined}, {orbDefaultInitRef, undefined},% {interceptors, false}, {local_interceptors, false}, {lightweight, false},% {secure, no}, {iiop_ssl_backlog, 5}, {iiop_ssl_port, 4002}, % nat_iiop_ssl_port, {ssl_server_certfile, []}, {ssl_client_certfile, []},% {ssl_server_verify, 0}, {ssl_client_verify, 0}, {ssl_server_depth, 1}, % {ssl_client_depth, 1}, {ssl_server_cacertfile, []}, % {ssl_client_cacertfile, []}, {ssl_client_password, []},% {ssl_server_password, []}, {ssl_client_keyfile, []}, % {ssl_server_keyfile, []}, {ssl_client_ciphers, []}, % {ssl_server_ciphers, []}, {ssl_client_cachetimeout, infinity},% {ssl_server_cachetimeout, infinity}, {orber_debug_level, 0}]).-record(parameters, {key, value, flags = 0}).-record(env, {acl, parameters, flags = 0}).%%-----------------------------------------------------------------%% External functions%%----------------------------------------------------------------- %%-----------------------------------------------------------------%% function : %% Arguments: %% Returns : %% Exception: %% Effect : %%-----------------------------------------------------------------start(Opts) -> gen_server:start_link({local, orber_env}, ?MODULE, Opts, []).%%-----------------------------------------------------------------%% function : get_keys%% Arguments: %% Returns : %% Exception: %% Effect : %%-----------------------------------------------------------------get_keys() -> ?ENV_KEYS.%%-----------------------------------------------------------------%% function : get_env%% Arguments: %% Returns : %% Exception: %% Effect : %%-----------------------------------------------------------------get_env(Key) when atom(Key) -> case catch ets:lookup(?ENV_DB, Key) of [#parameters{value = Val}] -> {ok, Val}; _ -> undefined end. %%-----------------------------------------------------------------%% function : get_env%% Arguments: %% Returns : %% Exception: %% Effect : %%-----------------------------------------------------------------set_env(Key, Value) when atom(Key) -> case catch ets:insert(?ENV_DB, #parameters{key = Key, value = Value}) of true -> ok; _ -> undefined end. %%-----------------------------------------------------------------%% function : info%% Arguments: IoDervice - info_msg | string | io | {io, Dev}%% Returns : %% Exception: %% Effect : %%-----------------------------------------------------------------info() -> info(info_msg).info(IoDevice) -> Info = case orber_tb:is_running() of true -> Info1 = create_main_info(), Info2 = create_flag_info(Info1), create_security_info(secure(), Info2); _ -> lists:flatten( io_lib:format("======= Orber Execution Environment ======~n" " *** Orber-~s is not running ***~n" "==========================================~n", [?ORBVSN])) end, case IoDevice of info_msg -> error_logger:info_msg(Info); string -> Info; io -> io:format("~s", [Info]); {io, Dev} -> io:format(Dev, "~s", [Info]); _ -> exit("Bad parameter") end.create_main_info() -> {Major, Minor} = giop_version(), [io_lib:format("======= Orber Execution Environment ======~n" "Orber version.................: ~s~n" "Orber domain..................: ~s~n" "IIOP port number..............: ~p~n" "IIOP NAT port number..........: ~p~n" "Interface(s)..................: ~p~n" "Interface(s) NAT..............: ~p~n" "Local Interface (default).....: ~p~n" "Nodes in domain...............: ~p~n" "GIOP version (default)........: ~p.~p~n" "IIOP out timeout..............: ~p msec~n" "IIOP out connection timeout...: ~p msec~n" "IIOP setup connection timeout.: ~p msec~n" "IIOP out ports................: ~p~n" "IIOP out connections..........: ~p~n" "IIOP out connections (pending): ~p~n" "IIOP out keepalive............: ~p~n" "IIOP in connections...........: ~p~n" "IIOP in connection timeout....: ~p msec~n" "IIOP in keepalive.............: ~p~n" "IIOP max fragments............: ~p~n" "IIOP max in requests..........: ~p~n" "IIOP max in connections.......: ~p~n" "IIOP backlog..................: ~p~n" "IIOP ACL......................: ~p~n" "IIOP maximum packet size......: ~p~n" "Object Keys GC interval.......: ~p~n" "Using Interceptors............: ~p~n" "Using Local Interceptors......: ~p~n" "Debug Level...................: ~p~n" "orbInitRef....................: ~p~n" "orbDefaultInitRef.............: ~p~n", [?ORBVSN, domain(), iiop_port(), nat_iiop_port(), host(), nat_host(), ip_address_local(), orber:orber_nodes(), Major, Minor, iiop_timeout(), iiop_connection_timeout(), iiop_setup_connection_timeout(), iiop_out_ports(), orber:iiop_connections(out), orber:iiop_connections_pending(), iiop_out_keepalive(), orber:iiop_connections(in), iiop_in_connection_timeout(), iiop_in_keepalive(), iiop_max_fragments(), iiop_max_in_requests(), iiop_max_in_connections(), iiop_backlog(), iiop_acl(), iiop_packet_size(), objectkeys_gc_time(), get_interceptors(), get_local_interceptors(), get_debug_level(), get_ORBInitRef(), get_ORBDefaultInitRef()])].create_flag_info(Info) -> case get_flags() of ?ORB_ENV_INIT_FLAGS -> [Info, "System Flags Set..............: -\n"]; Flags -> FlagData = check_flags(?ORB_ENV_FLAGS, Flags, []), [Info, "System Flags Set..............: \n", FlagData, "\n"] end. check_flags([], _, Acc) -> Acc;check_flags([{Flag, Txt}|T], Flags, Acc) when ?ORB_FLAG_TEST(Flags, Flag) -> check_flags(T, Flags, [" - ", Txt, "\n"|Acc]);check_flags([_|T], Flags, Acc) -> check_flags(T, Flags, Acc).create_security_info(no, Info) -> lists:flatten([Info, "=========================================\n"]);create_security_info(ssl, Info) -> lists:flatten([Info, io_lib:format("ORB security..................: ssl~n"% "SSL IIOP in keepalive.........: ~p~n"% "SSL IIOP out keepalive........: ~p~n" "SSL IIOP port number..........: ~p~n" "SSL IIOP NAT port number......: ~p~n" "SSL IIOP accept timeout.......: ~p~n" "SSL IIOP backlog..............: ~p~n" "SSL IIOP Local Interface......: ~p~n" "SSL server certfile...........: ~p~n" "SSL server verification type..: ~p~n" "SSL server verification depth.: ~p~n" "SSL server cacertfile.........: ~p~n" "SSL server keyfile............: ~p~n" "SSL server password...........: ~p~n" "SSL server ciphers............: ~p~n" "SSL server cachetimeout.......: ~p~n" "SSL client certfile...........: ~p~n" "SSL client verification type..: ~p~n" "SSL client verification depth.: ~p~n" "SSL client cacertfile.........: ~p~n" "SSL client keyfile............: ~p~n" "SSL client password...........: ~p~n" "SSL client ciphers............: ~p~n" "SSL client cachetimeout.......: ~p~n" "=========================================~n", [iiop_ssl_port(), % iiop_ssl_in_keepalive(), iiop_ssl_out_keepalive(), nat_iiop_ssl_port(), iiop_ssl_accept_timeout(), iiop_ssl_backlog(), iiop_ssl_ip_address_local(), ssl_server_certfile(), ssl_server_verify(), ssl_server_depth(), ssl_server_cacertfile(), ssl_server_keyfile(), ssl_server_password(), ssl_server_ciphers(), ssl_server_cachetimeout(), ssl_client_certfile(), ssl_client_verify(), ssl_client_depth(), ssl_client_cacertfile(), ssl_client_keyfile(), ssl_client_password(), ssl_client_ciphers(), ssl_client_cachetimeout()])]).%%-----------------------------------------------------------------%% function : iiop_acl%% Arguments: %% Returns : %% Exception: %% Effect : %%-----------------------------------------------------------------iiop_acl() -> case application:get_env(orber, iiop_acl) of {ok, ACL} when list(ACL) -> ACL; _ -> [] end.iiop_packet_size() -> case application:get_env(orber, iiop_packet_size) of {ok, Max} when integer(Max), Max > 0 -> Max; _ -> infinity end. iiop_port() -> case application:get_env(orber, iiop_port) of {ok, Port} when integer(Port), Port >= 0 -> Port; _ -> 4001 end.nat_iiop_port() -> case application:get_env(orber, nat_iiop_port) of {ok, Port} when integer(Port), Port > 0 ->
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?