fix(ldap): integrate parser and fix lexer errors
This commit is contained in:
parent
fa6343cc80
commit
8c9b136d15
|
@ -0,0 +1,2 @@
|
||||||
|
src/emqx_ldap_filter_lexer.erl
|
||||||
|
src/emqx_ldap_filter_parser.erl
|
|
@ -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(
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in New Issue