2003-11-10 22:25:36 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : ejabberd_receiver.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2003-11-10 22:25:36 +01:00
|
|
|
%%% Purpose : Socket receiver for C2S and S2S connections
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 10 Nov 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2017-01-02 21:41:53 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 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-12 15:44:42 +01:00
|
|
|
%%%
|
2014-02-22 11:27:40 +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.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
2003-11-10 22:25:36 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(ejabberd_receiver).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2006-01-13 02:55:20 +01:00
|
|
|
-behaviour(gen_server).
|
|
|
|
|
|
|
|
%% API
|
2006-09-05 06:26:28 +02:00
|
|
|
-export([start_link/4,
|
2006-01-29 05:38:31 +01:00
|
|
|
start/3,
|
2006-04-22 05:35:13 +02:00
|
|
|
start/4,
|
2003-11-10 22:25:36 +01:00
|
|
|
change_shaper/2,
|
2004-08-01 22:12:20 +02:00
|
|
|
reset_stream/1,
|
2006-01-13 02:55:20 +01:00
|
|
|
starttls/2,
|
2006-01-19 03:17:31 +01:00
|
|
|
compress/2,
|
2006-09-05 06:26:28 +02:00
|
|
|
become_controller/2,
|
2006-01-13 02:55:20 +01:00
|
|
|
close/1]).
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2006-01-13 02:55:20 +01:00
|
|
|
%% gen_server callbacks
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([init/1, handle_call/3, handle_cast/2,
|
|
|
|
handle_info/2, terminate/2, code_change/3]).
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2006-01-13 02:55:20 +01:00
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-record(state,
|
2016-02-03 16:13:16 +01:00
|
|
|
{socket :: inet:socket() | fast_tls:tls_socket() | ezlib:zlib_socket(),
|
|
|
|
sock_mod = gen_tcp :: gen_tcp | fast_tls | ezlib,
|
2013-03-14 10:33:02 +01:00
|
|
|
shaper_state = none :: shaper:shaper(),
|
|
|
|
c2s_pid :: pid(),
|
|
|
|
max_stanza_size = infinity :: non_neg_integer() | infinity,
|
2016-02-03 19:03:17 +01:00
|
|
|
xml_stream_state :: fxml_stream:xml_stream_state(),
|
2013-03-14 10:33:02 +01:00
|
|
|
timeout = infinity:: timeout()}).
|
2006-01-13 02:55:20 +01:00
|
|
|
|
2016-02-04 19:45:29 +01:00
|
|
|
-define(HIBERNATE_TIMEOUT, ejabberd_config:get_option(receiver_hibernate, fun(X) when is_integer(X); X == hibernate-> X end, 90000)).
|
|
|
|
|
2008-11-23 10:43:52 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec start_link(inet:socket(), atom(), shaper:shaper(),
|
|
|
|
non_neg_integer() | infinity) -> ignore |
|
|
|
|
{error, any()} |
|
|
|
|
{ok, pid()}.
|
|
|
|
|
2006-09-05 06:26:28 +02:00
|
|
|
start_link(Socket, SockMod, Shaper, MaxStanzaSize) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_server:start_link(?MODULE,
|
|
|
|
[Socket, SockMod, Shaper, MaxStanzaSize], []).
|
|
|
|
|
|
|
|
-spec start(inet:socket(), atom(), shaper:shaper()) -> undefined | pid().
|
2006-01-29 05:38:31 +01:00
|
|
|
|
2003-11-10 22:25:36 +01:00
|
|
|
start(Socket, SockMod, Shaper) ->
|
2006-04-22 05:35:13 +02:00
|
|
|
start(Socket, SockMod, Shaper, infinity).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec start(inet:socket(), atom(), shaper:shaper(),
|
|
|
|
non_neg_integer() | infinity) -> undefined | pid().
|
|
|
|
|
2006-04-22 05:35:13 +02:00
|
|
|
start(Socket, SockMod, Shaper, MaxStanzaSize) ->
|
2015-12-11 15:33:22 +01:00
|
|
|
{ok, Pid} = gen_server:start(ejabberd_receiver,
|
|
|
|
[Socket, SockMod, Shaper, MaxStanzaSize], []),
|
2006-01-13 02:55:20 +01:00
|
|
|
Pid.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec change_shaper(pid(), shaper:shaper()) -> ok.
|
|
|
|
|
2006-01-13 02:55:20 +01:00
|
|
|
change_shaper(Pid, Shaper) ->
|
|
|
|
gen_server:cast(Pid, {change_shaper, Shaper}).
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec reset_stream(pid()) -> ok | {error, any()}.
|
|
|
|
|
|
|
|
reset_stream(Pid) -> do_call(Pid, reset_stream).
|
|
|
|
|
2016-02-03 16:13:16 +01:00
|
|
|
-spec starttls(pid(), fast_tls:tls_socket()) -> ok.
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2006-01-13 02:55:20 +01:00
|
|
|
starttls(Pid, TLSSocket) ->
|
2012-02-14 08:03:08 +01:00
|
|
|
do_call(Pid, {starttls, TLSSocket}).
|
2006-01-13 02:55:20 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec compress(pid(), iodata() | undefined) -> {error, any()} |
|
2013-04-08 11:12:54 +02:00
|
|
|
{ok, ezlib:zlib_socket()}.
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
compress(Pid, Data) ->
|
|
|
|
do_call(Pid, {compress, Data}).
|
2006-01-19 03:17:31 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec become_controller(pid(), pid()) -> ok | {error, any()}.
|
|
|
|
|
2006-09-05 06:26:28 +02:00
|
|
|
become_controller(Pid, C2SPid) ->
|
2012-02-14 08:03:08 +01:00
|
|
|
do_call(Pid, {become_controller, C2SPid}).
|
2006-01-13 02:55:20 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-spec close(pid()) -> ok.
|
|
|
|
|
2006-01-13 02:55:20 +01:00
|
|
|
close(Pid) ->
|
|
|
|
gen_server:cast(Pid, close).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2006-01-13 02:55:20 +01:00
|
|
|
%%====================================================================
|
|
|
|
%% gen_server callbacks
|
|
|
|
%%====================================================================
|
|
|
|
|
2006-09-05 06:26:28 +02:00
|
|
|
init([Socket, SockMod, Shaper, MaxStanzaSize]) ->
|
2003-11-10 22:25:36 +01:00
|
|
|
ShaperState = shaper:new(Shaper),
|
|
|
|
Timeout = case SockMod of
|
2013-03-14 10:33:02 +01:00
|
|
|
ssl -> 20;
|
|
|
|
_ -> infinity
|
2003-11-10 22:25:36 +01:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok,
|
|
|
|
#state{socket = Socket, sock_mod = SockMod,
|
|
|
|
shaper_state = ShaperState,
|
|
|
|
max_stanza_size = MaxStanzaSize, timeout = Timeout}}.
|
2006-01-13 02:55:20 +01:00
|
|
|
|
2015-11-09 16:05:02 +01:00
|
|
|
handle_call({starttls, TLSSocket}, _From, State) ->
|
|
|
|
State1 = reset_parser(State),
|
|
|
|
NewState = State1#state{socket = TLSSocket,
|
2016-02-03 16:13:16 +01:00
|
|
|
sock_mod = fast_tls},
|
|
|
|
case fast_tls:recv_data(TLSSocket, <<"">>) of
|
2006-01-13 02:55:20 +01:00
|
|
|
{ok, TLSData} ->
|
2015-10-07 00:06:58 +02:00
|
|
|
{reply, ok,
|
|
|
|
process_data(TLSData, NewState), ?HIBERNATE_TIMEOUT};
|
2006-01-13 02:55:20 +01:00
|
|
|
{error, _Reason} ->
|
|
|
|
{stop, normal, ok, NewState}
|
|
|
|
end;
|
2013-04-08 11:12:54 +02:00
|
|
|
handle_call({compress, Data}, _From,
|
2015-11-09 16:05:02 +01:00
|
|
|
#state{socket = Socket, sock_mod = SockMod} =
|
2013-04-08 11:12:54 +02:00
|
|
|
State) ->
|
2016-03-16 11:11:43 +01:00
|
|
|
ejabberd:start_app(ezlib),
|
2013-04-08 11:12:54 +02:00
|
|
|
{ok, ZlibSocket} = ezlib:enable_zlib(SockMod,
|
|
|
|
Socket),
|
|
|
|
if Data /= undefined -> do_send(State, Data);
|
|
|
|
true -> ok
|
|
|
|
end,
|
2015-11-09 16:05:02 +01:00
|
|
|
State1 = reset_parser(State),
|
|
|
|
NewState = State1#state{socket = ZlibSocket,
|
|
|
|
sock_mod = ezlib},
|
2013-04-08 11:12:54 +02:00
|
|
|
case ezlib:recv_data(ZlibSocket, <<"">>) of
|
|
|
|
{ok, ZlibData} ->
|
2015-10-07 00:06:58 +02:00
|
|
|
{reply, {ok, ZlibSocket},
|
|
|
|
process_data(ZlibData, NewState), ?HIBERNATE_TIMEOUT};
|
|
|
|
{error, _Reason} ->
|
|
|
|
{stop, normal, ok, NewState}
|
2006-01-19 03:17:31 +01:00
|
|
|
end;
|
2015-11-09 16:05:02 +01:00
|
|
|
handle_call(reset_stream, _From, State) ->
|
|
|
|
NewState = reset_parser(State),
|
2006-01-13 02:55:20 +01:00
|
|
|
Reply = ok,
|
2015-11-09 16:05:02 +01:00
|
|
|
{reply, Reply, NewState, ?HIBERNATE_TIMEOUT};
|
2006-09-05 06:26:28 +02:00
|
|
|
handle_call({become_controller, C2SPid}, _From, State) ->
|
2016-02-03 19:03:17 +01:00
|
|
|
XMLStreamState = fxml_stream:new(C2SPid, State#state.max_stanza_size),
|
2006-09-05 06:26:28 +02:00
|
|
|
NewState = State#state{c2s_pid = C2SPid,
|
|
|
|
xml_stream_state = XMLStreamState},
|
|
|
|
activate_socket(NewState),
|
2006-01-13 02:55:20 +01:00
|
|
|
Reply = ok,
|
2008-11-23 10:43:52 +01:00
|
|
|
{reply, Reply, NewState, ?HIBERNATE_TIMEOUT};
|
2006-01-13 02:55:20 +01:00
|
|
|
handle_call(_Request, _From, State) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
Reply = ok, {reply, Reply, State, ?HIBERNATE_TIMEOUT}.
|
2006-01-13 02:55:20 +01:00
|
|
|
|
|
|
|
handle_cast({change_shaper, Shaper}, State) ->
|
|
|
|
NewShaperState = shaper:new(Shaper),
|
2013-03-14 10:33:02 +01:00
|
|
|
{noreply, State#state{shaper_state = NewShaperState},
|
|
|
|
?HIBERNATE_TIMEOUT};
|
|
|
|
handle_cast(close, State) -> {stop, normal, State};
|
2006-01-13 02:55:20 +01:00
|
|
|
handle_cast(_Msg, State) ->
|
2008-11-23 10:43:52 +01:00
|
|
|
{noreply, State, ?HIBERNATE_TIMEOUT}.
|
2006-01-13 02:55:20 +01:00
|
|
|
|
|
|
|
handle_info({Tag, _TCPSocket, Data},
|
2013-03-14 10:33:02 +01:00
|
|
|
#state{socket = Socket, sock_mod = SockMod} = State)
|
|
|
|
when (Tag == tcp) or (Tag == ssl) or
|
|
|
|
(Tag == ejabberd_xml) ->
|
2006-01-13 02:55:20 +01:00
|
|
|
case SockMod of
|
2016-02-03 16:13:16 +01:00
|
|
|
fast_tls ->
|
|
|
|
case fast_tls:recv_data(Socket, Data) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, TLSData} ->
|
|
|
|
{noreply, process_data(TLSData, State),
|
|
|
|
?HIBERNATE_TIMEOUT};
|
2015-03-03 11:32:04 +01:00
|
|
|
{error, Reason} ->
|
|
|
|
if is_binary(Reason) ->
|
2015-09-24 12:00:59 +02:00
|
|
|
?DEBUG("TLS error = ~s", [Reason]);
|
2015-03-03 11:32:04 +01:00
|
|
|
true ->
|
|
|
|
ok
|
|
|
|
end,
|
|
|
|
{stop, normal, State}
|
2013-03-14 10:33:02 +01:00
|
|
|
end;
|
2013-04-08 11:12:54 +02:00
|
|
|
ezlib ->
|
|
|
|
case ezlib:recv_data(Socket, Data) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{ok, ZlibData} ->
|
|
|
|
{noreply, process_data(ZlibData, State),
|
|
|
|
?HIBERNATE_TIMEOUT};
|
|
|
|
{error, _Reason} -> {stop, normal, State}
|
|
|
|
end;
|
|
|
|
_ ->
|
|
|
|
{noreply, process_data(Data, State), ?HIBERNATE_TIMEOUT}
|
2006-01-13 02:55:20 +01:00
|
|
|
end;
|
|
|
|
handle_info({Tag, _TCPSocket}, State)
|
2013-03-14 10:33:02 +01:00
|
|
|
when (Tag == tcp_closed) or (Tag == ssl_closed) ->
|
2006-01-13 02:55:20 +01:00
|
|
|
{stop, normal, State};
|
|
|
|
handle_info({Tag, _TCPSocket, Reason}, State)
|
2013-03-14 10:33:02 +01:00
|
|
|
when (Tag == tcp_error) or (Tag == ssl_error) ->
|
2006-01-13 02:55:20 +01:00
|
|
|
case Reason of
|
2013-03-14 10:33:02 +01:00
|
|
|
timeout -> {noreply, State, ?HIBERNATE_TIMEOUT};
|
|
|
|
_ -> {stop, normal, State}
|
2006-01-13 02:55:20 +01:00
|
|
|
end;
|
|
|
|
handle_info({timeout, _Ref, activate}, State) ->
|
|
|
|
activate_socket(State),
|
2008-11-23 10:43:52 +01:00
|
|
|
{noreply, State, ?HIBERNATE_TIMEOUT};
|
|
|
|
handle_info(timeout, State) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
proc_lib:hibernate(gen_server, enter_loop,
|
|
|
|
[?MODULE, [], State]),
|
2008-11-23 10:43:52 +01:00
|
|
|
{noreply, State, ?HIBERNATE_TIMEOUT};
|
2006-01-13 02:55:20 +01:00
|
|
|
handle_info(_Info, State) ->
|
2008-11-23 10:43:52 +01:00
|
|
|
{noreply, State, ?HIBERNATE_TIMEOUT}.
|
2006-01-13 02:55:20 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
terminate(_Reason,
|
|
|
|
#state{xml_stream_state = XMLStreamState,
|
|
|
|
c2s_pid = C2SPid} =
|
|
|
|
State) ->
|
2008-02-11 16:36:56 +01:00
|
|
|
close_stream(XMLStreamState),
|
2013-03-14 10:33:02 +01:00
|
|
|
if C2SPid /= undefined ->
|
|
|
|
gen_fsm:send_event(C2SPid, closed);
|
|
|
|
true -> ok
|
2006-12-08 21:48:26 +01:00
|
|
|
end,
|
2006-01-13 02:55:20 +01:00
|
|
|
catch (State#state.sock_mod):close(State#state.socket),
|
|
|
|
ok.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
2006-01-13 02:55:20 +01:00
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
%%% Internal functions
|
|
|
|
%%--------------------------------------------------------------------
|
|
|
|
|
|
|
|
activate_socket(#state{socket = Socket,
|
2008-07-16 14:55:29 +02:00
|
|
|
sock_mod = SockMod}) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
PeerName = case SockMod of
|
|
|
|
gen_tcp ->
|
|
|
|
inet:setopts(Socket, [{active, once}]),
|
|
|
|
inet:peername(Socket);
|
|
|
|
_ ->
|
|
|
|
SockMod:setopts(Socket, [{active, once}]),
|
|
|
|
SockMod:peername(Socket)
|
|
|
|
end,
|
2007-05-07 19:52:35 +02:00
|
|
|
case PeerName of
|
2013-03-14 10:33:02 +01:00
|
|
|
{error, _Reason} -> self() ! {tcp_closed, Socket};
|
|
|
|
{ok, _} -> ok
|
2003-11-10 22:25:36 +01:00
|
|
|
end.
|
|
|
|
|
2009-08-31 20:37:52 +02:00
|
|
|
%% Data processing for connectors directly generating xmlelement in
|
|
|
|
%% Erlang data structure.
|
|
|
|
%% WARNING: Shaper does not work with Erlang data structure.
|
|
|
|
process_data([], State) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
activate_socket(State), State;
|
|
|
|
process_data([Element | Els],
|
|
|
|
#state{c2s_pid = C2SPid} = State)
|
|
|
|
when element(1, Element) == xmlel;
|
|
|
|
element(1, Element) == xmlstreamstart;
|
|
|
|
element(1, Element) == xmlstreamelement;
|
|
|
|
element(1, Element) == xmlstreamend ->
|
|
|
|
if C2SPid == undefined -> State;
|
|
|
|
true ->
|
|
|
|
catch gen_fsm:send_event(C2SPid,
|
|
|
|
element_wrapper(Element)),
|
|
|
|
process_data(Els, State)
|
2009-08-31 20:37:52 +02:00
|
|
|
end;
|
|
|
|
%% Data processing for connectors receivind data as string.
|
2006-01-13 02:55:20 +01:00
|
|
|
process_data(Data,
|
|
|
|
#state{xml_stream_state = XMLStreamState,
|
2013-03-14 10:33:02 +01:00
|
|
|
shaper_state = ShaperState, c2s_pid = C2SPid} =
|
|
|
|
State) ->
|
|
|
|
?DEBUG("Received XML on stream = ~p", [(Data)]),
|
2015-09-17 11:36:45 +02:00
|
|
|
XMLStreamState1 = case XMLStreamState of
|
|
|
|
undefined ->
|
|
|
|
XMLStreamState;
|
|
|
|
_ ->
|
2016-02-03 19:03:17 +01:00
|
|
|
fxml_stream:parse(XMLStreamState, Data)
|
2015-09-17 11:36:45 +02:00
|
|
|
end,
|
2013-03-14 10:33:02 +01:00
|
|
|
{NewShaperState, Pause} = shaper:update(ShaperState, byte_size(Data)),
|
2006-01-13 02:55:20 +01:00
|
|
|
if
|
2008-05-04 09:38:24 +02:00
|
|
|
C2SPid == undefined ->
|
|
|
|
ok;
|
2006-01-13 02:55:20 +01:00
|
|
|
Pause > 0 ->
|
|
|
|
erlang:start_timer(Pause, self(), activate);
|
|
|
|
true ->
|
|
|
|
activate_socket(State)
|
|
|
|
end,
|
|
|
|
State#state{xml_stream_state = XMLStreamState1,
|
|
|
|
shaper_state = NewShaperState}.
|
2003-11-10 22:25:36 +01:00
|
|
|
|
2009-08-31 20:37:52 +02:00
|
|
|
%% Element coming from XML parser are wrapped inside xmlstreamelement
|
|
|
|
%% When we receive directly xmlelement tuple (from a socket module
|
|
|
|
%% speaking directly Erlang XML), we wrap it inside the same
|
|
|
|
%% xmlstreamelement coming from the XML parser.
|
|
|
|
element_wrapper(XMLElement)
|
2013-03-14 10:33:02 +01:00
|
|
|
when element(1, XMLElement) == xmlel ->
|
2009-08-31 20:37:52 +02:00
|
|
|
{xmlstreamelement, XMLElement};
|
2013-03-14 10:33:02 +01:00
|
|
|
element_wrapper(Element) -> Element.
|
2009-08-31 20:37:52 +02:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
close_stream(undefined) -> ok;
|
2008-02-11 16:36:56 +01:00
|
|
|
close_stream(XMLStreamState) ->
|
2016-02-03 19:03:17 +01:00
|
|
|
fxml_stream:close(XMLStreamState).
|
2012-02-14 08:03:08 +01:00
|
|
|
|
2015-11-09 16:05:02 +01:00
|
|
|
reset_parser(#state{xml_stream_state = undefined} = State) ->
|
|
|
|
State;
|
|
|
|
reset_parser(#state{c2s_pid = C2SPid,
|
|
|
|
max_stanza_size = MaxStanzaSize,
|
|
|
|
xml_stream_state = XMLStreamState}
|
|
|
|
= State) ->
|
2016-02-03 19:03:17 +01:00
|
|
|
NewStreamState = try fxml_stream:reset(XMLStreamState)
|
2015-11-09 16:05:02 +01:00
|
|
|
catch error:_ ->
|
|
|
|
close_stream(XMLStreamState),
|
|
|
|
case C2SPid of
|
|
|
|
undefined ->
|
|
|
|
undefined;
|
|
|
|
_ ->
|
2016-02-03 19:03:17 +01:00
|
|
|
fxml_stream:new(C2SPid, MaxStanzaSize)
|
2015-11-09 16:05:02 +01:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
State#state{xml_stream_state = NewStreamState}.
|
|
|
|
|
2013-04-08 11:12:54 +02:00
|
|
|
do_send(State, Data) ->
|
|
|
|
(State#state.sock_mod):send(State#state.socket, Data).
|
|
|
|
|
2012-02-14 08:03:08 +01:00
|
|
|
do_call(Pid, Msg) ->
|
|
|
|
case catch gen_server:call(Pid, Msg) of
|
2013-03-14 10:33:02 +01:00
|
|
|
{'EXIT', Why} -> {error, Why};
|
|
|
|
Res -> Res
|
2012-02-14 08:03:08 +01:00
|
|
|
end.
|