]> granicus.if.org Git - ejabberd/commitdiff
* src/web/ejabberd_http.erl: Fixed processing of POST body for
authorAlexey Shchepin <alexey@process-one.net>
Thu, 30 Sep 2004 21:54:39 +0000 (21:54 +0000)
committerAlexey Shchepin <alexey@process-one.net>
Thu, 30 Sep 2004 21:54:39 +0000 (21:54 +0000)
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

ChangeLog
src/translate.erl
src/web/ejabberd_http.erl

index 829312912061db79bb9cd3e281bad4f4c3c0a4db..6cbef661bfeccd8918c57e051fb3aa0da4cc6d6a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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>
 
        * src/ejabberd_listener.erl: Check result of controlling_process
index 664cbed49f1816e7db590bafe0f9cd3f698e9f1f..a6cc8c146457b731a0b017c623e6723ce724c9c0 100644 (file)
@@ -40,16 +40,18 @@ load_dir(Dir) ->
                         fun(FN) ->
                                 case string:len(FN) > 4 of
                                     true ->
-                                        string:substr(FN,
-                                                      string:len(FN) - 3) == ".msg";
+                                        string:substr(
+                                          FN,
+                                          string:len(FN) - 3) == ".msg";
                                     _ ->
                                         false
                                 end
                         end, Files),
            lists:foreach(
              fun(FN) ->
-                     load_file(string:substr(FN, 1, string:len(FN) - 4),
-                               Dir ++ "/" ++ FN)
+                     L = ascii_tolower(
+                           string:substr(FN, 1, string:len(FN) - 4)),
+                     load_file(L, Dir ++ "/" ++ FN)
              end, MsgFiles),
            ok;
        {error, Reason} ->
@@ -74,15 +76,21 @@ load_file(Lang, File) ->
     end.
 
 translate(Lang, Msg) ->
-    case ets:lookup(translations, {Lang, Msg}) of
+    LLang = ascii_tolower(Lang),
+    case ets:lookup(translations, {LLang, Msg}) of
        [{_, Trans}] ->
            Trans;
        _ ->
-           ShortLang = string:substr(Lang, 1, 2),
+           ShortLang = case string:tokens(LLang, "-") of
+                           [] ->
+                               LLang;
+                           [SL | _] ->
+                               SL
+                       end,
            case ShortLang of
                "en" ->
                    Msg;
-               Lang ->
+               LLang ->
                    translate(Msg);
                _ ->
                    case ets:lookup(translations, {ShortLang, Msg}) of
@@ -101,11 +109,17 @@ translate(Msg) ->
        "en" ->
            Msg;
        Lang ->
-           case ets:lookup(translations, {Lang, Msg}) of
+           LLang = ascii_tolower(Lang),
+           case ets:lookup(translations, {LLang, Msg}) of
                [{_, Trans}] ->
                    Trans;
                _ ->
-                   ShortLang = string:substr(Lang, 1, 2),
+                   ShortLang = case string:tokens(LLang, "-") of
+                                   [] ->
+                                       LLang;
+                                   [SL | _] ->
+                                       SL
+                               end,
                    case ShortLang of
                        "en" ->
                            Msg;
@@ -122,3 +136,10 @@ translate(Msg) ->
            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([]) ->
+    [].
+
index 70e2d36d2ac6f78e45dbebd5856170b1a31b4b50..99041da61ec650584c238c7be2a8ec9b31e148e6 100644 (file)
@@ -25,6 +25,7 @@
                request_version,
                request_path,
                request_auth,
+               request_keepalive,
                request_content_length,
                request_lang = "en",
                use_http_poll = false,
@@ -127,9 +128,26 @@ process_header(State, Data) ->
     Socket = State#state.socket,
     case Data of
        {ok, {http_request, Method, Path, Version}} ->
+           KeepAlive = case Version of
+               {1, 1} ->
+                   true;
+               _ ->
+                   false
+           end,
            State#state{request_method = Method,
                        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}} ->
            State#state{request_auth = parse_auth(Auth)};
        {ok, {http_header, _, 'Content-Length', _, SLen}} ->
