summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2013-07-25 13:15:32 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2013-07-25 13:15:32 +0200
commit508d936078aecc8fbbb9ca1218104599c4a3cb4a (patch)
treed84c6b098342fc2f366d960bd90d6a158610ea48 /nest
parenta0b176e3b2b50d3a30574afa927e0ee8ef65be68 (diff)
Implements eval command and minor CLI cleanups.
Implemented eval command can be used to evaluate expressions. The patch also documents echo command and allows to use log classes instead of integer as a mask for echo.
Diffstat (limited to 'nest')
-rw-r--r--nest/cmds.c20
-rw-r--r--nest/cmds.h3
-rw-r--r--nest/config.Y8
3 files changed, 29 insertions, 2 deletions
diff --git a/nest/cmds.c b/nest/cmds.c
index 54ace169..9bdd66cd 100644
--- a/nest/cmds.c
+++ b/nest/cmds.c
@@ -13,6 +13,7 @@
#include "nest/cmds.h"
#include "lib/string.h"
#include "lib/resource.h"
+#include "filter/filter.h"
extern int shutting_down;
extern int configuring;
@@ -90,3 +91,22 @@ cmd_show_memory(void)
print_size("Total:", rmemsize(&root_pool));
cli_msg(0, "");
}
+
+extern const char *log_buffer_ptr;
+
+void
+cmd_eval(struct f_inst *expr)
+{
+ struct f_val v = f_eval(expr, this_cli->parser_pool);
+ log_reset();
+
+ if (v.type == T_RETURN)
+ {
+ cli_msg(8008, "runtime error");
+ return;
+ }
+
+ val_print(v);
+ cli_msg(23, "%s", log_buffer_ptr);
+ log_reset();
+}
diff --git a/nest/cmds.h b/nest/cmds.h
index 8b0bff7e..4cf8fb1b 100644
--- a/nest/cmds.h
+++ b/nest/cmds.h
@@ -11,6 +11,9 @@ struct sym_show_data {
struct symbol *sym;
};
+struct f_inst;
+
void cmd_show_status(void);
void cmd_show_symbols(struct sym_show_data *sym);
void cmd_show_memory(void);
+void cmd_eval(struct f_inst *expr);
diff --git a/nest/config.Y b/nest/config.Y
index b85a5733..a6f13808 100644
--- a/nest/config.Y
+++ b/nest/config.Y
@@ -612,7 +612,11 @@ CF_CLI(DUMP ROUTES,,, [[Dump routing table]])
CF_CLI(DUMP PROTOCOLS,,, [[Dump protocol information]])
{ protos_dump_all(); cli_msg(0, ""); } ;
-CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Configure echoing of log messages]]) {
+CF_CLI(EVAL, term, <expr>, [[Evaluate an expression]])
+{ cmd_eval($2); } ;
+
+CF_CLI_HELP(ECHO, ..., [[Control echoing of log messages]])
+CF_CLI(ECHO, echo_mask echo_size, (all | off | { debug | trace | info | remote | warning | error | auth }) [<buffer-size>], [[Control echoing of log messages]]) {
cli_set_log_echo(this_cli, $2, $3);
cli_msg(0, "");
} ;
@@ -620,7 +624,7 @@ CF_CLI(ECHO, echo_mask echo_size, [all | off | <mask>] [<buffer-size>], [[Config
echo_mask:
ALL { $$ = ~0; }
| OFF { $$ = 0; }
- | NUM
+ | '{' log_mask_list '}' { $$ = $2; }
;
echo_size: