From: Paweł Chmielowski Date: Fri, 6 Apr 2012 16:55:27 +0000 (+0200) Subject: Don't use binary:match to extract lines from binaries X-Git-Tag: v2.1.11~36 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2c228e6414c7e5bd4f94f623ccd1374317a9d294;p=ejabberd Don't use binary:match to extract lines from binaries This was added in R13B3, lets roll our own implementation to make sure it works on older erlang versions. --- diff --git a/src/web/ejabberd_http.erl b/src/web/ejabberd_http.erl index f9d390dbe..067ed07d9 100644 --- a/src/web/ejabberd_http.erl +++ b/src/web/ejabberd_http.erl @@ -923,12 +923,22 @@ old_integer_to_hex(I) when I>=16 -> % The following code is mostly taken from yaws_ssl.erl +extract_line(_, <<>>, _) -> + none; +extract_line(0, <<"\r", Rest/binary>>, Line) -> + extract_line(1, Rest, Line); +extract_line(0, <>, Line) -> + extract_line(0, Rest, <>); +extract_line(1, <<"\n", Rest/binary>>, Line) -> + {Line, Rest}; +extract_line(1, Data, Line) -> + extract_line(0, Data, <>). + decode_packet(_, <<"\r\n", Rest/binary>>) -> {ok, http_eoh, Rest}; decode_packet(Type, Data) -> - case binary:match(Data, <<"\r\n">>) of - {Start, _Len} -> - <> = Data, + case extract_line(0, Data, <<>>) of + {LineB, Rest} -> Line = binary_to_list(LineB), Result = case Type of http ->