25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

*** empty log message ***

SVN Revision: 28
This commit is contained in:
Alexey Shchepin 2003-01-04 20:09:25 +00:00
parent 5755092b92
commit 083e2b75d0
7 changed files with 53 additions and 25 deletions

View File

@ -16,5 +16,5 @@
-endif. -endif.
-define(MYNAME,"127.0.0.1"). -define(MYNAME,"e.localhost").

View File

@ -11,7 +11,9 @@
-vsn('$Revision$ '). -vsn('$Revision$ ').
-export([route/3, register_route/1, register_local_route/1, -export([route/3, register_route/1, register_local_route/1,
dirty_get_all_routes/0]). dirty_get_all_routes/0,
dirty_get_all_domains/0
]).
-export([start/0, init/0]). -export([start/0, init/0]).
@ -132,3 +134,7 @@ dirty_get_all_routes() ->
lists:umerge(lists:sort(mnesia:dirty_all_keys(route)), lists:umerge(lists:sort(mnesia:dirty_all_keys(route)),
lists:sort(mnesia:dirty_all_keys(local_route)))). lists:sort(mnesia:dirty_all_keys(local_route)))).
dirty_get_all_domains() ->
lists:umerge(lists:sort(mnesia:dirty_all_keys(route)),
lists:sort(mnesia:dirty_all_keys(local_route))).

View File

@ -137,6 +137,7 @@ try_register(Server) ->
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]),
{_, MyServer, _} = From,
{User, Server, Resource} = To, {User, Server, Resource} = To,
Key = randoms:get_string(), Key = randoms:get_string(),
F = fun() -> F = fun() ->
@ -172,7 +173,7 @@ do_route(From, To, Packet) ->
ok; ok;
{atomic, new} -> {atomic, new} ->
?DEBUG("starting new s2s connection~n", []), ?DEBUG("starting new s2s connection~n", []),
Pid = ejabberd_s2s_out:start(Server, {new, Key}), Pid = ejabberd_s2s_out:start(MyServer, Server, {new, Key}),
mnesia:transaction(fun() -> mnesia:write(#mys2s{server = Server, mnesia:transaction(fun() -> mnesia:write(#mys2s{server = Server,
pid = Pid}) end), pid = Pid}) end),
{xmlelement, Name, Attrs, Els} = Packet, {xmlelement, Name, Attrs, Els} = Packet,

View File

