Ejabberd Source Flow Carding

Source: Internet
Author: User

Ejabberd's project is organized mainly through Ejabberd.app.

Ejabberd.erl:

Application:start (Ejabberd).

Ejabberd_app.erl:

Mod:start (normal, _args); Start Ejabberd_listener:start_listeners () in this function

Ejabberd_listener.erl

Get <!---->ejabberd_c2s through Conf,

Start Listen

If there is a connection, after Accpet

<!---->ejabberd_socket:start (Module, gen_tcp, socket, Opts)

Receiver=ejabberd_receiver:start (

Socket,sockmod,none,maxstanzasize),

Ejabberd_receiver.erl

Ejabberd_receiver is a gen_server process (behaviour),

Receiver received data (Handle_info) sent to Xml_stream.

Xml_stream parses the data and sends it to the C2S state machine.

Ejabber_c2s.erl

is a GEN_FSM (finite state machine) that maintains a series of state between the client and the server. The state change of the GEN_FSM is triggered by Gen_fsm:send_event (fsmref,event). In Ejabberd, Ejabberd_receiver sends events and XML to ejabber_c2s through Xml_stream to change its state.
The initial state of the Ejabber_c2s finite state machine is wait_for_stream, and the remaining states are:
Wait_for_auth,wait_for_feature_request,wait_for_sasl_response,wait_for_bind,wait_for_session,session_ Established

The hooks in Ejabberd's official documentation about the events that XMPP receives are implemented in C2s.

Call Ejabberd_hooks:run_fold () in C2s to run the corresponding hook.

1.Presence Message Flow

During the user login process:

Called in the waitforsession of C2s

{Fs, Ts} = Ejabberd_hooks:run_fold (

Roster_get_subscription_lists,

Statedata#state.server,

{[], []},

[U, Statedata#state.server]),

Get the From and to friends list, and place them in state separately. Pres_f and state. The pres_t.

After the client login is successful, send to the server

<presence id= "b0djg-12" >

<status> Online </status>

<priority>1</priority>

</presence>

The presence has no destination address (to).

the server receives the message in C2s's Session_established2 ,

Call Presence_update (Fromjid, Presenceel,statedata)

Èpresence_broadcast_first (from, Newstatedata, Packet);

(1) Send probe to each member of state.pres_t;

(2) Send presence to each member of State.pres_f

2. Add Buddy Process

Take Lihengz add admin friend as an example

The first item in the following status values is "subscription (subscription)", and the second item is "Pending (ask)"

The Lihengz state changes are: Out_state_change (None,none, subscribe), {none, out};

The state of the admin changes to: In_state_change (None,none, subscribe), {none, in};

After the admin accepts the request, the state changes: Out_state_change (None,in, subscribed), {from, none};

Lihengz Status change: In_state_change (None,out, subscribed), {to, none};

If admin also adds Lihengz as a friend:

Admin status change: Out_state_change (From,none, subscribe), {from, out};

Lihengz Status change: In_state_change (To, none, subscribe)---{to, in};

Lihengz Accept request, state changes: Out_state_change (to, in, subscribed), {both, none};

Admin status change: In_state_change (From,out, subscribed), {both, none};

3. Add contacts on the server

Add Mine1 as a friend on the server for mine (mine1 not set to add friends automatically)

The mine client receives the following message:

<iq id= "push3140513066" to= "[email protected]/spark 2.6.3" from= "[email protected]" type= "Set" >

<query xmlns= "Jabber:iq:roster" >

<item jid= "[email protected]" subscription= "none" ask= "subscribe"/>

</query>

</iq>

If Mine1 rejects the request, the mine client will not receive a follow-up message. The suspend state is maintained in the Roster table.

If Mine1 is set to add friends automatically, the mine client receives:

<iq id= "push3548743800" to= "[email protected]/spark 2.6.3" from= "[email protected]" type= "Set" >

<query xmlns= "Jabber:iq:roster" >

<item jid= "[email protected]" subscription= "both"/>

</query>

</iq>

From:http://www.cnblogs.com/unqiang/p/4402418.html

Ejabberd Source Flow Carding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.