Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

505 lines
12 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rpcuuid.cxx
  5. Abstract:
  6. The implementations of the methods used to manipulate RPC_UUID
  7. instances (which contain UUIDs) live in this file.
  8. Author:
  9. Michael Montague (mikemon) 15-Nov-1991
  10. Revision History:
  11. Danny Glasser (dannygl) 03-Mar-1992
  12. Created worker functions for IsNullUuid, CopyUuid, and
  13. ConvertToString. This is necessary for medium-model
  14. (i.e. Win16) support, because the Glock C++ translator
  15. doesn't support far "this" pointers.
  16. Danny Glasser (dannygl) 07-Mar-1992
  17. Same as above for ConvertFromString.
  18. Michael Montague (mikemon) 30-Nov-1992
  19. Removed the I_ routines.
  20. --*/
  21. #include <precomp.hxx>
  22. #include <osfpcket.hxx>
  23. static RPC_CHAR PAPI *
  24. HexStringToULong (
  25. IN RPC_CHAR PAPI * String,
  26. OUT unsigned long PAPI * Number
  27. )
  28. /*++
  29. Routine Description:
  30. This routine converts the hex representation of a number into an
  31. unsigned long. The hex representation is assumed to be a full
  32. eight characters long.
  33. Arguments:
  34. String - Supplies the hex representation of the number.
  35. Number - Returns the number converted from hex representation.
  36. Return Value:
  37. A pointer to the end of the hex representation is returned if the
  38. hex representation was successfully converted to an unsigned long.
  39. Otherwise, zero is returned, indicating that an error occured.
  40. --*/
  41. {
  42. unsigned long Result;
  43. int Count;
  44. Result = 0;
  45. for (Count = 0; Count < 8; Count++, String++)
  46. {
  47. if ( (*String >= RPC_CONST_CHAR('0'))
  48. && (*String <= RPC_CONST_CHAR('9')))
  49. Result = (Result << 4) + *String - RPC_CONST_CHAR('0');
  50. else if ( (*String >= RPC_CONST_CHAR('A'))
  51. && (*String <= RPC_CONST_CHAR('F')))
  52. Result = (Result << 4) + *String - RPC_CONST_CHAR('A') + 10;
  53. else if ( (*String >= RPC_CONST_CHAR('a'))
  54. && (*String <= RPC_CONST_CHAR('f')))
  55. Result = (Result << 4) + *String - RPC_CONST_CHAR('a') + 10;
  56. else
  57. return(0);
  58. }
  59. *Number = Result;
  60. return(String);
  61. }
  62. static RPC_CHAR PAPI *
  63. HexStringToUShort (
  64. IN RPC_CHAR PAPI * String,
  65. OUT unsigned short PAPI * Number
  66. )
  67. /*++
  68. Routine Description:
  69. This routine converts the hex representation of a number into an
  70. unsigned short. The hex representation is assumed to be a full
  71. four characters long.
  72. Arguments:
  73. String - Supplies the hex representation of the number.
  74. Number - Returns the number converted from hex representation.
  75. Return Value:
  76. A pointer to the end of the hex representation is returned if the
  77. hex representation was successfully converted to an unsigned short.
  78. Otherwise, zero is returned, indicating that an error occured.
  79. --*/
  80. {
  81. unsigned short Result;
  82. int Count;
  83. Result = 0;
  84. for (Count = 0; Count < 4; Count++, String++)
  85. {
  86. if ( (*String >= RPC_CONST_CHAR('0'))
  87. && (*String <= RPC_CONST_CHAR('9')))
  88. Result = (Result << 4) + *String - RPC_CONST_CHAR('0');
  89. else if ( (*String >= RPC_CONST_CHAR('A'))
  90. && (*String <= RPC_CONST_CHAR('F')))
  91. Result = (Result << 4) + *String - RPC_CONST_CHAR('A') + 10;
  92. else if ( (*String >= RPC_CONST_CHAR('a'))
  93. && (*String <= RPC_CONST_CHAR('f')))
  94. Result = (Result << 4) + *String - RPC_CONST_CHAR('a') + 10;
  95. else
  96. return(0);
  97. }
  98. *Number = Result;
  99. return(String);
  100. }
  101. static RPC_CHAR PAPI *
  102. HexStringToUChar (
  103. IN RPC_CHAR PAPI * String,
  104. OUT unsigned char PAPI * Number
  105. )
  106. /*++
  107. Routine Description:
  108. This routine converts the hex representation of a number into an
  109. unsigned char. The hex representation is assumed to be a full
  110. two characters long.
  111. Arguments:
  112. String - Supplies the hex representation of the number.
  113. Number - Returns the number converted from hex representation.
  114. Return Value:
  115. A pointer to the end of the hex representation is returned if the
  116. hex representation was successfully converted to an unsigned char.
  117. Otherwise, zero is returned, indicating that an error occured.
  118. --*/
  119. {
  120. RPC_CHAR Result;
  121. int Count;
  122. Result = 0;
  123. for (Count = 0; Count < 2; Count++, String++)
  124. {
  125. if ( (*String >= RPC_CONST_CHAR('0'))
  126. && (*String <= RPC_CONST_CHAR('9')))
  127. Result = (Result << 4) + *String - RPC_CONST_CHAR('0');
  128. else if ( (*String >= RPC_CONST_CHAR('A'))
  129. && (*String <= RPC_CONST_CHAR('F')))
  130. Result = (Result << 4) + *String - RPC_CONST_CHAR('A') + 10;
  131. else if ( (*String >= RPC_CONST_CHAR('a'))
  132. && (*String <= RPC_CONST_CHAR('f')))
  133. Result = (Result << 4) + *String - RPC_CONST_CHAR('a') + 10;
  134. else
  135. return(0);
  136. }
  137. *Number = (unsigned char)Result;
  138. return(String);
  139. }
  140. int
  141. RPC_UUID::ConvertFromString (
  142. IN RPC_CHAR PAPI * String
  143. )
  144. /*++
  145. Routine Description:
  146. We convert the string representation of uuid into an actual uuid
  147. in this method. The convert uuid is placed into this.
  148. Arguments:
  149. String - Supplies the string representation of the uuid.
  150. Return Value:
  151. 0 - The operation completed successfully.
  152. 1 - String does not supply a valid uuid.
  153. --*/
  154. {
  155. String = HexStringToULong(String,&(Uuid.Data1));
  156. if (String == 0)
  157. return(1);
  158. if (*String++ != RPC_CONST_CHAR('-'))
  159. return(1);
  160. String = HexStringToUShort(String,&(Uuid.Data2));
  161. if (String == 0)
  162. return(1);
  163. if (*String++ != RPC_CONST_CHAR('-'))
  164. return(1);
  165. String = HexStringToUShort(String,&(Uuid.Data3));
  166. if (String == 0)
  167. return(1);
  168. if (*String++ != RPC_CONST_CHAR('-'))
  169. return(1);
  170. String = HexStringToUChar(String,&(Uuid.Data4[0]));
  171. if (String == 0)
  172. return(1);
  173. String = HexStringToUChar(String,&(Uuid.Data4[1]));
  174. if (String == 0)
  175. return(1);
  176. if (*String++ != RPC_CONST_CHAR('-'))
  177. return(1);
  178. String = HexStringToUChar(String,&(Uuid.Data4[2]));
  179. if (String == 0)
  180. return(1);
  181. String = HexStringToUChar(String,&(Uuid.Data4[3]));
  182. if (String == 0)
  183. return(1);
  184. String = HexStringToUChar(String,&(Uuid.Data4[4]));
  185. if (String == 0)
  186. return(1);
  187. String = HexStringToUChar(String,&(Uuid.Data4[5]));
  188. if (String == 0)
  189. return(1);
  190. String = HexStringToUChar(String,&(Uuid.Data4[6]));
  191. if (String == 0)
  192. return(1);
  193. String = HexStringToUChar(String,&(Uuid.Data4[7]));
  194. if (String == 0)
  195. return(1);
  196. if ( *String != 0 )
  197. {
  198. return(1);
  199. }
  200. return(0);
  201. }
  202. void
  203. RPC_UUID::SetToNullUuid (
  204. )
  205. /*++
  206. Routine Description:
  207. This is set to the null UUID value.
  208. --*/
  209. {
  210. RpcpMemorySet( (void __RPC_FAR *)&Uuid, 0, sizeof(Uuid));
  211. }
  212. static RPC_CHAR HexDigits[] =
  213. {
  214. RPC_CONST_CHAR('0'),
  215. RPC_CONST_CHAR('1'),
  216. RPC_CONST_CHAR('2'),
  217. RPC_CONST_CHAR('3'),
  218. RPC_CONST_CHAR('4'),
  219. RPC_CONST_CHAR('5'),
  220. RPC_CONST_CHAR('6'),
  221. RPC_CONST_CHAR('7'),
  222. RPC_CONST_CHAR('8'),
  223. RPC_CONST_CHAR('9'),
  224. RPC_CONST_CHAR('a'),
  225. RPC_CONST_CHAR('b'),
  226. RPC_CONST_CHAR('c'),
  227. RPC_CONST_CHAR('d'),
  228. RPC_CONST_CHAR('e'),
  229. RPC_CONST_CHAR('f')
  230. };
  231. static RPC_CHAR PAPI *
  232. ULongToHexString (
  233. IN RPC_CHAR PAPI * String,
  234. IN unsigned long Number
  235. )
  236. /*++
  237. Routine Description:
  238. We convert an unsigned long into hex representation in the specified
  239. string. The result is always eight characters long; zero padding is
  240. done if necessary.
  241. Arguments:
  242. String - Supplies a buffer to put the hex representation into.
  243. Number - Supplies the unsigned long to convert to hex.
  244. Return Value:
  245. A pointer to the end of the hex string is returned.
  246. --*/
  247. {
  248. *String++ = HexDigits[(Number >> 28) & 0x0F];
  249. *String++ = HexDigits[(Number >> 24) & 0x0F];
  250. *String++ = HexDigits[(Number >> 20) & 0x0F];
  251. *String++ = HexDigits[(Number >> 16) & 0x0F];
  252. *String++ = HexDigits[(Number >> 12) & 0x0F];
  253. *String++ = HexDigits[(Number >> 8) & 0x0F];
  254. *String++ = HexDigits[(Number >> 4) & 0x0F];
  255. *String++ = HexDigits[Number & 0x0F];
  256. return(String);
  257. }
  258. static RPC_CHAR PAPI *
  259. UShortToHexString (
  260. IN RPC_CHAR PAPI * String,
  261. IN unsigned short Number
  262. )
  263. /*++
  264. Routine Description:
  265. We convert an unsigned short into hex representation in the specified
  266. string. The result is always four characters long; zero padding is
  267. done if necessary.
  268. Arguments:
  269. String - Supplies a buffer to put the hex representation into.
  270. Number - Supplies the unsigned short to convert to hex.
  271. Return Value:
  272. A pointer to the end of the hex string is returned.
  273. --*/
  274. {
  275. *String++ = HexDigits[(Number >> 12) & 0x0F];
  276. *String++ = HexDigits[(Number >> 8) & 0x0F];
  277. *String++ = HexDigits[(Number >> 4) & 0x0F];
  278. *String++ = HexDigits[Number & 0x0F];
  279. return(String);
  280. }
  281. static RPC_CHAR PAPI *
  282. UCharToHexString (
  283. IN RPC_CHAR PAPI * String,
  284. IN RPC_CHAR Number
  285. )
  286. /*++
  287. Routine Description:
  288. We convert an unsigned char into hex representation in the specified
  289. string. The result is always two characters long; zero padding is
  290. done if necessary.
  291. Arguments:
  292. String - Supplies a buffer to put the hex representation into.
  293. Number - Supplies the unsigned char to convert to hex.
  294. Return Value:
  295. A pointer to the end of the hex string is returned.
  296. --*/
  297. {
  298. *String++ = HexDigits[(Number >> 4) & 0x0F];
  299. *String++ = HexDigits[Number & 0x0F];
  300. return(String);
  301. }
  302. RPC_CHAR PAPI *
  303. RPC_UUID::ConvertToString (
  304. OUT RPC_CHAR PAPI * String
  305. )
  306. /*++
  307. Routine Description:
  308. The string representation of this uuid is written into the string
  309. argument. The printf statement used to print a uuid follows.
  310. printf("%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
  311. Uuid.Data1, Uuid.Data2, Uuid.Data3, Uuid.Data4[0],
  312. Uuid.Data4[1], Uuid.Data4[2], Uuid.Data4[3], Uuid.Data4[4],
  313. Uuid.Data4[5], Uuid.Data4[6], Uuid.Data4[7]);
  314. Arguments:
  315. String - Returns the string representation of the uuid.
  316. Return Value:
  317. A pointer to the end of the string representation of the uuid is
  318. returned.
  319. --*/
  320. {
  321. String = ULongToHexString(String, Uuid.Data1);
  322. *String++ = RPC_CONST_CHAR('-');
  323. String = UShortToHexString(String, Uuid.Data2);
  324. *String++ = RPC_CONST_CHAR('-');
  325. String = UShortToHexString(String, Uuid.Data3);
  326. *String++ = RPC_CONST_CHAR('-');
  327. String = UCharToHexString(String, Uuid.Data4[0]);
  328. String = UCharToHexString(String, Uuid.Data4[1]);
  329. *String++ = RPC_CONST_CHAR('-');
  330. String = UCharToHexString(String, Uuid.Data4[2]);
  331. String = UCharToHexString(String, Uuid.Data4[3]);
  332. String = UCharToHexString(String, Uuid.Data4[4]);
  333. String = UCharToHexString(String, Uuid.Data4[5]);
  334. String = UCharToHexString(String, Uuid.Data4[6]);
  335. String = UCharToHexString(String, Uuid.Data4[7]);
  336. return(String);
  337. }
  338. int
  339. RPC_UUID::IsNullUuid (
  340. )
  341. /*++
  342. Routine Description:
  343. This predicate tests whether this is the null uuid or not.
  344. Return Value:
  345. FALSE - This is not the null uuid.
  346. TRUE - This is the null uuid.
  347. --*/
  348. {
  349. unsigned long PAPI * Vector;
  350. Vector = (unsigned long PAPI *) &Uuid;
  351. if ( (Vector[0] == 0)
  352. && (Vector[1] == 0)
  353. && (Vector[2] == 0)
  354. && (Vector[3] == 0))
  355. return(TRUE);
  356. return(FALSE);
  357. }
  358. unsigned short
  359. RPC_UUID::HashUuid (
  360. )
  361. /*++
  362. Routine Description:
  363. This routine computes a unsigned short hash value for the Uuid.
  364. Return Value:
  365. A hash value.
  366. --*/
  367. {
  368. unsigned short __RPC_FAR *Values;
  369. Values = (unsigned short __RPC_FAR *)&Uuid;
  370. return( Values[0] ^ Values[1] ^ Values[2] ^ Values[3]
  371. ^ Values[4] ^ Values[5] ^ Values[6] ^ Values[7] );
  372. }
  373. void ByteSwapUuid(
  374. RPC_UUID PAPI *pRpcUuid
  375. )
  376. {
  377. UUID PAPI *pUuid = (UUID PAPI *)pRpcUuid;
  378. ByteSwapLong(pUuid->Data1);
  379. ByteSwapShort(pUuid->Data2);
  380. ByteSwapShort(pUuid->Data3);
  381. }