factlooki.blogg.se

Ejabberd source
Ejabberd source








  1. #EJABBERD SOURCE HOW TO#
  2. #EJABBERD SOURCE CODE#

ejabberd (brightly) splitted this task into two subtasks: one is to handle all the data transmition(sending and receiving, encapsulating the low-level socket implementation), the other is to parse and handle the message corresponding to the data. When a new socket is accepted, ejabberd_socket:start/4 is invoked to handle the socket events. Init () -> Listener = -> ReceiverMod : close ( Receiver ) end In ejabberd_sup:start_link/0, ejabberd_listener:start_link/0 is invoked: %% ejabberd_sup.erl Start ( normal, _ Args ) -> Sup = ejabberd_sup : start_link (), ejabberd_listener : start_listeners (). Let’s start with the application module: %% file: ejabberd_app.erl

ejabberd source

The logic module parses and handles the packets, and sends responses and requests using the ejabberd_socket utils. The ejabberd_receiver is responsible for receiving any incoming packets and then forwarding them to the logic module. When it finishes, it starts ejabberd_socket which in turn starts two processes: ejabberd_receiver and logic module according to the config (ejabberd_c2s for 5222, for example). The ejabberd_listener listens on every port specified in the ejabberd configuration file, spawns a process for each port and then accepts the sockets. The modules related to ejabberd’s socket infrastructure are: ejabberd_listener, ejabberd_socket and ejabberd_receiver.

ejabberd source

In ejabberd, the whole server is packaged into a single OTP application.

#EJABBERD SOURCE CODE#

Notice: for the sake of clearity, I intentionally omitted a lot of code which are either unrelated to the topic discussed or only used for error handling. That said, let’s examine the listener/socket code of ejabberd first, throwing aside other features along the way. The essential task of the server, then, is to listen on a specific port, wait for clients or other servers to connect to it, and then exchange information using specific data formats(in the XMPP’s situation, XML stanzas).

  • Alice uses the XMPP client to exchange messages/presences/iqs with the server, completing tasks such as instant messaging and presence notifying.
  • The server authenticates the client by exchanging XML stanzas.
  • ejabberd source

    Alice started an XMPP client on her computer, which establishes a TCP connection to :5222.What is the key idea of this XMPP(Jabber) server, then? Let’s review some of the key usages of a typical XMPP session: Like reading a book, we need to get the key idea first. Ejabberd is a big project (with 80k+lines of erlang code), so it’s impossible for us to understand it all at once. The first step to source hacking is code reading. The source code version in discussion is ejabberd 2.1.10 release, which is the latest stable version at this time.

    #EJABBERD SOURCE HOW TO#

    In these series of blogs, I want to take notes about how the ejabberd works, and how to hack it to get customized features. Welcome to my first blog about ejabberd source code hacking.










    Ejabberd source