From 201891c31df7c51d853e137f222dacd96b2263d9 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 13 Sep 2017 14:13:37 -0700 Subject: ovsdb-error: New function ovsdb_error_to_json_free(). This simplifies little bits of code here and there. Signed-off-by: Ben Pfaff Tested-by: Yifeng Sun Reviewed-by: Yifeng Sun --- lib/ovsdb-error.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib/ovsdb-error.c') diff --git a/lib/ovsdb-error.c b/lib/ovsdb-error.c index 9b1af68c6..a75ad36b7 100644 --- a/lib/ovsdb-error.c +++ b/lib/ovsdb-error.c @@ -203,6 +203,8 @@ ovsdb_error_clone(const struct ovsdb_error *old) } } +/* Returns 'error' converted to the JSON object format described in RFC + * 7047. The caller must free the returned json (with json_destroy()). */ struct json * ovsdb_error_to_json(const struct ovsdb_error *error) { @@ -211,6 +213,8 @@ ovsdb_error_to_json(const struct ovsdb_error *error) if (error->details) { json_object_put_string(json, "details", error->details); } + + /* These are RFC 7047-compliant extensions. */ if (error->syntax) { json_object_put_string(json, "syntax", error->syntax); } @@ -218,6 +222,19 @@ ovsdb_error_to_json(const struct ovsdb_error *error) json_object_put_string(json, "io-error", ovs_retval_to_string(error->errno_)); } + + return json; +} + +/* Returns 'error' converted to the JSON object format described in RFC + * 7047. The caller must free the returned json (with json_destroy()). + * + * Also, frees 'error'. */ +struct json * +ovsdb_error_to_json_free(struct ovsdb_error *error) +{ + struct json *json = ovsdb_error_to_json(error); + ovsdb_error_destroy(error); return json; } -- cgit v1.2.1