]> granicus.if.org Git - ejabberd/commitdiff
* src/ejabberd_s2s.erl: Confirm to RFC3920 section 10.3 (thanks to
authorAlexey Shchepin <alexey@process-one.net>
Sun, 18 Feb 2007 17:58:47 +0000 (17:58 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Sun, 18 Feb 2007 17:58:47 +0000 (17:58 +0000)
Jerome Sautret)

SVN Revision: 726

ChangeLog
src/ejabberd_s2s.erl

index c5bdc1fd31be0f000270b61da45d42013fc347a5..d8c4c251ff4ce4c70c374e87e49be27287e38fdc 100644 (file)
--- 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
index 9b11772924218131876e4d2d067b28dd8b91f9c1..6096957706b9616686fe6752269d2b628cc929a1 100644 (file)
@@ -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.
-