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.

273 lines
6.7 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1991 - 1999
  3. Module Name:
  4. dcestrng.cxx
  5. Abstract:
  6. This module contains the code for the String Object DCE RPC runtime
  7. APIs, as well as the APIs which compose and parse string bindings.
  8. Author:
  9. Michael Montague (mikemon) 25-Sep-1991
  10. Revision History:
  11. --*/
  12. #include <precomp.hxx>
  13. RPC_STATUS RPC_ENTRY
  14. RpcStringBindingCompose (
  15. IN unsigned short PAPI * ObjUuid OPTIONAL,
  16. IN unsigned short PAPI * Protseq OPTIONAL,
  17. IN unsigned short PAPI * NetworkAddr OPTIONAL,
  18. IN unsigned short PAPI * Endpoint OPTIONAL,
  19. IN unsigned short PAPI * Options OPTIONAL,
  20. OUT unsigned short PAPI * PAPI * StringBinding OPTIONAL
  21. )
  22. /*++
  23. Routine Description:
  24. This routine combines the components of a string binding into a
  25. string binding. Empty fields in the string binding can be specified
  26. by passing a NULL argument value or by providing an empty string ("").
  27. Arguments:
  28. ObjUuid - Optionally supplies a string representation of an object UUID.
  29. Protseq - Optionally supplies a string representation of a protocol
  30. sequence.
  31. NetworkAddr - Optionally supplies a string representation of a
  32. network address.
  33. Endpoint - Optionally supplies a string representation of an endpoint.
  34. Options - Optionally supplies a string representation of network options.
  35. StringBinding - Optionally returns the string binding composed from the
  36. pieces specified by the other parameters.
  37. Return Value:
  38. RPC_S_OK - The operation completed successfully.
  39. RPC_S_OUT_OF_MEMORY - Insuffient memory is available to allocate space
  40. for the string binding.
  41. --*/
  42. {
  43. DCE_BINDING * DceBinding;
  44. RPC_STATUS Status;
  45. InitializeIfNecessary();
  46. // If the caller did not want us to return the string binding, then
  47. // do not even bother to compose one.
  48. if (!ARGUMENT_PRESENT(StringBinding))
  49. {
  50. return (RPC_S_OK);
  51. }
  52. DceBinding = new DCE_BINDING(ObjUuid, Protseq, NetworkAddr, Endpoint,
  53. Options, &Status);
  54. if (DceBinding == 0)
  55. return(RPC_S_OUT_OF_MEMORY);
  56. if (Status != RPC_S_OK)
  57. {
  58. delete DceBinding;
  59. return(Status);
  60. }
  61. *StringBinding = DceBinding->StringBindingCompose(0);
  62. delete DceBinding;
  63. if (*StringBinding == 0)
  64. return(RPC_S_OUT_OF_MEMORY);
  65. return(RPC_S_OK);
  66. }
  67. RPC_STATUS RPC_ENTRY
  68. RpcStringBindingParse (
  69. IN unsigned short PAPI * StringBinding,
  70. OUT unsigned short PAPI * PAPI * ObjUuid OPTIONAL,
  71. OUT unsigned short PAPI * PAPI * Protseq OPTIONAL,
  72. OUT unsigned short PAPI * PAPI * NetworkAddr OPTIONAL,
  73. OUT unsigned short PAPI * PAPI * Endpoint OPTIONAL,
  74. OUT unsigned short PAPI * PAPI * NetworkOptions OPTIONAL
  75. )
  76. /*++
  77. Routine Description:
  78. RpcStringBindingParse returns as seperate strings the object UUID
  79. part and address parts of a string binding.
  80. Arguments:
  81. StringBinding - Supplies a string binding to parsed into its component
  82. parts.
  83. ObjUuid - Optionally returns the object UUID part of the string binding.
  84. Protseq - Optionally returns the protocol sequence part of the string
  85. binding.
  86. NetworkAddr - Optionally returns the network address part of the string
  87. binding.
  88. Endpoint - Optionally returns the endpoint part of the string binding.
  89. NetworkOptions - Optionally returns the network options part of the
  90. string binding.
  91. Return Value:
  92. RPC_S_OK - The operation completed successfully.
  93. RPC_S_OUT_OF_MEMORY - Insufficent memory is available to allocate
  94. space for the fields of the string binding.
  95. RPC_S_INVALID_STRING_BINDING - The string binding is syntactically
  96. invalid.
  97. RPC_S_INVALID_ARG - The string binding is not specified
  98. (ie. ARGUMENT_PRESENT(StringBinding) is false).
  99. --*/
  100. {
  101. RPC_STATUS Status;
  102. DCE_BINDING * DceBinding;
  103. RPC_CHAR __RPC_FAR * CopiedStringBinding;
  104. InitializeIfNecessary();
  105. if (!ARGUMENT_PRESENT(StringBinding))
  106. return(RPC_S_INVALID_ARG);
  107. CopiedStringBinding = (RPC_CHAR *)
  108. _alloca( (RpcpStringLength(StringBinding)+1)*(sizeof(RPC_CHAR)) );
  109. if (CopiedStringBinding == 0)
  110. {
  111. return (RPC_S_OUT_OF_MEMORY);
  112. }
  113. RpcpStringCopy(CopiedStringBinding, StringBinding);
  114. DceBinding = new DCE_BINDING(CopiedStringBinding,&Status);
  115. if ( DceBinding == 0 )
  116. {
  117. return(RPC_S_OUT_OF_MEMORY);
  118. }
  119. if ( Status != RPC_S_OK )
  120. {
  121. delete DceBinding;
  122. return(Status);
  123. }
  124. if ( ARGUMENT_PRESENT(ObjUuid) )
  125. {
  126. *ObjUuid = DceBinding->ObjectUuidCompose(&Status);
  127. }
  128. if ( ARGUMENT_PRESENT(Protseq) && (Status == RPC_S_OK))
  129. {
  130. *Protseq = DceBinding->RpcProtocolSequenceCompose(&Status);
  131. }
  132. if ( ARGUMENT_PRESENT(NetworkAddr) && (Status == RPC_S_OK))
  133. {
  134. *NetworkAddr = DceBinding->NetworkAddressCompose(&Status);
  135. }
  136. if ( ARGUMENT_PRESENT(Endpoint) && (Status == RPC_S_OK))
  137. {
  138. *Endpoint = DceBinding->EndpointCompose(&Status);
  139. }
  140. if ( ARGUMENT_PRESENT(NetworkOptions) && (Status == RPC_S_OK))
  141. {
  142. *NetworkOptions = DceBinding->OptionsCompose(&Status);
  143. }
  144. delete DceBinding;
  145. return(Status);
  146. }
  147. RPC_STATUS RPC_ENTRY
  148. RpcStringFreeW (
  149. IN OUT unsigned short PAPI * PAPI * String
  150. )
  151. /*++
  152. Routine Description:
  153. This routine frees a character string allocated by the runtime.
  154. Arguments:
  155. String - Supplies the address of the pointer to the character string
  156. to free, and returns zero.
  157. Return Values:
  158. RPC_S_OK - The operation completed successfully.
  159. RPC_S_INVALID_ARG - The String argument does not contain the address
  160. of a pointer to a character string.
  161. --*/
  162. {
  163. InitializeIfNecessary();
  164. if (String == 0)
  165. return(RPC_S_INVALID_ARG);
  166. RpcpFarFree(*String);
  167. *String = 0;
  168. return(RPC_S_OK);
  169. }
  170. RPC_STATUS RPC_ENTRY
  171. RpcStringFreeA (
  172. IN OUT unsigned char PAPI * PAPI * String
  173. )
  174. /*++
  175. Routine Description:
  176. This routine frees a character string allocated by the runtime.
  177. Arguments:
  178. String - Supplies the address of the pointer to the character string
  179. to free, and returns zero.
  180. Return Values:
  181. RPC_S_OK - The operation completed successfully.
  182. RPC_S_INVALID_ARG - The String argument does not contain the address
  183. of a pointer to a character string.
  184. --*/
  185. {
  186. return RpcStringFreeW((WCHAR **)String);
  187. }