Specifications
CHAPTER 5. IMPLEMENTATION 42
Configuration File Parser
The Input Abstraction Layer’s daemon configuration is stored in /etc/ial/iald.conf. It is
formatted as an XML document. The document root has to be <ialdconfig>. Beneath of
this document root, all configuration options for b oth the daemon and the modules are stored.
Each child node of the document root is a configuration option. The configuration file parser
conf parse file() evaluates all children nodes using functions of the library libxml2.
The configuration options can be divided into two categories: daemon options and module
options. The daemon’s configuration options are known at compile time. Thus, the parser
is able to evaluate them by comparing the configuration file’s options with expected options.
Since the modules are detected and loaded at run time, their configuration options are not
known at compile time. Once the parser has read a configuration option for a module, it has
to iterate through the double linked list in order to detect the corresponding module.
To keep apart the daemon’s configuration options from the modules’ configuration options
the nodes of the configuration file have to differ. Configuration options for the daemon are
children nodes without attributes. Configuration options for modules are encapsulated by
children nodes with the name module and the additional attribute token. The following
example is based on the already discussed demonstration module (§5.3). It shows one daemon
option daemon option and two module options (disable and verbose) for the module with
the token module example:
<ialdconfig>
<!-- Daemon option -->
<daemon_option>value</daemon_option>
<!-- Module options -->
<module token="example_module">
<disable>false</disable>
<verbose>true</verbose>
</module>
</ialdconfig>
The parser compares the daemon’s static configuration options with the expected config-
uration options. If a valid configuration option is found, the parser is responsible for taking
the corresponding action—e.g. set the value of a variable to the obtained value. The dy-
namic configuration options for modules are handled by the function conf parse module().
This function is invoked by conf parse file() if a child node with the name module and the
attribute token is found. The function conf parse module() iterates the double linked list
which contains all available modules, and looks up the token token of each module. Once
token matches with token read from the configuration file, conf parse module() iterates
through the module’s options and compares the options’ names with all children nodes’ name.
If a match is found, conf parse module() allocates memory and stores the value for the
corresponding option. It is each module’s responsibility to check whether the values of the
configuration options set by the daemon’s configuration file parser are reasonable.
The nested, rather complex implementation of the function conf parse module() is illus-
trated using C pseudocode. The pseudocode shows the various iterations and the performed
comparison operations: