From 92532a0d66763e213e88c5c333dc6ead3a7ec3b5 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Sat, 5 Aug 2017 20:58:21 +0300 Subject: [PATCH] Replace gen_fsm with p1_fsm to avoid warnings in OTP20+ --- src/ejabberd_bosh.erl | 38 ++++++++++++++++++-------------------- src/ejabberd_http_ws.erl | 14 +++++++------- src/ejabberd_receiver.erl | 4 ++-- src/ejabberd_s2s.erl | 2 +- src/ejabberd_sql.erl | 30 ++++++++++++++---------------- src/eldap.erl | 30 +++++++++++++++--------------- src/mod_irc_connection.erl | 10 +++++----- src/mod_muc.erl | 6 +++--- src/mod_muc_admin.erl | 20 ++++++++++---------- src/mod_muc_log.erl | 2 +- src/mod_muc_room.erl | 12 ++++++------ src/mod_proxy65_stream.erl | 10 +++++----- src/mod_sip_proxy.erl | 7 +++---- 13 files changed, 90 insertions(+), 95 deletions(-) diff --git a/src/ejabberd_bosh.erl b/src/ejabberd_bosh.erl index 0755067e7..1df6681ff 100644 --- a/src/ejabberd_bosh.erl +++ b/src/ejabberd_bosh.erl @@ -27,9 +27,7 @@ -protocol({xep, 124, '1.11'}). -protocol({xep, 206, '1.4'}). --define(GEN_FSM, p1_fsm). - --behaviour(?GEN_FSM). +-behaviour(p1_fsm). %% API -export([start/2, start/3, start_link/3]). @@ -137,18 +135,18 @@ start(#body{attrs = Attrs} = Body, IP, SID) -> end. start(StateName, State) -> - (?GEN_FSM):start_link(?MODULE, [StateName, State], + p1_fsm:start_link(?MODULE, [StateName, State], ?FSMOPTS). start_link(Body, IP, SID) -> - (?GEN_FSM):start_link(?MODULE, [Body, IP, SID], + p1_fsm:start_link(?MODULE, [Body, IP, SID], ?FSMOPTS). send({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_TIMEOUT) of @@ -160,12 +158,12 @@ send_xml({http_bind, FsmRef, _IP}, Packet) -> setopts({http_bind, FsmRef, _IP}, Opts) -> case lists:member({active, once}, Opts) of true -> - (?GEN_FSM):send_all_state_event(FsmRef, + p1_fsm:send_all_state_event(FsmRef, {activate, self()}); _ -> case lists:member({active, false}, Opts) of true -> - case catch (?GEN_FSM):sync_send_all_state_event(FsmRef, + case catch p1_fsm:sync_send_all_state_event(FsmRef, deactivate_socket) of {'EXIT', _} -> {error, einval}; @@ -181,7 +179,7 @@ custom_receiver({http_bind, FsmRef, _IP}) -> {receiver, ?MODULE, FsmRef}. become_controller(FsmRef, C2SPid) -> - (?GEN_FSM):send_all_state_event(FsmRef, + p1_fsm:send_all_state_event(FsmRef, {become_controller, 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. change_shaper({http_bind, FsmRef, _IP}, Shaper) -> - (?GEN_FSM):send_all_state_event(FsmRef, + p1_fsm:send_all_state_event(FsmRef, {change_shaper, Shaper}). monitor({http_bind, FsmRef, _IP}) -> erlang:monitor(process, FsmRef). close({http_bind, FsmRef, _IP}) -> - catch (?GEN_FSM):sync_send_all_state_event(FsmRef, + catch p1_fsm:sync_send_all_state_event(FsmRef, close). sockname(_Socket) -> {ok, {{0, 0, 0, 0}, 0}}. @@ -269,7 +267,7 @@ process_request(Data, IP, Type) -> end. 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) of #body{} = Resp -> bosh_response(Resp, Type); @@ -571,7 +569,7 @@ handle_sync_event({send_xml, El}, _From, StateName, of {{value, {TRef, From, Body}}, Q} -> cancel_timer(TRef), - (?GEN_FSM):send_event(self(), {Body, From}), + p1_fsm:send_event(self(), {Body, From}), State1#state{shaped_receivers = Q}; _ -> State1 end, @@ -598,7 +596,7 @@ handle_info({timeout, TRef, shaper_timeout}, StateName, State) -> case p1_queue:out(State#state.shaped_receivers) of {{value, {TRef, From, Req}}, Q} -> - (?GEN_FSM):send_event(self(), {Req, From}), + p1_fsm:send_event(self(), {Req, From}), {next_state, StateName, State#state{shaped_receivers = Q}}; {{value, _}, _} -> @@ -630,7 +628,7 @@ terminate(_Reason, _StateName, State) -> mod_bosh:close_session(State#state.sid), case State#state.c2s_pid of C2SPid when is_pid(C2SPid) -> - (?GEN_FSM):send_event(C2SPid, closed); + p1_fsm:send_event(C2SPid, closed); _ -> ok end, bounce_receivers(State, closed), @@ -644,7 +642,7 @@ print_state(State) -> State. route_els(#state{el_ibuf = Buf, c2s_pid = C2SPid} = State) -> NewBuf = p1_queue:dropwhile( fun(El) -> - ?GEN_FSM:send_event(C2SPid, El), + p1_fsm:send_event(C2SPid, El), true end, Buf), State#state{el_ibuf = NewBuf}. @@ -653,7 +651,7 @@ route_els(State, Els) -> case State#state.c2s_pid of C2SPid when is_pid(C2SPid) -> lists:foreach(fun (El) -> - (?GEN_FSM):send_event(C2SPid, El) + p1_fsm:send_event(C2SPid, El) end, Els), State; @@ -676,7 +674,7 @@ reply(State, Body, RID, From) -> case catch gb_trees:take_smallest(Receivers) of {NextRID, {From1, Req}, Receivers1} 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 = Receivers} end. @@ -715,7 +713,7 @@ do_reply(State, From, Body, RID) -> ?DEBUG("send reply:~n** RequestID: ~p~n** Reply: " "~p~n** To: ~p~n** State: ~p", [RID, Body, From, State]), - (?GEN_FSM):reply(From, Body), + p1_fsm:reply(From, Body), Responses = gb_trees:delete_any(RID, State#state.responses), Responses1 = case gb_trees:size(Responses) of @@ -1053,7 +1051,7 @@ buf_out(Buf, I, Els) -> end. cancel_timer(TRef) when is_reference(TRef) -> - (?GEN_FSM):cancel_timer(TRef); + p1_fsm:cancel_timer(TRef); cancel_timer(_) -> false. restart_timer(TRef, Timeout, Msg) -> diff --git a/src/ejabberd_http_ws.erl b/src/ejabberd_http_ws.erl index 2c44d6552..f9f7b07e9 100644 --- a/src/ejabberd_http_ws.erl +++ b/src/ejabberd_http_ws.erl @@ -28,7 +28,7 @@ -author('ecestari@process-one.net'). --behaviour(gen_fsm). +-behaviour(p1_fsm). -export([start/1, start_link/1, init/1, handle_event/3, handle_sync_event/4, code_change/4, handle_info/3, @@ -75,13 +75,13 @@ -export_type([ws_socket/0]). start(WS) -> - gen_fsm:start(?MODULE, [WS], ?FSMOPTS). + p1_fsm:start(?MODULE, [WS], ?FSMOPTS). start_link(WS) -> - gen_fsm:start_link(?MODULE, [WS], ?FSMOPTS). + p1_fsm:start_link(?MODULE, [WS], ?FSMOPTS). 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}, 15000) of @@ -93,7 +93,7 @@ send_xml({http_ws, FsmRef, _IP}, Packet) -> setopts({http_ws, FsmRef, _IP}, Opts) -> case lists:member({active, once}, Opts) of true -> - gen_fsm:send_all_state_event(FsmRef, + p1_fsm:send_all_state_event(FsmRef, {activate, self()}); _ -> ok end. @@ -105,11 +105,11 @@ peername({http_ws, _FsmRef, IP}) -> {ok, IP}. controlling_process(_Socket, _Pid) -> ok. become_controller(FsmRef, C2SPid) -> - gen_fsm:send_all_state_event(FsmRef, + p1_fsm:send_all_state_event(FsmRef, {become_controller, C2SPid}). 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) -> ejabberd_websocket:socket_handoff(LocalPath, Request, Socket, SockMod, diff --git a/src/ejabberd_receiver.erl b/src/ejabberd_receiver.erl index 44c29680c..52077ac3c 100644 --- a/src/ejabberd_receiver.erl +++ b/src/ejabberd_receiver.erl @@ -234,7 +234,7 @@ terminate(_Reason, State) -> close_stream(XMLStreamState), if C2SPid /= undefined -> - gen_fsm:send_event(C2SPid, closed); + p1_fsm:send_event(C2SPid, closed); true -> ok end, catch (State#state.sock_mod):close(State#state.socket), @@ -272,7 +272,7 @@ process_data([Element | Els], element(1, Element) == xmlstreamend -> if C2SPid == undefined -> State; true -> - catch gen_fsm:send_event(C2SPid, + catch p1_fsm:send_event(C2SPid, element_wrapper(Element)), process_data(Els, State) end; diff --git a/src/ejabberd_s2s.erl b/src/ejabberd_s2s.erl index a0e9411cf..c7f9b6684 100644 --- a/src/ejabberd_s2s.erl +++ b/src/ejabberd_s2s.erl @@ -682,7 +682,7 @@ complete_s2s_info([Connection | T], Type, Result) -> -spec get_s2s_state(pid()) -> [{status, open | closed | error} | {s2s_pid, pid()}]. 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) of {state_infos, Is} -> [{status, open} | Is]; diff --git a/src/ejabberd_sql.erl b/src/ejabberd_sql.erl index 35d970291..cae41da6c 100644 --- a/src/ejabberd_sql.erl +++ b/src/ejabberd_sql.erl @@ -29,9 +29,7 @@ -author('alexey@process-one.net'). --define(GEN_FSM, p1_fsm). - --behaviour(?GEN_FSM). +-behaviour(p1_fsm). %% External exports -export([start/1, start_link/2, @@ -113,11 +111,11 @@ %%% API %%%---------------------------------------------------------------------- start(Host) -> - (?GEN_FSM):start(ejabberd_sql, [Host], + p1_fsm:start(ejabberd_sql, [Host], fsm_limit_opts() ++ (?FSMOPTS)). start_link(Host, StartInterval) -> - (?GEN_FSM):start_link(ejabberd_sql, + p1_fsm:start_link(ejabberd_sql, [Host, StartInterval], fsm_limit_opts() ++ (?FSMOPTS)). @@ -160,7 +158,7 @@ sql_call(Host, Msg) -> case ejabberd_sql_sup:get_random_pid(Host) of none -> {error, <<"Unknown Host">>}; 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)}, query_timeout(Host)) end; @@ -168,7 +166,7 @@ sql_call(Host, Msg) -> end. keep_alive(Host, PID) -> - (?GEN_FSM):sync_send_event(PID, + p1_fsm:sync_send_event(PID, {sql_cmd, {sql_query, ?KEEPALIVE_QUERY}, p1_time_compat:monotonic_time(milli_seconds)}, query_timeout(Host)). @@ -280,7 +278,7 @@ init([Host, StartInterval]) -> keep_alive, [Host, self()]) end, [DBType | _] = db_opts(Host), - (?GEN_FSM):send_event(self(), connect), + p1_fsm:send_event(self(), connect), ejabberd_sql_sup:add_pid(Host, self()), QueueType = case ejabberd_config:get_option({sql_queue_type, Host}) of undefined -> @@ -313,7 +311,7 @@ connecting(connect, #state{host = Host} = State) -> PendingRequests = p1_queue:dropwhile( fun(Req) -> - ?GEN_FSM:send_event(self(), Req), + p1_fsm:send_event(self(), Req), true end, State#state.pending_requests), State1 = State#state{db_ref = Ref, @@ -325,7 +323,7 @@ connecting(connect, #state{host = Host} = State) -> "Retry after: ~p seconds", [State#state.db_type, Reason, 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), {next_state, connecting, State} end; @@ -337,7 +335,7 @@ connecting(Event, State) -> connecting({sql_cmd, {sql_query, ?KEEPALIVE_QUERY}, _Timestamp}, From, State) -> - (?GEN_FSM):reply(From, + p1_fsm:reply(From, {error, <<"SQL connection failed">>}), {next_state, connecting, State}; connecting({sql_cmd, Command, Timestamp} = Req, From, @@ -350,7 +348,7 @@ connecting({sql_cmd, Command, Timestamp} = Req, From, catch error:full -> Q = p1_queue:dropwhile( fun({sql_cmd, _, To, _Timestamp}) -> - (?GEN_FSM):reply( + p1_fsm:reply( To, {error, <<"SQL connection failed">>}), true end, State#state.pending_requests), @@ -393,7 +391,7 @@ code_change(_OldVsn, StateName, State, _Extra) -> %% monitoring the connection) handle_info({'DOWN', _MonitorRef, process, _Pid, _Info}, _StateName, State) -> - (?GEN_FSM):send_event(self(), connect), + p1_fsm:send_event(self(), connect), {next_state, connecting, State}; handle_info(Info, StateName, State) -> ?WARNING_MSG("unexpected info in ~p: ~p", @@ -734,16 +732,16 @@ sql_query_to_iolist(SQLQuery) -> abort_on_driver_error({error, <<"query timed out">>} = Reply, From) -> - (?GEN_FSM):reply(From, Reply), + p1_fsm:reply(From, Reply), {stop, timeout, get(?STATE_KEY)}; abort_on_driver_error({error, <<"Failed sending data on socket", _/binary>>} = Reply, From) -> - (?GEN_FSM):reply(From, Reply), + p1_fsm:reply(From, Reply), {stop, closed, get(?STATE_KEY)}; abort_on_driver_error(Reply, From) -> - (?GEN_FSM):reply(From, Reply), + p1_fsm:reply(From, Reply), {next_state, session_established, get(?STATE_KEY)}. %% == pure ODBC code diff --git a/src/eldap.erl b/src/eldap.erl index f47550353..8e6b710b1 100644 --- a/src/eldap.erl +++ b/src/eldap.erl @@ -63,7 +63,7 @@ %%% active_bind - sent bind() request and waiting for response %%%---------------------------------------------------------------------- --behaviour(gen_fsm). +-behaviour(p1_fsm). -include("ejabberd.hrl"). -include("logger.hrl"). @@ -148,7 +148,7 @@ start_link(Name) -> Reg_name = misc:binary_to_atom(<<"eldap_", 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(), binary(), tlsopts()) -> any(). @@ -156,7 +156,7 @@ start_link(Name) -> start_link(Name, Hosts, Port, Rootdn, Passwd, Opts) -> Reg_name = misc:binary_to_atom(<<"eldap_", Name/binary>>), - gen_fsm:start_link({local, Reg_name}, ?MODULE, + p1_fsm:start_link({local, Reg_name}, ?MODULE, [Hosts, Port, Rootdn, Passwd, Opts], []). -spec get_status(handle()) -> any(). @@ -166,7 +166,7 @@ start_link(Name, Hosts, Port, Rootdn, Passwd, Opts) -> %%% -------------------------------------------------------------------- get_status(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. @@ -175,7 +175,7 @@ get_status(Handle) -> close(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 @@ -192,7 +192,7 @@ close(Handle) -> %%% -------------------------------------------------------------------- add(Handle, Entry, Attributes) -> Handle1 = get_handle(Handle), - gen_fsm:sync_send_event(Handle1, + p1_fsm:sync_send_event(Handle1, {add, Entry, add_attrs(Attributes)}, ?CALL_TIMEOUT). %%% Do sanity check ! @@ -216,7 +216,7 @@ add_attrs(Attrs) -> %%% -------------------------------------------------------------------- delete(Handle, Entry) -> Handle1 = get_handle(Handle), - gen_fsm:sync_send_event(Handle1, {delete, Entry}, + p1_fsm:sync_send_event(Handle1, {delete, Entry}, ?CALL_TIMEOUT). %%% -------------------------------------------------------------------- @@ -234,7 +234,7 @@ delete(Handle, Entry) -> modify(Handle, Object, Mods) -> Handle1 = get_handle(Handle), - gen_fsm:sync_send_event(Handle1, {modify, Object, Mods}, + p1_fsm:sync_send_event(Handle1, {modify, Object, Mods}, ?CALL_TIMEOUT). %%% @@ -274,7 +274,7 @@ m(Operation, Type, Values) -> modify_dn(Handle, Entry, NewRDN, DelOldRDN, NewSup) -> Handle1 = get_handle(Handle), - gen_fsm:sync_send_event(Handle1, + p1_fsm:sync_send_event(Handle1, {modify_dn, Entry, NewRDN, bool_p(DelOldRDN), optional(NewSup)}, ?CALL_TIMEOUT). @@ -283,7 +283,7 @@ modify_dn(Handle, Entry, NewRDN, DelOldRDN, NewSup) -> modify_passwd(Handle, DN, Passwd) -> Handle1 = get_handle(Handle), - gen_fsm:sync_send_event(Handle1, + p1_fsm:sync_send_event(Handle1, {modify_passwd, DN, Passwd}, ?CALL_TIMEOUT). %%% -------------------------------------------------------------------- @@ -298,7 +298,7 @@ modify_passwd(Handle, DN, Passwd) -> bind(Handle, RootDN, Passwd) -> Handle1 = get_handle(Handle), - gen_fsm:sync_send_event(Handle1, {bind, RootDN, Passwd}, + p1_fsm:sync_send_event(Handle1, {bind, RootDN, Passwd}, ?CALL_TIMEOUT). %%% Sanity checks ! @@ -356,7 +356,7 @@ search(Handle, L) when is_list(L) -> call_search(Handle, A) -> Handle1 = get_handle(Handle), - gen_fsm:sync_send_event(Handle1, {search, A}, + p1_fsm:sync_send_event(Handle1, {search, A}, ?CALL_TIMEOUT). -spec parse_search_args(search_args()) -> eldap_search(). @@ -637,7 +637,7 @@ active(Event, From, S) -> %%---------------------------------------------------------------------- %% 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} | %% {next_state, NextStateName, NextStateData, Timeout} | %% {stop, Reason, NewStateData} @@ -680,7 +680,7 @@ handle_info({Tag, _Socket, Data}, StateName, S) case catch recvd_packet(Data, S) of {response, Response, RequestType} -> 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 end, if StateName == active_bind andalso @@ -709,7 +709,7 @@ handle_info({timeout, Timer, {cmd_timeout, Id}}, StateName, S) -> case cmd_timeout(Timer, Id, S) of {reply, To, Reason, NewS} -> - gen_fsm:reply(To, Reason), + p1_fsm:reply(To, Reason), {next_state, StateName, NewS}; {error, _Reason} -> {next_state, StateName, S} end; diff --git a/src/mod_irc_connection.erl b/src/mod_irc_connection.erl index 1e90c4005..b7b2f8e1d 100644 --- a/src/mod_irc_connection.erl +++ b/src/mod_irc_connection.erl @@ -27,7 +27,7 @@ -author('alexey@process-one.net'). --behaviour(gen_fsm). +-behaviour(p1_fsm). %% External exports -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, Password, Ident, RemoteAddr, RealName, WebircPassword, Mod) -> - gen_fsm:start_link(?MODULE, + p1_fsm:start_link(?MODULE, [From, Host, Server, Username, Encoding, Port, Password, Ident, RemoteAddr, RealName, WebircPassword, Mod], ?FSMOPTS). @@ -109,7 +109,7 @@ start_link(From, Host, Server, Username, Encoding, Port, %%---------------------------------------------------------------------- init([From, Host, Server, Username, Encoding, Port, Password, Ident, RemoteAddr, RealName, WebircPassword, Mod]) -> - gen_fsm:send_event(self(), init), + p1_fsm:send_event(self(), init), {ok, open_socket, #state{mod = Mod, encoding = Encoding, port = Port, password = Password, @@ -628,11 +628,11 @@ handle_info({tcp, _Socket, Data}, StateName, StateData#state{inbuf = NewBuf}}; handle_info({tcp_closed, _Socket}, StateName, StateData) -> - gen_fsm:send_event(self(), closed), + p1_fsm:send_event(self(), closed), {next_state, StateName, StateData}; handle_info({tcp_error, _Socket, _Reason}, StateName, StateData) -> - gen_fsm:send_event(self(), closed), + p1_fsm:send_event(self(), closed), {next_state, StateName, StateData}. %%---------------------------------------------------------------------- diff --git a/src/mod_muc.erl b/src/mod_muc.erl index 8b6d7b8b9..2d87dd1d5 100644 --- a/src/mod_muc.erl +++ b/src/mod_muc.erl @@ -668,7 +668,7 @@ iq_disco_items(_ServerHost, _Host, _From, Lang, _MaxRoomsDiscoItems, _Node, _RSM {error, timeout | notfound}. get_room_disco_item({Name, Host, Pid}, Query) -> 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} -> {ok, #disco_item{jid = RoomJID, name = Desc}}; false -> @@ -684,7 +684,7 @@ get_subscribed_rooms(ServerHost, Host, From) -> BareFrom = jid:remove_resource(From), lists:flatmap( 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)]; false -> [] end; @@ -766,7 +766,7 @@ process_iq_register_set(ServerHost, Host, From, broadcast_service_message(ServerHost, Host, Msg) -> lists:foreach( fun({_, _, Pid}) -> - gen_fsm:send_all_state_event( + p1_fsm:send_all_state_event( Pid, {service_message, Msg}) end, get_online_rooms(ServerHost, Host)). diff --git a/src/mod_muc_admin.erl b/src/mod_muc_admin.erl index 2d1e66ba5..332c83b55 100644 --- a/src/mod_muc_admin.erl +++ b/src/mod_muc_admin.erl @@ -597,7 +597,7 @@ muc_create_room(ServerHost, {Name, Host, _}, DefRoomOpts) -> destroy_room(Name, Service) -> case mod_muc:find_online_room(Name, Service) of {ok, Pid} -> - gen_fsm:send_all_state_event(Pid, destroy), + p1_fsm:send_all_state_event(Pid, destroy), ok; error -> error @@ -716,11 +716,11 @@ get_rooms(ServerHost) -> end, Hosts). 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. 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. %%--------------- @@ -786,7 +786,7 @@ find_serverhost(Host, ServerHosts) -> ServerHost. 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.">>}), mod_muc:room_destroyed(H, N, Pid, SH), 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), Config = get_room_config(Pid), 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 end. @@ -983,7 +983,7 @@ get_room_affiliations(Name, Service) -> case mod_muc:find_online_room(Name, Service) of {ok, Pid} -> %% 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), lists:map( 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 {ok, Pid} -> %% 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)), ok; error -> @@ -1035,7 +1035,7 @@ subscribe_room(User, Nick, Room, Nodes) -> UserJID -> case get_room_pid(Name, Host) of Pid when is_pid(Pid) -> - case gen_fsm:sync_send_all_state_event( + case p1_fsm:sync_send_all_state_event( Pid, {muc_subscribe, UserJID, Nick, NodeList}) of {ok, SubscribedNodes} -> @@ -1062,7 +1062,7 @@ unsubscribe_room(User, Room) -> UserJID -> case get_room_pid(Name, Host) of Pid when is_pid(Pid) -> - case gen_fsm:sync_send_all_state_event( + case p1_fsm:sync_send_all_state_event( Pid, {muc_unsubscribe, UserJID}) of ok -> @@ -1085,7 +1085,7 @@ unsubscribe_room(User, Room) -> get_subscribers(Name, Host) -> case get_room_pid(Name, Host) of 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]; _ -> throw({error, "The room does not exist"}) diff --git a/src/mod_muc_log.erl b/src/mod_muc_log.erl index 3d4c87c0f..61101d1c2 100644 --- a/src/mod_muc_log.erl +++ b/src/mod_muc_log.erl @@ -1142,7 +1142,7 @@ get_room_state(RoomName, MucService) -> -spec get_room_state(pid()) -> mod_muc_room:state(). 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), R. diff --git a/src/mod_muc_room.erl b/src/mod_muc_room.erl index 31dbbbfa7..2a1ca6011 100644 --- a/src/mod_muc_room.erl +++ b/src/mod_muc_room.erl @@ -27,7 +27,7 @@ -author('alexey@process-one.net'). --behaviour(gen_fsm). +-behaviour(p1_fsm). %% External exports -export([start_link/10, @@ -94,23 +94,23 @@ %%%---------------------------------------------------------------------- start(Host, ServerHost, Access, Room, HistorySize, RoomShaper, 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], ?FSMOPTS). 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], ?FSMOPTS). start_link(Host, ServerHost, Access, Room, HistorySize, RoomShaper, 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], ?FSMOPTS). 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], ?FSMOPTS). @@ -703,7 +703,7 @@ terminate(Reason, _StateName, StateData) -> -spec route(pid(), stanza()) -> ok. route(Pid, 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(). process_groupchat_message(#message{from = From, lang = Lang} = Packet, StateData) -> diff --git a/src/mod_proxy65_stream.erl b/src/mod_proxy65_stream.erl index 899b66727..1fa6ff804 100644 --- a/src/mod_proxy65_stream.erl +++ b/src/mod_proxy65_stream.erl @@ -26,7 +26,7 @@ -author('xram@jabber.ru'). --behaviour(gen_fsm). +-behaviour(p1_fsm). %% gen_fsm callbacks. -export([init/1, handle_event/3, handle_sync_event/4, @@ -75,7 +75,7 @@ start({gen_tcp, Socket}, Opts1) -> [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]) -> process_flag(trap_exit, true), @@ -106,9 +106,9 @@ socket_type() -> raw. stop(StreamPid) -> StreamPid ! stop. 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), - gen_fsm:sync_send_all_state_event(P2, get_socket)} + p1_fsm:sync_send_all_state_event(P2, get_socket)} of {S1, S2} when is_port(S1), is_port(S2) -> P1 ! {activate, P2, S2, J1, J2}, @@ -197,7 +197,7 @@ handle_info({tcp, _S, Data}, StateName, StateData) when StateName /= wait_for_activation -> erlang:cancel_timer(StateData#state.timer), 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}}; %% Activation message. handle_info({activate, PeerPid, PeerSocket, IJid, TJid}, diff --git a/src/mod_sip_proxy.erl b/src/mod_sip_proxy.erl index 19a02e8e4..25f035377 100644 --- a/src/mod_sip_proxy.erl +++ b/src/mod_sip_proxy.erl @@ -27,8 +27,7 @@ -ifndef(SIP). -export([]). -else. --define(GEN_FSM, p1_fsm). --behaviour(?GEN_FSM). +-behaviour(p1_fsm). %% API -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]). start_link(LServer, Opts) -> - ?GEN_FSM:start_link(?MODULE, [LServer, Opts], []). + p1_fsm:start_link(?MODULE, [LServer, Opts], []). 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) -> case proplists:get_bool(authenticated, Opts) of