summaryrefslogtreecommitdiff
path: root/osdep/OSUtils.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/OSUtils.hpp')
-rw-r--r--osdep/OSUtils.hpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp
index 4f74344f..adf1488e 100644
--- a/osdep/OSUtils.hpp
+++ b/osdep/OSUtils.hpp
@@ -45,6 +45,8 @@
#include <arpa/inet.h>
#endif
+#include "../ext/json/json.hpp"
+
namespace ZeroTier {
/**
@@ -110,12 +112,22 @@ public:
static std::vector<std::string> listDirectory(const char *path);
/**
- * List a directory's subdirectories
+ * List all contents in a directory
*
* @param path Path to list
- * @return Names of subdirectories (without path prepended)
+ * @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.
+ *
+ * @param olderThan Last modified older than timestamp (ms since epoch)
+ * @return Number of cleaned files or negative on fatal error
*/
- static std::vector<std::string> listSubdirectories(const char *path);
+ static long cleanDirectory(const char *path,const uint64_t olderThan);
/**
* Delete a directory and all its files and subdirectories recursively
@@ -237,6 +249,17 @@ public:
static bool writeFile(const char *path,const void *buf,unsigned int len);
/**
+ * Split a string by delimiter, with optional escape and quote characters
+ *
+ * @param s String to split
+ * @param sep One or more separators
+ * @param esc Zero or more escape characters
+ * @param quot Zero or more quote characters
+ * @return Vector of tokens
+ */
+ static std::vector<std::string> split(const char *s,const char *const sep,const char *esc,const char *quot);
+
+ /**
* Write a block of data to disk, replacing any current file contents
*
* @param path Path to write
@@ -256,6 +279,13 @@ public:
*/
static std::string platformDefaultHomePath();
+ static nlohmann::json jsonParse(const std::string &buf);
+ static std::string jsonDump(const nlohmann::json &j);
+ static uint64_t jsonInt(const nlohmann::json &jv,const uint64_t dfl);
+ static bool jsonBool(const nlohmann::json &jv,const bool dfl);
+ static std::string jsonString(const nlohmann::json &jv,const char *dfl);
+ static std::string jsonBinFromHex(const nlohmann::json &jv);
+
private:
static const unsigned char TOLOWER_TABLE[256];
};