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.

327 lines
5.8 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. Util.hxx
  5. Author:
  6. Mario Goertzel [MarioGo]
  7. Revision History:
  8. MarioGo 1/13/1997 Bits 'n pieces
  9. --*/
  10. #ifdef TRANSPORT_DLL
  11. inline
  12. PVOID __cdecl
  13. operator new(
  14. size_t size
  15. )
  16. {
  17. return(I_RpcAllocate(size));
  18. }
  19. inline
  20. void __cdecl
  21. operator delete(
  22. PVOID ptr
  23. )
  24. {
  25. I_RpcFree(ptr);
  26. }
  27. #endif
  28. inline
  29. PVOID __cdecl
  30. operator new(
  31. size_t size,
  32. size_t extra
  33. )
  34. {
  35. return (PVOID) new char[size+extra];
  36. }
  37. inline
  38. PVOID __cdecl
  39. operator new(
  40. size_t size,
  41. PVOID pPlacement
  42. )
  43. {
  44. return pPlacement;
  45. }
  46. inline BOOL
  47. IsNumeric(
  48. PCHAR String
  49. )
  50. /*++
  51. Routine Description:
  52. Determines if a string is made of only decimal numbers
  53. --*/
  54. {
  55. while(*String)
  56. {
  57. // REVIEW - could subtract and compare - check generated code.
  58. if ( *String < '0'
  59. || *String > '9' )
  60. {
  61. return(FALSE);
  62. }
  63. String++;
  64. }
  65. return(TRUE);
  66. }
  67. inline BOOL
  68. IsNumeric(
  69. RPC_CHAR *String
  70. )
  71. /*++
  72. Routine Description:
  73. Determines if a string is made of only decimal numbers
  74. --*/
  75. {
  76. while(*String)
  77. {
  78. // REVIEW - could subtract and compare - check generated code.
  79. if ( *String < '0'
  80. || *String > '9' )
  81. {
  82. return(FALSE);
  83. }
  84. String++;
  85. }
  86. return(TRUE);
  87. }
  88. RPC_STATUS
  89. EndpointToPortNumber(
  90. IN RPC_CHAR *endpoint,
  91. OUT USHORT &port);
  92. RPC_STATUS
  93. EndpointToPortNumberA(
  94. IN char *endpoint,
  95. OUT USHORT &port);
  96. void
  97. PortNumberToEndpoint(
  98. IN USHORT port,
  99. OUT RPC_CHAR *pEndpoint);
  100. void
  101. PortNumberToEndpointA(
  102. IN USHORT port,
  103. OUT char *pEndpoint
  104. );
  105. UCHAR
  106. HexDigitsToBinary(
  107. IN UCHAR high,
  108. IN UCHAR low);
  109. char * _cdecl
  110. RpcStrTok(
  111. IN char * string,
  112. IN const char * control,
  113. IN OUT char ** ppStrPrev
  114. );
  115. DWORD
  116. UTIL_WaitForSyncIO(
  117. LPOVERLAPPED lpOverlapped,
  118. BOOL fAlertable,
  119. DWORD dwTimeout
  120. );
  121. DWORD
  122. UTIL_WaitForSyncHTTP2IO(
  123. IN LPOVERLAPPED lpOverlapped,
  124. IN HANDLE hEvent,
  125. IN BOOL fAlertable,
  126. IN DWORD dwTimeout
  127. );
  128. RPC_STATUS
  129. UTIL_GetOverlappedResultEx(
  130. RPC_TRANSPORT_CONNECTION ThisConnection,
  131. LPOVERLAPPED lpOverlapped,
  132. LPDWORD lpNumberOfBytesTransferred,
  133. BOOL fAlertable,
  134. DWORD dwTimeout
  135. );
  136. RPC_STATUS
  137. UTIL_GetOverlappedHTTP2ResultEx(
  138. RPC_TRANSPORT_CONNECTION ThisConnection,
  139. IN LPOVERLAPPED lpOverlapped,
  140. IN HANDLE hEvent,
  141. IN BOOL fAlertable,
  142. IN DWORD dwTimeout
  143. );
  144. inline RPC_STATUS
  145. UTIL_GetOverlappedResult(
  146. RPC_TRANSPORT_CONNECTION ThisConnection,
  147. LPOVERLAPPED lpOverlapped,
  148. LPDWORD lpNumberOfBytesTransferred
  149. )
  150. {
  151. return (UTIL_GetOverlappedResultEx(ThisConnection,
  152. lpOverlapped,
  153. lpNumberOfBytesTransferred,
  154. FALSE,
  155. INFINITE));
  156. }
  157. FORCE_INLINE
  158. RPC_STATUS
  159. UTIL_ReadFile(
  160. IN HANDLE hFile,
  161. IN LPVOID lpBuffer,
  162. IN DWORD nNumberOfBytesToRead,
  163. OUT LPDWORD lpNumberOfBytesRead,
  164. IN OUT LPOVERLAPPED lpOverlapped
  165. )
  166. {
  167. LARGE_INTEGER Li;
  168. NTSTATUS Status;
  169. lpOverlapped->Internal = STATUS_PENDING;
  170. Li.QuadPart = 0;
  171. Status = NtReadFile(
  172. hFile,
  173. lpOverlapped->hEvent,
  174. NULL,
  175. PtrToUlong(lpOverlapped->hEvent) & 1 ? NULL : lpOverlapped,
  176. (PIO_STATUS_BLOCK)&lpOverlapped->Internal,
  177. lpBuffer,
  178. nNumberOfBytesToRead,
  179. &Li,
  180. NULL);
  181. if (Status == STATUS_PENDING)
  182. {
  183. // Shortcut the common path
  184. return(ERROR_IO_PENDING);
  185. }
  186. if (NT_SUCCESS(Status))
  187. {
  188. *lpNumberOfBytesRead = (ULONG) (lpOverlapped->InternalHigh);
  189. return(RPC_S_OK);
  190. }
  191. return(RtlNtStatusToDosError(Status));
  192. }
  193. FORCE_INLINE
  194. RPC_STATUS
  195. UTIL_WriteFile(
  196. IN HANDLE hFile,
  197. IN LPCVOID lpBuffer,
  198. IN DWORD nNumberOfBytesToWrite,
  199. OUT LPDWORD lpNumberOfBytesWritten,
  200. IN OUT LPOVERLAPPED lpOverlapped
  201. )
  202. {
  203. LARGE_INTEGER Li;
  204. NTSTATUS Status;
  205. lpOverlapped->Internal = STATUS_PENDING;
  206. Li.QuadPart = 0;
  207. Status = NtWriteFile(
  208. hFile,
  209. lpOverlapped->hEvent,
  210. NULL,
  211. PtrToUlong(lpOverlapped->hEvent) & 1 ? NULL : lpOverlapped,
  212. (PIO_STATUS_BLOCK)&lpOverlapped->Internal,
  213. (PVOID)lpBuffer,
  214. nNumberOfBytesToWrite,
  215. &Li,
  216. NULL
  217. );
  218. if (Status == STATUS_PENDING)
  219. {
  220. // Shortcut the common path
  221. return(ERROR_IO_PENDING);
  222. }
  223. if (NT_SUCCESS(Status))
  224. {
  225. *lpNumberOfBytesWritten = (ULONG) (lpOverlapped->InternalHigh);
  226. return(RPC_S_OK);
  227. }
  228. return(RtlNtStatusToDosError(Status));
  229. }
  230. FORCE_INLINE
  231. RPC_STATUS
  232. UTIL_WriteFile2(
  233. IN HANDLE hFile,
  234. IN LPCVOID lpBuffer,
  235. IN DWORD nNumberOfBytesToWrite,
  236. IN OUT LPOVERLAPPED lpOverlapped
  237. )
  238. {
  239. LARGE_INTEGER Li;
  240. NTSTATUS Status;
  241. lpOverlapped->Internal = STATUS_PENDING;
  242. Li.QuadPart = 0;
  243. Status = NtWriteFile(
  244. hFile,
  245. lpOverlapped->hEvent,
  246. NULL,
  247. PtrToUlong(lpOverlapped->hEvent) & 1 ? NULL : lpOverlapped,
  248. (PIO_STATUS_BLOCK)&lpOverlapped->Internal,
  249. (PVOID)lpBuffer,
  250. nNumberOfBytesToWrite,
  251. &Li,
  252. NULL
  253. );
  254. if (Status == STATUS_PENDING)
  255. {
  256. // Shortcut the common path
  257. return(ERROR_IO_PENDING);
  258. }
  259. if (NT_SUCCESS(Status))
  260. {
  261. return(RPC_S_OK);
  262. }
  263. return(RtlNtStatusToDosError(Status));
  264. }
  265. #ifndef ARGUMENT_PRESENT
  266. #define ARGUMENT_PRESENT(Argument) (Argument != 0)
  267. #endif // ARGUMENT_PRESENT