mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Convert to exmpp.
SVN Revision: 1389
This commit is contained in:
parent
d05c2ee8a1
commit
264e72830b
@ -7,6 +7,8 @@
|
|||||||
src/ejabberd_s2s_out.erl: Use -include_lib instead of -include to
|
src/ejabberd_s2s_out.erl: Use -include_lib instead of -include to
|
||||||
include exmpp.hrl.
|
include exmpp.hrl.
|
||||||
|
|
||||||
|
* src/ejabberd_s2s.erl: Convert to exmpp.
|
||||||
|
|
||||||
2008-06-27 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-06-27 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
* src/ejabberd_c2s.erl, src/ejabberd_s2s_out.erl,
|
* src/ejabberd_c2s.erl, src/ejabberd_s2s_out.erl,
|
||||||
|
@ -46,13 +46,21 @@
|
|||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||||
terminate/2, code_change/3]).
|
terminate/2, code_change/3]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
-include("ejabberd_ctl.hrl").
|
-include("ejabberd_ctl.hrl").
|
||||||
|
|
||||||
-define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER, 1).
|
-define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER, 1).
|
||||||
-define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER_PER_NODE, 1).
|
-define(DEFAULT_MAX_S2S_CONNECTIONS_NUMBER_PER_NODE, 1).
|
||||||
|
|
||||||
|
% These are the namespace already declared by the stream opening. This is
|
||||||
|
% used at serialization time.
|
||||||
|
-define(DEFAULT_NS, ?NS_JABBER_CLIENT).
|
||||||
|
-define(PREFIXED_NS, [
|
||||||
|
{?NS_XMPP, ?NS_XMPP_pfx}, {?NS_DIALBACK, ?NS_DIALBACK_pfx}
|
||||||
|
]).
|
||||||
|
|
||||||
-record(s2s, {fromto, pid, key}).
|
-record(s2s, {fromto, pid, key}).
|
||||||
-record(state, {}).
|
-record(state, {}).
|
||||||
|
|
||||||
@ -66,7 +74,12 @@
|
|||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
route(From, To, Packet) ->
|
route(FromOld, ToOld, PacketOld) ->
|
||||||
|
% XXX OLD FORMAT: From, To, Packet.
|
||||||
|
From = exmpp_jid:from_ejabberd_jid(FromOld),
|
||||||
|
To = exmpp_jid:from_ejabberd_jid(ToOld),
|
||||||
|
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
case catch do_route(From, To, Packet) of
|
case catch do_route(From, To, Packet) of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||||
@ -201,7 +214,12 @@ handle_cast(_Msg, State) ->
|
|||||||
handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
|
handle_info({mnesia_system_event, {mnesia_down, Node}}, State) ->
|
||||||
clean_table_from_bad_node(Node),
|
clean_table_from_bad_node(Node),
|
||||||
{noreply, State};
|
{noreply, State};
|
||||||
handle_info({route, From, To, Packet}, State) ->
|
handle_info({route, FromOld, ToOld, PacketOld}, State) ->
|
||||||
|
% XXX OLD FORMAT: From, To, Packet
|
||||||
|
From = exmpp_jid:from_ejabberd_jid(FromOld),
|
||||||
|
To = exmpp_jid:from_ejabberd_jid(ToOld),
|
||||||
|
Packet = exmpp_xml:xmlelement_to_xmlel(PacketOld,
|
||||||
|
[?NS_JABBER_CLIENT], [{?NS_XMPP, ?NS_XMPP_pfx}]),
|
||||||
case catch do_route(From, To, Packet) of
|
case catch do_route(From, To, Packet) of
|
||||||
{'EXIT', Reason} ->
|
{'EXIT', Reason} ->
|
||||||
?ERROR_MSG("~p~nwhen processing: ~p",
|
?ERROR_MSG("~p~nwhen processing: ~p",
|
||||||
@ -249,35 +267,42 @@ clean_table_from_bad_node(Node) ->
|
|||||||
do_route(From, To, Packet) ->
|
do_route(From, To, Packet) ->
|
||||||
?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
?DEBUG("s2s manager~n\tfrom ~p~n\tto ~p~n\tpacket ~P~n",
|
||||||
[From, To, Packet, 8]),
|
[From, To, Packet, 8]),
|
||||||
|
% XXX OLD FORMAT: From, To.
|
||||||
|
FromOld = exmpp_jid:to_ejabberd_jid(From),
|
||||||
|
ToOld = exmpp_jid:to_ejabberd_jid(To),
|
||||||
case find_connection(From, To) of
|
case find_connection(From, To) of
|
||||||
{atomic, Pid} when pid(Pid) ->
|
{atomic, Pid} when pid(Pid) ->
|
||||||
?DEBUG("sending to process ~p~n", [Pid]),
|
?DEBUG("sending to process ~p~n", [Pid]),
|
||||||
{xmlelement, Name, Attrs, Els} = Packet,
|
NewPacket1 = exmpp_stanza:set_sender(Packet, From),
|
||||||
NewAttrs = jlib:replace_from_to_attrs(jlib:jid_to_string(From),
|
NewPacket = exmpp_stanza:set_recipient(NewPacket1, To),
|
||||||
jlib:jid_to_string(To),
|
#jid{ldomain = MyServer} = From,
|
||||||
Attrs),
|
% XXX OLD FORMAT: NewPacket.
|
||||||
#jid{lserver = MyServer} = From,
|
NewPacketOld = exmpp_xml:xmlel_to_xmlelement(NewPacket,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
ejabberd_hooks:run(
|
ejabberd_hooks:run(
|
||||||
s2s_send_packet,
|
s2s_send_packet,
|
||||||
MyServer,
|
MyServer,
|
||||||
[From, To, Packet]),
|
[FromOld, ToOld, NewPacketOld]),
|
||||||
send_element(Pid, {xmlelement, Name, NewAttrs, Els}),
|
send_element(Pid, NewPacket),
|
||||||
ok;
|
ok;
|
||||||
{aborted, _Reason} ->
|
{aborted, _Reason} ->
|
||||||
case xml:get_tag_attr_s("type", Packet) of
|
case exmpp_stanza:get_type(Packet) of
|
||||||
"error" -> ok;
|
"error" -> ok;
|
||||||
"result" -> ok;
|
"result" -> ok;
|
||||||
_ ->
|
_ ->
|
||||||
Err = jlib:make_error_reply(
|
Err = exmpp_stanza:reply_with_error(Packet,
|
||||||
Packet, ?ERR_SERVICE_UNAVAILABLE),
|
exmpp_stanza:error('service-unavailable')),
|
||||||
ejabberd_router:route(To, From, Err)
|
% XXX OLD FORMAT: Err.
|
||||||
|
ErrOld = exmpp_xml:xmlel_to_xmlelement(Err,
|
||||||
|
[?DEFAULT_NS], ?PREFIXED_NS),
|
||||||
|
ejabberd_router:route(ToOld, FromOld, ErrOld)
|
||||||
end,
|
end,
|
||||||
false
|
false
|
||||||
end.
|
end.
|
||||||
|
|
||||||
find_connection(From, To) ->
|
find_connection(From, To) ->
|
||||||
#jid{lserver = MyServer} = From,
|
#jid{ldomain = MyServer} = From,
|
||||||
#jid{lserver = Server} = To,
|
#jid{ldomain = Server} = To,
|
||||||
FromTo = {MyServer, Server},
|
FromTo = {MyServer, Server},
|
||||||
MaxS2SConnectionsNumber = max_s2s_connections_number(FromTo),
|
MaxS2SConnectionsNumber = max_s2s_connections_number(FromTo),
|
||||||
MaxS2SConnectionsNumberPerNode =
|
MaxS2SConnectionsNumberPerNode =
|
||||||
@ -330,7 +355,7 @@ choose_pid(From, Pids) ->
|
|||||||
% Use sticky connections based on the JID of the sender (whithout
|
% Use sticky connections based on the JID of the sender (whithout
|
||||||
% the resource to ensure that a muc room always uses the same
|
% the resource to ensure that a muc room always uses the same
|
||||||
% connection)
|
% connection)
|
||||||
Pid = lists:nth(erlang:phash(jlib:jid_remove_resource(From), length(Pids1)),
|
Pid = lists:nth(erlang:phash(exmpp_jid:jid_to_bare_jid(From), length(Pids1)),
|
||||||
Pids1),
|
Pids1),
|
||||||
?DEBUG("Using ejabberd_s2s_out ~p~n", [Pid]),
|
?DEBUG("Using ejabberd_s2s_out ~p~n", [Pid]),
|
||||||
Pid.
|
Pid.
|
||||||
@ -381,14 +406,14 @@ new_connection(MyServer, Server, From, FromTo,
|
|||||||
|
|
||||||
max_s2s_connections_number({From, To}) ->
|
max_s2s_connections_number({From, To}) ->
|
||||||
case acl:match_rule(
|
case acl:match_rule(
|
||||||
From, max_s2s_connections, jlib:make_jid("", To, "")) of
|
From, max_s2s_connections, exmpp_jid:make_bare_jid(To)) of
|
||||||
Max when is_integer(Max) -> Max;
|
Max when is_integer(Max) -> Max;
|
||||||
_ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER
|
_ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER
|
||||||
end.
|
end.
|
||||||
|
|
||||||
max_s2s_connections_number_per_node({From, To}) ->
|
max_s2s_connections_number_per_node({From, To}) ->
|
||||||
case acl:match_rule(
|
case acl:match_rule(
|
||||||
From, max_s2s_connections_per_node, jlib:make_jid("", To, "")) of
|
From, max_s2s_connections_per_node, exmpp_jid:make_bare_jid(To)) of
|
||||||
Max when is_integer(Max) -> Max;
|
Max when is_integer(Max) -> Max;
|
||||||
_ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER_PER_NODE
|
_ -> ?DEFAULT_MAX_S2S_CONNECTIONS_NUMBER_PER_NODE
|
||||||
end.
|
end.
|
||||||
@ -405,12 +430,12 @@ needed_connections_number(Ls, MaxS2SConnectionsNumber,
|
|||||||
%% service.
|
%% service.
|
||||||
%% --------------------------------------------------------------------
|
%% --------------------------------------------------------------------
|
||||||
is_service(From, To) ->
|
is_service(From, To) ->
|
||||||
LFromDomain = From#jid.lserver,
|
LFromDomain = From#jid.ldomain,
|
||||||
case ejabberd_config:get_local_option({route_subdomains, LFromDomain}) of
|
case ejabberd_config:get_local_option({route_subdomains, LFromDomain}) of
|
||||||
s2s -> % bypass RFC 3920 10.3
|
s2s -> % bypass RFC 3920 10.3
|
||||||
false;
|
false;
|
||||||
_ ->
|
_ ->
|
||||||
LDstDomain = To#jid.lserver,
|
LDstDomain = To#jid.ldomain,
|
||||||
P = fun(Domain) -> is_subdomain(LDstDomain, Domain) end,
|
P = fun(Domain) -> is_subdomain(LDstDomain, Domain) end,
|
||||||
lists:any(P, ?MYHOSTS)
|
lists:any(P, ?MYHOSTS)
|
||||||
end.
|
end.
|
||||||
|
Loading…
Reference in New Issue
Block a user