* C-API change: xml_new() changed from xml_new(name, xp, ys) to xml_new(name, prefix, xp, type)

* If you have used, `ys`, add `xml_spec_set(x, ys)` after the statement
  * If you have `xml_type_set(x, TYPE)` or `xml_prefix_set(x, PREFIX)` immediately after the statement, you can remove those and set them directly as: `xml_new(name, PREFIX, xp, TYPE)`
This commit is contained in:
Olof hagsand 2020-03-12 22:29:28 +01:00
parent 71efe18f94
commit 7425a3b520
26 changed files with 135 additions and 155 deletions

View file

@ -39,6 +39,10 @@ Expected: Early March 2020
[search](https://clixon-docs.readthedocs.io/en/latest/xml.html#searching-in-xml)
### API changes on existing features (you may need to change your code)
* C-API change: `xml_new()` changed from:
* `xml_new(name, xp, ys)` to `xml_new(name, prefix, xp, type)`
* If you have used, `ys`, add `xml_spec_set(x, ys)` after the statement
* If you have `xml_type_set(x, TYPE)` or `xml_prefix_set(x, PREFIX)` immediately after the statement, you can remove those and set them directly as: `xml_new(name, PREFIX, xp, TYPE)`
* NACM datanode write rules have been changed from looking at datastore being chekend (eg running/candidate/startup) to *only* look at running.
* C-API:
* All uses of `api_path2xpath_cvv()` should be replaced by `api_path2xpath()`

View file

@ -120,7 +120,7 @@ clixon_plugin_statedata(clicon_handle h,
while ((cp = clixon_plugin_each(h, cp)) != NULL) {
if ((fn = cp->cp_api.ca_statedata) == NULL)
continue;
if ((x = xml_new("config", NULL, NULL)) == NULL)
if ((x = xml_new("config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (fn(h, nsc, xpath, x) < 0)
goto fail; /* Dont quit here on user callbacks */

View file

@ -200,9 +200,8 @@ dbxml_body(cxobj *xbot,
clicon_err(OE_UNIX, errno, "cv2str_dup");
goto done;
}
if ((xb = xml_new("body", xbot, NULL)) == NULL)
if ((xb = xml_new("body", NULL, xbot, CX_BODY)) == NULL)
goto done;
xml_type_set(xb, CX_BODY);
if (xml_value_set(xb, str) < 0)
goto done;
retval = 0;
@ -259,7 +258,7 @@ 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)) == NULL)
if ((xtop = xml_new("config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xbot = xtop;
if (api_path){
@ -277,10 +276,8 @@ cli_dbxml(clicon_handle h,
goto done;
}
}
if ((xa = xml_new("operation", xbot, NULL)) == NULL)
if ((xa = xml_new("operation", NETCONF_BASE_PREFIX, xbot, CX_ATTR)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
xml_prefix_set(xa, NETCONF_BASE_PREFIX);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
goto done;
if (yang_keyword_get(y) != Y_LIST && yang_keyword_get(y) != Y_LEAF_LIST){
@ -1234,7 +1231,7 @@ cli_copy_config(clicon_handle h,
}
toname = cv_string_get(tocv);
/* Create copy xml tree x2 */
if ((x2 = xml_new("new", NULL, NULL)) == NULL)
if ((x2 = xml_new("config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (xml_copy(x1, x2) < 0)
goto done;

View file

@ -165,7 +165,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)) == NULL)
if ((xtop = xml_new("config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xbot = xtop;
/* This is primarily to get "y",

View file

@ -671,9 +671,8 @@ netconf_rpc_dispatch(clicon_handle h,
* It may even be wrong if something else is done with the incoming message?
*/
if ((username = clicon_username_get(h)) != NULL){
if ((xa = xml_new("username", xn, NULL)) == NULL)
if ((xa = xml_new("username", NULL, xn, CX_ATTR)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, username) < 0)
goto done;
}

View file

@ -685,11 +685,8 @@ restconf_insert_attributes(cxobj *xdata,
if (xmlns_set(xdata, "yang", YANG_XML_NAMESPACE) < 0)
goto done;
/* Then add insert attribute */
if ((xa = xml_new("insert", xdata, NULL)) == NULL)
if ((xa = xml_new("insert", "yang", xdata, CX_ATTR)) == NULL)
goto done;
if (xml_prefix_set(xa, "yang") < 0)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, instr) < 0)
goto done;
}
@ -703,11 +700,8 @@ restconf_insert_attributes(cxobj *xdata,
else
attrname="value";
/* Then add value/key attribute */
if ((xa = xml_new(attrname, xdata, NULL)) == NULL)
if ((xa = xml_new(attrname, "yang", xdata, CX_ATTR)) == NULL)
goto done;
if (xml_prefix_set(xa, "yang") < 0)
goto done;
xml_type_set(xa, CX_ATTR);
if ((ret = api_path2xpath(pstr, ys_spec(y), &xpath, &nsc, NULL)) < 0)
goto done;
if ((cb = cbuf_new()) == NULL){

View file

@ -327,7 +327,7 @@ api_data_write(clicon_handle h,
xret = NULL;
}
/* Create config top-of-tree */
if ((xtop = xml_new("config", NULL, NULL)) == NULL)
if ((xtop = xml_new("config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
/* Translate api_path to xml in the form of xtop/xbot */
xbot = xtop;
@ -362,7 +362,7 @@ api_data_write(clicon_handle h,
}
/* Create a dummy data tree parent to hook in the parsed data.
*/
if ((xdata0 = xml_new("data0", NULL, NULL)) == NULL)
if ((xdata0 = xml_new("data0", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (api_path){ /* XXX mv to copy? */
cxobj *xfrom;
@ -373,7 +373,7 @@ api_data_write(clicon_handle h,
goto done;
xa = NULL;
while ((xa = xml_child_each(xfrom, xa, CX_ATTR)) != NULL) {
if ((xac = xml_new(xml_name(xa), xdata0, NULL)) == NULL)
if ((xac = xml_new(xml_name(xa), NULL, xdata0, CX_ATTR)) == NULL)
goto done;
if (xml_copy(xa, xac) < 0) /* recursion */
goto done;
@ -479,11 +479,8 @@ api_data_write(clicon_handle h,
/* Add operation create as attribute. If that fails with Conflict, then
* try "replace" (see comment in function header)
*/
if ((xa = xml_new("operation", xdata, NULL)) == NULL)
if ((xa = xml_new("operation", NETCONF_BASE_PREFIX, xdata, CX_ATTR)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
xml_prefix_set(xa, NETCONF_BASE_PREFIX);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
goto done;
@ -839,7 +836,7 @@ 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)) == NULL)
if ((xtop = xml_new("config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xbot = xtop;
if (api_path){
@ -855,9 +852,8 @@ api_data_delete(clicon_handle h,
goto ok;
}
}
if ((xa = xml_new("operation", xbot, NULL)) == NULL)
if ((xa = xml_new("operation", NULL, xbot, CX_ATTR)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
goto done;
if (xml_namespace_change(xa, NETCONF_BASE_NAMESPACE, NETCONF_BASE_PREFIX) < 0)

View file

@ -131,7 +131,7 @@ api_data_get2(clicon_handle h,
for (i=0; i<pi; i++)
api_path = index(api_path+1, '/');
if (api_path){
if ((xtop = xml_new("top", NULL, NULL)) == NULL)
if ((xtop = xml_new("top", NULL, 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

View file

@ -139,7 +139,7 @@ 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)) == NULL)
if ((xtop = xml_new("config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
/* Translate api_path to xtop/xbot */
xbot = xtop;
@ -265,9 +265,8 @@ api_data_post(clicon_handle h,
}
/* Add operation (create/replace) as attribute */
if ((xa = xml_new("operation", xdata, NULL)) == NULL)
if ((xa = xml_new("operation", NULL, xdata, CX_ATTR)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, xml_operation2str(op)) < 0)
goto done;
if (xml_namespace_change(xa, NETCONF_BASE_NAMESPACE, NETCONF_BASE_PREFIX) < 0)
@ -789,14 +788,13 @@ api_operations_post(clicon_handle h,
/* 3. Build xml tree with user and rpc:
* <rpc username="foo"><myfn xmlns="uri"/>
*/
if ((xtop = xml_new("rpc", NULL, NULL)) == NULL)
if ((xtop = xml_new("rpc", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xbot = xtop;
/* Here xtop is: <rpc/> */
if ((username = clicon_username_get(h)) != NULL){
if ((xa = xml_new("username", xtop, NULL)) == NULL)
if ((xa = xml_new("username", NULL, xtop, CX_ATTR)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, username) < 0)
goto done;
/* Here xtop is: <rpc username="foo"/> */

View file

@ -160,8 +160,8 @@ cxobj *xml_child_each(cxobj *xparent, cxobj *xprev, enum cxobj_type type);
int xml_child_insert_pos(cxobj *x, cxobj *xc, int i);
int xml_childvec_set(cxobj *x, int len);
cxobj **xml_childvec_get(cxobj *x);
cxobj *xml_new(char *name, cxobj *xn_parent, yang_stmt *spec);
cxobj *xml_new2(char *name, cxobj *xn_parent, enum cxobj_type type);
cxobj *xml_new(char *name, char *prefix, cxobj *xn_parent, enum cxobj_type type);
yang_stmt *xml_spec(cxobj *x);
int xml_spec_set(cxobj *x, yang_stmt *spec);
cg_var *xml_cv(cxobj *x);

View file

@ -213,14 +213,14 @@ xmldb_copy(clicon_handle h,
x2 = NULL;
}
else if (x2 == NULL){ /* create x2 and copy from x1 */
if ((x2 = xml_new(xml_name(x1), NULL, xml_spec(x1))) == NULL)
if ((x2 = xml_new(xml_name(x1), NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (xml_copy(x1, x2) < 0)
goto done;
}
else{ /* copy x1 to x2 */
xml_free(x2);
if ((x2 = xml_new(xml_name(x1), NULL, xml_spec(x1))) == NULL)
if ((x2 = xml_new(xml_name(x1), NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (xml_copy(x1, x2) < 0)
goto done;

View file

@ -145,7 +145,8 @@ xml_copy_marked(cxobj *x0,
assert(x0 && x1);
yt = xml_spec(x0); /* can be null */
/* Copy prefix*/
xml_spec_set(x1, yt);
/* Copy prefix*/
if ((prefix = xml_prefix(x0)) != NULL)
if (xml_prefix_set(x1, prefix) < 0)
goto done;
@ -154,7 +155,7 @@ xml_copy_marked(cxobj *x0,
x = NULL;
while ((x = xml_child_each(x0, x, CX_ATTR)) != NULL) {
name = xml_name(x);
if ((xcopy = xml_new(name, x1, xml_spec(x))) == NULL)
if ((xcopy = xml_new(name, NULL, x1, CX_ATTR)) == NULL)
goto done;
if (xml_copy(x, xcopy) < 0)
goto done;
@ -177,7 +178,7 @@ xml_copy_marked(cxobj *x0,
name = xml_name(x);
if (xml_flag(x, XML_FLAG_MARK)){
/* (2) the complete subtree of that node is copied. */
if ((xcopy = xml_new(name, x1, xml_spec(x))) == NULL)
if ((xcopy = xml_new(name, NULL, x1, CX_ELMNT)) == NULL)
goto done;
if (xml_copy(x, xcopy) < 0)
goto done;
@ -185,7 +186,7 @@ xml_copy_marked(cxobj *x0,
}
if (xml_flag(x, XML_FLAG_CHANGE)){
/* Copy individual nodes marked with XML_FLAG_CHANGE */
if ((xcopy = xml_new(name, x1, xml_spec(x))) == NULL)
if ((xcopy = xml_new(name, NULL, x1, CX_ELMNT)) == NULL)
goto done;
if (xml_copy_marked(x, xcopy) < 0) /* */
goto done;
@ -197,7 +198,7 @@ xml_copy_marked(cxobj *x0,
if ((iskey = yang_key_match(yt, name)) < 0)
goto done;
if (iskey){
if ((xcopy = xml_new(name, x1, xml_spec(x))) == NULL)
if ((xcopy = xml_new(name, NULL, x1, CX_ELMNT)) == NULL)
goto done;
if (xml_copy(x, xcopy) < 0)
goto done;
@ -537,8 +538,10 @@ xmldb_get_cache(clicon_handle h,
goto done;
/* Make new tree by copying top-of-tree from x0t to x1t */
if ((x1t = xml_new(xml_name(x0t), NULL, xml_spec(x0t))) == NULL)
if ((x1t = xml_new(xml_name(x0t), NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xml_spec_set(x1t, xml_spec(x0t));
/* Iterate through the match vector
* For every node found in x0, mark the tree up to t1
*/

View file

@ -180,16 +180,13 @@ check_identityref(cxobj *x0,
goto done;
/* Create xmlns attribute to x1 XXX same code ^*/
if (prefix){
if ((xa = xml_new(prefix, x, NULL)) == NULL)
goto done;
if (xml_prefix_set(xa, "xmlns") < 0)
if ((xa = xml_new(prefix, "xmlns", x, CX_ATTR)) == NULL)
goto done;
}
else{
if ((xa = xml_new("xmlns", x, NULL)) == NULL)
if ((xa = xml_new("xmlns", NULL, x, CX_ATTR)) == NULL)
goto done;
}
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, ns0) < 0)
goto done;
xml_sort(x, NULL); /* Ensure attr is first / XXX xml_insert? */
@ -343,8 +340,10 @@ text_modify(clicon_handle h,
}
/* Add new xml node but without parent - insert when node fully
copied (see changed conditional below) */
if ((x0 = xml_new(x1name, NULL, (yang_stmt*)y0)) == NULL)
if ((x0 = xml_new(x1name, NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xml_spec_set(x0, y0);
/* Get namespace from x1
* Check if namespace exists in x0 parent
* if not add new binding and replace in x0.
@ -355,9 +354,8 @@ text_modify(clicon_handle h,
if (op==OP_NONE)
xml_flag_set(x0, XML_FLAG_NONE); /* Mark for potential deletion */
if (x1bstr){ /* empty type does not have body */
if ((x0b = xml_new("body", x0, NULL)) == NULL)
if ((x0b = xml_new("body", NULL, x0, CX_BODY)) == NULL)
goto done;
xml_type_set(x0b, CX_BODY);
}
}
if (x1bstr){
@ -490,7 +488,7 @@ text_modify(clicon_handle h,
if (x0){
xml_purge(x0);
}
if ((x0 = xml_new(x1name, x0p, (yang_stmt*)y0)) == NULL)
if ((x0 = xml_new(x1name, NULL, x0p, CX_ELMNT)) == NULL)
goto done;
if (xml_copy(x1, x0) < 0)
goto done;
@ -508,8 +506,10 @@ text_modify(clicon_handle h,
* copied (see changed conditional below)
* Note x0 may dangle cases if exit before changed conditional
*/
if ((x0 = xml_new(x1name, NULL, (yang_stmt*)y0)) == NULL)
if ((x0 = xml_new(x1name, NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xml_spec_set(x0, y0);
changed++;
/* Get namespace from x1
* Check if namespace exists in x0 parent

View file

@ -345,10 +345,7 @@ json2xml_decode_identityref(cxobj *x,
if (prefix2 == NULL)
prefix2 = yang_find_myprefix(ymod);
/* Add "xmlns:prefix2=namespace" */
if ((xa = xml_new(prefix2, x, NULL)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (xml_prefix_set(xa, "xmlns") < 0)
if ((xa = xml_new(prefix2, "xmlns", x, CX_ATTR)) == NULL)
goto done;
if (xml_value_set(xa, namespace) < 0)
goto done;
@ -968,7 +965,7 @@ xml2json_cbuf_vec(cbuf *cb,
cxobj *xc;
cvec *nsc = NULL;
if ((xp = xml_new("xml2json", NULL, NULL)) == NULL)
if ((xp = xml_new("xml2json", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
/* Make a copy of old and graft it into new top-object
* Also copy namespace context */
@ -1298,7 +1295,7 @@ json_parse_str2(char *str,
return -1;
}
if (*xt == NULL){
if ((*xt = xml_new("top", NULL, NULL)) == NULL)
if ((*xt = xml_new("top", NULL, NULL, CX_ELMNT)) == NULL)
return -1;
}
return _json_parse(str, yb, yspec, *xt, xerr);
@ -1319,7 +1316,7 @@ json_parse_str(char *str,
}
if (*xt == NULL){
yb = YB_TOP; /* ad-hoc #1 */
if ((*xt = xml_new("top", NULL, NULL)) == NULL)
if ((*xt = xml_new("top", NULL, NULL, CX_ELMNT)) == NULL)
return -1;
}
else{
@ -1400,7 +1397,7 @@ json_parse_file(int fd,
jsonbuf[len++] = ch;
if (ret == 0){
if (*xt == NULL)
if ((*xt = xml_new(JSON_TOP_SYMBOL, NULL, NULL)) == NULL)
if ((*xt = xml_new(JSON_TOP_SYMBOL, NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (len){
if ((ret = _json_parse(ptr, yb, yspec, *xt, xerr)) < 0)

View file

@ -179,10 +179,8 @@ json_current_new(clixon_json_yacc *jy,
/* Find colon separator and if found split into prefix:name */
if (nodeid_split(name, &prefix, &id) < 0)
goto done;
if ((x = xml_new(id, jy->jy_current, NULL)) == NULL)
if ((x = xml_new(id, prefix, jy->jy_current, CX_ELMNT)) == NULL)
goto done;
if (prefix && xml_prefix_set(x, prefix) < 0)
goto done;
/* If topmost, add to top-list created list */
if (jy->jy_current == jy->jy_xtop){
if (cxvec_append(x, &jy->jy_xvec, &jy->jy_xlen) < 0)
@ -229,9 +227,8 @@ json_current_body(clixon_json_yacc *jy,
cxobj *xn;
clicon_debug(2, "%s", __FUNCTION__);
if ((xn = xml_new("body", jy->jy_current, NULL)) == NULL)
if ((xn = xml_new("body", NULL, jy->jy_current, CX_BODY)) == NULL)
goto done;
xml_type_set(xn, CX_BODY);
if (value && xml_value_append(xn, value) < 0)
goto done;
retval = 0;

View file

@ -127,12 +127,12 @@ netconf_invalid_value_xml(cxobj **xret,
char *encstr = NULL;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>%s</error-type>"
"<error-tag>invalid-value</error-tag>"
@ -307,12 +307,12 @@ netconf_bad_attribute_xml(cxobj **xret,
char *encstr = NULL;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>%s</error-type>"
"<error-tag>bad-attribute</error-tag>"
@ -396,12 +396,12 @@ netconf_common_xml(cxobj **xret,
char *encstr = NULL;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>%s</error-type>"
"<error-tag>%s</error-tag>"
@ -646,12 +646,12 @@ netconf_access_denied_xml(cxobj **xret,
char *encstr = NULL;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>%s</error-type>"
"<error-tag>access-denied</error-tag>"
@ -876,12 +876,12 @@ netconf_data_missing_xml(cxobj **xret,
cxobj *xerr;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL,
"<error-type>application</error-type>"
@ -1004,12 +1004,12 @@ netconf_operation_failed_xml(cxobj **xret,
char *encstr = NULL;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>%s</error-type>"
"<error-tag>operation-failed</error-tag>"
@ -1083,12 +1083,12 @@ netconf_malformed_message_xml(cxobj **xret,
char *encstr = NULL;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>rpc</error-type>"
"<error-tag>malformed-message</error-tag>"
@ -1130,12 +1130,12 @@ netconf_data_not_unique_xml(cxobj **xret,
cbuf *cb = NULL;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>protocol</error-type>"
"<error-tag>operation-failed</error-tag>"
@ -1143,7 +1143,7 @@ netconf_data_not_unique_xml(cxobj **xret,
"<error-severity>error</error-severity>") < 0)
goto done;
if (cvec_len(cvk)){
if ((xinfo = xml_new("error-info", xerr, NULL)) == NULL)
if ((xinfo = xml_new("error-info", NULL, xerr, CX_ELMNT)) == NULL)
goto done;
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
@ -1183,12 +1183,12 @@ netconf_minmax_elements_xml(cxobj **xret,
cxobj *xerr;
if (*xret == NULL){
if ((*xret = xml_new("rpc-reply", NULL, NULL)) == NULL)
if ((*xret = xml_new("rpc-reply", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else if (xml_name_set(*xret, "rpc-reply") < 0)
goto done;
if ((xerr = xml_new("rpc-error", *xret, NULL)) == NULL)
if ((xerr = xml_new("rpc-error", NULL, *xret, CX_ELMNT)) == NULL)
goto done;
if (xml_parse_va(&xerr, NULL, "<error-type>protocol</error-type>"
"<error-tag>operation-failed</error-tag>"

View file

@ -953,12 +953,12 @@ api_path2xml_vec(char **vec,
clicon_err(OE_XML, 0, "malformed key, expected '=restval'");
goto done;
}
if ((x = xml_new(yang_argument_get(y), x0, y)) == NULL)
if ((x = xml_new(yang_argument_get(y), NULL, x0, CX_ELMNT)) == NULL)
goto done;
xml_type_set(x, CX_ELMNT);
if ((xb = xml_new("body", x, NULL)) == NULL)
xml_spec_set(x, y);
if ((xb = xml_new("body", NULL, x, CX_BODY)) == NULL)
goto done;
xml_type_set(xb, CX_BODY);
if (restval && xml_value_set(xb, restval) < 0)
goto done;
break;
@ -991,9 +991,10 @@ api_path2xml_vec(char **vec,
}
cvi = NULL;
/* create list object */
if ((x = xml_new(name, x0, y)) == NULL)
if ((x = xml_new(name, NULL, x0, CX_ELMNT)) == NULL)
goto done;
xml_type_set(x, CX_ELMNT);
xml_spec_set(x, y);
vi = 0;
/* Create keys */
while ((cvi = cvec_each(cvk, cvi)) != NULL){
@ -1005,12 +1006,12 @@ api_path2xml_vec(char **vec,
goto done;
goto fail;
}
if ((xn = xml_new(keyname, x, ykey)) == NULL)
if ((xn = xml_new(keyname, NULL, x, CX_ELMNT)) == NULL)
goto done;
xml_type_set(xn, CX_ELMNT);
if ((xb = xml_new("body", xn, NULL)) == NULL)
xml_spec_set(xn, ykey);
if ((xb = xml_new("body", NULL, xn, CX_BODY)) == NULL)
goto done;
xml_type_set(xb, CX_BODY);
if (vi++ < nvalvec){
if (xml_value_set(xb, valvec[vi-1]) < 0)
goto done;
@ -1019,9 +1020,9 @@ api_path2xml_vec(char **vec,
break;
default: /* eg Y_CONTAINER, Y_LEAF */
if ((x = xml_find_type(x0, NULL, name, CX_ELMNT)) == NULL){ /* eg key of list */
if ((x = xml_new(name, x0, y)) == NULL)
if ((x = xml_new(name, NULL, x0, CX_ELMNT)) == NULL)
goto done;
xml_type_set(x, CX_ELMNT);
xml_spec_set(x, y);
}
break;
}

View file

@ -398,7 +398,7 @@ clicon_rpc_get_config(clicon_handle h,
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
if ((xd = xml_new("data", NULL, NULL)) == NULL)
if ((xd = xml_new("data", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else{
@ -754,7 +754,7 @@ clicon_rpc_get(clicon_handle h,
if ((xd = xpath_first(xret, NULL, "/rpc-reply/rpc-error")) != NULL)
xd = xml_parent(xd); /* point to rpc-reply */
else if ((xd = xpath_first(xret, NULL, "/rpc-reply/data")) == NULL){
if ((xd = xml_new("data", NULL, NULL)) == NULL)
if ((xd = xml_new("data", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
}
else{

View file

@ -955,7 +955,7 @@ xml_childvec_get(cxobj *x)
* @retval NULL Error and clicon_err() called
* @code
* cxobj *x;
* if ((x = xml_new(name, xparent, NULL)) == NULL)
* if ((x = xml_new(name, prefix, xparent, CX_ELMNT)) == NULL)
* err;
* ...
* xml_free(x);
@ -967,9 +967,10 @@ xml_childvec_get(cxobj *x)
* @see xml_sort_insert
*/
cxobj *
xml_new(char *name,
cxobj *xp,
yang_stmt *yspec)
xml_new(char *name,
char *prefix,
cxobj *xp,
enum cxobj_type type)
{
cxobj *x;
@ -978,7 +979,12 @@ xml_new(char *name,
return NULL;
}
memset(x, 0, sizeof(cxobj));
if ((xml_name_set(x, name)) < 0)
xml_type_set(x, type);
if (name != NULL &&
xml_name_set(x, name) < 0)
return NULL;
if (prefix != NULL &&
xml_prefix_set(x, prefix) < 0)
return NULL;
if (xp){
xml_parent_set(x, xp);
@ -986,11 +992,12 @@ xml_new(char *name,
return NULL;
x->_x_i = xml_child_nr(xp)-1;
}
x->x_spec = yspec; /* Can be NULL */
_stats_nr++;
return x;
}
#ifdef NOTYET
/*! Create new xml node given a name and parent. Free with xml_free().
*/
cxobj *
@ -1031,6 +1038,7 @@ xml_new2(char *name,
_stats_nr++;
return x;
}
#endif /* NOTYET */
/*! Return yang spec of node.
* Not necessarily set. Either has not been set yet (by xml_spec_set( or anyxml.
@ -1194,7 +1202,7 @@ xml_wrap_all(cxobj *xp,
if (!is_element(xp))
return NULL;
if ((xw = xml_new(tag, NULL, NULL)) == NULL)
if ((xw = xml_new(tag, NULL, NULL, CX_ELMNT)) == NULL)
goto done;
while (xp->x_childvec_len)
if (xml_addsub(xw, xml_child_i(xp, 0)) < 0)
@ -1223,7 +1231,7 @@ xml_wrap(cxobj *xc,
cxobj *xp; /* parent */
xp = xml_parent(xc);
if ((xw = xml_new(tag, xp, NULL)) == NULL)
if ((xw = xml_new(tag, NULL, xp, CX_ELMNT)) == NULL)
goto done;
if (xml_addsub(xw, xc) < 0)
goto done;
@ -1804,7 +1812,7 @@ xml_copy_one(cxobj *x0,
* @retval 0 OK
* @retval -1 Error
* @code
* x1 = xml_new("new", xparent, NULL);
* x1 = xml_new("new", NULL, xparent, xml_type(x0));
* if (xml_copy(x0, x1) < 0)
* err;
* @endcode
@ -1822,7 +1830,7 @@ xml_copy(cxobj *x0,
goto done;
x = NULL;
while ((x = xml_child_each(x0, x, -1)) != NULL) {
if ((xcopy = xml_new(xml_name(x), x1, xml_spec(x))) == NULL)
if ((xcopy = xml_new(xml_name(x), NULL, x1, xml_type(x))) == NULL)
goto done;
if (xml_copy(x, xcopy) < 0) /* recursion */
goto done;
@ -1846,7 +1854,7 @@ xml_dup(cxobj *x0)
{
cxobj *x1;
if ((x1 = xml_new("new", NULL, xml_spec(x0))) == NULL)
if ((x1 = xml_new("new", NULL, NULL, xml_type(x0))) == NULL)
return NULL;
if (xml_copy(x0, x1) < 0)
return NULL;

View file

@ -591,7 +591,7 @@ xml_parse_file2(int fd,
(endtag && (state == endtaglen))){
state = 0;
if (*xt == NULL)
if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, NULL)) == NULL)
if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if ((ret = _xml_parse(ptr, yb, yspec, *xt, xerr)) < 0)
goto done;
@ -657,7 +657,7 @@ xml_parse_string2(const char *str,
return -1;
}
if (*xt == NULL){
if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, NULL)) == NULL)
if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, NULL, CX_ELMNT)) == NULL)
return -1;
}
return _xml_parse(str, yb, yspec, *xt, xerr);
@ -698,7 +698,7 @@ xml_parse_string(const char *str,
}
if (*xt == NULL){
yb = YB_TOP; /* ad-hoc #1 */
if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, NULL)) == NULL)
if ((*xt = xml_new(XML_TOP_SYMBOL, NULL, NULL, CX_ELMNT)) == NULL)
return -1;
}
else{

View file

@ -386,7 +386,7 @@ cvec2xml_1(cvec *cvv,
cv = NULL;
while ((cv = cvec_each(cvv, cv)) != NULL)
len++;
if ((xt = xml_new(toptag, xp, NULL)) == NULL)
if ((xt = xml_new(toptag, NULL, xp, CX_ELMNT)) == NULL)
goto err;
if (xml_childvec_set(xt, len) < 0)
goto err;
@ -395,13 +395,12 @@ cvec2xml_1(cvec *cvv,
while ((cv = cvec_each(cvv, cv)) != NULL) {
if (cv_type_get(cv)==CGV_ERR || cv_name_get(cv) == NULL)
continue;
if ((xn = xml_new(cv_name_get(cv), NULL, NULL)) == NULL) /* this leaks */
if ((xn = xml_new(cv_name_get(cv), NULL, NULL, CX_ELMNT)) == NULL) /* this leaks */
goto err;
xml_parent_set(xn, xt);
xml_child_i_set(xt, i++, xn);
if ((xb = xml_new("body", xn, NULL)) == NULL) /* this leaks */
if ((xb = xml_new("body", NULL, xn, CX_BODY)) == NULL) /* this leaks */
goto err;
xml_type_set(xb, CX_BODY);
val = cv2str_dup(cv);
xml_value_set(xb, val); /* this leaks */
if (val)
@ -823,16 +822,13 @@ add_namespace(cxobj *x,
goto done;
/* Create xmlns attribute to x1p/x1 XXX same code v */
if (prefix){
if ((xa = xml_new(prefix, xp, NULL)) == NULL)
goto done;
if (xml_prefix_set(xa, "xmlns") < 0)
if ((xa = xml_new(prefix, "xmlns", xp, CX_ATTR)) == NULL)
goto done;
}
else{
if ((xa = xml_new("xmlns", xp, NULL)) == NULL)
if ((xa = xml_new("xmlns", NULL, xp, CX_ATTR)) == NULL)
goto done;
}
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, namespace) < 0)
goto done;
xml_sort(xp, NULL); /* Ensure attr is first / XXX xml_insert? */
@ -928,8 +924,10 @@ xml_default(cxobj *xt,
continue;
if (!cv_flag(yang_cv_get(y), V_UNSET)){ /* Default value exists */
if (!xml_find(xt, yang_argument_get(y))){
if ((xc = xml_new(yang_argument_get(y), NULL, y)) == NULL)
if ((xc = xml_new(yang_argument_get(y), NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xml_spec_set(xc, y);
/* assign right prefix */
if ((namespace = yang_find_mynamespace(y)) != NULL){
prefix = NULL;
@ -950,9 +948,8 @@ xml_default(cxobj *xt,
}
xml_flag_set(xc, XML_FLAG_DEFAULT);
if ((xb = xml_new("body", xc, NULL)) == NULL)
if ((xb = xml_new("body", NULL, xc, CX_BODY)) == NULL)
goto done;
xml_type_set(xb, CX_BODY);
if ((str = cv2str_dup(yang_cv_get(y))) == NULL){
clicon_err(OE_UNIX, errno, "cv2str_dup");
goto done;
@ -1752,19 +1749,18 @@ xml_merge1(cxobj *x0, /* the target */
if (yang_keyword_get(y0) == Y_LEAF_LIST || yang_keyword_get(y0) == Y_LEAF){
x1bstr = xml_body(x1);
if (x0==NULL){
if ((x0 = xml_new(x1name, x0p, (yang_stmt*)y0)) == NULL)
if ((x0 = xml_new(x1name, NULL, x0p, CX_ELMNT)) == NULL)
goto done;
xml_spec_set(x0, y0);
if (x1bstr){ /* empty type does not have body */
if ((x0b = xml_new("body", x0, NULL)) == NULL)
if ((x0b = xml_new("body", NULL, x0, CX_BODY)) == NULL)
goto done;
xml_type_set(x0b, CX_BODY);
}
}
if (x1bstr){
if ((x0b = xml_body_get(x0)) == NULL){
if ((x0b = xml_new("body", x0, NULL)) == NULL)
if ((x0b = xml_new("body", NULL, x0, CX_BODY)) == NULL)
goto done;
xml_type_set(x0b, CX_BODY);
}
if (xml_value_set(x0b, x1bstr) < 0)
goto done;
@ -1774,8 +1770,9 @@ xml_merge1(cxobj *x0, /* the target */
} /* if LEAF|LEAF_LIST */
else { /* eg Y_CONTAINER, Y_LIST */
if (x0==NULL){
if ((x0 = xml_new(x1name, NULL, (yang_stmt*)y0)) == NULL)
if ((x0 = xml_new(x1name, NULL, NULL, CX_ELMNT)) == NULL)
goto done;
xml_spec_set(x0, y0);
}
if (assign_namespaces(x1, x0, x0p) < 0)
goto done;

View file

@ -489,16 +489,13 @@ xmlns_set(cxobj *x,
cxobj *xa;
if (prefix != NULL){ /* xmlns:<prefix>="<uri>" */
if ((xa = xml_new(prefix, x, NULL)) == NULL)
goto done;
if (xml_prefix_set(xa, "xmlns") < 0)
if ((xa = xml_new(prefix, "xmlns", x, CX_ATTR)) == NULL)
goto done;
}
else{ /* xmlns="<uri>" */
if ((xa = xml_new("xmlns", x, NULL)) == NULL)
if ((xa = xml_new("xmlns", NULL, x, CX_ATTR)) == NULL)
goto done;
}
xml_type_set(xa, CX_ATTR);
if (xml_value_set(xa, ns) < 0)
goto done;
/* (re)set namespace cache (as used in xml2ns) */

View file

@ -108,9 +108,8 @@ xml_parse_content(clixon_xml_yacc *xy,
xy->xy_xelement = NULL; /* init */
if (xn == NULL){
if ((xn = xml_new("body", xp, NULL)) == NULL)
if ((xn = xml_new("body", NULL, xp, CX_BODY)) == NULL)
goto done;
xml_type_set(xn, CX_BODY);
}
if (xml_value_append(xn, str) < 0)
goto done;
@ -145,9 +144,8 @@ xml_parse_whitespace(clixon_xml_yacc *xy,
goto ok; /* Skip if already element */
}
if (xn == NULL){
if ((xn = xml_new("body", xp, NULL)) == NULL)
if ((xn = xml_new("body", NULL, xp, CX_BODY)) == NULL)
goto done;
xml_type_set(xn, CX_BODY);
}
if (xml_value_append(xn, str) < 0)
goto done;
@ -189,10 +187,7 @@ xml_parse_prefixed_name(clixon_xml_yacc *xy,
cxobj *xp; /* xml parent */
xp = xy->xy_xparent;
if ((x = xml_new(name, xp, NULL)) == NULL)
goto done;
xml_type_set(x, CX_ELMNT);
if (prefix && xml_prefix_set(x, prefix) < 0)
if ((x = xml_new(name, prefix, xp, CX_ELMNT)) == NULL)
goto done;
xy->xy_xelement = x;
/* If topmost, add to top-list created list */
@ -305,10 +300,7 @@ xml_parse_attr(clixon_xml_yacc *xy,
cxobj *xa = NULL;
if ((xa = xml_find_type(xy->xy_xelement, prefix, name, CX_ATTR)) == NULL){
if ((xa = xml_new(name, xy->xy_xelement, NULL)) == NULL)
goto done;
xml_type_set(xa, CX_ATTR);
if (prefix && xml_prefix_set(xa, prefix) < 0)
if ((xa = xml_new(name, prefix, xy->xy_xelement, CX_ATTR)) == NULL)
goto done;
}
if (xml_value_set(xa, attval) < 0)

View file

@ -116,7 +116,7 @@ main(int argc,
if ((h = clicon_handle_init()) == NULL)
goto done;
/* Initialize config tree (needed for -Y below) */
if ((xcfg = xml_new("clixon-config", NULL, NULL)) == NULL)
if ((xcfg = xml_new("clixon-config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (clicon_conf_xml_set(h, xcfg) < 0)
goto done;

View file

@ -169,11 +169,11 @@ main(int argc,
/* Initialize clixon handle */
if ((h = clicon_handle_init()) == NULL)
goto done;
if ((xcfg = xml_new("clixon-config", NULL, NULL)) == NULL)
if ((xcfg = xml_new("clixon-config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (clicon_conf_xml_set(h, xcfg) < 0)
goto done;
xcfg = xml_new("clixon-config", NULL, NULL);
xcfg = xml_new("clixon-config", NULL, NULL, CX_ELMNT);
clicon_conf_xml_set(h, xcfg);
optind = 1;
opterr = 0;

View file

@ -147,7 +147,7 @@ main(int argc,
if ((h = clicon_handle_init()) == NULL)
goto done;
/* Initialize config tree (needed for -Y below) */
if ((xcfg = xml_new("clixon-config", NULL, NULL)) == NULL)
if ((xcfg = xml_new("clixon-config", NULL, NULL, CX_ELMNT)) == NULL)
goto done;
if (clicon_conf_xml_set(h, xcfg) < 0)
goto done;