Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

cmname.c

Go to the documentation of this file.
00001 /*++ 00002 00003 Copyright (c) 1992 Microsoft Corporation 00004 00005 Module Name: 00006 00007 cmname.c 00008 00009 Abstract: 00010 00011 Provides routines for handling name comparisons and converting to/from the registry 00012 compressed name format. 00013 00014 Author: 00015 00016 John Vert (jvert) 28-Oct-1993 00017 00018 Revision History: 00019 00020 00021 --*/ 00022 #include "cmp.h" 00023 #ifdef ALLOC_PRAGMA 00024 #pragma alloc_text(PAGE,CmpNameSize) 00025 #pragma alloc_text(PAGE,CmpCopyName) 00026 #pragma alloc_text(PAGE,CmpCompressedNameSize) 00027 #pragma alloc_text(PAGE,CmpCopyCompressedName) 00028 #pragma alloc_text(PAGE,CmpCompareCompressedName) 00029 #endif 00030 00031 00032 USHORT 00033 CmpNameSize( 00034 IN PHHIVE Hive, 00035 IN PUNICODE_STRING Name 00036 ) 00037 00038 /*++ 00039 00040 Routine Description: 00041 00042 Determines the space needed to store a given string in the registry. May apply 00043 any relevant compression to compute the length, but the compression used is 00044 guaranteed to be the same as CmpCopyName. 00045 00046 Arguments: 00047 00048 Hive - supplies the hive control structure (for version checking) 00049 00050 Name - Supplies the unicode string to be copied into the registry. 00051 00052 Return Value: 00053 00054 The number of bytes of storage required to store this name. 00055 00056 --*/ 00057 00058 { 00059 ULONG i; 00060 00061 if (Hive->Version == 1) { 00062 return(Name->Length); 00063 } 00064 for (i=0;i<Name->Length/sizeof(WCHAR);i++) { 00065 if ((USHORT)Name->Buffer[i] > (UCHAR)-1) { 00066 return(Name->Length); 00067 } 00068 } 00069 return(Name->Length / sizeof(WCHAR)); 00070 00071 } 00072 00073 USHORT 00074 CmpCopyName( 00075 IN PHHIVE Hive, 00076 IN PWCHAR Destination, 00077 IN PUNICODE_STRING Source 00078 ) 00079 00080 /*++ 00081 00082 Routine Description: 00083 00084 Copies the given unicode name into the registry, applying any relevant compression 00085 at the same time. 00086 00087 Arguments: 00088 00089 Hive - supplies the hive control structure (For version checking) 00090 00091 Destination - Supplies the destination of the given string. 00092 00093 Source - Supplies the unicode string to copy into the registry. 00094 00095 Return Value: 00096 00097 Number of bytes of storage copied 00098 00099 --*/ 00100 00101 { 00102 ULONG i; 00103 00104 if (Hive->Version==1) { 00105 RtlCopyMemory(Destination,Source->Buffer, Source->Length); 00106 return(Source->Length); 00107 } 00108 00109 for (i=0;i<Source->Length/sizeof(WCHAR);i++) { 00110 if ((USHORT)Source->Buffer[i] > (UCHAR)-1) { 00111 RtlCopyMemory(Destination,Source->Buffer, Source->Length); 00112 return(Source->Length); 00113 } 00114 ((PUCHAR)Destination)[i] = (UCHAR)(Source->Buffer[i]); 00115 } 00116 return(Source->Length / sizeof(WCHAR)); 00117 } 00118 00119 00120 USHORT 00121 CmpCompressedNameSize( 00122 IN PWCHAR Name, 00123 IN ULONG Length 00124 ) 00125 00126 /*++ 00127 00128 Routine Description: 00129 00130 Computes the length of the unicode string that the given compressed name 00131 expands into. 00132 00133 Arguments: 00134 00135 Name - Supplies the compressed name. 00136 00137 Length - Supplies the length in bytes of the compressed name 00138 00139 Return Value: 00140 00141 The number of bytes of storage required to hold the Unicode expanded name. 00142 00143 --*/ 00144 00145 { 00146 return((USHORT)Length*sizeof(WCHAR)); 00147 } 00148 00149 00150 VOID 00151 CmpCopyCompressedName( 00152 IN PWCHAR Destination, 00153 IN ULONG DestinationLength, 00154 IN PWCHAR Source, 00155 IN ULONG SourceLength 00156 ) 00157 00158 /*++ 00159 00160 Routine Description: 00161 00162 Copies a compressed name from the registry and expands it to Unicode. 00163 00164 Arguments: 00165 00166 Destination - Supplies the destination Unicode buffer 00167 00168 DestinationLength - Supplies the max length of the destination buffer in bytes 00169 00170 Source - Supplies the compressed string. 00171 00172 SourceLength - Supplies the length of the compressed string in bytes 00173 00174 Return Value: 00175 00176 None. 00177 00178 --*/ 00179 00180 { 00181 ULONG i; 00182 ULONG Chars; 00183 00184 Chars = (DestinationLength/sizeof(WCHAR) < SourceLength) 00185 ? DestinationLength/sizeof(WCHAR) 00186 : SourceLength; 00187 00188 for (i=0;i<Chars;i++) { 00189 Destination[i] = (WCHAR)(((PUCHAR)Source)[i]); 00190 } 00191 } 00192 00193 00194 LONG 00195 CmpCompareCompressedName( 00196 IN PUNICODE_STRING SearchName, 00197 IN PWCHAR CompressedName, 00198 IN ULONG NameLength 00199 ) 00200 00201 /*++ 00202 00203 Routine Description: 00204 00205 Compares a compressed registry string to a Unicode string. Does a case-insensitive 00206 comparison. 00207 00208 Arguments: 00209 00210 SearchName - Supplies the Unicode string to be compared 00211 00212 CompressedName - Supplies the compressed string to be compared 00213 00214 NameLength - Supplies the length of the compressed string 00215 00216 Return Value: 00217 00218 0 = SearchName == CompressedName (of Cell) 00219 00220 < 0 = SearchName < CompressedName 00221 00222 > 0 = SearchName > CompressedName 00223 00224 --*/ 00225 00226 { 00227 WCHAR *s1; 00228 UCHAR *s2; 00229 USHORT n1, n2; 00230 WCHAR c1; 00231 WCHAR c2; 00232 LONG cDiff; 00233 00234 s1 = SearchName->Buffer; 00235 s2 = (UCHAR *)CompressedName; 00236 n1 = (USHORT )(SearchName->Length / sizeof(WCHAR)); 00237 n2 = (USHORT )(NameLength); 00238 while (n1 && n2) { 00239 c1 = *s1++; 00240 c2 = (WCHAR)(*s2++); 00241 00242 c1 = RtlUpcaseUnicodeChar(c1); 00243 c2 = RtlUpcaseUnicodeChar(c2); 00244 00245 if ((cDiff = ((LONG)c1 - (LONG)c2)) != 0) { 00246 return( cDiff ); 00247 } 00248 00249 n1--; 00250 n2--; 00251 } 00252 00253 return( n1 - n2 ); 00254 } 00255

Generated on Sat May 15 19:39:28 2004 for test by doxygen 1.3.7