Source code of Windows XP (NT5)
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.

266 lines
6.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1999
  6. //
  7. // File: dplconnectionobj.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "Direct.h"
  12. #include "dms.h"
  13. #include "dplConnectionObj.h"
  14. #include "dpAddressObj.h"
  15. #include "dpSessDataObj.h"
  16. #pragma message ("Should INTERNAL_CREATE_STRUCT play with AddRef and refcount")
  17. extern HRESULT FillRealSessionDesc(DPSESSIONDESC2 *dpSessionDesc,DPSessionDesc2 *sessionDesc);
  18. extern void FillCoverSessionDesc(DPSessionDesc2 *sessionDesc, DPSESSIONDESC2 *dpSessionDesc);
  19. extern HRESULT BSTRtoGUID(LPGUID,BSTR);
  20. extern BSTR GUIDtoBSTR(LPGUID);
  21. extern HRESULT DPLBSTRtoGUID(LPGUID,BSTR);
  22. extern BSTR DPLGUIDtoBSTR(LPGUID);
  23. CONSTRUCTOR_STRUCT(_dxj_DPLConnection, {init();})
  24. //ANDREWKE - broke out for debuging
  25. //DESTRUCTOR_STRUCT(_dxj_DPLConnection, {cleanUp();})
  26. C_dxj_DPLConnectionObject::~C_dxj_DPLConnectionObject()
  27. {
  28. C_dxj_DPLConnectionObject *prev=NULL;
  29. for (
  30. C_dxj_DPLConnectionObject *ptr=(C_dxj_DPLConnectionObject *)g_dxj_DPLConnection;
  31. ptr;
  32. ptr=(C_dxj_DPLConnectionObject *)ptr->nextobj
  33. )
  34. {
  35. if(ptr == this)
  36. {
  37. if(prev)
  38. prev->nextobj = ptr->nextobj;
  39. else
  40. g_dxj_DPLConnection = (void*)ptr->nextobj;
  41. break;
  42. }
  43. prev = ptr;
  44. }
  45. cleanUp();
  46. }
  47. void C_dxj_DPLConnectionObject::init() {
  48. ZeroMemory(&m_connect,sizeof(DPLCONNECTION));
  49. m_connect.dwSize=sizeof(DPLCONNECTION);
  50. ZeroMemory(&m_dpName,sizeof(DPNAME));
  51. m_dpName.dwSize=sizeof(DPNAME);
  52. m_pAddress=NULL;
  53. ZeroMemory(&m_sessionDesc,sizeof(DPSESSIONDESC2));
  54. }
  55. void C_dxj_DPLConnectionObject::cleanUp() {
  56. if (m_pAddress) free (m_pAddress);
  57. if (m_dpName.lpszShortName) SysFreeString(m_dpName.lpszShortName);
  58. if (m_dpName.lpszLongName) SysFreeString(m_dpName.lpszLongName);
  59. if (m_sessionDesc.lpszSessionName) SysFreeString(m_sessionDesc.lpszSessionName);
  60. if (m_sessionDesc.lpszPassword) SysFreeString(m_sessionDesc.lpszPassword);
  61. }
  62. HRESULT C_dxj_DPLConnectionObject::getConnectionStruct( long *pOut){
  63. //TODO this is haneous;
  64. *pOut=(long)&m_connect;
  65. return S_OK;
  66. }
  67. //TODO consider - most of the time you are handed a buffer with
  68. //all the necessary pointers in tact. why not copy the buffer
  69. //as is?
  70. HRESULT C_dxj_DPLConnectionObject::setConnectionStruct( long pIn){
  71. DPLCONNECTION *pcon=(LPDPLCONNECTION)pIn;
  72. memcpy((void*)&m_connect,(void*)pcon,sizeof(DPLCONNECTION));
  73. ZeroMemory(&m_dpName,sizeof(DPNAME));
  74. ZeroMemory(&m_sessionDesc,sizeof(DPSESSIONDESC2));
  75. if (pcon->lpPlayerName){
  76. //copy over the flags...
  77. memcpy ((void*)&m_dpName,(void*)pcon->lpPlayerName,sizeof(DPNAME));
  78. //copy over the names
  79. m_dpName.lpszShortName=SysAllocString(pcon->lpPlayerName->lpszShortName);
  80. m_dpName.lpszLongName=SysAllocString(pcon->lpPlayerName->lpszLongName);
  81. }
  82. if (pcon->lpSessionDesc){
  83. //copy over flags
  84. memcpy ((void*)&m_sessionDesc,(void*)pcon->lpSessionDesc,sizeof(DPSESSIONDESC2));
  85. if (m_sessionDesc.lpszSessionName) SysFreeString(m_sessionDesc.lpszSessionName);
  86. if (m_sessionDesc.lpszPassword)SysFreeString(m_sessionDesc.lpszPassword);
  87. m_sessionDesc.lpszSessionName=SysAllocString(pcon->lpSessionDesc->lpszSessionName);
  88. m_sessionDesc.lpszPassword=SysAllocString(pcon->lpSessionDesc->lpszPassword);
  89. }
  90. if (pcon->lpAddress){
  91. if (m_pAddress)
  92. free(m_pAddress);
  93. m_pAddress=malloc(pcon->dwAddressSize);
  94. if (m_pAddress==NULL)
  95. return E_OUTOFMEMORY;
  96. memcpy ((void*)m_pAddress,(void*)pcon->lpAddress,pcon->dwAddressSize);
  97. }
  98. return S_OK;
  99. }
  100. HRESULT C_dxj_DPLConnectionObject::setFlags(long flags){
  101. m_connect.dwFlags=(DWORD)flags;
  102. return S_OK;
  103. }
  104. HRESULT C_dxj_DPLConnectionObject::getFlags(long *flags){
  105. *flags=(long)m_connect.dwFlags;
  106. return S_OK;
  107. }
  108. HRESULT C_dxj_DPLConnectionObject::setSessionDesc(I_dxj_DirectPlaySessionData *desc){
  109. //FillRealSessionDesc(&m_sessionDesc,desc);
  110. if (!desc) return E_INVALIDARG;
  111. desc->AddRef();
  112. desc->getData((long*)&m_sessionDesc);
  113. m_connect.lpSessionDesc=&m_sessionDesc;
  114. //we copy over the structure but we dont own the strings yet
  115. if (m_sessionDesc.lpszSessionName) SysFreeString(m_sessionDesc.lpszSessionName);
  116. if (m_sessionDesc.lpszPassword) SysFreeString(m_sessionDesc.lpszPassword);
  117. m_sessionDesc.lpszSessionName=SysAllocString(m_sessionDesc.lpszSessionName);
  118. m_sessionDesc.lpszPassword=SysAllocString(m_sessionDesc.lpszPassword);
  119. desc->Release();
  120. return S_OK;
  121. }
  122. HRESULT C_dxj_DPLConnectionObject::getSessionDesc(I_dxj_DirectPlaySessionData **desc){
  123. //FillCoverSessionDesc(desc,&m_sessionDesc);
  124. HRESULT hr;
  125. hr=C_dxj_DirectPlaySessionDataObject::create(&m_sessionDesc,desc);
  126. return hr;
  127. }
  128. HRESULT C_dxj_DPLConnectionObject::setGuidSP(BSTR strGuid){
  129. HRESULT hr=DPLBSTRtoGUID(&m_connect.guidSP,strGuid);
  130. return hr;
  131. }
  132. HRESULT C_dxj_DPLConnectionObject::getGuidSP(BSTR *strGuid){
  133. *strGuid=DPLGUIDtoBSTR(&m_connect.guidSP);
  134. return S_OK;
  135. }
  136. HRESULT C_dxj_DPLConnectionObject::getPlayerShortName(BSTR *name){
  137. *name = SysAllocString(m_dpName.lpszShortName);
  138. return S_OK;
  139. }
  140. HRESULT C_dxj_DPLConnectionObject::getPlayerLongName(BSTR *name){
  141. *name = SysAllocString(m_dpName.lpszLongName);
  142. return S_OK;
  143. }
  144. HRESULT C_dxj_DPLConnectionObject::setPlayerShortName(BSTR name){
  145. if (m_dpName.lpszShortName) SysFreeString (m_dpName.lpszShortName);
  146. m_dpName.lpszShortName=NULL;
  147. if (!name) return S_OK;
  148. m_dpName.lpszShortName = SysAllocString(name);
  149. m_connect.lpPlayerName=&m_dpName;
  150. return S_OK;
  151. }
  152. HRESULT C_dxj_DPLConnectionObject::setPlayerLongName(BSTR name){
  153. if (m_dpName.lpszLongName) SysFreeString (m_dpName.lpszLongName);
  154. m_dpName.lpszLongName=NULL;
  155. if (!name) return S_OK;
  156. m_dpName.lpszLongName =SysAllocString(name);
  157. m_connect.lpPlayerName=&m_dpName;
  158. return S_OK;
  159. }
  160. HRESULT C_dxj_DPLConnectionObject::getAddress(I_dxj_DPAddress **pRetAddress){
  161. HRESULT hr;
  162. INTERNAL_CREATE_STRUCT(_dxj_DPAddress,pRetAddress);
  163. if (*pRetAddress==NULL) return E_OUTOFMEMORY;
  164. hr=(*pRetAddress)->setAddress((long)m_connect.lpAddress,m_connect.dwAddressSize);
  165. //ASSERT(SUCCESS(hr),"setAddress C_dxj_DPLConnectionObject::getAddress)
  166. if FAILED(hr) return hr;
  167. return S_OK;
  168. }
  169. HRESULT C_dxj_DPLConnectionObject::setAddress(I_dxj_DPAddress *address){
  170. DWORD length=0;
  171. Byte *pAddress=NULL;
  172. //BUGFIX for MANBUG28198 2/2/00 ANDREWKE
  173. if (!address) return E_INVALIDARG;
  174. //NOTE: TODO make this cleaner
  175. address->getAddress((long*)&pAddress,(long*)&length);
  176. if (m_pAddress) free (m_pAddress);
  177. m_pAddress=NULL;
  178. m_pAddress=malloc((DWORD)length);
  179. if (m_pAddress==NULL) return E_OUTOFMEMORY;
  180. #pragma message ("Write ASSERT macro")
  181. if (pAddress==NULL) return E_FAIL;
  182. memcpy((void*)m_pAddress,(void*)pAddress,length);
  183. m_connect.lpAddress=m_pAddress;
  184. m_connect.dwAddressSize=length;
  185. return S_OK;
  186. }