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.

130 lines
3.8 KiB

  1. //#---------------------------------------------------------------
  2. // File: pxpacket.cpp
  3. //
  4. // Synopsis: This class contains the implementation of the
  5. // CProxyPacket class.
  6. //
  7. // Copyright (C) 1995 Microsoft Corporation
  8. // All rights reserved.
  9. //
  10. // Authors: t-alexwe
  11. //----------------------------------------------------------------
  12. #include <windows.h>
  13. #include <winsock.h>
  14. #include "dbgtrace.h"
  15. #include "pxpacket.h"
  16. //+----------------------------------------------------------------------
  17. //
  18. // Function: PProxyPacket
  19. //
  20. // Synopsis: constructor
  21. //
  22. // History: t-alexwe Created 19 July 1995
  23. //
  24. //-----------------------------------------------------------------------
  25. CProxyPacket::CProxyPacket()
  26. {
  27. clear();
  28. }
  29. //+----------------------------------------------------------------------
  30. //
  31. // Function: ~ProxyConnector
  32. //
  33. // Synopsis: destructor
  34. //
  35. // History: t-alexwe Created 19 July 1995
  36. //
  37. //-----------------------------------------------------------------------
  38. CProxyPacket::~CProxyPacket()
  39. {
  40. clear();
  41. }
  42. //+----------------------------------------------------------------------
  43. //
  44. // Function: addMessage
  45. //
  46. // Synopsis: Adds a message to the packet. the message data is assumed
  47. // to have been written to the area returned by
  48. // getNextDataPointer(). cData must be <= getAvailableSpace()
  49. //
  50. // Arguments: wCommand - the message command
  51. // cData - number of bytes of data
  52. //
  53. // History: t-alexwe Created 19 July 1995
  54. //
  55. //-----------------------------------------------------------------------
  56. void CProxyPacket::addMessage( WORD wCommand,
  57. WORD cData )
  58. {
  59. TraceFunctEnter("CProxyPacket::AddMessage");
  60. _ASSERT(cData <= getAvailableSpace());
  61. _ASSERT(cMessages < MAXMSGSPERPACKET);
  62. DebugTrace((LPARAM) this, "adding message: wCommand = 0x%x cData = %i",
  63. wCommand, cData);
  64. pMessages[cMessages].wCommand = wCommand;
  65. pMessages[cMessages].cOffset = cLength - PACKETHDRSIZE;
  66. pMessages[cMessages].cData = cData;
  67. cLength += cData;
  68. cMessages++;
  69. TraceFunctLeave();
  70. }
  71. //+----------------------------------------------------------------------
  72. //
  73. // Function: getMessage
  74. //
  75. // Synopsis: Gets the data pointer, size of data, and command from
  76. // a message in a packet.
  77. //
  78. // Arguments: wIndex - the message index in the packet
  79. // pwCommand - returned: the message command
  80. // cData - returned: the size of the data buffer
  81. //
  82. // Returns: pointer to the data buffer, or NULL on error.
  83. //
  84. // History: t-alexwe Created 19 July 1995
  85. //
  86. //-----------------------------------------------------------------------
  87. PVOID CProxyPacket::getMessage( WORD wIndex,
  88. PWORD pwCommand,
  89. PWORD pcData )
  90. {
  91. TraceFunctEnter("CProxyPacket::GetMessage");
  92. WORD cOffset = pMessages[wIndex].cOffset;
  93. _ASSERT(wIndex < getMessageCount());
  94. *pcData = pMessages[wIndex].cData;
  95. //
  96. // make sure that the data length is valid
  97. //
  98. // algorithm: if this is the last message then make sure that
  99. // the data count is the same as the amount of space left in the
  100. // packet data area. if this is not the last message make sure
  101. // that the space in the packet data area (marked by the messages
  102. // cOffset and the next messages cOffset) is the same size as
  103. // the messages cData.
  104. //
  105. if (!(((wIndex == cMessages - 1) &&
  106. (*pcData == cLength - PACKETHDRSIZE - cOffset)) ||
  107. (*pcData == pMessages[wIndex + 1].cOffset - cOffset)))
  108. {
  109. TraceFunctLeave();
  110. return NULL;
  111. } else
  112. {
  113. *pwCommand = pMessages[wIndex].wCommand;
  114. DebugTrace((LPARAM) this, "getting msg: wCommand = 0x%x cData = %i",
  115. *pwCommand, *pcData);
  116. TraceFunctLeave();
  117. return &(pData[pMessages[wIndex].cOffset]);
  118. }
  119. }