GideonLeGrange/mikrotik-java

Add support for nested query expressions

colinhd8 opened this issue · 9 comments

Hi, seems that the query expression not support mixed query type, for example:
/ip/firewall/nat/print where action=dst-nat and (chain ="dstnat" or chain="dstnat_cnc")

The grammar doesn't currently support (expression). I'll see if I can work out how to support it.

You can give this a try by pulling and building master.

Please let me know if it works or does not work for you.

Gideon

Thank you very much. I'll try it and report the result.

I have taken some time to test it, and below is the result:
rule in ros:
/ip firewall nat print where (src-address="192.168.15.52" or src-address="192.168.15.53")
Flags: X - disabled, I - invalid, D - dynamic
0 chain=api_test action=log src-address=192.168.15.52 log=no log-prefix=""
1 chain=api_test action=log src-address=192.168.15.53 log=no log-prefix=""

1.con.execute("/ip/firewall/nat/print where chain=api_test and (src-address=192.168.15.52) and action=log ")
no result.

2.con.execute("/ip/firewall/nat/print where chain=api_test and (src-address=192.168.15.52 or src-address=192.168.15.53) and action=log ")
1 result(192.168.15.52)

3.con.execute("/ip/firewall/nat/print where chain=api_test and (src-address=192.168.15.53 or src-address=192.168.15.52) and action=log ")
1 result(192.168.15.53)

4.con.execute("/ip/firewall/nat/print where chain=api_test and (src-address=\"192.168.15.53\" or src-address=\"192.168.15.52\") and action=log ")
error: me.legrange.mikrotik.impl.ParseException: Expected [=, <, >, !=] but found TEXT at position 109

Thank you for the feedback.

Ok, so the 4th one fails. I will investigate why and let you know.

I'll work through all 4 scenarios

@colinhd8 The example you provided was very handy, thank you.

I have fixed a small mistake in the parsing of the command when closing a nested expression and it seems to have made all the difference. I now get the following results for your four examples:

Command: /ip/firewall/nat/print where (src-address="192.168.15.52" or src-address="192.168.15.53")
tag=2, data={chain=api_test, log=false, log-prefix=, bytes=0, invalid=false, .id=*2, action=log, dynamic=false, packets=0, src-address=192.168.15.52}
tag=2, data={chain=api_test, log=false, log-prefix=, bytes=0, invalid=false, .id=*3, action=log, dynamic=false, packets=0, src-address=192.168.15.53}

Command: /ip/firewall/nat/print where chain=api_test and (src-address=192.168.15.52) and action=log 
tag=3, data={chain=api_test, log=false, log-prefix=, bytes=0, invalid=false, .id=*2, action=log, dynamic=false, packets=0, src-address=192.168.15.52}

Command: /ip/firewall/nat/print where chain=api_test and (src-address=192.168.15.53 or src-address=192.168.15.52) and action=log 
tag=4, data={chain=api_test, log=false, log-prefix=, bytes=0, invalid=false, .id=*2, action=log, dynamic=false, packets=0, src-address=192.168.15.52}
tag=4, data={chain=api_test, log=false, log-prefix=, bytes=0, invalid=false, .id=*3, action=log, dynamic=false, packets=0, src-address=192.168.15.53}

Command: /ip/firewall/nat/print where chain=api_test and (src-address="192.168.15.53" or src-address="192.168.15.52") and action=log 
tag=5, data={chain=api_test, log=false, log-prefix=, bytes=0, invalid=false, .id=*2, action=log, dynamic=false, packets=0, src-address=192.168.15.52}
tag=5, data={chain=api_test, log=false, log-prefix=, bytes=0, invalid=false, .id=*3, action=log, dynamic=false, packets=0, src-address=192.168.15.53}

If you confirm that it works for you as well, I'll release a new version to Maven Central.

@GideonLeGrange It's worked now, thank you.