* src/web/ejabberd_http.erl: Fixed processing of POST body for

HTTP Polling

* src/web/ejabberd_http.erl: Support for "Connection" HTTP header
(thanks to Sergei Golovan)

* src/translate.erl: Much better handling of xml:lang (thanks to
Sergei Golovan)

SVN Revision: 271
This commit is contained in:
Alexey Shchepin 2004-09-30 21:54:39 +00:00
parent db824bfc64
commit 34de660c44
3 changed files with 109 additions and 57 deletions

View File

@ -1,3 +1,14 @@
2004-09-30 Alexey Shchepin <alexey@sevcom.net>
* src/web/ejabberd_http.erl: Fixed processing of POST body for
HTTP Polling
* src/web/ejabberd_http.erl: Support for "Connection" HTTP header
(thanks to Sergei Golovan)
* src/translate.erl: Much better handling of xml:lang (thanks to
Sergei Golovan)
2004-09-29 Alexey Shchepin <alexey@sevcom.net> 2004-09-29 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_listener.erl: Check result of controlling_process * src/ejabberd_listener.erl: Check result of controlling_process

View File

@ -40,16 +40,18 @@ load_dir(Dir) ->
fun(FN) -> fun(FN) ->
case string:len(FN) > 4 of case string:len(FN) > 4 of
true -> true ->
string:substr(FN, string:substr(
string:len(FN) - 3) == ".msg"; FN,
string:len(FN) - 3) == ".msg";
_ -> _ ->
false false
end end
end, Files), end, Files),
lists:foreach( lists:foreach(
fun(FN) -> fun(FN) ->
load_file(string:substr(FN, 1, string:len(FN) - 4), L = ascii_tolower(
Dir ++ "/" ++ FN) string:substr(FN, 1, string:len(FN) - 4)),
load_file(L, Dir ++ "/" ++ FN)
end, MsgFiles), end, MsgFiles),
ok; ok;
{error, Reason} -> {error, Reason} ->
@ -74,15 +76,21 @@ load_file(Lang, File) ->
end. end.
translate(Lang, Msg) -> translate(Lang, Msg) ->
case ets:lookup(translations, {Lang, Msg}) of LLang = ascii_tolower(Lang),
case ets:lookup(translations, {LLang, Msg}) of
[{_, Trans}] -> [{_, Trans}] ->
Trans; Trans;
_ -> _ ->
ShortLang = string:substr(Lang, 1, 2), ShortLang = case string:tokens(LLang, "-") of
[] ->
LLang;
[SL | _] ->
SL
end,
case ShortLang of case ShortLang of
"en" -> "en" ->
Msg; Msg;
Lang -> LLang ->
translate(Msg); translate(Msg);
_ -> _ ->
case ets:lookup(translations, {ShortLang, Msg}) of case ets:lookup(translations, {ShortLang, Msg}) of
@ -101,11 +109,17 @@ translate(Msg) ->
"en" -> "en" ->
Msg; Msg;
Lang -> Lang ->
case ets:lookup(translations, {Lang, Msg}) of LLang = ascii_tolower(Lang),
case ets:lookup(translations, {LLang, Msg}) of
[{_, Trans}] -> [{_, Trans}] ->
Trans; Trans;
_ -> _ ->
ShortLang = string:substr(Lang, 1, 2), ShortLang = case string:tokens(LLang, "-") of
[] ->
LLang;
[SL | _] ->
SL
end,
case ShortLang of case ShortLang of
"en" -> "en" ->
Msg; Msg;
@ -122,3 +136,10 @@ translate(Msg) ->
end end
end. end.
ascii_tolower([C | Cs]) when C >= $A, C =< $Z ->
[C + ($a - $A) | ascii_tolower(Cs)];
ascii_tolower([C | Cs]) ->
[C | ascii_tolower(Cs)];
ascii_tolower([]) ->
[].

View File

