ReactOS 0.4.15-dev-7788-g1ad9096
cmname.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Registry Library
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/cmlib/cmname.c
5 * PURPOSE: Configuration Manager - Name Management
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include "cmlib.h"
12#define NDEBUG
13#include <debug.h>
14
15/* GLOBALS *******************************************************************/
16
17/* FUNCTIONS *****************************************************************/
18
24{
25 ULONG i;
26
27 /* Check for old hives */
28 if (Hive->Version == 1)
29 {
30 /* Just copy the source directly */
31 RtlCopyMemory(Destination, Source->Buffer, Source->Length);
32 return Source->Length;
33 }
34
35 /* For new versions, check for compressed name */
36 for (i = 0; i < (Source->Length / sizeof(WCHAR)); i++)
37 {
38 /* Check if the name is non compressed */
39 if (Source->Buffer[i] > (UCHAR)-1)
40 {
41 /* Do the copy */
42 RtlCopyMemory(Destination, Source->Buffer, Source->Length);
43 return Source->Length;
44 }
45
46 /* Copy this character */
47 ((PCHAR)Destination)[i] = (CHAR)(Source->Buffer[i]);
48 }
49
50 /* Compressed name, return length */
51 return Source->Length / sizeof(WCHAR);
52}
53
54VOID
57 IN ULONG DestinationLength,
59 IN ULONG SourceLength)
60{
61 ULONG i, Length;
62
63 /* Get the actual length to copy */
64 Length = min(DestinationLength / sizeof(WCHAR), SourceLength);
65 for (i = 0; i < Length; i++)
66 {
67 /* Copy each character */
69 }
70}
71
76{
77 ULONG i;
78
79 /* For old hives, just return the length */
80 if (Hive->Version == 1) return Name->Length;
81
82 /* For new versions, check for compressed name */
83 for (i = 0; i < (Name->Length / sizeof(WCHAR)); i++)
84 {
85 /* Check if the name is non compressed */
86 if (Name->Buffer[i] > (UCHAR)-1) return Name->Length;
87 }
88
89 /* Compressed name, return length */
90 return Name->Length / sizeof(WCHAR);
91}
92
97{
98 /*
99 * Don't remove this: compressed names are "opaque" and just because
100 * the current implementation turns them into ansi-names doesn't mean
101 * that it will remain that way forever, so -never- assume this code
102 * below internally!
103 */
104 return (USHORT)Length * sizeof(WCHAR);
105}
106
107LONG
108NTAPI
110 IN PWCHAR CompressedName,
111 IN ULONG NameLength)
112{
113 WCHAR* p;
114 UCHAR* pp;
115 WCHAR chr1, chr2;
116 USHORT SearchLength;
117 LONG Result;
118
119 /* Set the pointers and length and then loop */
120 p = SearchName->Buffer;
121 pp = (PUCHAR)CompressedName;
122 SearchLength = (SearchName->Length / sizeof(WCHAR));
123 while (SearchLength > 0 && NameLength > 0)
124 {
125 /* Get the characters */
126 chr1 = *p++;
127 chr2 = (WCHAR)(*pp++);
128
129 /* Check if we have a direct match */
130 if (chr1 != chr2)
131 {
132 /* See if they match and return result if they don't */
135 if (Result) return Result;
136 }
137
138 /* Next chars */
139 SearchLength--;
140 NameLength--;
141 }
142
143 /* Return the difference directly */
144 return SearchLength - NameLength;
145}
146
148NTAPI
152 OUT PULONG ChildIndex OPTIONAL,
153 OUT PHCELL_INDEX CellIndex)
154{
155 PCELL_DATA CellData;
156 HCELL_INDEX CellToRelease = HCELL_NIL;
157 ULONG i;
158 PCM_KEY_VALUE KeyValue;
159 LONG Result;
160 UNICODE_STRING SearchName;
162
163 /* Make sure there's actually something on the list */
164 if (ChildList->Count != 0)
165 {
166 /* Get the cell data */
167 CellData = (PCELL_DATA)HvGetCell(Hive, ChildList->List);
168 if (!CellData)
169 {
170 /* Couldn't get the cell... tell the caller */
171 *CellIndex = HCELL_NIL;
172 return FALSE;
173 }
174
175 /* Now loop every entry */
176 for (i = 0; i < ChildList->Count; i++)
177 {
178 /* Check if we have a cell to release */
179 if (CellToRelease != HCELL_NIL)
180 {
181 /* Release it */
182 HvReleaseCell(Hive, CellToRelease);
183 CellToRelease = HCELL_NIL;
184 }
185
186 /* Get this value */
187 KeyValue = (PCM_KEY_VALUE)HvGetCell(Hive, CellData->u.KeyList[i]);
188 if (!KeyValue)
189 {
190 /* Return with no data found */
191 *CellIndex = HCELL_NIL;
192 Success = FALSE;
193 goto Return;
194 }
195
196 /* Save the cell to release */
197 CellToRelease = CellData->u.KeyList[i];
198
199 /* Check if it's a compressed value name */
200 if (KeyValue->Flags & VALUE_COMP_NAME)
201 {
202 /* Compare compressed names */
204 KeyValue->Name,
205 KeyValue->NameLength);
206 }
207 else
208 {
209 /* Compare the Unicode name directly */
210 SearchName.Length = KeyValue->NameLength;
211 SearchName.MaximumLength = SearchName.Length;
212 SearchName.Buffer = KeyValue->Name;
213 Result = RtlCompareUnicodeString(Name, &SearchName, TRUE);
214 }
215
216 /* Check if we found it */
217 if (!Result)
218 {
219 /* We did... return info to caller */
220 if (ChildIndex) *ChildIndex = i;
221 *CellIndex = CellData->u.KeyList[i];
222
223 /* Set success state */
224 Success = TRUE;
225 goto Return;
226 }
227 }
228
229 /* Got to the end of the list */
230 if (ChildIndex) *ChildIndex = i;
231 *CellIndex = HCELL_NIL;
232
233 /* Nothing found if we got here */
234 Success = TRUE;
235 goto Return;
236 }
237
238 /* Nothing found... check if the caller wanted more info */
239 ASSERT(ChildList->Count == 0);
240 if (ChildIndex) *ChildIndex = 0;
241 *CellIndex = HCELL_NIL;
242
243 /* Nothing found if we got here */
244 return TRUE;
245
246Return:
247 /* Release the first cell we got */
248 if (CellData) HvReleaseCell(Hive, ChildList->List);
249
250 /* Release the secondary one, if we have one */
251 if (CellToRelease) HvReleaseCell(Hive, CellToRelease);
252 return Success;
253}
unsigned char BOOLEAN
#define CHAR(Char)
struct _CELL_DATA * PCELL_DATA
struct _CM_KEY_VALUE * PCM_KEY_VALUE
#define VALUE_COMP_NAME
Definition: cmdata.h:44
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:455
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:452
USHORT NTAPI CmpCopyName(IN PHHIVE Hive, OUT PWCHAR Destination, IN PCUNICODE_STRING Source)
Definition: cmname.c:21
USHORT NTAPI CmpNameSize(IN PHHIVE Hive, IN PCUNICODE_STRING Name)
Definition: cmname.c:74
VOID NTAPI CmpCopyCompressedName(OUT PWCHAR Destination, IN ULONG DestinationLength, IN PWCHAR Source, IN ULONG SourceLength)
Definition: cmname.c:56
LONG NTAPI CmpCompareCompressedName(IN PCUNICODE_STRING SearchName, IN PWCHAR CompressedName, IN ULONG NameLength)
Definition: cmname.c:109
USHORT NTAPI CmpCompressedNameSize(IN PWCHAR Name, IN ULONG Length)
Definition: cmname.c:95
BOOLEAN NTAPI CmpFindNameInList(IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PCUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
Definition: cmname.c:149
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
@ Success
Definition: eventcreate.c:712
GLfloat GLfloat p
Definition: glext.h:8902
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
ULONG * PHCELL_INDEX
Definition: hivedata.h:105
#define HCELL_NIL
Definition: hivedata.h:110
ULONG HCELL_INDEX
Definition: hivedata.h:105
#define PCHAR
Definition: match.c:90
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3004
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:176
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
union _CELL_DATA::@4298 u
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:131
USHORT NameLength
Definition: cmdata.h:125
USHORT Flags
Definition: cmdata.h:129
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define IN
Definition: typedefs.h:39
uint16_t * PWCHAR
Definition: typedefs.h:56
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCHILDLIST * ChildList
Definition: wdfchildlist.h:481
_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
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180