[ovs-dev] [join ovsdb schema v2 6/8] ovsdb: add logic for parsing schema file names from a string
Andy Zhou
azhou at nicira.com
Thu Jun 25 21:53:38 UTC 2015
Any ovsdb programs that accepts a single schema file name will be
extended to accept multiple file names. This patch implements the
parsing logic for future patches.
Signed-off-by: Andy Zhou <azhou at nicira.com>
---
ovsdb/ovsdb.c | 38 ++++++++++++++++++++++++++++++++++++++
ovsdb/ovsdb.h | 2 ++
2 files changed, 40 insertions(+)
diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c
index 5929306..5305360 100644
--- a/ovsdb/ovsdb.c
+++ b/ovsdb/ovsdb.c
@@ -24,6 +24,7 @@
#include "ovsdb-parser.h"
#include "ovsdb-types.h"
#include "simap.h"
+#include "sset.h"
#include "table.h"
#include "transaction.h"
@@ -673,3 +674,40 @@ error:
return err;
}
+
+/*
+ * Parse schema file names from a string.
+ *
+ * A leading comma indicates the default schema name.
+ *
+ * Duplicated filenames will be ignored. */
+void
+ovsdb_parse_schema_file_names(const char *file_names, struct sset *name_set,
+ const char *default_schema)
+{
+ const char *delimiter=", \t\r\n";
+ const char *filename;
+ char *saveptr;
+ char *fns;
+
+ if (!file_names) {
+ sset_add(name_set, default_schema);
+ return;
+ }
+
+ if (*file_names == ',') {
+ sset_add(name_set, default_schema);
+ }
+
+ fns = xstrdup(file_names);
+ filename = strtok_r(fns, delimiter, &saveptr);
+ if (!filename) {
+ filename = default_schema;
+ }
+
+ while(filename) {
+ sset_add(name_set, filename);
+ filename = strtok_r(NULL, delimiter, &saveptr);
+ }
+ free(fns);
+}
diff --git a/ovsdb/ovsdb.h b/ovsdb/ovsdb.h
index 2e7f7e0..b61b6ba 100644
--- a/ovsdb/ovsdb.h
+++ b/ovsdb/ovsdb.h
@@ -56,6 +56,8 @@ struct shash *ovsdb_schemas_clone(const struct shash *schemas);
struct ovsdb_error *ovsdb_schemas_from_files(const struct sset *files,
struct shash** )
OVS_WARN_UNUSED_RESULT;
+void ovsdb_parse_schema_file_names(const char *file_names, struct sset *names,
+ const char *default_schema);
void ovsdb_schemas_destroy(struct shash *schemas);
struct json *ovsdb_schemas_to_json(const struct shash *schemas)
OVS_WARN_UNUSED_RESULT;
--
1.9.1
More information about the dev
mailing list