2 * Common hostapd/wpa_supplicant command line interface functions
3 * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
11 #include "utils/common.h"
12 #include "common/cli.h"
15 void cli_txt_list_free(struct cli_txt_entry *e)
17 dl_list_del(&e->list);
23 void cli_txt_list_flush(struct dl_list *list)
25 struct cli_txt_entry *e;
27 while ((e = dl_list_first(list, struct cli_txt_entry, list)))
32 struct cli_txt_entry * cli_txt_list_get(struct dl_list *txt_list,
35 struct cli_txt_entry *e;
37 dl_list_for_each(e, txt_list, struct cli_txt_entry, list) {
38 if (os_strcmp(e->txt, txt) == 0)
45 void cli_txt_list_del(struct dl_list *txt_list, const char *txt)
47 struct cli_txt_entry *e;
49 e = cli_txt_list_get(txt_list, txt);
55 void cli_txt_list_del_addr(struct dl_list *txt_list, const char *txt)
60 if (hwaddr_aton(txt, addr) < 0)
62 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
63 cli_txt_list_del(txt_list, buf);
67 void cli_txt_list_del_word(struct dl_list *txt_list, const char *txt,
73 end = os_strchr(txt, separator);
75 end = txt + os_strlen(txt);
76 buf = dup_binstr(txt, end - txt);
79 cli_txt_list_del(txt_list, buf);
84 int cli_txt_list_add(struct dl_list *txt_list, const char *txt)
86 struct cli_txt_entry *e;
88 e = cli_txt_list_get(txt_list, txt);
91 e = os_zalloc(sizeof(*e));
94 e->txt = os_strdup(txt);
99 dl_list_add(txt_list, &e->list);
104 int cli_txt_list_add_addr(struct dl_list *txt_list, const char *txt)
109 if (hwaddr_aton(txt, addr) < 0)
111 os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
112 return cli_txt_list_add(txt_list, buf);
116 int cli_txt_list_add_word(struct dl_list *txt_list, const char *txt,
123 end = os_strchr(txt, separator);
125 end = txt + os_strlen(txt);
126 buf = dup_binstr(txt, end - txt);
129 ret = cli_txt_list_add(txt_list, buf);
135 char ** cli_txt_list_array(struct dl_list *txt_list)
137 unsigned int i, count = dl_list_len(txt_list);
139 struct cli_txt_entry *e;
141 res = os_calloc(count + 1, sizeof(char *));
146 dl_list_for_each(e, txt_list, struct cli_txt_entry, list) {
147 res[i] = os_strdup(e->txt);