diff --git a/CHANGELOG.md b/CHANGELOG.md index 2454dfec..92519821 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ ### Minor changes +* Obsoleted and removed XMLDB format "tree". This function did not work. Only xml and json allowed. * Test framework * Added `-- -S ` command-line to main example to be able to return any state to main example. * Added `test/cicd` test scripts for running on a set of other hosts diff --git a/lib/src/Makefile.in b/lib/src/Makefile.in index 7eb4189f..b3866703 100644 --- a/lib/src/Makefile.in +++ b/lib/src/Makefile.in @@ -77,7 +77,6 @@ SRC = clixon_sig.c clixon_uid.c clixon_log.c clixon_err.c clixon_event.c \ clixon_proto.c clixon_proto_client.c \ clixon_xpath.c clixon_xpath_ctx.c clixon_xpath_eval.c clixon_xpath_optimize.c \ clixon_sha1.c clixon_datastore.c clixon_datastore_write.c clixon_datastore_read.c \ - clixon_datastore_tree.c \ clixon_netconf_lib.c clixon_stream.c clixon_nacm.c YACCOBJS := lex.clixon_xml_parse.o clixon_xml_parse.tab.o \ diff --git a/lib/src/clixon_datastore_read.c b/lib/src/clixon_datastore_read.c index 29e096e5..b4cc9b01 100644 --- a/lib/src/clixon_datastore_read.c +++ b/lib/src/clixon_datastore_read.c @@ -78,7 +78,6 @@ #include "clixon_datastore.h" #include "clixon_datastore_read.h" -#include "clixon_datastore_tree.h" #define handle(xh) (assert(text_handle_check(xh)==0),(struct text_handle *)(xh)) @@ -335,35 +334,29 @@ xmldb_readfile(clicon_handle h, goto done; } /* Parse file into internal XML tree from different formats */ - if (strcmp(format, "tree")==0){ - if (datastore_tree_read(h, dbfile, &x0) < 0) + if ((fd = open(dbfile, O_RDONLY)) < 0) { + clicon_err(OE_UNIX, errno, "open(%s)", dbfile); + goto done; + } + if (strcmp(format, "json")==0){ + if ((ret = json_parse_file(fd, yspec, &x0, NULL)) < 0) /* XXX: ret == 0*/ goto done; } - else{ - if ((fd = open(dbfile, O_RDONLY)) < 0) { - clicon_err(OE_UNIX, errno, "open(%s)", dbfile); - goto done; - } - if (strcmp(format, "json")==0){ - if ((ret = json_parse_file(fd, yspec, &x0, NULL)) < 0) /* XXX: ret == 0*/ - goto done; - } - else if ((xml_parse_file(fd, "", yspec, &x0)) < 0) - goto done; + else if ((xml_parse_file(fd, "", yspec, &x0)) < 0) + goto done; - /* Always assert a top-level called "config". - To ensure that, deal with two cases: - 1. File is empty -> rename top-level to "config" */ - if (xml_child_nr(x0) == 0){ - if (xml_name_set(x0, "config") < 0) - goto done; - } - /* 2. File is not empty ... -> replace root */ - else{ - /* There should only be one element and called config */ - if (singleconfigroot(x0, &x0) < 0) - goto done; - } + /* Always assert a top-level called "config". + To ensure that, deal with two cases: + 1. File is empty -> rename top-level to "config" */ + if (xml_child_nr(x0) == 0){ + if (xml_name_set(x0, "config") < 0) + goto done; + } + /* 2. File is not empty ... -> replace root */ + else{ + /* There should only be one element and called config */ + if (singleconfigroot(x0, &x0) < 0) + goto done; } /* From Clixon 3.10,datastore files may contain module-state defining * which modules are used in the file. diff --git a/lib/src/clixon_datastore_tree.c b/lib/src/clixon_datastore_tree.c deleted file mode 100644 index f2788f2f..00000000 --- a/lib/src/clixon_datastore_tree.c +++ /dev/null @@ -1,458 +0,0 @@ -/* - * - ***** BEGIN LICENSE BLOCK ***** - - Copyright (C) 2009-2019 Olof Hagsand and Benny Holmgren - - This file is part of CLIXON. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - Alternatively, the contents of this file may be used under the terms of - the GNU General Public License Version 3 or later (the "GPL"), - in which case the provisions of the GPL are applicable instead - of those above. If you wish to allow use of your version of this file only - under the terms of the GPL, and not to allow others to - use your version of this file under the terms of Apache License version 2, - indicate your decision by deleting the provisions above and replace them with - the notice and other provisions required by the GPL. If you do not delete - the provisions above, a recipient may use your version of this file under - the terms of any one of the Apache License version 2 or the GPL. - - ***** END LICENSE BLOCK ***** - - * - * XML file save - */ - -#ifdef HAVE_CONFIG_H -#include "clixon_config.h" /* generated by config & autoconf */ -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* cligen */ -#include - -/* clicon */ - -#include "clixon_string.h" -#include "clixon_queue.h" -#include "clixon_hash.h" -#include "clixon_err.h" -#include "clixon_log.h" -#include "clixon_handle.h" -#include "clixon_yang.h" -#include "clixon_xml.h" - -#include "clixon_datastore_tree.h" - -#define align4(s) (((s)/4)*4 + 4) - -struct indexlist{ - qelem_t il_q; /* this must be there */ - uint32_t il_i; - int il_len; /* How many */ -}; -typedef struct indexlist indexlist; - -struct indexhead{ - indexlist *ih_list; -}; -typedef struct indexhead indexhead; - -static int -indexhead_free(indexhead *ih) -{ - indexlist *il; - - while ((il = ih->ih_list) != NULL) - DELQ(il, ih->ih_list, indexlist*); - return 0; -} - -int -index_get(indexhead *ih, - size_t len, /* in bytes */ - uint32_t *indexp) -{ - int retval = -1; - int nr; - uint32_t index = 0; - struct indexlist *il; - indexlist *new; - - nr = len/DF_BLOCK + 1; - if ((new = malloc(sizeof(indexlist))) == NULL){ - clicon_err(OE_XML, errno, "malloc"); - goto done; - } - memset(new, 0, sizeof(indexlist)); - // new->il_i = i; Dont know i yet - new->il_len = nr; - if ((il = ih->ih_list) != NULL) { - il = PREVQ(indexlist*, il); - index = il->il_i + il->il_len; - } - ADDQ(new, ih->ih_list); - new->il_i = index; - *indexp = index; - retval = 0; - done: - return retval; -} -#ifdef NOTYET -int -index_get(indexhead *ih, - size_t len, /* in bytes */ - uint32_t *indexp) -{ - int retval = -1; - int nr; - uint32_t index = 0; - struct indexlist *il; - indexlist *new; - - nr = len/DF_BLOCK + 1; - if ((new = malloc(sizeof(indexlist))) == NULL){ - clicon_err(OE_XML, errno, "malloc"); - goto done; - } - memset(new, 0, sizeof(indexlist)); - // new->il_i = i; Dont know i yet - new->il_len = nr; - - /* Find nr conseq blocks */ - if ((il = ih->ih_list) != NULL) { - do { - if (il->il_i - index >= nr){ /* Found */ - INSQ(new, il); - break; - } - index = il->il_i + il->il_len; - il = NEXTQ(indexlist*, il); - } while (il != ih->ih_list); - ADDQ(new, il); /* after? */ - } - else - INSQ(new, ih->ih_list); - new->il_i = index; - *indexp = index; - retval = 0; - done: - return retval; -} -#endif - -int -index_dump(FILE *f, - indexhead *ih) -{ - indexlist *il; - - if ((il = ih->ih_list) != NULL) { - do { - fprintf(f, "%u %d\n", il->il_i, il->il_len); - il = NEXTQ(indexlist*, il); - } while (il != ih->ih_list); - } - return 0; -} - -/* - * @param[out] xp - * @param[out] vec If type is CX_ELMNT, points to vector of indexes,... - * @retval -1 Error - * @retval 0 Sanity check failed - * @retval 1 OK xp set (or NULL if empty) - */ -static int -buf2xml(FILE *f, - uint32_t index, - cxobj **xp) -{ - int retval = -1; - uint8_t ver; - uint8_t type; - int ptr; - uint32_t len; - cxobj *x = NULL; - char *name; - char *prefix = NULL; - char hdr[8] = {0, }; - char *buf = NULL; - int vlen; - int i; - uint32_t ind; - cxobj *xc; - size_t ret; - - /* Read hdr - * +-----+-----+-----+-----+-----+-----+-----+-----+ - * | ver | type| de | ad | len | - * +-----+-----+-----+-----+-----+-----+-----+-----+ - */ - if (fseek(f, index*DF_BLOCK, SEEK_SET) < 0){ - clicon_err(OE_UNIX, errno, "fseek"); - goto done; - } - if ((ret = fread(hdr, sizeof(char), sizeof(hdr), f)) != sizeof(hdr)){ - clicon_err(OE_XML, errno, "fread"); - goto done; - } - if ((ver = hdr[0]&0xff) == 0) /* Means empty */ - goto ok; - if (ver != 1){ - clicon_debug(1, "%s Wrong version: %d", __FUNCTION__, ver); - goto fail; - } - type = hdr[1]&0x0f; - if (type != CX_BODY && type != CX_ELMNT && type != CX_ATTR){ - clicon_debug(1, "%s Wrong type: %d", __FUNCTION__, type); - goto fail; - } - if ((hdr[2]&0xff) != 0xde){ - clicon_debug(1, "%s Expected 0xde: %x", __FUNCTION__, hdr[2]&0xff); - goto fail; - } - if ((hdr[3]&0xff) != 0xad){ - clicon_debug(1, "%s Expected 0xad: %x", __FUNCTION__, hdr[3]&0xff); - goto fail; - } - /* Copy and byte-swap length field */ - memcpy(&len, &hdr[4], 4); - len = ntohl(len); - - /* Read rest - */ - ptr = 0; - if ((buf = malloc(len - sizeof(hdr))) == NULL){ - clicon_err(OE_UNIX, errno, "malloc"); - goto done; - } - if ((ret = fread(buf, sizeof(char), len-sizeof(hdr), f)) != len-sizeof(hdr)){ - clicon_err(OE_XML, errno, "fread"); - goto done; - } - if ((name = strchr(buf, ':')) != NULL){ - *name = '\0'; - name++; - prefix = buf; - ptr += strlen(prefix)+1; - } - else - name = buf; - ptr += strlen(name) + 1; - ptr = align4(ptr); - if ((x = xml_new(name, NULL, NULL)) == NULL) - goto done; - if (prefix) - if (xml_prefix_set(x, prefix) < 0) - goto done; - xml_type_set(x, type); - if (xml_type(x) != CX_ELMNT){ - if (xml_value_set(x, &buf[ptr]) < 0) - goto done; - ptr += strlen(xml_value(x)) +1; - } - else{ - vlen = (len - sizeof(hdr) - ptr)/ sizeof(uint32_t); - if (vlen < 0){ - clicon_debug(1, "%s Nr of elements should not be negative: %d", __FUNCTION__, vlen); - goto fail; - } - for (i=0; ia$rndfoo$rnd$" # Depth and augment diff --git a/util/clixon_util_datastore.c b/util/clixon_util_datastore.c index ec069a34..51063a07 100644 --- a/util/clixon_util_datastore.c +++ b/util/clixon_util_datastore.c @@ -76,7 +76,7 @@ usage(char *argv0) "\t-D\t\tDebug\n" "\t-d \t\tDatabase name. Default: running. Alt: candidate,startup\n" "\t-b \tDatabase directory. Mandatory\n" - "\t-f \tDatabase format: xml, json, tree\n" + "\t-f \tDatabase format: xml or json\n" "\t-x \tXML file. Alternative to put argument\n" "\t-y \tYang file. Mandatory\n" "and command is either:\n" diff --git a/yang/clixon/clixon-config@2019-09-11.yang b/yang/clixon/clixon-config@2019-09-11.yang index 745defb2..84a9ab9e 100644 --- a/yang/clixon/clixon-config@2019-09-11.yang +++ b/yang/clixon/clixon-config@2019-09-11.yang @@ -105,10 +105,6 @@ module clixon-config { enum json{ description "Save and load xmldb as JSON"; } - enum tree{ - description "Save and load xmldb as Clixon record-based tree - file format (experimental)"; - } } } typedef datastore_cache{