Bug fixes

Fix support for exporting SSD-Android compatible SSD subscriptions.
Fix format error in exporting SIP002 subscriptions.
This commit is contained in:
Tindy X
2019-12-31 15:46:28 +08:00
parent c38c1b4cf5
commit 3b4ad47dae
3 changed files with 36 additions and 5 deletions

View File

@@ -935,3 +935,33 @@ std::string getFormData(const std::string &raw_data)
}
return file;
}
std::string UTF8ToCodePoint(std::string data)
{
std::stringstream ss;
int charcode = 0;
for(std::string::size_type i = 0; i < data.size(); i++)
{
charcode = data[i] & 0xff;
if((charcode >> 7) == 0)
{
ss<<data[i];
}
else if((charcode >> 5) == 6)
{
ss<<"\\u"<<std::hex<<((data[i + 1] & 0x3f) | (data[i] & 0x1f) << 6);
i++;
}
else if((charcode >> 4) == 14)
{
ss<<"\\u"<<std::hex<<((data[i + 2] & 0x3f) | (data[i + 1] & 0x3f) << 6 | (data[i] & 0xf) << 12);
i += 2;
}
else if((charcode >> 3) == 30)
{
ss<<"\\u"<<std::hex<<((data[i + 3] & 0x3f) | (data[i + 2] & 0x3f) << 6 | (data[i + 1] & 0x3f) << 12 | (data[i] & 0x7) << 18);
i += 3;
}
}
return ss.str();
}

View File

@@ -53,6 +53,7 @@ void removeUTF8BOM(std::string &data);
int shortAssemble(unsigned short num_a, unsigned short num_b);
void shortDisassemble(int source, unsigned short &num_a, unsigned short &num_b);
int to_int(std::string &s, int def_vaule = 0);
std::string UTF8ToCodePoint(std::string data);
std::string fileGet(std::string path, bool binary = true);
int fileWrite(std::string path, std::string content, bool overwrite);

View File

@@ -954,7 +954,7 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
switch(x.linkType)
{
case SPEEDTEST_MESSAGE_FOUNDSS:
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password + "@" + hostname + ":" + port);
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password) + "@" + hostname + ":" + port;
if(plugin.size() && pluginopts.size())
{
proxyStr += "/?plugin=" + UrlEncode(plugin + ";" +pluginopts);
@@ -963,7 +963,7 @@ std::string netchToSS(std::vector<nodeInfo> &nodes, extra_settings &ext)
break;
case SPEEDTEST_MESSAGE_FOUNDSSR:
if(std::count(ss_ciphers.begin(), ss_ciphers.end(), method) > 0 && protocol == "origin" && obfs == "plain")
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password + "@" + hostname + ":" + port) + "#" + UrlEncode(remark);
proxyStr = "ss://" + urlsafe_base64_encode(method + ":" + password) + "@" + hostname + ":" + port + "#" + UrlEncode(remark);
break;
default:
continue;
@@ -1317,7 +1317,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
{
json.Parse(x.proxyStr.data());
remark = x.remarks;
remark = "\"" + replace_all_distinct(UTF8ToCodePoint(x.remarks), "\\u1f1", "\\ud83c\\udd") + "\"";
hostname = GetMember(json, "Hostname");
port = (unsigned short)stoi(GetMember(json, "Port"));
password = GetMember(json, "Password");
@@ -1348,7 +1348,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
writer.Key("plugin_options");
writer.String(pluginopts.data());
writer.Key("remarks");
writer.String(remark.data());
writer.RawValue(remark.data(), remark.size(), rapidjson::Type::kStringType);
writer.Key("id");
writer.Int(index);
writer.EndObject();
@@ -1367,7 +1367,7 @@ std::string netchToSSD(std::vector<nodeInfo> &nodes, std::string &group, extra_s
writer.String(password.data());
writer.String(pluginopts.data());
writer.Key("remarks");
writer.String(remark.data());
writer.RawValue(remark.data(), remark.size(), rapidjson::Type::kStringType);
writer.Key("id");
writer.Int(index);
writer.EndObject();