summaryrefslogtreecommitdiff
path: root/src/cstore/unionfs/cstore-unionfs.cpp
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2011-02-28 18:25:01 -0800
committerAn-Cheng Huang <ancheng@vyatta.com>2011-02-28 18:25:01 -0800
commit24b3de8987f622b349cbe14dca99594f2c279902 (patch)
tree32d2b36144872943726b00ea63c274c0f7107933 /src/cstore/unionfs/cstore-unionfs.cpp
parent2d0d7bc61e12779a56272f82bc66044a5580e778 (diff)
downloadvyatta-cfg-24b3de8987f622b349cbe14dca99594f2c279902.tar.gz
vyatta-cfg-24b3de8987f622b349cbe14dca99594f2c279902.zip
add config template abstraction
Diffstat (limited to 'src/cstore/unionfs/cstore-unionfs.cpp')
-rw-r--r--src/cstore/unionfs/cstore-unionfs.cpp30
1 files changed, 17 insertions, 13 deletions
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp
index 59b5582..b42c8f8 100644
--- a/src/cstore/unionfs/cstore-unionfs.cpp
+++ b/src/cstore/unionfs/cstore-unionfs.cpp
@@ -415,17 +415,21 @@ UnionfsCstore::tmpl_node_exists()
return (b_fs_exists(tmpl_path) && b_fs_is_directory(tmpl_path));
}
-/* parse template at current tmpl_path.
- * def: for storing parsed template.
- * return true if successful. otherwise return false.
+/* parse template at current tmpl_path and return an allocated Ctemplate
+ * pointer if successful. otherwise return 0.
*/
-bool
-UnionfsCstore::tmpl_parse(vtw_def& def)
+Ctemplate *
+UnionfsCstore::tmpl_parse()
{
+ tr1::shared_ptr<vtw_def> def(new vtw_def);
+ vtw_def *_def = def.get();
b_fs::path tp = tmpl_path / C_DEF_NAME;
- bool ret = (b_fs_exists(tp) && b_fs_is_regular(tp)
- && parse_def(&def, tp.file_string().c_str(), 0) == 0);
- return ret;
+ if (_def && b_fs_exists(tp) && b_fs_is_regular(tp)
+ && parse_def(_def, tp.file_string().c_str(), 0) == 0) {
+ // succes
+ return (new Ctemplate(def));
+ }
+ return 0;
}
bool
@@ -905,11 +909,11 @@ UnionfsCstore::cfg_node_changed()
* be only one operation on the path).
*/
bool
-UnionfsCstore::marked_committed(const vtw_def& def, bool is_set)
+UnionfsCstore::marked_committed(const Ctemplate *def, bool is_set)
{
b_fs::path cpath = mutable_cfg_path;
string com_str = cpath.file_string() + "/";
- if (def.is_value && !def.tag) {
+ if (def->isLeafValue()) {
// path includes leaf value. construct the right string.
string val = _unescape_path_name(cpath.filename());
cpath = cpath.parent_path();
@@ -917,7 +921,7 @@ UnionfsCstore::marked_committed(const vtw_def& def, bool is_set)
* single-value nodes but not for multi-value nodes for some
* reason. the following match current behavior.
*/
- if (!def.multi) {
+ if (!def->isMulti()) {
val = _escape_path_name(val);
}
com_str = cpath.file_string() + "/value:" + val;
@@ -927,7 +931,7 @@ UnionfsCstore::marked_committed(const vtw_def& def, bool is_set)
}
bool
-UnionfsCstore::validate_val_impl(vtw_def *def, char *value)
+UnionfsCstore::validate_val_impl(const Ctemplate *def, char *value)
{
/* XXX filesystem paths/accesses are completely embedded in var ref lib.
* for now, treat the lib as a unionfs-specific implementation.
@@ -936,7 +940,7 @@ UnionfsCstore::validate_val_impl(vtw_def *def, char *value)
* processing. this is a global var in cli_new.c.
*/
var_ref_handle = (void *) this;
- bool ret = validate_value(def, value);
+ bool ret = validate_value(def->getDef(), value);
var_ref_handle = NULL;
return ret;
}