-/* Copyright (c) 2009 Nicira Networks
+/* Copyright (c) 2009, 2010 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
bool mutable, bool persistent,
const struct ovsdb_type *type)
{
+ /* Doesn't set the new column's 'index': the caller must do that. */
struct ovsdb_column *column;
column = xzalloc(sizeof *column);
column->comment = comment ? xstrdup(comment) : NULL;
column->mutable = mutable;
column->persistent = persistent;
- column->type = *type;
+ ovsdb_type_clone(&column->type, type);
return column;
}
+struct ovsdb_column *
+ovsdb_column_clone(const struct ovsdb_column *old)
+{
+ /* Doesn't copy the column's 'index': the caller must do that. */
+ return ovsdb_column_create(old->name, old->comment,
+ old->mutable, old->persistent,
+ &old->type);
+}
+
void
ovsdb_column_destroy(struct ovsdb_column *column)
{
+ ovsdb_type_destroy(&column->type);
free(column->name);
free(column->comment);
free(column);
comment ? json_string(comment) : NULL,
mutable ? json_boolean(mutable) : true,
persistent, &type);
+
+ ovsdb_type_destroy(&type);
+
return NULL;
}
return NULL;
} else {
+ struct ovsdb_error *error = NULL;
size_t i;
if (json->type != JSON_ARRAY) {
/* XXX this is O(n**2) */
for (i = 0; i < json->u.array.n; i++) {
- struct ovsdb_column *column;
+ const struct ovsdb_column *column;
+ const char *s;
if (json->u.array.elems[i]->type != JSON_STRING) {
goto error;
}
- column = shash_find_data(&table->schema->columns,
- json->u.array.elems[i]->u.string);
- if (ovsdb_column_set_contains(set, column->index)) {
+ s = json->u.array.elems[i]->u.string;
+ column = shash_find_data(&table->schema->columns, s);
+ if (!column) {
+ error = ovsdb_syntax_error(json, NULL, "%s is not a valid "
+ "column name", s);
+ goto error;
+ } else if (ovsdb_column_set_contains(set, column->index)) {
goto error;
}
ovsdb_column_set_add(set, column);
}
-
return NULL;
- }
-error:
- ovsdb_column_set_destroy(set);
- return ovsdb_syntax_error(json, NULL,
- "array of distinct column names expected");
+ error:
+ ovsdb_column_set_destroy(set);
+ ovsdb_column_set_init(set);
+ if (!error) {
+ error = ovsdb_syntax_error(json, NULL, "array of distinct column "
+ "names expected");
+ }
+ return error;
+ }
}
struct json *