26
1
mirror of https://github.com/processone/ejabberd.git synced 2025-01-01 17:53:00 +01:00

Replace gen_fsm with p1_fsm to avoid warnings in OTP20+

This commit is contained in:
Evgeniy Khramtsov 2017-08-05 20:58:21 +03:00
parent b673539a2a
commit 92532a0d66
13 changed files with 90 additions and 95 deletions

View File

@ -27,9 +27,7 @@
-protocol({xep, 124, '1.11'}). -protocol({xep, 124, '1.11'}).
-protocol({xep, 206, '1.4'}). -protocol({xep, 206, '1.4'}).
-define(GEN_FSM, p1_fsm). -behaviour(p1_fsm).
-behaviour(?GEN_FSM).
%% API %% API
-export([start/2, start/3, start_link/3]). -export([start/2, start/3, start_link/3]).
@ -137,18 +135,18 @@ start(#body{attrs = Attrs} = Body, IP, SID) ->
end. end.
start(StateName, State) -> start(StateName, State) ->
(?GEN_FSM):start_link(?MODULE, [StateName, State], p1_fsm:start_link(?MODULE, [StateName, State],
?FSMOPTS). ?FSMOPTS).
start_link(Body, IP, SID) -> start_link(Body, IP, SID) ->
(?GEN_FSM):start_link(?MODULE, [Body, IP, SID], p1_fsm:start_link(?MODULE, [Body, IP, SID],
?FSMOPTS). ?FSMOPTS).
send({http_bind, FsmRef, IP}, Packet) -> send({http_bind, FsmRef, IP}, Packet) ->
send_xml({http_bind, FsmRef, IP}, Packet). send_xml({http_bind, FsmRef, IP}, Packet).
send_xml({http_bind, FsmRef, _IP}, Packet) -> send_xml({http_bind, FsmRef, _IP}, Packet) ->
case catch (?GEN_FSM):sync_send_all_state_event(FsmRef, case catch p1_fsm:sync_send_all_state_event(FsmRef,
{send_xml, Packet}, {send_xml, Packet},
?SEND_TIMEOUT) ?SEND_TIMEOUT)
of of
@ -160,12 +158,12 @@ send_xml({http_bind, FsmRef, _IP}, Packet) ->
setopts({http_bind, FsmRef, _IP}, Opts) -> setopts({http_bind, FsmRef, _IP}, Opts) ->
case lists:member({active, once}, Opts) of case lists:member({active, once}, Opts) of
true -> true ->
(?GEN_FSM):send_all_state_event(FsmRef, p1_fsm:send_all_state_event(FsmRef,
{activate, self()}); {activate, self()});
_ -> _ ->
case lists:member({active, false}, Opts) of case lists:member({active, false}, Opts) of
true -> true ->
case catch (?GEN_FSM):sync_send_all_state_event(FsmRef, case catch p1_fsm:sync_send_all_state_event(FsmRef,
deactivate_socket) deactivate_socket)
of of
{'EXIT', _} -> {error, einval}; {'EXIT', _} -> {error, einval};
@ -181,7 +179,7 @@ custom_receiver({http_bind, FsmRef, _IP}) ->
{receiver, ?MODULE, FsmRef}. {receiver, ?MODULE, FsmRef}.
become_controller(FsmRef, C2SPid) -> become_controller(FsmRef, C2SPid) ->
(?GEN_FSM):send_all_state_event(FsmRef, p1_fsm:send_all_state_event(FsmRef,
{become_controller, C2SPid}). {become_controller, C2SPid}).
change_controller({http_bind, FsmRef, _IP}, C2SPid) -> change_controller({http_bind, FsmRef, _IP}, C2SPid) ->
@ -190,14 +188,14 @@ change_controller({http_bind, FsmRef, _IP}, C2SPid) ->
reset_stream({http_bind, _FsmRef, _IP}) -> ok. reset_stream({http_bind, _FsmRef, _IP}) -> ok.
change_shaper({http_bind, FsmRef, _IP}, Shaper) -> change_shaper({http_bind, FsmRef, _IP}, Shaper) ->
(?GEN_FSM):send_all_state_event(FsmRef, p1_fsm:send_all_state_event(FsmRef,
{change_shaper, Shaper}). {change_shaper, Shaper}).
monitor({http_bind, FsmRef, _IP}) -> monitor({http_bind, FsmRef, _IP}) ->
erlang:monitor(process, FsmRef). erlang:monitor(process, FsmRef).
close({http_bind, FsmRef, _IP}) -> close({http_bind, FsmRef, _IP}) ->
catch (?GEN_FSM):sync_send_all_state_event(FsmRef, catch p1_fsm:sync_send_all_state_event(FsmRef,
close). close).
sockname(_Socket) -> {ok, {{0, 0, 0, 0}, 0}}. sockname(_Socket) -> {ok, {{0, 0, 0, 0}, 0}}.
@ -269,7 +267,7 @@ process_request(Data, IP, Type) ->
end. end.
process_request(Pid, Req, _IP, Type) -> process_request(Pid, Req, _IP, Type) ->
case catch (?GEN_FSM):sync_send_event(Pid, Req, case catch p1_fsm:sync_send_event(Pid, Req,
infinity) infinity)
of of
#body{} = Resp -> bosh_response(Resp, Type); #body{} = Resp -> bosh_response(Resp, Type);
@ -571,7 +569,7 @@ handle_sync_event({send_xml, El}, _From, StateName,
of of
{{value, {TRef, From, Body}}, Q} -> {{value, {TRef, From, Body}}, Q} ->
cancel_timer(TRef), cancel_timer(TRef),
(?GEN_FSM):send_event(self(), {Body, From}), p1_fsm:send_event(self(), {Body, From}),
State1#state{shaped_receivers = Q}; State1#state{shaped_receivers = Q};
_ -> State1 _ -> State1
end, end,
@ -598,7 +596,7 @@ handle_info({timeout, TRef, shaper_timeout}, StateName,
State) -> State) ->
case p1_queue:out(State#state.shaped_receivers) of case p1_queue:out(State#state.shaped_receivers) of
{{value, {TRef, From, Req}}, Q} -> {{value, {TRef, From, Req}}, Q} ->
(?GEN_FSM):send_event(self(), {Req, From}), p1_fsm:send_event(self(), {Req, From}),
{next_state, StateName, {next_state, StateName,
State#state{shaped_receivers = Q}}; State#state{shaped_receivers = Q}};
{{value, _}, _} -> {{value, _}, _} ->
@ -630,7 +628,7 @@ terminate(_Reason, _StateName, State) ->
mod_bosh:close_session(State#state.sid), mod_bosh:close_session(State#state.sid),
case State#state.c2s_pid of case State#state.c2s_pid of
C2SPid when is_pid(C2SPid) -> C2SPid when is_pid(C2SPid) ->
(?GEN_FSM):send_event(C2SPid, closed); p1_fsm:send_event(C2SPid, closed);
_ -> ok _ -> ok
end, end,
bounce_receivers(State, closed), bounce_receivers(State, closed),
@ -644,7 +642,7 @@ print_state(State) -> State.
route_els(#state{el_ibuf = Buf, c2s_pid = C2SPid} = State) -> route_els(#state{el_ibuf = Buf, c2s_pid = C2SPid} = State) ->
NewBuf = p1_queue:dropwhile( NewBuf = p1_queue:dropwhile(
fun(El) -> fun(El) ->
?GEN_FSM:send_event(C2SPid, El), p1_fsm:send_event(C2SPid, El),
true true
end, Buf), end, Buf),
State#state{el_ibuf = NewBuf}. State#state{el_ibuf = NewBuf}.
@ -653,7 +651,7 @@ route_els(State, Els) ->
case State#state.c2s_pid of case State#state.c2s_pid of
C2SPid when is_pid(C2SPid) -> C2SPid when is_pid(C2SPid) ->
lists:foreach(fun (El) -> lists:foreach(fun (El) ->
(?GEN_FSM):send_event(C2SPid, El) p1_fsm:send_event(C2SPid, El)
end, end,
Els), Els),
State; State;
@ -676,7 +674,7 @@ reply(State, Body, RID, From) ->
case catch gb_trees:take_smallest(Receivers) of case catch gb_trees:take_smallest(Receivers) of
{NextRID, {From1, Req}, Receivers1} {NextRID, {From1, Req}, Receivers1}
when NextRID == RID + 1 -> when NextRID == RID + 1 ->
(?GEN_FSM):send_event(self(), {Req, From1}), p1_fsm:send_event(self(), {Req, From1}),
State2#state{receivers = Receivers1}; State2#state{receivers = Receivers1};
_ -> State2#state{receivers = Receivers} _ -> State2#state{receivers = Receivers}
end. end.
@ -715,7 +713,7 @@ do_reply(State, From, Body, RID) ->
?DEBUG("send reply:~n** RequestID: ~p~n** Reply: " ?DEBUG("send reply:~n** RequestID: ~p~n** Reply: "
"~p~n** To: ~p~n** State: ~p", "~p~n** To: ~p~n** State: ~p",
[RID, Body, From, State]), [RID, Body, From, State]),
(?GEN_FSM):reply(From, Body), p1_fsm:reply(From, Body),
Responses = gb_trees:delete_any(RID, Responses = gb_trees:delete_any(RID,
State#state.responses), State#state.responses),
Responses1 = case gb_trees:size(Responses) of Responses1 = case gb_trees:size(Responses) of
@ -1053,7 +1051,7 @@ buf_out(Buf, I, Els) ->
end. end.
cancel_timer(TRef) when is_reference(TRef) -> cancel_timer(TRef) when is_reference(TRef) ->
(?GEN_FSM):cancel_timer(TRef); p1_fsm:cancel_timer(TRef);
cancel_timer(_) -> false. cancel_timer(_) -> false.
restart_timer(TRef, Timeout, Msg) -> restart_timer(TRef, Timeout, Msg) ->

View File

@ -28,7 +28,7 @@
-author('ecestari@process-one.net'). -author('ecestari@process-one.net').
-behaviour(gen_fsm). -behaviour(p1_fsm).
-export([start/1, start_link/1, init/1, handle_event/3, -export([start/1, start_link/1, init/1, handle_event/3,
handle_sync_event/4, code_change/4, handle_info/3, handle_sync_event/4, code_change/4, handle_info/3,
@ -75,13 +75,13 @@
-export_type([ws_socket/0]). -export_type([ws_socket/0]).
start(WS) -> start(WS) ->
gen_fsm:start(?MODULE, [WS], ?FSMOPTS). p1_fsm:start(?MODULE, [WS], ?FSMOPTS).
start_link(WS) -> start_link(WS) ->
gen_fsm:start_link(?MODULE, [WS], ?FSMOPTS). p1_fsm:start_link(?MODULE, [WS], ?FSMOPTS).
send_xml({http_ws, FsmRef, _IP}, Packet) -> send_xml({http_ws, FsmRef, _IP}, Packet) ->
case catch gen_fsm:sync_send_all_state_event(FsmRef, case catch p1_fsm:sync_send_all_state_event(FsmRef,
{send_xml, Packet}, {send_xml, Packet},
15000) 15000)
of of
@ -93,7 +93,7 @@ send_xml({http_ws, FsmRef, _IP}, Packet) ->
setopts({http_ws, FsmRef, _IP}, Opts) -> setopts({http_ws, FsmRef, _IP}, Opts) ->
case lists:member({active, once}, Opts) of case lists:member({active, once}, Opts) of
true -> true ->
gen_fsm:send_all_state_event(FsmRef, p1_fsm:send_all_state_event(FsmRef,
{activate, self()}); {activate, self()});
_ -> ok _ -> ok
end. end.
@ -105,11 +105,11 @@ peername({http_ws, _FsmRef, IP}) -> {ok, IP}.
controlling_process(_Socket, _Pid) -> ok. controlling_process(_Socket, _Pid) -> ok.
become_controller(FsmRef, C2SPid) -> become_controller(FsmRef, C2SPid) ->
gen_fsm:send_all_state_event(FsmRef, p1_fsm:send_all_state_event(FsmRef,
{become_controller, C2SPid}). {become_controller, C2SPid}).
close({http_ws, FsmRef, _IP}) -> close({http_ws, FsmRef, _IP}) ->
catch gen_fsm:sync_send_all_state_event(FsmRef, close). catch p1_fsm:sync_send_all_state_event(FsmRef, close).
socket_handoff(LocalPath, Request, Socket, SockMod, Buf, Opts) -> socket_handoff(LocalPath, Request, Socket, SockMod, Buf, Opts) ->
ejabberd_websocket:socket_handoff(LocalPath, Request, Socket, SockMod, ejabberd_websocket:socket_handoff(LocalPath, Request, Socket, SockMod,

View File

@ -234,7 +234,7 @@ terminate(_Reason,
State) -> State) ->
close_stream(XMLStreamState), close_stream(XMLStreamState),
if C2SPid /= undefined -> if C2SPid /= undefined ->
gen_fsm:send_event(C2SPid, closed); p1_fsm:send_event(C2SPid, closed);
true -> ok true -> ok
end, end,
catch (State#state.sock_mod):close(State#state.socket), catch (State#state.sock_mod):close(State#state.socket),
@ -272,7 +272,7 @@ process_data([Element | Els],
element(1, Element) == xmlstreamend -> element(1, Element) == xmlstreamend ->
if C2SPid == undefined -> State; if C2SPid == undefined -> State;
true -> true ->
catch gen_fsm:send_event(C2SPid, catch p1_fsm:send_event(C2SPid,
element_wrapper(Element)), element_wrapper(Element)),
process_data(Els, State) process_data(Els, State)
end; end;

View File

@ -682,7 +682,7 @@ complete_s2s_info([Connection | T], Type, Result) ->
-spec get_s2s_state(pid()) -> [{status, open | closed | error} | {s2s_pid, pid()}]. -spec get_s2s_state(pid()) -> [{status, open | closed | error} | {s2s_pid, pid()}].
get_s2s_state(S2sPid) -> get_s2s_state(S2sPid) ->
Infos = case gen_fsm:sync_send_all_state_event(S2sPid, Infos = case p1_fsm:sync_send_all_state_event(S2sPid,
get_state_infos) get_state_infos)
of of
{state_infos, Is} -> [{status, open} | Is]; {state_infos, Is} -> [{status, open} | Is];

View File

@ -29,9 +29,7 @@
-author('alexey@process-one.net'). -author('alexey@process-one.net').
-define(GEN_FSM, p1_fsm). -behaviour(p1_fsm).
-behaviour(?GEN_FSM).
%% External exports %% External exports
-export([start/1, start_link/2, -export([start/1, start_link/2,
@ -113,11 +111,11 @@
%%% API %%% API
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
start(Host) -> start(Host) ->
(?GEN_FSM):start(ejabberd_sql, [Host], p1_fsm:start(ejabberd_sql, [Host],
fsm_limit_opts() ++ (?FSMOPTS)). fsm_limit_opts() ++ (?FSMOPTS)).
start_link(Host, StartInterval) -> start_link(Host, StartInterval) ->
(?GEN_FSM):start_link(ejabberd_sql, p1_fsm:start_link(ejabberd_sql,
[Host, StartInterval], [Host, StartInterval],
fsm_limit_opts() ++ (?FSMOPTS)). fsm_limit_opts() ++ (?FSMOPTS)).
@ -160,7 +158,7 @@ sql_call(Host, Msg) ->
case ejabberd_sql_sup:get_random_pid(Host) of case ejabberd_sql_sup:get_random_pid(Host) of
none -> {error, <<"Unknown Host">>}; none -> {error, <<"Unknown Host">>};
Pid -> Pid ->
(?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg, p1_fsm:sync_send_event(Pid,{sql_cmd, Msg,
p1_time_compat:monotonic_time(milli_seconds)}, p1_time_compat:monotonic_time(milli_seconds)},
query_timeout(Host)) query_timeout(Host))
end; end;
@ -168,7 +166,7 @@ sql_call(Host, Msg) ->
end. end.
keep_alive(Host, PID) -> keep_alive(Host, PID) ->
(?GEN_FSM):sync_send_event(PID, p1_fsm:sync_send_event(PID,
{sql_cmd, {sql_query, ?KEEPALIVE_QUERY}, {sql_cmd, {sql_query, ?KEEPALIVE_QUERY},
p1_time_compat:monotonic_time(milli_seconds)}, p1_time_compat:monotonic_time(milli_seconds)},
query_timeout(Host)). query_timeout(Host)).
@ -280,7 +278,7 @@ init([Host, StartInterval]) ->
keep_alive, [Host, self()]) keep_alive, [Host, self()])
end, end,
[DBType | _] = db_opts(Host), [DBType | _] = db_opts(Host),
(?GEN_FSM):send_event(self(), connect), p1_fsm:send_event(self(), connect),
ejabberd_sql_sup:add_pid(Host, self()), ejabberd_sql_sup:add_pid(Host, self()),
QueueType = case ejabberd_config:get_option({sql_queue_type, Host}) of QueueType = case ejabberd_config:get_option({sql_queue_type, Host}) of
undefined -> undefined ->
@ -313,7 +311,7 @@ connecting(connect, #state{host = Host} = State) ->
PendingRequests = PendingRequests =
p1_queue:dropwhile( p1_queue:dropwhile(
fun(Req) -> fun(Req) ->
?GEN_FSM:send_event(self(), Req), p1_fsm:send_event(self(), Req),
true true
end, State#state.pending_requests), end, State#state.pending_requests),
State1 = State#state{db_ref = Ref, State1 = State#state{db_ref = Ref,
@ -325,7 +323,7 @@ connecting(connect, #state{host = Host} = State) ->
"Retry after: ~p seconds", "Retry after: ~p seconds",
[State#state.db_type, Reason, [State#state.db_type, Reason,
State#state.start_interval div 1000]), State#state.start_interval div 1000]),
(?GEN_FSM):send_event_after(State#state.start_interval, p1_fsm:send_event_after(State#state.start_interval,
connect), connect),
{next_state, connecting, State} {next_state, connecting, State}
end; end;
@ -337,7 +335,7 @@ connecting(Event, State) ->
connecting({sql_cmd, {sql_query, ?KEEPALIVE_QUERY}, connecting({sql_cmd, {sql_query, ?KEEPALIVE_QUERY},
_Timestamp}, _Timestamp},
From, State) -> From, State) ->
(?GEN_FSM):reply(From, p1_fsm:reply(From,
{error, <<"SQL connection failed">>}), {error, <<"SQL connection failed">>}),
{next_state, connecting, State}; {next_state, connecting, State};
connecting({sql_cmd, Command, Timestamp} = Req, From, connecting({sql_cmd, Command, Timestamp} = Req, From,
@ -350,7 +348,7 @@ connecting({sql_cmd, Command, Timestamp} = Req, From,
catch error:full -> catch error:full ->
Q = p1_queue:dropwhile( Q = p1_queue:dropwhile(
fun({sql_cmd, _, To, _Timestamp}) -> fun({sql_cmd, _, To, _Timestamp}) ->
(?GEN_FSM):reply( p1_fsm:reply(
To, {error, <<"SQL connection failed">>}), To, {error, <<"SQL connection failed">>}),
true true
end, State#state.pending_requests), end, State#state.pending_requests),
@ -393,7 +391,7 @@ code_change(_OldVsn, StateName, State, _Extra) ->
%% monitoring the connection) %% monitoring the connection)
handle_info({'DOWN', _MonitorRef, process, _Pid, _Info}, handle_info({'DOWN', _MonitorRef, process, _Pid, _Info},
_StateName, State) -> _StateName, State) ->
(?GEN_FSM):send_event(self(), connect), p1_fsm:send_event(self(), connect),
{next_state, connecting, State}; {next_state, connecting, State};
handle_info(Info, StateName, State) -> handle_info(Info, StateName, State) ->
?WARNING_MSG("unexpected info in ~p: ~p", ?WARNING_MSG("unexpected info in ~p: ~p",
@ -734,16 +732,16 @@ sql_query_to_iolist(SQLQuery) ->
abort_on_driver_error({error, <<"query timed out">>} = abort_on_driver_error({error, <<"query timed out">>} =
Reply, Reply,
From) -> From) ->
(?GEN_FSM):reply(From, Reply), p1_fsm:reply(From, Reply),
{stop, timeout, get(?STATE_KEY)}; {stop, timeout, get(?STATE_KEY)};
abort_on_driver_error({error, abort_on_driver_error({error,
<<"Failed sending data on socket", _/binary>>} = <<"Failed sending data on socket", _/binary>>} =
Reply, Reply,
From) -> From) ->
(?GEN_FSM):reply(From, Reply), p1_fsm:reply(From, Reply),
{stop, closed, get(?STATE_KEY)}; {stop, closed, get(?STATE_KEY)};
abort_on_driver_error(Reply, From) -> abort_on_driver_error(Reply, From) ->
(?GEN_FSM):reply(From, Reply), p1_fsm:reply(From, Reply),
{next_state, session_established, get(?STATE_KEY)}. {next_state, session_established, get(?STATE_KEY)}.
%% == pure ODBC code %% == pure ODBC code

View File

@ -63,7 +63,7 @@
%%% active_bind - sent bind() request and waiting for response %%% active_bind - sent bind() request and waiting for response
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
-behaviour(gen_fsm). -behaviour(p1_fsm).
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-include("logger.hrl"). -include("logger.hrl").
@ -148,7 +148,7 @@
start_link(Name) -> start_link(Name) ->
Reg_name = misc:binary_to_atom(<<"eldap_", Reg_name = misc:binary_to_atom(<<"eldap_",
Name/binary>>), Name/binary>>),
gen_fsm:start_link({local, Reg_name}, ?MODULE, [], []). p1_fsm:start_link({local, Reg_name}, ?MODULE, [], []).
-spec start_link(binary(), [binary()], inet:port_number(), binary(), -spec start_link(binary(), [binary()], inet:port_number(), binary(),
binary(), tlsopts()) -> any(). binary(), tlsopts()) -> any().
@ -156,7 +156,7 @@ start_link(Name) ->
start_link(Name, Hosts, Port, Rootdn, Passwd, Opts) -> start_link(Name, Hosts, Port, Rootdn, Passwd, Opts) ->
Reg_name = misc:binary_to_atom(<<"eldap_", Reg_name = misc:binary_to_atom(<<"eldap_",
Name/binary>>), Name/binary>>),
gen_fsm:start_link({local, Reg_name}, ?MODULE, p1_fsm:start_link({local, Reg_name}, ?MODULE,
[Hosts, Port, Rootdn, Passwd, Opts], []). [Hosts, Port, Rootdn, Passwd, Opts], []).
-spec get_status(handle()) -> any(). -spec get_status(handle()) -> any().
@ -166,7 +166,7 @@ start_link(Name, Hosts, Port, Rootdn, Passwd, Opts) ->
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
get_status(Handle) -> get_status(Handle) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_all_state_event(Handle1, get_status). p1_fsm:sync_send_all_state_event(Handle1, get_status).
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
%%% Shutdown connection (and process) asynchronous. %%% Shutdown connection (and process) asynchronous.
@ -175,7 +175,7 @@ get_status(Handle) ->
close(Handle) -> close(Handle) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:send_all_state_event(Handle1, close). p1_fsm:send_all_state_event(Handle1, close).
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
%%% Add an entry. The entry field MUST NOT exist for the AddRequest %%% Add an entry. The entry field MUST NOT exist for the AddRequest
@ -192,7 +192,7 @@ close(Handle) ->
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
add(Handle, Entry, Attributes) -> add(Handle, Entry, Attributes) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_event(Handle1, p1_fsm:sync_send_event(Handle1,
{add, Entry, add_attrs(Attributes)}, ?CALL_TIMEOUT). {add, Entry, add_attrs(Attributes)}, ?CALL_TIMEOUT).
%%% Do sanity check ! %%% Do sanity check !
@ -216,7 +216,7 @@ add_attrs(Attrs) ->
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
delete(Handle, Entry) -> delete(Handle, Entry) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_event(Handle1, {delete, Entry}, p1_fsm:sync_send_event(Handle1, {delete, Entry},
?CALL_TIMEOUT). ?CALL_TIMEOUT).
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
@ -234,7 +234,7 @@ delete(Handle, Entry) ->
modify(Handle, Object, Mods) -> modify(Handle, Object, Mods) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_event(Handle1, {modify, Object, Mods}, p1_fsm:sync_send_event(Handle1, {modify, Object, Mods},
?CALL_TIMEOUT). ?CALL_TIMEOUT).
%%% %%%
@ -274,7 +274,7 @@ m(Operation, Type, Values) ->
modify_dn(Handle, Entry, NewRDN, DelOldRDN, NewSup) -> modify_dn(Handle, Entry, NewRDN, DelOldRDN, NewSup) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_event(Handle1, p1_fsm:sync_send_event(Handle1,
{modify_dn, Entry, NewRDN, bool_p(DelOldRDN), {modify_dn, Entry, NewRDN, bool_p(DelOldRDN),
optional(NewSup)}, optional(NewSup)},
?CALL_TIMEOUT). ?CALL_TIMEOUT).
@ -283,7 +283,7 @@ modify_dn(Handle, Entry, NewRDN, DelOldRDN, NewSup) ->
modify_passwd(Handle, DN, Passwd) -> modify_passwd(Handle, DN, Passwd) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_event(Handle1, p1_fsm:sync_send_event(Handle1,
{modify_passwd, DN, Passwd}, ?CALL_TIMEOUT). {modify_passwd, DN, Passwd}, ?CALL_TIMEOUT).
%%% -------------------------------------------------------------------- %%% --------------------------------------------------------------------
@ -298,7 +298,7 @@ modify_passwd(Handle, DN, Passwd) ->
bind(Handle, RootDN, Passwd) -> bind(Handle, RootDN, Passwd) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_event(Handle1, {bind, RootDN, Passwd}, p1_fsm:sync_send_event(Handle1, {bind, RootDN, Passwd},
?CALL_TIMEOUT). ?CALL_TIMEOUT).
%%% Sanity checks ! %%% Sanity checks !
@ -356,7 +356,7 @@ search(Handle, L) when is_list(L) ->
call_search(Handle, A) -> call_search(Handle, A) ->
Handle1 = get_handle(Handle), Handle1 = get_handle(Handle),
gen_fsm:sync_send_event(Handle1, {search, A}, p1_fsm:sync_send_event(Handle1, {search, A},
?CALL_TIMEOUT). ?CALL_TIMEOUT).
-spec parse_search_args(search_args()) -> eldap_search(). -spec parse_search_args(search_args()) -> eldap_search().
@ -637,7 +637,7 @@ active(Event, From, S) ->
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
%% Func: handle_event/3 %% Func: handle_event/3
%% Called when gen_fsm:send_all_state_event/2 is invoked. %% Called when p1_fsm:send_all_state_event/2 is invoked.
%% Returns: {next_state, NextStateName, NextStateData} | %% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} | %% {next_state, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} %% {stop, Reason, NewStateData}
@ -680,7 +680,7 @@ handle_info({Tag, _Socket, Data}, StateName, S)
case catch recvd_packet(Data, S) of case catch recvd_packet(Data, S) of
{response, Response, RequestType} -> {response, Response, RequestType} ->
NewS = case Response of NewS = case Response of
{reply, Reply, To, S1} -> gen_fsm:reply(To, Reply), S1; {reply, Reply, To, S1} -> p1_fsm:reply(To, Reply), S1;
{ok, S1} -> S1 {ok, S1} -> S1
end, end,
if StateName == active_bind andalso if StateName == active_bind andalso
@ -709,7 +709,7 @@ handle_info({timeout, Timer, {cmd_timeout, Id}},
StateName, S) -> StateName, S) ->
case cmd_timeout(Timer, Id, S) of case cmd_timeout(Timer, Id, S) of
{reply, To, Reason, NewS} -> {reply, To, Reason, NewS} ->
gen_fsm:reply(To, Reason), p1_fsm:reply(To, Reason),
{next_state, StateName, NewS}; {next_state, StateName, NewS};
{error, _Reason} -> {next_state, StateName, S} {error, _Reason} -> {next_state, StateName, S}
end; end;

View File

@ -27,7 +27,7 @@
-author('alexey@process-one.net'). -author('alexey@process-one.net').
-behaviour(gen_fsm). -behaviour(p1_fsm).
%% External exports %% External exports
-export([start_link/12, start/13, route_chan/4, -export([start_link/12, start/13, route_chan/4,
@ -91,7 +91,7 @@ start(From, Host, ServerHost, Server, Username,
start_link(From, Host, Server, Username, Encoding, Port, start_link(From, Host, Server, Username, Encoding, Port,
Password, Ident, RemoteAddr, RealName, WebircPassword, Mod) -> Password, Ident, RemoteAddr, RealName, WebircPassword, Mod) ->
gen_fsm:start_link(?MODULE, p1_fsm:start_link(?MODULE,
[From, Host, Server, Username, Encoding, Port, Password, [From, Host, Server, Username, Encoding, Port, Password,
Ident, RemoteAddr, RealName, WebircPassword, Mod], Ident, RemoteAddr, RealName, WebircPassword, Mod],
?FSMOPTS). ?FSMOPTS).
@ -109,7 +109,7 @@ start_link(From, Host, Server, Username, Encoding, Port,
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
init([From, Host, Server, Username, Encoding, Port, init([From, Host, Server, Username, Encoding, Port,
Password, Ident, RemoteAddr, RealName, WebircPassword, Mod]) -> Password, Ident, RemoteAddr, RealName, WebircPassword, Mod]) ->
gen_fsm:send_event(self(), init), p1_fsm:send_event(self(), init),
{ok, open_socket, {ok, open_socket,
#state{mod = Mod, #state{mod = Mod,
encoding = Encoding, port = Port, password = Password, encoding = Encoding, port = Port, password = Password,
@ -628,11 +628,11 @@ handle_info({tcp, _Socket, Data}, StateName,
StateData#state{inbuf = NewBuf}}; StateData#state{inbuf = NewBuf}};
handle_info({tcp_closed, _Socket}, StateName, handle_info({tcp_closed, _Socket}, StateName,
StateData) -> StateData) ->
gen_fsm:send_event(self(), closed), p1_fsm:send_event(self(), closed),
{next_state, StateName, StateData}; {next_state, StateName, StateData};
handle_info({tcp_error, _Socket, _Reason}, StateName, handle_info({tcp_error, _Socket, _Reason}, StateName,
StateData) -> StateData) ->
gen_fsm:send_event(self(), closed), p1_fsm:send_event(self(), closed),
{next_state, StateName, StateData}. {next_state, StateName, StateData}.
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------

View File

@ -668,7 +668,7 @@ iq_disco_items(_ServerHost, _Host, _From, Lang, _MaxRoomsDiscoItems, _Node, _RSM
{error, timeout | notfound}. {error, timeout | notfound}.
get_room_disco_item({Name, Host, Pid}, Query) -> get_room_disco_item({Name, Host, Pid}, Query) ->
RoomJID = jid:make(Name, Host), RoomJID = jid:make(Name, Host),
try gen_fsm:sync_send_all_state_event(Pid, Query, 100) of try p1_fsm:sync_send_all_state_event(Pid, Query, 100) of
{item, Desc} -> {item, Desc} ->
{ok, #disco_item{jid = RoomJID, name = Desc}}; {ok, #disco_item{jid = RoomJID, name = Desc}};
false -> false ->
@ -684,7 +684,7 @@ get_subscribed_rooms(ServerHost, Host, From) ->
BareFrom = jid:remove_resource(From), BareFrom = jid:remove_resource(From),
lists:flatmap( lists:flatmap(
fun({Name, _, Pid}) -> fun({Name, _, Pid}) ->
case gen_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of case p1_fsm:sync_send_all_state_event(Pid, {is_subscribed, BareFrom}) of
true -> [jid:make(Name, Host)]; true -> [jid:make(Name, Host)];
false -> [] false -> []
end; end;
@ -766,7 +766,7 @@ process_iq_register_set(ServerHost, Host, From,
broadcast_service_message(ServerHost, Host, Msg) -> broadcast_service_message(ServerHost, Host, Msg) ->
lists:foreach( lists:foreach(
fun({_, _, Pid}) -> fun({_, _, Pid}) ->
gen_fsm:send_all_state_event( p1_fsm:send_all_state_event(
Pid, {service_message, Msg}) Pid, {service_message, Msg})
end, get_online_rooms(ServerHost, Host)). end, get_online_rooms(ServerHost, Host)).

View File

@ -597,7 +597,7 @@ muc_create_room(ServerHost, {Name, Host, _}, DefRoomOpts) ->
destroy_room(Name, Service) -> destroy_room(Name, Service) ->
case mod_muc:find_online_room(Name, Service) of case mod_muc:find_online_room(Name, Service) of
{ok, Pid} -> {ok, Pid} ->
gen_fsm:send_all_state_event(Pid, destroy), p1_fsm:send_all_state_event(Pid, destroy),
ok; ok;
error -> error ->
error error
@ -716,11 +716,11 @@ get_rooms(ServerHost) ->
end, Hosts). end, Hosts).
get_room_config(Room_pid) -> get_room_config(Room_pid) ->
{ok, R} = gen_fsm:sync_send_all_state_event(Room_pid, get_config), {ok, R} = p1_fsm:sync_send_all_state_event(Room_pid, get_config),
R. R.
get_room_state(Room_pid) -> get_room_state(Room_pid) ->
{ok, R} = gen_fsm:sync_send_all_state_event(Room_pid, get_state), {ok, R} = p1_fsm:sync_send_all_state_event(Room_pid, get_state),
R. R.
%%--------------- %%---------------
@ -786,7 +786,7 @@ find_serverhost(Host, ServerHosts) ->
ServerHost. ServerHost.
act_on_room(destroy, {N, H, Pid}, SH) -> act_on_room(destroy, {N, H, Pid}, SH) ->
gen_fsm:send_all_state_event( p1_fsm:send_all_state_event(
Pid, {destroy, <<"Room destroyed by rooms_unused_destroy.">>}), Pid, {destroy, <<"Room destroyed by rooms_unused_destroy.">>}),
mod_muc:room_destroyed(H, N, Pid, SH), mod_muc:room_destroyed(H, N, Pid, SH),
mod_muc:forget_room(SH, H, N); mod_muc:forget_room(SH, H, N);
@ -888,7 +888,7 @@ change_room_option(Name, Service, OptionString, ValueString) ->
{Option, Value} = format_room_option(OptionString, ValueString), {Option, Value} = format_room_option(OptionString, ValueString),
Config = get_room_config(Pid), Config = get_room_config(Pid),
Config2 = change_option(Option, Value, Config), Config2 = change_option(Option, Value, Config),
{ok, _} = gen_fsm:sync_send_all_state_event(Pid, {change_config, Config2}), {ok, _} = p1_fsm:sync_send_all_state_event(Pid, {change_config, Config2}),
ok ok
end. end.
@ -983,7 +983,7 @@ get_room_affiliations(Name, Service) ->
case mod_muc:find_online_room(Name, Service) of case mod_muc:find_online_room(Name, Service) of
{ok, Pid} -> {ok, Pid} ->
%% Get the PID of the online room, then request its state %% Get the PID of the online room, then request its state
{ok, StateData} = gen_fsm:sync_send_all_state_event(Pid, get_state), {ok, StateData} = p1_fsm:sync_send_all_state_event(Pid, get_state),
Affiliations = ?DICT:to_list(StateData#state.affiliations), Affiliations = ?DICT:to_list(StateData#state.affiliations),
lists:map( lists:map(
fun({{Uname, Domain, _Res}, {Aff, Reason}}) when is_atom(Aff)-> fun({{Uname, Domain, _Res}, {Aff, Reason}}) when is_atom(Aff)->
@ -1012,7 +1012,7 @@ set_room_affiliation(Name, Service, JID, AffiliationString) ->
case mod_muc:find_online_room(Name, Service) of case mod_muc:find_online_room(Name, Service) of
{ok, Pid} -> {ok, Pid} ->
%% Get the PID for the online room so we can get the state of the room %% Get the PID for the online room so we can get the state of the room
{ok, StateData} = gen_fsm:sync_send_all_state_event(Pid, {process_item_change, {jid:decode(JID), affiliation, Affiliation, <<"">>}, undefined}), {ok, StateData} = p1_fsm:sync_send_all_state_event(Pid, {process_item_change, {jid:decode(JID), affiliation, Affiliation, <<"">>}, undefined}),
mod_muc:store_room(StateData#state.server_host, StateData#state.host, StateData#state.room, make_opts(StateData)), mod_muc:store_room(StateData#state.server_host, StateData#state.host, StateData#state.room, make_opts(StateData)),
ok; ok;
error -> error ->
@ -1035,7 +1035,7 @@ subscribe_room(User, Nick, Room, Nodes) ->
UserJID -> UserJID ->
case get_room_pid(Name, Host) of case get_room_pid(Name, Host) of
Pid when is_pid(Pid) -> Pid when is_pid(Pid) ->
case gen_fsm:sync_send_all_state_event( case p1_fsm:sync_send_all_state_event(
Pid, Pid,
{muc_subscribe, UserJID, Nick, NodeList}) of {muc_subscribe, UserJID, Nick, NodeList}) of
{ok, SubscribedNodes} -> {ok, SubscribedNodes} ->
@ -1062,7 +1062,7 @@ unsubscribe_room(User, Room) ->
UserJID -> UserJID ->
case get_room_pid(Name, Host) of case get_room_pid(Name, Host) of
Pid when is_pid(Pid) -> Pid when is_pid(Pid) ->
case gen_fsm:sync_send_all_state_event( case p1_fsm:sync_send_all_state_event(
Pid, Pid,
{muc_unsubscribe, UserJID}) of {muc_unsubscribe, UserJID}) of
ok -> ok ->
@ -1085,7 +1085,7 @@ unsubscribe_room(User, Room) ->
get_subscribers(Name, Host) -> get_subscribers(Name, Host) ->
case get_room_pid(Name, Host) of case get_room_pid(Name, Host) of
Pid when is_pid(Pid) -> Pid when is_pid(Pid) ->
{ok, JIDList} = gen_fsm:sync_send_all_state_event(Pid, get_subscribers), {ok, JIDList} = p1_fsm:sync_send_all_state_event(Pid, get_subscribers),
[jid:encode(jid:remove_resource(J)) || J <- JIDList]; [jid:encode(jid:remove_resource(J)) || J <- JIDList];
_ -> _ ->
throw({error, "The room does not exist"}) throw({error, "The room does not exist"})

View File

@ -1142,7 +1142,7 @@ get_room_state(RoomName, MucService) ->
-spec get_room_state(pid()) -> mod_muc_room:state(). -spec get_room_state(pid()) -> mod_muc_room:state().
get_room_state(RoomPid) -> get_room_state(RoomPid) ->
{ok, R} = gen_fsm:sync_send_all_state_event(RoomPid, {ok, R} = p1_fsm:sync_send_all_state_event(RoomPid,
get_state), get_state),
R. R.

View File

@ -27,7 +27,7 @@
-author('alexey@process-one.net'). -author('alexey@process-one.net').
-behaviour(gen_fsm). -behaviour(p1_fsm).
%% External exports %% External exports
-export([start_link/10, -export([start_link/10,
@ -94,23 +94,23 @@
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
start(Host, ServerHost, Access, Room, HistorySize, RoomShaper, start(Host, ServerHost, Access, Room, HistorySize, RoomShaper,
Creator, Nick, DefRoomOpts, QueueType) -> Creator, Nick, DefRoomOpts, QueueType) ->
gen_fsm:start(?MODULE, [Host, ServerHost, Access, Room, HistorySize, p1_fsm:start(?MODULE, [Host, ServerHost, Access, Room, HistorySize,
RoomShaper, Creator, Nick, DefRoomOpts, QueueType], RoomShaper, Creator, Nick, DefRoomOpts, QueueType],
?FSMOPTS). ?FSMOPTS).
start(Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, QueueType) -> start(Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, QueueType) ->
gen_fsm:start(?MODULE, [Host, ServerHost, Access, Room, HistorySize, p1_fsm:start(?MODULE, [Host, ServerHost, Access, Room, HistorySize,
RoomShaper, Opts, QueueType], RoomShaper, Opts, QueueType],
?FSMOPTS). ?FSMOPTS).
start_link(Host, ServerHost, Access, Room, HistorySize, RoomShaper, start_link(Host, ServerHost, Access, Room, HistorySize, RoomShaper,
Creator, Nick, DefRoomOpts, QueueType) -> Creator, Nick, DefRoomOpts, QueueType) ->
gen_fsm:start_link(?MODULE, [Host, ServerHost, Access, Room, HistorySize, p1_fsm:start_link(?MODULE, [Host, ServerHost, Access, Room, HistorySize,
RoomShaper, Creator, Nick, DefRoomOpts, QueueType], RoomShaper, Creator, Nick, DefRoomOpts, QueueType],
?FSMOPTS). ?FSMOPTS).
start_link(Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, QueueType) -> start_link(Host, ServerHost, Access, Room, HistorySize, RoomShaper, Opts, QueueType) ->
gen_fsm:start_link(?MODULE, [Host, ServerHost, Access, Room, HistorySize, p1_fsm:start_link(?MODULE, [Host, ServerHost, Access, Room, HistorySize,
RoomShaper, Opts, QueueType], RoomShaper, Opts, QueueType],
?FSMOPTS). ?FSMOPTS).
@ -703,7 +703,7 @@ terminate(Reason, _StateName, StateData) ->
-spec route(pid(), stanza()) -> ok. -spec route(pid(), stanza()) -> ok.
route(Pid, Packet) -> route(Pid, Packet) ->
#jid{lresource = Nick} = xmpp:get_to(Packet), #jid{lresource = Nick} = xmpp:get_to(Packet),
gen_fsm:send_event(Pid, {route, Nick, Packet}). p1_fsm:send_event(Pid, {route, Nick, Packet}).
-spec process_groupchat_message(message(), state()) -> fsm_next(). -spec process_groupchat_message(message(), state()) -> fsm_next().
process_groupchat_message(#message{from = From, lang = Lang} = Packet, StateData) -> process_groupchat_message(#message{from = From, lang = Lang} = Packet, StateData) ->

View File

@ -26,7 +26,7 @@
-author('xram@jabber.ru'). -author('xram@jabber.ru').
-behaviour(gen_fsm). -behaviour(p1_fsm).
%% gen_fsm callbacks. %% gen_fsm callbacks.
-export([init/1, handle_event/3, handle_sync_event/4, -export([init/1, handle_event/3, handle_sync_event/4,
@ -75,7 +75,7 @@ start({gen_tcp, Socket}, Opts1) ->
[Socket, Host, Opts]). [Socket, Host, Opts]).
start_link(Socket, Host, Opts) -> start_link(Socket, Host, Opts) ->
gen_fsm:start_link(?MODULE, [Socket, Host, Opts], []). p1_fsm:start_link(?MODULE, [Socket, Host, Opts], []).
init([Socket, Host, Opts]) -> init([Socket, Host, Opts]) ->
process_flag(trap_exit, true), process_flag(trap_exit, true),
@ -106,9 +106,9 @@ socket_type() -> raw.
stop(StreamPid) -> StreamPid ! stop. stop(StreamPid) -> StreamPid ! stop.
activate({P1, J1}, {P2, J2}) -> activate({P1, J1}, {P2, J2}) ->
case catch {gen_fsm:sync_send_all_state_event(P1, case catch {p1_fsm:sync_send_all_state_event(P1,
get_socket), get_socket),
gen_fsm:sync_send_all_state_event(P2, get_socket)} p1_fsm:sync_send_all_state_event(P2, get_socket)}
of of
{S1, S2} when is_port(S1), is_port(S2) -> {S1, S2} when is_port(S1), is_port(S2) ->
P1 ! {activate, P2, S2, J1, J2}, P1 ! {activate, P2, S2, J1, J2},
@ -197,7 +197,7 @@ handle_info({tcp, _S, Data}, StateName, StateData)
when StateName /= wait_for_activation -> when StateName /= wait_for_activation ->
erlang:cancel_timer(StateData#state.timer), erlang:cancel_timer(StateData#state.timer),
TRef = erlang:send_after(?WAIT_TIMEOUT, self(), stop), TRef = erlang:send_after(?WAIT_TIMEOUT, self(), stop),
gen_fsm:send_event(self(), Data), p1_fsm:send_event(self(), Data),
{next_state, StateName, StateData#state{timer = TRef}}; {next_state, StateName, StateData#state{timer = TRef}};
%% Activation message. %% Activation message.
handle_info({activate, PeerPid, PeerSocket, IJid, TJid}, handle_info({activate, PeerPid, PeerSocket, IJid, TJid},

View File

@ -27,8 +27,7 @@
-ifndef(SIP). -ifndef(SIP).
-export([]). -export([]).
-else. -else.
-define(GEN_FSM, p1_fsm). -behaviour(p1_fsm).
-behaviour(?GEN_FSM).
%% API %% API
-export([start/2, start_link/2, route/3, route/4]). -export([start/2, start_link/2, route/3, route/4]).
@ -58,10 +57,10 @@ start(LServer, Opts) ->
supervisor:start_child(mod_sip_proxy_sup, [LServer, Opts]). supervisor:start_child(mod_sip_proxy_sup, [LServer, Opts]).
start_link(LServer, Opts) -> start_link(LServer, Opts) ->
?GEN_FSM:start_link(?MODULE, [LServer, Opts], []). p1_fsm:start_link(?MODULE, [LServer, Opts], []).
route(SIPMsg, _SIPSock, TrID, Pid) -> route(SIPMsg, _SIPSock, TrID, Pid) ->
?GEN_FSM:send_event(Pid, {SIPMsg, TrID}). p1_fsm:send_event(Pid, {SIPMsg, TrID}).
route(#sip{hdrs = Hdrs} = Req, LServer, Opts) -> route(#sip{hdrs = Hdrs} = Req, LServer, Opts) ->
case proplists:get_bool(authenticated, Opts) of case proplists:get_bool(authenticated, Opts) of