@ -25,6 +25,7 @@
request_version, request_version,
request_path, request_path,
request_auth, request_auth,
request_keepalive,
request_content_length, request_content_length,
request_lang = "en", request_lang = "en",
use_http_poll = false, use_http_poll = false,
@ -127,9 +128,26 @@ process_header(State, Data) ->
Socket = State#state.socket, Socket = State#state.socket,
case Data of case Data of
{ok, {http_request, Method, Path, Version}} -> {ok, {http_request, Method, Path, Version}} ->
KeepAlive = case Version of
{1, 1} ->
true;
_ ->
false
end,
State#state{request_method = Method, State#state{request_method = Method,
request_version = Version, request_version = Version,
request_path = Path}; request_path = Path,
request_keepalive = KeepAlive};
{ok, {http_header, _, 'Connection', _, Conn}} ->
KeepAlive1 = case Conn of
"keep-alive" ->
true;
"close" ->
false;
_ ->
State#state.request_keepalive
end,
State#state{request_keepalive = KeepAlive1};
{ok, {http_header, _, 'Authorization', _, Auth}} -> {ok, {http_header, _, 'Authorization', _, Auth}} ->
State#state{request_auth = parse_auth(Auth)}; State#state{request_auth = parse_auth(Auth)};
{ok, {http_header, _, 'Content-Length', _, SLen}} -> {ok, {http_header, _, 'Content-Length', _, SLen}} ->
@ -150,8 +168,8 @@ process_header(State, Data) ->
element(2, State#state.request_path)]), element(2, State#state.request_path)]),
Out = process_request(State), Out = process_request(State),
send_text(State, Out), send_text(State, Out),
case State#state.request_version of case State#state.request_keepalive of
{1,1} -> true ->
case SockMod of case SockMod of
gen_tcp -> gen_tcp ->
inet:setopts(Socket, [{packet, http}]); inet:setopts(Socket, [{packet, http}]);
@ -200,29 +218,30 @@ process_request(#state{request_method = 'GET',
{'EXIT', _} -> {'EXIT', _} ->
process_request(false); process_request(false);
{NPath, Query} -> {NPath, Query} ->
case (catch parse_urlencoded(Query)) of LQuery = case (catch parse_urlencoded(Query)) of
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
process_request(false); [];
LQuery -> LQ ->
LPath = string:tokens(NPath, "/"), LQ
Request = #request{method = 'GET', end,
path = LPath, LPath = string:tokens(NPath, "/"),
q = LQuery, Request = #request{method = 'GET',
user = User, path = LPath,
lang = Lang}, q = LQuery,
case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin}, user = User,
Request) of lang = Lang},
El when element(1, El) == xmlelement -> case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin},
make_xhtml_output(200, [], El); Request) of
{Status, Headers, El} when El when element(1, El) == xmlelement ->
element(1, El) == xmlelement -> make_xhtml_output(200, [], El);
make_xhtml_output(Status, Headers, El); {Status, Headers, El} when
Text when is_list(Text) -> element(1, El) == xmlelement ->
make_text_output(200, [], Text); make_xhtml_output(Status, Headers, El);
{Status, Headers, Text} when Text when is_list(Text) ->
is_list(Text) -> make_text_output(200, [], Text);
make_text_output(Status, Headers, Text) {Status, Headers, Text} when
end is_list(Text) ->
make_text_output(Status, Headers, Text)
end end
end end
end; end;
@ -269,28 +288,29 @@ process_request(#state{request_method = 'POST',
process_request(false); process_request(false);
{NPath, Query} -> {NPath, Query} ->
LPath = string:tokens(NPath, "/"), LPath = string:tokens(NPath, "/"),
case (catch parse_urlencoded(Data)) of LQuery = case (catch parse_urlencoded(Data)) of
{'EXIT', _Reason} -> {'EXIT', _Reason} ->
process_request(false); [];
LQuery -> LQ ->
Request = #request{method = 'POST', LQ
path = LPath, end,
q = LQuery, Request = #request{method = 'POST',
user = User, path = LPath,
data = Data, q = LQuery,
lang = Lang}, user = User,
case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin}, data = Data,
Request) of lang = Lang},
El when element(1, El) == xmlelement -> case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin},
make_xhtml_output(200, [], El); Request) of
{Status, Headers, El} when El when element(1, El) == xmlelement ->
element(1, El) == xmlelement -> make_xhtml_output(200, [], El);
make_xhtml_output(Status, Headers, El); {Status, Headers, El} when
Text when is_list(Text) -> element(1, El) == xmlelement ->
make_text_output(200, [], Text); make_xhtml_output(Status, Headers, El);
{Status, Headers, Text} when is_list(Text) -> Text when is_list(Text) ->
make_text_output(Status, Headers, Text) make_text_output(200, [], Text);
end {Status, Headers, Text} when is_list(Text) ->
make_text_output(Status, Headers, Text)
end end
end end
end; end;