Changed C-API for xml translation/print to other formats.

* Added `skiptop` parameter, if set only apply to children of a node, skip top node
    * default is 0
* Functions are merged, ie removed and replaced with more generic functions
* `xml2json_cbuf()`: Added `skiptop` parameter: `xml2json_cbuf(..., int skiptop)`
* `xml2json()` and `xml2json_cb()` merged into `xml2json_file()` with `skiptop`
    * Replace `xml2json(...)` with `xml2json_file(..., stdout, 0)`
    * Replace `xml2json_cb(...)` with `xml2json_file(..., 0)`
* `clicon_xml2cbuf()`: Added `skiptop` parameter: `clicon_xml2cbuf(..., int skiptop)`
* `xml2cli()`: Added `skiptop` parameter: `xml2cli(..., int skiptop)`
This commit is contained in:
Olof hagsand 2022-06-01 10:48:39 +02:00
parent 724b94137f
commit 43a57dad79
39 changed files with 306 additions and 481 deletions

View file

@ -119,7 +119,7 @@ yang_patch_xml2json_modified_cbuf(cxobj *x_simple_patch)
if (json_simple_patch == NULL)
return NULL;
cb = cbuf_new();
xml2json_cbuf(cb, x_simple_patch, 1);
xml2json_cbuf(cb, x_simple_patch, 0);
// Insert a '[' after the first '{' to get the JSON to match what api_data_post/write() expect
json_simple_patch_tmp = cbuf_get(cb);
@ -266,7 +266,7 @@ yang_patch_do_replace(clicon_handle h,
}
}
// Convert the data to json
xml2json_cbuf(json_simple_patch, x_simple_patch, 1);
xml2json_cbuf(json_simple_patch, x_simple_patch, 0);
// Send the POST request
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri), pi, qvec, cbuf_get(json_simple_patch), pretty, YANG_DATA_JSON, media_out, ds ) < 0)
@ -327,7 +327,7 @@ yang_patch_do_create(clicon_handle h,
xml_addsub(x_simple_patch, value_vec_tmp);
}
}
if (xml2json_cbuf(cb, x_simple_patch, 1) < 0)
if (xml2json_cbuf(cb, x_simple_patch, 0) < 0)
goto done;
if (api_data_post(h, req, cbuf_get(simple_patch_request_uri),
pi, qvec,
@ -477,7 +477,7 @@ yang_patch_do_merge(clicon_handle h,
xml_addsub(x_simple_patch, value_vec_tmp);
}
cbuf_reset(cb); /* reuse cb */
xml2json_cbuf(cb, x_simple_patch, 1);
xml2json_cbuf(cb, x_simple_patch, 0);
if ((json_simple_patch = yang_patch_xml2json_modified_cbuf(x_simple_patch)) == NULL)
goto done;