Source code of Windows XP (NT5)
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.

274 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name:
  4. client.c
  5. Abstract:
  6. This module contains the message client code.
  7. Author:
  8. Michael Tsang (MikeTs) 25-May-2000
  9. Environment:
  10. User mode
  11. Revision History:
  12. --*/
  13. #include "pch.h"
  14. //
  15. // Global Data
  16. //
  17. DWORD gdwfWinTrace = 0;
  18. CLIENTINFO gClientInfo = {0};
  19. char gszClientName[MAX_CLIENTNAME_LEN] = {0};
  20. HANDLE ghTraceMutex = NULL;
  21. HANDLE ghClientThread = (HANDLE)-1;
  22. HCLIENT ghClient = 0;
  23. PSZ gpszProcName = NULL;
  24. RPC_BINDING_HANDLE ghTracerBinding = NULL;
  25. /*++
  26. @doc INTERNAL
  27. @func VOID | ClientThread | Client thread procedure.
  28. @parm IN PSZ | pszClientName | Points to client name string.
  29. @rvalue None.
  30. --*/
  31. VOID __cdecl
  32. ClientThread(
  33. IN PSZ pszClientName
  34. )
  35. {
  36. WTTRACEPROC("ClientThread", 1)
  37. BOOL fDone = FALSE;
  38. RPC_STATUS status;
  39. unsigned char *StringBinding = NULL;
  40. WTENTER(("(ClientName=%s)\n", pszClientName));
  41. while (!fDone)
  42. {
  43. if ((status = RpcStringBindingCompose(NULL,
  44. TEXT("ncalrpc"),
  45. NULL,
  46. NULL,
  47. NULL,
  48. &StringBinding)) != RPC_S_OK)
  49. {
  50. WTERRPRINT(("RpcStringBindingCompose failed (status=%d)\n",
  51. status));
  52. break;
  53. }
  54. else if ((status = RpcBindingFromStringBinding(StringBinding,
  55. &ghTracerBinding)) !=
  56. RPC_S_OK)
  57. {
  58. WTERRPRINT(("RpcBindingFromStringBinding failed (status=%d)\n",
  59. status));
  60. break;
  61. }
  62. else if ((status = RpcBindingSetAuthInfo(ghTracerBinding,
  63. NULL,
  64. RPC_C_AUTHN_LEVEL_NONE,
  65. RPC_C_AUTHN_WINNT,
  66. NULL,
  67. 0)) != RPC_S_OK)
  68. {
  69. WTERRPRINT(("RpcBindingSetAuthInfo failed (status=%d)\n", status));
  70. break;
  71. }
  72. else
  73. {
  74. RPC_TRY("WTRegisterClient",
  75. ghClient = WTRegisterClient(ghTracerBinding,
  76. pszClientName));
  77. if (ghClient == 0)
  78. {
  79. WTWARNPRINT(("Failed to register client \"%s\", try again later...\n",
  80. pszClientName));
  81. }
  82. else
  83. {
  84. //
  85. // Service server callback requests. This call does not
  86. // come back until the server terminates the link.
  87. //
  88. gdwfWinTrace |= WTF_CLIENT_READY;
  89. RPC_TRY("WTDispatchServerRequests",
  90. WTDispatchServerRequests(ghTracerBinding, ghClient));
  91. gdwfWinTrace &= ~WTF_CLIENT_READY;
  92. }
  93. }
  94. if (StringBinding != NULL)
  95. {
  96. RpcStringFree(&StringBinding);
  97. StringBinding = NULL;
  98. }
  99. if (gdwfWinTrace & WTF_TERMINATING)
  100. {
  101. break;
  102. }
  103. Sleep(TIMEOUT_WAIT_SERVER);
  104. }
  105. _endthread();
  106. WTEXIT(("!\n"));
  107. return;
  108. } //ClientThread
  109. /*++
  110. @doc EXTERNAL
  111. @func VOID | WTGetClientInfo | Get client info.
  112. @parm IN PCLIENTINFO | ClientInfo | Points to the buffer to hold client
  113. info.
  114. @rvalue None.
  115. --*/
  116. VOID
  117. WTGetClientInfo(
  118. IN PCLIENTINFO ClientInfo
  119. )
  120. {
  121. WTTRACEPROC("WTGetClientInfo", 1)
  122. WTENTER(("(ClientInfo=%p)\n", ClientInfo));
  123. *ClientInfo = gClientInfo;
  124. WTEXIT(("!\n"));
  125. return;
  126. } //WTGetClientInfo
  127. /*++
  128. @doc EXTERNAL
  129. @func VOID | WTSetClientInfo | Set client info.
  130. @parm IN PCLIENTINFO | ClientInfo | Points to the client info.
  131. info.
  132. @rvalue None.
  133. --*/
  134. VOID
  135. WTSetClientInfo(
  136. IN PCLIENTINFO ClientInfo
  137. )
  138. {
  139. WTTRACEPROC("WTSetClientInfo", 1)
  140. WTENTER(("(ClientInfo=%p)\n", ClientInfo));
  141. gClientInfo = *ClientInfo;
  142. WTEXIT(("!\n"));
  143. return;
  144. } //WTSetClientInfo
  145. /*++
  146. @doc INTERNAL
  147. @func PTRIGPT | FindTrigPt |
  148. Determine if the given procedure is a trigger point.
  149. @parm IN PSZ | pszProcName | Points to procedure name string.
  150. @rvalue SUCCESS | Returns the trigger point found.
  151. @rvalue FAILURE | Returns NULL.
  152. --*/
  153. PTRIGPT LOCAL
  154. FindTrigPt(
  155. IN PSZ pszProcName
  156. )
  157. {
  158. WTTRACEPROC("FindTrigPt", 3)
  159. PTRIGPT TrigPt = NULL;
  160. int i;
  161. WTENTER(("(ProcName=%s)\n", pszProcName));
  162. for (i = 0; i < NUM_TRIGPTS; ++i)
  163. {
  164. if ((gClientInfo.TrigPts[i].dwfTrigPt &
  165. (TRIGPT_TRACE_ENABLED | TRIGPT_BREAK_ENABLED)) &&
  166. strstr(pszProcName, gClientInfo.TrigPts[i].szProcName))
  167. {
  168. TrigPt = &gClientInfo.TrigPts[i];
  169. break;
  170. }
  171. }
  172. WTEXIT(("=%p\n", TrigPt));
  173. return TrigPt;
  174. } //FindTrigPt
  175. /*++
  176. @doc EXTERNAL
  177. @func void __RPC_FAR * | MIDL_alloc | MIDL allocate.
  178. @parm IN size_t | len | size of allocation.
  179. @rvalue SUCCESS | Returns the pointer to the memory allocated.
  180. @rvalue FAILURE | Returns NULL.
  181. --*/
  182. void __RPC_FAR * __RPC_USER
  183. MIDL_alloc(
  184. IN size_t len
  185. )
  186. {
  187. WTTRACEPROC("MIDL_alloc", 5)
  188. void __RPC_FAR *ptr;
  189. WTENTER(("(len=%d)\n", len));
  190. ptr = malloc(len);
  191. WTEXIT(("=%p\n", ptr));
  192. return ptr;
  193. } //MIDL_alloc
  194. /*++
  195. @doc EXTERNAL
  196. @func void | MIDL_free | MIDL free.
  197. @parm IN void __PRC_FAR * | ptr | Points to the memory to be freed.
  198. @rvalue None.
  199. --*/
  200. void __RPC_USER
  201. MIDL_free(
  202. IN void __RPC_FAR *ptr
  203. )
  204. {
  205. WTTRACEPROC("MIDL_free", 5)
  206. WTENTER(("(ptr=%p)\n", ptr));
  207. free(ptr);
  208. WTEXIT(("!\n"));
  209. return;
  210. } //MIDL_free