Skip to content

Commit

Permalink
Fix error in parsing ShadowsocksR configurations
Browse files Browse the repository at this point in the history
Fix code style.
  • Loading branch information
tindy2013 committed Oct 4, 2021
1 parent a653e3a commit 9983e9e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 42 deletions.
11 changes: 3 additions & 8 deletions src/parser/subparser.cpp
Expand Up @@ -528,7 +528,7 @@ void explodeSSConf(std::string content, std::vector<Proxy> &nodes)
void explodeSSR(std::string ssr, Proxy &node)
{
std::string strobfs;
std::string remarks, group, server, port, method, password, protocol, protoparam, obfs, obfsparam, remarks_base64;
std::string remarks, group, server, port, method, password, protocol, protoparam, obfs, obfsparam;
ssr = replaceAllDistinct(ssr.substr(6), "\r", "");
ssr = urlSafeBase64Decode(ssr);
if(strFind(ssr, "/?"))
Expand All @@ -537,7 +537,6 @@ void explodeSSR(std::string ssr, Proxy &node)
ssr = ssr.substr(0, ssr.find("/?"));
group = urlSafeBase64Decode(getUrlArg(strobfs, "group"));
remarks = urlSafeBase64Decode(getUrlArg(strobfs, "remarks"));
remarks_base64 = urlSafeBase64Reverse(getUrlArg(strobfs, "remarks"));
obfsparam = regReplace(urlSafeBase64Decode(getUrlArg(strobfs, "obfsparam")), "\\s", "");
protoparam = regReplace(urlSafeBase64Decode(getUrlArg(strobfs, "protoparam")), "\\s", "");
}
Expand All @@ -551,10 +550,7 @@ void explodeSSR(std::string ssr, Proxy &node)
if(group.empty())
group = SSR_DEFAULT_GROUP;
if(remarks.empty())
{
remarks = server + ":" + port;
remarks_base64 = base64Encode(remarks);
}

if(find(ss_ciphers.begin(), ss_ciphers.end(), method) != ss_ciphers.end() && (obfs.empty() || obfs == "plain") && (protocol.empty() || protocol == "origin"))
{
Expand All @@ -570,7 +566,7 @@ void explodeSSRConf(std::string content, std::vector<Proxy> &nodes)
{
Proxy node;
Document json;
std::string remarks, remarks_base64, group, server, port, method, password, protocol, protoparam, obfs, obfsparam, plugin, pluginopts;
std::string remarks, group, server, port, method, password, protocol, protoparam, obfs, obfsparam, plugin, pluginopts;
int index = nodes.size();

json.Parse(content.data());
Expand Down Expand Up @@ -615,7 +611,6 @@ void explodeSSRConf(std::string content, std::vector<Proxy> &nodes)
if(remarks.empty())
remarks = server + ":" + port;

remarks_base64 = GetMember(json["configs"][i], "remarks_base64"); // electron-ssr does not contain this field
password = GetMember(json["configs"][i], "password");
method = GetMember(json["configs"][i], "method");

Expand All @@ -624,7 +619,7 @@ void explodeSSRConf(std::string content, std::vector<Proxy> &nodes)
obfs = GetMember(json["configs"][i], "obfs");
obfsparam = GetMember(json["configs"][i], "obfsparam");

ssrConstruct(node, group, remarks, remarks_base64, server, port, protocol, method, obfs, password, obfsparam, protoparam);
ssrConstruct(node, group, remarks, server, port, protocol, method, obfs, password, obfsparam, protoparam);
node.Id = index;
nodes.emplace_back(std::move(node));
node = Proxy();
Expand Down
2 changes: 1 addition & 1 deletion src/script/cron.cpp
Expand Up @@ -37,7 +37,7 @@ struct script_info

int timeout_checker(JSRuntime *rt, void *opaque)
{
script_info info = *((script_info*)opaque);
script_info info = *static_cast<script_info*>(opaque);
if(info.timeout != 0 && time(NULL) >= info.begin_time + info.timeout) /// timeout reached
{
writeLog(0, "Script '" + info.name + "' has exceeded timeout " + std::to_string(info.timeout) + ", terminate now.", LOG_LEVEL_WARNING);
Expand Down
8 changes: 3 additions & 5 deletions src/script/script_quickjs.cpp
Expand Up @@ -227,7 +227,7 @@ class qjs_fetch_Request
qjs_fetch_Headers headers;
std::string cookies;
std::string postdata;
qjs_fetch_Request(const std::string &url) : url(url) {}
explicit qjs_fetch_Request(const std::string &url) : url(url) {}
};

class qjs_fetch_Response
Expand Down Expand Up @@ -390,14 +390,12 @@ void script_runtime_init(qjs::Runtime &runtime)
JS_SetModuleLoaderFunc(runtime.rt, nullptr, js_module_loader, nullptr);
}

int ShowMsgbox(std::string title, std::string content, uint16_t type = 0)
int ShowMsgbox(const std::string &title, std::string content, uint16_t type = 0)
{
#ifdef _WIN32
if(!type)
type = MB_ICONINFORMATION;
title = utf8ToACP(title);
content = utf8ToACP(content);
return MessageBoxA(NULL, content.c_str(), title.c_str(), type);
return MessageBoxA(NULL, utf8ToACP(content).c_str(), utf8ToACP(title).c_str(), type);
#else
return -1;
#endif // _WIN32
Expand Down
27 changes: 0 additions & 27 deletions src/utils/codepage.cpp
Expand Up @@ -71,30 +71,3 @@ std::string utf8ToACP(const std::string &str_src)
return str_src;
#endif
}

#ifdef _WIN32
// std::string to wstring
void stringToWstring(std::wstring& szDst, const std::string &str)
{
std::string temp = str;
int len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)temp.c_str(), -1, NULL,0);
wchar_t* wszUtf8 = new wchar_t[len + 1];
memset(wszUtf8, 0, len * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)temp.c_str(), -1, (LPWSTR)wszUtf8, len);
szDst = wszUtf8;
//std::wstring r = wszUtf8;
delete[] wszUtf8;
}

std::string wstringToString(LPWSTR str)
{
std::string result;
size_t srclen = wcslen(str);
size_t len = WideCharToMultiByte(CP_ACP, 0, str, srclen, 0, 0, 0, 0);
result.resize(len);
WideCharToMultiByte(CP_ACP, 0, str, srclen, result.data(), len, 0, 0);
return result;
}
#else
/* Unimplemented: std::codecvt_utf8 */
#endif // _WIN32
3 changes: 2 additions & 1 deletion src/utils/md5/md5.cpp
Expand Up @@ -391,7 +391,8 @@ namespace md5 {
message_length[0] = 0;
message_length[1] = 0;
stored_size = 0;
memset(&stored, 0, BLOCK_SIZE * 2);
memset(stored, 0, BLOCK_SIZE * 2);
memset(signature, 0, MD5_SIZE);

finished = false;
}
Expand Down

0 comments on commit 9983e9e

Please sign in to comment.