[ejabberd] config file options in ejabberd module

Badlop badlop at gmail.com
Mon Sep 21 13:47:46 MSD 2009


2009/9/17 Stephan Maihöfer <sma at turtle-entertainment.de>:
> i have a question regarding the accessing of module options
> that are set in ejabberd config-file. i have serveral hosts
> configured on my server, like this:
>
> {hosts, ["server1.example.com",
>         "server2.example.com"]}.
>
> and then i have the muc_module configured for each host.

I guess you mean mod_muc.


> now I have made some adjustements to mod_muc_log that would
> require defferent behaviour depending on what muc-service
> it is running at.

The options can be obtained, but it's required to know the vhost.
If it isn't provided as argument to your function, then try to modify
the calling functions to pass that information as argument.


> for this, i want to access some kind of config
> file variable of the module, per host. say "room_type".

I guess you refer to dirtype.


> i do not quite see how this is possible. there seems to be
> the "Opts" variable that gets all the options on module_init,
> some other functions also get "Opts" but add_message_to_log
> for example get's the room options.

Let's see an example.

Let's configure:

{hosts, ["localhost", "example.com"]}.
{modules, [
  ...
  {mod_muc, [{access, muc}]},
  ...
 ]}.
{host_config, "localhost",
 [{{add, modules},
   [
    {mod_muc_log, [{dirtype, plain}]}
   ]
  }
 ]}.
{host_config, "example.com",
 [{{add, modules},
   [
    {mod_muc_log, [{dirtype, subdirs}]}
   ]
  }
 ]}.


Let's apply this patch:
--- a/src/mod_muc/mod_muc_log.erl
+++ b/src/mod_muc/mod_muc_log.erl
@@ -318,6 +318,11 @@ add_message_to_log(Nick1, Message, RoomJID, Opts, State) ->
           timezone = Timezone,
           spam_prevention = NoFollow,
           top_link = TopLink} = State,
+    ?INFO_MSG("I am mod_muc_log of vhost ~s, and I'll log a message
now.", [State#logstate.host]),
+    DirTypeExp = gen_mod:get_module_opt(State#logstate.host, ?MODULE,
dirtype, default_dirtype),
+    ?INFO_MSG("mod_muc_log option dirtype: ~p", [DirTypeExp]),
+    AccessExp = gen_mod:get_module_opt(State#logstate.host, mod_muc,
access, default_access),
+    ?INFO_MSG("mod_muc option access: ~p", [AccessExp]),
     Room = get_room_info(RoomJID, Opts),
     Nick = htmlize(Nick1, FileFormat),
     Nick2 = htmlize("<"++Nick1++">", FileFormat),


When the occupant of a room with logging enabled says anything, you
will see in the logs:

=INFO REPORT==== 21-Sep-2009::11:35:23 ===
I(<0.311.0>:mod_muc_log:321) : I am mod_muc_log of vhost localhost,
and I'll log a message now.

=INFO REPORT==== 21-Sep-2009::11:35:23 ===
I(<0.311.0>:mod_muc_log:323) : mod_muc_log option dirtype: plain

=INFO REPORT==== 21-Sep-2009::11:35:23 ===
I(<0.311.0>:mod_muc_log:325) : mod_muc option access: muc


---
Badlop
ProcessOne


More information about the ejabberd mailing list