mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Retrieve correct IP from http connection (thanks to Christohpe Romain)
SVN Revision: 2240
This commit is contained in:
parent
44c2259a43
commit
2d9f715d65
@ -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 457 2007-12-21 19:55:21Z badlop $
|
%%% Id : $Id: ejabberd_http_bind.erl 674 2008-07-03 15:58:15Z cromain $
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
-module(ejabberd_http_bind).
|
-module(ejabberd_http_bind).
|
||||||
@ -26,7 +26,7 @@
|
|||||||
peername/1,
|
peername/1,
|
||||||
controlling_process/2,
|
controlling_process/2,
|
||||||
close/1,
|
close/1,
|
||||||
process_request/1]).
|
process_request/2]).
|
||||||
|
|
||||||
%%-define(ejabberd_debug, true).
|
%%-define(ejabberd_debug, true).
|
||||||
|
|
||||||
@ -36,6 +36,8 @@
|
|||||||
|
|
||||||
-record(http_bind, {id, pid, to, hold, wait, version}).
|
-record(http_bind, {id, pid, to, hold, wait, version}).
|
||||||
|
|
||||||
|
-define(NULL_PEER, {{0, 0, 0, 0}, 0}).
|
||||||
|
|
||||||
%% http binding request
|
%% http binding request
|
||||||
-record(hbr, {rid,
|
-record(hbr, {rid,
|
||||||
key,
|
key,
|
||||||
@ -55,7 +57,8 @@
|
|||||||
ctime = 0,
|
ctime = 0,
|
||||||
timer,
|
timer,
|
||||||
pause=0,
|
pause=0,
|
||||||
req_list = [] % list of requests
|
req_list = [], % list of requests
|
||||||
|
ip = ?NULL_PEER
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
|
||||||
@ -113,12 +116,19 @@ close({http_bind, FsmRef}) ->
|
|||||||
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, {{0, 0, 0, 0}, 0}}.
|
{ok, ?NULL_PEER}.
|
||||||
|
|
||||||
peername(_Socket) ->
|
peername({http_bind, FsmRef}) ->
|
||||||
{ok, {{0, 0, 0, 0}, 0}}.
|
gen_fsm:send_all_state_event(FsmRef, {peername, self()}),
|
||||||
|
%% XXX should improve that, but sync call seems not possible
|
||||||
|
receive
|
||||||
|
{peername, PeerName} -> {ok, PeerName}
|
||||||
|
after 1000 -> {ok, ?NULL_PEER}
|
||||||
|
end;
|
||||||
|
peername(_) ->
|
||||||
|
{ok, ?NULL_PEER}.
|
||||||
|
|
||||||
process_request(Data) ->
|
process_request(Data, IP) ->
|
||||||
case catch parse_request(Data) of
|
case catch parse_request(Data) of
|
||||||
{ok, {"", Rid, Attrs, Payload}} ->
|
{ok, {"", Rid, Attrs, Payload}} ->
|
||||||
case xml:get_attr_s("to",Attrs) of
|
case xml:get_attr_s("to",Attrs) of
|
||||||
@ -177,7 +187,7 @@ process_request(Data) ->
|
|||||||
version = Version
|
version = Version
|
||||||
})
|
})
|
||||||
end),
|
end),
|
||||||
handle_http_put(Sid, Rid, Attrs, Payload, true)
|
handle_http_put(Sid, Rid, Attrs, Payload, true, IP)
|
||||||
end;
|
end;
|
||||||
{ok, {Sid, Rid, Attrs, Payload1}} ->
|
{ok, {Sid, Rid, Attrs, Payload1}} ->
|
||||||
%% old session
|
%% old session
|
||||||
@ -195,7 +205,7 @@ process_request(Data) ->
|
|||||||
_ ->
|
_ ->
|
||||||
Payload1
|
Payload1
|
||||||
end,
|
end,
|
||||||
handle_http_put(Sid, Rid, Attrs, Payload2, StreamStart);
|
handle_http_put(Sid, Rid, Attrs, Payload2, StreamStart, IP);
|
||||||
_ ->
|
_ ->
|
||||||
{400, ?HEADER, ""}
|
{400, ?HEADER, ""}
|
||||||
end.
|
end.
|
||||||
@ -271,6 +281,10 @@ handle_event({activate, From}, StateName, StateData) ->
|
|||||||
last_receiver = Receiver}}
|
last_receiver = Receiver}}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
handle_event({peername, From}, StateName, StateData) ->
|
||||||
|
From ! {peername, StateData#state.ip},
|
||||||
|
{next_state, StateName, StateData};
|
||||||
|
|
||||||
handle_event(_Event, StateName, StateData) ->
|
handle_event(_Event, StateName, StateData) ->
|
||||||
{next_state, StateName, StateData}.
|
{next_state, StateName, StateData}.
|
||||||
|
|
||||||
@ -329,7 +343,7 @@ handle_sync_event(stop, _From, _StateName, StateData) ->
|
|||||||
Reply = ok,
|
Reply = ok,
|
||||||
{stop, normal, Reply, StateData};
|
{stop, normal, Reply, StateData};
|
||||||
|
|
||||||
handle_sync_event({http_put, Rid, Attrs, Payload, Hold, StreamTo},
|
handle_sync_event({http_put, Rid, Attrs, Payload, Hold, StreamTo, IP},
|
||||||
_From, StateName, StateData) ->
|
_From, StateName, StateData) ->
|
||||||
Key = xml:get_attr_s("key", Attrs),
|
Key = xml:get_attr_s("key", Attrs),
|
||||||
NewKey = xml:get_attr_s("newkey", Attrs),
|
NewKey = xml:get_attr_s("newkey", Attrs),
|
||||||
@ -466,7 +480,8 @@ handle_sync_event({http_put, Rid, Attrs, Payload, Hold, StreamTo},
|
|||||||
timer = Timer,
|
timer = Timer,
|
||||||
pause = Pause,
|
pause = Pause,
|
||||||
last_poll = LastPoll,
|
last_poll = LastPoll,
|
||||||
req_list = ReqList
|
req_list = ReqList,
|
||||||
|
ip = IP
|
||||||
}};
|
}};
|
||||||
{Receiver, _Tag} ->
|
{Receiver, _Tag} ->
|
||||||
SendPacket =
|
SendPacket =
|
||||||
@ -499,7 +514,8 @@ handle_sync_event({http_put, Rid, Attrs, Payload, Hold, StreamTo},
|
|||||||
timer = Timer,
|
timer = Timer,
|
||||||
pause = Pause,
|
pause = Pause,
|
||||||
last_poll = LastPoll,
|
last_poll = LastPoll,
|
||||||
req_list = ReqList
|
req_list = ReqList,
|
||||||
|
ip = IP
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
@ -685,8 +701,8 @@ terminate(_Reason, _StateName, StateData) ->
|
|||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
handle_http_put(Sid, Rid, Attrs, Payload, StreamStart) ->
|
handle_http_put(Sid, Rid, Attrs, Payload, StreamStart, IP) ->
|
||||||
case http_put(Sid, Rid, Attrs, Payload, StreamStart) of
|
case http_put(Sid, Rid, Attrs, Payload, StreamStart, IP) of
|
||||||
{error, not_exists} ->
|
{error, not_exists} ->
|
||||||
?DEBUG("no session associated with sid: ~p", [Sid]),
|
?DEBUG("no session associated with sid: ~p", [Sid]),
|
||||||
{404, ?HEADER, ""};
|
{404, ?HEADER, ""};
|
||||||
@ -700,7 +716,7 @@ handle_http_put(Sid, Rid, Attrs, Payload, StreamStart) ->
|
|||||||
prepare_response(Sess, Rid, Attrs, StreamStart)
|
prepare_response(Sess, Rid, Attrs, StreamStart)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
http_put(Sid, Rid, Attrs, Payload, StreamStart) ->
|
http_put(Sid, Rid, Attrs, Payload, StreamStart, IP) ->
|
||||||
?DEBUG("http-put",[]),
|
?DEBUG("http-put",[]),
|
||||||
case mnesia:dirty_read({http_bind, Sid}) of
|
case mnesia:dirty_read({http_bind, Sid}) of
|
||||||
[] ->
|
[] ->
|
||||||
@ -714,7 +730,7 @@ http_put(Sid, Rid, Attrs, Payload, StreamStart) ->
|
|||||||
""
|
""
|
||||||
end,
|
end,
|
||||||
{gen_fsm:sync_send_all_state_event(
|
{gen_fsm:sync_send_all_state_event(
|
||||||
FsmRef, {http_put, Rid, Attrs, Payload, Hold, NewStream}), Sess}
|
FsmRef, {http_put, Rid, Attrs, Payload, Hold, NewStream, IP}), Sess}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
handle_http_put_error(Reason, #http_bind{pid=FsmRef, version=Version})
|
handle_http_put_error(Reason, #http_bind{pid=FsmRef, version=Version})
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
%%% Author : Stefan Strigler <steve@zeank.in-berlin.de>
|
%%% Author : Stefan Strigler <steve@zeank.in-berlin.de>
|
||||||
%%% Purpose : Implementation of XMPP over BOSH (XEP-0206)
|
%%% Purpose : Implementation of XMPP over BOSH (XEP-0206)
|
||||||
%%% Created : Tue Feb 20 13:15:52 CET 2007
|
%%% Created : Tue Feb 20 13:15:52 CET 2007
|
||||||
%%% Id : $Id: mod_http_bind.erl 669 2008-06-30 13:08:16Z jsautret $
|
%%% Id : $Id: mod_http_bind.erl 674 2008-07-03 15:58:15Z cromain $
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
|
|
||||||
%%%----------------------------------------------------------------------
|
%%%----------------------------------------------------------------------
|
||||||
@ -42,9 +42,10 @@ process([], #request{method = 'POST',
|
|||||||
{400, [], {xmlelement, "h1", [],
|
{400, [], {xmlelement, "h1", [],
|
||||||
[{xmlcdata, "400 Bad Request"}]}};
|
[{xmlcdata, "400 Bad Request"}]}};
|
||||||
process([], #request{method = 'POST',
|
process([], #request{method = 'POST',
|
||||||
data = Data}) ->
|
data = Data,
|
||||||
|
ip = IP}) ->
|
||||||
?DEBUG("Incoming data: ~s", [Data]),
|
?DEBUG("Incoming data: ~s", [Data]),
|
||||||
ejabberd_http_bind:process_request(Data);
|
ejabberd_http_bind:process_request(Data, IP);
|
||||||
process([], #request{method = 'GET',
|
process([], #request{method = 'GET',
|
||||||
data = []}) ->
|
data = []}) ->
|
||||||
Heading = "Ejabberd " ++ atom_to_list(?MODULE) ++ " v" ++ ?MOD_HTTP_BIND_VERSION,
|
Heading = "Ejabberd " ++ atom_to_list(?MODULE) ++ " v" ++ ?MOD_HTTP_BIND_VERSION,
|
||||||
|
Loading…
Reference in New Issue
Block a user