]> git.proxmox.com Git - ovs.git/commitdiff
smap: New function smap_get_uuid().
authorBen Pfaff <blp@nicira.com>
Sat, 18 Jul 2015 23:59:08 +0000 (16:59 -0700)
committerBen Pfaff <blp@nicira.com>
Mon, 3 Aug 2015 17:16:44 +0000 (10:16 -0700)
To be used in an upcoming commit.

Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Russell Bryant <rbryant@redhat.com>
Acked-by: Justin Pettit <jpettit@nicira.com>
lib/smap.c
lib/smap.h

index 8865a8898cf061711edfca77487be0bc7d003ba0..1d59f568f4ae4580260e2932a6b486a7c4e6416a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014 Nicira, Inc.
+/* Copyright (c) 2012, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 
 #include "hash.h"
 #include "json.h"
+#include "uuid.h"
 
 static struct smap_node *smap_add__(struct smap *, char *, void *,
                                     size_t hash);
@@ -215,6 +216,16 @@ smap_get_int(const struct smap *smap, const char *key, int def)
     return value ? atoi(value) : def;
 }
 
+/* Gets the value associated with 'key' in 'smap' and converts it to a UUID
+ * using uuid_from_string().  Returns true if successful, false if 'key' is not
+ * in 'smap' or if 'key' does not have the correct syntax for a UUID. */
+bool
+smap_get_uuid(const struct smap *smap, const char *key, struct uuid *uuid)
+{
+    const char *value = smap_get(smap, key);
+    return value && uuid_from_string(uuid, value);
+}
+
 /* Returns true of there are no elements in 'smap'. */
 bool
 smap_is_empty(const struct smap *smap)
index cac3878990081285a7267c99b33b3ae9f47a3166..846e38407dcd52b2315249d4540b7602655cbcb1 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012, 2014 Nicira, Inc.
+/* Copyright (c) 2012, 2014, 2015 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
 #include "hmap.h"
 
 struct json;
+struct uuid;
 
 /* A map from string to string. */
 struct smap {
@@ -57,6 +58,7 @@ const char *smap_get(const struct smap *, const char *);
 struct smap_node *smap_get_node(const struct smap *, const char *);
 bool smap_get_bool(const struct smap *smap, const char *key, bool def);
 int smap_get_int(const struct smap *smap, const char *key, int def);
+bool smap_get_uuid(const struct smap *, const char *key, struct uuid *);
 
 bool smap_is_empty(const struct smap *);
 size_t smap_count(const struct smap *);