ReactOS 0.4.17-dev-573-g8315b8c
name.c File Reference
#include <rtl.h>
#include <debug.h>
Include dependency graph for name.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define DOS_STAR   (L'<')
 
#define DOS_QM   (L'>')
 
#define DOS_DOT   (L'"')
 
#define EXPRESSION_IS_WILDCARD(expr, len)
 
#define IS_LITERAL_OR_DOS_DOT(wchar)    (wchar == DOS_DOT || (wchar != L'*' && wchar != DOS_STAR && wchar != L'?' && wchar != DOS_QM))
 

Functions

static __inline BOOLEAN RtlpContainsWildcard (_In_ PWCH Buffer, _In_ ULONG Length)
 
static __inline WCHAR RtlpGetExprChar (_In_ PWCH Buffer, _In_ ULONG Position, _In_ ULONG Length, _In_ BOOLEAN IgnoreCase, _In_opt_ PWCH UpcaseTable)
 
BOOLEAN NTAPI RtlIsNameInExpression (_In_ PUNICODE_STRING Expression, _In_ PUNICODE_STRING Name, _In_ BOOLEAN IgnoreCase, _In_opt_ PWCH UpcaseTable)
 

Macro Definition Documentation

◆ DOS_DOT

#define DOS_DOT   (L'"')

Definition at line 14 of file name.c.

◆ DOS_QM

#define DOS_QM   (L'>')

Definition at line 13 of file name.c.

◆ DOS_STAR

#define DOS_STAR   (L'<')

Definition at line 12 of file name.c.

◆ EXPRESSION_IS_WILDCARD

#define EXPRESSION_IS_WILDCARD (   expr,
  len 
)
Value:
(len == 1 && expr->Buffer[0] == L'*') \
|| (len == 3 && expr->Buffer[0] == L'*' && expr->Buffer[1] == L'.' && expr->Buffer[2] == L'*')
#define L(x)
Definition: resources.c:13
GLenum GLsizei len
Definition: glext.h:6722
Definition: query.h:86

Definition at line 16 of file name.c.

◆ IS_LITERAL_OR_DOS_DOT

#define IS_LITERAL_OR_DOS_DOT (   wchar)     (wchar == DOS_DOT || (wchar != L'*' && wchar != DOS_STAR && wchar != L'?' && wchar != DOS_QM))

Definition at line 19 of file name.c.

◆ NDEBUG

#define NDEBUG

Definition at line 9 of file name.c.

Function Documentation

◆ RtlIsNameInExpression()

BOOLEAN NTAPI RtlIsNameInExpression ( _In_ PUNICODE_STRING  Expression,
_In_ PUNICODE_STRING  Name,
_In_ BOOLEAN  IgnoreCase,
_In_opt_ PWCH  UpcaseTable 
)

Definition at line 56 of file name.c.

