summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2011-01-07 11:03:45 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2011-01-07 18:18:51 -0800
commit9280b45e11e1c877d466f34f939eb70f29a669e5 (patch)
tree31dd9bd9fdd170afb95d53a1e5227c297fbcaf01
parentd4111b01462641baa21978a78390215987a5958a (diff)
downloadvyatta-cfg-9280b45e11e1c877d466f34f939eb70f29a669e5.tar.gz
vyatta-cfg-9280b45e11e1c877d466f34f939eb70f29a669e5.zip
improve load error message
(cherry picked from commit 42f2fdb35cff89debd346126eb69cd95d855ff7b)
-rw-r--r--src/cnode/cnode.cpp34
-rw-r--r--src/cnode/cnode.hpp2
-rw-r--r--src/cparse/cparse.ypp4
3 files changed, 26 insertions, 14 deletions
diff --git a/src/cnode/cnode.cpp b/src/cnode/cnode.cpp
index 876e32e..142ed9f 100644
--- a/src/cnode/cnode.cpp
+++ b/src/cnode/cnode.cpp
@@ -28,7 +28,8 @@ using namespace cnode;
////// constructors/destructors
CfgNode::CfgNode(vector<string>& path_comps, char *name, char *val,
- char *comment, int deact, Cstore *cstore)
+ char *comment, int deact, Cstore *cstore,
+ bool tag_if_invalid)
: _is_tag(false), _is_leaf(false), _is_multi(false), _is_value(false),
_is_default(false), _is_deactivated(false), _is_leaf_typeless(false),
_is_invalid(false), _is_empty(true), _exists(true)
@@ -63,16 +64,6 @@ CfgNode::CfgNode(vector<string>& path_comps, char *name, char *val,
*/
_is_default = false;
_is_deactivated = deact;
- if (name) {
- _name = name;
- }
- if (val) {
- if (_is_multi) {
- _values.push_back(val);
- } else {
- _value = val;
- }
- }
vector<string> tcnodes;
cstore->tmplGetChildNodes(path_comps, tcnodes);
@@ -88,17 +79,36 @@ CfgNode::CfgNode(vector<string>& path_comps, char *name, char *val,
} else {
// not a valid node
_is_invalid = true;
+ if (tag_if_invalid) {
+ /* this is only used when the parser is creating a "tag node". force
+ * the node to be tag since we don't have template for invalid node.
+ */
+ _is_tag = true;
+ }
+ if (val) {
+ /* if parser got value for the invalid node, always treat it as
+ * "tag value" for simplicity.
+ */
+ _is_tag = true;
+ _is_value = true;
+ }
break;
}
break;
}
- // restore path_comps
+ // restore path_comps. also set value/name for both valid and invalid nodes.
if (val) {
+ if (_is_multi) {
+ _values.push_back(val);
+ } else {
+ _value = val;
+ }
path_comps.pop_back();
}
if (name && name[0]) {
+ _name = name;
path_comps.pop_back();
}
}
diff --git a/src/cnode/cnode.hpp b/src/cnode/cnode.hpp
index 40fb5b6..dadfe85 100644
--- a/src/cnode/cnode.hpp
+++ b/src/cnode/cnode.hpp
@@ -26,7 +26,7 @@ namespace cnode {
class CfgNode {
public:
CfgNode(vector<string>& path_comps, char *name, char *val, char *comment,
- int deact, Cstore *cstore);
+ int deact, Cstore *cstore, bool tag_if_invalid = false);
CfgNode(Cstore& cstore, std::vector<string>& path_comps,
bool active = false, bool recursive = true);
~CfgNode() {};
diff --git a/src/cparse/cparse.ypp b/src/cparse/cparse.ypp
index 80d1120..23a63b2 100644
--- a/src/cparse/cparse.ypp
+++ b/src/cparse/cparse.ypp
@@ -77,7 +77,9 @@ add_node()
CfgNode *mapped_node = cur_node;
if (cur_node->isTag() && cur_node->isValue()) {
// tag value => need to add the "tag node" on top
- CfgNode *p = new CfgNode(pcomps, nname, NULL, NULL, ndeact, cstore);
+ // (need to force "tag" if the node is invalid => tag_if_invalid)
+ CfgNode *p = new CfgNode(pcomps, nname, NULL, NULL, ndeact, cstore,
+ true);
p->addChildNode(cur_node);
mapped_node = p;
}