mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-22 16:20:52 +01:00
* src/ejabberd_s2s_out.erl: Fixed error replies, added timeouts
* src/ejabberd_s2s_in.erl: Likewise SVN Revision: 107
This commit is contained in:
parent
86cd1729cb
commit
481cc2d1f4
@ -1,3 +1,8 @@
|
|||||||
|
2003-05-12 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
|
* src/ejabberd_s2s_out.erl: Fixed error replies, added timeouts
|
||||||
|
* src/ejabberd_s2s_in.erl: Likewise
|
||||||
|
|
||||||
2003-05-09 Alexey Shchepin <alexey@sevcom.net>
|
2003-05-09 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
* src/ejabberd_local.erl: Updated missed errors to new style
|
* src/ejabberd_local.erl: Updated missed errors to new style
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
terminate/3]).
|
terminate/3]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
|
-include("jlib.hrl").
|
||||||
|
|
||||||
-record(state, {socket, receiver, streamid,
|
-record(state, {socket, receiver, streamid,
|
||||||
myname, server, queue}).
|
myname, server, queue}).
|
||||||
@ -50,17 +51,14 @@
|
|||||||
|
|
||||||
-define(STREAM_TRAILER, "</stream:stream>").
|
-define(STREAM_TRAILER, "</stream:stream>").
|
||||||
|
|
||||||
-define(INVALID_HEADER_ERR,
|
-define(INVALID_NAMESPACE_ERR,
|
||||||
"<stream:stream>"
|
xml:element_to_string(?SERR_INVALID_NAMESPACE)).
|
||||||
"<stream:error>Invalid Stream Header</stream:error>"
|
|
||||||
"</stream:stream>"
|
|
||||||
).
|
|
||||||
|
|
||||||
-define(INVALID_DOMAIN_ERR,
|
-define(HOST_UNKNOWN_ERR,
|
||||||
"<stream:stream>"
|
xml:element_to_string(?SERR_HOST_UNKNOWN)).
|
||||||
"<stream:error>Invalid Destination</stream:error>"
|
|
||||||
"</stream:stream>"
|
-define(INVALID_XML_ERR,
|
||||||
).
|
xml:element_to_string(?SERR_XML_NOT_WELL_FORMED)).
|
||||||
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% API
|
%%% API
|
||||||
@ -82,10 +80,12 @@ start(SockData, Opts) ->
|
|||||||
init([{SockMod, Socket}]) ->
|
init([{SockMod, Socket}]) ->
|
||||||
?INFO_MSG("started: ~p", [{SockMod, Socket}]),
|
?INFO_MSG("started: ~p", [{SockMod, Socket}]),
|
||||||
ReceiverPid = spawn(?MODULE, receiver, [Socket, self()]),
|
ReceiverPid = spawn(?MODULE, receiver, [Socket, self()]),
|
||||||
{ok, wait_for_stream, #state{socket = Socket,
|
{ok, wait_for_stream,
|
||||||
receiver = ReceiverPid,
|
#state{socket = Socket,
|
||||||
streamid = new_id(),
|
receiver = ReceiverPid,
|
||||||
queue = queue:new()}}.
|
streamid = new_id(),
|
||||||
|
queue = queue:new()},
|
||||||
|
?S2STIMEOUT}.
|
||||||
|
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
%% Func: StateName/2
|
%% Func: StateName/2
|
||||||
@ -105,16 +105,25 @@ wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
|
|||||||
case lists:member(Me, ejabberd_router:dirty_get_all_domains()) of
|
case lists:member(Me, ejabberd_router:dirty_get_all_domains()) of
|
||||||
true ->
|
true ->
|
||||||
send_text(StateData#state.socket, ?STREAM_HEADER),
|
send_text(StateData#state.socket, ?STREAM_HEADER),
|
||||||
{next_state, wait_for_key, StateData#state{myname = Me}};
|
{next_state, wait_for_key,
|
||||||
|
StateData#state{myname = Me}, ?S2STIMEOUT};
|
||||||
_ ->
|
_ ->
|
||||||
send_text(StateData#state.socket, ?INVALID_DOMAIN_ERR),
|
send_text(StateData#state.socket, ?HOST_UNKNOWN_ERR),
|
||||||
{stop, normal, StateData}
|
{stop, normal, StateData}
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
send_text(StateData#state.socket, ?INVALID_HEADER_ERR),
|
send_text(StateData#state.socket, ?INVALID_NAMESPACE_ERR),
|
||||||
{stop, normal, StateData}
|
{stop, normal, StateData}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
wait_for_stream({xmlstreamerror, _}, StateData) ->
|
||||||
|
send_text(StateData#state.socket,
|
||||||
|
?STREAM_HEADER ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_stream(timeout, StateData) ->
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
wait_for_stream(closed, StateData) ->
|
wait_for_stream(closed, StateData) ->
|
||||||
{stop, normal, StateData}.
|
{stop, normal, StateData}.
|
||||||
|
|
||||||
@ -130,9 +139,10 @@ wait_for_key({xmlstreamelement, El}, StateData) ->
|
|||||||
{next_state,
|
{next_state,
|
||||||
wait_for_verification,
|
wait_for_verification,
|
||||||
StateData#state{myname = To,
|
StateData#state{myname = To,
|
||||||
server = From}};
|
server = From},
|
||||||
|
?S2STIMEOUT};
|
||||||
_ ->
|
_ ->
|
||||||
send_text(StateData#state.socket, ?INVALID_DOMAIN_ERR),
|
send_text(StateData#state.socket, ?HOST_UNKNOWN_ERR),
|
||||||
{stop, normal, StateData}
|
{stop, normal, StateData}
|
||||||
end;
|
end;
|
||||||
{verify, To, From, Id, Key} ->
|
{verify, To, From, Id, Key} ->
|
||||||
@ -149,13 +159,20 @@ wait_for_key({xmlstreamelement, El}, StateData) ->
|
|||||||
{"id", Id},
|
{"id", Id},
|
||||||
{"type", Type}],
|
{"type", Type}],
|
||||||
[]}),
|
[]}),
|
||||||
{next_state, wait_for_key, StateData};
|
{next_state, wait_for_key, StateData, ?S2STIMEOUT};
|
||||||
_ ->
|
_ ->
|
||||||
{next_state, wait_for_key, StateData}
|
{next_state, wait_for_key, StateData, ?S2STIMEOUT}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
wait_for_key({xmlstreamend, Name}, StateData) ->
|
wait_for_key({xmlstreamend, Name}, StateData) ->
|
||||||
% TODO
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_key({xmlstreamerror, _}, StateData) ->
|
||||||
|
send_text(StateData#state.socket,
|
||||||
|
?STREAM_HEADER ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_key(timeout, StateData) ->
|
||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
|
|
||||||
wait_for_key(closed, StateData) ->
|
wait_for_key(closed, StateData) ->
|
||||||
@ -170,7 +187,7 @@ wait_for_verification(valid, StateData) ->
|
|||||||
{"type", "valid"}],
|
{"type", "valid"}],
|
||||||
[]}),
|
[]}),
|
||||||
send_queue(StateData#state.socket, StateData#state.queue),
|
send_queue(StateData#state.socket, StateData#state.queue),
|
||||||
{next_state, stream_established, StateData};
|
{next_state, stream_established, StateData, ?S2STIMEOUT};
|
||||||
|
|
||||||
wait_for_verification(invalid, StateData) ->
|
wait_for_verification(invalid, StateData) ->
|
||||||
send_element(StateData#state.socket,
|
send_element(StateData#state.socket,
|
||||||
@ -198,13 +215,20 @@ wait_for_verification({xmlstreamelement, El}, StateData) ->
|
|||||||
{"id", Id},
|
{"id", Id},
|
||||||
{"type", Type}],
|
{"type", Type}],
|
||||||
[]}),
|
[]}),
|
||||||
{next_state, wait_for_verification, StateData};
|
{next_state, wait_for_verification, StateData, ?S2STIMEOUT};
|
||||||
_ ->
|
_ ->
|
||||||
{next_state, wait_for_verification, StateData}
|
{next_state, wait_for_verification, StateData, ?S2STIMEOUT}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
wait_for_verification({xmlstreamend, Name}, StateData) ->
|
wait_for_verification({xmlstreamend, Name}, StateData) ->
|
||||||
% TODO
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_verification({xmlstreamerror, _}, StateData) ->
|
||||||
|
send_text(StateData#state.socket,
|
||||||
|
?STREAM_HEADER ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_verification(timeout, StateData) ->
|
||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
|
|
||||||
wait_for_verification(closed, StateData) ->
|
wait_for_verification(closed, StateData) ->
|
||||||
@ -260,14 +284,17 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
|||||||
{next_state, stream_established, StateData, ?S2STIMEOUT};
|
{next_state, stream_established, StateData, ?S2STIMEOUT};
|
||||||
|
|
||||||
stream_established({xmlstreamend, Name}, StateData) ->
|
stream_established({xmlstreamend, Name}, StateData) ->
|
||||||
% TODO
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
stream_established({xmlstreamerror, _}, StateData) ->
|
||||||
|
send_text(StateData#state.socket,
|
||||||
|
?STREAM_HEADER ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
|
|
||||||
stream_established(timeout, StateData) ->
|
stream_established(timeout, StateData) ->
|
||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
|
|
||||||
stream_established(closed, StateData) ->
|
stream_established(closed, StateData) ->
|
||||||
% TODO
|
|
||||||
{stop, normal, StateData}.
|
{stop, normal, StateData}.
|
||||||
|
|
||||||
|
|
||||||
@ -292,7 +319,7 @@ stream_established(closed, StateData) ->
|
|||||||
%% {stop, Reason, NewStateData}
|
%% {stop, Reason, NewStateData}
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
handle_event(Event, StateName, StateData) ->
|
handle_event(Event, StateName, StateData) ->
|
||||||
{next_state, StateName, StateData}.
|
{next_state, StateName, StateData, ?S2STIMEOUT}.
|
||||||
|
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
%% Func: handle_sync_event/4
|
%% Func: handle_sync_event/4
|
||||||
@ -323,10 +350,10 @@ handle_info({send_element, El}, StateName, StateData) ->
|
|||||||
case StateName of
|
case StateName of
|
||||||
stream_established ->
|
stream_established ->
|
||||||
send_element(StateData#state.socket, El),
|
send_element(StateData#state.socket, El),
|
||||||
{next_state, StateName, StateData};
|
{next_state, StateName, StateData, ?S2STIMEOUT};
|
||||||
_ ->
|
_ ->
|
||||||
Q = queue:in(El, StateData#state.queue),
|
Q = queue:in(El, StateData#state.queue),
|
||||||
{next_state, StateName, StateData#state{queue = Q}}
|
{next_state, StateName, StateData#state{queue = Q}, ?S2STIMEOUT}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -53,11 +53,14 @@
|
|||||||
|
|
||||||
-define(STREAM_TRAILER, "</stream:stream>").
|
-define(STREAM_TRAILER, "</stream:stream>").
|
||||||
|
|
||||||
-define(INVALID_HEADER_ERR,
|
-define(INVALID_NAMESPACE_ERR,
|
||||||
"<stream:stream>"
|
xml:element_to_string(?SERR_INVALID_NAMESPACE)).
|
||||||
"<stream:error>Invalid Stream Header</stream:error>"
|
|
||||||
"</stream:stream>"
|
-define(HOST_UNKNOWN_ERR,
|
||||||
).
|
xml:element_to_string(?SERR_HOST_UNKNOWN)).
|
||||||
|
|
||||||
|
-define(INVALID_XML_ERR,
|
||||||
|
xml:element_to_string(?SERR_XML_NOT_WELL_FORMED)).
|
||||||
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% API
|
%%% API
|
||||||
@ -90,7 +93,8 @@ init([From, Server, Type]) ->
|
|||||||
myname = From,
|
myname = From,
|
||||||
server = Server,
|
server = Server,
|
||||||
new = New,
|
new = New,
|
||||||
verify = Verify}}.
|
verify = Verify},
|
||||||
|
?S2STIMEOUT}.
|
||||||
|
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
%% Func: StateName/2
|
%% Func: StateName/2
|
||||||
@ -111,7 +115,8 @@ open_socket(init, StateData) ->
|
|||||||
{next_state, wait_for_stream,
|
{next_state, wait_for_stream,
|
||||||
StateData#state{socket = Socket,
|
StateData#state{socket = Socket,
|
||||||
xmlpid = XMLStreamPid,
|
xmlpid = XMLStreamPid,
|
||||||
streamid = new_id()}};
|
streamid = new_id()},
|
||||||
|
?S2STIMEOUT};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?DEBUG("s2s_out: connect return ~p~n", [Reason]),
|
?DEBUG("s2s_out: connect return ~p~n", [Reason]),
|
||||||
Error = case Reason of
|
Error = case Reason of
|
||||||
@ -163,12 +168,21 @@ wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
|
|||||||
{"to", StateData#state.server}],
|
{"to", StateData#state.server}],
|
||||||
[{xmlcdata, Key2}]})
|
[{xmlcdata, Key2}]})
|
||||||
end,
|
end,
|
||||||
{next_state, wait_for_validation, StateData#state{new = New}};
|
{next_state, wait_for_validation,
|
||||||
|
StateData#state{new = New}, ?S2STIMEOUT};
|
||||||
_ ->
|
_ ->
|
||||||
send_text(StateData#state.socket, ?INVALID_HEADER_ERR),
|
send_text(StateData#state.socket, ?INVALID_NAMESPACE_ERR),
|
||||||
{stop, normal, StateData}
|
{stop, normal, StateData}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
wait_for_stream({xmlstreamerror, _}, StateData) ->
|
||||||
|
send_text(StateData#state.socket,
|
||||||
|
?STREAM_HEADER ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_stream(timeout, StateData) ->
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
wait_for_stream(closed, StateData) ->
|
wait_for_stream(closed, StateData) ->
|
||||||
{stop, normal, StateData}.
|
{stop, normal, StateData}.
|
||||||
|
|
||||||
@ -190,7 +204,7 @@ wait_for_validation({xmlstreamelement, El}, StateData) ->
|
|||||||
?INFO_MSG("recv verify: ~p", [{From, To, Id, Type}]),
|
?INFO_MSG("recv verify: ~p", [{From, To, Id, Type}]),
|
||||||
case StateData#state.verify of
|
case StateData#state.verify of
|
||||||
false ->
|
false ->
|
||||||
{next_state, wait_for_validation, StateData};
|
{next_state, wait_for_validation, StateData, ?S2STIMEOUT};
|
||||||
{Pid, Key} ->
|
{Pid, Key} ->
|
||||||
case Type of
|
case Type of
|
||||||
"valid" ->
|
"valid" ->
|
||||||
@ -203,15 +217,22 @@ wait_for_validation({xmlstreamelement, El}, StateData) ->
|
|||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
_ ->
|
_ ->
|
||||||
{next_state, wait_for_validation,
|
{next_state, wait_for_validation,
|
||||||
StateData#state{verify = false}}
|
StateData#state{verify = false}, ?S2STIMEOUT}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
_ ->
|
_ ->
|
||||||
{next_state, wait_for_validation, StateData}
|
{next_state, wait_for_validation, StateData, ?S2STIMEOUT}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
wait_for_validation({xmlstreamend, Name}, StateData) ->
|
wait_for_validation({xmlstreamend, Name}, StateData) ->
|
||||||
% TODO
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_validation({xmlstreamerror, _}, StateData) ->
|
||||||
|
send_text(StateData#state.socket,
|
||||||
|
?STREAM_HEADER ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
wait_for_validation(timeout, StateData) ->
|
||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
|
|
||||||
wait_for_validation(closed, StateData) ->
|
wait_for_validation(closed, StateData) ->
|
||||||
@ -263,6 +284,11 @@ stream_established({xmlstreamelement, El}, StateData) ->
|
|||||||
stream_established({xmlstreamend, Name}, StateData) ->
|
stream_established({xmlstreamend, Name}, StateData) ->
|
||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
stream_established({xmlstreamerror, _}, StateData) ->
|
||||||
|
send_text(StateData#state.socket,
|
||||||
|
?STREAM_HEADER ++ ?INVALID_XML_ERR ++ ?STREAM_TRAILER),
|
||||||
|
{stop, normal, StateData};
|
||||||
|
|
||||||
stream_established(timeout, StateData) ->
|
stream_established(timeout, StateData) ->
|
||||||
{stop, normal, StateData};
|
{stop, normal, StateData};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user