* New "general-purpose" datastore upgrade callback added which i called once on startup, intended for lo

w-level general upgrades and as a complement to module-specific upgrade.
  * Called on startup after initial XML parsing, but before module-specific upgrades
  * Enabled by definign the `.ca_datastore_upgrade`
  * [General-purpose upgrade documentation](https://clixon-docs.readthedocs.io/en/latest/backend.html#ge
neral-purpose)
* JSON parse error messages change from ` on line x: syntax error,..` to `json_parse: line x: syntax err
or`
* Unknown-element error message is more descriptive, eg from `namespace is: urn:example:clixon` to: `Fai
led to find YANG spec of XML node: x with parent: xp in namespace urn:example:clixon`.
* C-API parse and validation API more capable
  * `xml_spec_populate` family of functions extended with three-value return values
    * -1: error, 0: parse OK, 1: parse and YANG binding OK.
  * `xml_parse` and `json_parse` API changes
    * Three value returns: -1: error, 0: parse OK, 1: parse and YANG binding OK.
    * Extended `xml_parse_file2` and `xml_parse_string2` extended API functions with all options available.
      * New concept called `yang_bind` that defines how XML symbols are bound to YANG after parsing
    * Existing API same except `xml_parse_file` `endtag` argument moved to `xml_parse_file2`
* C-API: Added instrumentation: `xml_size` and `xml_stats_get`.
* Fixed: Enabling modstate (CLICON_XMLDB_MODSTATE), changing a revision on a yang, and restarting made the backend daemon exit at start (thanks Matt)
  * Also: ensure to load `ietf-yang-library.yang ` if CLICON_XMLDB_MODSTATE is set
This commit is contained in:
Olof hagsand 2020-02-20 14:00:01 +01:00
parent d665992f7c
commit 9fa5e216c4
80 changed files with 2204 additions and 755 deletions

View file

@ -3,7 +3,8 @@
***** BEGIN LICENSE BLOCK *****
Copyright (C) 2009-2016 Olof Hagsand and Benny Holmgren
Copyright (C) 2017-2020 Olof Hagsand
Copyright (C) 2017-2019 Olof Hagsand
Copyright (C) 2020 Olof Hagsand and Rubicon Communications, LLC
This file is part of CLIXON.
@ -77,10 +78,19 @@ enum insert_type{ /* edit-config insert */
INS_AFTER,
};
/* XML object types */
enum cxobj_type {CX_ERROR=-1,
CX_ELMNT,
CX_ATTR,
CX_BODY};
/* How to bind yang to XML top-level when parsing */
enum yang_bind{
YB_NONE, /* Dont try to do Yang binding */
YB_PARENT, /* Get yang binding from parents yang */
YB_TOP, /* Get yang binding from top-level modules */
};
#define CX_ANY CX_ERROR /* catch all and error is same */
typedef struct xml cxobj; /* struct defined in clicon_xml.c */
@ -107,6 +117,8 @@ typedef int (xml_applyfn_t)(cxobj *x, void *arg);
* Prototypes
*/
char *xml_type2str(enum cxobj_type type);
int xml_stats_get(uint64_t *nr);
size_t xml_size(cxobj *xt, size_t *szp);
char *xml_name(cxobj *xn);
int xml_name_set(cxobj *xn, char *name);
char *xml_prefix(cxobj *xn);
@ -115,7 +127,6 @@ char *nscache_get(cxobj *x, char *prefix);
int nscache_get_prefix(cxobj *x, char *namespace, char **prefix);
cvec *nscache_get_all(cxobj *x);
int nscache_set(cxobj *x, char *prefix, char *namespace);
int nscache_clear(cxobj *x);
int nscache_replace(cxobj *x, cvec *ns);
@ -181,8 +192,11 @@ int xml_free(cxobj *xn);
int xml_print(FILE *f, cxobj *xn);
int clicon_xml2file(FILE *f, cxobj *xn, int level, int prettyprint);
int clicon_xml2cbuf(cbuf *xf, cxobj *xn, int level, int prettyprint, int32_t depth);
int xml_parse_file(int fd, char *endtag, yang_stmt *yspec, cxobj **xt);
int xml_parse_file(int fd, yang_stmt *yspec, cxobj **xt);
int xml_parse_file2(int fd, enum yang_bind bind, yang_stmt *yspec, char *endtag, cxobj **xt, cxobj **xerr);
int xml_parse_string(const char *str, yang_stmt *yspec, cxobj **xml_top);
int xml_parse_string2(const char *str, enum yang_bind yb, yang_stmt *yspec, cxobj **xt, cxobj **xerr);
#if defined(__GNUC__) && __GNUC__ >= 3
int xml_parse_va(cxobj **xt, yang_stmt *yspec, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
#else