%% Returns: {ok, StateName, StateData} |
%% {ok, StateName, StateData, Timeout} |
%% ignore |
-%% {stop, StopReason}
+%% {stop, StopReason}
%%----------------------------------------------------------------------
init([{SockMod, Socket}, Opts]) ->
Access = case lists:keysearch(access, 1, Opts) of
%% Func: StateName/2
%% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} |
-%% {stop, Reason, NewStateData}
+%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
wait_for_stream({xmlstreamstart, _Name, Attrs}, StateData) ->
{stop, normal, StateData};
true ->
send_text(StateData, Header),
- fsm_next_state(wait_for_auth,
+ fsm_next_state(wait_for_auth,
StateData#state{
server = Server,
lang = Lang})
%% {reply, Reply, NextStateName, NextStateData} |
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} |
-%% {stop, Reason, Reply, NewStateData}
+%% {stop, Reason, Reply, NewStateData}
%%----------------------------------------------------------------------
%state_name(Event, From, StateData) ->
% Reply = ok,
%% Func: handle_event/3
%% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} |
-%% {stop, Reason, NewStateData}
+%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
handle_event(_Event, StateName, StateData) ->
fsm_next_state(StateName, StateData).
%% {reply, Reply, NextStateName, NextStateData} |
%% {reply, Reply, NextStateName, NextStateData, Timeout} |
%% {stop, Reason, NewStateData} |
-%% {stop, Reason, Reply, NewStateData}
+%% {stop, Reason, Reply, NewStateData}
%%----------------------------------------------------------------------
handle_sync_event({get_presence}, _From, StateName, StateData) ->
User = StateData#state.user,
%% Func: handle_info/3
%% Returns: {next_state, NextStateName, NextStateData} |
%% {next_state, NextStateName, NextStateData, Timeout} |
-%% {stop, Reason, NewStateData}
+%% {stop, Reason, NewStateData}
%%----------------------------------------------------------------------
handle_info({send_text, Text}, StateName, StateData) ->
send_text(StateData, Text),
ejabberd_hooks:run(c2s_loop_debug, [Text]),
-
fsm_next_state(StateName, StateData);
handle_info(replaced, _StateName, StateData) ->
Lang = StateData#state.lang,
jlib:make_jid("", "", ""),
jlib:iq_to_xml(ResIQ)),
send_element(StateData, jlib:remove_attr("to", Res1));
- _ ->
+ _ ->
send_element(StateData, Res)
end;
_ ->
%%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose : S2S connections manager
%%% Created : 7 Dec 2002 by Alexey Shchepin <alexey@sevcom.net>
-%%% Id : $Id$
+%%% Id : $Id: ejabberd_s2s.erl 820 2007-07-19 21:17:13Z mremond $
%%%----------------------------------------------------------------------
-module(ejabberd_s2s).
-author('alexey@sevcom.net').
--vsn('$Revision$ ').
+-vsn('$Revision: 820 $ ').
-behaviour(gen_server).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
- terminate/2, code_change/3]).
+ terminate/2, code_change/3]).
-include("ejabberd.hrl").
-include("jlib.hrl").
route(From, To, Packet) ->
case catch do_route(From, To, Packet) of
- {'EXIT', Reason} ->
- ?ERROR_MSG("~p~nwhen processing: ~p",
- [Reason, {From, To, Packet}]);
- _ ->
- ok
+ {'EXIT', Reason} ->
+ ?ERROR_MSG("~p~nwhen processing: ~p",
+ [Reason, {From, To, Packet}]);
+ _ ->
+ ok
end.
remove_connection(FromTo, Pid, Key) ->
have_connection(FromTo) ->
case catch mnesia:dirty_read(s2s, FromTo) of
- [_] ->
- true;
- _ ->
- false
+ [_] ->
+ true;
+ _ ->
+ false
end.
has_key(FromTo, Key) ->
end
end,
case mnesia:transaction(F) of
- {atomic, Res} ->
- Res;
- _ ->
- false
+ {atomic, Res} ->
+ Res;
+ _ ->
+ false
end.
dirty_get_connections() ->
{noreply, State};
handle_info({route, From, To, Packet}, State) ->
case catch do_route(From, To, Packet) of
- {'EXIT', Reason} ->
- ?ERROR_MSG("~p~nwhen processing: ~p",
- [Reason, {From, To, Packet}]);
- _ ->
- ok
+ {'EXIT', Reason} ->
+ ?ERROR_MSG("~p~nwhen processing: ~p",
+ [Reason, {From, To, Packet}]);
+ _ ->
+ ok
end,
{noreply, State};
handle_info(_Info, State) ->
do_route(From, To, Packet) ->
?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
- [From, To, Packet, 8]),
+ [From, To, Packet, 8]),
case find_connection(From, To) of
{atomic, Pid} when pid(Pid) ->
?DEBUG("sending to process ~p~n", [Pid]),
[] -> Pids;
Ps -> Ps
end,
- %% use sticky connections based on the full JID of the sender
- Pid = lists:nth(erlang:phash(From, length(Pids1)), Pids1),
+ % Use sticky connections based on the JID of the sender (whithout
+ % the resource to ensure that a muc room always uses the same
+ % connection)
+ Pid = lists:nth(erlang:phash(jlib:jid_remove_resource(From), length(Pids1)),
+ Pids1),
?DEBUG("Using ejabberd_s2s_out ~p~n", [Pid]),
Pid.
is_service(From, To) ->
LFromDomain = From#jid.lserver,
case ejabberd_config:get_local_option({route_subdomains, LFromDomain}) of
- s2s -> % bypass RFC 3920 10.3
- false;
- _ ->
- LDstDomain = To#jid.lserver,
- P = fun(Domain) -> is_subdomain(LDstDomain, Domain) end,
- lists:any(P, ?MYHOSTS)
+ s2s -> % bypass RFC 3920 10.3
+ false;
+ _ ->
+ LDstDomain = To#jid.lserver,
+ P = fun(Domain) -> is_subdomain(LDstDomain, Domain) end,
+ lists:any(P, ?MYHOSTS)
end.
%%--------------------------------------------------------------------
mnesia:delete_table(s2s)
end,
case catch mnesia:table_info(s2s, attributes) of
- [fromto, node, key] ->
- mnesia:transform_table(s2s, ignore, [fromto, pid, key]),
- mnesia:clear_table(s2s);
- [fromto, pid, key] ->
- ok;
- {'EXIT', _} ->
- ok
+ [fromto, node, key] ->
+ mnesia:transform_table(s2s, ignore, [fromto, pid, key]),
+ mnesia:clear_table(s2s);
+ [fromto, pid, key] ->
+ ok;
+ {'EXIT', _} ->
+ ok
end,
case lists:member(local_s2s, mnesia:system_info(tables)) of
- true ->
- mnesia:delete_table(local_s2s);
- false ->
- ok
+ true ->
+ mnesia:delete_table(local_s2s);
+ false ->
+ ok
end.
%% Check if host is in blacklist or white list
allow_host(MyServer, S2SHost) ->
case ejabberd_config:get_local_option({{s2s_host, S2SHost},MyServer}) of
- deny -> false;
- allow -> true;
- _ ->
- case ejabberd_config:get_local_option({s2s_default_policy, MyServer}) of
- deny -> false;
- allow -> true;
- _ -> true %% The default s2s policy is allow
- end
+ deny -> false;
+ allow -> true;
+ _ ->
+ case ejabberd_config:get_local_option({s2s_default_policy, MyServer}) of
+ deny -> false;
+ allow -> true;
+ _ -> true %% The default s2s policy is allow
+ end
end.
-