summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2011-04-15 17:23:28 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2011-04-15 17:23:28 -0700
commit37657313d95fa7735e52328b5427caf0fd3db03d (patch)
treebe970e0010a100cc44627038ba1169134406d708 /src
parent74b730a5a95abadba47bd05e816ed8c93abe9ca2 (diff)
downloadvyatta-cfg-37657313d95fa7735e52328b5427caf0fd3db03d.tar.gz
vyatta-cfg-37657313d95fa7735e52328b5427caf0fd3db03d.zip
add validation to config file API
Diffstat (limited to 'src')
-rw-r--r--src/cli_shell_api.cpp29
1 files changed, 17 insertions, 12 deletions
diff --git a/src/cli_shell_api.cpp b/src/cli_shell_api.cpp
index a701a71..3ab4996 100644
--- a/src/cli_shell_api.cpp
+++ b/src/cli_shell_api.cpp
@@ -471,6 +471,20 @@ loadFile(Cstore& cstore, const Cpath& args)
}
}
+static cnode::CfgNode *
+_cf_process_args(Cstore& cstore, const Cpath& args, Cpath& path)
+{
+ for (size_t i = 1; i < args.size(); i++) {
+ path.push(args[i]);
+ }
+ cnode::CfgNode *root = cparse::parse_file(args[0], cstore);
+ if (!root) {
+ fprintf(stderr, "Failed to parse config file\n");
+ exit(1);
+ }
+ return root;
+}
+
/* the following "cf" functions form the "config file" shell API, which
* allows shell scripts to "query" the "config" represented by a config
* file in a way similar to how they query the active/working config.
@@ -485,10 +499,7 @@ static void
cfExists(Cstore& cstore, const Cpath& args)
{
Cpath path;
- for (size_t i = 1; i < args.size(); i++) {
- path.push(args[i]);
- }
- cnode::CfgNode *root = cparse::parse_file(args[0], cstore);
+ cnode::CfgNode *root = _cf_process_args(cstore, args, path);
exit(cnode::findCfgNode(root, path) ? 0 : 1);
}
@@ -496,10 +507,7 @@ static void
cfReturnValue(Cstore& cstore, const Cpath& args)
{
Cpath path;
- for (size_t i = 1; i < args.size(); i++) {
- path.push(args[i]);
- }
- cnode::CfgNode *root = cparse::parse_file(args[0], cstore);
+ cnode::CfgNode *root = _cf_process_args(cstore, args, path);
string value;
if (!cnode::getCfgNodeValue(root, path, value)) {
exit(1);
@@ -511,10 +519,7 @@ static void
cfReturnValues(Cstore& cstore, const Cpath& args)
{
Cpath path;
- for (size_t i = 1; i < args.size(); i++) {
- path.push(args[i]);
- }
- cnode::CfgNode *root = cparse::parse_file(args[0], cstore);
+ cnode::CfgNode *root = _cf_process_args(cstore, args, path);
vector<string> values;
if (!cnode::getCfgNodeValues(root, path, values)) {
exit(1);