extending ejabberd

Greetings everybody! I have recently discovered ejabberd and erlang (thanks to ejabberd!). I want to extend ejabberd by providing my own services but I do not know where to begin. While I am not good at erlang (yet), I have chosen to create my services/modules in Java.

I have been searching online and cannot find a good place to start with this. Can anybody recommend the correct RFC that addresses this need, and can anybody share any resources that will point me in the right direction?

Sample Java code would perhaps be the most helpful.

Thanks in advance!

Keep in mind that I am not a

Keep in mind that I am not a real coder at all, so watch out for the suggested URLs! ;-)

--
sander

excellent resources

These are excellent links. Thank you very much. I do intend on learning Erlang because I think it is a GREAT tool for certain problems (especially problems that require concurrency). Your first link is extremely helpful. Thanks again!

What kind of services?

I want to extend ejabberd by providing my own services but I do not know where to begin.

What does 'services' mean to you? Services like these: Jabber components? Could you tell examples of services that you are interested in?

hhmmm...

I would like to create some custom behaviors to ejabberd. In particular, I would like to customize the multiuser chat components, or perhaps write my own; if there is a multiuser chat module available in Java that works with ejabberd then please let me know. I think I should start with reading JEP-0045 (is that the correct JEP?).

In the most general sense, I would like to extend ejabberd's functionality the same way one would extend a servlet container such as jetty or tomcat.

Thank you very much for your response!

Random suggestions

You can write "components" using the protocol in JEP-0114. Such components can be attached as subdomains of your ejabberd server. I don't use Java myself, but the JSO library is said to be useful for writing components.

Alternatively, you can run a Jive Messenger server on a separate machine, and try to customize their MUC module.

Of course, in the long run you'll be happier learning Erlang ;-)

not an option

Jive Messenger is out of the question (for a number of reasons). I will look into JEP-0114 and JSO. Thank you!

three free implementations of Multi-User Chat

I would like to customize the multiuser chat components, or perhaps write my own; if there is a multiuser chat module available in Java that works with ejabberd then please let me know.

There are at least three free implementations of Multi-User Chat (JEP-0045):

  • MU-Conference: stand-alone component that can be used with any Jabber server, including ejabberd.
  • MUC module embedded in ejabberd.
  • MUC module embedded in Jive Messenger 2.

first steps

I am in the process of learning Erlang. Could you please give me some starting points to start hacking at the embedded MUC module?

I am guessing the following approach might work.

1) copy the MUC module and rename it somehow
2) register the new module under the new name
3) incrementally modify it to suit my purposes

I would think that understanding how the MUC module works would also be a good starting point. I know nothing of the ejabberd architecture, so please let me know if I am barking up the wrong tree. I am making a number of assumptions here (most notably that the MUC module exists in an editable file).

Is there a module template that is lying around somewhere that I can start with? I will go over the documentation some more and look over my installation of ejabberd to better understand the architecture.

hacking mod_muc

I've checked out the code via SVN and feel this is a good place to start extending ejabberd. I will most defenitely start playing with mod_muc. I hope to get up to stud level in erlang programming and then hopefully be able to contribute better to ejabberd.

How to add a new module to ejabberd

How to add a brand new module to ejabberd:
  1. Put mod_echo2.erl on ejabberd/src
  2. Make sure the module is correctly named. On that file, modify this line to reflect the new name of the module:
    -module(mod_echo2).
  3. And make sure to change the name of the proccess, so it does not conflict with the existing one provided by 'mod_echo':
    -define(PROCNAME, ejabberd_mod_echotwo).
  4. Compile ejabberd. It will automatically compile the new file:
    ...
    Recompile: mod_echo2
    ...
  5. Configure ejabberd to start this module at startup. Edit ejabberd.cfg and add on 'modules' section:
    	{mod_echo2,      [{host, "echotest.localhost"}]},
  6. Now start ejabberd. If everything went ok, no mention to mod_echo2 will be shown on the error log. Log in with any account on the server and open the 'Service Discovery' on your Jabber client. You will see the new echotest.localhost, provided by the new module.

recompiling

Do I have to recompile the entire mod_echo2? I simply moved ejabberd.hrl, jlib.hrl, and mod_echo2.erl to another directory and then in erl I compiled with c( mod_echo2 ).

I got the following error:

./mod_echo2.erl:13: Warning: undefined call-back function start/1
./mod_echo2.erl:13: Warning: undefined call-back function stop/0
{ok,mod_echo2}

A beam file has been outputted as well. I moved the beam file to the mod directory and changed the cfg file to reflect the presence of the new mod. I then restarted the server and it seems to be up and running fine. Is this method acceptable as well or is the recompile necessary?

why didn't you follow the instructions?

I simply moved ejabberd.hrl, jlib.hrl, and mod_echo2.erl to another directory

I said 'Put mod_echo2.erl on ejabberd/src'. You did something completely different.

then in erl I compiled with c( mod_echo2 )

I said 'Compile ejabberd'. You did something completely different.

If you don't follow my instructions, don't ask me your problems, because I won't know. Weren't the instructions specific enought?

PD: I fixed some mistakes in the instructions and added more explanations.

miscommunication...

I'm sorry, I didn't mean to question what you were saying; the instructions you gave were very clear and concise. I was only trying to figure out if I could avoid a complete recompile of the entire server and save some time. I thought it would be easier to simply compile the parts of the server that were modified (i.e. the individual modules themselves), instead of the whole server. From now on, I will do exactly as you recommended. Thank you very much for taking the time to answer my questions; I really appreciate it!

avoid a complete recompile

avoid a complete recompile of the entire server and save some time

'make' only compiles new or modified source code files, so my proposed method is optimal.

log error

I have followed your directions exactly as specified and I get the following log error:

=ERROR REPORT==== 28-Sep-2005::12:33:31 ===
E(<0.918.0>:gen_mod:43): {undef,[{mod_echo2,
start,
[[{host,"echotest.localhost"}]]},
{gen_mod,start_module,2},
{lists,foreach,2},
{ejabberd_app,start,2},
{application_master,start_it_old,4}]}

Any ideas? [Thanks in advance!]

it's easier to modify current code

You can copy the current mod_muc, rename the files, rename the module, rename the Mnesia and ETS tables and the proccess, so all this does not conflict with the stock mod_muc. But why don't you just modify the code of the current mod_muc?

The module that implements MUC is called mod_muc, and the files that implement the required functionality are spread on several files on the mod_muc/ directory.

Just simply modify those files, recompile and restart ejabberd. It's the same for any other code.

The simpliest modules you can find are mod_echo, mod_time and mod_version.

Syndicate content