* New XML parsing API:
* `clixon_xml_parse_string()` * `clixon_xml_parse_file()` * New JSON parsing API, with same signature as XML parsing: * `clixon_json_parse_string()` * `clixon_xml_parse_file()` * XML YANG binding API have been rearranged as follows: * `xml_bind_yang_rpc()` * `xml_bind_yang_rpc_reply()` * `xml_bind_yang()` * `xml_bind_yang0()`
This commit is contained in:
parent
c4b0491754
commit
09a2e09848
54 changed files with 590 additions and 711 deletions
|
|
@ -232,7 +232,9 @@ api_root(clicon_handle h,
|
|||
FCGX_FPrintF(r->out, "Content-Type: %s\r\n", restconf_media_int2str(media_out));
|
||||
FCGX_FPrintF(r->out, "\r\n");
|
||||
|
||||
if (xml_parse_string("<restconf xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><data/><operations/><yang-library-version>2016-06-21</yang-library-version></restconf>", yspec, &xt) < 0)
|
||||
if (clixon_xml_parse_string("<restconf xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\"><data/>"
|
||||
"<operations/><yang-library-version>2016-06-21</yang-library-version></restconf>",
|
||||
YB_MODULE, yspec, &xt, NULL) < 0)
|
||||
goto done;
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_XML, errno, "cbuf_new");
|
||||
|
|
@ -283,7 +285,9 @@ api_yang_library_version(clicon_handle h,
|
|||
FCGX_FPrintF(r->out, "Cache-Control: no-cache\r\n");
|
||||
FCGX_FPrintF(r->out, "Content-Type: %s\r\n", restconf_media_int2str(media_out));
|
||||
FCGX_FPrintF(r->out, "\r\n");
|
||||
if (xml_parse_va(&xt, NULL, "<yang-library-version>%s</yang-library-version>", ietf_yang_library_revision) < 0)
|
||||
if (clixon_xml_parse_va(YB_NONE, NULL, &xt, NULL,
|
||||
"<yang-library-version>%s</yang-library-version>",
|
||||
ietf_yang_library_revision) < 0)
|
||||
goto done;
|
||||
if (xml_rootchild(xt, 0, &xt) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ api_data_write(clicon_handle h,
|
|||
char *namespace = NULL;
|
||||
char *dname;
|
||||
cvec *nsc = NULL;
|
||||
enum yang_bind yb;
|
||||
yang_bind yb;
|
||||
char *xpath = NULL;
|
||||
|
||||
clicon_debug(1, "%s api_path:\"%s\"", __FUNCTION__, api_path0);
|
||||
|
|
@ -380,7 +380,7 @@ api_data_write(clicon_handle h,
|
|||
}
|
||||
}
|
||||
if (xml_spec(xdata0)==NULL)
|
||||
yb = YB_TOP;
|
||||
yb = YB_MODULE;
|
||||
else
|
||||
yb = YB_PARENT;
|
||||
|
||||
|
|
@ -392,7 +392,7 @@ api_data_write(clicon_handle h,
|
|||
*/
|
||||
switch (media_in){
|
||||
case YANG_DATA_XML:
|
||||
if ((ret = xml_parse_string2(data, yb, yspec, &xdata0, &xerr)) < 0){
|
||||
if ((ret = clixon_xml_parse_string(data, yb, yspec, &xdata0, &xerr)) < 0){
|
||||
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
|
|
@ -414,7 +414,7 @@ api_data_write(clicon_handle h,
|
|||
}
|
||||
break;
|
||||
case YANG_DATA_JSON:
|
||||
if ((ret = json_parse_str2(data, yb, yspec, &xdata0, &xerr)) < 0){
|
||||
if ((ret = clixon_json_parse_string(data, yb, yspec, &xdata0, &xerr)) < 0){
|
||||
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
|
|
|
|||
|
|
@ -134,7 +134,7 @@ api_data_get2(clicon_handle h,
|
|||
if ((xtop = xml_new("top", NULL, CX_ELMNT)) == NULL)
|
||||
goto done;
|
||||
/* Translate api-path to xml, but to validate the api-path, note: strict=1
|
||||
* xtop and xbot unnecessary fir this function but neede by function
|
||||
* xtop and xbot unnecessary for this function but needed by function
|
||||
*/
|
||||
if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 1, &xbot, &y, &xerr)) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ api_data_post(clicon_handle h,
|
|||
int ret;
|
||||
restconf_media media_in;
|
||||
int nrchildren0 = 0;
|
||||
enum yang_bind yb;
|
||||
yang_bind yb;
|
||||
|
||||
clicon_debug(1, "%s api_path:\"%s\"", __FUNCTION__, api_path);
|
||||
clicon_debug(1, "%s data:\"%s\"", __FUNCTION__, data);
|
||||
|
|
@ -180,7 +180,7 @@ api_data_post(clicon_handle h,
|
|||
xml_flag_set(x, XML_FLAG_MARK);
|
||||
}
|
||||
if (xml_spec(xbot)==NULL)
|
||||
yb = YB_TOP;
|
||||
yb = YB_MODULE;
|
||||
else
|
||||
yb = YB_PARENT;
|
||||
/* Parse input data as json or xml into xml
|
||||
|
|
@ -190,7 +190,7 @@ api_data_post(clicon_handle h,
|
|||
media_in = restconf_content_type(r);
|
||||
switch (media_in){
|
||||
case YANG_DATA_XML:
|
||||
if ((ret = xml_parse_string2(data, yb, yspec, &xbot, &xerr)) < 0){
|
||||
if ((ret = clixon_xml_parse_string(data, yb, yspec, &xbot, &xerr)) < 0){
|
||||
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
|
|
@ -212,7 +212,7 @@ api_data_post(clicon_handle h,
|
|||
}
|
||||
break;
|
||||
case YANG_DATA_JSON:
|
||||
if ((ret = json_parse_str2(data, yb, yspec, &xbot, &xerr)) < 0){
|
||||
if ((ret = clixon_json_parse_string(data, yb, yspec, &xbot, &xerr)) < 0){
|
||||
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
|
|
@ -453,7 +453,9 @@ api_operations_post_input(clicon_handle h,
|
|||
media_in = restconf_content_type(r);
|
||||
switch (media_in){
|
||||
case YANG_DATA_XML:
|
||||
if (xml_parse_string(data, yspec, &xdata) < 0){
|
||||
/* XXX: Here data is on the form: <input xmlns="urn:example:clixon"/> and has no proper yang binding
|
||||
* support */
|
||||
if ((ret = clixon_xml_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 0){
|
||||
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
|
|
@ -464,9 +466,21 @@ api_operations_post_input(clicon_handle h,
|
|||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
if (ret == 0){
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
clicon_debug(1, "%s F", __FUNCTION__);
|
||||
clicon_err(OE_XML, EINVAL, "rpc-error not found (internal error)");
|
||||
goto done;
|
||||
}
|
||||
if (api_return_err(h, r, xe, pretty, media_out, 0) < 0)
|
||||
goto done;
|
||||
goto fail;
|
||||
}
|
||||
break;
|
||||
case YANG_DATA_JSON:
|
||||
if ((ret = json_parse_str(data, yspec, &xdata, &xerr)) < 0){
|
||||
/* XXX: Here data is on the form: {"clixon-example:input":null} and has no proper yang binding
|
||||
* support */
|
||||
if ((ret = clixon_json_parse_string(data, YB_NONE, yspec, &xdata, &xerr)) < 0){
|
||||
if (netconf_malformed_message_xml(&xerr, clicon_err_reason) < 0)
|
||||
goto done;
|
||||
if ((xe = xpath_first(xerr, NULL, "rpc-error")) == NULL){
|
||||
|
|
@ -492,6 +506,7 @@ api_operations_post_input(clicon_handle h,
|
|||
goto fail;
|
||||
break;
|
||||
} /* switch media_in */
|
||||
clicon_debug(1, "%s F", __FUNCTION__);
|
||||
xml_name_set(xdata, "data");
|
||||
/* Here xdata is:
|
||||
* <data><input xmlns="urn:example:clixon">...</input></data>
|
||||
|
|
@ -610,8 +625,8 @@ api_operations_post_output(clicon_handle h,
|
|||
*/
|
||||
if (youtput != NULL){
|
||||
xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
|
||||
#if 0
|
||||
if (xml_bind_yang(xoutput, yspec, NULL) < 0)
|
||||
#ifdef notyet
|
||||
if (xml_bind_yang(xoutput, YB_MODULE, yspec, NULL) < 0)
|
||||
goto done;
|
||||
if ((ret = xml_yang_validate_all(xoutput, &xerr)) < 0)
|
||||
goto done;
|
||||
|
|
@ -863,7 +878,7 @@ api_operations_post(clicon_handle h,
|
|||
if ((ret = rpc_callback_call(h, xbot, cbret, r)) < 0)
|
||||
goto done;
|
||||
if (ret > 0){ /* Handled locally */
|
||||
if (xml_parse_string(cbuf_get(cbret), NULL, &xret) < 0)
|
||||
if (clixon_xml_parse_string(cbuf_get(cbret), YB_NONE, NULL, &xret, NULL) < 0)
|
||||
goto done;
|
||||
/* Local error: return it and quit */
|
||||
if ((xe = xpath_first(xret, NULL, "rpc-reply/rpc-error")) != NULL){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue