2003-01-07 20:10:35 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_service.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2008-09-16 16:39:57 +02:00
|
|
|
%%% Purpose : External component management (XEP-0114)
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 6 Dec 2002 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2009-01-19 15:47:33 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2009 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-19 15:47:33 +01:00
|
|
|
%%%
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2003-01-07 20:10:35 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ejabberd_service).
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-01-07 20:10:35 +01:00
|
|
|
|
|
|
|
-behaviour(gen_fsm).
|
|
|
|
|
|
|
|
%% External exports
|
2006-01-13 02:55:20 +01:00
|
|
|
-export([start/2,
|
|
|
|
start_link/2,
|
|
|
|
send_text/2,
|
2006-09-25 05:51:11 +02:00
|
|
|
send_element/2,
|
|
|
|
socket_type/0]).
|
2003-01-07 20:10:35 +01:00
|
|
|
|
|
|
|
%% gen_fsm callbacks
|
|
|
|
-export([init/1,
|
|
|
|
wait_for_stream/2,
|
|
|
|
wait_for_handshake/2,
|
|
|
|
stream_established/2,
|
|
|
|
handle_event/3,
|
|
|
|
handle_sync_event/4,
|
|
|
|
code_change/4,
|
|
|
|
handle_info/3,
|
|
|
|
terminate/3]).
|
|
|
|
|
2008-07-11 14:41:48 +02:00
|
|
|
-include_lib("exmpp/include/exmpp.hrl").
|
|
|
|
|
2003-01-07 20:10:35 +01:00
|
|
|
-include("ejabberd.hrl").
|
|
|
|
|
2006-10-01 03:53:37 +02:00
|
|
|
-record(state, {socket, sockmod, streamid,
|
2007-06-28 16:32:48 +02:00
|
|
|
hosts, password, access,
|
|
|
|
check_from}).
|
2003-01-07 20:10:35 +01:00
|
|
|
|
2007-06-29 19:27:42 +02:00
|
|
|
%-define(DBGFSM, true).
|
2003-01-07 20:10:35 +01:00
|
|
|
|
|
|
|
-ifdef(DBGFSM).
|
|
|
|
-define(FSMOPTS, [{debug, [trace]}]).
|
|
|
|
-else.
|
|
|
|
-define(FSMOPTS, []).
|
|
|
|
-endif.
|
|
|
|
|
2008-07-11 14:41:48 +02:00
|
|
|
% These are the namespace already declared by the stream opening. This is
|
|
|
|
% used at serialization time.
|
|
|
|
-define(DEFAULT_NS, ?NS_COMPONENT_ACCEPT).
|
|
|
|
-define(PREFIXED_NS, [{?NS_XMPP, ?NS_XMPP_pfx}]).
|
2003-05-29 21:07:41 +02:00
|
|
|
|
2003-01-07 20:10:35 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% API
|
|
|
|
%%%----------------------------------------------------------------------
|
2003-07-20 22:35:35 +02:00
|
|
|
start(SockData, Opts) ->
|
|
|
|
supervisor:start_child(ejabberd_service_sup, [SockData, Opts]).
|
|
|
|
|
2003-07-14 20:06:03 +02:00
|
|
|
start_link(SockData, Opts) ->
|
|
|
|
gen_fsm:start_link(ejabberd_service, [SockData, Opts], ?FSMOPTS).
|
2003-01-07 20:10:35 +01:00
|
|
|
|
2006-09-25 05:51:11 +02:00
|
|
|
socket_type() ->
|
|
|
|
xml_stream.
|
|
|
|
|
2003-01-07 20:10:35 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Callback functions from gen_fsm
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: init/1
|
|
|
|
%% Returns: {ok, StateName, StateData} |
|
|
|
|
%% {ok, StateName, StateData, Timeout} |
|
|
|
|
%% ignore |
|
2007-03-13 16:01:27 +01:00
|
|
|
%% {stop, StopReason}
|
2003-01-07 20:10:35 +01:00
|
|
|
%%----------------------------------------------------------------------
|
2006-10-01 03:53:37 +02:00
|
|
|
init([{SockMod, Socket}, Opts]) ->
|
2007-03-13 17:01:39 +01:00
|
|
|
?INFO_MSG("(~w) External service connected", [Socket]),
|
2004-01-11 21:42:57 +01:00
|
|
|
Access = case lists:keysearch(access, 1, Opts) of
|
|
|
|
{value, {_, A}} -> A;
|
|
|
|
_ -> all
|
|
|
|
end,
|
2003-10-18 21:15:12 +02:00
|
|
|
{Hosts, Password} =
|
|
|
|
case lists:keysearch(hosts, 1, Opts) of
|
|
|
|
{value, {_, Hs, HOpts}} ->
|
2003-02-01 21:21:28 +01:00
|
|
|
case lists:keysearch(password, 1, HOpts) of
|
|
|
|
{value, {_, P}} ->
|
2003-10-18 21:15:12 +02:00
|
|
|
{Hs, P};
|
2003-02-01 21:21:28 +01:00
|
|
|
_ ->
|
|
|
|
% TODO: generate error
|
|
|
|
false
|
|
|
|
end;
|
|
|
|
_ ->
|
2003-10-18 21:15:12 +02:00
|
|
|
case lists:keysearch(host, 1, Opts) of
|
|
|
|
{value, {_, H, HOpts}} ->
|
|
|
|
case lists:keysearch(password, 1, HOpts) of
|
|
|
|
{value, {_, P}} ->
|
|
|
|
{[H], P};
|
|
|
|
_ ->
|
|
|
|
% TODO: generate error
|
|
|
|
false
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
% TODO: generate error
|
|
|
|
false
|
|
|
|
end
|
2003-02-01 21:21:28 +01:00
|
|
|
end,
|
2007-03-13 17:01:39 +01:00
|
|
|
Shaper = case lists:keysearch(shaper_rule, 1, Opts) of
|
|
|
|
{value, {_, S}} -> S;
|
|
|
|
_ -> none
|
|
|
|
end,
|
2007-06-28 16:32:48 +02:00
|
|
|
CheckFrom = case lists:keysearch(service_check_from, 1, Opts) of
|
|
|
|
{value, {_, CF}} -> CF;
|
|
|
|
_ -> true
|
|
|
|
end,
|
2007-03-13 17:01:39 +01:00
|
|
|
SockMod:change_shaper(Socket, Shaper),
|
2003-01-07 20:10:35 +01:00
|
|
|
{ok, wait_for_stream, #state{socket = Socket,
|
2006-10-01 03:53:37 +02:00
|
|
|
sockmod = SockMod,
|
2003-01-07 20:10:35 +01:00
|
|
|
streamid = new_id(),
|
2003-10-18 21:15:12 +02:00
|
|
|
hosts = Hosts,
|
2004-01-11 21:42:57 +01:00
|
|
|
password = Password,
|
2007-06-28 16:32:48 +02:00
|
|
|
access = Access,
|
|
|
|
check_from = CheckFrom
|
2003-01-07 20:10:35 +01:00
|
|
|
}}.
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: StateName/2
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
2007-03-13 16:01:27 +01:00
|
|
|
%% {stop, Reason, NewStateData}
|
2003-01-07 20:10:35 +01:00
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
|
2008-09-16 16:39:57 +02:00
|
|
|
wait_for_stream({xmlstreamstart, #xmlel{ns = NS, attrs = Attrs}}, StateData) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
case NS of
|
|
|
|
?NS_COMPONENT_ACCEPT ->
|
2008-09-16 16:39:57 +02:00
|
|
|
%% Note: XEP-0114 requires to check that destination is a Jabber
|
|
|
|
%% component served by this Jabber server.
|
|
|
|
%% However several transports don't respect that,
|
|
|
|
%% so ejabberd doesn't check 'to' attribute (EJAB-717)
|
2009-01-08 15:54:00 +01:00
|
|
|
To = binary_to_list(exmpp_stanza:get_recipient_from_attrs(Attrs)),
|
2008-09-16 16:39:57 +02:00
|
|
|
Opening_Reply = exmpp_stream:opening_reply(xml:crypt(To),
|
2008-07-11 14:41:48 +02:00
|
|
|
?NS_COMPONENT_ACCEPT,
|
|
|
|
{0, 0}, StateData#state.streamid),
|
|
|
|
send_element(StateData, Opening_Reply),
|
2003-01-07 20:10:35 +01:00
|
|
|
{next_state, wait_for_handshake, StateData};
|
|
|
|
_ ->
|
2008-07-11 14:41:48 +02:00
|
|
|
Error = #xmlel{ns = ?NS_XMPP, name = 'stream', children = [
|
|
|
|
#xmlel{ns = ?NS_XMPP, name = 'error', children = [
|
|
|
|
#xmlcdata{cdata = <<"Invalid Stream Header">>}
|
|
|
|
]}
|
|
|
|
]},
|
|
|
|
send_element(StateData, Error),
|
2003-01-07 20:10:35 +01:00
|
|
|
{stop, normal, StateData}
|
|
|
|
end;
|
|
|
|
|
2003-05-29 21:07:41 +02:00
|
|
|
wait_for_stream({xmlstreamerror, _}, StateData) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
Opening_Reply = exmpp_stream:opening_reply(?MYNAME,
|
|
|
|
?NS_COMPONENT_ACCEPT,
|
|
|
|
{0, 0}, "none"),
|
|
|
|
send_element(StateData, Opening_Reply),
|
|
|
|
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2003-05-29 21:07:41 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2003-01-07 20:10:35 +01:00
|
|
|
wait_for_stream(closed, StateData) ->
|
|
|
|
{stop, normal, StateData}.
|
|
|
|
|
|
|
|
|
|
|
|
wait_for_handshake({xmlstreamelement, El}, StateData) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
case {El#xmlel.name, exmpp_xml:get_cdata(El)} of
|
|
|
|
{'handshake', Digest} ->
|
2003-01-07 20:10:35 +01:00
|
|
|
case sha:sha(StateData#state.streamid ++
|
|
|
|
StateData#state.password) of
|
|
|
|
Digest ->
|
2008-07-11 14:41:48 +02:00
|
|
|
send_element(StateData,
|
|
|
|
#xmlel{ns = ?NS_COMPONENT_ACCEPT, name = 'handshake'}),
|
2003-10-18 21:15:12 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(H) ->
|
2007-03-13 16:01:27 +01:00
|
|
|
ejabberd_router:register_route(H),
|
|
|
|
?INFO_MSG("Route registered for service ~p~n", [H])
|
2003-10-18 21:15:12 +02:00
|
|
|
end, StateData#state.hosts),
|
2003-01-07 20:10:35 +01:00
|
|
|
{next_state, stream_established, StateData};
|
|
|
|
_ ->
|
2008-07-11 14:41:48 +02:00
|
|
|
send_element(StateData,
|
|
|
|
#xmlel{ns = ?NS_XMPP, name = 'error', children = [
|
|
|
|
#xmlcdata{cdata = <<"Invalid Handshake">>}]}),
|
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2003-01-07 20:10:35 +01:00
|
|
|
{stop, normal, StateData}
|
|
|
|
end;
|
|
|
|
_ ->
|
2006-01-13 02:55:20 +01:00
|
|
|
{next_state, wait_for_handshake, StateData}
|
2003-01-07 20:10:35 +01:00
|
|
|
end;
|
|
|
|
|
2003-10-18 21:15:12 +02:00
|
|
|
wait_for_handshake({xmlstreamend, _Name}, StateData) ->
|
2003-01-07 20:10:35 +01:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2003-05-29 21:07:41 +02:00
|
|
|
wait_for_handshake({xmlstreamerror, _}, StateData) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2003-05-29 21:07:41 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2003-01-07 20:10:35 +01:00
|
|
|
wait_for_handshake(closed, StateData) ->
|
|
|
|
{stop, normal, StateData}.
|
|
|
|
|
|
|
|
|
|
|
|
stream_established({xmlstreamelement, El}, StateData) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
From = exmpp_stanza:get_sender(El),
|
2007-06-28 16:32:48 +02:00
|
|
|
FromJID = case StateData#state.check_from of
|
|
|
|
%% If the admin does not want to check the from field
|
|
|
|
%% when accept packets from any address.
|
|
|
|
%% In this case, the component can send packet of
|
|
|
|
%% behalf of the server users.
|
2009-01-08 15:54:00 +01:00
|
|
|
false -> exmpp_jid:binary_to_jid(From);
|
2007-06-28 16:32:48 +02:00
|
|
|
%% The default is the standard behaviour in XEP-0114
|
|
|
|
_ ->
|
2009-01-08 15:54:00 +01:00
|
|
|
FromJID1 = exmpp_jid:binary_to_jid(From),
|
2009-01-03 16:15:38 +01:00
|
|
|
Server = exmpp_jid:ldomain_as_list(FromJID1),
|
|
|
|
case lists:member(Server, StateData#state.hosts) of
|
2007-06-28 16:32:48 +02:00
|
|
|
true -> FromJID1;
|
|
|
|
false -> error
|
2009-01-03 16:15:38 +01:00
|
|
|
end
|
2003-01-07 20:10:35 +01:00
|
|
|
end,
|
2008-07-11 14:41:48 +02:00
|
|
|
To = exmpp_stanza:get_recipient(El),
|
2003-01-07 20:10:35 +01:00
|
|
|
ToJID = case To of
|
2008-07-11 14:41:48 +02:00
|
|
|
undefined -> error;
|
2009-01-08 15:54:00 +01:00
|
|
|
_ -> exmpp_jib:binary_to_jid(To)
|
2003-01-07 20:10:35 +01:00
|
|
|
end,
|
2008-07-11 14:41:48 +02:00
|
|
|
if ((El#xmlel.name == 'iq') or
|
|
|
|
(El#xmlel.name == 'message') or
|
|
|
|
(El#xmlel.name == 'presence')) and
|
2003-01-07 20:10:35 +01:00
|
|
|
(ToJID /= error) and (FromJID /= error) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
ejabberd_router:route(FromJID, ToJID, El);
|
2003-01-07 20:10:35 +01:00
|
|
|
true ->
|
2008-07-11 14:41:48 +02:00
|
|
|
Err = exmpp_stanza:reply_with_error(El, 'bad-request'),
|
2003-10-18 21:15:12 +02:00
|
|
|
send_element(StateData, Err),
|
2003-01-07 20:10:35 +01:00
|
|
|
error
|
|
|
|
end,
|
|
|
|
{next_state, stream_established, StateData};
|
|
|
|
|
2003-10-18 21:15:12 +02:00
|
|
|
stream_established({xmlstreamend, _Name}, StateData) ->
|
2003-01-07 20:10:35 +01:00
|
|
|
% TODO
|
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2003-05-29 21:07:41 +02:00
|
|
|
stream_established({xmlstreamerror, _}, StateData) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
send_element(StateData, exmpp_stream:error('xml-not-well-formed')),
|
|
|
|
send_element(StateData, exmpp_stream:closing()),
|
2003-05-29 21:07:41 +02:00
|
|
|
{stop, normal, StateData};
|
|
|
|
|
2003-01-07 20:10:35 +01:00
|
|
|
stream_established(closed, StateData) ->
|
|
|
|
% TODO
|
|
|
|
{stop, normal, StateData}.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: StateName/3
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {stop, Reason, NewStateData} |
|
2007-03-13 16:01:27 +01:00
|
|
|
%% {stop, Reason, Reply, NewStateData}
|
2003-01-07 20:10:35 +01:00
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%state_name(Event, From, StateData) ->
|
|
|
|
% Reply = ok,
|
|
|
|
% {reply, Reply, state_name, StateData}.
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: handle_event/3
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
2007-03-13 16:01:27 +01:00
|
|
|
%% {stop, Reason, NewStateData}
|
2003-01-07 20:10:35 +01:00
|
|
|
%%----------------------------------------------------------------------
|
2003-10-18 21:15:12 +02:00
|
|
|
handle_event(_Event, StateName, StateData) ->
|
2003-01-07 20:10:35 +01:00
|
|
|
{next_state, StateName, StateData}.
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: handle_sync_event/4
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData} |
|
|
|
|
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
|
|
|
|
%% {stop, Reason, NewStateData} |
|
2007-03-13 16:01:27 +01:00
|
|
|
%% {stop, Reason, Reply, NewStateData}
|
2003-01-07 20:10:35 +01:00
|
|
|
%%----------------------------------------------------------------------
|
2003-10-18 21:15:12 +02:00
|
|
|
handle_sync_event(_Event, _From, StateName, StateData) ->
|
2003-01-07 20:10:35 +01:00
|
|
|
Reply = ok,
|
|
|
|
{reply, Reply, StateName, StateData}.
|
|
|
|
|
2003-10-18 21:15:12 +02:00
|
|
|
code_change(_OldVsn, StateName, StateData, _Extra) ->
|
2003-01-07 20:10:35 +01:00
|
|
|
{ok, StateName, StateData}.
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: handle_info/3
|
|
|
|
%% Returns: {next_state, NextStateName, NextStateData} |
|
|
|
|
%% {next_state, NextStateName, NextStateData, Timeout} |
|
2007-03-13 16:01:27 +01:00
|
|
|
%% {stop, Reason, NewStateData}
|
2003-01-07 20:10:35 +01:00
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
handle_info({send_text, Text}, StateName, StateData) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
% XXX OLD FORMAT: This clause should be removed.
|
2003-10-18 21:15:12 +02:00
|
|
|
send_text(StateData, Text),
|
2003-01-07 20:10:35 +01:00
|
|
|
{next_state, StateName, StateData};
|
|
|
|
handle_info({send_element, El}, StateName, StateData) ->
|
2003-10-18 21:15:12 +02:00
|
|
|
send_element(StateData, El),
|
2003-01-07 20:10:35 +01:00
|
|
|
{next_state, StateName, StateData};
|
2008-07-11 14:41:48 +02:00
|
|
|
handle_info({route, FromOld, ToOld, PacketOld}, StateName, StateData) ->
|
|
|
|
%% XXX OLD FORMAT: From, To and Packet are in the old format.
|
|
|
|
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
|
|
|
|
[?NS_JABBER_CLIENT], ?PREFIXED_NS),
|
|
|
|
From = jlib:from_old_jid(FromOld),
|
|
|
|
To = jlib:from_old_jid(ToOld),
|
2005-06-20 05:18:13 +02:00
|
|
|
case acl:match_rule(global, StateData#state.access, From) of
|
2004-01-11 21:42:57 +01:00
|
|
|
allow ->
|
2008-07-11 14:41:48 +02:00
|
|
|
El1 = exmpp_stanza:set_sender(Packet, From),
|
|
|
|
El2 = exmpp_stanza:set_recipient(El1, To),
|
|
|
|
send_element(StateData, El2);
|
2004-01-11 21:42:57 +01:00
|
|
|
deny ->
|
2008-07-11 14:41:48 +02:00
|
|
|
Err = exmpp_stanza:reply_with_error(Packet, 'not-allowed'),
|
2004-01-11 21:42:57 +01:00
|
|
|
ejabberd_router:route(To, From, Err)
|
|
|
|
end,
|
2003-01-07 20:10:35 +01:00
|
|
|
{next_state, StateName, StateData}.
|
|
|
|
|
|
|
|
|
|
|
|
%%----------------------------------------------------------------------
|
|
|
|
%% Func: terminate/3
|
|
|
|
%% Purpose: Shutdown the fsm
|
|
|
|
%% Returns: any
|
|
|
|
%%----------------------------------------------------------------------
|
2005-12-10 19:42:08 +01:00
|
|
|
terminate(Reason, StateName, StateData) ->
|
|
|
|
?INFO_MSG("terminated: ~p", [Reason]),
|
2003-01-07 20:10:35 +01:00
|
|
|
case StateName of
|
|
|
|
stream_established ->
|
2003-10-18 21:15:12 +02:00
|
|
|
lists:foreach(
|
|
|
|
fun(H) ->
|
2003-12-14 21:51:01 +01:00
|
|
|
ejabberd_router:unregister_route(H)
|
2003-10-18 21:15:12 +02:00
|
|
|
end, StateData#state.hosts);
|
2003-01-07 20:10:35 +01:00
|
|
|
_ ->
|
|
|
|
ok
|
|
|
|
end,
|
2006-10-01 03:53:37 +02:00
|
|
|
(StateData#state.sockmod):close(StateData#state.socket),
|
2003-01-07 20:10:35 +01:00
|
|
|
ok.
|
|
|
|
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2003-10-18 21:15:12 +02:00
|
|
|
send_text(StateData, Text) ->
|
2006-10-01 03:53:37 +02:00
|
|
|
(StateData#state.sockmod):send(StateData#state.socket, Text).
|
2003-01-07 20:10:35 +01:00
|
|
|
|
2008-07-11 14:41:48 +02:00
|
|
|
send_element(StateData, #xmlel{ns = ?NS_XMPP, name = 'stream'} = El) ->
|
|
|
|
send_text(StateData, exmpp_stream:to_list(El));
|
2003-10-18 21:15:12 +02:00
|
|
|
send_element(StateData, El) ->
|
2008-07-11 14:41:48 +02:00
|
|
|
send_text(StateData, exmpp_stanza:to_list(El)).
|
2003-01-07 20:10:35 +01:00
|
|
|
|
|
|
|
new_id() ->
|
|
|
|
randoms:get_string().
|