mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-20 21:43:08 +00:00
Move split() to OSUtils since it is not used in core.
This commit is contained in:
parent
673c0c811e
commit
ccdd4ffda7
@ -889,7 +889,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||||||
json &v6m = b["v6AssignMode"];
|
json &v6m = b["v6AssignMode"];
|
||||||
if (!nv6m.is_object()) nv6m = json::object();
|
if (!nv6m.is_object()) nv6m = json::object();
|
||||||
if (v6m.is_string()) { // backward compatibility
|
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());
|
std::sort(v6ms.begin(),v6ms.end());
|
||||||
v6ms.erase(std::unique(v6ms.begin(),v6ms.end()),v6ms.end());
|
v6ms.erase(std::unique(v6ms.begin(),v6ms.end()),v6ms.end());
|
||||||
nv6m["rfc4193"] = false;
|
nv6m["rfc4193"] = false;
|
||||||
|
@ -144,7 +144,7 @@ bool JSONDB::_isValidObjectName(const std::string &n)
|
|||||||
|
|
||||||
std::string JSONDB::_genPath(const std::string &n,bool create)
|
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)
|
if (pt.size() == 0)
|
||||||
return std::string();
|
return std::string();
|
||||||
|
|
||||||
|
@ -218,50 +218,6 @@ void Utils::getSecureRandom(void *buf,unsigned int bytes)
|
|||||||
s20.encrypt12(buf,buf,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)
|
bool Utils::scopy(char *dest,unsigned int len,const char *src)
|
||||||
{
|
{
|
||||||
if (!len)
|
if (!len)
|
||||||
|
@ -111,17 +111,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
static void getSecureRandom(void *buf,unsigned int bytes);
|
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)
|
* Tokenize a string (alias for strtok_r or strtok_s depending on platform)
|
||||||
*
|
*
|
||||||
|
4
one.cpp
4
one.cpp
@ -696,7 +696,7 @@ static int idtool(int argc,char **argv)
|
|||||||
|
|
||||||
CertificateOfMembership com;
|
CertificateOfMembership com;
|
||||||
for(int a=3;a<argc;++a) {
|
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) {
|
if (params.size() == 3) {
|
||||||
uint64_t qId = Utils::hexStrToU64(params[0].c_str());
|
uint64_t qId = Utils::hexStrToU64(params[0].c_str());
|
||||||
uint64_t qValue = Utils::hexStrToU64(params[1].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]);
|
fprintf(stderr,"%s: no home path specified and no platform default available" ZT_EOL_S,argv[0]);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} 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;
|
std::string ptmp;
|
||||||
if (homeDir[0] == ZT_PATH_SEPARATOR)
|
if (homeDir[0] == ZT_PATH_SEPARATOR)
|
||||||
ptmp.push_back(ZT_PATH_SEPARATOR);
|
ptmp.push_back(ZT_PATH_SEPARATOR);
|
||||||
|
@ -315,6 +315,50 @@ bool OSUtils::writeFile(const char *path,const void *buf,unsigned int len)
|
|||||||
return false;
|
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()
|
std::string OSUtils::platformDefaultHomePath()
|
||||||
{
|
{
|
||||||
#ifdef __UNIX_LIKE__
|
#ifdef __UNIX_LIKE__
|
||||||
|
@ -236,6 +236,17 @@ public:
|
|||||||
*/
|
*/
|
||||||
static bool writeFile(const char *path,const void *buf,unsigned int len);
|
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
|
* Write a block of data to disk, replacing any current file contents
|
||||||
*
|
*
|
||||||
|
@ -266,7 +266,7 @@ unsigned int ControlPlane::handleRequest(
|
|||||||
{
|
{
|
||||||
char json[8194];
|
char json[8194];
|
||||||
unsigned int scode = 404;
|
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;
|
std::map<std::string,std::string> urlArgs;
|
||||||
Mutex::Lock _l(_lock);
|
Mutex::Lock _l(_lock);
|
||||||
|
|
||||||
@ -279,7 +279,7 @@ unsigned int ControlPlane::handleRequest(
|
|||||||
if (qpos != std::string::npos) {
|
if (qpos != std::string::npos) {
|
||||||
std::string args(ps[ps.size() - 1].substr(qpos + 1));
|
std::string args(ps[ps.size() - 1].substr(qpos + 1));
|
||||||
ps[ps.size() - 1] = ps[ps.size() - 1].substr(0,qpos);
|
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) {
|
for(std::vector<std::string>::iterator a(asplit.begin());a!=asplit.end();++a) {
|
||||||
std::size_t eqpos = a->find('=');
|
std::size_t eqpos = a->find('=');
|
||||||
if (eqpos == std::string::npos)
|
if (eqpos == std::string::npos)
|
||||||
|
Loading…
Reference in New Issue
Block a user