62{
63 ULONG NameLen = Name->Length / sizeof(WCHAR);
64 ULONG ExprLen = Expression->Length / sizeof(WCHAR);
65 ULONG NamePos = 0, ExprPos = 0;
66 ULONG StarExprPos = MAXULONG;
67 ULONG StarNamePos = 0;
68
69 /* For more information about this algorithm, see
70 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/0b034646-4e23-4874-8488-2adac231ff23
71 */
72
73 /* *** Optimizations *** */
74
75 /* Empty string */
76 if (ExprLen == 0 || NameLen == 0)
77 return (ExprLen == 0 && NameLen == 0);
78
79 /* Wildcard only */
81 return TRUE;
82
83 /* Wildcard + literal with no other wildcards */
84 if (ExprLen >= 2
85 && NameLen >= ExprLen - 1
86 && Expression->Buffer[0] == L'*'
87 && !RtlpContainsWildcard(&Expression->Buffer[1], ExprLen - 1))
88 {
89 ExprPos = 1;
90 NamePos = NameLen - (ExprLen - 1);
91
92 while (ExprPos < ExprLen)
93 {
94 WCHAR NameChar = RtlpGetExprChar(Name->Buffer, NamePos, NameLen, IgnoreCase, UpcaseTable);
95 WCHAR ExprChar = RtlpGetExprChar(Expression->Buffer, ExprPos, ExprLen, IgnoreCase, UpcaseTable);
96 if (ExprChar != NameChar)
97 return FALSE;
98 NamePos++;
99 ExprPos++;
100 }
101
102 return TRUE;
103 }
104
105 /* *** Main parser *** */
106
107 for (;;)
108 {
109 /* We passed everything and reached the end of both the name and expression. */
110 if (NamePos >= NameLen && ExprPos >= ExprLen)
111 return TRUE;
112
113 WCHAR NameChar = RtlpGetExprChar(Name->Buffer, NamePos, NameLen, IgnoreCase, UpcaseTable);
114 WCHAR ExprChar = RtlpGetExprChar(Expression->Buffer, ExprPos, ExprLen, IgnoreCase, UpcaseTable);
115
116 /* '?' or character literal */
117 if ((ExprChar == L'?' && NamePos < NameLen)
118 || (IS_LITERAL_OR_DOS_DOT(ExprChar) && ExprChar == NameChar))
119 {
120 NamePos++;
121 ExprPos++;
122 continue;
123 }
124
125 /* '*' */
126 if (ExprChar == L'*')
127 {
128 StarExprPos = ExprPos;
129 StarNamePos = NamePos;
130 ExprPos++;
131 continue;
132 }
133
134 /* DOS_STAR */
135 if (ExprChar == DOS_STAR)
136 {
137 ULONG LookPos = ExprPos + 1;
138 StarExprPos = ExprPos;
139 StarNamePos = NamePos;
140
141 while (LookPos < ExprLen)
142 {
143 WCHAR LookChar = Expression->Buffer[LookPos];
144 if (IS_LITERAL_OR_DOS_DOT(LookChar))
145 break;
146 LookPos++;
147 }
148
149 ExprPos++;
150 continue;
151 }
152
153 /* DOS_QM */
154 if (ExprChar == DOS_QM)
155 {
156 if (NamePos >= NameLen || NameChar == L'.')
157 {
158 /* Dot or end-of-name: skip all consecutive DOS_QM tokens */
159 while (ExprPos < ExprLen && Expression->Buffer[ExprPos] == DOS_QM)
160 ExprPos++;
161 continue;
162 }
163
164 /* Normal DOS_QM: consume one non-dot character */
165 NamePos++;
166 ExprPos++;
167 continue;
168 }
169
170 /* DOS_DOT */
171 if (ExprChar == DOS_DOT)
172 {
173 if (NamePos >= NameLen)
174 {
175 ExprPos++;
176 continue;
177 }
178
179 if (NameChar == L'.')
180 {
181 NamePos++;
182 ExprPos++;
183 continue;
184 }
185 }
186
187 /* Backtrack from a '*' or DOS_STAR */
188 if (StarExprPos != MAXULONG)
189 {
190 /* A DOS_STAR at the end cannot consume a trailing '.' in the name */
191 if (Expression->Buffer[StarExprPos] == DOS_STAR && ExprPos >= ExprLen)
192 {
193 ULONG i;
194 for (i = StarNamePos; i < NameLen; i++)
195 {
196 if (Name->Buffer[i] == L'.')
197 return FALSE;
198 }
199 }
200
201 if (StarNamePos < NameLen)
202 {
203 StarNamePos++;
204 NamePos = StarNamePos;
205 ExprPos = StarExprPos + 1;
206 continue;
207 }
208 }
209
210 return FALSE;
211 }
212}
PCWSTR Expression
static _In_ PUNICODE_STRING _In_ BOOLEAN _In_opt_ PWCH UpcaseTable
Definition: bufpool.h:45
LPWSTR Name
Definition: desk.c:124
#define IgnoreCase
Definition: cdprocs.h:461
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
short WCHAR
Definition: pedump.c:58
#define DOS_STAR
Definition: name.c:12
#define DOS_QM
Definition: name.c:13
#define EXPRESSION_IS_WILDCARD(expr, len)
Definition: name.c:16
static __inline WCHAR RtlpGetExprChar(_In_ PWCH Buffer, _In_ ULONG Position, _In_ ULONG Length, _In_ BOOLEAN IgnoreCase, _In_opt_ PWCH UpcaseTable)
Definition: name.c:39
static __inline BOOLEAN RtlpContainsWildcard(_In_ PWCH Buffer, _In_ ULONG Length)
Definition: name.c:25
#define DOS_DOT
Definition: name.c:14
#define IS_LITERAL_OR_DOS_DOT(wchar)
Definition: name.c:19
#define MAXULONG
Definition: typedefs.h:251
uint32_t ULONG
Definition: typedefs.h:59

◆ RtlpContainsWildcard()

static __inline BOOLEAN RtlpContainsWildcard ( _In_ PWCH  Buffer,
_In_ ULONG  Length 
)
static

Definition at line 25 of file name.c.

28{
29 for (ULONG i = 0; i < Length; i++)
30 {
31 WCHAR c = Buffer[i];
32 if (c == L'*' || c == L'?' || c == DOS_STAR || c == DOS_QM || c == DOS_DOT)
33 return TRUE;
34 }
35 return FALSE;
36}
const GLubyte * c
Definition: glext.h:8905
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102

◆ RtlpGetExprChar()

static __inline WCHAR RtlpGetExprChar ( _In_ PWCH  Buffer,
_In_ ULONG  Position,
_In_ ULONG  Length,
_In_ BOOLEAN  IgnoreCase,
_In_opt_ PWCH  UpcaseTable 
)
static

Definition at line 39 of file name.c.

45{
47 if (IgnoreCase)
49 return Result;
50}
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:177
static COORD Position
Definition: mouse.c:34
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409