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.

182 lines
4.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dpenumsessionsobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dpSessdataObj.h"
  14. #include "DPEnumSessionsObj.h"
  15. extern BSTR GUIDtoBSTR(LPGUID pGuid);
  16. extern HRESULT BSTRtoPPGUID(LPGUID *,BSTR);
  17. extern BSTR DPLGUIDtoBSTR(LPGUID pGuid);
  18. extern HRESULT DPLBSTRtoPPGUID(LPGUID *,BSTR);
  19. extern HRESULT FillRealSessionDesc(DPSESSIONDESC2 *dpSessionDesc,DPSessionDesc2 *sessionDesc);
  20. extern void FillCoverSessionDesc(DPSessionDesc2 *sessionDesc,DPSESSIONDESC2 *dpSessionDesc);
  21. /////////////////////////////////////////////////////////////////////////////
  22. extern "C" BOOL PASCAL objEnumSessionsCallback2(const DPSESSIONDESC2 *gameDesc,
  23. DWORD *timeout, DWORD dwFlags, void *lpArg)
  24. {
  25. DPF(1,"Entered objEnumSessionsCallback2\r\n");
  26. //with no elements in a list will still call this callback once
  27. if (!gameDesc) return FALSE;
  28. C_dxj_DPEnumSessionsObject *pObj=(C_dxj_DPEnumSessionsObject*)lpArg;
  29. if (pObj==NULL) return TRUE;
  30. if (pObj->m_nCount >= pObj->m_nMax)
  31. {
  32. pObj->m_nMax += 10;
  33. if (pObj->m_pList)
  34. {
  35. void* tmp = realloc(pObj->m_pList,sizeof(DPSessionDesc2)* pObj->m_nMax);
  36. if (tmp)
  37. pObj->m_pList=(DPSessionDesc2*)tmp;
  38. else
  39. return FALSE;
  40. }
  41. else
  42. pObj->m_pList=(DPSessionDesc2*)malloc(sizeof(DPSessionDesc2)* pObj->m_nMax);
  43. if (pObj->m_pList==NULL)
  44. {
  45. pObj->m_bProblem=TRUE;
  46. return FALSE;
  47. }
  48. }
  49. ZeroMemory(&(pObj->m_pList[pObj->m_nCount]),sizeof(DPSessionDesc2));
  50. FillCoverSessionDesc(&(pObj->m_pList[pObj->m_nCount]),(DPSESSIONDESC2*)gameDesc);
  51. pObj->m_nCount++;
  52. return TRUE;
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. C_dxj_DPEnumSessionsObject::C_dxj_DPEnumSessionsObject()
  56. {
  57. m_nMax=0;
  58. m_pList=NULL;
  59. m_nCount=0;
  60. m_bProblem=FALSE;
  61. }
  62. C_dxj_DPEnumSessionsObject::~C_dxj_DPEnumSessionsObject()
  63. {
  64. //empty list
  65. if (m_pList){
  66. for (int i=0;i<m_nCount;i++)
  67. {
  68. DPSessionDesc2 *sessionDesc=&(m_pList[i]);
  69. if (sessionDesc->strGuidInstance) SysFreeString((BSTR)sessionDesc->strGuidInstance);
  70. if (sessionDesc->strGuidApplication) SysFreeString((BSTR)sessionDesc->strGuidApplication);
  71. if (sessionDesc->strSessionName) SysFreeString((BSTR)sessionDesc->strSessionName);
  72. if (sessionDesc->strPassword) SysFreeString((BSTR)sessionDesc->strPassword);
  73. }
  74. free(m_pList);
  75. }
  76. }
  77. HRESULT C_dxj_DPEnumSessionsObject::create(
  78. IDirectPlay4 * pdp,
  79. I_dxj_DirectPlaySessionData *sess,
  80. long timeout, long flags, I_dxj_DPEnumSessions2 **ppRet)
  81. {
  82. HRESULT hr;
  83. C_dxj_DPEnumSessionsObject *pNew=NULL;
  84. if (!sess) return E_INVALIDARG;
  85. *ppRet=NULL;
  86. pNew= new CComObject<C_dxj_DPEnumSessionsObject>;
  87. if (!pNew) return E_OUTOFMEMORY;
  88. pNew->m_bProblem=FALSE;
  89. if (sess){
  90. DPSESSIONDESC2 dpSessionDesc;
  91. //hr=FillRealSessionDesc(&dpSessionDesc,sess);
  92. //if FAILED(hr) return hr;
  93. sess->AddRef();
  94. sess->getData((void*)&dpSessionDesc);
  95. hr = pdp->EnumSessions(&dpSessionDesc, (DWORD)timeout, objEnumSessionsCallback2, pNew,(DWORD) flags);
  96. //if (dpSessionDesc.lpszSessionName) SysFreeString((BSTR)dpSessionDesc.lpszSessionName);
  97. //if (dpSessionDesc.lpszPassword) SysFreeString((BSTR)dpSessionDesc.lpszPassword);
  98. sess->Release();
  99. }
  100. else {
  101. hr = pdp->EnumSessions(NULL,(DWORD)timeout, objEnumSessionsCallback2, pNew,(DWORD) flags);
  102. }
  103. if (pNew->m_bProblem) hr=E_OUTOFMEMORY;
  104. if FAILED(hr)
  105. {
  106. free(pNew->m_pList);
  107. pNew->m_pList=NULL;
  108. delete pNew;
  109. return hr;
  110. }
  111. hr=pNew->QueryInterface(IID_I_dxj_DPEnumSessions2,(void**)ppRet);
  112. return hr;
  113. }
  114. HRESULT C_dxj_DPEnumSessionsObject::getItem( long index, I_dxj_DirectPlaySessionData **info)
  115. {
  116. if (m_pList==NULL) return E_FAIL;
  117. if (index < 1) return E_INVALIDARG;
  118. if (index > m_nCount) return E_INVALIDARG;
  119. HRESULT hr=C_dxj_DirectPlaySessionDataObject::create(&(m_pList[index-1]),info);
  120. /*
  121. memcpy(info,&(m_pList[index]),sizeof(DPSessionDesc2));
  122. if (info->strGuidInstance) SysFreeString((BSTR)info->strGuidInstance);
  123. if (info->strGuidApplication) SysFreeString((BSTR)info->strGuidApplication);
  124. if (info->strSessionName) SysFreeString((BSTR)info->strSessionName);
  125. if (info->strPassword) SysFreeString((BSTR)info->strPassword);
  126. info->strGuidInstance= SysAllocString(m_pList[index].strGuidInstance);
  127. info->strGuidApplication= SysAllocString(m_pList[index].strGuidApplication);
  128. info->strSessionName = SysAllocString(m_pList[index].strSessionName);
  129. info->strPassword = SysAllocString(m_pList[index].strPassword);
  130. */
  131. return hr;
  132. }
  133. HRESULT C_dxj_DPEnumSessionsObject::getCount(long *retVal)
  134. {
  135. *retVal=m_nCount;
  136. return S_OK;
  137. }