summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@gmail.com>2016-11-18 15:49:28 -0800
committerAdam Ierymenko <adam.ierymenko@gmail.com>2016-11-18 15:49:28 -0800
commitccdd4ffda70a35219fae1cdce1306f3d4ebd8dc9 (patch)
treedabf33f54a180293cd44961a9b9b557fe8fae4de
parent673c0c811ea443c217b3a4ca17eeaed3ab596501 (diff)
downloadinfinitytier-ccdd4ffda70a35219fae1cdce1306f3d4ebd8dc9.tar.gz
infinitytier-ccdd4ffda70a35219fae1cdce1306f3d4ebd8dc9.zip
Move split() to OSUtils since it is not used in core.
-rw-r--r--controller/EmbeddedNetworkController.cpp2
-rw-r--r--controller/JSONDB.cpp2
-rw-r--r--node/Utils.cpp44
-rw-r--r--node/Utils.hpp11
-rw-r--r--one.cpp4
-rw-r--r--osdep/OSUtils.cpp44
-rw-r--r--osdep/OSUtils.hpp11
-rw-r--r--service/ControlPlane.cpp4
8 files changed, 61 insertions, 61 deletions
diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp
index 74937dd8..974936e4 100644
--- a/controller/EmbeddedNetworkController.cpp
+++ b/controller/EmbeddedNetworkController.cpp
@@ -889,7 +889,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
json &v6m = b["v6AssignMode"];
if (!nv6m.is_object()) nv6m = json::object();
if (v6m.is_string()) { // backward compatibility
- std::vector<std::string> v6ms(Utils::split(_jS(v6m,"").c_str(),",","",""));
+ std::vector<std::string> v6ms(OSUtils::split(_jS(v6m,"").c_str(),",","",""));
std::sort(v6ms.begin(),v6ms.end());
v6ms.erase(std::unique(v6ms.begin(),v6ms.end()),v6ms.end());
nv6m["rfc4193"] = false;
diff --git a/controller/JSONDB.cpp b/controller/JSONDB.cpp
index 6adc8a66..a9e9d05b 100644
--- a/controller/JSONDB.cpp
+++ b/controller/JSONDB.cpp
@@ -144,7 +144,7 @@ bool JSONDB::_isValidObjectName(const std::string &n)
std::string JSONDB::_genPath(const std::string &n,bool create)
{
- std::vector<std::string> pt(Utils::split(n.c_str(),"/","",""));
+ std::vector<std::string> pt(OSUtils::split(n.c_str(),"/","",""));
if (pt.size() == 0)
return std::string();
diff --git a/node/Utils.cpp b/node/Utils.cpp
index 9d67fc22..215e3b3e 100644
--- a/node/Utils.cpp
+++ b/node/Utils.cpp
@@ -218,50 +218,6 @@ void Utils::getSecureRandom(void *buf,unsigned int bytes)
s20.encrypt12(buf,buf,bytes);
}
-std::vector<std::string> Utils::split(const char *s,const char *const sep,const char *esc,const char *quot)
-{
- std::vector<std::string> fields;
- std::string buf;
-
- if (!esc)
- esc = "";
- if (!quot)
- quot = "";
-
- bool escapeState = false;
- char quoteState = 0;
- while (*s) {
- if (escapeState) {
- escapeState = false;
- buf.push_back(*s);
- } else if (quoteState) {
- if (*s == quoteState) {
- quoteState = 0;
- fields.push_back(buf);
- buf.clear();
- } else buf.push_back(*s);
- } else {
- const char *quotTmp;
- if (strchr(esc,*s))
- escapeState = true;
- else if ((buf.size() <= 0)&&((quotTmp = strchr(quot,*s))))
- quoteState = *quotTmp;
- else if (strchr(sep,*s)) {
- if (buf.size() > 0) {
- fields.push_back(buf);
- buf.clear();
- } // else skip runs of seperators
- } else buf.push_back(*s);
- }
- ++s;
- }
-
- if (buf.size())
- fields.push_back(buf);
-
- return fields;
-}
-
bool Utils::scopy(char *dest,unsigned int len,const char *src)
{
if (!len)
diff --git a/node/Utils.hpp b/node/Utils.hpp
index cfe56501..48c43da3 100644
--- a/node/Utils.hpp
+++ b/node/Utils.hpp
@@ -112,17 +112,6 @@ public:
static void getSecureRandom(void *buf,unsigned int bytes);
/**
- * 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);
-
- /**
* Tokenize a string (alias for strtok_r or strtok_s depending on platform)
*
* @param str String to split
diff --git a/one.cpp b/one.cpp
index 51cda0c7..3dad2ed9 100644
--- a/one.cpp
+++ b/one.cpp
@@ -696,7 +696,7 @@ static int idtool(int argc,char **argv)
CertificateOfMembership com;
for(int a=3;a<argc;++a) {
- std::vector<std::string> params(Utils::split(argv[a],",","",""));
+ std::vector<std::string> params(OSUtils::split(argv[a],",","",""));
if (params.size() == 3) {
uint64_t qId = Utils::hexStrToU64(params[0].c_str());
uint64_t qValue = Utils::hexStrToU64(params[1].c_str());
@@ -1084,7 +1084,7 @@ int main(int argc,char **argv)
fprintf(stderr,"%s: no home path specified and no platform default available" ZT_EOL_S,argv[0]);
return 1;
} else {
- std::vector<std::string> hpsp(Utils::split(homeDir.c_str(),ZT_PATH_SEPARATOR_S,"",""));
+ std::vector<std::string> hpsp(OSUtils::split(homeDir.c_str(),ZT_PATH_SEPARATOR_S,"",""));
std::string ptmp;
if (homeDir[0] == ZT_PATH_SEPARATOR)
ptmp.push_back(ZT_PATH_SEPARATOR);
diff --git a/osdep/OSUtils.cpp b/osdep/OSUtils.cpp
index 4a81625b..65704fa3 100644
--- a/osdep/OSUtils.cpp
+++ b/osdep/OSUtils.cpp
@@ -315,6 +315,50 @@ bool OSUtils::writeFile(const char *path,const void *buf,unsigned int len)
return false;
}
+std::vector<std::string> OSUtils::split(const char *s,const char *const sep,const char *esc,const char *quot)
+{
+ std::vector<std::string> fields;
+ std::string buf;
+
+ if (!esc)
+ esc = "";
+ if (!quot)
+ quot = "";
+
+ bool escapeState = false;
+ char quoteState = 0;
+ while (*s) {
+ if (escapeState) {
+ escapeState = false;
+ buf.push_back(*s);
+ } else if (quoteState) {
+ if (*s == quoteState) {
+ quoteState = 0;
+ fields.push_back(buf);
+ buf.clear();
+ } else buf.push_back(*s);
+ } else {
+ const char *quotTmp;
+ if (strchr(esc,*s))
+ escapeState = true;
+ else if ((buf.size() <= 0)&&((quotTmp = strchr(quot,*s))))
+ quoteState = *quotTmp;
+ else if (strchr(sep,*s)) {
+ if (buf.size() > 0) {
+ fields.push_back(buf);
+ buf.clear();
+ } // else skip runs of seperators
+ } else buf.push_back(*s);
+ }
+ ++s;
+ }
+
+ if (buf.size())
+ fields.push_back(buf);
+
+ return fields;
+}
+
std::string OSUtils::platformDefaultHomePath()
{
#ifdef __UNIX_LIKE__
diff --git a/osdep/OSUtils.hpp b/osdep/OSUtils.hpp
index c481780b..c73f0bd3 100644
--- a/osdep/OSUtils.hpp
+++ b/osdep/OSUtils.hpp
@@ -237,6 +237,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
diff --git a/service/ControlPlane.cpp b/service/ControlPlane.cpp
index 150bba1b..07304fc9 100644
--- a/service/ControlPlane.cpp
+++ b/service/ControlPlane.cpp
@@ -266,7 +266,7 @@ unsigned int ControlPlane::handleRequest(
{
char json[8194];
unsigned int scode = 404;
- std::vector<std::string> ps(Utils::split(path.c_str(),"/","",""));
+ std::vector<std::string> ps(OSUtils::split(path.c_str(),"/","",""));
std::map<std::string,std::string> urlArgs;
Mutex::Lock _l(_lock);
@@ -279,7 +279,7 @@ unsigned int ControlPlane::handleRequest(
if (qpos != std::string::npos) {
std::string args(ps[ps.size() - 1].substr(qpos + 1));
ps[ps.size() - 1] = ps[ps.size() - 1].substr(0,qpos);
- std::vector<std::string> asplit(Utils::split(args.c_str(),"&","",""));
+ std::vector<std::string> asplit(OSUtils::split(args.c_str(),"&","",""));
for(std::vector<std::string>::iterator a(asplit.begin());a!=asplit.end();++a) {
std::size_t eqpos = a->find('=');
if (eqpos == std::string::npos)