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.

225 lines
4.6 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. cmdchan.c
  5. Abstract:
  6. Routines for managing channels in the sac.
  7. Author:
  8. Sean Selitrennikoff (v-seans) Sept, 2000.
  9. Brian Guarraci (briangu) March, 2001.
  10. Revision History:
  11. --*/
  12. #include "sac.h"
  13. NTSTATUS
  14. CmdChannelCreate(
  15. IN OUT PSAC_CHANNEL Channel
  16. )
  17. /*++
  18. Routine Description:
  19. This routine allocates a channel and returns a pointer to it.
  20. Arguments:
  21. Channel - The resulting channel.
  22. OpenChannelCmd - All the parameters for the new channel
  23. Return Value:
  24. STATUS_SUCCESS if successful, else the appropriate error code.
  25. --*/
  26. {
  27. ASSERT_STATUS(Channel, STATUS_INVALID_PARAMETER);
  28. Channel->IBuffer = (PUCHAR)ALLOCATE_POOL(SAC_CMD_IBUFFER_SIZE, GENERAL_POOL_TAG);
  29. ASSERT_STATUS(Channel->IBuffer, STATUS_NO_MEMORY);
  30. ChannelSetIBufferHasNewData(Channel, FALSE);
  31. return STATUS_SUCCESS;
  32. }
  33. NTSTATUS
  34. CmdChannelDestroy(
  35. IN OUT PSAC_CHANNEL Channel
  36. )
  37. /*++
  38. Routine Description:
  39. This routine closes a channel.
  40. Arguments:
  41. Channel - The channel to be closed
  42. Return Value:
  43. STATUS_SUCCESS if successful, else the appropriate error code.
  44. --*/
  45. {
  46. NTSTATUS Status;
  47. ASSERT_STATUS(Channel, STATUS_INVALID_PARAMETER);
  48. //
  49. // Free the dynamically allocated memory
  50. //
  51. if (Channel->IBuffer) {
  52. FREE_POOL(&(Channel->IBuffer));
  53. Channel->IBuffer = NULL;
  54. }
  55. //
  56. // Now that we've done our channel specific destroy,
  57. // Call the general channel destroy
  58. //
  59. Status = ChannelDestroy(Channel);
  60. return Status;
  61. }
  62. NTSTATUS
  63. CmdChannelOWrite(
  64. IN PSAC_CHANNEL Channel,
  65. IN PCUCHAR String,
  66. IN ULONG Size
  67. )
  68. /*++
  69. Routine Description:
  70. This routine takes a string and prints it to the specified channel. If the channel
  71. is the currently active channel, it puts the string out the headless port as well.
  72. Note: Current Channel lock must be held by caller
  73. Arguments:
  74. Channel - Previously created channel.
  75. String - Output string.
  76. Length - The # of String bytes to process
  77. Return Value:
  78. STATUS_SUCCESS if successful, otherwise status
  79. --*/
  80. {
  81. NTSTATUS Status;
  82. ASSERT_STATUS(Channel, STATUS_INVALID_PARAMETER_1);
  83. ASSERT_STATUS(String, STATUS_INVALID_PARAMETER_2);
  84. ASSERT_STATUS(Size > 0, STATUS_INVALID_PARAMETER_3);
  85. ASSERT(FIELD_OFFSET(HEADLESS_CMD_PUT_STRING, String) == 0); // ASSERT if anyone changes this structure.
  86. //
  87. // default: we succeeded
  88. //
  89. Status = STATUS_SUCCESS;
  90. //
  91. // if the current channel is the active channel and the user has selected
  92. // to display this channel, relay the output directly to the user
  93. //
  94. if (IoMgrIsWriteEnabled(Channel) && ChannelSentToScreen(Channel)){
  95. Status = Channel->OEcho(
  96. Channel,
  97. String,
  98. Size
  99. );
  100. }
  101. return Status;
  102. }
  103. NTSTATUS
  104. CmdChannelOFlush(
  105. IN PSAC_CHANNEL Channel
  106. )
  107. /*++
  108. Routine Description:
  109. Send all the data in the cmd buffer since the channel was last active
  110. (or since the channel was created)
  111. Arguments:
  112. Channel - Previously created channel.
  113. Return Value:
  114. STATUS_SUCCESS if successful, otherwise status
  115. --*/
  116. {
  117. ASSERT_STATUS(Channel, STATUS_INVALID_PARAMETER_1);
  118. return STATUS_SUCCESS;
  119. }
  120. NTSTATUS
  121. CmdChannelORead(
  122. IN PSAC_CHANNEL Channel,
  123. IN PUCHAR Buffer,
  124. IN ULONG BufferSize,
  125. OUT PULONG ByteCount
  126. )
  127. /*++
  128. Routine Description:
  129. This routine attempts to read BufferSize characters from the output buffer.
  130. Arguments:
  131. Channel - Previously created channel.
  132. Buffer - Outgoing buffer
  133. BufferSize - Outgoing buffer size
  134. ByteCount - The number of bytes actually read
  135. Note: if the buffered data stored in the channel has now been sent.
  136. If Channel is also in the Inactive state, the channel will
  137. now be qualified for removal.
  138. Return Value:
  139. Status
  140. --*/
  141. {
  142. ASSERT_STATUS(Channel, STATUS_INVALID_PARAMETER_1);
  143. ASSERT_STATUS(Buffer, STATUS_INVALID_PARAMETER_2);
  144. ASSERT_STATUS(BufferSize > 0, STATUS_INVALID_PARAMETER_3);
  145. ASSERT_STATUS(ByteCount, STATUS_INVALID_PARAMETER_4);
  146. //
  147. // don't return anything
  148. //
  149. *ByteCount = 0;
  150. return STATUS_SUCCESS;
  151. }