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.

405 lines
12 KiB

  1. //****************************************************************************
  2. //
  3. // BLObEvnt.cpp
  4. // Messenger integration to OE
  5. // Created 04/20/98 by YST
  6. //
  7. // Copyright (c) Microsoft Corporation 1997-1998
  8. //
  9. #include "pch.hxx"
  10. #include "MDispid.h"
  11. #include "BLObEvnt.h"
  12. // #include "demand.h"
  13. #include "bllist.h"
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[]=__FILE__;
  17. #define new DEBUG_NEW
  18. #endif
  19. #define ASSERT _ASSERTE
  20. #define STR_MAX 256
  21. //****************************************************************************
  22. //
  23. // CLASS CMsgrObjectEvents
  24. //
  25. //****************************************************************************
  26. //****************************************************************************
  27. //
  28. // Construction/Destruction
  29. //
  30. //****************************************************************************
  31. CMsgrObjectEvents::CMsgrObjectEvents()
  32. {
  33. // m_pBlAbCtrl = NULL;
  34. // lLocalState = BIMSTATE_OFFLINE;
  35. }
  36. CMsgrObjectEvents::~CMsgrObjectEvents()
  37. {
  38. }
  39. //****************************************************************************
  40. //
  41. // Methods from IUnknown
  42. //
  43. //****************************************************************************
  44. //****************************************************************************
  45. //
  46. // STDMETHODIMP_(ULONG) CMsgrObjectEvents::AddRef()
  47. //
  48. // Purpose : increment the object's reference count,
  49. // Entry : None
  50. // Exit : current count
  51. //
  52. //****************************************************************************
  53. STDMETHODIMP_ (ULONG) CMsgrObjectEvents::AddRef()
  54. {
  55. return RefCount::AddRef();
  56. }
  57. //****************************************************************************
  58. //
  59. // STDMETHODIMP_(ULONG) CMsgrObjectEvents::Release()
  60. //
  61. // Purpose : decrement the object's reference count
  62. // Entry : None
  63. // Exit : returns new count
  64. //
  65. //****************************************************************************
  66. STDMETHODIMP_ (ULONG) CMsgrObjectEvents::Release()
  67. {
  68. return RefCount::Release();
  69. }
  70. //****************************************************************************
  71. //
  72. // STDMETHODIMP CMsgrObjectEvents::QueryInterface(REFIID iid, LPVOID *ppv)
  73. //
  74. // returns a pointer to the requested interface on the same object
  75. // Purpose: To retrieve a pointer to requested interface
  76. // Entry : iid -- GUID of requested interface
  77. // Exit : ppv -- pointer to requested interface (if one exists)
  78. // return value : HRESULT
  79. //
  80. //****************************************************************************
  81. STDMETHODIMP CMsgrObjectEvents::QueryInterface (REFIID riid, LPVOID *ppv)
  82. {
  83. *ppv = NULL;
  84. HRESULT hr = E_NOINTERFACE;
  85. if (riid == IID_IUnknown)
  86. *ppv = (LPVOID) this;
  87. else if (riid == DIID_DBasicIMEvents)
  88. *ppv = (LPVOID) this;
  89. else if (riid == IID_IDispatch)
  90. *ppv = (LPVOID) this;
  91. if (*ppv)
  92. {
  93. ((LPUNKNOWN)*ppv)->AddRef();
  94. hr = S_OK;
  95. }
  96. return hr;
  97. }
  98. //****************************************************************************
  99. //
  100. // IDispatch implementation
  101. //
  102. //****************************************************************************
  103. //****************************************************************************
  104. //
  105. // STDMETHODIMP CMsgrObjectEvents::GetTypeInfoCount(UINT* pcTypeInfo)
  106. //
  107. // Set pcTypeInfo to 0 because we do not support type library
  108. //
  109. //****************************************************************************
  110. STDMETHODIMP CMsgrObjectEvents::GetTypeInfoCount(UINT* pcTypeInfo)
  111. {
  112. // g_AddToLog(LOG_LEVEL_COM, _T("GetTypeInfoCount call succeeded"));
  113. *pcTypeInfo = 0 ;
  114. return NOERROR ;
  115. }
  116. //****************************************************************************
  117. //
  118. // STDMETHODIMP CMsgrObjectEvents::GetTypeInfo(
  119. //
  120. // Returns E_NOTIMPL because we do not support type library
  121. //
  122. //****************************************************************************
  123. STDMETHODIMP CMsgrObjectEvents::GetTypeInfo(
  124. UINT iTypeInfo,
  125. LCID, // This object does not support localization.
  126. ITypeInfo** ppITypeInfo)
  127. {
  128. *ppITypeInfo = NULL ;
  129. if(iTypeInfo != 0)
  130. {
  131. // g_AddToLog(LOG_LEVEL_COM, _T("GetTypeInfo call failed -- bad iTypeInfo index"));
  132. return DISP_E_BADINDEX ;
  133. }
  134. else
  135. {
  136. //g_AddToLog(LOG_LEVEL_COM, _T("GetTypeInfo call succeeded"));
  137. return E_NOTIMPL;
  138. }
  139. }
  140. //****************************************************************************
  141. //
  142. // STDMETHODIMP CMsgrObjectEvents::GetIDsOfNames(
  143. // const IID& iid,
  144. // OLECHAR** arrayNames,
  145. // UINT countNames,
  146. // LCID, // Localization is not supported.
  147. // DISPID* arrayDispIDs)
  148. //
  149. // Returns E_NOTIMPL because we do not support type library
  150. //
  151. //****************************************************************************
  152. STDMETHODIMP CMsgrObjectEvents::GetIDsOfNames(
  153. const IID& iid,
  154. OLECHAR** arrayNames,
  155. UINT countNames,
  156. LCID, // Localization is not supported.
  157. DISPID* arrayDispIDs)
  158. {
  159. HRESULT hr;
  160. if (iid != IID_NULL)
  161. {
  162. // g_AddToLog(LOG_LEVEL_COM, _T("GetIDsOfNames call failed -- bad IID"));
  163. return DISP_E_UNKNOWNINTERFACE ;
  164. }
  165. // g_AddToLog(LOG_LEVEL_COM, _T("GetIDsOfNames call succeeded"));
  166. hr = E_NOTIMPL;
  167. return hr ;
  168. }
  169. // Set BLAB control for CMsgrObjectEvents
  170. STDMETHODIMP CMsgrObjectEvents::SetListOfBuddies(CMsgrList *pList)
  171. {
  172. m_pMsgrList = pList;
  173. return S_OK;
  174. }
  175. // Set BLAB control for CMsgrObjectEvents
  176. STDMETHODIMP CMsgrObjectEvents::DelListOfBuddies()
  177. {
  178. m_pMsgrList = NULL;
  179. return S_OK;
  180. }
  181. //****************************************************************************
  182. //
  183. // STDMETHODIMP CMsgrObjectEvents::Invoke(
  184. // DISPID dispidMember,
  185. // const IID& iid,
  186. // LCID, // Localization is not supported.
  187. // WORD wFlags,
  188. // DISPPARAMS* pDispParams,
  189. // VARIANT* pvarResult,
  190. // EXCEPINFO* pExcepInfo,
  191. // UINT* pArgErr)
  192. //
  193. // Returns E_NOTIMPL because we do not support type library
  194. //
  195. //****************************************************************************
  196. STDMETHODIMP CMsgrObjectEvents::Invoke(
  197. DISPID dispidMember,
  198. const IID& iid,
  199. LCID, // Localization is not supported.
  200. WORD wFlags,
  201. DISPPARAMS* pDispParams,
  202. VARIANT* pvarResult,
  203. EXCEPINFO* pExcepInfo,
  204. UINT* pArgErr)
  205. {
  206. // g_AddToLog(LOG_LEVEL_FUNCTIONS, _T("CMsgrObjectEvents::Invoke entered"));
  207. // g_AddToLog(LOG_LEVEL_NOTIFICATIONS, _T("Dispid passed : %s"), g_GetStringFromDISPID(dispidMember));
  208. HRESULT hr;
  209. HRESULT hrRet;
  210. if (iid != IID_NULL)
  211. {
  212. // g_AddToLog(LOG_LEVEL_COM, _T("Invoke call failed -- bad IID"));
  213. return DISP_E_UNKNOWNINTERFACE ;
  214. }
  215. ::SetErrorInfo(0, NULL) ;
  216. BOOL bRet = TRUE; //this variable is there for future use
  217. CComPtr<IBasicIMUser> spUser;
  218. CComPtr<IBasicIMUsers> spBuddies;
  219. switch (dispidMember)
  220. {
  221. case DISPID_ONLOGONRESULT:
  222. //we should only have one parameter, the result, and that it is a long
  223. ASSERT(pDispParams->cArgs == 1);
  224. ASSERT(pDispParams->rgvarg->vt == VT_I4);
  225. // g_AddToLog(LOG_LEVEL_NOTIFICATIONS, _T("Result passed : %s"), g_GetStringFromLogonResult(pDispParams->rgvarg->lVal));
  226. if(m_pMsgrList)
  227. bRet = m_pMsgrList->EventLogonResult(pDispParams->rgvarg->lVal);
  228. break;
  229. case DISPID_ONUSERFRIENDLYNAMECHANGERESULT :
  230. _ASSERTE(pDispParams->cArgs == 3);
  231. _ASSERTE(pDispParams->rgvarg[2].vt == VT_I4);
  232. _ASSERTE(pDispParams->rgvarg[1].vt == VT_DISPATCH);
  233. //if(lLocalState >= BIMSTATE_LOCAL_FINDING_SERVER)
  234. // break;
  235. hr = pDispParams->rgvarg[1].pdispVal->QueryInterface(IID_IBasicIMUser, (LPVOID *)&spUser);
  236. if (SUCCEEDED(hr))
  237. {
  238. if(m_pMsgrList)
  239. bRet = m_pMsgrList->EventUserNameChanged(spUser);
  240. }
  241. break;
  242. case DISPID_ONLOGOFF:
  243. if(m_pMsgrList)
  244. bRet = m_pMsgrList->EventLogoff();
  245. break;
  246. case DISPID_ONAPPSHUTDOWN:
  247. if(m_pMsgrList)
  248. bRet = m_pMsgrList->EventAppShutdown();
  249. break;
  250. case DISPID_ONLISTADDRESULT:
  251. // we should have two parameter, HRESULT, and the pMsgrUser
  252. //
  253. // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  254. // The parameters are inversed. This means that the las parameter in the
  255. // prototype of the function is the first one in the array received, and so on
  256. _ASSERTE(pDispParams->cArgs == 2);
  257. _ASSERTE(pDispParams->rgvarg[1].vt == VT_I4);
  258. _ASSERTE(pDispParams->rgvarg[0].vt == VT_DISPATCH);
  259. hrRet = V_I4(&pDispParams->rgvarg[1]);
  260. hr = pDispParams->rgvarg[0].pdispVal->QueryInterface(IID_IBasicIMUser, (LPVOID *)&spUser);
  261. if (SUCCEEDED(hr))
  262. {
  263. if( SUCCEEDED(hrRet) )
  264. {
  265. // g_AddToLog(LOG_LEVEL_COM, _T("User was added sucessfully."));
  266. if(m_pMsgrList)
  267. bRet = m_pMsgrList->EventUserAdded(spUser);
  268. }
  269. }
  270. else
  271. {
  272. // g_AddToLog(LOG_LEVEL_COM, _T("QueryInterface for IID_IBasicIMUser failed"));
  273. }
  274. break;
  275. case DISPID_ONLISTREMOVERESULT:
  276. // we should have two parameter, HRESULT, and the pMsgrUser
  277. //
  278. _ASSERTE(pDispParams->cArgs == 2);
  279. _ASSERTE(pDispParams->rgvarg[1].vt == VT_I4);
  280. _ASSERTE(pDispParams->rgvarg[0].vt == VT_DISPATCH);
  281. hrRet = V_I4(&pDispParams->rgvarg[1]);
  282. hr = pDispParams->rgvarg[0].pdispVal->QueryInterface(IID_IBasicIMUser, (LPVOID *)&spUser);
  283. if (SUCCEEDED(hr))
  284. {
  285. if( SUCCEEDED(hrRet) )
  286. {
  287. // g_AddToLog(LOG_LEVEL_COM, _T("User was removed sucessfully."));
  288. if(m_pMsgrList)
  289. bRet = m_pMsgrList->EventUserRemoved(spUser);
  290. }
  291. else
  292. {
  293. // g_AddToLog(LOG_LEVEL_COM, _T("User was not removed due to error %s."), g_GetErrorString(hrRet));
  294. }
  295. }
  296. else
  297. {
  298. // g_AddToLog(LOG_LEVEL_COM, _T("QueryInterface for IID_IBasicIMUser failed"));
  299. }
  300. break;
  301. case DISPID_ONUSERSTATECHANGED:
  302. //we should only have two parameters, the previousState and the pMsgrUser
  303. ASSERT(pDispParams->cArgs == 2);
  304. ASSERT(pDispParams->rgvarg[1].vt == VT_DISPATCH);
  305. ASSERT(pDispParams->rgvarg[0].vt == VT_I4);
  306. // if(lLocalState >= BIMSTATE_LOCAL_FINDING_SERVER)
  307. // break;
  308. hr = pDispParams->rgvarg[1].pdispVal->QueryInterface(IID_IBasicIMUser, (LPVOID *)&spUser);
  309. if (SUCCEEDED(hr))
  310. {
  311. if(m_pMsgrList)
  312. bRet = m_pMsgrList->EventUserStateChanged(spUser);
  313. }
  314. break;
  315. case DISPID_ONLOCALSTATECHANGERESULT:
  316. //we should only have two parameters, hr and the LocalState
  317. #if 0
  318. _ASSERTE(pDispParams->cArgs >== 2);
  319. _ASSERTE(pDispParams->rgvarg[1].vt == VT_I4);
  320. _ASSERTE(pDispParams->rgvarg[0].vt == VT_I4);
  321. #endif // 0
  322. // lLocalState = pDispParams->rgvarg[0].lVal;
  323. if(m_pMsgrList)
  324. bRet = m_pMsgrList->EventLocalStateChanged(((BIMSTATE) pDispParams->rgvarg[0].lVal));
  325. break;
  326. }
  327. return NOERROR;
  328. }