Skip to content

Commit fa0a9a9

Browse files
committed
Fix parameter reset issue in loop
1 parent 62c8d98 commit fa0a9a9

1 file changed

Lines changed: 86 additions & 88 deletions

File tree

src/parser/subparser.cpp

Lines changed: 86 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,8 @@ void explodeVmessConf(std::string content, std::vector<Proxy> &nodes)
450450
{
451451
Document json;
452452
rapidjson::Value nodejson, settings;
453-
std::string group, ps, add, port, type, id, aid, net, path, host, edge, tls, cipher, subid, sni;
454-
tribool udp, tfo, scv;
455-
int configType;
456453
uint32_t index = nodes.size();
457454
std::map<std::string, std::string> subdata;
458-
std::map<std::string, std::string>::iterator iter;
459455
std::string streamset = "streamSettings", tcpset = "tcpSettings", wsset = "wsSettings";
460456
regGetMatch(content, "((?i)streamsettings)", 2, 0, &streamset);
461457
regGetMatch(content, "((?i)tcpsettings)", 2, 0, &tcpset);
@@ -472,6 +468,8 @@ void explodeVmessConf(std::string content, std::vector<Proxy> &nodes)
472468
{
473469
Proxy node;
474470
nodejson = json["outbounds"][0];
471+
std::string add, port, type, id, aid, net, path, host, edge, tls, cipher, sni;
472+
tribool udp, tfo, scv;
475473
add = GetMember(nodejson["settings"]["vnext"][0], "address");
476474
port = GetMember(nodejson["settings"]["vnext"][0], "port");
477475
if(port == "0")
@@ -541,6 +539,9 @@ void explodeVmessConf(std::string content, std::vector<Proxy> &nodes)
541539
for(uint32_t i = 0; i < json["vmess"].Size(); i++)
542540
{
543541
Proxy node;
542+
std::string group, ps, add, port, type, id, aid, net, path, host, edge, tls, cipher, subid, sni;
543+
tribool udp, tfo, scv;
544+
int configType = 0;
544545
if(json["vmess"][i]["address"].IsNull() || json["vmess"][i]["port"].IsNull() || json["vmess"][i]["id"].IsNull())
545546
continue;
546547

@@ -554,7 +555,7 @@ void explodeVmessConf(std::string content, std::vector<Proxy> &nodes)
554555

555556
if(!subid.empty())
556557
{
557-
iter = subdata.find(subid);
558+
auto iter = subdata.find(subid);
558559
if(iter != subdata.end())
559560
group = iter->second;
560561
}
@@ -673,16 +674,16 @@ void explodeSSD(std::string link, std::vector<Proxy> &nodes)
673674
else
674675
return;
675676

676-
rapidjson::Value singlenode;
677677
for(uint32_t i = 0; i < listCount; i++)
678678
{
679+
rapidjson::Value singlenode;
680+
std::string port = GetMember(jsondata, "port");
681+
std::string method = GetMember(jsondata, "encryption");
682+
std::string password = GetMember(jsondata, "password");
683+
std::string plugin = GetMember(jsondata, "plugin");
684+
std::string pluginopts = GetMember(jsondata, "plugin_options");
685+
std::string server, remarks;
679686
//get default info
680-
port = GetMember(jsondata, "port");
681-
method = GetMember(jsondata, "encryption");
682-
password = GetMember(jsondata, "password");
683-
plugin = GetMember(jsondata, "plugin");
684-
pluginopts = GetMember(jsondata, "plugin_options");
685-
686687
//get server-specific info
687688
switch(listType)
688689
{
@@ -730,19 +731,19 @@ void explodeSSAndroid(std::string ss, std::vector<Proxy> &nodes)
730731
for(uint32_t i = 0; i < json["nodes"].Size(); i++)
731732
{
732733
Proxy node;
733-
server = GetMember(json["nodes"][i], "server");
734+
std::string server = GetMember(json["nodes"][i], "server");
734735
if(server.empty())
735736
continue;
736-
ps = GetMember(json["nodes"][i], "remarks");
737-
port = GetMember(json["nodes"][i], "server_port");
737+
std::string ps = GetMember(json["nodes"][i], "remarks");
738+
std::string port = GetMember(json["nodes"][i], "server_port");
738739
if(port == "0")
739740
continue;
740741
if(ps.empty())
741742
ps = server + ":" + port;
742-
password = GetMember(json["nodes"][i], "password");
743-
method = GetMember(json["nodes"][i], "method");
744-
plugin = GetMember(json["nodes"][i], "plugin");
745-
pluginopts = GetMember(json["nodes"][i], "plugin_opts");
743+
std::string password = GetMember(json["nodes"][i], "password");
744+
std::string method = GetMember(json["nodes"][i], "method");
745+
std::string plugin = GetMember(json["nodes"][i], "plugin");
746+
std::string pluginopts = GetMember(json["nodes"][i], "plugin_opts");
746747

747748
ssConstruct(node, group, ps, server, port, password, method, plugin, pluginopts);
748749
node.Id = index;
@@ -754,7 +755,7 @@ void explodeSSAndroid(std::string ss, std::vector<Proxy> &nodes)
754755
void explodeSSConf(std::string content, std::vector<Proxy> &nodes)
755756
{
756757
Document json;
757-
std::string ps, password, method, server, port, plugin, pluginopts, group = SS_DEFAULT_GROUP;
758+
std::string group = SS_DEFAULT_GROUP;
758759
auto index = nodes.size();
759760

760761
json.Parse(content.data());
@@ -768,18 +769,17 @@ void explodeSSConf(std::string content, std::vector<Proxy> &nodes)
768769
for(uint32_t i = 0; i < json[section].Size(); i++)
769770
{
770771
Proxy node;
771-
ps = GetMember(json[section][i], "remarks");
772-
port = GetMember(json[section][i], "server_port");
772+
std::string ps = GetMember(json[section][i], "remarks");
773+
std::string server = GetMember(json[section][i], "server");
774+
std::string port = GetMember(json[section][i], "server_port");
773775
if(port == "0")
774776
continue;
775777
if(ps.empty())
776778
ps = server + ":" + port;
777-
778-
password = GetMember(json[section][i], "password");
779-
method = GetMember(json[section][i], "method");
780-
server = GetMember(json[section][i], "server");
781-
plugin = GetMember(json[section][i], "plugin");
782-
pluginopts = GetMember(json[section][i], "plugin_opts");
779+
std::string password = GetMember(json[section][i], "password");
780+
std::string method = GetMember(json[section][i], "method");
781+
std::string plugin = GetMember(json[section][i], "plugin");
782+
std::string pluginopts = GetMember(json[section][i], "plugin_opts");
783783

784784
node.Id = index;
785785
ssConstruct(node, group, ps, server, port, password, method, plugin, pluginopts);
@@ -828,7 +828,6 @@ void explodeSSR(std::string ssr, Proxy &node)
828828
void explodeSSRConf(std::string content, std::vector<Proxy> &nodes)
829829
{
830830
Document json;
831-
std::string remarks, group, server, port, method, password, protocol, protoparam, obfs, obfsparam, plugin, pluginopts;
832831
auto index = nodes.size();
833832

834833
json.Parse(content.data());
@@ -838,22 +837,23 @@ void explodeSSRConf(std::string content, std::vector<Proxy> &nodes)
838837
if(json.HasMember("local_port") && json.HasMember("local_address")) //single libev config
839838
{
840839
Proxy node;
841-
server = GetMember(json, "server");
842-
port = GetMember(json, "server_port");
843-
remarks = server + ":" + port;
844-
method = GetMember(json, "method");
845-
obfs = GetMember(json, "obfs");
846-
protocol = GetMember(json, "protocol");
840+
std::string server = GetMember(json, "server");
841+
std::string port = GetMember(json, "server_port");
842+
std::string remarks = server + ":" + port;
843+
std::string method = GetMember(json, "method");
844+
std::string obfs = GetMember(json, "obfs");
845+
std::string protocol = GetMember(json, "protocol");
846+
std::string password = GetMember(json, "password");
847847
if(find(ss_ciphers.begin(), ss_ciphers.end(), method) != ss_ciphers.end() && (obfs.empty() || obfs == "plain") && (protocol.empty() || protocol == "origin"))
848848
{
849-
plugin = GetMember(json, "plugin");
850-
pluginopts = GetMember(json, "plugin_opts");
849+
std::string plugin = GetMember(json, "plugin");
850+
std::string pluginopts = GetMember(json, "plugin_opts");
851851
ssConstruct(node, SS_DEFAULT_GROUP, remarks, server, port, password, method, plugin, pluginopts);
852852
}
853853
else
854854
{
855-
protoparam = GetMember(json, "protocol_param");
856-
obfsparam = GetMember(json, "obfs_param");
855+
std::string protoparam = GetMember(json, "protocol_param");
856+
std::string obfsparam = GetMember(json, "obfs_param");
857857
ssrConstruct(node, SSR_DEFAULT_GROUP, remarks, server, port, protocol, method, obfs, password, obfsparam, protoparam);
858858
}
859859
nodes.emplace_back(std::move(node));
@@ -863,24 +863,24 @@ void explodeSSRConf(std::string content, std::vector<Proxy> &nodes)
863863
for(uint32_t i = 0; i < json["configs"].Size(); i++)
864864
{
865865
Proxy node;
866-
group = GetMember(json["configs"][i], "group");
866+
std::string group = GetMember(json["configs"][i], "group");
867867
if(group.empty())
868868
group = SSR_DEFAULT_GROUP;
869-
remarks = GetMember(json["configs"][i], "remarks");
870-
server = GetMember(json["configs"][i], "server");
871-
port = GetMember(json["configs"][i], "server_port");
869+
std::string remarks = GetMember(json["configs"][i], "remarks");
870+
std::string server = GetMember(json["configs"][i], "server");
871+
std::string port = GetMember(json["configs"][i], "server_port");
872872
if(port == "0")
873873
continue;
874874
if(remarks.empty())
875875
remarks = server + ":" + port;
876876

877-
password = GetMember(json["configs"][i], "password");
878-
method = GetMember(json["configs"][i], "method");
877+
std::string password = GetMember(json["configs"][i], "password");
878+
std::string method = GetMember(json["configs"][i], "method");
879879

880-
protocol = GetMember(json["configs"][i], "protocol");
881-
protoparam = GetMember(json["configs"][i], "protocolparam");
882-
obfs = GetMember(json["configs"][i], "obfs");
883-
obfsparam = GetMember(json["configs"][i], "obfsparam");
880+
std::string protocol = GetMember(json["configs"][i], "protocol");
881+
std::string protoparam = GetMember(json["configs"][i], "protocolparam");
882+
std::string obfs = GetMember(json["configs"][i], "obfs");
883+
std::string obfsparam = GetMember(json["configs"][i], "obfsparam");
884884

885885
ssrConstruct(node, group, remarks, server, port, protocol, method, obfs, password, obfsparam, protoparam);
886886
node.Id = index;
@@ -1219,27 +1219,25 @@ void explodeNetch(std::string netch, Proxy &node)
12191219

12201220
void explodeClash(Node yamlnode, std::vector<Proxy> &nodes)
12211221
{
1222-
std::string proxytype, ps, server, port, cipher, group, password, underlying_proxy; //common
1223-
std::string type = "none", id, aid = "0", net = "tcp", path, host, edge, tls, sni, mode; //vmess/vless
1224-
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host, pluginopts_mux; //ss
1225-
std::string protocol, protoparam, obfs, obfsparam; //ssr
1226-
std::string user; //socks
1227-
std::string ip, ipv6, private_key, public_key, mtu; //wireguard
1228-
std::string ports, obfs_protocol, up, up_speed, down, down_speed, auth, auth_str,/* obfs, sni,*/ fingerprint, ca, ca_str, recv_window_conn, recv_window, disable_mtu_discovery, hop_interval, alpn; //hysteria
1229-
std::string obfs_password, cwnd; //hysteria2
1230-
std::string uuid,/*ip , password*/ heartbeat_interval, disable_sni, reduce_rtt, request_timeout, udp_relay_mode, congestion_controller, max_udp_relay_packet_size, max_open_streams, fast_open; //TUIC
1231-
std::string idle_session_check_interval, idle_session_timeout, min_idle_session;
1232-
std::string flow, xtls, short_id;
1233-
1234-
string_array dns_server;
1235-
tribool udp, tfo, scv;
1236-
Node singleproxy;
12371222
uint32_t index = nodes.size();
12381223
const std::string section = yamlnode["proxies"].IsDefined() ? "proxies" : "Proxy";
12391224
for(uint32_t i = 0; i < yamlnode[section].size(); i++)
12401225
{
12411226
Proxy node;
1242-
singleproxy = yamlnode[section][i];
1227+
Node singleproxy = yamlnode[section][i];
1228+
std::string proxytype, ps, server, port, cipher, group, password, underlying_proxy; //common
1229+
std::string type = "none", id, aid = "0", net = "tcp", path, host, edge, tls, sni, mode; //vmess/vless
1230+
std::string plugin, pluginopts, pluginopts_mode, pluginopts_host, pluginopts_mux; //ss
1231+
std::string protocol, protoparam, obfs, obfsparam; //ssr
1232+
std::string user; //socks/http
1233+
std::string ip, ipv6, private_key, public_key, mtu; //wireguard
1234+
std::string ports, obfs_protocol, up, up_speed, down, down_speed, auth, auth_str, fingerprint, ca, ca_str, recv_window_conn, recv_window, disable_mtu_discovery, hop_interval, alpn; //hysteria
1235+
std::string obfs_password, cwnd; //hysteria2
1236+
std::string uuid, heartbeat_interval, disable_sni, reduce_rtt, request_timeout, udp_relay_mode, congestion_controller, max_udp_relay_packet_size, max_open_streams, fast_open; //TUIC
1237+
std::string idle_session_check_interval, idle_session_timeout, min_idle_session;
1238+
std::string flow, xtls, short_id;
1239+
string_array dns_server;
1240+
tribool udp, tfo, scv;
12431241
singleproxy["type"] >>= proxytype;
12441242
singleproxy["name"] >>= ps;
12451243
singleproxy["server"] >>= server;
@@ -2775,10 +2773,6 @@ bool explodeSurge(std::string surge, std::vector<Proxy> &nodes)
27752773

27762774
void explodeSSTap(std::string sstap, std::vector<Proxy> &nodes)
27772775
{
2778-
std::string configType, group, remarks, server, port;
2779-
std::string cipher;
2780-
std::string user, pass;
2781-
std::string protocol, protoparam, obfs, obfsparam;
27822776
Document json;
27832777
uint32_t index = nodes.size();
27842778
json.Parse(sstap.data());
@@ -2788,37 +2782,41 @@ void explodeSSTap(std::string sstap, std::vector<Proxy> &nodes)
27882782
for(uint32_t i = 0; i < json["configs"].Size(); i++)
27892783
{
27902784
Proxy node;
2791-
json["configs"][i]["group"] >> group;
2792-
json["configs"][i]["remarks"] >> remarks;
2793-
json["configs"][i]["server"] >> server;
2794-
port = GetMember(json["configs"][i], "server_port");
2785+
std::string group = GetMember(json["configs"][i], "group");
2786+
std::string remarks = GetMember(json["configs"][i], "remarks");
2787+
std::string server = GetMember(json["configs"][i], "server");
2788+
std::string port = GetMember(json["configs"][i], "server_port");
27952789
if(port == "0")
27962790
continue;
27972791

27982792
if(remarks.empty())
27992793
remarks = server + ":" + port;
28002794

2801-
json["configs"][i]["password"] >> pass;
2802-
json["configs"][i]["type"] >> configType;
2795+
std::string pass = GetMember(json["configs"][i], "password");
2796+
std::string configType = GetMember(json["configs"][i], "type");
28032797
switch(to_int(configType, 0))
28042798
{
28052799
case 5: //socks 5
2806-
json["configs"][i]["username"] >> user;
2807-
socksConstruct(node, group, remarks, server, port, user, pass);
2808-
break;
2809-
case 6: //ss/ssr
2810-
json["configs"][i]["protocol"] >> protocol;
2811-
json["configs"][i]["obfs"] >> obfs;
2812-
json["configs"][i]["method"] >> cipher;
2813-
if(find(ss_ciphers.begin(), ss_ciphers.end(), cipher) != ss_ciphers.end() && protocol == "origin" && obfs == "plain") //is ss
28142800
{
2815-
ssConstruct(node, group, remarks, server, port, pass, cipher, "", "");
2801+
std::string user = GetMember(json["configs"][i], "username");
2802+
socksConstruct(node, group, remarks, server, port, user, pass);
28162803
}
2817-
else //is ssr cipher
2804+
break;
2805+
case 6: //ss/ssr
28182806
{
2819-
json["configs"][i]["obfsparam"] >> obfsparam;
2820-
json["configs"][i]["protocolparam"] >> protoparam;
2821-
ssrConstruct(node, group, remarks, server, port, protocol, cipher, obfs, pass, obfsparam, protoparam);
2807+
std::string protocol = GetMember(json["configs"][i], "protocol");
2808+
std::string obfs = GetMember(json["configs"][i], "obfs");
2809+
std::string cipher = GetMember(json["configs"][i], "method");
2810+
if(find(ss_ciphers.begin(), ss_ciphers.end(), cipher) != ss_ciphers.end() && protocol == "origin" && obfs == "plain") //is ss
2811+
{
2812+
ssConstruct(node, group, remarks, server, port, pass, cipher, "", "");
2813+
}
2814+
else //is ssr cipher
2815+
{
2816+
std::string obfsparam = GetMember(json["configs"][i], "obfsparam");
2817+
std::string protoparam = GetMember(json["configs"][i], "protocolparam");
2818+
ssrConstruct(node, group, remarks, server, port, protocol, cipher, obfs, pass, obfsparam, protoparam);
2819+
}
28222820
}
28232821
break;
28242822
default:

0 commit comments

Comments
 (0)