-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace ejabberd_config with mongoose_config
- Loading branch information
Showing
45 changed files
with
256 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
-module(mongoose_config). | ||
|
||
-export([start/0, | ||
get_config_path/0, | ||
set_opt/2, | ||
lookup_opt/1, | ||
get_opt/1, | ||
get_opt/2]). | ||
|
||
-include("mongoose.hrl"). | ||
-include("ejabberd_config.hrl"). | ||
|
||
-type key() :: atom() | host_type_key() | host_type_or_global_key(). | ||
-type s2s_domain_key() :: {atom(), jid:lserver()}. | ||
-type host_type_key() :: {atom() | s2s_domain_key(), mongooseim:host_type()}. | ||
-type host_type_or_global_key() :: {shaper | access | acl, atom(), mongooseim:host_type() | global}. | ||
|
||
-type value() :: atom() | ||
| binary() | ||
| integer() | ||
| string() | ||
| [value()] | ||
| tuple(). | ||
|
||
-export_type([key/0, value/0]). | ||
|
||
-spec start() -> ok. | ||
start() -> | ||
Path = get_config_path(), | ||
State = mongoose_config_parser:parse_file(Path), | ||
set_opts(State). | ||
|
||
%% @doc Get the filename of the ejabberd configuration file. | ||
%% The filename can be specified with: erl -config "/path/to/mongooseim.toml". | ||
%% It can also be specified with the environment variable EJABBERD_CONFIG_PATH. | ||
%% If not specified, the default value 'mongooseim.toml' is assumed. | ||
-spec get_config_path() -> string(). | ||
get_config_path() -> | ||
DefaultPath = case os:getenv("MONGOOSE_CONFIG_PATH") of | ||
false -> ?CONFIG_PATH; | ||
Path -> Path | ||
end, | ||
application:get_env(mongooseim, config, DefaultPath). | ||
|
||
-spec set_opts(mongoose_config_parser:state()) -> ok. | ||
set_opts(State) -> | ||
Opts = mongoose_config_parser:state_to_opts(State), | ||
[set_opt(Key, Value) || #local_config{key = Key, value = Value} <- Opts], | ||
ok. | ||
|
||
-spec set_opt(key(), value()) -> ok. | ||
set_opt(Key, Value) -> | ||
persistent_term:put({?MODULE, Key}, Value). | ||
|
||
%% @doc Use instead of get_opt(Key, undefined) | ||
-spec lookup_opt(key()) -> | ||
{ok, value()} | {error, not_found}. | ||
lookup_opt(Key) -> | ||
try persistent_term:get({?MODULE, Key}) of | ||
Value -> {ok, Value} | ||
catch | ||
error:_ -> {error, not_found} | ||
end. | ||
|
||
%% @doc Fails if the option does not exist | ||
-spec get_opt(key()) -> value(). | ||
get_opt(Key) -> | ||
persistent_term:get({?MODULE, Key}). | ||
|
||
-spec get_opt(key(), value()) -> value(). | ||
get_opt(Key, Default) -> | ||
persistent_term:get({?MODULE, Key}, Default). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.