mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-20 06:02:23 +00:00
58 lines
No EOL
1.8 KiB
C#
58 lines
No EOL
1.8 KiB
C#
namespace ServiceLib.Handler.Fmt
|
|
{
|
|
public class TuicFmt : BaseFmt
|
|
{
|
|
public static ProfileItem? Resolve(string str, out string msg)
|
|
{
|
|
msg = ResUI.ConfigurationFormatIncorrect;
|
|
|
|
ProfileItem item = new()
|
|
{
|
|
ConfigType = EConfigType.TUIC
|
|
};
|
|
|
|
Uri url = new(str);
|
|
|
|
item.Address = url.IdnHost;
|
|
item.Port = url.Port;
|
|
item.Remarks = url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
|
|
var rawUserInfo = Utils.UrlDecode(url.UserInfo);
|
|
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
|
if (userInfoParts.Length == 2)
|
|
{
|
|
item.Id = userInfoParts[0];
|
|
item.Security = userInfoParts[1];
|
|
}
|
|
|
|
var query = Utils.ParseQueryString(url.Query);
|
|
ResolveStdTransport(query, ref item);
|
|
item.HeaderType = query["congestion_control"] ?? "";
|
|
|
|
return item;
|
|
}
|
|
|
|
public static string? ToUri(ProfileItem? item)
|
|
{
|
|
if (item == null) return null;
|
|
string url = string.Empty;
|
|
|
|
string remark = string.Empty;
|
|
if (Utils.IsNotEmpty(item.Remarks))
|
|
{
|
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
|
}
|
|
var dicQuery = new Dictionary<string, string>();
|
|
if (Utils.IsNotEmpty(item.Sni))
|
|
{
|
|
dicQuery.Add("sni", item.Sni);
|
|
}
|
|
if (Utils.IsNotEmpty(item.Alpn))
|
|
{
|
|
dicQuery.Add("alpn", Utils.UrlEncode(item.Alpn));
|
|
}
|
|
dicQuery.Add("congestion_control", item.HeaderType);
|
|
|
|
return ToUri(EConfigType.TUIC, item.Address, item.Port, $"{item.Id}:{item.Security}", dicQuery, remark);
|
|
}
|
|
}
|
|
} |