[ovs-dev] [ovsdb join 3/5] ovsdb: Add logic for parsing schema filenames from string
Andy Zhou
azhou at nicira.com
Tue Jun 16 02:35:54 UTC 2015
Any ovsdb programs that accepts a single schema file name will be
extended to accepts multiple file names. This patch implements the
file name parsing logic for future patches.
Signed-off-by: Andy Zhou <azhou at nicira.com>
---
ovsdb/ovsdb.c | 39 +++++++++++++++++++++++++++++++++++++++
ovsdb/ovsdb.h | 2 ++
2 files changed, 41 insertions(+)
diff --git a/ovsdb/ovsdb.c b/ovsdb/ovsdb.c
index 5ec59ca..02db118 100644
--- a/ovsdb/ovsdb.c
+++ b/ovsdb/ovsdb.c
@@ -24,6 +24,8 @@
#include "ovsdb-types.h"
#include "simap.h"
#include "table.h"
+#include "table.h"
+#include "sset.h"
#include "transaction.h"
struct ovsdb_schema *
@@ -608,3 +610,40 @@ error:
return err;
}
+
+/*
+ * Parse schemea file names passed 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 e3f3b1e..c711585 100644
--- a/ovsdb/ovsdb.h
+++ b/ovsdb/ovsdb.h
@@ -52,6 +52,8 @@ struct ovsdb_error *ovsdb_schema_from_json(struct json *,
struct json *ovsdb_schema_to_json(const struct ovsdb_schema *);
/* Multiple schemas. */
+void ovsdb_parse_schema_file_names(const char *file_names, struct sset *names,
+ const char *default_schema);
struct ovsdb_error *ovsdb_schemata_from_files(struct sset *files,
struct shash* schemata);
void ovsdb_schemata_destroy(struct shash *schemata);
--
1.9.1
More information about the dev
mailing list