mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
[TECH-1151] IP now correctly stored
This commit is contained in:
parent
0987700a27
commit
b44c462b0e
@ -420,6 +420,7 @@ process_request(#state{request_method = Method,
|
|||||||
Ws = #ws{socket = Socket,
|
Ws = #ws{socket = Socket,
|
||||||
sockmod = SockMod,
|
sockmod = SockMod,
|
||||||
ws_autoexit = true,
|
ws_autoexit = true,
|
||||||
|
ip = IP,
|
||||||
path = LPath,
|
path = LPath,
|
||||||
vsn = VSN,
|
vsn = VSN,
|
||||||
host = Host,
|
host = Host,
|
||||||
|
@ -39,9 +39,7 @@
|
|||||||
socket, % the socket handling the request
|
socket, % the socket handling the request
|
||||||
sockmod, % gen_tcp | tls
|
sockmod, % gen_tcp | tls
|
||||||
ws_autoexit, % websocket process is automatically killed: true | false
|
ws_autoexit, % websocket process is automatically killed: true | false
|
||||||
peer_addr, % peer IP | undefined
|
ip, % peer IP | undefined
|
||||||
peer_port, % peer port | undefined
|
|
||||||
peer_cert, % undefined | the DER encoded peer certificate that can be decoded with public_key:pkix_decode_cert/2
|
|
||||||
vsn, % {Maj,Min} | {'draft-hixie', Ver}
|
vsn, % {Maj,Min} | {'draft-hixie', Ver}
|
||||||
origin, % the originator
|
origin, % the originator
|
||||||
host, % the host
|
host, % the host
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
setopts/2,
|
setopts/2,
|
||||||
sockname/1, peername/1,
|
sockname/1, peername/1,
|
||||||
controlling_process/2,
|
controlling_process/2,
|
||||||
|
become_controller/2,
|
||||||
close/1]).
|
close/1]).
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
@ -108,8 +109,6 @@ close({http_ws, FsmRef, _IP}) ->
|
|||||||
|
|
||||||
|
|
||||||
init([WS]) ->
|
init([WS]) ->
|
||||||
?INFO_MSG("started: ~p", [WS]),
|
|
||||||
|
|
||||||
%% 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
|
||||||
%% TODO: We should have different access and shaper values for
|
%% TODO: We should have different access and shaper values for
|
||||||
@ -125,7 +124,8 @@ init([WS]) ->
|
|||||||
undefined -> ?WEBSOCKET_TIMEOUT
|
undefined -> ?WEBSOCKET_TIMEOUT
|
||||||
end,
|
end,
|
||||||
|
|
||||||
Socket = {http_ws, self(), {{127,0,0,1}, 5280}}, %FIXME
|
Socket = {http_ws, self(), WS:get(ip)},
|
||||||
|
?DEBUG("Client connected through websocket ~p", [Socket]),
|
||||||
ejabberd_socket:start(ejabberd_c2s, ?MODULE, Socket, Opts),
|
ejabberd_socket:start(ejabberd_c2s, ?MODULE, Socket, Opts),
|
||||||
Timer = erlang:start_timer(WSTimeout, self(), []),
|
Timer = erlang:start_timer(WSTimeout, self(), []),
|
||||||
{ok, loop, #state{
|
{ok, loop, #state{
|
||||||
@ -164,23 +164,20 @@ handle_sync_event(close, _From, _StateName, StateData) ->
|
|||||||
{stop, normal, Reply, StateData}.
|
{stop, normal, Reply, StateData}.
|
||||||
|
|
||||||
handle_info({browser, Packet}, StateName, StateData)->
|
handle_info({browser, Packet}, StateName, StateData)->
|
||||||
case StateData#state.waiting_input of
|
NewState = case StateData#state.waiting_input of
|
||||||
false ->
|
false ->
|
||||||
Input = [StateData#state.input|Packet],
|
Input = [StateData#state.input|Packet],
|
||||||
Reply = ok,
|
StateData#state{input = Input};
|
||||||
{reply, Reply, StateName, StateData#state{input = Input}};
|
|
||||||
{Receiver, _Tag} ->
|
{Receiver, _Tag} ->
|
||||||
Receiver ! {tcp, StateData#state.socket,
|
Receiver ! {tcp, StateData#state.socket,
|
||||||
list_to_binary(Packet)},
|
list_to_binary(Packet)},
|
||||||
cancel_timer(StateData#state.timer),
|
cancel_timer(StateData#state.timer),
|
||||||
Timer = erlang:start_timer(StateData#state.timeout, self(), []),
|
Timer = erlang:start_timer(StateData#state.timeout, self(), []),
|
||||||
Reply = ok,
|
StateData#state{waiting_input = false,
|
||||||
{reply, Reply, StateName,
|
|
||||||
StateData#state{waiting_input = false,
|
|
||||||
last_receiver = Receiver,
|
last_receiver = Receiver,
|
||||||
timer = Timer}}
|
timer = Timer}
|
||||||
end,
|
end,
|
||||||
{next_state, StateName, StateData};
|
{next_state, StateName, NewState};
|
||||||
|
|
||||||
|
|
||||||
handle_info({timeout, Timer, _}, _StateName,
|
handle_info({timeout, Timer, _}, _StateName,
|
||||||
|
@ -55,7 +55,7 @@ check(_Path, Headers)->
|
|||||||
is_acceptable(#ws{origin=Origin, protocol=Protocol,
|
is_acceptable(#ws{origin=Origin, protocol=Protocol,
|
||||||
headers = Headers, acceptable_origins = Origins})->
|
headers = Headers, acceptable_origins = Origins})->
|
||||||
ClientProtocol = lists:keyfind("Sec-WebSocket-Protocol",1, Headers),
|
ClientProtocol = lists:keyfind("Sec-WebSocket-Protocol",1, Headers),
|
||||||
case {Origin == [] or lists:member(Origin, Origins), ClientProtocol, Protocol } of
|
case {(Origin == []) or lists:member(Origin, Origins), ClientProtocol, Protocol } of
|
||||||
{false, _, _} ->
|
{false, _, _} ->
|
||||||
?DEBUG("client does not come from authorized origin", []),
|
?DEBUG("client does not come from authorized origin", []),
|
||||||
false;
|
false;
|
||||||
|
@ -54,12 +54,8 @@ get(socket) ->
|
|||||||
Ws#ws.socket;
|
Ws#ws.socket;
|
||||||
get(socket_mode) ->
|
get(socket_mode) ->
|
||||||
Ws#ws.sockmod;
|
Ws#ws.sockmod;
|
||||||
get(peer_addr) ->
|
get(ip) ->
|
||||||
Ws#ws.peer_addr;
|
Ws#ws.ip;
|
||||||
get(peer_port) ->
|
|
||||||
Ws#ws.peer_port;
|
|
||||||
get(peer_cert) ->
|
|
||||||
Ws#ws.peer_cert;
|
|
||||||
get(vsn) ->
|
get(vsn) ->
|
||||||
Ws#ws.vsn;
|
Ws#ws.vsn;
|
||||||
get(origin) ->
|
get(origin) ->
|
||||||
|
Loading…
Reference in New Issue
Block a user