summaryrefslogtreecommitdiff
path: root/accel-pptpd/cli/std_cmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel-pptpd/cli/std_cmd.c')
-rw-r--r--accel-pptpd/cli/std_cmd.c181
1 files changed, 43 insertions, 138 deletions
diff --git a/accel-pptpd/cli/std_cmd.c b/accel-pptpd/cli/std_cmd.c
index 491caf76..9a5747e8 100644
--- a/accel-pptpd/cli/std_cmd.c
+++ b/accel-pptpd/cli/std_cmd.c
@@ -7,118 +7,49 @@
#include "cli.h"
#include "utils.h"
-int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
+static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
- char buf[128];
-
- if (cli_send(client, "core:\r\n"))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " mempool_allocated: %u\r\n", triton_stat.mempool_allocated);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " mempool_available: %u\r\n", triton_stat.mempool_available);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " thread_count: %u\r\n", triton_stat.thread_count);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " thread_active: %u\r\n", triton_stat.thread_active);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " context_count: %u\r\n", triton_stat.context_count);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " context_sleeping: %u\r\n", triton_stat.context_sleeping);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " context_pending: %u\r\n", triton_stat.context_pending);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " md_handler_count: %u\r\n", triton_stat.md_handler_count);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " md_handler_pending: %u\r\n", triton_stat.md_handler_pending);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " timer_count: %u\r\n", triton_stat.timer_count);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " timer_pending: %u\r\n", triton_stat.timer_pending);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
+ cli_send(client, "core:\r\n");
+ cli_sendv(client, " mempool_allocated: %u\r\n", triton_stat.mempool_allocated);
+ cli_sendv(client, " mempool_available: %u\r\n", triton_stat.mempool_available);
+ cli_sendv(client, " thread_count: %u\r\n", triton_stat.thread_count);
+ cli_sendv(client, " thread_active: %u\r\n", triton_stat.thread_active);
+ cli_sendv(client, " context_count: %u\r\n", triton_stat.context_count);
+ cli_sendv(client, " context_sleeping: %u\r\n", triton_stat.context_sleeping);
+ cli_sendv(client, " context_pending: %u\r\n", triton_stat.context_pending);
+ cli_sendv(client, " md_handler_count: %u\r\n", triton_stat.md_handler_count);
+ cli_sendv(client, " md_handler_pending: %u\r\n", triton_stat.md_handler_pending);
+ cli_sendv(client, " timer_count: %u\r\n", triton_stat.timer_count);
+ cli_sendv(client, " timer_pending: %u\r\n", triton_stat.timer_pending);
//===========
- if (cli_send(client, "ppp:\r\n"))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " staring: %u\r\n", ppp_stat.starting);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " active: %u\r\n", ppp_stat.active);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
-
- sprintf(buf, " finishing: %u\r\n", ppp_stat.finishing);
- if (cli_send(client, buf))
- return CLI_CMD_FAILED;
+ cli_send(client, "ppp:\r\n");
+ cli_sendv(client, " staring: %u\r\n", ppp_stat.starting);
+ cli_sendv(client, " active: %u\r\n", ppp_stat.active);
+ cli_sendv(client, " finishing: %u\r\n", ppp_stat.finishing);
return CLI_CMD_OK;
}
-int show_stat_help(char * const *fields, int fields_cnt, void *client)
+static void show_stat_help(char * const *fields, int fields_cnt, void *client)
{
- if (cli_send(client, "show stat - shows various statistics information\r\n"))
- return -1;
-
- return 0;
+ cli_send(client, "show stat - shows various statistics information\r\n");
}
-
-const char *show_stat_hdr[] = {"show","stat"};
-static struct cli_simple_cmd_t show_stat_cmd = {
- .hdr_len = 2,
- .hdr = show_stat_hdr,
- .exec = show_stat_exec,
- .help = show_stat_help,
-};
-
//=============================
-int exit_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
+static int exit_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
return CLI_CMD_EXIT;
}
-int exit_help(char * const *fields, int fields_cnt, void *client)
+static void exit_help(char * const *fields, int fields_cnt, void *client)
{
- if (cli_send(client, "exit - exit cli\r\n"))
- return -1;
-
- return 0;
+ cli_send(client, "exit - exit cli\r\n");
}
-const char *exit_hdr[] = {"exit"};
-static struct cli_simple_cmd_t exit_cmd = {
- .hdr_len = 1,
- .hdr = exit_hdr,
- .exec = exit_exec,
- .help = exit_help,
-};
-
//=============================
-int show_ses_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
+static int show_ses_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
char buf[128];
char ip_str[17];
@@ -128,11 +59,8 @@ int show_ses_exec(const char *cmd, char * const *fields, int fields_cnt, void *c
int day,hour,min,sec;
struct ppp_t *ppp;
- if (cli_send(client, "interface: username: address: type: state: uptime:\r\n"))
- return CLI_CMD_FAILED;
-
- if (cli_send(client, "------------------------------------------------------------------------\r\n"))
- return CLI_CMD_FAILED;
+ cli_send(client, "interface: username: address: type: state: uptime:\r\n");
+ cli_send(client, "------------------------------------------------------------------------\r\n");
pthread_rwlock_rdlock(&ppp_lock);
list_for_each_entry(ppp, &ppp_list, entry) {
@@ -168,32 +96,18 @@ int show_ses_exec(const char *cmd, char * const *fields, int fields_cnt, void *c
sprintf(time_str, "%02i:%02i:%02i", hour, min, sec);
sprintf(buf, "%9s %15s %16s %6s %6s %10s\r\n", ppp->ifname, ppp->username ? ppp->username : "", ip_str, ppp->ctrl->name, state_str, time_str);
- if (cli_send(client, buf)) {
- pthread_rwlock_unlock(&ppp_lock);
- return CLI_CMD_FAILED;
- }
+ cli_send(client, buf);
}
pthread_rwlock_unlock(&ppp_lock);
return CLI_CMD_OK;
}
-int show_ses_help(char * const *fields, int fields_cnt, void *client)
+static void show_ses_help(char * const *fields, int fields_cnt, void *client)
{
- if (cli_send(client, "show sessions - shows all sessions\r\n"))
- return -1;
-
- return 0;
+ cli_send(client, "show sessions - shows all sessions\r\n");
}
-const char *show_ses_hdr[] = {"show", "sessions"};
-static struct cli_simple_cmd_t show_ses_cmd = {
- .hdr_len = 2,
- .hdr = show_ses_hdr,
- .exec = show_ses_exec,
- .help = show_ses_help,
-};
-
//=============================
static void ppp_terminate_soft(struct ppp_t *ppp)
@@ -206,20 +120,20 @@ static void ppp_terminate_hard(struct ppp_t *ppp)
ppp_terminate(ppp, 1, TERM_ADMIN_RESET);
}
-int terminate_help(char * const *fields, int fields_cnt, void *client);
-int terminate_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
+static void terminate_help(char * const *fields, int fields_cnt, void *client);
+static int terminate_exec(const char *cmd, char * const *fields, int fields_cnt, void *client)
{
struct ppp_t *ppp;
int hard = 0;
if (fields_cnt == 1)
- return terminate_help(NULL, 0, client);
+ goto help;
if (fields_cnt == 3) {
if (!strcmp(fields[2], "hard"))
hard = 1;
else if (strcmp(fields[2], "soft"))
- return terminate_help(NULL, 0, client);
+ goto help;
}
pthread_rwlock_rdlock(&ppp_lock);
@@ -244,31 +158,22 @@ int terminate_exec(const char *cmd, char * const *fields, int fields_cnt, void *
pthread_rwlock_unlock(&ppp_lock);
return CLI_CMD_OK;
+help:
+ terminate_help(fields, fields_cnt, client);
+ return CLI_CMD_OK;
}
-int terminate_help(char * const *fields, int fields_cnt, void *client)
+static void terminate_help(char * const *fields, int fields_cnt, void *client)
{
- if (cli_send(client, "terminate <interface> [soft|hard]- terminate session\r\n"))
- return -1;
-
- if (cli_send(client, "terminate all [soft|hard]- terminate all session\r\n"))
- return -1;
-
- return 0;
+ cli_send(client, "terminate <interface> [soft|hard]- terminate session\r\n");
+ cli_send(client, "terminate all [soft|hard]- terminate all session\r\n");
}
-const char *terminate_hdr[] = {"terminate"};
-static struct cli_simple_cmd_t terminate_cmd = {
- .hdr_len = 1,
- .hdr = terminate_hdr,
- .exec = terminate_exec,
- .help = terminate_help,
-};
-
static void __init init(void)
{
- cli_register_simple_cmd(&show_stat_cmd);
- cli_register_simple_cmd(&show_ses_cmd);
- cli_register_simple_cmd(&terminate_cmd);
- cli_register_simple_cmd(&exit_cmd);
+ cli_register_simple_cmd2(show_stat_exec, show_stat_help, 2, "show", "stat");
+ cli_register_simple_cmd2(show_ses_exec, show_ses_help, 2, "show", "sessions");
+ cli_register_simple_cmd2(terminate_exec, terminate_help, 1, "terminate");
+ cli_register_simple_cmd2(exit_exec, exit_help, 1, "exit");
}
+