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.

181 lines
3.5 KiB

  1. //--------------------------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation, 1996
  4. //
  5. // Description:
  6. //
  7. // Microsoft Internet LDAP Client Xaction Data class
  8. //
  9. //
  10. // History
  11. // davidsan 04-29-96 Created
  12. //
  13. //--------------------------------------------------------------------------------------------
  14. //--------------------------------------------------------------------------------------------
  15. //
  16. // INCLUDES
  17. //
  18. //--------------------------------------------------------------------------------------------
  19. #include "ldappch.h"
  20. #include "lclilist.h"
  21. #include "lclixd.h"
  22. //--------------------------------------------------------------------------------------------
  23. //
  24. // PROTOTYPES
  25. //
  26. //--------------------------------------------------------------------------------------------
  27. //--------------------------------------------------------------------------------------------
  28. //
  29. // GLOBALS
  30. //
  31. //--------------------------------------------------------------------------------------------
  32. //--------------------------------------------------------------------------------------------
  33. //
  34. // FUNCTIONS
  35. //
  36. //--------------------------------------------------------------------------------------------
  37. //--------------------------------------------------------------------------------------------
  38. //
  39. // CLASSES
  40. //
  41. //--------------------------------------------------------------------------------------------
  42. CXactionData::CXactionData()
  43. {
  44. ::InitializeCriticalSection(&m_cs);
  45. m_hsemSignal = NULL;
  46. m_pxb = NULL;
  47. m_xid = 0;
  48. m_xtype = xtypeNil;
  49. m_fCancelled = FALSE;
  50. m_fOOM = FALSE;
  51. m_pxdNext = NULL;
  52. }
  53. CXactionData::~CXactionData()
  54. {
  55. ::DeleteCriticalSection(&m_cs);
  56. if (m_hsemSignal)
  57. CloseHandle(m_hsemSignal);
  58. if (m_pxb)
  59. this->DeletePxbChain(m_pxb);
  60. }
  61. void
  62. CXactionData::DeletePxbChain(PXB pxb)
  63. {
  64. PXB pxbNext;
  65. while (pxb)
  66. {
  67. pxbNext = pxb->pxbNext;
  68. delete [] pxb->pbData;
  69. delete pxb;
  70. pxb = pxbNext;
  71. }
  72. }
  73. BOOL
  74. CXactionData::FInit(XID xid, DWORD xtype)
  75. {
  76. ::EnterCriticalSection(&m_cs);
  77. m_xid = xid;
  78. m_xtype = xtype;
  79. m_hsemSignal = CreateSemaphore(NULL, 0, 64000, NULL);
  80. m_pxb = NULL;
  81. m_pxdNext = NULL;
  82. m_fCancelled = FALSE;
  83. m_fOOM = FALSE;
  84. ::LeaveCriticalSection(&m_cs);
  85. return TRUE;
  86. }
  87. BOOL
  88. CXactionData::FAddBuffer(BYTE *pb, int cb)
  89. {
  90. BOOL fRet = FALSE;
  91. PXB pxb;
  92. PXB pxbPrev;
  93. ::EnterCriticalSection(&m_cs);
  94. pxb = new XB;
  95. if (!pxb)
  96. goto LBail;
  97. pxb->pbData = new BYTE[cb];
  98. if (!pxb->pbData)
  99. {
  100. delete pxb;
  101. goto LBail;
  102. }
  103. pxb->cbData = cb;
  104. CopyMemory(pxb->pbData, pb, cb);
  105. pxb->pxbNext = NULL;
  106. fRet = TRUE;
  107. if (m_pxb)
  108. {
  109. pxbPrev = m_pxb;
  110. while (pxbPrev->pxbNext)
  111. pxbPrev = pxbPrev->pxbNext;
  112. pxbPrev->pxbNext = pxb;
  113. }
  114. else
  115. {
  116. m_pxb = pxb;
  117. }
  118. LBail:
  119. ::LeaveCriticalSection(&m_cs);
  120. return fRet;
  121. }
  122. BOOL
  123. CXactionData::FGetBuffer(BYTE **ppb, int *pcb)
  124. {
  125. BOOL fRet = FALSE;
  126. PXB pxb;
  127. ::EnterCriticalSection(&m_cs);
  128. if (!m_pxb)
  129. {
  130. goto LBail;
  131. }
  132. if (!m_pxb->pbData)
  133. {
  134. goto LBail;
  135. }
  136. pxb = m_pxb;
  137. m_pxb = m_pxb->pxbNext;
  138. *ppb = pxb->pbData;
  139. *pcb = pxb->cbData;
  140. delete pxb;
  141. fRet = TRUE;
  142. LBail:
  143. ::LeaveCriticalSection(&m_cs);
  144. return fRet;
  145. }
  146. BOOL
  147. CXactionData::FHasData()
  148. {
  149. BOOL fRet;
  150. ::EnterCriticalSection(&m_cs);
  151. fRet = m_pxb && m_pxb->pbData;
  152. ::LeaveCriticalSection(&m_cs);
  153. return fRet;
  154. }