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.

327 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 1997 - 98, Microsoft Corporation
  3. Module Name:
  4. rtmmetd.c
  5. Abstract:
  6. Contains routines that deals with invocation
  7. of methods that entities export to other
  8. entities for the purpose of interpreting
  9. entity specific data.
  10. Author:
  11. Chaitanya Kodeboyina (chaitk) 22-Aug-1998
  12. Revision History:
  13. --*/
  14. #include "pchrtm.h"
  15. #pragma hdrstop
  16. DWORD
  17. WINAPI
  18. RtmGetEntityMethods (
  19. IN RTM_ENTITY_HANDLE RtmRegHandle,
  20. IN RTM_ENTITY_HANDLE EntityHandle,
  21. IN OUT PUINT NumMethods,
  22. OUT PRTM_ENTITY_EXPORT_METHOD ExptMethods
  23. )
  24. /*++
  25. Routine Description:
  26. Retrieves the set of methods exported by a given entity.
  27. Arguments:
  28. RtmRegHandle - RTM registration handle for calling entity,
  29. EntityHandle - RTM handle for entity whose methods we want,
  30. NumMethods - Number of methods that can be filled
  31. is passed in, and number of methods
  32. exported by this entity is returned,
  33. ExptMethods - Set of methods requested by the caller.
  34. Return Value:
  35. Status of the operation
  36. --*/
  37. {
  38. PRTM_ENTITY_EXPORT_METHODS EntityMethods;
  39. PENTITY_INFO Entity;
  40. DWORD Status;
  41. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  42. VALIDATE_ENTITY_HANDLE(EntityHandle, &Entity);
  43. EntityMethods = &Entity->EntityMethods;
  44. //
  45. // Does the caller just need number of methods ?
  46. //
  47. if (*NumMethods == 0)
  48. {
  49. *NumMethods = EntityMethods->NumMethods;
  50. return NO_ERROR;
  51. }
  52. //
  53. // Check if we have space to copy all methods
  54. //
  55. if (EntityMethods->NumMethods > *NumMethods)
  56. {
  57. Status = ERROR_INSUFFICIENT_BUFFER;
  58. }
  59. else
  60. {
  61. Status = NO_ERROR;
  62. *NumMethods = EntityMethods->NumMethods;
  63. }
  64. //
  65. // Copy as many methods as u can fit in output
  66. //
  67. ASSERT(ExptMethods != NULL);
  68. CopyMemory(ExptMethods,
  69. EntityMethods->Methods,
  70. *NumMethods * sizeof(RTM_ENTITY_EXPORT_METHOD));
  71. *NumMethods = EntityMethods->NumMethods;
  72. return Status;
  73. }
  74. DWORD
  75. WINAPI
  76. RtmInvokeMethod (
  77. IN RTM_ENTITY_HANDLE RtmRegHandle,
  78. IN RTM_ENTITY_HANDLE EntityHandle,
  79. IN PRTM_ENTITY_METHOD_INPUT Input,
  80. IN OUT PUINT OutputSize,
  81. OUT PRTM_ENTITY_METHOD_OUTPUT Output
  82. )
  83. /*++
  84. Routine Description:
  85. Invokes a method exported by another entity
  86. Arguments:
  87. RtmRegHandle - RTM registration handle for calling entity,
  88. EntityHandle - Handle for entity whose method we are invoking,
  89. Input - Input buffer with the following information
  90. - Methods to be invoked,
  91. - Common Input buffer to all these methods,
  92. OutputSize - Size of the output buffer is passed in, and
  93. the number of bytes filled in output is retd,
  94. Output - Output buffer that is filled in the format of
  95. a series of (Method Id, Corr. Output) tuples
  96. Return Value:
  97. Status of the operation
  98. --*/
  99. {
  100. PRTM_ENTITY_EXPORT_METHODS EntityMethods;
  101. PENTITY_INFO Entity;
  102. DWORD MethodsCalled;
  103. DWORD MethodsLeft;
  104. UINT OutputHdrSize;
  105. UINT OutBytes;
  106. UINT BytesTotal;
  107. UINT BytesLeft;
  108. UINT i;
  109. BytesTotal = BytesLeft = *OutputSize;
  110. *OutputSize = 0;
  111. DBG_VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  112. //
  113. // Validate the entity and target handles passed in
  114. //
  115. VALIDATE_ENTITY_HANDLE(EntityHandle, &Entity);
  116. //
  117. // Call each method in 'methods to be called' mask.
  118. //
  119. MethodsCalled = MethodsLeft = Input->MethodType;
  120. ACQUIRE_ENTITY_METHODS_READ_LOCK(Entity);
  121. if (Entity->State == ENTITY_STATE_DEREGISTERED)
  122. {
  123. RELEASE_ENTITY_METHODS_READ_LOCK(Entity);
  124. return ERROR_INVALID_HANDLE;
  125. }
  126. OutputHdrSize = FIELD_OFFSET(RTM_ENTITY_METHOD_OUTPUT, OutputData);
  127. EntityMethods = &Entity->EntityMethods;
  128. for (i = 0; (i < EntityMethods->NumMethods) && (MethodsLeft); i++)
  129. {
  130. //
  131. // Do we have bytes left for next method's output ?
  132. //
  133. if (BytesLeft < OutputHdrSize)
  134. {
  135. break;
  136. }
  137. //
  138. // If next method in list, prepare input and invoke
  139. //
  140. if (MethodsLeft & 0x01)
  141. {
  142. Input->MethodType = Output->MethodType = (1 << i);
  143. Output->OutputSize = BytesLeft - OutputHdrSize;
  144. //
  145. // Initialize the output params of this method
  146. //
  147. Output->OutputSize = 0;
  148. Output->MethodStatus = ERROR_NOT_SUPPORTED;
  149. //
  150. // If method supported, invoke with input/output
  151. //
  152. if (EntityMethods->Methods[i])
  153. {
  154. EntityMethods->Methods[i](RtmRegHandle,
  155. EntityHandle,
  156. Input,
  157. Output);
  158. }
  159. OutBytes = Output->OutputSize + OutputHdrSize;
  160. Output = (PRTM_ENTITY_METHOD_OUTPUT) (OutBytes + (PUCHAR) Output);
  161. BytesLeft -= OutBytes;
  162. }
  163. MethodsLeft >>= 1;
  164. }
  165. RELEASE_ENTITY_METHODS_READ_LOCK(Entity);
  166. Input->MethodType = MethodsCalled;
  167. *OutputSize = BytesTotal - BytesLeft;
  168. return NO_ERROR;
  169. }
  170. DWORD
  171. WINAPI
  172. RtmBlockMethods (
  173. IN RTM_ENTITY_HANDLE RtmRegHandle,
  174. IN HANDLE TargetHandle OPTIONAL,
  175. IN UCHAR TargetType OPTIONAL,
  176. IN DWORD BlockingFlag
  177. )
  178. /*++
  179. Routine Description:
  180. Blocks or unblocks the execution of methods on the target
  181. handle or on all targets if the target handle is NULL.
  182. Arguments:
  183. RtmRegHandle - RTM registration handle for calling entity,
  184. TargetHandle - Destination, Route or NextHop Handle
  185. TargetType - Type of the TargetHandle (DEST_TYPE, ...)
  186. BlockingFlag - RTM_BLOCK_METHODS or RTM_RESUME_METHODS
  187. to block, unblock method invocations resp.
  188. Return Value:
  189. Status of the operation
  190. --*/
  191. {
  192. PENTITY_INFO Entity;
  193. VALIDATE_ENTITY_HANDLE(RtmRegHandle, &Entity);
  194. UNREFERENCED_PARAMETER(TargetType);
  195. UNREFERENCED_PARAMETER(TargetHandle);
  196. #if DBG
  197. //
  198. // No method locks on the target used at present
  199. //
  200. if (ARGUMENT_PRESENT(TargetHandle))
  201. {
  202. PVOID Target;
  203. VALIDATE_OBJECT_HANDLE(TargetHandle, TargetType, &Target);
  204. }
  205. #endif
  206. if (BlockingFlag == RTM_BLOCK_METHODS)
  207. {
  208. ACQUIRE_ENTITY_METHODS_WRITE_LOCK(Entity);
  209. }
  210. else
  211. {
  212. RELEASE_ENTITY_METHODS_WRITE_LOCK(Entity);
  213. }
  214. return NO_ERROR;
  215. }