Use string split function in syntool #4933

This commit is contained in:
Jerry (Xinyu Hou) 2015-10-29 15:47:10 -07:00
parent 942dcabdcd
commit b4563a42c4
1 changed files with 51 additions and 32 deletions

View File

@ -152,31 +152,35 @@ ToolApp::loginAuth()
String credentials; String credentials;
std::cin >> credentials; std::cin >> credentials;
size_t separator1 = credentials.find(':'); std::vector<String> parts = synergy::string::splitString(credentials, ':');
size_t separator2 = credentials.find(':', separator1 + 1); int count = parts.size();
size_t separator3 = credentials.find(':', separator2 + 1);
String email = credentials.substr(0, separator1); if (count == 3 || count == 4) {
String password = credentials.substr(separator1 + 1, separator2 - separator1 - 1); String email = parts[0];
String macHash; String password = parts[1];
String os; String macHash = parts[2];
if (separator3 != String::npos) { String os;
macHash = credentials.substr(separator2 + 1, separator3 - separator2 - 1);
os = credentials.substr(separator3 + 1, credentials.length() - separator3 - 1); if (count == 4) {
os = parts[3];
}
else {
os = ARCH->getOSName();
}
std::stringstream ss;
ss << JSON_URL << "auth/";
ss << "?email=" << ARCH->internet().urlEncode(email);
ss << "&password=" << password;
ss << "&mac=" << macHash;
ss << "&os=" << ARCH->internet().urlEncode(os);
ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName());
std::cout << ARCH->internet().get(ss.str()) << std::endl;
} }
else { else {
macHash = credentials.substr(separator2 + 1, credentials.length() - separator2 - 1); throw XSynergy("Invalid credentials.");
os = ARCH->getOSName();
} }
std::stringstream ss;
ss << JSON_URL << "auth/";
ss << "?email=" << ARCH->internet().urlEncode(email);
ss << "&password=" << password;
ss << "&mac=" << macHash;
ss << "&os=" << ARCH->internet().urlEncode(os);
ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName());
std::cout << ARCH->internet().get(ss.str()) << std::endl;
} }
void void
@ -203,16 +207,31 @@ ToolApp::notifyActivation()
String info; String info;
std::cin >> info; std::cin >> info;
size_t separator = info.find(':'); std::vector<String> parts = synergy::string::splitString(info, ':');
String action = info.substr(0, separator); int count = parts.size();
String macHash = info.substr(separator + 1, info.length());
std::stringstream ss; if (count == 2 || count == 3) {
ss << JSON_URL << "notify/"; String action = parts[0];
ss << "?action=" << action; String macHash = parts[1];
ss << "&mac=" << macHash; String os;
ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName());
ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName());
std::cout << ARCH->internet().get(ss.str()) << std::endl; if (count == 3) {
os = parts[2];
}
else {
os = ARCH->getOSName();
}
std::stringstream ss;
ss << JSON_URL << "notify/";
ss << "?action=" << action;
ss << "&mac=" << macHash;
ss << "&os=" << ARCH->internet().urlEncode(ARCH->getOSName());
ss << "&arch=" << ARCH->internet().urlEncode(ARCH->getPlatformName());
std::cout << ARCH->internet().get(ss.str()) << std::endl;
}
else {
throw XSynergy("Invalid credentials.");
}
} }