diff options
Diffstat (limited to 'clitest.c')
-rw-r--r-- | clitest.c | 99 |
1 files changed, 62 insertions, 37 deletions
@@ -202,8 +202,39 @@ void pc(UNUSED(struct cli_def *cli), const char *string) int main() { - struct cli_command *c; struct cli_def *cli; + struct cli_command cmd_test_s = {(char *) "test", cmd_test, 0, NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_simple_s = {(char *) "simple", NULL, 0, NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_simon_s = {(char *) "simon", NULL, 0, NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_set_s = {(char *) "set", NULL, 0, NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + + struct cli_command cmd_show_s = {(char *) "show", NULL, 0, NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_show_regular_s = {(char *) "regular", cmd_show_regular, 0, + (char *) "Show the how many times cli_regular has run", + PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_show_counters_s = {(char *) "counters", cmd_test, 0, + (char *) "Show the counters that the system uses", + PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_show_junk_s = {(char *) "junk", cmd_test, 0, NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + + struct cli_command cmd_config_int_s = {(char *) "interface", cmd_config_int, 0, + (char *) "Configure an interface", + PRIVILEGE_PRIVILEGED, MODE_CONFIG, NULL, NULL, NULL}; + struct cli_command cmd_config_int_exit_s = {(char *) "exit", cmd_config_int_exit, 0, + (char *) "Exit from interface configuration", + PRIVILEGE_PRIVILEGED, MODE_CONFIG_INT, NULL, NULL, NULL}; + struct cli_command cmd_config_int_address_s = {(char *) "address", cmd_test, 0, + (char *) "Set IP address", + PRIVILEGE_PRIVILEGED, MODE_CONFIG_INT, NULL, NULL, NULL}; + struct cli_command cmd_debug_s = {(char *) "debug", NULL, 0, NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_debug_regular_s = {(char *) "regular", cmd_debug_regular, 0, + (char *) "Enable cli_regular() callback debugging", + PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + struct cli_command cmd_context_s = {(char *) "context", cmd_context, 0, + (char *) "Test a user-specified context", + PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL, NULL, NULL}; + + int s, x; struct sockaddr_in addr; int on = 1; @@ -219,57 +250,51 @@ int main() #endif // Prepare a small user context - char mymessage[] = "I contain user data!"; + static char mymessage[] = "I contain user data!"; + static char banner[] = "libcli test environment"; + static char hostname[] = "router"; struct my_context myctx; myctx.value = 5; myctx.message = mymessage; - cli = cli_init(); - cli_set_banner(cli, "libcli test environment"); - cli_set_hostname(cli, "router"); + if (!(cli = calloc(sizeof(struct cli_def), 1))) + return 0; + + if (! cli_init(cli)) { + printf("Error initialising CLI\n"); + return 1; + } + cli_set_banner(cli, banner); + cli_set_hostname(cli, hostname); cli_telnet_protocol(cli, 1); - cli_regular(cli, regular_callback); - cli_regular_interval(cli, 5); // Defaults to 1 second + //cli_regular(cli, regular_callback); + //cli_regular_interval(cli, 5); // Defaults to 1 second cli_set_idle_timeout_callback(cli, 60, idle_timeout); // 60 second idle timeout - cli_register_command(cli, NULL, "test", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL); - - cli_register_command(cli, NULL, "simple", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL); - - cli_register_command(cli, NULL, "simon", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL); - - cli_register_command(cli, NULL, "set", cmd_set, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL); + cli_register_command2(cli, &cmd_test_s, NULL); + cli_register_command2(cli, &cmd_simple_s, NULL); + cli_register_command2(cli, &cmd_simon_s, NULL); + cli_register_command2(cli, &cmd_set_s, NULL); - c = cli_register_command(cli, NULL, "show", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL); + cli_register_command2(cli, &cmd_show_s, NULL); + cli_register_command2(cli, &cmd_show_regular_s, &cmd_show_s); + cli_register_command2(cli, &cmd_show_counters_s, &cmd_show_s); + cli_register_command2(cli, &cmd_show_junk_s, &cmd_show_s); - cli_register_command(cli, c, "regular", cmd_show_regular, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, - "Show the how many times cli_regular has run"); + cli_register_command2(cli, &cmd_config_int_s, NULL); + cli_register_command2(cli, &cmd_config_int_exit_s, NULL); + cli_register_command2(cli, &cmd_config_int_address_s, NULL); - cli_register_command(cli, c, "counters", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, - "Show the counters that the system uses"); - - cli_register_command(cli, c, "junk", cmd_test, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL); - - cli_register_command(cli, NULL, "interface", cmd_config_int, PRIVILEGE_PRIVILEGED, MODE_CONFIG, - "Configure an interface"); - - cli_register_command(cli, NULL, "exit", cmd_config_int_exit, PRIVILEGE_PRIVILEGED, MODE_CONFIG_INT, - "Exit from interface configuration"); - - cli_register_command(cli, NULL, "address", cmd_test, PRIVILEGE_PRIVILEGED, MODE_CONFIG_INT, "Set IP address"); - - c = cli_register_command(cli, NULL, "debug", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL); - - cli_register_command(cli, c, "regular", cmd_debug_regular, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, - "Enable cli_regular() callback debugging"); + cli_register_command2(cli, &cmd_debug_s, NULL); + cli_register_command2(cli, &cmd_debug_regular_s, &cmd_debug_s); // Set user context and its command cli_set_context(cli, (void*)&myctx); - cli_register_command(cli, NULL, "context", cmd_context, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, - "Test a user-specified context"); + cli_register_command2(cli, &cmd_context_s, NULL); cli_set_auth_callback(cli, check_auth); cli_set_enable_callback(cli, check_enable); // Test reading from a file + /* { FILE *fh; @@ -282,7 +307,7 @@ int main() fclose(fh); } } - + */ if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) { perror("socket"); |