From bb1fca058de471395791df747b4d0839ed39b6a3 Mon Sep 17 00:00:00 2001 From: Christophe Romain Date: Fri, 18 Sep 2009 13:33:12 +0000 Subject: [PATCH] Return terminal binding condition on max stanza size limit (thanks to Aleksey) SVN Revision: 2602 --- src/web/ejabberd_http_bind.erl | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/web/ejabberd_http_bind.erl b/src/web/ejabberd_http_bind.erl index ddd53cccc..9e379c66a 100644 --- a/src/web/ejabberd_http_bind.erl +++ b/src/web/ejabberd_http_bind.erl @@ -180,7 +180,7 @@ process_request(Data, IP) -> {ok, {"", Rid, Attrs, Payload}} -> case xml:get_attr_s("to",Attrs) of "" -> - ?INFO_MSG("Session not created (Improper addressing).~nAttributes: ~p", [Attrs]), + ?ERROR_MSG("Session not created (Improper addressing)", []), {200, ?HEADER, ""}; @@ -216,8 +216,16 @@ process_request(Data, IP) -> end, handle_http_put(Sid, Rid, Attrs, Payload2, PayloadSize, StreamStart, IP); - {error, size_limit} -> - {413, ?HEADER, "Request Too Large"}; + {size_limit, Sid} -> + case mnesia:dirty_read({http_bind, Sid}) of + [] -> + {404, ?HEADER, ""}; + [#http_bind{pid = FsmRef}] -> + gen_fsm:sync_send_all_state_event(FsmRef, {stop, close}), + {200, ?HEADER, "Request Too Large"} + end; _ -> ?DEBUG("Received bad request: ~p", [Data]), {400, ?HEADER, ""} @@ -396,9 +404,7 @@ handle_sync_event(#http_put{rid = Rid}, ?DEBUG("Shaper timer for RID ~p: ~p", [Rid, Reply]), {reply, Reply, StateName, StateData}; -handle_sync_event(#http_put{rid = _Rid, attrs = _Attrs, - payload_size = PayloadSize, - hold = _Hold} = Request, +handle_sync_event(#http_put{payload_size = PayloadSize} = Request, _From, StateName, StateData) -> ?DEBUG("New request: ~p",[Request]), %% Updating trafic shaper @@ -1076,10 +1082,7 @@ send_outpacket(#http_bind{pid = FsmRef}, OutPacket) -> end end. -parse_request(_Data, PayloadSize, MaxStanzaSize) - when PayloadSize > MaxStanzaSize -> - {error, size_limit}; -parse_request(Data, _PayloadSize, _MaxStanzaSize) -> +parse_request(Data, PayloadSize, MaxStanzaSize) -> ?DEBUG("--- incoming data --- ~n~s~n --- END --- ", [Data]), %% MR: I do not think it works if put put several elements in the %% same body: @@ -1106,7 +1109,12 @@ parse_request(Data, _PayloadSize, _MaxStanzaSize) -> end end, Els), Sid = xml:get_attr_s("sid",Attrs), - {ok, {Sid, Rid, Attrs, FixedEls}} + if + PayloadSize =< MaxStanzaSize -> + {ok, {Sid, Rid, Attrs, FixedEls}}; + true -> + {size_limit, Sid} + end end end; {xmlelement, _Name, _Attrs, _Els} ->