fix(ldap): integrate parser and fix lexer errors

This commit is contained in:
firest 2023-08-01 11:40:37 +08:00
parent fa6343cc80
commit 8c9b136d15
4 changed files with 33 additions and 8 deletions

2
apps/emqx_ldap/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
src/emqx_ldap_filter_lexer.erl
src/emqx_ldap_filter_parser.erl

View File

@ -167,14 +167,22 @@ on_query(
[] -> [] ->
do_ldap_query(InstId, [{base, Base} | SearchOptions], State); do_ldap_query(InstId, [{base, Base} | SearchOptions], State);
_ -> _ ->
FilterBin = emqx_placeholder:proc_tmpl(FilterTks, Data), FilterBin = emqx_placeholder:proc_tmpl(FilterTks, Data, #{return => rawlist}),
%% TODO case emqx_ldap_filter_parser:scan_and_parse(FilterBin) of
Filter = FilterBin, {ok, Filter} ->
do_ldap_query( do_ldap_query(
InstId, InstId,
[{base, Base}, {filter, Filter} | SearchOptions], [{base, Base}, {filter, Filter} | SearchOptions],
State State
) );
{error, Reason} = Error ->
?SLOG(error, #{
msg => "filter_parse_failed",
filter => FilterBin,
reason => Reason
}),
Error
end
end. end.
do_ldap_query( do_ldap_query(

View File

@ -1,5 +1,6 @@
Definitions. Definitions.
Control = [()&|!=~><:*]
NonControl = [^()&|!=~><:*] NonControl = [^()&|!=~><:*]
String = {NonControl}* String = {NonControl}*
White = [\s\t\n\r]+ White = [\s\t\n\r]+
@ -20,5 +21,7 @@ Rules.
dn : {token, {dn, TokenLine}}. dn : {token, {dn, TokenLine}}.
{White} : skip_token. {White} : skip_token.
{String} : {token, {string, TokenLine, TokenChars}}. {String} : {token, {string, TokenLine, TokenChars}}.
%% Leex will hang if a composite operation is missing a character
{Control} : {error, lists:flatten(io_lib:format("Unexpected Tokens:~ts", [TokenChars]))}.
Erlang code. Erlang code.

View File

@ -94,6 +94,8 @@ matchingrule ->
colon value: {matchingRule, '$2'}. colon value: {matchingRule, '$2'}.
Erlang code. Erlang code.
-export([scan_and_parse/1]).
-ignore_xref({return_error, 2}).
'and'(Value) -> 'and'(Value) ->
eldap:'and'(Value). eldap:'and'(Value).
@ -131,3 +133,13 @@ flatten(List) -> lists:flatten(List).
get_value({_Token, _Line, Value}) -> get_value({_Token, _Line, Value}) ->
Value. Value.
scan_and_parse(Bin) when is_binary(Bin) ->
scan_and_parse(erlang:binary_to_list(Bin));
scan_and_parse(String) ->
case emqx_ldap_filter_lexer:string(String) of
{ok, Tokens, _} ->
parse(Tokens);
{error, Reason, _} ->
{error, Reason}
end.