Note: When I started writing this, I was using customized mongooseim version 3.7.1, now latest updates using TOML config and such have come up as on July 2021. So, if you want to refer to the latest documentation, feel free to read it here .
Important files and hierarchies
Last part, we saw how a stanza is represented in Erlang Terms (erlang records). This part we’ll be seeing the important files and how they fit into the functioning of MongooseIM.
# Some of the directories and files have been left out for convenience
As a developer, we’ll only need to modify certain folders or files in order to achieve a certain functionality such as
big_tests→ Contains a very big test suite for most of the MongooseIM functionalities, the big tests often times run nearly an hour and sometimes even more. They contain integrated test suites which tests a range of scenarios, grouped into various hierarchies. MongooseIM team, has been generous enough to include scripts that can trigger the integrated suites for a particular scenario on a particular module, which have been very well documented here
include→ Contains Erlang Header files, which define the commonly used erlang records and such
priv→ Contains the database schema files for different supported databases and internationalization files
rel→ Contains templates for variations of mongooseim configurations with support for federation, registration and such. Template files are changed when you want to configure mongooseim for a specific release with this configuration.
src→ Contains source code for the mongooseim modules and this is where you’ll be working mostly
test→ Contains smaller unit tests for the mongooseim modules
Erlang developers already know about
io:format(arg1, arg2) method to display or inspect values in the erlang shell and also we will be tempted to use the same here. There is no harm in doing it, but we will be bypassing the log from the mongooseim’s configured logger module, which might result in our debug statements left out from the corresponding log files.
The header file contains macros to make your life easier in including debug statements. You want to add a debug log in a source file, include this header file somewhere along after module statement in the source file as
Now you can simply add a debug statement, which will be shown in the mongooseim console output when the application is running. Simple example of a debug statement is as follows:
# without variables
?DEBUG("Hello this is a sample debug message!~n", ),
# Console Output
16:25:02.374 [debug] Hello this is a sample debug message!
# with variables
Author = "Jonas",
?DEBUG("Hello this is a sample debug message! Welcome ~p~n", [Author]),
# Console Output
16:25:02.374 [debug] Hello this is a sample debug message! Welcome Jonas
You don’t have to explicitly import this header file, instead if you include the
include/mongoose.hrl file, it already has included the mongoose_logger.hrl file.
ns stands for namespace which is relevant to the XML stanzas. This file holds all of supported namespaces for our XML stanzas and we can also define our custom namespaces here and use them anywhere in the source files. Any source file in mongooseim you see, they would have this file inclusion.
With this covered, let’s get on with understanding hooks and handlers in the coming parts.