mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
* src/xml_stream.erl: Cleanup
* src/ejabberd_service.erl: Updated to use ejabberd_receiver SVN Revision: 532
This commit is contained in:
parent
aa8e532cbd
commit
15a714ae68
@ -1,3 +1,9 @@
|
||||
2006-04-13 Alexey Shchepin <alexey@sevcom.net>
|
||||
|
||||
* src/xml_stream.erl: Cleanup
|
||||
|
||||
* src/ejabberd_service.erl: Updated to use ejabberd_receiver
|
||||
|
||||
2006-04-12 Alexey Shchepin <alexey@sevcom.net>
|
||||
|
||||
* src/ejabberd_c2s.erl: Minor fix
|
||||
|
@ -15,7 +15,6 @@
|
||||
%% External exports
|
||||
-export([start/2,
|
||||
start_link/2,
|
||||
receiver/3,
|
||||
send_text/2,
|
||||
send_element/2,
|
||||
become_controller/1]).
|
||||
@ -80,8 +79,8 @@ start(SockData, Opts) ->
|
||||
start_link(SockData, Opts) ->
|
||||
gen_fsm:start_link(ejabberd_service, [SockData, Opts], ?FSMOPTS).
|
||||
|
||||
become_controller(_Pid) ->
|
||||
ok.
|
||||
become_controller(Pid) ->
|
||||
gen_fsm:send_all_state_event(Pid, become_controller).
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Callback functions from gen_fsm
|
||||
@ -124,7 +123,7 @@ init([{SockMod, Socket}, Opts]) ->
|
||||
false
|
||||
end
|
||||
end,
|
||||
ReceiverPid = spawn(?MODULE, receiver, [Socket, SockMod, self()]),
|
||||
ReceiverPid = ejabberd_receiver:start(Socket, SockMod, none),
|
||||
{ok, wait_for_stream, #state{socket = Socket,
|
||||
receiver = ReceiverPid,
|
||||
streamid = new_id(),
|
||||
@ -260,6 +259,12 @@ stream_established(closed, StateData) ->
|
||||
%% {next_state, NextStateName, NextStateData, Timeout} |
|
||||
%% {stop, Reason, NewStateData}
|
||||
%%----------------------------------------------------------------------
|
||||
handle_event(become_controller, StateName, StateData) ->
|
||||
ok = (StateData#state.sockmod):controlling_process(
|
||||
StateData#state.socket,
|
||||
StateData#state.receiver),
|
||||
ejabberd_receiver:become_controller(StateData#state.receiver),
|
||||
{next_state, StateName, StateData};
|
||||
handle_event(_Event, StateName, StateData) ->
|
||||
{next_state, StateName, StateData}.
|
||||
|
||||
@ -323,28 +328,13 @@ terminate(Reason, StateName, StateData) ->
|
||||
_ ->
|
||||
ok
|
||||
end,
|
||||
(StateData#state.sockmod):close(StateData#state.socket),
|
||||
ejabberd_receiver:close(StateData#state.receiver),
|
||||
ok.
|
||||
|
||||
%%%----------------------------------------------------------------------
|
||||
%%% Internal functions
|
||||
%%%----------------------------------------------------------------------
|
||||
|
||||
receiver(Socket, SockMod, C2SPid) ->
|
||||
XMLStreamPid = xml_stream:start(C2SPid),
|
||||
receiver(Socket, SockMod, C2SPid, XMLStreamPid).
|
||||
|
||||
receiver(Socket, SockMod, C2SPid, XMLStreamPid) ->
|
||||
case SockMod:recv(Socket, 0) of
|
||||
{ok, Text} ->
|
||||
xml_stream:send_text(XMLStreamPid, Text),
|
||||
receiver(Socket, SockMod, C2SPid, XMLStreamPid);
|
||||
{error, _Reason} ->
|
||||
exit(XMLStreamPid, closed),
|
||||
gen_fsm:send_event(C2SPid, closed),
|
||||
ok
|
||||
end.
|
||||
|
||||
send_text(StateData, Text) ->
|
||||
(StateData#state.sockmod):send(StateData#state.socket,Text).
|
||||
|
||||
|
@ -10,10 +10,7 @@
|
||||
-author('alexey@sevcom.net').
|
||||
-vsn('$Revision$ ').
|
||||
|
||||
-export([start/1, start/2,
|
||||
init/1, init/2,
|
||||
send_text/2,
|
||||
new/1,
|
||||
-export([new/1,
|
||||
parse/2,
|
||||
close/1,
|
||||
parse_element/1]).
|
||||
@ -28,37 +25,6 @@
|
||||
|
||||
-record(xml_stream_state, {callback_pid, port, stack}).
|
||||
|
||||
start(CallbackPid) ->
|
||||
spawn(?MODULE, init, [CallbackPid]).
|
||||
|
||||
start(Receiver, CallbackPid) ->
|
||||
spawn(?MODULE, init, [Receiver, CallbackPid]).
|
||||
|
||||
init(CallbackPid) ->
|
||||
Port = open_port({spawn, expat_erl}, [binary]),
|
||||
loop(CallbackPid, Port, []).
|
||||
|
||||
init(Receiver, CallbackPid) ->
|
||||
erlang:monitor(process, Receiver),
|
||||
Port = open_port({spawn, expat_erl}, [binary]),
|
||||
loop(CallbackPid, Port, []).
|
||||
|
||||
loop(CallbackPid, Port, Stack) ->
|
||||
receive
|
||||
{Port, {data, Bin}} ->
|
||||
Data = binary_to_term(Bin),
|
||||
loop(CallbackPid, Port, process_data(CallbackPid, Stack, Data));
|
||||
{_From, {send, Str}} ->
|
||||
Res = port_control(Port, ?PARSE_COMMAND, Str),
|
||||
NewStack = lists:foldl(
|
||||
fun(Data, St) ->
|
||||
process_data(CallbackPid, St, Data)
|
||||
end, Stack, binary_to_term(Res)),
|
||||
loop(CallbackPid, Port, NewStack);
|
||||
{'DOWN', _Ref, _Type, _Object, _Info} ->
|
||||
ok
|
||||
end.
|
||||
|
||||
process_data(CallbackPid, Stack, Data) ->
|
||||
case Data of
|
||||
{?XML_START, {Name, Attrs}} ->
|
||||
@ -102,9 +68,6 @@ process_data(CallbackPid, Stack, Data) ->
|
||||
end.
|
||||
|
||||
|
||||
send_text(Pid, Text) ->
|
||||
Pid ! {self(), {send, Text}}.
|
||||
|
||||
|
||||
new(CallbackPid) ->
|
||||
Port = open_port({spawn, expat_erl}, [binary]),
|
||||
|
Loading…
Reference in New Issue
Block a user