api7 / lua-resty-ldap

Apache License 2.0
7 stars 6 forks source link

feat: support filter compiler #4

Closed bzp2010 closed 1 year ago

bzp2010 commented 1 year ago

SearchRequest [1] contains a field called filter, which is also based on the native structure of ASN.1, not just a string.

Users can write expressions to build filters using strings, but we can't pass them directly to the LDAP server, they need to be parsed and encoded into native ASN.1 format.

This PR uses LPeg [2] to implement a compiler front-end that parses user-entered custom string expressions into a custom abstract syntax tree, which is a Lua table, so that we can use it recursively for the ASN.1 encoding process.

[1] https://cwiki.apache.org/confluence/display/DIRxSRVx10/Ldap+ASN.1+Codec#LdapASN.1Codec-SearchRequest [2] https://luarocks.org/modules/gvvaughan/lpeg