mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-26 16:26:24 +01:00
Updated IP retrieving (thanks to Alexey Shchepin)
SVN Revision: 2305
This commit is contained in:
parent
d25bd8c1c6
commit
1d1f72fdc2
@ -4,7 +4,7 @@
|
|||||||
%%% Purpose : Implements XMPP over BOSH (XEP-0205) (formerly known as
|
%%% Purpose : Implements XMPP over BOSH (XEP-0205) (formerly known as
|
||||||
%%% HTTP Binding)
|
%%% HTTP Binding)
|
||||||
%%% Created : 21 Sep 2005 by Stefan Strigler <steve@zeank.in-berlin.de>
|
%%% Created : 21 Sep 2005 by Stefan Strigler <steve@zeank.in-berlin.de>
|
||||||
%%% Id : $Id: ejabberd_http_bind.erl 683 2008-07-08 10:30:45Z cromain $
|
%%% Id : $Id: ejabberd_http_bind.erl 694 2008-07-15 13:27:03Z alexey $
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ejabberd_http_bind).
|
-module(ejabberd_http_bind).
|
||||||
@ -13,7 +13,7 @@
|
|||||||
-behaviour(gen_fsm).
|
-behaviour(gen_fsm).
|
||||||
|
|
||||||
%% External exports
|
%% External exports
|
||||||
-export([start_link/2,
|
-export([start_link/3,
|
||||||
init/1,
|
init/1,
|
||||||
handle_event/3,
|
handle_event/3,
|
||||||
handle_sync_event/4,
|
handle_sync_event/4,
|
||||||
@ -47,6 +47,7 @@
|
|||||||
-record(state, {id,
|
-record(state, {id,
|
||||||
rid = none,
|
rid = none,
|
||||||
key,
|
key,
|
||||||
|
socket,
|
||||||
output = "",
|
output = "",
|
||||||
input = "",
|
input = "",
|
||||||
waiting_input = false,
|
waiting_input = false,
|
||||||
@ -91,17 +92,17 @@
|
|||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
%%% API
|
%%% API
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
start(Sid, Key) ->
|
start(Sid, Key, IP) ->
|
||||||
setup_database(),
|
setup_database(),
|
||||||
supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key]).
|
supervisor:start_child(ejabberd_http_bind_sup, [Sid, Key, IP]).
|
||||||
|
|
||||||
start_link(Sid, Key) ->
|
start_link(Sid, Key, IP) ->
|
||||||
gen_fsm:start_link(?MODULE, [Sid, Key], ?FSMOPTS).
|
gen_fsm:start_link(?MODULE, [Sid, Key, IP], ?FSMOPTS).
|
||||||
|
|
||||||
send({http_bind, FsmRef}, Packet) ->
|
send({http_bind, FsmRef, _IP}, Packet) ->
|
||||||
gen_fsm:sync_send_all_state_event(FsmRef, {send, Packet}).
|
gen_fsm:sync_send_all_state_event(FsmRef, {send, Packet}).
|
||||||
|
|
||||||
setopts({http_bind, FsmRef}, Opts) ->
|
setopts({http_bind, FsmRef, _IP}, Opts) ->
|
||||||
case lists:member({active, once}, Opts) of
|
case lists:member({active, once}, Opts) of
|
||||||
true ->
|
true ->
|
||||||
gen_fsm:send_all_state_event(FsmRef, {activate, self()});
|
gen_fsm:send_all_state_event(FsmRef, {activate, self()});
|
||||||
@ -112,19 +113,14 @@ setopts({http_bind, FsmRef}, Opts) ->
|
|||||||
controlling_process(_Socket, _Pid) ->
|
controlling_process(_Socket, _Pid) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
close({http_bind, FsmRef}) ->
|
close({http_bind, FsmRef, _IP}) ->
|
||||||
catch gen_fsm:sync_send_all_state_event(FsmRef, stop).
|
catch gen_fsm:sync_send_all_state_event(FsmRef, stop).
|
||||||
|
|
||||||
sockname(_Socket) ->
|
sockname(_Socket) ->
|
||||||
{ok, ?NULL_PEER}.
|
{ok, ?NULL_PEER}.
|
||||||
|
|
||||||
peername({http_bind, FsmRef}) ->
|
peername({http_bind, _FsmRef, IP}) ->
|
||||||
case catch gen_fsm:sync_send_all_state_event(FsmRef, peername, 1000) of
|
{ok, IP}.
|
||||||
{ok, IP} -> {ok, IP};
|
|
||||||
_ -> {ok, ?NULL_PEER}
|
|
||||||
end;
|
|
||||||
peername(_) ->
|
|
||||||
{ok, ?NULL_PEER}.
|
|
||||||
|
|
||||||
process_request(Data, IP) ->
|
process_request(Data, IP) ->
|
||||||
case catch parse_request(Data) of
|
case catch parse_request(Data) of
|
||||||
@ -137,7 +133,7 @@ process_request(Data, IP) ->
|
|||||||
XmppDomain ->
|
XmppDomain ->
|
||||||
%% create new session
|
%% create new session
|
||||||
Sid = sha:sha(term_to_binary({now(), make_ref()})),
|
Sid = sha:sha(term_to_binary({now(), make_ref()})),
|
||||||
{ok, Pid} = start(Sid, ""),
|
{ok, Pid} = start(Sid, "", IP),
|
||||||
?DEBUG("got pid: ~p", [Pid]),
|
?DEBUG("got pid: ~p", [Pid]),
|
||||||
Wait = case
|
Wait = case
|
||||||
string:to_integer(xml:get_attr_s("wait",Attrs))
|
string:to_integer(xml:get_attr_s("wait",Attrs))
|
||||||
@ -219,8 +215,8 @@ process_request(Data, IP) ->
|
|||||||
%% ignore |
|
%% ignore |
|
||||||
%% {stop, StopReason}
|
%% {stop, StopReason}
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
init([Sid, Key]) ->
|
init([Sid, Key, IP]) ->
|
||||||
?DEBUG("started: ~p", [{Sid, Key}]),
|
?DEBUG("started: ~p", [{Sid, Key, IP}]),
|
||||||
|
|
||||||
%% Read c2s options from the first ejabberd_c2s configuration in
|
%% Read c2s options from the first ejabberd_c2s configuration in
|
||||||
%% the config file listen section
|
%% the config file listen section
|
||||||
@ -230,12 +226,12 @@ init([Sid, Key]) ->
|
|||||||
%% connector.
|
%% connector.
|
||||||
Opts = ejabberd_c2s_config:get_c2s_limits(),
|
Opts = ejabberd_c2s_config:get_c2s_limits(),
|
||||||
|
|
||||||
ejabberd_socket:start(ejabberd_c2s, ?MODULE, {http_bind, self()}, Opts),
|
Socket = {http_bind, self(), IP},
|
||||||
% {ok, C2SPid} = ejabberd_c2s:start({?MODULE, {http_bind, self()}}, Opts),
|
ejabberd_socket:start(ejabberd_c2s, ?MODULE, Socket, Opts),
|
||||||
% ejabberd_c2s:become_controller(C2SPid),
|
|
||||||
Timer = erlang:start_timer(?MAX_INACTIVITY, self(), []),
|
Timer = erlang:start_timer(?MAX_INACTIVITY, self(), []),
|
||||||
{ok, loop, #state{id = Sid,
|
{ok, loop, #state{id = Sid,
|
||||||
key = Key,
|
key = Key,
|
||||||
|
socket = Socket,
|
||||||
timer = Timer}}.
|
timer = Timer}}.
|
||||||
|
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
@ -272,7 +268,7 @@ handle_event({activate, From}, StateName, StateData) ->
|
|||||||
waiting_input = {From, ok}}};
|
waiting_input = {From, ok}}};
|
||||||
Input ->
|
Input ->
|
||||||
Receiver = From,
|
Receiver = From,
|
||||||
Receiver ! {tcp, {http_bind, self()}, list_to_binary(Input)},
|
Receiver ! {tcp, StateData#state.socket, list_to_binary(Input)},
|
||||||
{next_state, StateName, StateData#state{
|
{next_state, StateName, StateData#state{
|
||||||
input = "",
|
input = "",
|
||||||
waiting_input = false,
|
waiting_input = false,
|
||||||
@ -495,7 +491,7 @@ handle_sync_event({http_put, Rid, Attrs, Payload, Hold, StreamTo, IP},
|
|||||||
Payload
|
Payload
|
||||||
end,
|
end,
|
||||||
?DEBUG("really sending now: ~s", [SendPacket]),
|
?DEBUG("really sending now: ~s", [SendPacket]),
|
||||||
Receiver ! {tcp, {http_bind, self()},
|
Receiver ! {tcp, StateData#state.socket,
|
||||||
list_to_binary(SendPacket)},
|
list_to_binary(SendPacket)},
|
||||||
Reply = ok,
|
Reply = ok,
|
||||||
{reply, Reply, StateName,
|
{reply, Reply, StateName,
|
||||||
@ -689,9 +685,9 @@ terminate(_Reason, _StateName, StateData) ->
|
|||||||
false ->
|
false ->
|
||||||
case StateData#state.last_receiver of
|
case StateData#state.last_receiver of
|
||||||
undefined -> ok;
|
undefined -> ok;
|
||||||
Receiver -> Receiver ! {tcp_closed, {http_bind, self()}}
|
Receiver -> Receiver ! {tcp_closed, StateData#state.socket}
|
||||||
end;
|
end;
|
||||||
{Receiver, _Tag} -> Receiver ! {tcp_closed, {http_bind, self()}}
|
{Receiver, _Tag} -> Receiver ! {tcp_closed, StateData#state.socket}
|
||||||
end,
|
end,
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user