Incorrect warning message on thread pool startup in full AOT:ed Windows build.
[mono.git] / mcs / class / referencesource / System / net / System / _UncName.cs
1 #if !PLATFORM_UNIX
2 //------------------------------------------------------------------------------
3 // <copyright file="_UncName.cs" company="Microsoft">
4 //     Copyright (c) Microsoft Corporation.  All rights reserved.
5 // </copyright>
6 //------------------------------------------------------------------------------
7 using System.Globalization;
8
9 namespace System {
10
11     // The class designed as to keep minimal the working set of Uri class.
12     // The idea is to stay with static helper methods and strings
13     internal class UncNameHelper {
14
15     // fields
16
17         internal const int MaximumInternetNameLength = 256;
18
19         private UncNameHelper() {
20         }
21
22
23     // properties
24
25     // methods
26         internal static string ParseCanonicalName(string str, int start, int end, ref bool loopback) {
27             return DomainNameHelper.ParseCanonicalName(str, start, end, ref loopback);
28         }
29
30         //
31         // IsValid
32         //
33         //
34         //   ATTN: This class has been re-designed as to conform to XP+ UNC hostname format
35         //         It is now similar to DNS name but can contain Unicode characters as well
36         //         This class will be removed and replaced by IDN specification later,
37         //         but for now we violate URI RFC cause we never escape Unicode characters on the wire
38         //         For the same reason we never unescape UNC host names since we never accept
39         //         them in escaped format.
40         //
41         //
42         //      Valid UNC server name chars:
43         //          a Unicode Letter    (not allowed as the only in a segment)
44         //          a Latin-1 digit
45         //          '-'    45 0x2D
46         //          '.'    46 0x2E    (only as a host domain delimiter)
47         //          '_'    95 0x5F
48         //
49         //
50         // Assumption is the caller will check on the resulting name length
51         // Remarks:  MUST NOT be used unless all input indexes are are verified and trusted.
52         internal unsafe static bool IsValid(char* name, ushort start, ref int returnedEnd, bool notImplicitFile) {
53             ushort end = (ushort) returnedEnd;
54
55             if (start==end)
56                 return false;
57             //
58             // First segment could consist of only '_' or '-' but it cannot be all digits or empty
59             //
60             bool validShortName = false;
61             ushort i = start;
62             for (; i < end; ++i)
63             {
64                 if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
65                 {
66                     end = i;
67                     break;
68                 }
69                 else if (name[i] == '.')
70                 {
71                     ++i;
72                     break;
73                 }
74                 if (Char.IsLetter(name[i]) || name[i] == '-' || name[i] == '_')
75                 {
76                     validShortName = true;
77                 }
78                 else if (name[i] < '0' || name[i] > '9')
79                     return false;
80             }
81
82             if (!validShortName)
83                 return false;
84
85             //
86             // Subsequent segments must start with a letter or a digit
87             //
88
89             for (; i < end; ++i)
90             {
91                 if (name[i] == '/' || name[i] == '\\' || (notImplicitFile && (name[i] == ':' || name[i] == '?' || name[i] == '#')))
92                 {
93                     end = i;
94                     break;
95                 }
96                 else if (name[i] == '.')
97                 {
98                     if (!validShortName || ((i-1) >= start && name[i-1] == '.'))
99                         return false;
100
101                     validShortName = false;
102                 }
103                 else if (name[i] == '-' || name[i] == '_')
104                 {
105                     if (!validShortName)
106                         return false;
107                 }
108                 else if (Char.IsLetter(name[i]) || (name[i] >= '0' && name[i] <= '9'))
109                 {
110                     if (!validShortName)
111                         validShortName = true;
112                 }
113                 else
114                     return false;
115             }
116
117             // last segment can end with the dot
118             if (((i-1) >= start && name[i-1] == '.'))
119                 validShortName = true;
120
121             if (!validShortName)
122                 return false;
123
124             //  caller must check for (end - start <= MaximumInternetNameLength)
125
126             returnedEnd = end;
127             return true;
128         }
129     }
130 }
131 #endif // !PLATFORM_UNIX