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.

232 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. control.c
  5. Abstract:
  6. User-mode interface to UL.SYS.
  7. Author:
  8. Keith Moore (keithmo) 15-Dec-1998
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. //
  13. // Private macros.
  14. //
  15. //
  16. // Private prototypes.
  17. //
  18. //
  19. // Public functions.
  20. //
  21. /***************************************************************************++
  22. Routine Description:
  23. Opens a control channel to UL.SYS.
  24. Arguments:
  25. pControlChannel - Receives a handle to the control channel if successful.
  26. Options - Supplies zero or more HTTP_OPTION_* flags.
  27. Return Value:
  28. ULONG - Completion status.
  29. --***************************************************************************/
  30. ULONG
  31. WINAPI
  32. HttpOpenControlChannel(
  33. OUT PHANDLE pControlChannel,
  34. IN ULONG Options
  35. )
  36. {
  37. NTSTATUS status;
  38. //
  39. // First, just try to open the driver.
  40. //
  41. status = HttpApiOpenDriverHelper(
  42. pControlChannel, // pHandle
  43. GENERIC_READ | // DesiredAccess
  44. GENERIC_WRITE |
  45. SYNCHRONIZE,
  46. HttpApiControlChannelHandleType, // handle type
  47. NULL, // pObjectName
  48. Options, // Options
  49. FILE_OPEN, // CreateDisposition
  50. NULL // pSecurityAttributes
  51. );
  52. //
  53. // If we couldn't open the driver because it's not running, then try
  54. // to start the driver & retry the open.
  55. //
  56. if (status == STATUS_OBJECT_NAME_NOT_FOUND ||
  57. status == STATUS_OBJECT_PATH_NOT_FOUND)
  58. {
  59. if (HttpApiTryToStartDriver())
  60. {
  61. status = HttpApiOpenDriverHelper(
  62. pControlChannel, // pHandle
  63. GENERIC_READ | // DesiredAccess
  64. GENERIC_WRITE |
  65. SYNCHRONIZE,
  66. HttpApiControlChannelHandleType, // handle type
  67. NULL, // pObjectName
  68. Options, // Options
  69. FILE_OPEN, // CreateDisposition
  70. NULL // pSecurityAttributes
  71. );
  72. }
  73. }
  74. return HttpApiNtStatusToWin32Status( status );
  75. } // HttpOpenControlChannel
  76. /***************************************************************************++
  77. Routine Description:
  78. Queries information from a control channel.
  79. Arguments:
  80. ControlChannelHandle - Supplies a UL.SYS control channel handle.
  81. InformationClass - Supplies the type of information to query.
  82. pControlChannelInformation - Supplies a buffer for the query.
  83. Length - Supplies the length of pControlChannelInformation.
  84. pReturnLength - Receives the length of data written to the buffer.
  85. Return Value:
  86. ULONG - Completion status.
  87. --***************************************************************************/
  88. ULONG
  89. WINAPI
  90. HttpQueryControlChannelInformation(
  91. IN HANDLE ControlChannelHandle,
  92. IN HTTP_CONTROL_CHANNEL_INFORMATION_CLASS InformationClass,
  93. OUT PVOID pControlChannelInformation,
  94. IN ULONG Length,
  95. OUT PULONG pReturnLength OPTIONAL
  96. )
  97. {
  98. NTSTATUS status;
  99. HTTP_CONTROL_CHANNEL_INFO channelInfo;
  100. //
  101. // Initialize the input structure.
  102. //
  103. channelInfo.InformationClass = InformationClass;
  104. //
  105. // Make the request.
  106. //
  107. status = HttpApiSynchronousDeviceControl(
  108. ControlChannelHandle, // FileHandle
  109. IOCTL_HTTP_QUERY_CONTROL_CHANNEL, // IoControlCode
  110. &channelInfo, // pInputBuffer
  111. sizeof(channelInfo), // InputBufferLength
  112. pControlChannelInformation, // pOutputBuffer
  113. Length, // OutputBufferLength
  114. pReturnLength // pBytesTransferred
  115. );
  116. return HttpApiNtStatusToWin32Status( status );
  117. } // HttpQueryControlChannelInformation
  118. /***************************************************************************++
  119. Routine Description:
  120. Sets information in a control channel.
  121. Arguments:
  122. ControlChannelHandle - Supplies a UL.SYS control channel handle.
  123. InformationClass - Supplies the type of information to set.
  124. pControlChannelInformation - Supplies the data to set.
  125. Length - Supplies the length of pControlChannelInformation.
  126. Return Value:
  127. ULONG - Completion status.
  128. --***************************************************************************/
  129. ULONG
  130. WINAPI
  131. HttpSetControlChannelInformation(
  132. IN HANDLE ControlChannelHandle,
  133. IN HTTP_CONTROL_CHANNEL_INFORMATION_CLASS InformationClass,
  134. IN PVOID pControlChannelInformation,
  135. IN ULONG Length
  136. )
  137. {
  138. NTSTATUS status;
  139. HTTP_CONTROL_CHANNEL_INFO channelInfo;
  140. //
  141. // Initialize the input structure.
  142. //
  143. channelInfo.InformationClass = InformationClass;
  144. //
  145. // Make the request.
  146. //
  147. status = HttpApiSynchronousDeviceControl(
  148. ControlChannelHandle, // FileHandle
  149. IOCTL_HTTP_SET_CONTROL_CHANNEL, // IoControlCode
  150. &channelInfo, // pInputBuffer
  151. sizeof(channelInfo), // InputBufferLength
  152. pControlChannelInformation, // pOutputBuffer
  153. Length, // OutputBufferLength
  154. NULL // pBytesTransferred
  155. );
  156. return HttpApiNtStatusToWin32Status( status );
  157. } // HttpSetControlChannelInformation
  158. //
  159. // Private functions.
  160. //