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.

262 lines
7.0 KiB

  1. #include "precomp.h"
  2. #include "fsdiag.h"
  3. DEBUG_FILEZONE(ZONE_T120_APP_ROSTER);
  4. /*
  5. * arostmsg.cpp
  6. *
  7. * Copyright (c) 1995 by DataBeam Corporation, Lexington, KY
  8. *
  9. * Abstract:
  10. * This is the implementation file for the Application Roster Message
  11. * Class. This class maintains a list of application rosters, and is able
  12. * to "serialize" the list into a block of memory. It utilizes a
  13. * "Lock - UnLock" facility to ensure that the roster list memory remains
  14. * valid until all interested parties are through using the object.
  15. *
  16. * Protected Instance Variables:
  17. *
  18. * Private Member Functions:
  19. *
  20. * Caveats:
  21. * This message container holds a list of application rosters that is very
  22. * temporary. This list should not be accessed after Free is called. It
  23. * is important for the users of this class to understand that lock should
  24. * be called at least once before any of the application rosters contained
  25. * in this list are deleted.
  26. *
  27. * Author:
  28. * jbo/blp
  29. */
  30. #include "arostmsg.h"
  31. /*
  32. * CAppRosterMsg()
  33. *
  34. * Public Function Description
  35. * This constructor is used to create an empty Application Roster
  36. * Message.
  37. */
  38. CAppRosterMsg::CAppRosterMsg(void)
  39. :
  40. CRefCount(MAKE_STAMP_ID('A','R','M','g')),
  41. m_pMsgData(NULL)
  42. {
  43. }
  44. /*
  45. * ~CAppRosterMsg()
  46. *
  47. * Public Function Description:
  48. * The destructor for the CAppRosterMsg class will clean up
  49. * any memory allocated during the life of the object.
  50. */
  51. CAppRosterMsg::~CAppRosterMsg(void)
  52. {
  53. delete m_pMsgData;
  54. }
  55. /*
  56. * GCCError LockApplicationRosterMessage ()
  57. *
  58. * Public Function Description
  59. * This routine is used to lock an CAppRosterMsg. The memory
  60. * necessary to hold the list of rosters is allocated and the rosters are
  61. * "serialized" into the allocated memory block.
  62. */
  63. GCCError CAppRosterMsg::LockApplicationRosterMessage(void)
  64. {
  65. GCCError rc = GCC_NO_ERROR;
  66. PGCCApplicationRoster * roster_list;
  67. DWORD i;
  68. UINT roster_data_length;
  69. LPBYTE memory_pointer;
  70. UINT number_of_rosters;
  71. DebugEntry(CAppRosterMsg::LockApplicationRosterMessage);
  72. /*
  73. * If this is the first time this routine is called, determine the size of
  74. * the memory required to hold the list of application rosters and go ahead
  75. * and serialize the data. Otherwise, just increment the lock count.
  76. */
  77. if (Lock() == 1)
  78. {
  79. CAppRoster *lpAppRoster;
  80. ASSERT(NULL == m_pMsgData);
  81. // Here we are determining the size of the memory block.
  82. number_of_rosters = m_AppRosterList.GetCount();
  83. roster_data_length = number_of_rosters *
  84. (sizeof(PGCCApplicationRoster) + ROUNDTOBOUNDARY(sizeof(GCCApplicationRoster)));
  85. m_AppRosterList.Reset();
  86. while (NULL != (lpAppRoster = m_AppRosterList.Iterate()))
  87. {
  88. roster_data_length += lpAppRoster->LockApplicationRoster();
  89. }
  90. /*
  91. * Allocate space to hold the list of GCCApplicationRoster pointers
  92. * as well as rosters and all associated data.
  93. */
  94. if (roster_data_length != 0)
  95. {
  96. DBG_SAVE_FILE_LINE
  97. if (NULL != (m_pMsgData = new BYTE[roster_data_length]))
  98. {
  99. ::ZeroMemory(m_pMsgData, roster_data_length);
  100. /*
  101. * Retrieve the memory pointer and save it in the list of
  102. * GCCApplicationRoster pointers.
  103. */
  104. memory_pointer = m_pMsgData;
  105. roster_list = (PGCCApplicationRoster *)memory_pointer;
  106. /*
  107. * Initialize all of the roster list pointers to NULL. Move
  108. * the memory pointer past the list of pointers. This is where
  109. * the first application roster will be written.
  110. */
  111. for (i = 0; i < number_of_rosters; i++)
  112. {
  113. roster_list[i] = NULL;
  114. }
  115. memory_pointer += number_of_rosters * sizeof(PGCCApplicationRoster);
  116. /*
  117. * Retrieve all of the data for each application roster.
  118. */
  119. i = 0;
  120. m_AppRosterList.Reset();
  121. while (NULL != (lpAppRoster = m_AppRosterList.Iterate()))
  122. {
  123. /*
  124. * Save the pointer to the roster structure in the list.
  125. */
  126. roster_list[i] = (PGCCApplicationRoster)memory_pointer;
  127. /*
  128. * Move the memory pointer past the actual roster structure.
  129. */
  130. memory_pointer += ROUNDTOBOUNDARY(sizeof(GCCApplicationRoster));
  131. /*
  132. * Fill in the roster structure and all associated data.
  133. */
  134. roster_data_length = lpAppRoster->GetAppRoster(roster_list[i], memory_pointer);
  135. /*
  136. * Move the memory pointer past the roster data. This where
  137. * the next roster structure will begin.
  138. */
  139. memory_pointer += roster_data_length;
  140. // Increment the counter
  141. i++;
  142. }
  143. }
  144. else
  145. {
  146. ERROR_OUT(("CAppRosterMsg::LockApplicationRosterMessage: "
  147. "can't allocate memory, size=%u", (UINT) roster_data_length));
  148. rc = GCC_ALLOCATION_FAILURE;
  149. }
  150. }
  151. /*
  152. ** Since we do not need the application rosters anymore it is
  153. ** OK to unlock them here.
  154. */
  155. m_AppRosterList.Reset();
  156. while (NULL != (lpAppRoster = m_AppRosterList.Iterate()))
  157. {
  158. lpAppRoster->UnLockApplicationRoster();
  159. }
  160. }
  161. if (rc != GCC_NO_ERROR)
  162. {
  163. Unlock();
  164. }
  165. return (rc);
  166. }
  167. /*
  168. * GCCError GetAppRosterMsg ()
  169. *
  170. * Public Function Description
  171. * This routine is used to obtain a pointer to the Application Roster
  172. * list memory block used to deliver messages.
  173. * This routine should not be called before LockApplicationRosterMessage is
  174. * called.
  175. */
  176. GCCError CAppRosterMsg::GetAppRosterMsg(LPBYTE *ppRosterData, ULONG *pcRosters)
  177. {
  178. GCCError rc;
  179. DebugEntry(CAppRosterMsg::GetAppRosterMsg);
  180. if (GetLockCount() > 0)
  181. {
  182. if (((m_pMsgData != NULL) && (m_AppRosterList.GetCount() != 0)) ||
  183. (m_AppRosterList.GetCount() == 0))
  184. {
  185. *ppRosterData = m_pMsgData;
  186. *pcRosters = m_AppRosterList.GetCount();
  187. rc = GCC_NO_ERROR;
  188. }
  189. }
  190. else
  191. {
  192. ERROR_OUT(("CAppRosterMsg::GetAppRosterMsg: app roster msg is not locked"));
  193. rc = GCC_ALLOCATION_FAILURE;
  194. }
  195. DebugExitINT(CAppRosterMsg::GetAppRosterMsg, rc);
  196. return rc;
  197. }
  198. /*
  199. * void UnLockApplicationRosterMessage ()
  200. *
  201. * Public Function Description
  202. * This member function is responsible for unlocking the data locked for
  203. * the "API" application roster after the lock count goes to zero.
  204. */
  205. void CAppRosterMsg::UnLockApplicationRosterMessage(void)
  206. {
  207. DebugEntry(CAppRosterMsg::UnLockApplicationRosterMessage);
  208. if (Unlock(FALSE) == 0)
  209. {
  210. /*
  211. * Free up the memory block allocated to hold the roster
  212. */
  213. delete m_pMsgData;
  214. m_pMsgData = NULL;
  215. }
  216. // we have to call Release() because we used Unlock(FALSE)
  217. Release();
  218. }
  219. /*
  220. * GCCError AddRosterToMessage ()
  221. *
  222. * Public Function Description
  223. * This function adds an application roster pointer to the internal list
  224. * of app roster pointers. Note that this list is very temporary and
  225. * should not be accessed after the free flag is set.
  226. */
  227. void CAppRosterMsg::AddRosterToMessage(CAppRoster *pAppRoster)
  228. {
  229. m_AppRosterList.Append(pAppRoster);
  230. }