25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

*** empty log message ***

SVN Revision: 3
This commit is contained in:
Alexey Shchepin 2002-11-19 20:58:49 +00:00
parent e0b348319a
commit d3c120d55d

View File

@ -66,11 +66,16 @@
-endif. -endif.
-define(STREAM_HEADER, -define(STREAM_HEADER,
"<?xml version='1.0'?>"
"<stream:stream xmlns='jabber:client' " "<stream:stream xmlns='jabber:client' "
"xmlns:stream='http://etherx.jabber.org/streams' " "xmlns:stream='http://etherx.jabber.org/streams' "
"id='~s' from='~s'>" "id='~s' from='~s'>"
). ).
-define(STREAM_TRAILER, "</stream:stream>").
-define(INVALID_NS_ERR, "<stream:error>Invalid Namespace</stream:error>").
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% API %%% API
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -107,14 +112,17 @@ state_name(Event, StateData) ->
{next_state, state_name, StateData}. {next_state, state_name, StateData}.
wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) -> wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
% TODO
Header = io_lib:format(?STREAM_HEADER, ["SID", "localhost"]),
send_text(StateData#state.sender, Header),
case lists:keysearch("xmlns:stream", 1, Attrs) of case lists:keysearch("xmlns:stream", 1, Attrs) of
{value, {"xmlns:stream", "http://etherx.jabber.org/streams"}} -> {value, {"xmlns:stream", "http://etherx.jabber.org/streams"}} ->
% TODO % TODO
Header = io_lib:format(?STREAM_HEADER, ["SID", "localhost"]),
StateData#state.sender ! {text, Header},
{next_state, wait_for_auth, StateData}; {next_state, wait_for_auth, StateData};
_ -> _ ->
{stop, error, StateData} send_text(StateData#state.sender, ?INVALID_NS_ERR),
send_text(StateData#state.sender, ?STREAM_TRAILER),
{stop, normal, StateData}
end; end;
wait_for_stream(closed, StateData) -> wait_for_stream(closed, StateData) ->
@ -184,7 +192,8 @@ handle_info(Info, StateName, StateData) ->
%% Purpose: Shutdown the fsm %% Purpose: Shutdown the fsm
%% Returns: any %% Returns: any
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
terminate(Reason, StateName, StatData) -> terminate(Reason, StateName, StateData) ->
StateData#state.sender ! close,
ok. ok.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -201,6 +210,7 @@ receiver(Socket, C2SPid, XMLStreamPid) ->
xml_stream:send_text(XMLStreamPid, Text), xml_stream:send_text(XMLStreamPid, Text),
receiver(Socket, C2SPid, XMLStreamPid); receiver(Socket, C2SPid, XMLStreamPid);
{error, closed} -> {error, closed} ->
exit(XMLStreamPid, closed),
gen_fsm:send_event(C2SPid, closed), gen_fsm:send_event(C2SPid, closed),
ok ok
end. end.
@ -210,7 +220,8 @@ sender(Socket) ->
{text, Text} -> {text, Text} ->
gen_tcp:send(Socket,Text), gen_tcp:send(Socket,Text),
sender(Socket); sender(Socket);
closed -> close ->
gen_tcp:close(Socket),
ok ok
end. end.