summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--controller/EmbeddedNetworkController.cpp7
-rw-r--r--controller/JSONDB.cpp22
-rw-r--r--controller/JSONDB.hpp6
-rw-r--r--osdep/OSUtils.cpp37
-rw-r--r--osdep/OSUtils.hpp8
5 files changed, 13 insertions, 67 deletions
diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp
index d2f40b1c..8fbc1cf8 100644
--- a/controller/EmbeddedNetworkController.cpp
+++ b/controller/EmbeddedNetworkController.cpp
@@ -533,11 +533,10 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
Mutex::Lock _l(_db_m);
responseBody = "{";
- std::string pfx(std::string("network/") + nwids + "member/");
- _db.filter(pfx,ZT_NETCONF_DB_CACHE_TTL,[&responseBody](const std::string &n,const json &member) {
- if (member.size() > 0) {
+ _db.filter((std::string("network/") + nwids + "/member/"),ZT_NETCONF_DB_CACHE_TTL,[&responseBody](const std::string &n,const json &member) {
+ if ((member.is_object())&&(member.size() > 0)) {
responseBody.append((responseBody.length() == 1) ? "\"" : ",\"");
- responseBody.append(OSUtils::jsonString(member["id"],""));
+ responseBody.append(OSUtils::jsonString(member["id"],"0"));
responseBody.append("\":");
responseBody.append(OSUtils::jsonString(member["revision"],"0"));
}
diff --git a/controller/JSONDB.cpp b/controller/JSONDB.cpp
index 1277aabb..298ac721 100644
--- a/controller/JSONDB.cpp
+++ b/controller/JSONDB.cpp
@@ -126,22 +126,14 @@ void JSONDB::erase(const std::string &n)
_db.erase(n);
}
-void JSONDB::_reload(const std::string &p)
+void JSONDB::_reload(const std::string &p,const std::string &b)
{
- std::map<std::string,char> l(OSUtils::listDirectoryFull(p.c_str()));
- for(std::map<std::string,char>::iterator li(l.begin());li!=l.end();++li) {
- if (li->second == 'f') {
- // assume p starts with _basePath, which it always does -- will throw otherwise
- std::string n(p.substr(_basePath.length()));
- while ((n.length() > 0)&&(n[0] == ZT_PATH_SEPARATOR)) n = n.substr(1);
- if (ZT_PATH_SEPARATOR != '/') std::replace(n.begin(),n.end(),ZT_PATH_SEPARATOR,'/');
- if ((n.length() > 0)&&(n[n.length() - 1] != '/')) n.push_back('/');
- n.append(li->first);
- if ((n.length() > 5)&&(n.substr(n.length() - 5) == ".json")) {
- this->get(n.substr(0,n.length() - 5),0); // causes load and cache or update
- }
- } else if (li->second == 'd') {
- this->_reload(p + ZT_PATH_SEPARATOR + li->first);
+ std::vector<std::string> dl(OSUtils::listDirectory(p.c_str()));
+ for(std::vector<std::string>::const_iterator di(dl.begin());di!=dl.end();++di) {
+ if ((di->length() > 5)&&(di->substr(di->length() - 5) == ".json")) {
+ this->get(b + di->substr(0,di->length() - 5),0);
+ } else {
+ this->_reload((p + ZT_PATH_SEPARATOR + *di),(b + *di + ZT_PATH_SEPARATOR));
}
}
}
diff --git a/controller/JSONDB.hpp b/controller/JSONDB.hpp
index 5b7c5e50..d2549173 100644
--- a/controller/JSONDB.hpp
+++ b/controller/JSONDB.hpp
@@ -45,13 +45,13 @@ public:
JSONDB(const std::string &basePath) :
_basePath(basePath)
{
- _reload(_basePath);
+ _reload(_basePath,std::string());
}
inline void reload()
{
_db.clear();
- _reload(_basePath);
+ _reload(_basePath,std::string());
}
bool writeRaw(const std::string &n,const std::string &obj);
@@ -95,7 +95,7 @@ public:
inline bool operator!=(const JSONDB &db) const { return (!(*this == db)); }
private:
- void _reload(const std::string &p);
+ void _reload(const std::string &p,const std::string &b);
bool _isValidObjectName(const std::string &n);
std::string _genPath(const std::string &n,bool create);
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp
index 6b95258c..aac6bdd8 100644
--- a/osdep/OSUtils.cpp
+++ b/osdep/OSUtils.cpp
@@ -108,43 +108,6 @@ std::vector<std::string> OSUtils::listDirectory(const char *path)
return r;
}
-std::map<std::string,char> OSUtils::listDirectoryFull(const char *path)
-{
- std::map<std::string,char> r;
-
-#ifdef __WINDOWS__
- HANDLE hFind;
- WIN32_FIND_DATAA ffd;
- if ((hFind = FindFirstFileA((std::string(path) + "\\*").c_str(),&ffd)) != INVALID_HANDLE_VALUE) {
- do {
- if ((strcmp(ffd.cFileName,"."))&&(strcmp(ffd.cFileName,".."))) {
- r[ffd.cFileName] = ((ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) ? 'd' : 'f';
- }
- } while (FindNextFileA(hFind,&ffd));
- FindClose(hFind);
- }
-#else
- struct dirent de;
- struct dirent *dptr;
- DIR *d = opendir(path);
- if (!d)
- return r;
- dptr = (struct dirent *)0;
- for(;;) {
- if (readdir_r(d,&de,&dptr))
- break;
- if (dptr) {
- if ((strcmp(dptr->d_name,"."))&&(strcmp(dptr->d_name,".."))) {
- r[dptr->d_name] = (dptr->d_type == DT_DIR) ? 'd' : 'f';
- }
- } else break;
- }
- closedir(d);
-#endif
-
- return r;
-}
-
long OSUtils::cleanDirectory(const char *path,const uint64_t olderThan)
{
long cleaned = 0;
diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp
index adf1488e..2e007ef2 100644
--- a/osdep/OSUtils.hpp
+++ b/osdep/OSUtils.hpp
@@ -112,14 +112,6 @@ public:
static std::vector<std::string> listDirectory(const char *path);
/**
- * List all contents in a directory
- *
- * @param path Path to list
- * @return Names of things and types, currently just 'f' and 'd'
- */
- static std::map<std::string,char> listDirectoryFull(const char *path);
-
- /**
* Clean a directory of files whose last modified time is older than this
*
* This ignores directories, symbolic links, and other special files.