@@ -4,6 +4,8 @@ namespace ServiceLib.Handler.Fmt;
44
55public class BaseFmt
66{
7+ private static readonly string [ ] _allowInsecureArray = new [ ] { "insecure" , "allowInsecure" , "allow_insecure" , "verify" } ;
8+
79 protected static string GetIpv6 ( string address )
810 {
911 if ( Utils . IsIpv6 ( address ) )
@@ -17,7 +19,7 @@ protected static string GetIpv6(string address)
1719 }
1820 }
1921
20- protected static int GetStdTransport ( ProfileItem item , string ? securityDef , ref Dictionary < string , string > dicQuery )
22+ protected static int ToUriQuery ( ProfileItem item , string ? securityDef , ref Dictionary < string , string > dicQuery )
2123 {
2224 if ( item . Flow . IsNotEmpty ( ) )
2325 {
@@ -37,11 +39,7 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref
3739 }
3840 if ( item . Sni . IsNotEmpty ( ) )
3941 {
40- dicQuery . Add ( "sni" , item . Sni ) ;
41- }
42- if ( item . Alpn . IsNotEmpty ( ) )
43- {
44- dicQuery . Add ( "alpn" , Utils . UrlEncode ( item . Alpn ) ) ;
42+ dicQuery . Add ( "sni" , Utils . UrlEncode ( item . Sni ) ) ;
4543 }
4644 if ( item . Fingerprint . IsNotEmpty ( ) )
4745 {
@@ -63,9 +61,14 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref
6361 {
6462 dicQuery . Add ( "pqv" , Utils . UrlEncode ( item . Mldsa65Verify ) ) ;
6563 }
66- if ( item . AllowInsecure . Equals ( "true" ) )
64+
65+ if ( item . StreamSecurity . Equals ( Global . StreamSecurity ) )
6766 {
68- dicQuery . Add ( "allowInsecure" , "1" ) ;
67+ if ( item . Alpn . IsNotEmpty ( ) )
68+ {
69+ dicQuery . Add ( "alpn" , Utils . UrlEncode ( item . Alpn ) ) ;
70+ }
71+ ToUriQueryAllowInsecure ( item , ref dicQuery ) ;
6972 }
7073
7174 dicQuery . Add ( "type" , item . Network . IsNotEmpty ( ) ? item . Network : nameof ( ETransport . tcp ) ) ;
@@ -153,7 +156,40 @@ protected static int GetStdTransport(ProfileItem item, string? securityDef, ref
153156 return 0 ;
154157 }
155158
156- protected static int ResolveStdTransport ( NameValueCollection query , ref ProfileItem item )
159+ protected static int ToUriQueryLite ( ProfileItem item , ref Dictionary < string , string > dicQuery )
160+ {
161+ if ( item . Sni . IsNotEmpty ( ) )
162+ {
163+ dicQuery . Add ( "sni" , Utils . UrlEncode ( item . Sni ) ) ;
164+ }
165+ if ( item . Alpn . IsNotEmpty ( ) )
166+ {
167+ dicQuery . Add ( "alpn" , Utils . UrlEncode ( item . Alpn ) ) ;
168+ }
169+
170+ ToUriQueryAllowInsecure ( item , ref dicQuery ) ;
171+
172+ return 0 ;
173+ }
174+
175+ private static int ToUriQueryAllowInsecure ( ProfileItem item , ref Dictionary < string , string > dicQuery )
176+ {
177+ if ( item . AllowInsecure . Equals ( Global . AllowInsecure . First ( ) ) )
178+ {
179+ // Add two for compatibility
180+ dicQuery . Add ( "insecure" , "1" ) ;
181+ dicQuery . Add ( "allowInsecure" , "1" ) ;
182+ }
183+ else
184+ {
185+ dicQuery . Add ( "insecure" , "0" ) ;
186+ dicQuery . Add ( "allowInsecure" , "0" ) ;
187+ }
188+
189+ return 0 ;
190+ }
191+
192+ protected static int ResolveUriQuery ( NameValueCollection query , ref ProfileItem item )
157193 {
158194 item . Flow = GetQueryValue ( query , "flow" ) ;
159195 item . StreamSecurity = GetQueryValue ( query , "security" ) ;
@@ -164,7 +200,19 @@ protected static int ResolveStdTransport(NameValueCollection query, ref ProfileI
164200 item . ShortId = GetQueryDecoded ( query , "sid" ) ;
165201 item . SpiderX = GetQueryDecoded ( query , "spx" ) ;
166202 item . Mldsa65Verify = GetQueryDecoded ( query , "pqv" ) ;
167- item . AllowInsecure = new [ ] { "allowInsecure" , "allow_insecure" , "insecure" } . Any ( k => ( query [ k ] ?? "" ) == "1" ) ? "true" : "" ;
203+
204+ if ( _allowInsecureArray . Any ( k => GetQueryDecoded ( query , k ) == "1" ) )
205+ {
206+ item . AllowInsecure = Global . AllowInsecure . First ( ) ;
207+ }
208+ else if ( _allowInsecureArray . Any ( k => GetQueryDecoded ( query , k ) == "0" ) )
209+ {
210+ item . AllowInsecure = Global . AllowInsecure . Skip ( 1 ) . First ( ) ;
211+ }
212+ else
213+ {
214+ item . AllowInsecure = string . Empty ;
215+ }
168216
169217 item . Network = GetQueryValue ( query , "type" , nameof ( ETransport . tcp ) ) ;
170218 switch ( item . Network )
0 commit comments