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.

153 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 1998-2000 Microsoft Corporation
  3. Module Name :
  4. parport.cpp
  5. Abstract:
  6. Parallel port Device object handles one redirected parallel port
  7. Revision History:
  8. --*/
  9. #include "precomp.hxx"
  10. #define TRC_FILE "parport"
  11. #include "trc.h"
  12. DrParallelPort::DrParallelPort(SmartPtr<DrSession> &Session, ULONG DeviceType, ULONG DeviceId,
  13. PUCHAR PreferredDosName) : DrPrinterPort(Session, DeviceType, DeviceId, PreferredDosName)
  14. {
  15. BEGIN_FN("DrParallelPort::DrParallelPort");
  16. SetClassName("DrParallelPort");
  17. _PortType = FILE_DEVICE_PARALLEL_PORT;
  18. }
  19. BOOL DrParallelPort::ShouldCreatePrinter()
  20. {
  21. BEGIN_FN("DrParallelPort::ShouldCreatePrinter");
  22. return FALSE;
  23. }
  24. BOOL DrParallelPort::ShouldCreatePort()
  25. {
  26. BEGIN_FN("DrParallelPort::ShouldCreatePort");
  27. return !_Session->DisableLptPortMapping();
  28. }
  29. NTSTATUS DrParallelPort::Initialize(PRDPDR_DEVICE_ANNOUNCE DeviceAnnounce, ULONG Length)
  30. {
  31. NTSTATUS Status;
  32. BEGIN_FN("DrParallelPort::Initialize");
  33. if (ShouldCreatePort()) {
  34. Status = DrPrinterPort::Initialize(DeviceAnnounce, Length);
  35. if (NT_SUCCESS(Status) && _Session->GetClientCapabilitySet().PortCap.version > 0) {
  36. Status = CreateLptPort(DeviceAnnounce);
  37. }
  38. }
  39. else {
  40. Status = STATUS_SUCCESS;
  41. }
  42. return Status;
  43. }
  44. NTSTATUS DrParallelPort::CreateLptPort(PRDPDR_DEVICE_ANNOUNCE devAnnounceMsg)
  45. {
  46. NTSTATUS Status;
  47. UNICODE_STRING PortName;
  48. WCHAR PortNameBuff[PREFERRED_DOS_NAME_SIZE];
  49. USHORT OemCodePage, AnsiCodePage;
  50. NTSTATUS status;
  51. INT len, comLen;
  52. ULONG portAnnounceEventReqSize;
  53. PRDPDR_PORTDEVICE_SUB portAnnounceEvent;
  54. BEGIN_FN("DrParallelPort::CreateLptPort");
  55. //
  56. // Convert the LPT name
  57. //
  58. PortName.MaximumLength = sizeof(PortNameBuff);
  59. PortName.Length = 0;
  60. PortName.Buffer = &PortNameBuff[0];
  61. memset(&PortNameBuff, 0, sizeof(PortNameBuff));
  62. comLen = strlen((char *)_PreferredDosName);
  63. RtlGetDefaultCodePage(&AnsiCodePage, &OemCodePage);
  64. len = ConvertToAndFromWideChar(AnsiCodePage, PortName.Buffer,
  65. PortName.MaximumLength, (char *)_PreferredDosName,
  66. comLen, TRUE);
  67. if (len != -1) {
  68. //
  69. // We need just the LPTx portion for later...
  70. //
  71. PortName.Length = (USHORT)len;
  72. PortName.Buffer[len/sizeof(WCHAR)] = L'\0';
  73. } else {
  74. TRC_ERR((TB, "Error converting comName"));
  75. Status = STATUS_UNSUCCESSFUL;
  76. goto CleanUpAndReturn;
  77. }
  78. //
  79. // Allocate the port device announce buffer.
  80. //
  81. Status = CreatePortAnnounceEvent(devAnnounceMsg, NULL, 0, L"",
  82. &portAnnounceEventReqSize);
  83. ASSERT(Status == STATUS_BUFFER_TOO_SMALL);
  84. if (Status != STATUS_BUFFER_TOO_SMALL) {
  85. goto CleanUpAndReturn;
  86. }
  87. portAnnounceEvent = (PRDPDR_PORTDEVICE_SUB)new(NonPagedPool)
  88. BYTE[portAnnounceEventReqSize];
  89. if (portAnnounceEvent == NULL) {
  90. TRC_ERR((TB, "Unable to allocate portAnnounceEvent"));
  91. Status = STATUS_NO_MEMORY;
  92. goto CleanUpAndReturn;
  93. }
  94. //
  95. // Create the port anounce message.
  96. //
  97. Status = CreatePortAnnounceEvent(devAnnounceMsg, portAnnounceEvent,
  98. portAnnounceEventReqSize, PortName.Buffer, NULL);
  99. if (Status != STATUS_SUCCESS) {
  100. delete portAnnounceEvent;
  101. #if DBG
  102. portAnnounceEvent = NULL;
  103. #endif
  104. goto CleanUpAndReturn;
  105. }
  106. //
  107. // Dispatch the event to the associated session.
  108. //
  109. Status = RDPDYN_DispatchNewDevMgmtEvent(
  110. portAnnounceEvent,
  111. _Session->GetSessionId(),
  112. RDPDREVT_PORTANNOUNCE,
  113. NULL
  114. );
  115. CleanUpAndReturn:
  116. return Status;
  117. }