* 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:
Olof hagsand 2020-03-19 21:32:27 +01:00
parent c4b0491754
commit 09a2e09848
54 changed files with 590 additions and 711 deletions

View file

@ -186,7 +186,7 @@ client_get_capabilities(clicon_handle h,
cprintf(cb, "<capability>urn:ietf:params:restconf:capability:defaults:1.0?basic-mode=explicit</capability>");
cprintf(cb, "<capability>urn:ietf:params:restconf:capability:depth:1.0</capability>");
cprintf(cb, "</capabilities>");
if (xml_parse_string2(cbuf_get(cb), YB_PARENT, NULL, &xrstate, NULL) < 0)
if (clixon_xml_parse_string(cbuf_get(cb), YB_PARENT, NULL, &xrstate, NULL) < 0)
goto done;
retval = 0;
done:
@ -236,7 +236,7 @@ client_get_streams(clicon_handle h,
goto done;
cprintf(cb,"</%s>", top);
if (xml_parse_string(cbuf_get(cb), yspec, &x) < 0){
if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, &x, NULL) < 0){
if (netconf_operation_failed_xml(xret, "protocol", clicon_err_reason)< 0)
goto done;
goto fail;
@ -320,7 +320,7 @@ clixon_stats_get(clicon_handle h,
clixon_stats_get_db(h, "candidate", cb);
clixon_stats_get_db(h, "startup", cb);
cprintf(cb, "</clixon-stats>");
if ((ret = xml_parse_string2(cbuf_get(cb), YB_TOP, yspec, xret, NULL)) < 0)
if ((ret = clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, xret, NULL)) < 0)
goto done;
if (ret == 0){
clicon_err(OE_XML, EINVAL, "Internal error");
@ -376,7 +376,7 @@ client_statedata(clicon_handle h,
goto done;
}
cprintf(cb, "<netconf xmlns=\"%s\"/>", namespace);
if (xml_parse_string2(cbuf_get(cb), YB_TOP, yspec, xret, NULL) < 0)
if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, xret, NULL) < 0)
goto done;
if ((ret = client_get_streams(h, yspec, xpath, ymod, "netconf", xret)) < 0)
goto done;
@ -394,7 +394,7 @@ client_statedata(clicon_handle h,
}
cbuf_reset(cb);
cprintf(cb, "<restconf-state xmlns=\"%s\"/>", namespace);
if (xml_parse_string2(cbuf_get(cb), YB_TOP, yspec, xret, NULL) < 0)
if (clixon_xml_parse_string(cbuf_get(cb), YB_MODULE, yspec, xret, NULL) < 0)
goto done;
if ((ret = client_get_streams(h, yspec, xpath, ymod, "restconf-state", xret)) < 0)
goto done;
@ -670,7 +670,7 @@ from_client_edit_config(clicon_handle h,
xml_spec_set(xc, NULL);
/* Populate XML with Yang spec (why not do this in parser?)
*/
if (xml_bind_yang(xc, yspec, NULL) < 0)
if (xml_bind_yang(xc, YB_MODULE, yspec, NULL) < 0)
goto done;
/* Maybe validate xml here as in text_modify_top? */
if (xml_apply(xc, CX_ELMNT, xml_non_config_data, &non_config) < 0)

View file

@ -214,7 +214,7 @@ startup_common(clicon_handle h,
goto done;
}
/* After upgrading, XML tree needs to be sorted and yang spec populated */
if (xml_bind_yang(xt, yspec, NULL) < 0)
if (xml_bind_yang(xt, YB_MODULE, yspec, NULL) < 0)
goto done;
if (xml_apply0(xt, CX_ELMNT, xml_sort, h) < 0)
goto done;

View file

@ -211,7 +211,7 @@ nacm_load_external(clicon_handle h)
goto done;
fd = fileno(f);
/* Read configfile */
if (xml_parse_file(fd, yspec, &xt) < 0)
if (clixon_xml_parse_file(fd, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
goto done;
if (xt == NULL){
clicon_err(OE_XML, 0, "No xml tree in %s", filename);

View file

@ -128,7 +128,7 @@ clixon_plugin_statedata(clicon_handle h,
if (debug)
clicon_log_xml(LOG_DEBUG, x, "%s STATE:", __FUNCTION__);
#endif
if (xml_bind_yang(x, yspec, NULL) < 0)
if (xml_bind_yang(x, YB_MODULE, yspec, NULL) < 0)
goto done;
if ((ret = netconf_trymerge(x, yspec, xret)) < 0)
goto done;

View file

@ -176,7 +176,7 @@ load_extraxml(clicon_handle h,
goto done;
}
yspec = clicon_dbspec_yang(h);
if (xml_parse_file(fd, yspec, &xt) < 0)
if (clixon_xml_parse_file(fd, YB_MODULE, yspec, NULL, &xt, NULL) < 0)
goto done;
/* Replace parent w first child */
if (xml_rootchild(xt, 0, &xt) < 0)

View file

@ -712,13 +712,13 @@ compare_dbs(clicon_handle h,
if (clicon_rpc_get_config(h, NULL, "running", "/", NULL, &xc1) < 0)
goto done;
if ((xerr = xpath_first(xc1, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Get configuration", NULL);
goto done;
}
if (clicon_rpc_get_config(h, NULL, "candidate", "/", NULL, &xc2) < 0)
goto done;
if ((xerr = xpath_first(xc2, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Get configuration", NULL);
goto done;
}
if (compare_xmls(xc1, xc2, astext) < 0) /* astext? */
@ -795,7 +795,7 @@ load_config_file(clicon_handle h,
clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
}
if (xml_parse_file(fd, NULL, &xt) < 0)
if (clixon_xml_parse_file(fd, YB_NONE, NULL, NULL, &xt, NULL) < 0)
goto done;
if (xt == NULL)
goto done;
@ -882,7 +882,7 @@ save_config_file(clicon_handle h,
goto done;
}
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Get configuration", NULL);
goto done;
}
/* get-config returns a <data> tree. Save as <config> tree so it can be used
@ -1222,7 +1222,7 @@ cli_copy_config(clicon_handle h,
if (clicon_rpc_get_config(h, NULL, db, cbuf_get(cb), nsc, &x1) < 0)
goto done;
if ((xerr = xpath_first(x1, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Get configuration", NULL);
goto done;
}

View file

@ -159,7 +159,7 @@ expand_dbvar(void *h,
if (clicon_rpc_get_config(h, NULL, dbstr, xpath, nsc, &xt) < 0) /* XXX */
goto done;
if ((xe = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xe, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xe, "Get configuration", NULL);
goto ok;
}
xcur = xt; /* default top-of-tree */
@ -176,7 +176,7 @@ expand_dbvar(void *h,
if ((ret = api_path2xml(api_path, yspec, xtop, YC_DATANODE, 0, &xbot, &y, &xerr)) < 0)
goto done;
if (ret == 0){
clicon_rpc_generate_error(xerr, "Expand datastore symbol", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Expand datastore symbol", NULL);
goto done;
}
}
@ -492,7 +492,7 @@ cli_show_config1(clicon_handle h,
goto done;
}
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Get configuration", NULL);
goto done;
}
/* Print configuration according to format */
@ -633,7 +633,7 @@ show_conf_xpath(clicon_handle h,
if (clicon_rpc_get_config(h, NULL, str, xpath, nsc, &xt) < 0)
goto done;
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Get configuration", NULL);
goto done;
}
@ -735,7 +735,7 @@ cli_show_auto1(clicon_handle h,
goto done;
}
if ((xerr = xpath_first(xt, NULL, "/rpc-error")) != NULL){
clicon_rpc_generate_error(xerr, "Get configuration", NULL);
clixon_netconf_error(OE_NETCONF, xerr, "Get configuration", NULL);
goto done;
}
if ((xp = xpath_first(xt, nsc, "%s", xpath)) != NULL)

View file

@ -197,7 +197,7 @@ netconf_output(int s,
clicon_debug(1, "SEND %s", msg);
if (debug > 1){ /* XXX: below only works to stderr, clicon_debug may log to syslog */
cxobj *xt = NULL;
if (xml_parse_string(buf, NULL, &xt) == 0){
if (clixon_xml_parse_string(buf, YB_NONE, NULL, &xt, NULL) == 0){
clicon_xml2file(stderr, xml_child_i(xt, 0), 0, 0);
fprintf(stderr, "\n");
xml_free(xt);

View file

@ -138,7 +138,7 @@ netconf_input_packet(clicon_handle h,
}
str = str0;
/* Parse incoming XML message */
if (xml_parse_string(str, yspec, &xreq) < 0){
if (clixon_xml_parse_string(str, YB_MODULE, yspec, &xreq, NULL) < 0){
free(str0);
if (netconf_operation_failed(cbret, "rpc", clicon_err_reason)< 0)
goto done;

View file

@ -93,12 +93,12 @@ netconf_get_config_subtree(clicon_handle h,
if ((xdata = xpath_first(*xret, NULL, "/rpc-reply/data")) == NULL)
goto ok;
if (xml_filter(xfilter, xdata) < 0){
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
"<error-info>filtering</error-info>"
"</rpc-error></rpc-reply>");
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
"<error-info>filtering</error-info>"
"</rpc-error></rpc-reply>");
}
ok:
retval = 0;
@ -180,13 +180,13 @@ netconf_get_config(clicon_handle h,
goto done;
}
else{
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
"<error-message>filter type not supported</error-message>"
"<error-info>type</error-info>"
"</rpc-error></rpc-reply>");
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
"<error-message>filter type not supported</error-message>"
"<error-info>type</error-info>"
"</rpc-error></rpc-reply>");
}
retval = 0;
done:
@ -245,11 +245,11 @@ get_edit_opts(cxobj *xn,
retval = 1; /* hunky dory */
return retval;
parerr: /* parameter error, xret set */
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>invalid-value</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
"</rpc-error></rpc-reply>");
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>invalid-value</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
"</rpc-error></rpc-reply>");
return 0;
}
@ -322,11 +322,11 @@ netconf_edit_config(clicon_handle h,
* (implement the features before removing these checks)
*/
if (testopt!=TEST_THEN_SET || erropt!=STOP_ON_ERROR){
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-not-supported</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
"</rpc-error></rpc-reply>");
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-not-supported</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
"</rpc-error></rpc-reply>");
goto ok;
}
if (clicon_rpc_netconf_xml(h, xml_parent(xn), xret, NULL) < 0)
@ -377,13 +377,13 @@ netconf_get(clicon_handle h,
goto done;
}
else{
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
"<error-message>filter type not supported</error-message>"
"<error-info>type</error-info>"
"</rpc-error></rpc-reply>");
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
"<error-message>filter type not supported</error-message>"
"<error-info>type</error-info>"
"</rpc-error></rpc-reply>");
}
retval = 0;
done:
@ -498,13 +498,13 @@ netconf_create_subscription(clicon_handle h,
if ((xfilter = xpath_first(xn, NULL, "//filter")) != NULL){
if ((ftype = xml_find_value(xfilter, "type")) != NULL){
if (strcmp(ftype, "xpath") != 0){
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>application</error-type>"
"<error-severity>error</error-severity>"
"<error-message>only xpath filter type supported</error-message>"
"<error-info>type</error-info>"
"</rpc-error></rpc-reply>");
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>application</error-type>"
"<error-severity>error</error-severity>"
"<error-message>only xpath filter type supported</error-message>"
"<error-info>type</error-info>"
"</rpc-error></rpc-reply>");
goto ok;
}
}
@ -572,13 +572,13 @@ netconf_application_rpc(clicon_handle h,
if (ys_module_by_xml(yspec, xn, &ymod) < 0)
goto done;
if (ymod == NULL){
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>rpc</error-type>"
"<error-severity>error</error-severity>"
"<error-message>%s</error-message>"
"<error-info>Not recognized module</error-info>"
"</rpc-error></rpc-reply>", xml_name(xn));
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>rpc</error-type>"
"<error-severity>error</error-severity>"
"<error-message>%s</error-message>"
"<error-info>Not recognized module</error-info>"
"</rpc-error></rpc-reply>", xml_name(xn));
goto ok;
}
yrpc = yang_find(ymod, Y_RPC, xml_name(xn));
@ -587,7 +587,7 @@ netconf_application_rpc(clicon_handle h,
/* 1. Check xn arguments with input statement. */
if ((yinput = yang_find(yrpc, Y_INPUT, NULL)) != NULL){
xml_spec_set(xn, yinput); /* needed for xml_bind_yang */
if (xml_bind_yang(xn, yspec, NULL) < 0)
if (xml_bind_yang(xn, YB_MODULE, yspec, NULL) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, xn, &xerr)) < 0)
goto done;
@ -604,7 +604,7 @@ netconf_application_rpc(clicon_handle h,
if ((ret = rpc_callback_call(h, xn, cbret, NULL)) < 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;
}
else /* Send to backend */
@ -619,7 +619,7 @@ netconf_application_rpc(clicon_handle h,
if ((youtput = yang_find(yrpc, Y_OUTPUT, NULL)) != NULL){
xoutput=xpath_first(*xret, NULL, "/");
xml_spec_set(xoutput, youtput); /* needed for xml_bind_yang */
if (xml_bind_yang(xoutput, yspec, NULL) < 0)
if (xml_bind_yang(xoutput, YB_MODULE, yspec, NULL) < 0)
goto done;
if ((ret = xml_yang_validate_all_top(h, xoutput, &xerr)) < 0)
goto done;
@ -724,13 +724,13 @@ netconf_rpc_dispatch(clicon_handle h,
if ((retval = netconf_application_rpc(h, xe, xret)) < 0)
goto done;
if (retval == 0){ /* not handled by callback */
xml_parse_va(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>rpc</error-type>"
"<error-severity>error</error-severity>"
"<error-message>%s</error-message>"
"<error-info>Not recognized</error-info>"
"</rpc-error></rpc-reply>", xml_name(xe));
clixon_xml_parse_va(YB_NONE, NULL, xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>rpc</error-type>"
"<error-severity>error</error-severity>"
"<error-message>%s</error-message>"
"<error-info>Not recognized</error-info>"
"</rpc-error></rpc-reply>", xml_name(xe));
goto done;
}
}

View file

@ -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;

View file

@ -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){

View file

@ -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;

View file

@ -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){