X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fovsdb-data.c;h=20d333eff177f6b93633f4b81d3bd627350d7acf;hb=f696f12fbe84f49d650f48c45ce1a24b94547ad2;hp=dba89acb588634a33129ed2b2c125fe851c1ecdc;hpb=2b66469b96c8a2955d4321fc7caf96be74d33185;p=openvswitch diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c index dba89acb..20d333ef 100644 --- a/lib/ovsdb-data.c +++ b/lib/ovsdb-data.c @@ -264,6 +264,7 @@ unwrap_json(const struct json *json, const char *name, || (name && strcmp(json->u.array.elems[0]->u.string, name)) || json->u.array.elems[1]->type != value_type) { + *value = NULL; return ovsdb_syntax_error(json, NULL, "expected [\"%s\", <%s>]", name, json_type_to_string(value_type)); } @@ -1214,23 +1215,6 @@ ovsdb_datum_from_json(struct ovsdb_datum *datum, return error; } -/* This is the same as ovsdb_datum_from_json(), except that duplicate values - * in a set or map are dropped instead of being treated as an error. */ -struct ovsdb_error * -ovsdb_datum_from_json_unique(struct ovsdb_datum *datum, - const struct ovsdb_type *type, - const struct json *json, - struct ovsdb_symbol_table *symtab) -{ - struct ovsdb_error *error; - - error = ovsdb_datum_from_json__(datum, type, json, symtab); - if (!error) { - ovsdb_datum_sort_unique(datum, type->key.type, type->value.type); - } - return error; -} - /* Converts 'datum', of the specified 'type', to JSON format, and returns the * JSON. The caller is responsible for freeing the returned JSON. * @@ -1461,6 +1445,31 @@ ovsdb_datum_to_string(const struct ovsdb_datum *datum, } } +/* Initializes 'datum' as a string-to-string map whose contents are taken from + * 'sh'. Destroys 'sh'. */ +void +ovsdb_datum_from_shash(struct ovsdb_datum *datum, struct shash *sh) +{ + struct shash_node *node, *next; + size_t i; + + datum->n = shash_count(sh); + datum->keys = xmalloc(datum->n * sizeof *datum->keys); + datum->values = xmalloc(datum->n * sizeof *datum->values); + + i = 0; + SHASH_FOR_EACH_SAFE (node, next, sh) { + datum->keys[i].string = node->name; + datum->values[i].string = node->data; + shash_steal(sh, node); + i++; + } + assert(i == datum->n); + + shash_destroy(sh); + ovsdb_datum_sort_unique(datum, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING); +} + static uint32_t hash_atoms(enum ovsdb_atomic_type type, const union ovsdb_atom *atoms, unsigned int n, uint32_t basis)