diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dd9ac21..412356e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,8 @@ Expected: July 2023 ### C/CLI-API changes on existing features Developers may need to change their code +* Added output function to JSON output: + * `xml2json_vec(...,skiptop)` --> `xml2json_vec(..., cligen_output, skiptop)` * `yang2cli_yspec` removed last argument `printgen`. * Removed obsolete: `cli_auto_show()` diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 71ee0f0b..444b68eb 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -506,7 +506,7 @@ cli_show_common(clicon_handle h, if (format == FORMAT_JSON){ switch (format){ case FORMAT_JSON: - if (xml2json_vec(stdout, vec, veclen, pretty, skiptop) < 0) // XXX cligen_output + if (xml2json_vec(stdout, vec, veclen, pretty, cligen_output, skiptop) < 0) goto done; break; default: diff --git a/lib/clixon/clixon_json.h b/lib/clixon/clixon_json.h index 4b5a9785..5758aa6b 100644 --- a/lib/clixon/clixon_json.h +++ b/lib/clixon/clixon_json.h @@ -48,7 +48,7 @@ int clixon_json2cbuf(cbuf *cb, cxobj *x, int pretty, int skiptop, int autocliext int xml2json_cbuf_vec(cbuf *cb, cxobj **vec, size_t veclen, int pretty, int skiptop); int clixon_json2file(FILE *f, cxobj *x, int pretty, clicon_output_cb *fn, int skiptop, int autocliext); int json_print(FILE *f, cxobj *x); -int xml2json_vec(FILE *f, cxobj **vec, size_t veclen, int pretty, int skiptop); +int xml2json_vec(FILE *f, cxobj **vec, size_t veclen, int pretty, clicon_output_cb *fn, int skiptop); int clixon_json_parse_string(char *str, int rfc7951, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xret); int clixon_json_parse_file(FILE *fp, int rfc7951, yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xret); diff --git a/lib/src/clixon_json.c b/lib/src/clixon_json.c index 4e107849..9c6bb5c8 100644 --- a/lib/src/clixon_json.c +++ b/lib/src/clixon_json.c @@ -1227,7 +1227,7 @@ xml2json_cbuf_vec(cbuf *cb, * @param[in] f File to print to * @param[in] xn XML tree to translate from * @param[in] pretty Set if output is pretty-printed - * @param[in] fn File print function (if NULL, use fprintf) + * @param[in] fn File print function * @param[in] skiptop 0: Include top object 1: Skip top-object, only children, * @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow * @retval 0 OK @@ -1286,6 +1286,7 @@ json_print(FILE *f, * @param[in] vec Vector of xml objecst * @param[in] veclen Length of vector * @param[in] pretty Set if output is pretty-printed (2 for debug) + * @param[in] fn File print function * @param[in] skiptop 0: Include top object 1: Skip top-object, only children, * @retval 0 OK * @retval -1 Error @@ -1294,11 +1295,12 @@ json_print(FILE *f, * @see xml2json1_cbuf */ int -xml2json_vec(FILE *f, - cxobj **vec, - size_t veclen, - int pretty, - int skiptop) +xml2json_vec(FILE *f, + cxobj **vec, + size_t veclen, + int pretty, + clicon_output_cb *fn, + int skiptop) { int retval = 1; cbuf *cb = NULL; @@ -1309,7 +1311,7 @@ xml2json_vec(FILE *f, } if (xml2json_cbuf_vec(cb, vec, veclen, pretty, skiptop) < 0) goto done; - fprintf(f, "%s\n", cbuf_get(cb)); + (*fn)(f, "%s\n", cbuf_get(cb)); retval = 0; done: if (cb)