24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-07-04 23:15:31 +02:00

[TECH-1151] IP now correctly stored

This commit is contained in:
Eric Cestari 2010-09-17 14:49:04 +02:00
parent 0987700a27
commit b44c462b0e
5 changed files with 13 additions and 21 deletions

View File

@ -420,6 +420,7 @@ process_request(#state{request_method = Method,
Ws = #ws{socket = Socket,
sockmod = SockMod,
ws_autoexit = true,
ip = IP,
path = LPath,
vsn = VSN,
host = Host,

View File

@ -39,9 +39,7 @@
socket, % the socket handling the request
sockmod, % gen_tcp | tls
ws_autoexit, % websocket process is automatically killed: true | false
peer_addr, % 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
ip, % peer IP | undefined
vsn, % {Maj,Min} | {'draft-hixie', Ver}
origin, % the originator
host, % the host

View File

@ -43,6 +43,7 @@
setopts/2,
sockname/1, peername/1,
controlling_process/2,
become_controller/2,
close/1]).
-include("ejabberd.hrl").
@ -108,8 +109,6 @@ close({http_ws, FsmRef, _IP}) ->
init([WS]) ->
?INFO_MSG("started: ~p", [WS]),
%% Read c2s options from the first ejabberd_c2s configuration in
%% the config file listen section
%% TODO: We should have different access and shaper values for
@ -125,7 +124,8 @@ init([WS]) ->
undefined -> ?WEBSOCKET_TIMEOUT
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),
Timer = erlang:start_timer(WSTimeout, self(), []),
{ok, loop, #state{
@ -164,23 +164,20 @@ handle_sync_event(close, _From, _StateName, StateData) ->
{stop, normal, Reply, StateData}.
handle_info({browser, Packet}, StateName, StateData)->
case StateData#state.waiting_input of
NewState = case StateData#state.waiting_input of
false ->
Input = [StateData#state.input|Packet],
Reply = ok,
{reply, Reply, StateName, StateData#state{input = Input}};
StateData#state{input = Input};
{Receiver, _Tag} ->
Receiver ! {tcp, StateData#state.socket,
list_to_binary(Packet)},
cancel_timer(StateData#state.timer),
Timer = erlang:start_timer(StateData#state.timeout, self(), []),
Reply = ok,
{reply, Reply, StateName,
StateData#state{waiting_input = false,
StateData#state{waiting_input = false,
last_receiver = Receiver,
timer = Timer}}
timer = Timer}
end,
{next_state, StateName, StateData};
{next_state, StateName, NewState};
handle_info({timeout, Timer, _}, _StateName,

View File

@ -55,7 +55,7 @@ check(_Path, Headers)->
is_acceptable(#ws{origin=Origin, protocol=Protocol,
headers = Headers, acceptable_origins = Origins})->
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, _, _} ->
?DEBUG("client does not come from authorized origin", []),
false;

View File

@ -54,12 +54,8 @@ get(socket) ->
Ws#ws.socket;
get(socket_mode) ->
Ws#ws.sockmod;
get(peer_addr) ->
Ws#ws.peer_addr;
get(peer_port) ->
Ws#ws.peer_port;
get(peer_cert) ->
Ws#ws.peer_cert;
get(ip) ->
Ws#ws.ip;
get(vsn) ->
Ws#ws.vsn;
get(origin) ->