summaryrefslogtreecommitdiff
path: root/src/cstore
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2010-07-28 19:08:43 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2010-07-28 19:08:43 -0700
commita56723cbb6424e1d49289efceeb9c251eed324bb (patch)
tree79f97da29cc8e1aa972ec978703622a61a34ae5b /src/cstore
parentde31f1befb8a92cecadd0c716f7313bd578511f9 (diff)
downloadvyatta-cfg-a56723cbb6424e1d49289efceeb9c251eed324bb.tar.gz
vyatta-cfg-a56723cbb6424e1d49289efceeb9c251eed324bb.zip
add cstore-specific header file
Diffstat (limited to 'src/cstore')
-rw-r--r--src/cstore/cstore-c.cpp11
-rw-r--r--src/cstore/cstore-c.h7
-rw-r--r--src/cstore/cstore-varref.cpp8
-rw-r--r--src/cstore/cstore-varref.hpp2
-rw-r--r--src/cstore/cstore.cpp37
-rw-r--r--src/cstore/cstore.hpp8
-rw-r--r--src/cstore/unionfs/cstore-unionfs.cpp19
-rw-r--r--src/cstore/unionfs/cstore-unionfs.hpp13
8 files changed, 47 insertions, 58 deletions
diff --git a/src/cstore/cstore-c.cpp b/src/cstore/cstore-c.cpp
index 3215707..0e25b3c 100644
--- a/src/cstore/cstore-c.cpp
+++ b/src/cstore/cstore-c.cpp
@@ -18,8 +18,8 @@
#include <vector>
#include <string>
-#include "cstore-c.h"
-#include "cstore/unionfs/cstore-unionfs.hpp"
+#include <cstore/cstore-c.h>
+#include <cstore/unionfs/cstore-unionfs.hpp>
void *
cstore_init(void)
@@ -80,12 +80,13 @@ cstore_cfg_path_exists(void *handle, const char *path_comps[], int num_comps)
}
int
-cstore_get_var_ref(void *handle, const char *ref_str, clind_val *cval,
- int from_active)
+cstore_get_var_ref(void *handle, const char *ref_str, vtw_type_e *type,
+ char **val, int from_active)
{
if (handle) {
Cstore *cs = (Cstore *) handle;
- return (cs->getVarRef(ref_str, *cval, from_active) ? 1 : 0);
+ *val = cs->getVarRef(ref_str, *type, from_active);
+ return (*val ? 1 : 0);
}
return 0;
}
diff --git a/src/cstore/cstore-c.h b/src/cstore/cstore-c.h
index e664f95..c2c5fa0 100644
--- a/src/cstore/cstore-c.h
+++ b/src/cstore/cstore-c.h
@@ -20,8 +20,7 @@
extern "C" {
#endif
-#include <cli_val.h>
-#include <cli_val_engine.h>
+#include <cli_cstore.h>
void *cstore_init(void);
void cstore_free(void *handle);
@@ -39,8 +38,8 @@ int cstore_cfg_path_deactivated(void *handle, const char *path_comps[],
* during cstore operations since they operate on "current" paths constructed
* by the operations.
*/
-int cstore_get_var_ref(void *handle, const char *ref_str, clind_val *cval,
- int from_active);
+int cstore_get_var_ref(void *handle, const char *ref_str, vtw_type_e *type,
+ char **val, int from_active);
int cstore_set_var_ref(void *handle, const char *ref_str, const char *value,
int to_active);
diff --git a/src/cstore/cstore-varref.cpp b/src/cstore/cstore-varref.cpp
index 6d71307..46950fa 100644
--- a/src/cstore/cstore-varref.cpp
+++ b/src/cstore/cstore-varref.cpp
@@ -19,12 +19,8 @@
#include <string>
#include <algorithm>
-#include "cstore-varref.hpp"
-
-extern "C" {
-#include "cli_val.h"
-#include "cli_objects.h"
-}
+#include <cli_cstore.h>
+#include <cstore/cstore-varref.hpp>
using namespace std;
diff --git a/src/cstore/cstore-varref.hpp b/src/cstore/cstore-varref.hpp
index 1fc1d52..7ab523f 100644
--- a/src/cstore/cstore-varref.hpp
+++ b/src/cstore/cstore-varref.hpp
@@ -20,7 +20,7 @@
#include <string>
#include <map>
-#include "cstore.hpp"
+#include <cstore/cstore.hpp>
using namespace std;
diff --git a/src/cstore/cstore.cpp b/src/cstore/cstore.cpp
index 31c896a..e97ea2c 100644
--- a/src/cstore/cstore.cpp
+++ b/src/cstore/cstore.cpp
@@ -25,12 +25,9 @@
#include <algorithm>
#include <sstream>
-extern "C" {
-#include "cli_val.h"
-}
-
-#include "cstore.hpp"
-#include "cstore-varref.hpp"
+#include <cli_cstore.h>
+#include <cstore/cstore.hpp>
+#include <cstore/cstore-varref.hpp>
////// constants
@@ -57,8 +54,9 @@ const string Cstore::C_ENV_SHAPI_COMP_HELP = "_cli_shell_api_comp_help";
const string Cstore::C_ENV_SHAPI_HELP_ITEMS = "_cli_shell_api_hitems";
const string Cstore::C_ENV_SHAPI_HELP_STRS = "_cli_shell_api_hstrs";
-//// dirs
+//// dirs/files
const string Cstore::C_ENUM_SCRIPT_DIR = "/opt/vyatta/share/enumeration";
+const string Cstore::C_LOGFILE_STDOUT = "/tmp/cfg-stdout.log";
////// constructors/destructors
/* this constructor just returns the generic environment string,
@@ -1691,25 +1689,24 @@ Cstore::cfgPathGetEffectiveValues(const vector<string>& path_comps,
/* get the value string that corresponds to specified variable ref string.
* ref_str: var ref string (e.g., "./cost/@").
- * cval: (output) contains the resulting string.
+ * type: (output) the node type.
* from_active: if true, value string should come from "active config".
* otherwise from "working config".
- * return true if successful. otherwise return false.
+ * return a pointer to the value string if successful (caller must free).
+ * otherwise return NULL.
*/
-bool
-Cstore::getVarRef(const string& ref_str, clind_val& cval, bool from_active)
+char *
+Cstore::getVarRef(const string& ref_str, vtw_type_e& type, bool from_active)
{
- bool ret = true;
+ char *ret = NULL;
SAVE_PATHS;
VarRef vref(this, ref_str, from_active);
string val;
- vtw_type_e type;
- if (!vref.getValue(val, type)) {
- ret = false;
- } else {
- cval.val_type = type;
+ vtw_type_e t;
+ if (vref.getValue(val, t)) {
+ type = t;
// follow original implementation. caller is supposed to free this.
- cval.value = strdup(val.c_str());
+ ret = strdup(val.c_str());
}
RESTORE_PATHS;
return ret;
@@ -1855,8 +1852,8 @@ Cstore::output_internal(const char *fmt, ...)
int fdout = -1;
FILE *fout = NULL;
do {
- // XXX for now use the constant from cli_val.h
- if ((fdout = open(LOGFILE_STDOUT, O_WRONLY | O_CREAT, 0660)) == -1) {
+ if ((fdout = open(C_LOGFILE_STDOUT.c_str(),
+ O_WRONLY | O_CREAT, 0660)) == -1) {
break;
}
if (lseek(fdout, 0, SEEK_END) == ((off_t) -1)) {
diff --git a/src/cstore/cstore.hpp b/src/cstore/cstore.hpp
index f6a4215..1d4ffe2 100644
--- a/src/cstore/cstore.hpp
+++ b/src/cstore/cstore.hpp
@@ -20,10 +20,7 @@
#include <string>
#include <map>
-extern "C" {
-#include <cli_val.h>
-#include <cli_val_engine.h>
-}
+#include <cli_cstore.h>
#define exit_internal(fmt, args...) do \
{ \
@@ -65,6 +62,7 @@ public:
static const string C_ENV_SHAPI_HELP_STRS;
static const string C_ENUM_SCRIPT_DIR;
+ static const string C_LOGFILE_STDOUT;
static const size_t MAX_CMD_OUTPUT_SIZE = 4096;
@@ -245,7 +243,7 @@ public:
* the limitations of the original CLI library implementation and MUST NOT
* be used by anyone other than the original CLI library.
*/
- bool getVarRef(const string& ref_str, clind_val& cval, bool from_active);
+ char *getVarRef(const string& ref_str, vtw_type_e& type, bool from_active);
bool setVarRef(const string& ref_str, const string& value, bool to_active);
protected:
diff --git a/src/cstore/unionfs/cstore-unionfs.cpp b/src/cstore/unionfs/cstore-unionfs.cpp
index 977a597..6e6e5de 100644
--- a/src/cstore/unionfs/cstore-unionfs.cpp
+++ b/src/cstore/unionfs/cstore-unionfs.cpp
@@ -24,12 +24,8 @@
#include <errno.h>
#include <sys/mount.h>
-extern "C" {
-#include "cli_val.h"
-#include "cli_objects.h"
-}
-
-#include "cstore-unionfs.hpp"
+#include <cli_cstore.h>
+#include <cstore/unionfs/cstore-unionfs.hpp>
////// constants
@@ -61,6 +57,9 @@ const string UnionfsCstore::C_MARKER_CHANGED = ".modified";
const string UnionfsCstore::C_MARKER_UNSAVED = ".unsaved";
const string UnionfsCstore::C_COMMITTED_MARKER_FILE = "/tmp/.changes";
const string UnionfsCstore::C_COMMENT_FILE = ".comment";
+const string UnionfsCstore::C_TAG_NAME = "node.tag";
+const string UnionfsCstore::C_VAL_NAME = "node.val";
+const string UnionfsCstore::C_DEF_NAME = "node.def";
////// static
@@ -414,9 +413,9 @@ UnionfsCstore::tmpl_node_exists()
bool
UnionfsCstore::tmpl_parse(vtw_def& def)
{
- push_tmpl_path(DEF_NAME);
+ push_tmpl_path(C_DEF_NAME);
bool ret = (b_fs::exists(tmpl_path) && b_fs::is_regular(tmpl_path)
- && parse_def(&def, tmpl_path.file_string().c_str(), FALSE) == 0);
+ && parse_def(&def, tmpl_path.file_string().c_str(), 0) == 0);
pop_tmpl_path();
return ret;
}
@@ -490,8 +489,8 @@ UnionfsCstore::get_all_child_node_names_impl(vector<string>& cnodes,
* node.val
* def
*/
- if (b_fs::exists(p / VAL_NAME) && b_fs::is_regular(p / VAL_NAME)) {
- cnodes.push_back(VAL_NAME);
+ if (b_fs::exists(p / C_VAL_NAME) && b_fs::is_regular(p / C_VAL_NAME)) {
+ cnodes.push_back(C_VAL_NAME);
}
if (b_fs::exists(p / C_MARKER_DEF_VALUE)
&& b_fs::is_regular(p / C_MARKER_DEF_VALUE)) {
diff --git a/src/cstore/unionfs/cstore-unionfs.hpp b/src/cstore/unionfs/cstore-unionfs.hpp
index 357e307..dd44d9a 100644
--- a/src/cstore/unionfs/cstore-unionfs.hpp
+++ b/src/cstore/unionfs/cstore-unionfs.hpp
@@ -26,13 +26,9 @@
#include <boost/filesystem.hpp>
+#include <cli_cstore.h>
#include <cstore/cstore.hpp>
-extern "C" {
-#include <cli_val.h>
-#include <cli_val_engine.h>
-}
-
namespace b_fs = boost::filesystem;
class UnionfsCstore : public Cstore {
@@ -71,6 +67,9 @@ private:
static const string C_MARKER_UNSAVED;
static const string C_COMMITTED_MARKER_FILE;
static const string C_COMMENT_FILE;
+ static const string C_TAG_NAME;
+ static const string C_VAL_NAME;
+ static const string C_DEF_NAME;
static const size_t MAX_FILE_READ_SIZE = 8192;
@@ -93,7 +92,7 @@ private:
push_path(tmpl_path, new_comp);
};
void push_tmpl_path_tag() {
- push_tmpl_path(TAG_NAME);
+ push_tmpl_path(C_TAG_NAME);
};
string pop_tmpl_path() {
return pop_path(tmpl_path);
@@ -102,7 +101,7 @@ private:
push_path(mutable_cfg_path, new_comp);
};
void push_cfg_path_val() {
- push_cfg_path(VAL_NAME);
+ push_cfg_path(C_VAL_NAME);
};
string pop_cfg_path() {
return pop_path(mutable_cfg_path);