mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-20 16:15:59 +01:00
*** empty log message ***
SVN Revision: 9
This commit is contained in:
parent
b2229bffcc
commit
9fdf316aab
@ -19,7 +19,8 @@
|
||||
%-export([init/1, state_name/2, state_name/3, handle_event/3,
|
||||
% handle_sync_event/4, handle_info/3, terminate/3]).
|
||||
%
|
||||
-export([init/1, wait_for_stream/2, wait_for_auth/2, terminate/3]).
|
||||
-export([init/1, wait_for_stream/2, wait_for_auth/2, session_established/2,
|
||||
terminate/3]).
|
||||
|
||||
-record(state, {socket, sender, receiver, streamid,
|
||||
user = "", server = "localhost", resource = ""}).
|
||||
@ -89,8 +90,7 @@ wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
|
||||
% TODO
|
||||
{next_state, wait_for_auth, StateData};
|
||||
_ ->
|
||||
send_text(StateData#state.sender, ?INVALID_NS_ERR),
|
||||
send_text(StateData#state.sender, ?STREAM_TRAILER),
|
||||
send_text(StateData#state.sender, ?INVALID_NS_ERR ?STREAM_TRAILER),
|
||||
{stop, normal, StateData}
|
||||
end;
|
||||
|
||||
@ -109,7 +109,7 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
|
||||
{next_state, session_established,
|
||||
StateData#state{user = U, resource = R}};
|
||||
_ ->
|
||||
Err = jlib:make_error_iq_reply(El, "404", "Unauthorized"),
|
||||
Err = jlib:make_error_reply(El, "404", "Unauthorized"),
|
||||
send_element(StateData#state.sender, Err),
|
||||
{next_state, wait_for_auth, StateData}
|
||||
end;
|
||||
@ -127,6 +127,9 @@ wait_for_auth(closed, StateData) ->
|
||||
session_established({xmlstreamelement, El}, StateData) ->
|
||||
{xmlelement, Name, Attrs, Els} = El,
|
||||
% TODO
|
||||
FromJID = {StateData#state.user, "localhost", StateData#state.resource},
|
||||
ToJID = jlib:string_to_jid(xml:get_attr_s("to", Attrs)),
|
||||
ejabberd_router:route(FromJID, ToJID, El),
|
||||
{next_state, session_established, StateData};
|
||||
|
||||
session_established(closed, StateData) ->
|
||||
|
@ -8,12 +8,15 @@
|
||||
|
||||
-module(ejabberd_router).
|
||||
-author('alexey@sevcom.net').
|
||||
-vsn('$Revision$ ').
|
||||
|
||||
%%-export([Function/Arity, ...]).
|
||||
-export([route/3]).
|
||||
|
||||
-export([start/0, init/0]).
|
||||
|
||||
-record(service, {domain, node, pid}).
|
||||
-include("ejabberd.hrl").
|
||||
|
||||
-record(route, {domain, node, pid}).
|
||||
|
||||
|
||||
start() ->
|
||||
@ -21,23 +24,82 @@ start() ->
|
||||
|
||||
init() ->
|
||||
register(ejabberd_router, self()),
|
||||
mnesia:create_table(service,
|
||||
mnesia:create_table(route,
|
||||
[{ram_copies, [node()]},
|
||||
{attributes,
|
||||
record_info(fields, service)}]),
|
||||
record_info(fields, route)}]),
|
||||
loop().
|
||||
|
||||
loop() ->
|
||||
receive
|
||||
{route, From, To, Packet} ->
|
||||
% TODO
|
||||
do_route(From, To, Packet),
|
||||
loop();
|
||||
{register_service, Domain, Pid, Node} ->
|
||||
% TODO
|
||||
{register_route, Domain, Pid, Node} ->
|
||||
F = fun() ->
|
||||
case mnesia:wread({route, Domain}) of
|
||||
[] ->
|
||||
ok;
|
||||
[Old] ->
|
||||
% TODO: notify
|
||||
ok
|
||||
end,
|
||||
mnesia:write(#route{domain = Domain,
|
||||
node = Node,
|
||||
pid = Pid})
|
||||
end,
|
||||
mnesia:transaction(F),
|
||||
loop();
|
||||
{unregister_service, Domain} ->
|
||||
% TODO
|
||||
{unregister_route, Domain} ->
|
||||
F = fun() ->
|
||||
case mnesia:wread({route, Domain}) of
|
||||
[] ->
|
||||
ok;
|
||||
[Old] ->
|
||||
% TODO: notify
|
||||
ok
|
||||
end,
|
||||
mnesia:delete({route, Domain})
|
||||
end,
|
||||
mnesia:transaction(F),
|
||||
loop();
|
||||
_ ->
|
||||
loop()
|
||||
end.
|
||||
|
||||
|
||||
do_route(From, To, Packet) ->
|
||||
?DEBUG("route~n\tfrom ~p~n\tto ~p~n\tpacket ~p~n", [From, To, Packet]),
|
||||
{DstNode, DstDomain, DstResourse} = To,
|
||||
F = fun() ->
|
||||
case mnesia:read({route, DstDomain}) of
|
||||
[] ->
|
||||
error;
|
||||
[R] ->
|
||||
{ok, R#route.node, R#route.pid}
|
||||
end
|
||||
end,
|
||||
case mnesia:transaction(F) of
|
||||
{atomic, error} ->
|
||||
% TODO: start s2s instead of below
|
||||
{xmlelement, Name, Attrs, SubTags} = Packet,
|
||||
case xml:get_attr_s("type", Attrs) of
|
||||
"error" ->
|
||||
ok;
|
||||
_ ->
|
||||
Err = jlib:make_error_reply(Packet,
|
||||
502, "Service Unavailable"),
|
||||
ejabberd_router ! {route, To, From, Err}
|
||||
end;
|
||||
{atomic, {ok, Node, Pid}} ->
|
||||
{Pid, Node} ! {packet, From, To, Packet};
|
||||
_ ->
|
||||
% TODO
|
||||
error
|
||||
end.
|
||||
|
||||
|
||||
route(From, To, Packet) ->
|
||||
ejabberd_router ! {route, From, To, Packet}.
|
||||
|
||||
|
@ -10,21 +10,20 @@
|
||||
-author('alexey@sevcom.net').
|
||||
-vsn('$Revision$ ').
|
||||
|
||||
-export([make_error_iq_reply/3, make_correct_from_to_attrs/3,
|
||||
-export([make_error_reply/3, make_correct_from_to_attrs/3,
|
||||
replace_from_to_attrs/3, string_to_jid/1, tolower/1]).
|
||||
|
||||
|
||||
%send_iq(From, To, ID, SubTags) ->
|
||||
% ok.
|
||||
|
||||
make_error_iq_reply({xmlelement, Name, Attrs, SubTags}, Code, Desc)
|
||||
when Name == "iq" ->
|
||||
NewAttrs = make_error_iq_reply_attrs(Attrs),
|
||||
make_error_reply({xmlelement, Name, Attrs, SubTags}, Code, Desc) ->
|
||||
NewAttrs = make_error_reply_attrs(Attrs),
|
||||
{xmlelement, Name, NewAttrs, SubTags ++ [{xmlelement, "error",
|
||||
[{"code", Code}],
|
||||
[{xmlcdata, Desc}]}]}.
|
||||
|
||||
make_error_iq_reply_attrs(Attrs) ->
|
||||
make_error_reply_attrs(Attrs) ->
|
||||
To = xml:get_attr("to", Attrs),
|
||||
From = xml:get_attr("from", Attrs),
|
||||
Attrs1 = lists:keydelete("to", 1, Attrs),
|
||||
|
Loading…
Reference in New Issue
Block a user