1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
-module(ephraim_roster_handler).
-include_lib("exmpp/include/exmpp_client.hrl").
-behaviour(gen_event).
-export([start/2, stop/1]).
-export([init/1, handle_event/2, handle_call/2, handle_info/2, terminate/2, code_change/3]).
start(EventManager, Roster) ->
gen_event:add_handler(EventManager, ?MODULE, Roster).
stop(EventManager) ->
gen_event:delete_handler(EventManager, ?MODULE, []).
init(Roster) ->
{ok, Roster}.
handle_event({received_packet, #received_packet{packet_type=presence, raw_packet=Packet}}, Roster) ->
%io:format("Received packet ~p~n", [Packet]),
ephraim_roster:presence(Roster, Packet),
{ok, Roster};
handle_event({received_packet, #received_packet{packet_type=iq, raw_packet=Packet}}, Roster) ->
%io:format("Received packet ~p~n", [Packet]),
From = exmpp_stanza:get_sender(Packet),
IQ = exmpp_iq:xmlel_to_iq(Packet),
case IQ of
{iq, response, result, _, 'jabber:iq:roster', Payload, _, _, 'jabber:client'} ->
ephraim_roster:roster_iq(Roster, Payload);
{iq, response, result, _, 'vcard-temp', Payload, _, _, 'jabber:client'} ->
ephraim_roster:vcard_iq(Roster, From, Payload);
_ ->
ok %io:format("ephraim: IQ from ~p: ~p~n", [From, IQ])
end,
{ok, Roster};
handle_event(_Event, Roster) ->
{ok, Roster}.
handle_call(_Msg, Roster) ->
{noreply, Roster}.
handle_info(_Msg, Roster) ->
{ok, Roster}.
terminate(_Reason, _Roster) ->
ok.
code_change(_OldVersion, Roster, _Extra) ->
{ok, Roster}.
|