diff options
| author | Matthew Sackman <matthew@rabbitmq.com> | 2010-12-14 18:26:59 +0000 |
|---|---|---|
| committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-12-14 18:26:59 +0000 |
| commit | b2b3c39fc89e3a00ba26e2d22542d9d76c4f4234 (patch) | |
| tree | e308db9543c397f55e09a58f5e2d0eb3ce55826c /src | |
| parent | 5f40f022bbfc23b16df506239d5fd427f4eca895 (diff) | |
| download | rabbitmq-server-git-b2b3c39fc89e3a00ba26e2d22542d9d76c4f4234.tar.gz | |
Don't use re where it can be easily avoided in the plain auth mech
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_auth_mechanism_plain.erl | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/rabbit_auth_mechanism_plain.erl b/src/rabbit_auth_mechanism_plain.erl index e5f8f3e6a1..fcb7fe6b45 100644 --- a/src/rabbit_auth_mechanism_plain.erl +++ b/src/rabbit_auth_mechanism_plain.erl @@ -56,11 +56,17 @@ init(_Sock) -> []. handle_response(Response, _State) -> - %% The '%%"' at the end of the next line is for Emacs - case re:run(Response, "^\\0([^\\0]*)\\0([^\\0]*)$",%%" - [{capture, all_but_first, binary}]) of - {match, [User, Pass]} -> - rabbit_access_control:check_user_pass_login(User, Pass); - _ -> - {protocol_error, "response ~p invalid", [Response]} - end. + {User, Response1} = split_on_null(drop_leading_null(Response), []), + {Pass, _Response2} = split_on_null(Response1, []), + rabbit_access_control:check_user_pass_login( + list_to_binary(User), list_to_binary(Pass)). + +drop_leading_null(<<0:8, Rest/binary>>) -> + Rest. + +split_on_null(<<0:8, Rest/binary>>, Acc) -> + {lists:reverse(Acc), Rest}; +split_on_null(<<>>, Acc) -> + {lists:reverse(Acc), <<>>}; +split_on_null(<<C:8, Rest/binary>>, Acc) -> + split_on_null(Rest, [C | Acc]). |