@@ -150,8 +168,8 @@ process_header(State, Data) ->
                       element(2, State#state.request_path)]),
            Out = process_request(State),
            send_text(State, Out),
-           case State#state.request_version of
-               {1,1} ->
+           case State#state.request_keepalive of
+               true ->
                    case SockMod of
                        gen_tcp ->
                            inet:setopts(Socket, [{packet, http}]);
@@ -200,29 +218,30 @@ process_request(#state{request_method = 'GET',
                {'EXIT', _} ->
                    process_request(false);
                {NPath, Query} ->
-                   case (catch parse_urlencoded(Query)) of
-                       {'EXIT', _Reason} ->
-                           process_request(false);
-                       LQuery ->
-                           LPath = string:tokens(NPath, "/"),
-                           Request = #request{method = 'GET',
-                                              path = LPath,
-                                              q = LQuery,
-                                              user = User,
-                                              lang = Lang},
-                           case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin},
-                                                         Request) of
-                               El when element(1, El) == xmlelement ->
-                                   make_xhtml_output(200, [], El);
-                               {Status, Headers, El} when
-                                     element(1, El) == xmlelement ->
-                                   make_xhtml_output(Status, Headers, El);
-                               Text when is_list(Text) ->
-                                   make_text_output(200, [], Text);
-                               {Status, Headers, Text} when
-                                     is_list(Text) ->
-                                   make_text_output(Status, Headers, Text)
-                           end
+                   LQuery = case (catch parse_urlencoded(Query)) of
+                                {'EXIT', _Reason} ->
+                                    [];
+                                LQ ->
+                                    LQ
+                            end,
+                   LPath = string:tokens(NPath, "/"),
+                   Request = #request{method = 'GET',
+                                      path = LPath,
+                                      q = LQuery,
+                                      user = User,
+                                      lang = Lang},
+                   case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin},
+                                                 Request) of
+                       El when element(1, El) == xmlelement ->
+                           make_xhtml_output(200, [], El);
+                       {Status, Headers, El} when
+                             element(1, El) == xmlelement ->
+                           make_xhtml_output(Status, Headers, El);
+                       Text when is_list(Text) ->
+                           make_text_output(200, [], Text);
+                       {Status, Headers, Text} when
+                             is_list(Text) ->
+                           make_text_output(Status, Headers, Text)
                    end
            end
     end;
@@ -269,28 +288,29 @@ process_request(#state{request_method = 'POST',
                    process_request(false);
                {NPath, Query} ->
                    LPath = string:tokens(NPath, "/"),
-                   case (catch parse_urlencoded(Data)) of
-                       {'EXIT', _Reason} ->
-                           process_request(false);
-                       LQuery ->
-                           Request = #request{method = 'POST',
-                                              path = LPath,
-                                              q = LQuery,
-                                              user = User,
-                                              data = Data,
-                                              lang = Lang},
-                           case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin},
-                                                         Request) of
-                               El when element(1, El) == xmlelement ->
-                                   make_xhtml_output(200, [], El);
-                               {Status, Headers, El} when
-                                     element(1, El) == xmlelement ->
-                                   make_xhtml_output(Status, Headers, El);
-                               Text when is_list(Text) ->
-                                   make_text_output(200, [], Text);
-                               {Status, Headers, Text} when is_list(Text) ->
-                                   make_text_output(Status, Headers, Text)
-                           end
+                   LQuery = case (catch parse_urlencoded(Data)) of
+                                {'EXIT', _Reason} ->
+                                    [];
+                                LQ ->
+                                    LQ
+                            end,
+                   Request = #request{method = 'POST',
+                                      path = LPath,
+                                      q = LQuery,
+                                      user = User,
+                                      data = Data,
+                                      lang = Lang},
+                   case ejabberd_web:process_get({UseHTTPPoll, UseWebAdmin},
+                                                 Request) of
+                       El when element(1, El) == xmlelement ->
+                           make_xhtml_output(200, [], El);
+                       {Status, Headers, El} when
+                             element(1, El) == xmlelement ->
+                           make_xhtml_output(Status, Headers, El);
+                       Text when is_list(Text) ->
+                           make_text_output(200, [], Text);
+                       {Status, Headers, Text} when is_list(Text) ->
+                           make_text_output(Status, Headers, Text)
                    end
            end
     end;