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.

440 lines
9.5 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. svrbind.cxx
  5. Abstract:
  6. This file contains the implementation of the server binding handle
  7. class, SVR_BINDING_HANDLE.
  8. Author:
  9. Michael Montague (mikemon) 23-Nov-1991
  10. Revision History:
  11. --*/
  12. #include <precomp.hxx>
  13. RPC_STATUS
  14. SVR_BINDING_HANDLE::InsureRealBindingHandle (
  15. )
  16. /*++
  17. Routine Description:
  18. This method is used to insure that we have transformed this binding
  19. handle into a real full fledged binding handle. If we do not
  20. have a real binding handle, then we attempt to create one.
  21. Return Value:
  22. RPC_S_OK will be returned if we successfully obtain a real binding
  23. handle. Otherwise, the result of trying to create a binding handle
  24. will be returned; see DCE_BINDING::CreateBindingHandle for a list
  25. of error codes.
  26. --*/
  27. {
  28. RPC_STATUS Status;
  29. if (RealBindingHandle == 0)
  30. {
  31. RealBindingHandle = DceBinding->CreateBindingHandle(&Status);
  32. if (Status != RPC_S_OK)
  33. {
  34. RealBindingHandle = 0;
  35. return(Status);
  36. }
  37. // This binding needs to transfer its ObjectUuid, if any,
  38. // to the new binding. It is not possible to efficiently add
  39. // the object uuid to the DceBinding first.
  40. if (InqIfNullObjectUuid() == 0)
  41. {
  42. RealBindingHandle->SetObjectUuid(InqPointerAtObjectUuid());
  43. }
  44. DceBinding = 0;
  45. }
  46. return(RPC_S_OK);
  47. }
  48. SVR_BINDING_HANDLE::SVR_BINDING_HANDLE (
  49. IN DCE_BINDING * DceBinding,
  50. IN RPC_CHAR * DynamicEndpoint
  51. )
  52. /*++
  53. Routine Description:
  54. This constructor is trivial. We just stash the binding information
  55. and dynamic endpoint away for future use.
  56. Arguments:
  57. DceBinding - Supplies the binding information. Ownership of this
  58. object passes to this routine.
  59. DynamicEndpoint - Supplies the dynamic endpoint for the rpc address
  60. corresponding to this binding. Ownership of this object passes
  61. to this routine.
  62. --*/
  63. {
  64. this->DceBinding = DceBinding;
  65. RealBindingHandle = 0;
  66. if( DynamicEndpoint )
  67. {
  68. EndpointIsDynamic = 1;
  69. DceBinding->AddEndpoint(DynamicEndpoint);
  70. }
  71. else
  72. {
  73. EndpointIsDynamic = 0;
  74. }
  75. }
  76. SVR_BINDING_HANDLE::~SVR_BINDING_HANDLE (
  77. )
  78. /*++
  79. Routine Description:
  80. Since ownership of the binding information passed to the constructor
  81. of this instance, we need to delete the binding information now.
  82. Actually, before we can delete the binding information we need to
  83. check to see if ownership has passed to the real binding handle.
  84. --*/
  85. {
  86. if (DceBinding != 0)
  87. delete DceBinding;
  88. }
  89. RPC_STATUS
  90. SVR_BINDING_HANDLE::SendReceive (
  91. IN OUT PRPC_MESSAGE Message
  92. )
  93. /*++
  94. Routine Description:
  95. We need to transport the server binding handle into a full fledged
  96. binding handle, and then let the full fledged binding handle take
  97. care of performing the requested operation.
  98. Arguments:
  99. Message - Supplies and returns information describing the remote
  100. procedure call to be sent.
  101. Return Value:
  102. For possible return codes, see DCE_BINDING::CreateBindingHandle and
  103. SendReceive.
  104. --*/
  105. {
  106. RPC_STATUS Status;
  107. Status = InsureRealBindingHandle();
  108. if (Status != RPC_S_OK)
  109. return(Status);
  110. return(RealBindingHandle->SendReceive(Message));
  111. }
  112. RPC_STATUS
  113. SVR_BINDING_HANDLE::GetBuffer (
  114. IN OUT PRPC_MESSAGE Message
  115. )
  116. /*++
  117. Routine Description:
  118. We need to transport the server binding handle into a full fledged
  119. binding handle, and then let the full fledged binding handle take
  120. care of performing the requested operation.
  121. Arguments:
  122. Message - Supplies and returns information describing the buffer
  123. we need to allocate.
  124. Return Value:
  125. For possible return codes, see DCE_BINDING::CreateBindingHandle and
  126. GetBuffer.
  127. --*/
  128. {
  129. RPC_STATUS Status;
  130. Status = InsureRealBindingHandle();
  131. if (Status != RPC_S_OK)
  132. return(Status);
  133. return(RealBindingHandle->GetBuffer(Message));
  134. }
  135. void
  136. SVR_BINDING_HANDLE::FreeBuffer (
  137. IN PRPC_MESSAGE Message
  138. )
  139. /*++
  140. Routine Description:
  141. We need to transport the server binding handle into a full fledged
  142. binding handle, and then let the full fledged binding handle take
  143. care of performing the requested operation.
  144. Arguments:
  145. Message - Supplies the buffer to be freed.
  146. --*/
  147. {
  148. RPC_STATUS Status;
  149. Status = InsureRealBindingHandle();
  150. ASSERT(Status == RPC_S_OK);
  151. RealBindingHandle->FreeBuffer(Message);
  152. }
  153. RPC_STATUS
  154. SVR_BINDING_HANDLE::BindingCopy (
  155. OUT BINDING_HANDLE * PAPI * DestinationBinding,
  156. IN unsigned int MaintainContext
  157. )
  158. /*++
  159. Routine Description:
  160. We need to copy this binding handle. This is relatively easy to
  161. do: we just need to duplicate the binding information and construct
  162. another server binding handle.
  163. Arguments:
  164. DestinationBinding - Returns a copy of this binding handle.
  165. MaintainContext - Supplies a flag that indicates whether or not context
  166. is being maintained over this binding handle. A non-zero value
  167. indicates that context is being maintained.
  168. Return Value:
  169. RPC_S_OUT_OF_MEMORY - This indicates that there is not enough memory
  170. to allocate a new binding handle.
  171. RPC_S_OK - We successfully copied this binding handle.
  172. --*/
  173. {
  174. SVR_BINDING_HANDLE * Binding;
  175. DCE_BINDING * DceBinding;
  176. if (RealBindingHandle != 0)
  177. return(RealBindingHandle->BindingCopy(DestinationBinding,
  178. MaintainContext));
  179. // Even if the binding is really dynamic, the endpoint has
  180. // been added to the DceBinding in the constructor.
  181. DceBinding = this->DceBinding->DuplicateDceBinding();
  182. if (DceBinding == 0)
  183. {
  184. *DestinationBinding = 0;
  185. return(RPC_S_OUT_OF_MEMORY);
  186. }
  187. Binding = new SVR_BINDING_HANDLE(DceBinding,0);
  188. *DestinationBinding = Binding;
  189. if (Binding == 0)
  190. return(RPC_S_OUT_OF_MEMORY);
  191. return(RPC_S_OK);
  192. }
  193. RPC_STATUS
  194. SVR_BINDING_HANDLE::BindingFree (
  195. )
  196. /*++
  197. Routine Description:
  198. The application wants to free this binding handle. If there is a real
  199. binding handle, we need to invoke BindingFree on it as well; otherwise,
  200. all we have got to do is to delete it.
  201. Return Value:
  202. RPC_S_OK - This value will be returned, unless an error occurs in the
  203. BindingFree operation invoked on the real binding handle.
  204. --*/
  205. {
  206. RPC_STATUS Status;
  207. if (RealBindingHandle != 0)
  208. {
  209. Status = RealBindingHandle->BindingFree();
  210. RealBindingHandle = 0;
  211. if (Status != RPC_S_OK)
  212. return(Status);
  213. }
  214. delete this;
  215. return(RPC_S_OK);
  216. }
  217. RPC_STATUS
  218. SVR_BINDING_HANDLE::ToStringBinding (
  219. OUT RPC_CHAR PAPI * PAPI * StringBinding
  220. )
  221. /*++
  222. Routine Description:
  223. We need to convert the binding handle into a string binding. We
  224. can just use the information in this server binding handle to
  225. create the string binding.
  226. Arguments:
  227. StringBinding - Returns the string representation of the binding
  228. handle.
  229. Return Value:
  230. RPC_S_OK - The operation completed successfully.
  231. RPC_S_OUT_OF_MEMORY - We do not have enough memory available to
  232. allocate space for the string binding.
  233. --*/
  234. {
  235. if (RealBindingHandle != 0)
  236. return(RealBindingHandle->ToStringBinding(StringBinding));
  237. *StringBinding = DceBinding->StringBindingCompose(
  238. InqPointerAtObjectUuid());
  239. if (*StringBinding == 0)
  240. return(RPC_S_OUT_OF_MEMORY);
  241. return(RPC_S_OK);
  242. }
  243. RPC_STATUS
  244. SVR_BINDING_HANDLE::InquireDynamicEndpoint (
  245. OUT RPC_CHAR PAPI * PAPI * DynamicEndpoint
  246. )
  247. /*++
  248. Routine Description:
  249. This routine is used to obtain the dynamic endpoint from a binding
  250. handle which was created from an rpc address. If there is a dynamic
  251. endpoint, we just need to duplicate it, and return a pointer to it.
  252. Arguments:
  253. DynamicEndpoint - Returns a pointer to the dynamic endpoint, it is
  254. always set to zero.
  255. Return Value:
  256. RPC_S_OK - The operation completed successfully.
  257. RPC_S_OUT_OF_MEMORY - Unable to allocate memory for the endpoint string.
  258. --*/
  259. {
  260. if (EndpointIsDynamic == 1)
  261. {
  262. *DynamicEndpoint = DuplicateStringPAPI(DceBinding->InqEndpoint());
  263. if (*DynamicEndpoint == 0)
  264. return(RPC_S_OUT_OF_MEMORY);
  265. }
  266. else
  267. {
  268. *DynamicEndpoint = 0;
  269. }
  270. return(RPC_S_OK);
  271. }
  272. void
  273. SVR_BINDING_HANDLE::PrepareBindingHandle (
  274. IN void * TransportInterface,
  275. IN DCE_BINDING * DceBinding
  276. )
  277. {
  278. UNUSED(this);
  279. UNUSED(TransportInterface);
  280. UNUSED(DceBinding);
  281. ASSERT( 0 );
  282. }
  283. RPC_STATUS
  284. SVR_BINDING_HANDLE::ResolveBinding (
  285. IN PRPC_CLIENT_INTERFACE RpcClientInterface
  286. )
  287. {
  288. RPC_STATUS Status;
  289. Status = InsureRealBindingHandle();
  290. if (Status != RPC_S_OK)
  291. return (Status);
  292. return(RealBindingHandle->ResolveBinding(RpcClientInterface));
  293. }
  294. RPC_STATUS
  295. SVR_BINDING_HANDLE::BindingReset (
  296. )
  297. {
  298. RPC_STATUS Status;
  299. Status = InsureRealBindingHandle();
  300. if (Status != RPC_S_OK)
  301. return(Status);
  302. Status = RealBindingHandle->BindingReset();
  303. if (Status == RPC_S_OK)
  304. {
  305. EndpointIsDynamic = 0;
  306. }
  307. return (Status);
  308. }
  309. RPC_STATUS
  310. SVR_BINDING_HANDLE::InquireTransportType(
  311. OUT unsigned int PAPI *Type
  312. )
  313. {
  314. RPC_STATUS Status;
  315. Status = InsureRealBindingHandle();
  316. if (Status != RPC_S_OK)
  317. return(Status);
  318. return(RealBindingHandle->InquireTransportType(Type));
  319. }