summaryrefslogtreecommitdiffstats
path: root/lib/librte_kvargs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/librte_kvargs')
-rw-r--r--lib/librte_kvargs/Makefile34
-rw-r--r--lib/librte_kvargs/meson.build5
-rw-r--r--lib/librte_kvargs/rte_kvargs.c61
-rw-r--r--lib/librte_kvargs/rte_kvargs.h58
-rw-r--r--lib/librte_kvargs/rte_kvargs_version.map8
5 files changed, 115 insertions, 51 deletions
diff --git a/lib/librte_kvargs/Makefile b/lib/librte_kvargs/Makefile
index 4eaa9334..87593954 100644
--- a/lib/librte_kvargs/Makefile
+++ b/lib/librte_kvargs/Makefile
@@ -1,35 +1,5 @@
-# BSD LICENSE
-#
+# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2014 6WIND S.A.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions
-# are met:
-#
-# - Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# - Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in
-# the documentation and/or other materials provided with the
-# distribution.
-#
-# - Neither the name of 6WIND S.A. nor the names of its
-# contributors may be used to endorse or promote products derived
-# from this software without specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-# OF THE POSSIBILITY OF SUCH DAMAGE.
include $(RTE_SDK)/mk/rte.vars.mk
@@ -37,7 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
LIB = librte_kvargs.a
CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
-LDLIBS += -lrte_eal
+CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common/include
EXPORT_MAP := rte_kvargs_version.map
diff --git a/lib/librte_kvargs/meson.build b/lib/librte_kvargs/meson.build
index 0c5b9cb2..acd3e543 100644
--- a/lib/librte_kvargs/meson.build
+++ b/lib/librte_kvargs/meson.build
@@ -1,6 +1,11 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2017 Intel Corporation
+includes = [global_inc]
+includes += include_directories('../librte_eal/common/include')
+
version = 1
sources = files('rte_kvargs.c')
headers = files('rte_kvargs.h')
+
+deps += 'compat'
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 9662375e..a28f7694 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -6,14 +6,13 @@
#include <string.h>
#include <stdlib.h>
-#include <rte_log.h>
#include <rte_string_fns.h>
#include "rte_kvargs.h"
/*
* Receive a string with a list of arguments following the pattern
- * key=value;key=value;... and insert them into the list.
+ * key=value,key=value,... and insert them into the list.
* strtok() is used so the params string will be copied to be modified.
*/
static int
@@ -28,29 +27,22 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
* to pass to rte_strsplit
*/
kvlist->str = strdup(params);
- if (kvlist->str == NULL) {
- RTE_LOG(ERR, PMD, "Cannot parse arguments: not enough memory\n");
+ if (kvlist->str == NULL)
return -1;
- }
/* browse each key/value pair and add it in kvlist */
str = kvlist->str;
while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
i = kvlist->count;
- if (i >= RTE_KVARGS_MAX) {
- RTE_LOG(ERR, PMD, "Cannot parse arguments: list full\n");
+ if (i >= RTE_KVARGS_MAX)
return -1;
- }
kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
- if (kvlist->pairs[i].key == NULL || kvlist->pairs[i].value == NULL) {
- RTE_LOG(ERR, PMD,
- "Cannot parse arguments: wrong key or value\n"
- "params=<%s>\n", params);
+ if (kvlist->pairs[i].key == NULL ||
+ kvlist->pairs[i].value == NULL)
return -1;
- }
kvlist->count++;
str = NULL;
@@ -89,12 +81,8 @@ check_for_valid_keys(struct rte_kvargs *kvlist,
for (i = 0; i < kvlist->count; i++) {
pair = &kvlist->pairs[i];
ret = is_valid_key(valid, pair->key);
- if (!ret) {
- RTE_LOG(ERR, PMD,
- "Error parsing device, invalid key <%s>\n",
- pair->key);
+ if (!ret)
return -1;
- }
}
return 0;
}
@@ -154,7 +142,7 @@ rte_kvargs_free(struct rte_kvargs *kvlist)
}
/*
- * Parse the arguments "key=value;key=value;..." string and return
+ * Parse the arguments "key=value,key=value,..." string and return
* an allocated structure that contains a key/value list. Also
* check if only valid keys were used.
*/
@@ -180,3 +168,38 @@ rte_kvargs_parse(const char *args, const char * const valid_keys[])
return kvlist;
}
+
+__rte_experimental
+struct rte_kvargs *
+rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],
+ const char *valid_ends)
+{
+ struct rte_kvargs *kvlist = NULL;
+ char *copy;
+ size_t len;
+
+ if (valid_ends == NULL)
+ return rte_kvargs_parse(args, valid_keys);
+
+ copy = strdup(args);
+ if (copy == NULL)
+ return NULL;
+
+ len = strcspn(copy, valid_ends);
+ copy[len] = '\0';
+
+ kvlist = rte_kvargs_parse(copy, valid_keys);
+
+ free(copy);
+ return kvlist;
+}
+
+__rte_experimental
+int
+rte_kvargs_strcmp(const char *key __rte_unused,
+ const char *value, void *opaque)
+{
+ const char *str = opaque;
+
+ return -abs(strcmp(str, value));
+}
diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h
index 51b8120b..fc041956 100644
--- a/lib/librte_kvargs/rte_kvargs.h
+++ b/lib/librte_kvargs/rte_kvargs.h
@@ -25,6 +25,8 @@
extern "C" {
#endif
+#include <rte_compat.h>
+
/** Maximum number of key/value associations */
#define RTE_KVARGS_MAX 32
@@ -72,6 +74,36 @@ struct rte_kvargs *rte_kvargs_parse(const char *args,
const char *const valid_keys[]);
/**
+ * Allocate a rte_kvargs and store key/value associations from a string.
+ * This version will consider any byte from valid_ends as a possible
+ * terminating character, and will not parse beyond any of their occurrence.
+ *
+ * The function allocates and fills an rte_kvargs structure from a given
+ * string whose format is key1=value1,key2=value2,...
+ *
+ * The structure can be freed with rte_kvargs_free().
+ *
+ * @param args
+ * The input string containing the key/value associations
+ *
+ * @param valid_keys
+ * A list of valid keys (table of const char *, the last must be NULL).
+ * This argument is ignored if NULL
+ *
+ * @param valid_ends
+ * Acceptable terminating characters.
+ * If NULL, the behavior is the same as ``rte_kvargs_parse``.
+ *
+ * @return
+ * - A pointer to an allocated rte_kvargs structure on success
+ * - NULL on error
+ */
+__rte_experimental
+struct rte_kvargs *rte_kvargs_parse_delim(const char *args,
+ const char *const valid_keys[],
+ const char *valid_ends);
+
+/**
* Free a rte_kvargs structure
*
* Free a rte_kvargs structure previously allocated with
@@ -121,6 +153,32 @@ int rte_kvargs_process(const struct rte_kvargs *kvlist,
unsigned rte_kvargs_count(const struct rte_kvargs *kvlist,
const char *key_match);
+/**
+ * Generic kvarg handler for string comparison.
+ *
+ * This function can be used for a generic string comparison processing
+ * on a list of kvargs.
+ *
+ * @param key
+ * kvarg pair key.
+ *
+ * @param value
+ * kvarg pair value.
+ *
+ * @param opaque
+ * Opaque pointer to a string.
+ *
+ * @return
+ * 0 if the strings match.
+ * !0 otherwise or on error.
+ *
+ * Unless strcmp, comparison ordering is not kept.
+ * In order for rte_kvargs_process to stop processing on match error,
+ * a negative value is returned even if strcmp had returned a positive one.
+ */
+__rte_experimental
+int rte_kvargs_strcmp(const char *key, const char *value, void *opaque);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map
index 2030ec46..8f4b4e3f 100644
--- a/lib/librte_kvargs/rte_kvargs_version.map
+++ b/lib/librte_kvargs/rte_kvargs_version.map
@@ -8,3 +8,11 @@ DPDK_2.0 {
local: *;
};
+
+EXPERIMENTAL {
+ global:
+
+ rte_kvargs_parse_delim;
+ rte_kvargs_strcmp;
+
+} DPDK_2.0;