Fixed https://github.com/clicon/clixon/issues/46 Issue with empty values in leaf-list

Thanks achernavin22
This commit is contained in:
Olof hagsand 2018-10-27 17:06:08 +02:00
parent b477e22d1e
commit 61869c8d44
5 changed files with 33 additions and 12 deletions

View file

@ -94,6 +94,8 @@
* Added -l option for clixon_backend for directing syslog to stderr or stdout if running in foreground
### Corrected Bugs
* Fixed https://github.com/clicon/clixon/issues/46 Issue with empty values in leaf-list
* Thanks achernavin22
* Identity without any identityref:s caused SEGV
* Memory error in backend transaction revert
* Set dir /www-data with www-data as owner, see https://github.com/clicon/clixon/issues/37

View file

@ -99,7 +99,7 @@ restconf_stream_cb(int s,
struct clicon_msg *reply = NULL;
cxobj *xtop = NULL; /* top xml */
cxobj *xn; /* notification xml */
cbuf *cb;
cbuf *cb = NULL;
int pretty = 0; /* XXX should be via arg */
clicon_debug(1, "%s", __FUNCTION__);

View file

@ -74,12 +74,13 @@
int xml_child_sort = 1;
/*! Given an XML object and a child name, return yang stmt of child
/*! Given a child name and an XML object, return yang stmt of child
* If no xml parent, find root yang stmt matching name
* @param[in] name Name of child
* @param[in] x Child
* @param[in] xp XML parent, can be NULL.
* @param[in] yspec Yang specification (top level)
* @param[out] yresult Pointer to yang stmt of result, or NULL, if not found
* @note special rule for rpc, ie <rpc><foo>,look for top "foo" node.
*/
int
xml_child_spec(char *name,
@ -108,6 +109,7 @@ xml_child_spec(char *name,
* @retval >0 if arg1 is greater than arg2
* @note args are pointer ot pointers, to fit into qsort cmp function
* @see xml_cmp1 Similar, but for one object
* @note empty value/NULL is smallest value
*/
int
xml_cmp(const void* arg1,
@ -144,7 +146,12 @@ xml_cmp(const void* arg1,
return 0; /* Ordered by user: maintain existing order */
switch (y1->ys_keyword){
case Y_LEAF_LIST: /* Match with name and value */
equal = strcmp(xml_body(x1), xml_body(x2));
if ((b1 = xml_body(x1)) == NULL)
equal = -1;
else if ((b2 = xml_body(x2)) == NULL)
equal = 1;
else
equal = strcmp(b1, b2);
break;
case Y_LIST: /* Match with key values
* Use Y_LIST cache (see struct yang_stmt)
@ -168,7 +175,7 @@ xml_cmp(const void* arg1,
}
/*! Compare xml object
* @param[in] yangi Yang order
* @param[in] yangi Yang order
* @param[in] keynr Length of keyvec/keyval vector when applicable
* @param[in] keyvec Array of of yang key identifiers
* @param[in] keyval Array of of yang key values
@ -203,8 +210,10 @@ xml_cmp1(cxobj *x,
case Y_LEAF_LIST: /* Match with name and value */
if (userorder && yang_find((yang_node*)y, Y_ORDERED_BY, "user") != NULL)
*userorder=1;
b=xml_body(x);
match = strcmp(keyval[0], b);
if ((b=xml_body(x)) == NULL)
match = 1;
else
match = strcmp(keyval[0], b);
break;
case Y_LIST: /* Match with array of key values */
if (userorder && yang_find((yang_node*)y, Y_ORDERED_BY, "user") != NULL)

View file

@ -5,8 +5,6 @@ APPNAME=example
# include err() and new() functions and creates $dir
. ./lib.sh
cfg=$dir/conf_yang.xml
fyang=$dir/test.yang
@ -91,8 +89,8 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><validate><source><candid
new "minmax: empty"
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><edit-config><target><candidate/></target><default-operation>replace</default-operation><config><c/></config></edit-config></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
exit # NYI
# NYI
if false; then
new "minmax: validate should fail"
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" "^<rpc-reply><rpc-error/></rpc-reply>]]>]]>$"
@ -119,7 +117,7 @@ expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><edit-config><target><can
new "minmax: validate should fail"
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><validate><source><candidate/></source></validate></rpc>]]>]]>" "^<rpc-reply><rpc-error/></rpc-reply>]]>]]>$"
fi # NYI
# kill backend

View file

@ -114,6 +114,18 @@ fi
new "cli defined extension"
expectfn "$clixon_cli -1f $cfg -y $fyang show version" 0 "3."
new "empty values in leaf-list"
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><edit-config><target><candidate/></target><config><x><f><e>a</e></f></x></config></edit-config></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "empty values in leaf-list2"
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><edit-config><target><candidate/></target><config><x><f><e/></f></x></config></edit-config></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "netconf get config"
expecteof "$clixon_netconf -qf $cfg -y $fyang" 0 "<rpc><get-config><source><candidate/></source></get-config></rpc>]]>]]>" "^<rpc-reply><data><x><f><e/><e>a</e></f></x></data></rpc-reply>]]>]]>$"
new "netconf discard-changes"
expecteof "$clixon_netconf -qf $cfg" 0 "<rpc><discard-changes/></rpc>]]>]]>" "^<rpc-reply><ok/></rpc-reply>]]>]]>$"
new "cli not defined extension"
# This text yields an error, but the test cannot detect the error message yet
#expectfn "$clixon_cli -1f $cfg -y $fyangerr show version" 0 "Yang error: Extension ex:not-defined not found"