@ -27,7 +27,7 @@
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-record(state, {socket, receiver, streamid, -record(state, {socket, receiver, streamid,
myself = ?MYNAME, server, queue}). myname, server, queue}).
-define(DBGFSM, true). -define(DBGFSM, true).
@ -53,6 +53,12 @@
"</stream:stream>" "</stream:stream>"
). ).
-define(INVALID_DOMAIN_ERR,
"<stream:stream>"
"<stream:error>Invalid Destination</stream:error>"
"</stream:stream>"
).
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% API %%% API
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -90,8 +96,19 @@ wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
% TODO % TODO
case {xml:get_attr_s("xmlns", Attrs), xml:get_attr_s("xmlns:db", Attrs)} of case {xml:get_attr_s("xmlns", Attrs), xml:get_attr_s("xmlns:db", Attrs)} of
{"jabber:server", "jabber:server:dialback"} -> {"jabber:server", "jabber:server:dialback"} ->
send_text(StateData#state.socket, ?STREAM_HEADER), Me = case xml:get_attr_s("to", Attrs) of
{next_state, wait_for_key, StateData}; "" -> ?MYNAME;
Dom -> Dom
end,
case lists:member(Me, ejabberd_router:dirty_get_all_domains()) of
true ->
send_text(StateData#state.socket, ?STREAM_HEADER),
{next_state, wait_for_key, StateData#state{myname = Me}};
_ ->
send_text(StateData#state.socket, ?INVALID_DOMAIN_ERR),
{stop, normal, StateData}
end;
_ -> _ ->
send_text(StateData#state.socket, ?INVALID_HEADER_ERR), send_text(StateData#state.socket, ?INVALID_HEADER_ERR),
{stop, normal, StateData} {stop, normal, StateData}
@ -105,7 +122,8 @@ wait_for_key({xmlstreamelement, El}, StateData) ->
case is_key_packet(El) of case is_key_packet(El) of
{key, To, From, Id, Key} -> {key, To, From, Id, Key} ->
io:format("GET KEY: ~p~n", [{To, From, Id, Key}]), io:format("GET KEY: ~p~n", [{To, From, Id, Key}]),
ejabberd_s2s_out:start(From, {verify, self(), Key}), ejabberd_s2s_out:start(StateData#state.myname, From,
{verify, self(), Key}),
{next_state, {next_state,
wait_for_verification, wait_for_verification,
StateData#state{server = From}}; StateData#state{server = From}};
@ -118,7 +136,7 @@ wait_for_key({xmlstreamelement, El}, StateData) ->
send_element(StateData#state.socket, send_element(StateData#state.socket,
{xmlelement, {xmlelement,
"db:verify", "db:verify",
[{"from", ?MYNAME}, [{"from", StateData#state.myname},
{"to", From}, {"to", From},
{"id", Id}, {"id", Id},
{"type", Type}], {"type", Type}],
@ -139,7 +157,7 @@ wait_for_verification(valid, StateData) ->
send_element(StateData#state.socket, send_element(StateData#state.socket,
{xmlelement, {xmlelement,
"db:result", "db:result",
[{"from", ?MYNAME}, [{"from", StateData#state.myname},
{"to", StateData#state.server}, {"to", StateData#state.server},
{"type", "valid"}], {"type", "valid"}],
[]}), []}),
@ -150,7 +168,7 @@ wait_for_verification(invalid, StateData) ->
send_element(StateData#state.socket, send_element(StateData#state.socket,
{xmlelement, {xmlelement,
"db:result", "db:result",
[{"from", ?MYNAME}, [{"from", StateData#state.myname},
{"to", StateData#state.server}, {"to", StateData#state.server},
{"type", "invalid"}], {"type", "invalid"}],
[]}), []}),
@ -167,7 +185,7 @@ wait_for_verification({xmlstreamelement, El}, StateData) ->
send_element(StateData#state.socket, send_element(StateData#state.socket,
{xmlelement, {xmlelement,
"db:verify", "db:verify",
[{"from", ?MYNAME}, [{"from", StateData#state.myname},
{"to", From}, {"to", From},
{"id", Id}, {"id", Id},
{"type", Type}], {"type", Type}],
@ -198,7 +216,7 @@ stream_established({xmlstreamelement, El}, StateData) ->
send_element(StateData#state.socket, send_element(StateData#state.socket,
{xmlelement, {xmlelement,
"db:verify", "db:verify",
[{"from", ?MYNAME}, [{"from", StateData#state.myname},
{"to", From}, {"to", From},
{"id", Id}, {"id", Id},
{"type", Type}], {"type", Type}],

View File

@ -13,7 +13,7 @@
-behaviour(gen_fsm). -behaviour(gen_fsm).
%% External exports %% External exports
-export([start/2, receiver/2, send_text/2, send_element/2]). -export([start/3, receiver/2, send_text/2, send_element/2]).
%% gen_fsm callbacks %% gen_fsm callbacks
-export([init/1, -export([init/1,
@ -27,7 +27,7 @@
-include("ejabberd.hrl"). -include("ejabberd.hrl").
-record(state, {socket, receiver, streamid, -record(state, {socket, receiver, streamid,
myself = ?MYNAME, server, xmlpid, queue, myname, server, xmlpid, queue,
new = false, verify = false}). new = false, verify = false}).
-define(DBGFSM, true). -define(DBGFSM, true).
@ -43,7 +43,8 @@
"<stream:stream " "<stream:stream "
"xmlns:stream='http://etherx.jabber.org/streams' " "xmlns:stream='http://etherx.jabber.org/streams' "
"xmlns='jabber:server' " "xmlns='jabber:server' "
"xmlns:db='jabber:server:dialback'>" "xmlns:db='jabber:server:dialback' "
"to='~s'>"
). ).
-define(STREAM_TRAILER, "</stream:stream>"). -define(STREAM_TRAILER, "</stream:stream>").
@ -57,8 +58,8 @@
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% API %%% API
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
start(Host, Type) -> start(From, Host, Type) ->
{ok, Pid} = gen_fsm:start(ejabberd_s2s_out, [Host, Type], ?FSMOPTS), {ok, Pid} = gen_fsm:start(ejabberd_s2s_out, [From, Host, Type], ?FSMOPTS),
Pid. Pid.
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -72,7 +73,7 @@ start(Host, Type) ->
%% ignore | %% ignore |
%% {stop, StopReason} %% {stop, StopReason}
%%---------------------------------------------------------------------- %%----------------------------------------------------------------------
init([Server, Type]) -> init([From, Server, Type]) ->
gen_fsm:send_event(self(), init), gen_fsm:send_event(self(), init),
{New, Verify} = case Type of {New, Verify} = case Type of
{new, Key} -> {new, Key} ->
@ -81,6 +82,7 @@ init([Server, Type]) ->
{false, {Pid, Key}} {false, {Pid, Key}}
end, end,
{ok, open_socket, #state{queue = queue:new(), {ok, open_socket, #state{queue = queue:new(),
myname = From,
server = Server, server = Server,
new = New, new = New,
verify = Verify}}. verify = Verify}}.
@ -96,7 +98,8 @@ open_socket(init, StateData) ->
[binary, {packet, 0}]) of [binary, {packet, 0}]) of
{ok, Socket} -> {ok, Socket} ->
XMLStreamPid = xml_stream:start(self()), XMLStreamPid = xml_stream:start(self()),
send_text(Socket, ?STREAM_HEADER), send_text(Socket, io_lib:format(?STREAM_HEADER,
[StateData#state.server])),
{next_state, wait_for_stream, {next_state, wait_for_stream,
StateData#state{socket = Socket, StateData#state{socket = Socket,
xmlpid = XMLStreamPid, xmlpid = XMLStreamPid,
@ -135,7 +138,7 @@ wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
send_element(StateData#state.socket, send_element(StateData#state.socket,
{xmlelement, {xmlelement,
"db:result", "db:result",
[{"from", ?MYNAME}, [{"from", StateData#state.myname},
{"to", Server}], {"to", Server}],
[{xmlcdata, Key1}]}) [{xmlcdata, Key1}]})
end, end,
@ -146,7 +149,7 @@ wait_for_stream({xmlstreamstart, Name, Attrs}, StateData) ->
send_element(StateData#state.socket, send_element(StateData#state.socket,
{xmlelement, {xmlelement,
"db:verify", "db:verify",
[{"from", ?MYNAME}, [{"from", StateData#state.myname},
{"to", StateData#state.server}], {"to", StateData#state.server}],
[{xmlcdata, Key2}]}) [{xmlcdata, Key2}]})
end, end,

View File

@ -23,7 +23,7 @@
-record(session, {ur, user, node}). -record(session, {ur, user, node}).
-record(mysession, {ur, pid}). -record(mysession, {ur, pid}).
-record(presence, {ur, user, priority}). -record(presence, {ur, user, priority}).
-record(offline_msg, {user, timestamp, xml}).
start() -> start() ->
spawn(ejabberd_sm, init, []). spawn(ejabberd_sm, init, []).

View File

@ -172,8 +172,8 @@ set_vcard(LUser, VCARD) ->
[{xmlcdata, "Fill in fields to search " [{xmlcdata, "Fill in fields to search "
"for any matching Jabber User"}]}, "for any matching Jabber User"}]},
{xmlelement, "field", [{"type", "text-single"}, {xmlelement, "field", [{"type", "text-single"},
{"label", "JID"}, {"label", "User"},
{"var", "jid"}], []}, {"var", "user"}], []},
{xmlelement, "field", [{"type", "text-single"}, {xmlelement, "field", [{"type", "text-single"},
{"label", "Full Name"}, {"label", "Full Name"},
{"var", "fn"}], []}, {"var", "fn"}], []},
@ -403,7 +403,7 @@ filter_fields([], Match) ->
filter_fields([{SVar, [Val]} | Ds], Match) filter_fields([{SVar, [Val]} | Ds], Match)
when is_list(Val) and (Val /= "") -> when is_list(Val) and (Val /= "") ->
NewMatch = case SVar of NewMatch = case SVar of
"jid" -> Match; "user" -> Match#vcard_search{user = Val};
"fn" -> Match#vcard_search{fn = Val}; "fn" -> Match#vcard_search{fn = Val};
"family" -> Match#vcard_search{family = Val}; "family" -> Match#vcard_search{family = Val};
"given" -> Match#vcard_search{given = Val}; "given" -> Match#vcard_search{given = Val};