Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
update 17 february: keyword feature greately improved, and now macros can be used inside strings.
Macros are replaced in the yconf library, this is very powerful at the YAML level... but unfortunately macros cannot be defined inside host_config.
This PR adds a new option, define_keyword, complementary to define_macro. As define_keyword internal code is implemented in ejabberd, define_keyword can be set in host_config.
In ejabberd there were already a few keywords hard-coded in specific options, for example some module hosts can use the keyword @host@. This PR allows all the options to use this and other keywords, no need to add code for each option.
Tests are also added for all those features.
Release Notes
Keywords predefined for all options
Some options in ejabberd supported the possibility to use hard-coded keywords. For example, many modules like mod_vcard could used
HOST
in their optionhosts
. Also, thecaptcha_cmd
toplevel option could useVERSION
andSEMVER
keywords. This was implemented for each individual option.Now those keywords are predefined and can be used by any option, and this is implemented in ejabberd core, no need to implement the keyword substitution in each option.
The predefined keywords are:
HOST
,HOME
,VERSION
andSEMVER
.For example, this configuration is possible without requiring any implementation in the option source code:
New define_keyword option
Now you can define your own keywords, similarly to how macros are defined:
Macros can be used inside string
Macros can be used inside string options, similarly to how keywords can be used.
This is now possible:
Documentation
This is the documentation that could be included in the Docs site. Notice that the markdown and links in this github issue may not be perfect, as it's designed for the docs site.
Macros and Keywords
In the ejabberd configuration file, you can define a macro or keyword for a value (atom, integer, string...) and later use it when configuring an ejabberd option.
Macros is a feature implemented internally by the yconf library and are replaced early and transparently to ejabberd. However, macros cannot be defined inside
host_config
.Keywords is a feature similar to macros, implemented by ejabberd itself, and are replaced after macro replacement. Keywords can be defined inside
host_config
for module options, but not for toplevel options. Keywords cannot be used in those toplevel options: hosts, loglevel, version.First define_macro and define_keyword and then use them like this:
where:
NAME: should be specified in capital letters for convenience. Duplicated macro/keyword names are not allowed. If a macro is defined with the same name than a keyword, the macro is used.
value: for all options, the value can be any valid YAML element. It is also possible to use as value the name of another macro.
use a macro/keyword when configuring the option: simply set
NAME
instead of option value. Macros are processed after additional configuration files have been included, so it is possible to use macros that are defined in configuration files included before the usage.use inside a string: surround its name with
@
charactersLet's see examples of all this in detail:
Atom
The resulting configuration is:
Integer
The resulting configuration is:
Map
Option values can be any arbitrary YAML value:
The resulting configuration is:
String
The resulting configuration is:
Inside string
A macro or keyword can be used inside an option string:
is equivalent to:
is equivalent to:
The resulting configuration in all the cases is:
Macro over keyword
If a macro and a keyword are defined with the same name, the macro definition takes precedence and the keyword definition is ignored:
The resulting configuration is:
Keyword inside macro
A macro definition can use a keyword:
The resulting configuration is:
Predefined keywords
Several keywords are predefined automatically by ejabberd, so you can use them without need to define them explicitly:
"example.org"
. That keyword is only predefined for module options, not toplevel options."/home/ejabberd"
XX.YY
format, for example"24.05"
"24.5"
), otherwise it's inXX.YY
format ("24.05"
)It is possible to overwrite predefined keywords, global or for a vhost like in this example:
The resulting behaviour is equivalent to a configuration like:
Macro and host_config
Macros can be used inside host_config:
The resulting configuration is:
!!! warning "Don't use macro defined in host_config"
Keyword and host_config
Keywords can be used and defined inside host_config:
The resulting configuration is:
!!! warning "Don't use in toplevel a keyword defined in host_config"