Datastore cache introduced; Added yang to XML API

This commit is contained in:
Olof hagsand 2017-12-02 14:49:49 +01:00
parent c1cb3a2b6c
commit e169485985
34 changed files with 884 additions and 389 deletions

View file

@ -443,7 +443,7 @@ load_extraxml(clicon_handle h,
clicon_err(OE_UNIX, errno, "open(%s)", filename);
goto done;
}
if (clicon_xml_parse_file(fd, &xt, "</config>") < 0)
if (clicon_xml_parse_file(fd, "</config>", NULL, &xt) < 0)
goto done;
/* Replace parent w first child */
if (xml_rootchild(xt, 0, &xt) < 0)

View file

@ -752,7 +752,7 @@ backend_statedata_call(clicon_handle h,
for (i = 0; i < _nplugins; i++) {
p = &_plugins[i];
if (p->p_statedata) {
if ((x = xml_new("config", NULL)) == NULL)
if ((x = xml_new("config", NULL, NULL)) == NULL)
goto done;
if ((p->p_statedata)(h, xpath, x) < 0){
retval = 1;

View file

@ -233,12 +233,12 @@ cli_dbxml(clicon_handle h,
if (api_path_fmt2api_path(api_path_fmt, cvv, &api_path) < 0)
goto done;
/* Create config top-of-tree */
if ((xtop = xml_new("config", NULL)) == NULL)
if ((xtop = xml_new("config", NULL, NULL)) == NULL)
goto done;
xbot = xtop;
if (api_path && api_path2xml(api_path, yspec, xtop, 0, &xbot, &y) < 0)
goto done;
if ((xa = xml_new("operation", xbot)) == NULL)
if ((xa = xml_new("operation", xbot, NULL)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
@ -251,7 +251,7 @@ cli_dbxml(clicon_handle h,
clicon_err(OE_UNIX, errno, "cv2str_dup");
goto done;
}
if ((xb = xml_new("body", xbot)) == NULL)
if ((xb = xml_new("body", xbot, NULL)) == NULL)
goto done;
xml_type_set(xb, CX_BODY);
if (xml_value_set(xb, str) < 0)
@ -746,7 +746,7 @@ load_config_file(clicon_handle h,
clicon_err(OE_UNIX, errno, "%s: open(%s)", __FUNCTION__, filename);
goto done;
}
if (clicon_xml_parse_file(fd, &xt, "</clicon>") < 0)
if (clicon_xml_parse_file(fd, "</clicon>", NULL, &xt) < 0)
goto done;
if (xt == NULL)
goto done;
@ -1189,7 +1189,7 @@ cli_copy_config(clicon_handle h,
}
toname = cv_string_get(tocv);
/* Create copy xml tree x2 */
if ((x2 = xml_new("new", NULL)) == NULL)
if ((x2 = xml_new("new", NULL, NULL)) == NULL)
goto done;
if (xml_copy(x1, x2) < 0)
goto done;

View file

@ -166,7 +166,7 @@ expand_dbvar(void *h,
xcur = xt; /* default top-of-tree */
xpathcur = xpath;
/* Create config top-of-tree */
if ((xtop = xml_new("config", NULL)) == NULL)
if ((xtop = xml_new("config", NULL, NULL)) == NULL)
goto done;
xbot = xtop;
/* This is primarily to get "y",

View file

@ -190,7 +190,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 (clicon_xml_parse_string(&buf, &xt) == 0){
if (clicon_xml_parse_str(buf, NULL, &xt) == 0){
clicon_xml2file(stderr, xml_child_i(xt, 0), 0, 0);
fprintf(stderr, "\n");
xml_free(xt);

View file

@ -98,7 +98,7 @@ process_incoming_packet(clicon_handle h,
}
str = str0;
/* Parse incoming XML message */
if (clicon_xml_parse_string(&str, &xreq) < 0){
if (clicon_xml_parse_str(str, NULL, &xreq) < 0){
if ((cbret = cbuf_new()) == NULL){
cprintf(cbret, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"

View file

@ -135,7 +135,7 @@ netconf_get_config(clicon_handle h,
cxobj *xconf;
if ((source = netconf_get_target(xn, "source")) == NULL){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -163,7 +163,7 @@ netconf_get_config(clicon_handle h,
/* xml_filter removes parts of xml tree not matching */
if ((strcmp(xml_name(xfilterconf), xml_name(xconf))!=0) ||
xml_filter(xfilterconf, xconf) < 0){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
@ -173,7 +173,7 @@ netconf_get_config(clicon_handle h,
}
}
else{
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
@ -241,7 +241,7 @@ get_edit_opts(cxobj *xn,
retval = 1; /* hunky dory */
return retval;
parerr: /* parameter error, xret set */
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>invalid-value</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -317,7 +317,7 @@ netconf_edit_config(clicon_handle h,
/* must have target, and it should be candidate */
if ((target = netconf_get_target(xn, "target")) == NULL ||
strcmp(target, "candidate")){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -329,7 +329,7 @@ netconf_edit_config(clicon_handle h,
if ((xfilter = xpath_first(xn, "filter")) != NULL) {
if ((ftype = xml_find_value(xfilter, "type")) != NULL)
if (strcmp(ftype,"restconf")){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>invalid-value</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -339,7 +339,7 @@ netconf_edit_config(clicon_handle h,
}
if ((x = xpath_first(xn, "default-operation")) != NULL){
if (xml_operation(xml_body(x), &operation) < 0){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>invalid-value</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -353,7 +353,7 @@ netconf_edit_config(clicon_handle h,
goto ok;
/* not supported opts */
if (testopt!=TEST_THEN_SET || erropt!=STOP_ON_ERROR){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-not-supported</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -403,7 +403,7 @@ netconf_copy_config(clicon_handle h,
char *target; /* filenames */
if ((source = netconf_get_target(xn, "source")) == NULL){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -412,7 +412,7 @@ netconf_copy_config(clicon_handle h,
goto ok;
}
if ((target = netconf_get_target(xn, "target")) == NULL){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -450,7 +450,7 @@ netconf_delete_config(clicon_handle h,
if ((target = netconf_get_target(xn, "target")) == NULL ||
strcmp(target, "running")==0){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -486,7 +486,7 @@ netconf_lock(clicon_handle h,
char *target;
if ((target = netconf_get_target(xn, "target")) == NULL){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -566,7 +566,7 @@ netconf_get(clicon_handle h,
/* xml_filter removes parts of xml tree not matching */
if ((strcmp(xml_name(xfilterconf), xml_name(xconf))!=0) ||
xml_filter(xfilterconf, xconf) < 0){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
@ -576,7 +576,7 @@ netconf_get(clicon_handle h,
}
}
else{
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>applicatio</error-type>"
"<error-severity>error</error-severity>"
@ -627,7 +627,7 @@ netconf_kill_session(clicon_handle h,
cxobj *xs;
if ((xs = xpath_first(xn, "//session-id")) == NULL){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -658,7 +658,7 @@ netconf_validate(clicon_handle h,
char *target;
if ((target = netconf_get_target(xn, "source")) == NULL){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>missing-element</error-tag>"
"<error-type>protocol</error-type>"
"<error-severity>error</error-severity>"
@ -826,7 +826,7 @@ netconf_create_subscription(clicon_handle h,
if ((xfilter = xpath_first(xn, "//filter")) != NULL){
if ((ftype = xml_find_value(xfilter, "type")) != NULL){
if (strcmp(ftype, "xpath") != 0){
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>application</error-type>"
"<error-severity>error</error-severity>"
@ -901,7 +901,7 @@ netconf_rpc_dispatch(clicon_handle h,
if ((ret = netconf_plugin_callbacks(h, xe, xret)) < 0)
return -1;
if (ret == 0){ /* not handled by callback */
clicon_xml_parse(xret, "<rpc-reply><rpc-error>"
clicon_xml_parse(xret, NULL, "<rpc-reply><rpc-error>"
"<error-tag>operation-failed</error-tag>"
"<error-type>rpc</error-type>"
"<error-severity>error</error-severity>"

View file

@ -369,14 +369,14 @@ api_data_post(clicon_handle h,
for (i=0; i<pi; i++)
api_path = index(api_path+1, '/');
/* Create config top-of-tree */
if ((xtop = xml_new("config", NULL)) == NULL)
if ((xtop = xml_new("config", NULL, NULL)) == NULL)
goto done;
xbot = xtop;
if (api_path && api_path2xml(api_path, yspec, xtop, 0, &xbot, &y) < 0)
goto done;
/* Parse input data as json or xml into xml */
if (parse_xml){
if (clicon_xml_parse_str(data, &xdata) < 0){
if (clicon_xml_parse_str(data, NULL, &xdata) < 0){
clicon_debug(1, "%s json parse fail: %s", __FUNCTION__, data);
goto done;
}
@ -388,7 +388,7 @@ api_data_post(clicon_handle h,
/* Add xdata to xbot */
x = NULL;
while ((x = xml_child_each(xdata, x, CX_ELMNT)) != NULL) {
if ((xa = xml_new("operation", x)) == NULL)
if ((xa = xml_new("operation", x, NULL)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
@ -488,14 +488,14 @@ api_data_put(clicon_handle h,
for (i=0; i<pi; i++)
api_path = index(api_path+1, '/');
/* Create config top-of-tree */
if ((xtop = xml_new("config", NULL)) == NULL)
if ((xtop = xml_new("config", NULL, NULL)) == NULL)
goto done;
xbot = xtop;
if (api_path && api_path2xml(api_path, yspec, xtop, 0, &xbot, &y) < 0)
goto done;
/* Parse input data as json or xml into xml */
if (parse_xml){
if (clicon_xml_parse_str(data, &xdata) < 0){
if (clicon_xml_parse_str(data, NULL, &xdata) < 0){
clicon_debug(1, "%s json parse fail: %s", __FUNCTION__, data);
goto done;
}
@ -510,7 +510,7 @@ api_data_put(clicon_handle h,
goto done;
}
x = xml_child_i(xdata,0);
if ((xa = xml_new("operation", x)) == NULL)
if ((xa = xml_new("operation", x, NULL)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
@ -613,12 +613,12 @@ api_data_delete(clicon_handle h,
for (i=0; i<pi; i++)
api_path = index(api_path+1, '/');
/* Create config top-of-tree */
if ((xtop = xml_new("config", NULL)) == NULL)
if ((xtop = xml_new("config", NULL, NULL)) == NULL)
goto done;
xbot = xtop;
if (api_path && api_path2xml(api_path, yspec, xtop, 0, &xbot, &y) < 0)
goto done;
if ((xa = xml_new("operation", xbot)) == NULL)
if ((xa = xml_new("operation", xbot, NULL)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
@ -721,7 +721,7 @@ api_operation_post(clicon_handle h,
* eg <rpc><fib-route><name>
*/
/* Create config top-of-tree */
if ((xtop = xml_new("rpc", NULL)) == NULL)
if ((xtop = xml_new("rpc", NULL, NULL)) == NULL)
goto done;
xbot = xtop;
if (api_path2xml(oppath, yspec, xtop, 1, &xbot, &y) < 0)
@ -729,7 +729,7 @@ api_operation_post(clicon_handle h,
if (data && strlen(data)){
/* Parse input data as json or xml into xml */
if (parse_xml){
if (clicon_xml_parse_str(data, &xdata) < 0){
if (clicon_xml_parse_str(data, NULL, &xdata) < 0){
clicon_debug(1, "%s json parse fail: %s", __FUNCTION__, data);
goto done;
}
@ -768,7 +768,7 @@ api_operation_post(clicon_handle h,
if ((cookie = FCGX_GetParam("HTTP_COOKIE", r->envp)) != NULL &&
get_user_cookie(cookie, "c-user", &cookieval) ==0){
if ((xa = xml_new("id", xtop)) == NULL)
if ((xa = xml_new("id", xtop, NULL)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, cookieval) < 0)