24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-16 22:05:29 +02:00

* src/web/ejabberd_http.hrl: Added "ip" field in the "request"

record
* src/web/ejabberd_http.erl: Likewise

SVN Revision: 762
This commit is contained in:
Alexey Shchepin 2007-05-07 15:47:33 +00:00
parent 372944df6c
commit 32613987a8
3 changed files with 34 additions and 20 deletions

View File

@ -1,3 +1,9 @@
2007-05-07 Alexey Shchepin <alexey@sevcom.net>
* src/web/ejabberd_http.hrl: Added "ip" field in the "request"
record
* src/web/ejabberd_http.erl: Likewise
2007-05-03 Alexey Shchepin <alexey@sevcom.net> 2007-05-03 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_sm.erl: Added set_presence_hook * src/ejabberd_sm.erl: Added set_presence_hook

View File

@ -1,7 +1,7 @@
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% File : ejabberd_http.erl %%% File : ejabberd_http.erl
%%% Author : Alexey Shchepin <alexey@sevcom.net> %%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose : %%% Purpose :
%%% Created : 27 Feb 2004 by Alexey Shchepin <alexey@sevcom.net> %%% Created : 27 Feb 2004 by Alexey Shchepin <alexey@sevcom.net>
%%% Id : $Id$ %%% Id : $Id$
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -82,7 +82,7 @@ start_link({SockMod, Socket}, Opts) ->
%% XXX bard: for backward compatibility: expand web_admin and %% XXX bard: for backward compatibility: expand web_admin and
%% http_poll in Opts respectively to {["admin"], %% http_poll in Opts respectively to {["admin"],
%% ejabberd_web_admin} and {["http-poll"], ejabberd_http_poll} %% ejabberd_web_admin} and {["http-poll"], ejabberd_http_poll}
RequestHandlers = RequestHandlers =
case lists:keysearch(request_handlers, 1, Opts) of case lists:keysearch(request_handlers, 1, Opts) of
{value, {request_handlers, H}} -> H; {value, {request_handlers, H}} -> H;
@ -253,7 +253,9 @@ process_request(#state{request_method = 'GET',
request_path = {abs_path, Path}, request_path = {abs_path, Path},
request_auth = Auth, request_auth = Auth,
request_lang = Lang, request_lang = Lang,
request_handlers = RequestHandlers} = State) -> request_handlers = RequestHandlers,
sockmod = SockMod,
socket = Socket} = State) ->
case (catch url_decode_q_split(Path)) of case (catch url_decode_q_split(Path)) of
{'EXIT', _} -> {'EXIT', _} ->
process_request(false); process_request(false);
@ -265,11 +267,19 @@ process_request(#state{request_method = 'GET',
LQ LQ
end, end,
LPath = string:tokens(NPath, "/"), LPath = string:tokens(NPath, "/"),
{ok, {IP, _Port}} =
case SockMod of
gen_tcp ->
inet:peername(Socket);
_ ->
SockMod:peername(Socket)
end,
Request = #request{method = 'GET', Request = #request{method = 'GET',
path = LPath, path = LPath,
q = LQuery, q = LQuery,
auth = Auth, auth = Auth,
lang = Lang}, lang = Lang,
ip=IP},
%% XXX bard: This previously passed control to %% XXX bard: This previously passed control to
%% ejabberd_web:process_get, now passes it to a local %% ejabberd_web:process_get, now passes it to a local
%% procedure (process) that handles dispatching based on %% procedure (process) that handles dispatching based on
@ -335,7 +345,7 @@ process_request(#state{request_method = 'POST',
end; end;
process_request(State) -> process_request(State) ->
make_xhtml_output(State, make_xhtml_output(State,
400, 400,
[], [],
ejabberd_web:make_xhtml([{xmlelement, "h1", [], ejabberd_web:make_xhtml([{xmlelement, "h1", [],
@ -383,9 +393,9 @@ make_xhtml_output(State, Status, Headers, XHTML) ->
HeadersOut = case {State#state.request_version, HeadersOut = case {State#state.request_version,
State#state.request_keepalive} of State#state.request_keepalive} of
{{1, 1}, true} -> Headers1; {{1, 1}, true} -> Headers1;
{_, true} -> {_, true} ->
[{"Connection", "keep-alive"} | Headers1]; [{"Connection", "keep-alive"} | Headers1];
{_, false} -> {_, false} ->
% not required for http versions < 1.1 % not required for http versions < 1.1
% but would make no harm % but would make no harm
[{"Connection", "close"} | Headers1] [{"Connection", "close"} | Headers1]
@ -395,7 +405,7 @@ make_xhtml_output(State, Status, Headers, XHTML) ->
{1, 1} -> "HTTP/1.1 "; {1, 1} -> "HTTP/1.1 ";
_ -> "HTTP/1.0 " _ -> "HTTP/1.0 "
end, end,
H = lists:map(fun({Attr, Val}) -> H = lists:map(fun({Attr, Val}) ->
[Attr, ": ", Val, "\r\n"]; [Attr, ": ", Val, "\r\n"];
(_) -> (_) ->
@ -422,9 +432,9 @@ make_text_output(State, Status, Headers, Data) when is_binary(Data) ->
HeadersOut = case {State#state.request_version, HeadersOut = case {State#state.request_version,
State#state.request_keepalive} of State#state.request_keepalive} of
{{1, 1}, true} -> Headers1; {{1, 1}, true} -> Headers1;
{_, true} -> {_, true} ->
[{"Connection", "keep-alive"} | Headers1]; [{"Connection", "keep-alive"} | Headers1];
{_, false} -> {_, false} ->
% not required for http versions < 1.1 % not required for http versions < 1.1
% but would make no harm % but would make no harm
[{"Connection", "close"} | Headers1] [{"Connection", "close"} | Headers1]
@ -533,7 +543,7 @@ start_dir(N, Path, "./" ++ T ) -> start_dir(N , Path, T);
start_dir(N, Path, "../" ++ T ) -> start_dir(N + 1, Path, T); start_dir(N, Path, "../" ++ T ) -> start_dir(N + 1, Path, T);
start_dir(N, Path, T ) -> rest_dir (N , Path, T). start_dir(N, Path, T ) -> rest_dir (N , Path, T).
rest_dir (_N, Path, [] ) -> case Path of rest_dir (_N, Path, [] ) -> case Path of
[] -> "/"; [] -> "/";
_ -> Path _ -> Path
end; end;
@ -761,7 +771,7 @@ get_req(Data) ->
{FirstLine, Trail} = lists:splitwith(fun not_eol/1, Data), {FirstLine, Trail} = lists:splitwith(fun not_eol/1, Data),
R = parse_req(FirstLine), R = parse_req(FirstLine),
{R, Trail}. {R, Trail}.
not_eol($\r)-> not_eol($\r)->
false; false;
@ -940,11 +950,11 @@ drop_spaces(YS=[X|XS]) ->
is_nb_space(X) -> is_nb_space(X) ->
lists:member(X, [$\s, $\t]). lists:member(X, [$\s, $\t]).
% ret: {line, Line, Trail} | {lastline, Line, Trail} % ret: {line, Line, Trail} | {lastline, Line, Trail}
get_line(L) -> get_line(L) ->
get_line(L, []). get_line(L, []).
get_line("\r\n\r\n" ++ Tail, Cur) -> get_line("\r\n\r\n" ++ Tail, Cur) ->
{lastline, lists:reverse(Cur), Tail}; {lastline, lists:reverse(Cur), Tail};
@ -954,7 +964,7 @@ get_line("\r\n" ++ Tail, Cur) ->
{incomplete, lists:reverse(Cur) ++ "\r\n"}; {incomplete, lists:reverse(Cur) ++ "\r\n"};
_ -> _ ->
case is_nb_space(hd(Tail)) of case is_nb_space(hd(Tail)) of
true -> %% multiline ... continue true -> %% multiline ... continue
get_line(Tail, [$\n, $\r | Cur]); get_line(Tail, [$\n, $\r | Cur]);
false -> false ->
{line, lists:reverse(Cur), Tail} {line, lists:reverse(Cur), Tail}
@ -962,4 +972,3 @@ get_line("\r\n" ++ Tail, Cur) ->
end; end;
get_line([H|T], Cur) -> get_line([H|T], Cur) ->
get_line(T, [H|Cur]). get_line(T, [H|Cur]).

View File

@ -1,7 +1,7 @@
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
%%% File : ejabberd_http.hrl %%% File : ejabberd_http.hrl
%%% Author : Alexey Shchepin <alexey@sevcom.net> %%% Author : Alexey Shchepin <alexey@sevcom.net>
%%% Purpose : %%% Purpose :
%%% Created : 4 Mar 2004 by Alexey Shchepin <alexey@sevcom.net> %%% Created : 4 Mar 2004 by Alexey Shchepin <alexey@sevcom.net>
%%% Id : $Id$ %%% Id : $Id$
%%%---------------------------------------------------------------------- %%%----------------------------------------------------------------------
@ -12,7 +12,6 @@
us, us,
auth, auth,
lang = "", lang = "",
data = "" data = "",
ip
}). }).