aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Shchepin <alexey@process-one.net>2007-02-18 17:58:47 +0000
committerAlexey Shchepin <alexey@process-one.net>2007-02-18 17:58:47 +0000
commit0d5e433b91c5bc071d057b0c03f0dc8c9f654745 (patch)
treeba812bba1d8f851cb925e7872df6292c8ebd62e7
parent* src/mod_muc/mod_muc.erl: Node now try to clean its own online room when res... (diff)
* src/ejabberd_s2s.erl: Confirm to RFC3920 section 10.3 (thanks to
Jerome Sautret) SVN Revision: 726
-rw-r--r--ChangeLog5
-rw-r--r--src/ejabberd_s2s.erl72
2 files changed, 57 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index c5bdc1fd3..d8c4c251f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-02-18 Alexey Shchepin <alexey@sevcom.net>
+
+ * src/ejabberd_s2s.erl: Confirm to RFC3920 section 10.3 (thanks to
+ Jerome Sautret)
+
2007-02-18 Mickael Remond <mickael.remond@process-one.net>
* src/mod_muc/mod_muc.erl: Node now try to clean its own online room
diff --git a/src/ejabberd_s2s.erl b/src/ejabberd_s2s.erl
index 9b1177292..609695770 100644
--- a/src/ejabberd_s2s.erl
+++ b/src/ejabberd_s2s.erl
@@ -203,7 +203,6 @@ do_route(From, To, Packet) ->
case find_connection(From, To) of
{atomic, Pid} when pid(Pid) ->
?DEBUG("sending to process ~p~n", [Pid]),
- % TODO
{xmlelement, Name, Attrs, Els} = Packet,
NewAttrs = jlib:replace_from_to_attrs(jlib:jid_to_string(From),
jlib:jid_to_string(To),
@@ -211,7 +210,9 @@ do_route(From, To, Packet) ->
send_element(Pid, {xmlelement, Name, NewAttrs, Els}),
ok;
{aborted, Reason} ->
- ?DEBUG("delivery failed: ~p~n", [Reason]),
+ Err = jlib:make_error_reply(
+ Packet, ?ERR_SERVICE_UNAVAILABLE),
+ ejabberd_router:route(To, From, Err),
false
end.
@@ -223,27 +224,59 @@ find_connection(From, To) ->
{'EXIT', Reason} ->
{aborted, Reason};
[] ->
- ?DEBUG("starting new s2s connection~n", []),
- Key = randoms:get_string(),
- {ok, Pid} = ejabberd_s2s_out:start(MyServer, Server, {new, Key}),
- F = fun() ->
- case mnesia:read({s2s, FromTo}) of
- [El] ->
- El#s2s.pid;
- [] ->
- mnesia:write(#s2s{fromto = FromTo,
- pid = Pid,
- key = Key}),
- Pid
- end
- end,
- TRes = mnesia:transaction(F),
- ejabberd_s2s_out:start_connection(Pid),
- TRes;
+ case is_service(From, To) of
+ true ->
+ {aborted, error};
+ false ->
+ ?DEBUG("starting new s2s connection~n", []),
+ Key = randoms:get_string(),
+ {ok, Pid} = ejabberd_s2s_out:start(
+ MyServer, Server, {new, Key}),
+ F = fun() ->
+ case mnesia:read({s2s, FromTo}) of
+ [El] ->
+ El#s2s.pid;
+ [] ->
+ mnesia:write(#s2s{fromto = FromTo,
+ pid = Pid,
+ key = Key}),
+ Pid
+ end
+ end,
+ TRes = mnesia:transaction(F),
+ ejabberd_s2s_out:start_connection(Pid),
+ TRes
+ end;
[El] ->
{atomic, El#s2s.pid}
end.
+
+%%--------------------------------------------------------------------
+%% Function: is_service(From, To) -> true | false
+%% Description: Return true if the destination must be considered as a
+%% service.
+%% --------------------------------------------------------------------
+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_subdmomain(LDstDomain, Domain) end,
+ lists:any(P, ?MYHOSTS)
+ end.
+
+%%--------------------------------------------------------------------
+%% Function: is_subdmomain(Domain1, Domain2) -> true | false
+%% Description: Return true if Domain1 (a string representing an
+%% internet domain name) is a subdomain (or the same domain) of
+%% Domain2
+%% --------------------------------------------------------------------
+is_subdmomain(Domain1, Domain2) ->
+ lists:suffix(string:tokens(Domain2, "."), string:tokens(Domain1, ".")).
+
send_element(Pid, El) ->
Pid ! {send_element, El}.
@@ -274,4 +307,3 @@ update_tables() ->
false ->
ok
end.
-