ReactOS  0.4.14-dev-608-gd495a4f
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 }
uint16_t * PWSTR
Definition: typedefs.h:54
static WCHAR name1[]
Definition: record.c:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define GetProcessHeap()
Definition: compat.h:403
int ret
static LPWSTR dns_strdup_aw(LPCSTR str)
Definition: precomp.h:49
BOOL WINAPI DnsNameCompare_W(PCWSTR name1, PCWSTR name2)
Definition: names.c:51
static WCHAR name2[]
Definition: record.c:35
#define HeapFree(x, y, z)
Definition: compat.h:402

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 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define TRUE
Definition: types.h:120
static WCHAR name1[]
Definition: record.c:34
#define lstrlenW
Definition: compat.h:415
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
static WCHAR name2[]
Definition: record.c:35
#define towupper(c)
Definition: wctype.h:99
GLfloat GLfloat p
Definition: glext.h:8902

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 {
83  PWSTR nameW;
84  DNS_STATUS ret;
85 
88 
90  return ret;
91 }
uint16_t * PWSTR
Definition: typedefs.h:54
DNS_STATUS WINAPI DnsValidateName_W(PCWSTR name, DNS_NAME_FORMAT format)
Definition: names.c:124
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static const WCHAR nameW[]
Definition: main.c:46
#define GetProcessHeap()
Definition: compat.h:403
int ret
static LPWSTR dns_strdup_aw(LPCSTR str)
Definition: precomp.h:49
Definition: name.c:38
#define HeapFree(x, y, z)
Definition: compat.h:402

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 {
99  PWSTR nameW;
100  DNS_STATUS ret;
101 
102  nameW = dns_strdup_uw( name );
104 
105  HeapFree(GetProcessHeap(), 0, nameW );
106  return ret;
107 }
uint16_t * PWSTR
Definition: typedefs.h:54
static LPWSTR dns_strdup_uw(const char *str)
Definition: precomp.h:37
DNS_STATUS WINAPI DnsValidateName_W(PCWSTR name, DNS_NAME_FORMAT format)
Definition: names.c:124
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
static const WCHAR nameW[]
Definition: main.c:46
#define GetProcessHeap()
Definition: compat.h:403
int ret
Definition: name.c:38
#define HeapFree(x, y, z)
Definition: compat.h:402

◆ 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))
164  return DNS_ERROR_NUMERIC_NAME;
165  if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
166  return DNS_ERROR_NON_RFC_NAME;
167  if ((state & HAS_SPACE) ||
168  (state & HAS_INVALID) ||
170  break;
171  }
172  case DnsNameDomainLabel:
173  {
174  if (state & HAS_DOT) return ERROR_INVALID_NAME;
175  if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
176  return DNS_ERROR_NON_RFC_NAME;
177  if ((state & HAS_SPACE) ||
178  (state & HAS_INVALID) ||
180  break;
181  }
182  case DnsNameHostnameFull:
183  {
184  if (!(state & HAS_NON_NUMERIC) && (state & HAS_NUMERIC))
185  return DNS_ERROR_NUMERIC_NAME;
186  if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
187  return DNS_ERROR_NON_RFC_NAME;
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))
197  return DNS_ERROR_NUMERIC_NAME;
198  if ((state & HAS_EXTENDED) || (state & HAS_UNDERSCORE))
199  return DNS_ERROR_NON_RFC_NAME;
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])
223  return DNS_ERROR_NON_RFC_NAME;
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 }
#define HAS_DOT
Definition: names.c:112
static const WCHAR invalid[]
Definition: assoc.c:39
#define HAS_LONG_LABEL
Definition: names.c:118
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define HAS_DOT_DOT
Definition: names.c:113
#define ERROR_SUCCESS
Definition: deptool.c:10
#define DNS_ERROR_NON_RFC_NAME
Definition: winerror.h:1872
#define HAS_ASTERISK
Definition: names.c:116
#define HAS_INVALID
Definition: names.c:115
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
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
#define HAS_NUMERIC
Definition: names.c:110
#define HAS_SPACE
Definition: names.c:114
#define HAS_UNDERSCORE
Definition: names.c: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 GLint GLint j
Definition: glfuncs.h:250
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static int state
Definition: maze.c:121
#define HAS_EXTENDED
Definition: names.c:109
#define DPRINT1
Definition: precomp.h:8
#define DNS_ERROR_INVALID_NAME_CHAR
Definition: winerror.h:1877
Definition: name.c:38
#define ERROR_INVALID_NAME
Definition: compat.h:93
#define HAS_NON_NUMERIC
Definition: names.c:111
GLfloat GLfloat p
Definition: glext.h:8902
#define DNS_ERROR_NUMERIC_NAME
Definition: winerror.h:1878

Referenced by DnsValidateName_A(), and DnsValidateName_UTF8().