diff options
author | Ben Pfaff <blp@ovn.org> | 2017-09-13 14:13:37 -0700 |
---|---|---|
committer | Ben Pfaff <blp@ovn.org> | 2017-12-13 11:32:54 -0800 |
commit | 201891c31df7c51d853e137f222dacd96b2263d9 (patch) | |
tree | 2e45fbfbc75704a815af6da53662de6777c5eca4 /lib/ovsdb-error.c | |
parent | 3865965dd99325bd7bcd5bd3ab2a5d059dd4832e (diff) | |
download | openvswitch-201891c31df7c51d853e137f222dacd96b2263d9.tar.gz |
ovsdb-error: New function ovsdb_error_to_json_free().
This simplifies little bits of code here and there.
Signed-off-by: Ben Pfaff <blp@ovn.org>
Tested-by: Yifeng Sun <pkusunyifeng@gmail.com>
Reviewed-by: Yifeng Sun <pkusunyifeng@gmail.com>
Diffstat (limited to 'lib/ovsdb-error.c')
-rw-r--r-- | lib/ovsdb-error.c | 17 |
1 files changed, 17 insertions, 0 deletions
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 <error> 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 <error> 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; } |