ofproto: Querying port stats for individual ports (OpenFlow 1.0)
[openvswitch] / lib / ovsdb-types.c
index ff819609f8e9734af2fb0557447b5b03665d2f50..5b7e7d8f68d37793607b53d12c831a123f9f0082 100644 (file)
@@ -134,7 +134,9 @@ ovsdb_base_type_init(struct ovsdb_base_type *base, enum ovsdb_atomic_type type)
         break;
 
     case OVSDB_TYPE_STRING:
+#ifdef HAVE_PCRE
         base->u.string.re = NULL;
+#endif
         base->u.string.reMatch = NULL;
         base->u.string.reComment = NULL;
         base->u.string.minLen = 0;
@@ -142,6 +144,8 @@ ovsdb_base_type_init(struct ovsdb_base_type *base, enum ovsdb_atomic_type type)
         break;
 
     case OVSDB_TYPE_UUID:
+        base->u.uuid.refTableName = NULL;
+        base->u.uuid.refTable = NULL;
         break;
 
     case OVSDB_N_TYPES:
@@ -166,12 +170,25 @@ ovsdb_base_type_clone(struct ovsdb_base_type *dst,
         break;
 
     case OVSDB_TYPE_STRING:
+#if HAVE_PCRE
         if (dst->u.string.re) {
             pcre_refcount(dst->u.string.re, 1);
         }
+#else
+        if (dst->u.string.reMatch) {
+            dst->u.string.reMatch = xstrdup(dst->u.string.reMatch);
+        }
+        if (dst->u.string.reComment) {
+            dst->u.string.reComment = xstrdup(dst->u.string.reComment);
+        }
+#endif
         break;
 
+
     case OVSDB_TYPE_UUID:
+        if (dst->u.uuid.refTableName) {
+            dst->u.uuid.refTableName = xstrdup(dst->u.uuid.refTableName);
+        }
         break;
 
     case OVSDB_N_TYPES:
@@ -192,14 +209,20 @@ ovsdb_base_type_destroy(struct ovsdb_base_type *base)
             break;
 
         case OVSDB_TYPE_STRING:
+#ifdef HAVE_PCRE
             if (base->u.string.re && !pcre_refcount(base->u.string.re, -1)) {
                 pcre_free(base->u.string.re);
                 free(base->u.string.reMatch);
                 free(base->u.string.reComment);
             }
+#else
+            free(base->u.string.reMatch);
+            free(base->u.string.reComment);
+#endif
             break;
 
         case OVSDB_TYPE_UUID:
+            free(base->u.uuid.refTableName);
             break;
 
         case OVSDB_N_TYPES:
@@ -263,7 +286,7 @@ ovsdb_base_type_has_constraints(const struct ovsdb_base_type *base)
                 || base->u.string.maxLen != UINT_MAX);
 
     case OVSDB_TYPE_UUID:
-        return false;
+        return base->u.uuid.refTableName != NULL;
 
     case OVSDB_N_TYPES:
         NOT_REACHED();
@@ -285,6 +308,7 @@ struct ovsdb_error *
 ovsdb_base_type_set_regex(struct ovsdb_base_type *base,
                           const char *reMatch, const char *reComment)
 {
+#ifdef HAVE_PCRE
     const char *errorString;
     const char *pattern;
     int errorOffset;
@@ -294,6 +318,10 @@ ovsdb_base_type_set_regex(struct ovsdb_base_type *base,
     if (pattern[0] == '\0' || strchr(pattern, '\0')[-1] != '$') {
         pattern = xasprintf("%s$", pattern);
     }
+
+#ifndef PCRE_JAVASCRIPT_COMPAT  /* Added in PCRE 7.7. */
+#define PCRE_JAVASCRIPT_COMPAT 0
+#endif
     base->u.string.re = pcre_compile(pattern, (PCRE_ANCHORED | PCRE_UTF8
                                                | PCRE_JAVASCRIPT_COMPAT),
                                      &errorString, &errorOffset, NULL);
@@ -305,9 +333,10 @@ ovsdb_base_type_set_regex(struct ovsdb_base_type *base,
                                   "\"%s\" is not a valid regular "
                                   "expression: %s", reMatch, errorString);
     }
+    pcre_refcount(base->u.string.re, 1);
+#endif
 
     /* Save regular expression. */
-    pcre_refcount(base->u.string.re, 1);
     base->u.string.reMatch = xstrdup(reMatch);
     base->u.string.reComment = reComment ? xstrdup(reComment) : NULL;
     return NULL;
@@ -411,6 +440,17 @@ ovsdb_base_type_from_json(struct ovsdb_base_type *base,
             error = ovsdb_syntax_error(json, NULL,
                                        "minLength exceeds maxLength");
         }
+    } else if (base->type == OVSDB_TYPE_UUID) {
+        const struct json *refTable;
+
+        refTable = ovsdb_parser_member(&parser, "refTable",
+                                       OP_ID | OP_OPTIONAL);
+        if (refTable) {
+            base->u.uuid.refTableName = xstrdup(refTable->u.string);
+            /* We can't set base->u.uuid.refTable here because we don't have
+             * enough context (we might not even be running in ovsdb-server).
+             * ovsdb_create() will set refTable later. */
+        }
     }
 
     if (error) {
@@ -485,6 +525,10 @@ ovsdb_base_type_to_json(const struct ovsdb_base_type *base)
         break;
 
     case OVSDB_TYPE_UUID:
+        if (base->u.uuid.refTableName) {
+            json_object_put_string(json, "refTable",
+                                   base->u.uuid.refTableName);
+        }
         break;
 
     case OVSDB_N_TYPES:
@@ -522,7 +566,8 @@ ovsdb_type_is_valid(const struct ovsdb_type *type)
             && ovsdb_base_type_is_valid(&type->key)
             && ovsdb_base_type_is_valid(&type->value)
             && type->n_min <= 1
-            && type->n_min <= type->n_max);
+            && type->n_min <= type->n_max
+            && type->n_max >= 1);
 }
 
 static struct ovsdb_error *