1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2013 Intel Corporation.
3 * Copyright(c) 2014 6WIND S.A.
11 * RTE Argument parsing
13 * This module can be used to parse arguments whose format is
14 * key1=value1,key2=value2,key3=value3,...
16 * The same key can appear several times with the same or a different
17 * value. Indeed, the arguments are stored as a list of key/values
18 * associations and not as a dictionary.
20 * This file provides some helpers that are especially used by virtual
21 * ethernet devices at initialization for arguments parsing.
28 /** Maximum number of key/value associations */
29 #define RTE_KVARGS_MAX 32
31 /** separator character used between each pair */
32 #define RTE_KVARGS_PAIRS_DELIM ","
34 /** separator character used between key and value */
35 #define RTE_KVARGS_KV_DELIM "="
37 /** Type of callback function used by rte_kvargs_process() */
38 typedef int (*arg_handler_t)(const char *key, const char *value, void *opaque);
40 /** A key/value association */
41 struct rte_kvargs_pair {
42 char *key; /**< the name (key) of the association */
43 char *value; /**< the value associated to that key */
46 /** Store a list of key/value associations */
48 char *str; /**< copy of the argument string */
49 unsigned count; /**< number of entries in the list */
50 struct rte_kvargs_pair pairs[RTE_KVARGS_MAX]; /**< list of key/values */
54 * Allocate a rte_kvargs and store key/value associations from a string
56 * The function allocates and fills a rte_kvargs structure from a given
57 * string whose format is key1=value1,key2=value2,...
59 * The structure can be freed with rte_kvargs_free().
62 * The input string containing the key/value associations
64 * A list of valid keys (table of const char *, the last must be NULL).
65 * This argument is ignored if NULL
68 * - A pointer to an allocated rte_kvargs structure on success
71 struct rte_kvargs *rte_kvargs_parse(const char *args,
72 const char *const valid_keys[]);
75 * Free a rte_kvargs structure
77 * Free a rte_kvargs structure previously allocated with
81 * The rte_kvargs structure
83 void rte_kvargs_free(struct rte_kvargs *kvlist);
86 * Call a handler function for each key/value matching the key
88 * For each key/value association that matches the given key, calls the
89 * handler function with the for a given arg_name passing the value on the
90 * dictionary for that key and a given extra argument. If *kvlist* is NULL
91 * function does nothing.
94 * The rte_kvargs structure
96 * The key on which the handler should be called, or NULL to process handler
99 * The function to call for each matching key
101 * A pointer passed unchanged to the handler
105 * - Negative on error
107 int rte_kvargs_process(const struct rte_kvargs *kvlist,
108 const char *key_match, arg_handler_t handler, void *opaque_arg);
111 * Count the number of associations matching the given key
114 * The rte_kvargs structure
116 * The key that should match, or NULL to count all associations
119 * The number of entries
121 unsigned rte_kvargs_count(const struct rte_kvargs *kvlist,
122 const char *key_match);