From ac81b3948bba66af3d2845332d6ef8f75d0a918f Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Sat, 6 Aug 2016 12:46:39 +0300 Subject: [PATCH] cli: Share a common tokenize_cmd() implementation wpa_cli and hostapd_cli had identical copies of this function. Signed-off-by: Jouni Malinen --- hostapd/hostapd_cli.c | 32 -------------------------------- src/common/cli.c | 30 ++++++++++++++++++++++++++++++ src/common/cli.h | 3 +++ wpa_supplicant/wpa_cli.c | 31 ------------------------------- 4 files changed, 33 insertions(+), 63 deletions(-) diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c index 196f512..04819d1 100644 --- a/hostapd/hostapd_cli.c +++ b/hostapd/hostapd_cli.c @@ -1478,38 +1478,6 @@ static void hostapd_cli_receive(int sock, void *eloop_ctx, void *sock_ctx) } -#define max_args 10 - -static int tokenize_cmd(char *cmd, char *argv[]) -{ - char *pos; - int argc = 0; - - pos = cmd; - for (;;) { - while (*pos == ' ') - pos++; - if (*pos == '\0') - break; - argv[argc] = pos; - argc++; - if (argc == max_args) - break; - if (*pos == '"') { - char *pos2 = os_strrchr(pos, '"'); - if (pos2) - pos = pos2 + 1; - } - while (*pos != '\0' && *pos != ' ') - pos++; - if (*pos == ' ') - *pos++ = '\0'; - } - - return argc; -} - - static void hostapd_cli_ping(void *eloop_ctx, void *timeout_ctx) { if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) { diff --git a/src/common/cli.c b/src/common/cli.c index 64c0159..b583d1c 100644 --- a/src/common/cli.c +++ b/src/common/cli.c @@ -235,3 +235,33 @@ fail: printf("Too long command\n"); return -1; } + + +int tokenize_cmd(char *cmd, char *argv[]) +{ + char *pos; + int argc = 0; + + pos = cmd; + for (;;) { + while (*pos == ' ') + pos++; + if (*pos == '\0') + break; + argv[argc] = pos; + argc++; + if (argc == max_args) + break; + if (*pos == '"') { + char *pos2 = os_strrchr(pos, '"'); + if (pos2) + pos = pos2 + 1; + } + while (*pos != '\0' && *pos != ' ') + pos++; + if (*pos == ' ') + *pos++ = '\0'; + } + + return argc; +} diff --git a/src/common/cli.h b/src/common/cli.h index 9f9f851..41ef329 100644 --- a/src/common/cli.h +++ b/src/common/cli.h @@ -41,4 +41,7 @@ int get_cmd_arg_num(const char *str, int pos); int write_cmd(char *buf, size_t buflen, const char *cmd, int argc, char *argv[]); +#define max_args 10 +int tokenize_cmd(char *cmd, char *argv[]); + #endif /* CLI_H */ diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index c4b92b7..ca3d8f8 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -3808,37 +3808,6 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor) } } -#define max_args 10 - -static int tokenize_cmd(char *cmd, char *argv[]) -{ - char *pos; - int argc = 0; - - pos = cmd; - for (;;) { - while (*pos == ' ') - pos++; - if (*pos == '\0') - break; - argv[argc] = pos; - argc++; - if (argc == max_args) - break; - if (*pos == '"') { - char *pos2 = os_strrchr(pos, '"'); - if (pos2) - pos = pos2 + 1; - } - while (*pos != '\0' && *pos != ' ') - pos++; - if (*pos == ' ') - *pos++ = '\0'; - } - - return argc; -} - static void wpa_cli_ping(void *eloop_ctx, void *timeout_ctx) { -- 2.1.4