ovs-dpctl: Support more than one option for "add-if" command.
[openvswitch] / utilities / ovs-vsctl.c
index 31c485bab7afc9ccf6b540c9f65eff41cf828c72..4435f41d197e5c7562cc9ede0b423fc18527918a 100644 (file)
@@ -1403,7 +1403,7 @@ get_external_id(char **keys, char **values, size_t n,
         if (!key && !strncmp(keys[i], prefix, prefix_len)) {
             svec_add_nocopy(&svec, xasprintf("%s=%s",
                                              keys[i] + prefix_len, values[i]));
-        } else if (key_matches(keys[i], prefix, prefix_len, key)) {
+        } else if (key && key_matches(keys[i], prefix, prefix_len, key)) {
             svec_add(&svec, values[i]);
             break;
         }
@@ -2408,13 +2408,12 @@ missing_operator_error(const char *arg, const char **allowed_operators,
 
 /* Breaks 'arg' apart into a number of fields in the following order:
  *
- *      - If 'columnp' is nonnull, the name of a column in 'table'.  The column
- *        is stored into '*columnp'.  The column name may be abbreviated.
+ *      - The name of a column in 'table', stored into '*columnp'.  The column
+ *        name may be abbreviated.
  *
- *      - If 'keyp' is nonnull, optionally a key string.  (If both 'columnp'
- *        and 'keyp' are nonnull, then the column and key names are expected to
- *        be separated by ':').  The key is stored as a malloc()'d string into
- *        '*keyp', or NULL if no key is present in 'arg'.
+ *      - Optionally ':' followed by a key string.  The key is stored as a
+ *        malloc()'d string into '*keyp', or NULL if no key is present in
+ *        'arg'.
  *
  *      - If 'valuep' is nonnull, an operator followed by a value string.  The
  *        allowed operators are the 'n_allowed' string in 'allowed_operators',
@@ -2424,8 +2423,6 @@ missing_operator_error(const char *arg, const char **allowed_operators,
  *        stored as a malloc()'d string into '*valuep', or NULL if no value is
  *        present in 'arg'.
  *
- * At least 'columnp' or 'keyp' must be nonnull.
- *
  * On success, returns NULL.  On failure, returned a malloc()'d string error
  * message and stores NULL into all of the nonnull output arguments. */
 static char * WARN_UNUSED_RESULT
@@ -2437,51 +2434,38 @@ parse_column_key_value(const char *arg,
                        char **valuep)
 {
     const char *p = arg;
+    char *column_name;
     char *error;
 
-    assert(columnp || keyp);
     assert(!(operatorp && !valuep));
-    if (keyp) {
-        *keyp = NULL;
-    }
+    *keyp = NULL;
     if (valuep) {
         *valuep = NULL;
     }
 
     /* Parse column name. */
-    if (columnp) {
-        char *column_name;
-
-        error = ovsdb_token_parse(&p, &column_name);
-        if (error) {
-            goto error;
-        }
-        if (column_name[0] == '\0') {
-            free(column_name);
-            error = xasprintf("%s: missing column name", arg);
-            goto error;
-        }
-        error = get_column(table, column_name, columnp);
+    error = ovsdb_token_parse(&p, &column_name);
+    if (error) {
+        goto error;
+    }
+    if (column_name[0] == '\0') {
         free(column_name);
-        if (error) {
-            goto error;
-        }
+        error = xasprintf("%s: missing column name", arg);
+        goto error;
+    }
+    error = get_column(table, column_name, columnp);
+    free(column_name);
+    if (error) {
+        goto error;
     }
 
     /* Parse key string. */
-    if (*p == ':' || !columnp) {
-        if (columnp) {
-            p++;
-        } else if (!keyp) {
-            error = xasprintf("%s: key not accepted here", arg);
-            goto error;
-        }
+    if (*p == ':') {
+        p++;
         error = ovsdb_token_parse(&p, keyp);
         if (error) {
             goto error;
         }
-    } else if (keyp) {
-        *keyp = NULL;
     }
 
     /* Parse value string. */
@@ -2529,13 +2513,9 @@ parse_column_key_value(const char *arg,
     return NULL;
 
 error:
-    if (columnp) {
-        *columnp = NULL;
-    }
-    if (keyp) {
-        free(*keyp);
-        *keyp = NULL;
-    }
+    *columnp = NULL;
+    free(*keyp);
+    *keyp = NULL;
     if (valuep) {
         free(*valuep);
         *valuep = NULL;
@@ -2869,6 +2849,7 @@ cmd_find(struct vsctl_context *ctx)
 
     next_row: ;
     }
+    free(columns);
 }
 
 static void
@@ -3146,7 +3127,9 @@ post_create(struct vsctl_context *ctx)
     const struct uuid *real;
     struct uuid dummy;
 
-    uuid_from_string(&dummy, ds_cstr(&ctx->output));
+    if (!uuid_from_string(&dummy, ds_cstr(&ctx->output))) {
+        NOT_REACHED();
+    }
     real = ovsdb_idl_txn_get_insert_uuid(ctx->txn, &dummy);
     if (real) {
         ds_clear(&ctx->output);