Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ServiceNameStore.cs
Go to the documentation of this file.
6
7namespace System.Net;
8
9internal sealed class ServiceNameStore
10{
11 private readonly List<string> _serviceNames;
12
14
26
28 {
31 }
32
33 private static string NormalizeServiceName(string inputServiceName)
34 {
35 if (string.IsNullOrWhiteSpace(inputServiceName))
36 {
37 return inputServiceName;
38 }
39 int num = inputServiceName.IndexOf('/');
40 if (num < 0)
41 {
42 return inputServiceName;
43 }
44 string text = inputServiceName.Substring(0, num + 1);
45 string text2 = inputServiceName.Substring(num + 1);
46 if (string.IsNullOrWhiteSpace(text2))
47 {
48 return inputServiceName;
49 }
50 string text3 = text2;
51 string text4 = string.Empty;
52 string text5 = string.Empty;
54 if (uriHostNameType == UriHostNameType.Unknown)
55 {
56 string text6 = text2;
57 int num2 = text2.IndexOf('/');
58 if (num2 >= 0)
59 {
60 text6 = text2.Substring(0, num2);
61 text5 = text2.Substring(num2);
62 text3 = text6;
63 }
64 int num3 = text6.LastIndexOf(':');
65 if (num3 >= 0)
66 {
67 text3 = text6.Substring(0, num3);
68 text4 = text6.Substring(num3 + 1);
69 if (!ushort.TryParse(text4, NumberStyles.Integer, CultureInfo.InvariantCulture, out var _))
70 {
71 return inputServiceName;
72 }
73 text4 = text6.Substring(num3);
74 }
76 }
78 {
79 return inputServiceName;
80 }
82 {
83 return inputServiceName;
84 }
85 string components = result2.GetComponents(UriComponents.NormalizedHost, UriFormat.SafeUnescaped);
86 string text7 = text + components + text4 + text5;
87 if (inputServiceName.Equals(text7, StringComparison.OrdinalIgnoreCase))
88 {
89 return inputServiceName;
90 }
91 return text7;
92 }
93
94 private bool AddSingleServiceName(string spn)
95 {
97 if (Contains(spn))
98 {
99 return false;
100 }
102 return true;
103 }
104
105 public bool Add(string uriPrefix)
106 {
108 bool flag = false;
109 string[] array2 = array;
110 foreach (string text in array2)
111 {
113 {
114 flag = true;
115 if (System.Net.NetEventSource.Log.IsEnabled())
116 {
118 }
119 }
120 }
121 if (flag)
122 {
124 }
125 else if (System.Net.NetEventSource.Log.IsEnabled())
126 {
128 }
129 return flag;
130 }
131
132 public bool Remove(string uriPrefix)
133 {
136 bool flag = Contains(inputServiceName);
137 if (flag)
138 {
141 }
142 if (System.Net.NetEventSource.Log.IsEnabled())
143 {
144 if (flag)
145 {
147 }
148 else
149 {
151 }
152 }
153 return flag;
154 }
155
156 private bool Contains(string newServiceName)
157 {
158 if (newServiceName == null)
159 {
160 return false;
161 }
162 foreach (string serviceName in _serviceNames)
163 {
164 if (serviceName.Equals(newServiceName, StringComparison.OrdinalIgnoreCase))
165 {
166 return true;
167 }
168 }
169 return false;
170 }
171
172 public void Clear()
173 {
176 }
177
179 {
181 {
182 Uri uri = new Uri(uriPrefix);
183 return uri.Host;
184 }
186 {
187 int num = uriPrefix.IndexOf("://", StringComparison.Ordinal) + 3;
188 int i = num;
189 for (bool flag = false; i < uriPrefix.Length && uriPrefix[i] != '/' && (uriPrefix[i] != ':' || flag); i++)
190 {
191 if (uriPrefix[i] == '[')
192 {
193 if (flag)
194 {
195 i = num;
196 break;
197 }
198 flag = true;
199 }
200 if (flag && uriPrefix[i] == ']')
201 {
202 flag = false;
203 }
204 }
205 return uriPrefix.Substring(num, i - num);
206 }
207 return null;
208 }
209
210 public string BuildSimpleServiceName(string uriPrefix)
211 {
213 if (text != null)
214 {
215 return "HTTP/" + text;
216 }
217 return null;
218 }
219
220 public string[] BuildServiceNames(string uriPrefix)
221 {
223 IPAddress address = null;
224 if (string.Equals(text, "*", StringComparison.OrdinalIgnoreCase) || string.Equals(text, "+", StringComparison.OrdinalIgnoreCase) || IPAddress.TryParse(text, out address))
225 {
226 try
227 {
228 string hostName = Dns.GetHostEntry(string.Empty).HostName;
229 return new string[1] { "HTTP/" + hostName };
230 }
231 catch (SocketException)
232 {
233 return Array.Empty<string>();
234 }
235 catch (SecurityException)
236 {
237 return Array.Empty<string>();
238 }
239 }
240 if (!text.Contains('.'))
241 {
242 try
243 {
244 string hostName2 = Dns.GetHostEntry(text).HostName;
245 return new string[2]
246 {
247 "HTTP/" + text,
248 "HTTP/" + hostName2
249 };
250 }
251 catch (SocketException)
252 {
253 return new string[1] { "HTTP/" + text };
254 }
255 catch (SecurityException)
256 {
257 return new string[1] { "HTTP/" + text };
258 }
259 }
260 return new string[1] { "HTTP/" + text };
261 }
262}
static CultureInfo InvariantCulture
static IPHostEntry GetHostEntry(IPAddress address)
Definition Dns.cs:36
static bool TryParse([NotNullWhen(true)] string? ipString, [NotNullWhen(true)] out IPAddress? address)
Definition IPAddress.cs:303
static readonly System.Net.NetEventSource Log
static void Info(object thisOrContextObject, FormattableString formattableString=null, [CallerMemberName] string memberName=null)
string BuildSimpleServiceName(string uriPrefix)
static string NormalizeServiceName(string inputServiceName)
bool Add(string uriPrefix)
bool Contains(string newServiceName)
string[] BuildServiceNames(string uriPrefix)
string ExtractHostname(string uriPrefix, bool allowInvalidUriStrings)
bool AddSingleServiceName(string spn)
readonly List< string > _serviceNames
bool Remove(string uriPrefix)
ServiceNameCollection ServiceNames
ServiceNameCollection _serviceNameCollection
static string net_log_listener_spn_not_remove
Definition SR.cs:74
static string net_log_listener_spn_remove
Definition SR.cs:72
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string net_log_listener_spn_add
Definition SR.cs:68
static string net_log_listener_spn_not_add
Definition SR.cs:70
Definition SR.cs:7
string Host
Definition Uri.cs:441
static bool TryCreate([NotNullWhen(true)] string? uriString, UriKind uriKind, [NotNullWhen(true)] out Uri? result)
Definition Uri.cs:3793
static unsafe UriHostNameType CheckHostName(string? name)
Definition Uri.cs:963
static readonly string SchemeDelimiter
Definition Uri.cs:187
static bool IsWellFormedUriString([NotNullWhen(true)] string? uriString, UriKind uriKind)
Definition Uri.cs:3955
static readonly string UriSchemeHttp
Definition Uri.cs:165
UriKind
Definition UriKind.cs:4
UriFormat
Definition UriFormat.cs:4