Leaked source code of windows server 2003
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.

255 lines
6.0 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. Module Name:
  4. uuidfmt.c {v1.00}
  5. Abstract:
  6. This module contains I_UuidStringGenerate, which coalesces
  7. the procedures UuidCreate and UuidToString to create a UUID
  8. in one of the formats IDL, C struct, or plain.
  9. Author:
  10. Joev Dubach (t-joevd) 6/11/92
  11. Revision History:
  12. --*/
  13. //
  14. // Defines
  15. //
  16. #define IDL_STR "[\nuuid(%s),\nversion(1.0)\n]\ninterface %s\n{\n\n}\n"
  17. //
  18. // Inclusions
  19. //
  20. // The order in which these includes are performed seems, after
  21. // extensive testing and analysis, to be highly crucial to a
  22. // successful NT build.
  23. #include <sysinc.h>
  24. #include <rpc.h>
  25. #include <uuidfmt.h>
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. //
  29. // Function prototypes.
  30. //
  31. void GenUuidAsIDL (
  32. char PAPI * MyUuidString,
  33. char PAPI * UuidFormattedString,
  34. char PAPI * InterfaceName
  35. );
  36. void GenUuidAsCStruct (
  37. char PAPI * MyUuidString,
  38. char PAPI * UuidFormattedString,
  39. char PAPI * InterfaceName
  40. );
  41. void GenUuidPlain (
  42. char PAPI * MyUuidString,
  43. char PAPI * UuidFormattedString
  44. );
  45. void __RPC_FAR * __RPC_API
  46. MIDL_user_allocate(
  47. size_t size
  48. )
  49. {
  50. return malloc(size);
  51. }
  52. void __RPC_API
  53. MIDL_user_free(
  54. void __RPC_FAR * pvBuf
  55. )
  56. {
  57. free(pvBuf);
  58. }
  59. /*
  60. Routine Description:
  61. This routine creates a UUID in one of several string representations.
  62. Arguments:
  63. Flag - UUIDGEN_FORMAT_IDL gives an IDL template;
  64. UUIDGEN_FORMAT_CSTRUCT gives a C Struct;
  65. UUIDGEN_FORMAT_PLAIN gives a plain UUID.
  66. UuidFormattedString - Must be preinitialized; will contain result.
  67. InterfaceName - Name of desired interface; used for IDL and C Structs.
  68. Return Value:
  69. RPC_S_OK - We successfully converted the UUID into its string
  70. representation.
  71. RPC_S_OUT_OF_MEMORY - Insufficient memory is available to allocate
  72. a string.
  73. RPC_S_UUID_NO_ADDRESS - We were unable to obtain the ethernet or
  74. token ring address for this machine.
  75. */
  76. RPC_STATUS I_UuidStringGenerate(
  77. int Flag,
  78. int Sequential,
  79. int AllCaps,
  80. char PAPI * UuidFormattedString,
  81. char PAPI * InterfaceName
  82. )
  83. {
  84. UUID MyUuid; // Storage for a retrieved UUID.
  85. char PAPI * MyUuidString;
  86. RPC_STATUS Result;
  87. int LocalOnly = 0;
  88. ASSERT( (Flag == UUIDGEN_FORMAT_IDL)
  89. || (Flag == UUIDGEN_FORMAT_CSTRUCT)
  90. || (Flag == UUIDGEN_FORMAT_PLAIN));
  91. if (Sequential)
  92. {
  93. Result = UuidCreateSequential(&MyUuid);
  94. }
  95. else
  96. {
  97. Result = UuidCreate(&MyUuid);
  98. }
  99. ASSERT( (Result == RPC_S_UUID_NO_ADDRESS)
  100. || (Result == RPC_S_OK)
  101. || (Result == RPC_S_UUID_LOCAL_ONLY) );
  102. if (Result == RPC_S_UUID_LOCAL_ONLY)
  103. {
  104. Result = RPC_S_OK;
  105. LocalOnly = 1;
  106. }
  107. if (Result == RPC_S_OK)
  108. {
  109. Result = UuidToString(
  110. &MyUuid,
  111. &MyUuidString
  112. );
  113. ASSERT((Result == RPC_S_OK) || (Result == RPC_S_OUT_OF_MEMORY));
  114. if (Result == RPC_S_OK)
  115. {
  116. if (AllCaps) {
  117. char *p = MyUuidString;
  118. while (*p)
  119. {
  120. *p= (char)toupper(*p);
  121. p++;
  122. }
  123. }
  124. switch(Flag)
  125. {
  126. case UUIDGEN_FORMAT_IDL:
  127. GenUuidAsIDL(
  128. MyUuidString,
  129. UuidFormattedString,
  130. InterfaceName
  131. );
  132. break;
  133. case UUIDGEN_FORMAT_CSTRUCT:
  134. GenUuidAsCStruct(
  135. MyUuidString,
  136. UuidFormattedString,
  137. InterfaceName
  138. );
  139. break;
  140. case UUIDGEN_FORMAT_PLAIN:
  141. GenUuidPlain(
  142. MyUuidString,
  143. UuidFormattedString
  144. );
  145. } // end switch
  146. RpcStringFree(&MyUuidString);
  147. } // end if
  148. } // end if
  149. if ( (Result == RPC_S_OK)
  150. && (LocalOnly) )
  151. {
  152. return(RPC_S_UUID_LOCAL_ONLY);
  153. }
  154. return(Result);
  155. } // end I_UuidStringGenerate
  156. void GenUuidAsIDL (
  157. char PAPI * MyUuidString,
  158. char PAPI * UuidFormattedString,
  159. char PAPI * InterfaceName
  160. )
  161. {
  162. sprintf(
  163. UuidFormattedString,
  164. IDL_STR,
  165. MyUuidString,
  166. InterfaceName
  167. );
  168. }
  169. void GenUuidAsCStruct (
  170. char PAPI * MyUuidString,
  171. char PAPI * UuidFormattedString,
  172. char PAPI * InterfaceName
  173. )
  174. {
  175. int i;
  176. char temp[157] =
  177. "%s = { /* ........-....-....-....-............ */\n"
  178. " 0x........,\n"
  179. " 0x....,\n"
  180. " 0x....,\n"
  181. " {0x.., 0x.., 0x.., 0x.., 0x.., 0x.., 0x.., 0x..}\n"
  182. " };\n\0";
  183. for (i=0; i<36; i++) temp[10+i] = MyUuidString[i];
  184. for (i=0; i<8; i++) temp[56+i] = MyUuidString[i];
  185. for (i=0; i<4; i++) temp[72+i] = MyUuidString[9+i];
  186. for (i=0; i<4; i++) temp[84+i] = MyUuidString[14+i];
  187. for (i=0; i<2; i++) temp[97+i] = MyUuidString[19+i];
  188. for (i=0; i<2; i++) temp[103+i] = MyUuidString[21+i];
  189. for (i=0; i<2; i++) temp[109+i] = MyUuidString[24+i];
  190. for (i=0; i<2; i++) temp[115+i] = MyUuidString[26+i];
  191. for (i=0; i<2; i++) temp[121+i] = MyUuidString[28+i];
  192. for (i=0; i<2; i++) temp[127+i] = MyUuidString[30+i];
  193. for (i=0; i<2; i++) temp[133+i] = MyUuidString[32+i];
  194. for (i=0; i<2; i++) temp[139+i] = MyUuidString[34+i];
  195. sprintf(UuidFormattedString, temp, InterfaceName);
  196. }
  197. void GenUuidPlain (
  198. char PAPI * MyUuidString,
  199. char PAPI * UuidFormattedString
  200. )
  201. {
  202. strcpy(UuidFormattedString, MyUuidString);
  203. strcat(UuidFormattedString, "\n");
  204. }