[ovs-dev] [PATCH 13/13] json: New function json_object_put_format().

Ben Pfaff blp at ovn.org
Sat Oct 7 00:44:58 UTC 2017


This will acquire users in an upcoming commit.

Signed-off-by: Ben Pfaff <blp at ovn.org>
---
 include/openvswitch/json.h |  6 +++++-
 lib/json.c                 | 12 ++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/openvswitch/json.h b/include/openvswitch/json.h
index edf53e594eb0..61b9a02cfc19 100644
--- a/include/openvswitch/json.h
+++ b/include/openvswitch/json.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009, 2010, 2015 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2015, 2016 Nicira, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@ extern "C" {
 #endif
 
 struct ds;
+struct uuid;
 
 /* Type of a JSON value. */
 enum json_type {
@@ -92,6 +93,9 @@ struct json *json_object_create(void);
 void json_object_put(struct json *, const char *name, struct json *value);
 void json_object_put_string(struct json *,
                             const char *name, const char *value);
+void json_object_put_format(struct json *,
+                            const char *name, const char *format, ...)
+    OVS_PRINTF_FORMAT(3, 4);
 
 const char *json_string(const struct json *);
 struct json_array *json_array(const struct json *);
diff --git a/lib/json.c b/lib/json.c
index b98e60f87f4b..5e93190b8a03 100644
--- a/lib/json.c
+++ b/lib/json.c
@@ -29,6 +29,7 @@
 #include "openvswitch/shash.h"
 #include "unicode.h"
 #include "util.h"
+#include "uuid.h"
 
 /* The type of a JSON token. */
 enum json_token_type {
@@ -284,6 +285,17 @@ json_object_put_string(struct json *json, const char *name, const char *value)
     json_object_put(json, name, json_string_create(value));
 }
 
+void OVS_PRINTF_FORMAT(3, 4)
+json_object_put_format(struct json *json,
+                       const char *name, const char *format, ...)
+{
+    va_list args;
+    va_start(args, format);
+    json_object_put(json, name,
+                    json_string_create_nocopy(xvasprintf(format, args)));
+    va_end(args);
+}
+
 const char *
 json_string(const struct json *json)
 {
-- 
2.10.2



More information about the dev mailing list