diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2011-04-15 17:23:28 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2011-04-15 17:23:28 -0700 |
commit | 37657313d95fa7735e52328b5427caf0fd3db03d (patch) | |
tree | be970e0010a100cc44627038ba1169134406d708 | |
parent | 74b730a5a95abadba47bd05e816ed8c93abe9ca2 (diff) | |
download | vyatta-cfg-37657313d95fa7735e52328b5427caf0fd3db03d.tar.gz vyatta-cfg-37657313d95fa7735e52328b5427caf0fd3db03d.zip |
add validation to config file API
-rw-r--r-- | src/cli_shell_api.cpp | 29 |
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); |