projects
/
openvswitch
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ofp-msgs: Open Flow 1.1 and 1.2 Port Status Messages
[openvswitch]
/
lib
/
ovsdb-data.c
diff --git
a/lib/ovsdb-data.c
b/lib/ovsdb-data.c
index 150ae618ef83106ea4fc6bc8754f0990a0f118dc..e357233bc69a063616fe70513f1eab446e021b46 100644
(file)
--- a/
lib/ovsdb-data.c
+++ b/
lib/ovsdb-data.c
@@
-1,4
+1,4
@@
-/* Copyright (c) 2009, 2010, 2011
Nicira Networks
+/* Copyright (c) 2009, 2010, 2011
, 2012 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@
-29,6
+29,7
@@
#include "ovsdb-parser.h"
#include "json.h"
#include "shash.h"
#include "ovsdb-parser.h"
#include "json.h"
#include "shash.h"
+#include "smap.h"
#include "sort.h"
#include "unicode.h"
#include "sort.h"
#include "unicode.h"
@@
-590,6
+591,7
@@
ovsdb_atom_from_string(union ovsdb_atom *atom,
error = ovsdb_atom_check_constraints(atom, base);
if (error) {
error = ovsdb_atom_check_constraints(atom, base);
if (error) {
+ ovsdb_atom_destroy(atom, base->type);
msg = ovsdb_error_to_string(error);
ovsdb_error_destroy(error);
}
msg = ovsdb_error_to_string(error);
ovsdb_error_destroy(error);
}
@@
-690,8
+692,7
@@
check_string_constraints(const char *s,
struct ovsdb_error *error;
error = ovsdb_error("constraint violation",
struct ovsdb_error *error;
error = ovsdb_error("constraint violation",
- "\"%s\" is not a valid UTF-8 string: %s",
- s, msg);
+ "not a valid UTF-8 string: %s", msg);
free(msg);
return error;
}
free(msg);
return error;
}
@@
-883,9
+884,10
@@
ovsdb_datum_default(const struct ovsdb_type *type)
d = &default_data[kt][vt];
if (!d->n) {
d->n = 1;
d = &default_data[kt][vt];
if (!d->n) {
d->n = 1;
- d->keys =
(union ovsdb_atom *) ovsdb_atom_default(kt
);
+ d->keys =
CONST_CAST(union ovsdb_atom *, ovsdb_atom_default(kt)
);
if (vt != OVSDB_TYPE_VOID) {
if (vt != OVSDB_TYPE_VOID) {
- d->values = (union ovsdb_atom *) ovsdb_atom_default(vt);
+ d->values = CONST_CAST(union ovsdb_atom *,
+ ovsdb_atom_default(vt));
}
}
return d;
}
}
return d;
@@
-1279,30
+1281,30
@@
struct json *
ovsdb_datum_to_json(const struct ovsdb_datum *datum,
const struct ovsdb_type *type)
{
ovsdb_datum_to_json(const struct ovsdb_datum *datum,
const struct ovsdb_type *type)
{
- if (datum->n == 1 && !ovsdb_type_is_map(type)) {
- return ovsdb_atom_to_json(&datum->keys[0], type->key.type);
- } else if (type->value.type == OVSDB_TYPE_VOID) {
+ if (ovsdb_type_is_map(type)) {
struct json **elems;
size_t i;
elems = xmalloc(datum->n * sizeof *elems);
for (i = 0; i < datum->n; i++) {
struct json **elems;
size_t i;
elems = xmalloc(datum->n * sizeof *elems);
for (i = 0; i < datum->n; i++) {
- elems[i] = ovsdb_atom_to_json(&datum->keys[i], type->key.type);
+ elems[i] = json_array_create_2(
+ ovsdb_atom_to_json(&datum->keys[i], type->key.type),
+ ovsdb_atom_to_json(&datum->values[i], type->value.type));
}
}
- return wrap_json("set", json_array_create(elems, datum->n));
+ return wrap_json("map", json_array_create(elems, datum->n));
+ } else if (datum->n == 1) {
+ return ovsdb_atom_to_json(&datum->keys[0], type->key.type);
} else {
struct json **elems;
size_t i;
elems = xmalloc(datum->n * sizeof *elems);
for (i = 0; i < datum->n; i++) {
} else {
struct json **elems;
size_t i;
elems = xmalloc(datum->n * sizeof *elems);
for (i = 0; i < datum->n; i++) {
- elems[i] = json_array_create_2(
- ovsdb_atom_to_json(&datum->keys[i], type->key.type),
- ovsdb_atom_to_json(&datum->values[i], type->value.type));
+ elems[i] = ovsdb_atom_to_json(&datum->keys[i], type->key.type);
}
}
- return wrap_json("
map
", json_array_create(elems, datum->n));
+ return wrap_json("
set
", json_array_create(elems, datum->n));
}
}
}
}
@@
-1524,27
+1526,26
@@
ovsdb_datum_to_bare(const struct ovsdb_datum *datum,
}
/* Initializes 'datum' as a string-to-string map whose contents are taken from
}
/* Initializes 'datum' as a string-to-string map whose contents are taken from
- * 's
h'. Destroys 'sh
'. */
+ * 's
map'. Destroys 'smap
'. */
void
void
-ovsdb_datum_from_s
hash(struct ovsdb_datum *datum, struct shash *sh
)
+ovsdb_datum_from_s
map(struct ovsdb_datum *datum, struct smap *smap
)
{
{
- struct s
hash
_node *node, *next;
+ struct s
map
_node *node, *next;
size_t i;
size_t i;
- datum->n = s
hash_count(sh
);
+ datum->n = s
map_count(smap
);
datum->keys = xmalloc(datum->n * sizeof *datum->keys);
datum->values = xmalloc(datum->n * sizeof *datum->values);
i = 0;
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);
+ SMAP_FOR_EACH_SAFE (node, next, smap) {
+ smap_steal(smap, node,
+ &datum->keys[i].string, &datum->values[i].string);
i++;
}
assert(i == datum->n);
i++;
}
assert(i == datum->n);
- s
hash_destroy(sh
);
+ s
map_destroy(smap
);
ovsdb_datum_sort_unique(datum, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING);
}
ovsdb_datum_sort_unique(datum, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING);
}
@@
-1688,6
+1689,9
@@
ovsdb_datum_includes_all(const struct ovsdb_datum *a,
{
size_t i;
{
size_t i;
+ if (a->n > b->n) {
+ return false;
+ }
for (i = 0; i < a->n; i++) {
if (ovsdb_datum_find(a, i, b, type) == UINT_MAX) {
return false;
for (i = 0; i < a->n; i++) {
if (ovsdb_datum_find(a, i, b, type) == UINT_MAX) {
return false;