ReactOS 0.4.15-dev-8339-g4028de8
names.c File Reference
#include "precomp.h"
#include <debug.h>
Include dependency graph for names.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define HAS_EXTENDED   0x0001
 
#define HAS_NUMERIC   0x0002
 
#define HAS_NON_NUMERIC   0x0004
 
#define HAS_DOT   0x0008
 
#define HAS_DOT_DOT   0x0010
 
#define HAS_SPACE   0x0020
 
#define HAS_INVALID   0x0040
 
#define HAS_ASTERISK   0x0080
 
#define HAS_UNDERSCORE   0x0100
 
#define HAS_LONG_LABEL   0x0200
 

Functions

BOOL WINAPI DnsNameCompare_A (LPCSTR name1, LPCSTR name2)
 
BOOL WINAPI DnsNameCompare_W (PCWSTR name1, PCWSTR name2)
 
DNS_STATUS WINAPI DnsValidateName_A (PCSTR name, DNS_NAME_FORMAT format)
 
DNS_STATUS WINAPI DnsValidateName_UTF8 (PCSTR name, DNS_NAME_FORMAT format)
 
DNS_STATUS WINAPI DnsValidateName_W (PCWSTR name, DNS_NAME_FORMAT format)
 

Macro Definition Documentation

◆ HAS_ASTERISK

#define HAS_ASTERISK   0x0080

Definition at line 116 of file names.c.

◆ HAS_DOT

#define HAS_DOT   0x0008

Definition at line 112 of file names.c.

◆ HAS_DOT_DOT

#define HAS_DOT_DOT   0x0010

Definition at line 113 of file names.c.

◆ HAS_EXTENDED

#define HAS_EXTENDED   0x0001

Definition at line 109 of file names.c.

◆ HAS_INVALID

#define HAS_INVALID   0x0040

Definition at line 115 of file names.c.

◆ HAS_LONG_LABEL

#define HAS_LONG_LABEL   0x0200

Definition at line 118 of file names.c.

◆ HAS_NON_NUMERIC

#define HAS_NON_NUMERIC   0x0004

Definition at line 111 of file names.c.

◆ HAS_NUMERIC

#define HAS_NUMERIC   0x0002

Definition at line 110 of file names.c.

◆ HAS_SPACE

#define HAS_SPACE   0x0020

Definition at line 114 of file names.c.

◆ HAS_UNDERSCORE

#define HAS_UNDERSCORE   0x0100

Definition at line 117 of file names.c.

◆ NDEBUG

#define NDEBUG

Definition at line 24 of file names.c.

Function Documentation

◆ DnsNameCompare_A()

BOOL WINAPI DnsNameCompare_A ( LPCSTR  name1,
LPCSTR  name2 
)

Definition at line 31 of file names.c.

32{
33 BOOL ret;
34 PWSTR name1W, name2W;
35
36 name1W = dns_strdup_aw( name1 );
37 name2W = dns_strdup_aw( name2 );
38
39 ret = DnsNameCompare_W( name1W, name2W );
40
41 HeapFree(GetProcessHeap(), 0, name1W );
42 HeapFree(GetProcessHeap(), 0, name2W );
43
44 return ret;
45}
#define GetProcessHeap()
Definition: compat.h:736
#define HeapFree(x, y, z)
Definition: compat.h:735
static LPWSTR dns_strdup_aw(LPCSTR str)
Definition: precomp.h:49
unsigned int BOOL
Definition: ntddk_ex.h:94
static WCHAR name1[]
Definition: record.c:34
static WCHAR name2[]
Definition: record.c:35
BOOL WINAPI DnsNameCompare_W(PCWSTR name1, PCWSTR name2)
Definition: names.c:51
uint16_t * PWSTR
Definition: typedefs.h:56
int ret

Referenced by test_DnsNameCompare_A().

◆ DnsNameCompare_W()

BOOL WINAPI DnsNameCompare_W ( PCWSTR  name1,
PCWSTR  name2 
)

Definition at line 51 of file names.c.

52{
53 PCWSTR p, q;
54
55 if (!name1 && !name2) return TRUE;
56 if (!name1 || !name2) return FALSE;
57
58 p = name1 + lstrlenW( name1 ) - 1;
59 q = name2 + lstrlenW( name2 ) - 1;
60
61 while (*p == '.' && p >= name1) p--;
62 while (*q == '.' && q >= name2) q--;
63
64 if (p - name1 != q - name2) return FALSE;
65
66 while (name1 <= p)
67 {
68 if (towupper( *name1 ) != towupper( *name2 ))
69 return FALSE;
70
71 name1++;
72 name2++;
73 }
74 return TRUE;
75}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define lstrlenW
Definition: compat.h:750
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLfloat GLfloat p
Definition: glext.h:8902
#define towupper(c)
Definition: wctype.h:99
const uint16_t * PCWSTR
Definition: typedefs.h:57

Referenced by DnsNameCompare_A(), and SaBlob_Query().

◆ DnsValidateName_A()

DNS_STATUS WINAPI DnsValidateName_A ( PCSTR  name,
DNS_NAME_FORMAT  format 
)

Definition at line 81 of file names.c.

82{
84 DNS_STATUS ret;
85
88
90 return ret;
91}
static const WCHAR nameW[]
Definition: main.c:49
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
DNS_STATUS WINAPI DnsValidateName_W(PCWSTR name, DNS_NAME_FORMAT format)
Definition: names.c:124
Definition: name.c:39

