Fixed bug in handling nested expressions. Added simple excample class

This commit is contained in:
Gideon Le Grange 2020-01-04 20:10:14 +02:00
parent 8fa8711ec5
commit 42c281ab88
3 changed files with 37 additions and 4 deletions

View File

@ -7,8 +7,8 @@ package examples;
*/ */
public class Config { public class Config {
public static final String HOST = "192.168.1.1"; public static final String HOST = "192.168.1.25";
public static final String USERNAME = "admin"; public static final String USERNAME = "gideon";
public static final String PASSWORD = ""; public static final String PASSWORD = "minapp";
} }

View File

@ -0,0 +1,33 @@
package examples;
import me.legrange.mikrotik.MikrotikApiException;
import java.util.List;
import java.util.Map;
/**
* Example 2: A command that returns results. Print all interfaces
*
* @author gideon
*/
public class NestedExpressions extends Example {
public static void main(String... args) throws Exception {
NestedExpressions ex = new NestedExpressions();
ex.connect();
ex.test("/ip/firewall/nat/print where (src-address=\"192.168.15.52\" or src-address=\"192.168.15.53\")");
ex.test("/ip/firewall/nat/print where chain=api_test and (src-address=192.168.15.52) and action=log ");
ex.test("/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 ");
ex.test("/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 ");
ex.disconnect();
}
private void test(String cmd) throws MikrotikApiException {
System.out.println("Command: " + cmd);
List<Map<String, String>> results = con.execute(cmd);
for (Map<String, String> result : results) {
System.out.println(result);
}
System.out.println();
}
}

View File

@ -121,7 +121,7 @@ class Scanner {
*/ */
private Token name() throws ScanException { private Token name() throws ScanException {
text = new StringBuilder(); text = new StringBuilder();
while (!in(c, "[ \t\r\n=<>!]")) { while (!in(c, "[ \t\r\n=<>!)]")) {
text.append(c); text.append(c);
nextChar(); nextChar();
} }