Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencmname.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS Kernel 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: ntoskrnl/config/cmname.c 00005 * PURPOSE: Configuration Manager - Name Management 00006 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org) 00007 */ 00008 00009 /* INCLUDES ******************************************************************/ 00010 00011 #include "ntoskrnl.h" 00012 #define NDEBUG 00013 #include "debug.h" 00014 00015 /* GLOBALS *******************************************************************/ 00016 00017 /* FUNCTIONS *****************************************************************/ 00018 00019 USHORT 00020 NTAPI 00021 CmpCopyName(IN PHHIVE Hive, 00022 IN PWCHAR Destination, 00023 IN PUNICODE_STRING Source) 00024 { 00025 ULONG i; 00026 00027 /* Check for old hives */ 00028 if (Hive->Version == 1) 00029 { 00030 /* Just copy the source directly */ 00031 RtlCopyMemory(Destination, Source->Buffer, Source->Length); 00032 return Source->Length; 00033 } 00034 00035 /* For new versions, check for compressed name */ 00036 for (i = 0; i < (Source->Length / sizeof(WCHAR)); i++) 00037 { 00038 /* Check if the name is non compressed */ 00039 if (Source->Buffer[i] > (UCHAR)-1) 00040 { 00041 /* Do the copy */ 00042 RtlCopyMemory(Destination, Source->Buffer, Source->Length); 00043 return Source->Length; 00044 } 00045 00046 /* Copy this character */ 00047 ((PCHAR)Destination)[i] = (CHAR)(Source->Buffer[i]); 00048 } 00049 00050 /* Compressed name, return length */ 00051 return Source->Length / sizeof(WCHAR); 00052 } 00053 00054 VOID 00055 NTAPI 00056 CmpCopyCompressedName(IN PWCHAR Destination, 00057 IN ULONG DestinationLength, 00058 IN PWCHAR Source, 00059 IN ULONG SourceLength) 00060 { 00061 ULONG i, Length; 00062 00063 /* Get the actual length to copy */ 00064 Length = min(DestinationLength / sizeof(WCHAR), SourceLength); 00065 for (i = 0; i < Length; i++) 00066 { 00067 /* Copy each character */ 00068 Destination[i] = (WCHAR)((PCHAR)Source)[i]; 00069 } 00070 } 00071 00072 USHORT 00073 NTAPI 00074 CmpNameSize(IN PHHIVE Hive, 00075 IN PUNICODE_STRING Name) 00076 { 00077 ULONG i; 00078 00079 /* For old hives, just retun the length */ 00080 if (Hive->Version == 1) return Name->Length; 00081 00082 /* For new versions, check for compressed name */ 00083 for (i = 0; i < (Name->Length / sizeof(WCHAR)); i++) 00084 { 00085 /* Check if the name is non compressed */ 00086 if (Name->Buffer[i] > (UCHAR)-1) return Name->Length; 00087 } 00088 00089 /* Compressed name, return length */ 00090 return Name->Length / sizeof(WCHAR); 00091 } 00092 00093 USHORT 00094 NTAPI 00095 CmpCompressedNameSize(IN PWCHAR Name, 00096 IN ULONG Length) 00097 { 00098 /* 00099 * Don't remove this: compressed names are "opaque" and just because 00100 * the current implementation turns them into ansi-names doesn't mean 00101 * that it will remain that way forever, so -never- assume this code 00102 * below internally! 00103 */ 00104 return (USHORT)Length * sizeof(WCHAR); 00105 } 00106 00107 LONG 00108 NTAPI 00109 CmpCompareCompressedName(IN PCUNICODE_STRING SearchName, 00110 IN PWCHAR CompressedName, 00111 IN ULONG NameLength) 00112 { 00113 WCHAR *p; 00114 CHAR *pp; 00115 WCHAR p1, p2; 00116 USHORT SearchLength; 00117 LONG Result; 00118 00119 /* Set the pointers and length and then loop */ 00120 p = SearchName->Buffer; 00121 pp = (PCHAR)CompressedName; 00122 SearchLength = (SearchName->Length / sizeof(WCHAR)); 00123 while ((SearchLength) && (NameLength)) 00124 { 00125 /* Get the characters */ 00126 p1 = *p++; 00127 p2 = (WCHAR)(*pp++); 00128 00129 /* Check if we have a direct match */ 00130 if (p1 != p2) 00131 { 00132 /* See if they match and return result if they don't */ 00133 Result = (LONG)RtlUpcaseUnicodeChar(p1) - 00134 (LONG)RtlUpcaseUnicodeChar(p2); 00135 if (Result) return Result; 00136 } 00137 00138 /* Next chars */ 00139 SearchLength--; 00140 NameLength--; 00141 } 00142 00143 /* Return the difference directly */ 00144 return SearchLength - NameLength; 00145 } 00146 00147 BOOLEAN 00148 NTAPI 00149 CmpFindNameInList(IN PHHIVE Hive, 00150 IN PCHILD_LIST ChildList, 00151 IN PUNICODE_STRING Name, 00152 IN PULONG ChildIndex, 00153 IN PHCELL_INDEX CellIndex) 00154 { 00155 PCELL_DATA CellData; 00156 HCELL_INDEX CellToRelease = HCELL_NIL; 00157 ULONG i; 00158 PCM_KEY_VALUE KeyValue; 00159 LONG Result; 00160 UNICODE_STRING SearchName; 00161 BOOLEAN Success; 00162 00163 /* Make sure there's actually something on the list */ 00164 if (ChildList->Count != 0) 00165 { 00166 /* Get the cell data */ 00167 CellData = (PCELL_DATA)HvGetCell(Hive, ChildList->List); 00168 if (!CellData) 00169 { 00170 /* Couldn't get the cell... tell the caller */ 00171 *CellIndex = HCELL_NIL; 00172 return FALSE; 00173 } 00174 00175 /* Now loop every entry */ 00176 for (i = 0; i < ChildList->Count; i++) 00177 { 00178 /* Check if we have a cell to release */ 00179 if (CellToRelease != HCELL_NIL) 00180 { 00181 /* Release it */ 00182 HvReleaseCell(Hive, CellToRelease); 00183 CellToRelease = HCELL_NIL; 00184 } 00185 00186 /* Get this value */ 00187 KeyValue = (PCM_KEY_VALUE)HvGetCell(Hive, CellData->u.KeyList[i]); 00188 if (!KeyValue) 00189 { 00190 /* Return with no data found */ 00191 *CellIndex = HCELL_NIL; 00192 Success = FALSE; 00193 goto Return; 00194 } 00195 00196 /* Save the cell to release */ 00197 CellToRelease = CellData->u.KeyList[i]; 00198 00199 /* Check if it's a compressed value name */ 00200 if (KeyValue->Flags & VALUE_COMP_NAME) 00201 { 00202 /* Use the compressed name check */ 00203 Result = CmpCompareCompressedName(Name, 00204 KeyValue->Name, 00205 KeyValue->NameLength); 00206 } 00207 else 00208 { 00209 /* Setup the Unicode string */ 00210 SearchName.Length = KeyValue->NameLength; 00211 SearchName.MaximumLength = SearchName.Length; 00212 SearchName.Buffer = KeyValue->Name; 00213 Result = RtlCompareUnicodeString(Name, &SearchName, TRUE); 00214 } 00215 00216 /* Check if we found it */ 00217 if (!Result) 00218 { 00219 /* We did...return info to caller */ 00220 if (ChildIndex) *ChildIndex = i; 00221 *CellIndex = CellData->u.KeyList[i]; 00222 00223 /* Set success state */ 00224 Success = TRUE; 00225 goto Return; 00226 } 00227 } 00228 00229 /* Got to the end of the list */ 00230 if (ChildIndex) *ChildIndex = i; 00231 *CellIndex = HCELL_NIL; 00232 00233 /* Nothing found if we got here */ 00234 Success = TRUE; 00235 goto Return; 00236 } 00237 00238 /* Nothing found...check if the caller wanted more info */ 00239 ASSERT(ChildList->Count == 0); 00240 if (ChildIndex) *ChildIndex = 0; 00241 *CellIndex = HCELL_NIL; 00242 00243 /* Nothing found if we got here */ 00244 return TRUE; 00245 00246 Return: 00247 /* Release the first cell we got */ 00248 if (CellData) HvReleaseCell(Hive, ChildList->List); 00249 00250 /* Release the secondary one, if we have one */ 00251 if (CellToRelease) HvReleaseCell(Hive, CellToRelease); 00252 return Success; 00253 } Generated on Wed May 23 2012 04:34:53 for ReactOS by
1.7.6.1
|