Referenced by test_DnsValidateName_A().

◆ DnsValidateName_UTF8()

DNS_STATUS WINAPI DnsValidateName_UTF8 ( PCSTR  name,
DNS_NAME_FORMAT  format 
)

Definition at line 97 of file names.c.

98{
100 DNS_STATUS ret;
101
104
106 return ret;
107}
static LPWSTR dns_strdup_uw(const char *str)
Definition: precomp.h:37

◆ DnsValidateName_W()

DNS_STATUS WINAPI DnsValidateName_W ( PCWSTR  name,
DNS_NAME_FORMAT  format 
)

Definition at line 124 of file names.c.

125{
126 PCWSTR p;
127 unsigned int i, j, state = 0;
128 static const WCHAR invalid[] = {
129 '{','|','}','~','[','\\',']','^','\'',':',';','<','=','>',
130 '?','@','!','\"','#','$','%','^','`','(',')','+','/',',',0 };
131
132 if (!name) return ERROR_INVALID_NAME;
133
134 for (p = name, i = 0, j = 0; *p; p++, i++, j++)
135 {
136 if (*p == '.')
137 {
138 j = 0;
139 state |= HAS_DOT;
140 if (p[1] == '.') state |= HAS_DOT_DOT;
141 }
142 else if (*p < '0' || *p > '9') state |= HAS_NON_NUMERIC;
143 else state |= HAS_NUMERIC;
144
145 if (j > 62) state |= HAS_LONG_LABEL;
146
147 if (wcschr( invalid, *p )) state |= HAS_INVALID;
148 else if ((unsigned)*p > 127) state |= HAS_EXTENDED;
149 else if (*p == ' ') state |= HAS_SPACE;
150 else if (*p == '_') state |= HAS_UNDERSCORE;
151 else if (*p == '*') state |= HAS_ASTERISK;
152 }
153
154 if (i == 0 || i > 255 ||
155 (state & HAS_LONG_LABEL) ||
156 (state & HAS_DOT_DOT) ||
157 (name[0] == '.' && name[1])) return ERROR_INVALID_NAME;
158
159 switch (format)
160 {
161 case DnsNameDomain:
162 {
163 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
165 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
167 if ((state & HAS_SPACE) ||
168 (state & HAS_INVALID) ||
170 break;
171 }
173 {
174 if (state & HAS_DOT) return ERROR_INVALID_NAME;
175 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
177 if ((state & HAS_SPACE) ||
178 (state & HAS_INVALID) ||
180 break;
181 }
183 {
184 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
186 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
188 if ((state & HAS_SPACE) ||
189 (state & HAS_INVALID) ||
191 break;
192 }
194 {
195 if (state & HAS_DOT) return ERROR_INVALID_NAME;
196 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
198 if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
200 if ((state & HAS_SPACE) ||
201 (state & HAS_INVALID) ||
203 break;
204 }
205 case DnsNameWildcard:
206 {
207 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
208 return ERROR_INVALID_NAME;
209 if (name[0] != '*') return ERROR_INVALID_NAME;
210 if (name[1] && name[1] != '.')
212 if ((state & HAS_EXTENDED) ||
213 (state & HAS_SPACE) ||
215 break;
216 }
217 case DnsNameSrvRecord:
218 {
219 if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
220 return ERROR_INVALID_NAME;
221 if (name[0] != '_') return ERROR_INVALID_NAME;
222 if ((state & HAS_UNDERSCORE) && !name[1])
224 if ((state & HAS_EXTENDED) ||
225 (state & HAS_SPACE) ||
227 break;
228 }
229 default:
230 DPRINT1( "unknown format: %d\n", format );
231 break;
232 }
233 return ERROR_SUCCESS;
234}
static int state
Definition: maze.c:121
#define DPRINT1
Definition: precomp.h:8
#define ERROR_SUCCESS
Definition: deptool.c:10
#define wcschr
Definition: compat.h:17
#define ERROR_INVALID_NAME
Definition: compat.h:103
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
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 GLint GLint j
Definition: glfuncs.h:250
static const WCHAR invalid[]
Definition: assoc.c:39
#define HAS_INVALID
Definition: names.c:115
#define HAS_DOT_DOT
Definition: names.c:113
#define HAS_LONG_LABEL
Definition: names.c:118
#define HAS_UNDERSCORE
Definition: names.c:117
#define HAS_EXTENDED
Definition: names.c:109
#define HAS_SPACE
Definition: names.c:114
#define HAS_NON_NUMERIC
Definition: names.c:111
#define HAS_ASTERISK
Definition: names.c:116
#define HAS_DOT
Definition: names.c:112
#define HAS_NUMERIC
Definition: names.c:110
@ DnsNameSrvRecord
Definition: windns.h:149
@ DnsNameHostnameLabel
Definition: windns.h:147
@ DnsNameDomainLabel
Definition: windns.h:145
@ DnsNameDomain
Definition: windns.h:144
@ DnsNameHostnameFull
Definition: windns.h:146
@ DnsNameWildcard
Definition: windns.h:148
#define DNS_ERROR_NUMERIC_NAME
Definition: winerror.h:1878
#define DNS_ERROR_NON_RFC_NAME
Definition: winerror.h:1872
#define DNS_ERROR_INVALID_NAME_CHAR
Definition: winerror.h:1877
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by DnsValidateName_A(), DnsValidateName_UTF8(), IsValidComputerName(), and IsValidDomainName().