2 // Copyright (c) 2016-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
19 * All rights reserved.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions are met:
23 * * Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 * * Neither the name of the University of California, Berkeley nor the
29 * names of its contributors may be used to endorse or promote products
30 * derived from this software without specific prior written permission.
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
33 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
34 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
35 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
36 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
37 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
38 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 #include <netinet/in.h>
52 #include <cmdline_parse.h>
53 #include <cmdline_parse_ipaddr.h>
55 #include <rte_string_fns.h>
57 #include "parse_obj_list.h"
59 /* This file is an example of extension of libcmdline. It provides an
60 * example of objects stored in a list. */
62 struct cmdline_token_ops token_obj_list_ops = {
63 .parse = parse_obj_list,
64 .complete_get_nb = complete_get_nb_obj_list,
65 .complete_get_elt = complete_get_elt_obj_list,
66 .get_help = get_help_obj_list,
70 parse_obj_list(cmdline_parse_token_hdr_t *tk, const char *buf, void *res,
73 struct token_obj_list *tk2 = (struct token_obj_list *)tk;
74 struct token_obj_list_data *tkd = &tk2->obj_list_data;
76 unsigned int token_len = 0;
81 if (res && ressize < sizeof(struct object *))
84 while(!cmdline_isendoftoken(buf[token_len]))
87 SLIST_FOREACH(o, tkd->list, next) {
88 if (token_len != strnlen(o->name, OBJ_NAME_LEN_MAX))
90 if (strncmp(buf, o->name, token_len))
94 if (!o) /* not found */
97 /* store the address of object in structure */
99 *(struct object **)res = o;
104 int complete_get_nb_obj_list(cmdline_parse_token_hdr_t *tk)
106 struct token_obj_list *tk2 = (struct token_obj_list *)tk;
107 struct token_obj_list_data *tkd = &tk2->obj_list_data;
111 SLIST_FOREACH(o, tkd->list, next) {
117 int complete_get_elt_obj_list(cmdline_parse_token_hdr_t *tk,
118 int idx, char *dstbuf, unsigned int size)
120 struct token_obj_list *tk2 = (struct token_obj_list *)tk;
121 struct token_obj_list_data *tkd = &tk2->obj_list_data;
126 SLIST_FOREACH(o, tkd->list, next) {
133 len = strnlen(o->name, OBJ_NAME_LEN_MAX);
134 if ((len + 1) > size)
138 snprintf(dstbuf, size, "%s", o->name);
144 int get_help_obj_list(__attribute__((unused)) cmdline_parse_token_hdr_t *tk,
145 char *dstbuf, unsigned int size)
147 snprintf(dstbuf, size, "Obj-List");