json: Move from lib to include/openvswitch.
[cascardo/ovs.git] / ovsdb / mutation.c
index 7ae83fe..e5d192e 100644 (file)
@@ -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.
 
 #include "column.h"
 #include "ovsdb-error.h"
-#include "json.h"
+#include "openvswitch/json.h"
 #include "row.h"
+
+#include <string.h>
+
 #include "table.h"
+#include "util.h"
 
 struct ovsdb_error *
 ovsdb_mutator_from_string(const char *name, enum ovsdb_mutator *mutator)
@@ -53,7 +57,7 @@ ovsdb_mutator_to_string(enum ovsdb_mutator mutator)
     return NULL;
 }
 
-static WARN_UNUSED_RESULT struct ovsdb_error *
+static OVS_WARN_UNUSED_RESULT struct ovsdb_error *
 type_mismatch(const struct ovsdb_mutation *m, const struct json *json)
 {
     struct ovsdb_error *error;
@@ -69,7 +73,7 @@ type_mismatch(const struct ovsdb_mutation *m, const struct json *json)
     return error;
 }
 
-static WARN_UNUSED_RESULT struct ovsdb_error *
+static OVS_WARN_UNUSED_RESULT struct ovsdb_error *
 ovsdb_mutation_from_json(const struct ovsdb_table_schema *ts,
                          const struct json *json,
                          struct ovsdb_symbol_table *symtab,
@@ -95,6 +99,12 @@ ovsdb_mutation_from_json(const struct ovsdb_table_schema *ts,
                                   "No column %s in table %s.",
                                   column_name, ts->name);
     }
+    if (!m->column->mutable) {
+        return ovsdb_syntax_error(json, "constraint violation",
+                                  "Cannot mutate immutable column %s in "
+                                  "table %s.", column_name, ts->name);
+    }
+
     ovsdb_type_clone(&m->type, &m->column->type);
 
     mutator_name = json_string(array->elems[1]);
@@ -144,7 +154,7 @@ ovsdb_mutation_from_json(const struct ovsdb_table_schema *ts,
         break;
 
     default:
-        NOT_REACHED();
+        OVS_NOT_REACHED();
     }
 
 exit:
@@ -300,7 +310,7 @@ mutate_scalar(const struct ovsdb_type *dst_type, struct ovsdb_datum *dst,
             }
         }
     } else {
-        NOT_REACHED();
+        OVS_NOT_REACHED();
     }
 
     for (i = 0; i < dst->n; i++) {
@@ -381,7 +391,7 @@ ovsdb_mutation_set_execute(struct ovsdb_row *row,
             break;
 
         default:
-            NOT_REACHED();
+            OVS_NOT_REACHED();
         }
         if (error) {
             return error;