* Added clicon_handle as parameter to all validate functions

* Added libxml2 XSD regexp mode as alternative to posix translation
* Added `CLICON_YANG_REGEXP` option with possible values libxml2 and posix
This commit is contained in:
Olof hagsand 2019-05-23 22:48:33 +02:00
parent 69f2eb30f1
commit a804e05375
27 changed files with 501 additions and 289 deletions

View file

@ -470,7 +470,7 @@ from_client_edit_config(clicon_handle h,
goto ok;
}
/* xmldb_put (difflist handling) requires list keys */
if ((ret = xml_yang_validate_list_key_only(xc, cbret)) < 0)
if ((ret = xml_yang_validate_list_key_only(h, xc, cbret)) < 0)
goto done;
if (ret == 0)
goto ok;
@ -1147,7 +1147,7 @@ from_client_msg(clicon_handle h,
* maybe not necessary since it should be */
if (xml_spec_populate_rpc(h, x, yspec) < 0)
goto done;
if ((ret = xml_yang_validate_rpc(x, cbret)) < 0)
if ((ret = xml_yang_validate_rpc(h, x, cbret)) < 0)
goto done;
if (ret == 0)
goto reply;

View file

@ -87,7 +87,8 @@
* @retval 1 Validation OK
*/
static int
generic_validate(yang_stmt *yspec,
generic_validate(clicon_handle h,
yang_stmt *yspec,
transaction_data_t *td,
cbuf *cbret)
{
@ -99,7 +100,7 @@ generic_validate(yang_stmt *yspec,
int ret;
/* All entries */
if ((ret = xml_yang_validate_all_top(td->td_target, cbret)) < 0)
if ((ret = xml_yang_validate_all_top(h, td->td_target, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -108,7 +109,7 @@ generic_validate(yang_stmt *yspec,
x1 = td->td_scvec[i]; /* source changed */
x2 = td->td_tcvec[i]; /* target changed */
/* Should this be recursive? */
if ((ret = xml_yang_validate_add(x2, cbret)) < 0)
if ((ret = xml_yang_validate_add(h, x2, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -126,7 +127,7 @@ generic_validate(yang_stmt *yspec,
/* added entries */
for (i=0; i<td->td_alen; i++){
x2 = td->td_avec[i];
if ((ret = xml_yang_validate_add(x2, cbret)) < 0)
if ((ret = xml_yang_validate_add(h, x2, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -224,7 +225,7 @@ startup_common(clicon_handle h,
/* 5. Make generic validation on all new or changed data.
Note this is only call that uses 3-values */
clicon_debug(1, "Validating startup %s", db);
if ((ret = generic_validate(yspec, td, cbret)) < 0)
if ((ret = generic_validate(h, yspec, td, cbret)) < 0)
goto done;
if (ret == 0)
goto fail; /* STARTUP_INVALID */
@ -408,7 +409,7 @@ from_validate_common(clicon_handle h,
* But xml_diff requires some basic validation, at least check that yang-specs
* have been assigned
*/
if ((ret = xml_yang_validate_all_top(td->td_target, cbret)) < 0)
if ((ret = xml_yang_validate_all_top(h, td->td_target, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;
@ -461,7 +462,7 @@ from_validate_common(clicon_handle h,
/* 5. Make generic validation on all new or changed data.
Note this is only call that uses 3-values */
if ((ret = generic_validate(yspec, td, cbret)) < 0)
if ((ret = generic_validate(h, yspec, td, cbret)) < 0)
goto done;
if (ret == 0)
goto fail;

View file

@ -497,6 +497,12 @@ main(int argc,
if (help)
usage(h, argv[0]);
#ifndef HAVE_LIBXML2
if (strcmp(clicon_yang_regexp(h), "libxml2")==0){
clicon_err(OE_FATAL, 0, "CLICON_YANG_REGEXP set to libxml2, but HAVE_LIBXM2 not set (Either change CLICON_YANG_REGEXP to posix, or install libxml2?))");
goto done;
}
#endif
/* Check pid-file, if zap kil the old daemon, else return here */
if ((pidfile = clicon_backend_pidfile(h)) == NULL){
clicon_err(OE_FATAL, 0, "pidfile not set");