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.

499 lines
7.9 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. ciolecmd.cxx
  5. Abstract:
  6. This file contains the implementation of the IOleCommandTarget
  7. interface for receiving events from IE5.
  8. Author:
  9. Gopal Parupudi <GopalP>
  10. Notes:
  11. These events are not used on NT5. They are used on Win9x and NT4
  12. platforms.
  13. Revision History:
  14. GopalP 1/26/1998 Start.
  15. --*/
  16. #include <precomp.hxx>
  17. #include <onestop.cxx> // This is a source file!
  18. //
  19. // IOleCommandTarget group for WININET events.
  20. //
  21. // Should have the IE5 folks put it in a header file. This is moot as this
  22. // file is no longer used on any platform.
  23. //
  24. CLSID CLSID_EVENTGROUP_WININET = { /* ab8ed004-b86a-11d1-b1f8-00c04fa357fa */
  25. 0xab8ed004,
  26. 0xb86a,
  27. 0x11d1,
  28. {0xb1, 0xf8, 0x00, 0xc0, 0x4f, 0xa3, 0x57, 0xfa}
  29. };
  30. //
  31. // Globals
  32. //
  33. LONG g_cCommandObj; // Count of active components
  34. LONG g_cCommandLock; // Count of Server locks
  35. //
  36. // Constructors and Destructors
  37. //
  38. CImpIOleCommandTarget::CImpIOleCommandTarget(
  39. void
  40. ) : m_cRef(1L) // Add a reference.
  41. {
  42. InterlockedIncrement(&g_cCommandObj);
  43. }
  44. CImpIOleCommandTarget::~CImpIOleCommandTarget(
  45. void
  46. )
  47. {
  48. InterlockedDecrement(&g_cCommandObj);
  49. }
  50. //
  51. // Standard QueryInterface
  52. //
  53. STDMETHODIMP
  54. CImpIOleCommandTarget::QueryInterface(
  55. REFIID riid,
  56. LPVOID *ppv
  57. )
  58. {
  59. HRESULT hr;
  60. DebugTraceGuid("CImpIOleCommandTarget:QueryInterface()", riid);
  61. hr = S_OK;
  62. *ppv = NULL;
  63. // IUnknown
  64. if (IsEqualIID(riid, IID_IUnknown))
  65. {
  66. *ppv = (IOleCommandTarget *) this;
  67. }
  68. else
  69. // IOleCommandTarget
  70. if (IsEqualIID(riid, IID_IOleCommandTarget))
  71. {
  72. *ppv = (IOleCommandTarget *) this;
  73. }
  74. else
  75. {
  76. hr = E_NOINTERFACE;
  77. }
  78. if (NULL != *ppv)
  79. {
  80. ((LPUNKNOWN)*ppv)->AddRef();
  81. }
  82. return hr;
  83. }
  84. //
  85. // Standard AddRef and Release
  86. //
  87. STDMETHODIMP_(ULONG)
  88. CImpIOleCommandTarget::AddRef(
  89. void
  90. )
  91. {
  92. return InterlockedIncrement(&m_cRef);
  93. }
  94. STDMETHODIMP_(ULONG)
  95. CImpIOleCommandTarget::Release(
  96. void
  97. )
  98. {
  99. LONG cRefT;
  100. SensPrint(SENS_INFO, (SENS_STRING("\t| CImpIOleCommandTarget::Release(m_cRef = %d) called.\n"), m_cRef));
  101. cRefT = InterlockedDecrement((PLONG) &m_cRef);
  102. if (0 == m_cRef)
  103. {
  104. delete this;
  105. }
  106. return cRefT;
  107. }
  108. //
  109. // IOleCommandTarget Implementation.
  110. //
  111. STDMETHODIMP
  112. CImpIOleCommandTarget::QueryStatus(
  113. const GUID *pguidCmdGroup,
  114. ULONG cCmds,
  115. OLECMD prgCmds[],
  116. OLECMDTEXT *pCmdText
  117. )
  118. {
  119. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  120. SensPrint(SENS_INFO, (SENS_STRING("CImpIOleCommandTarget::QueryStatus() called\n\n")));
  121. SensPrint(SENS_INFO, (SENS_STRING(" pguidCmdGroup - 0x%x\n"), pguidCmdGroup));
  122. SensPrint(SENS_INFO, (SENS_STRING(" cCmds - 0x%x\n"), cCmds));
  123. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  124. if (IsEqualGUID(*pguidCmdGroup, CLSID_EVENTGROUP_WININET))
  125. {
  126. // Subscribe to WININET events
  127. return S_OK;
  128. }
  129. return(OLECMDERR_E_UNKNOWNGROUP);
  130. }
  131. STDMETHODIMP
  132. CImpIOleCommandTarget::Exec(
  133. const GUID *pguidCmdGroup,
  134. DWORD nCmdID,
  135. DWORD nCmdexecopt,
  136. VARIANT *pvaIn,
  137. VARIANT *pvaOut
  138. )
  139. {
  140. HRESULT hr;
  141. hr = S_OK;
  142. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  143. SensPrint(SENS_INFO, (SENS_STRING("CImpIOleCommandTarget::Exec() called\n\n")));
  144. SensPrint(SENS_INFO, (SENS_STRING(" pguidCmdGroup - 0x%x\n"), pguidCmdGroup));
  145. SensPrint(SENS_INFO, (SENS_STRING(" cCmds - 0x%x\n"), nCmdID));
  146. SensPrint(SENS_INFO, (SENS_STRING(" cCmdexecopt - 0x%x\n"), nCmdexecopt));
  147. SensPrint(SENS_INFO, (SENS_STRING("---------------------------------------------------------\n")));
  148. if ( (NULL == pguidCmdGroup)
  149. || (FALSE == IsEqualGUID(*pguidCmdGroup, CLSID_EVENTGROUP_WININET)))
  150. {
  151. return(E_NOTIMPL);
  152. }
  153. //
  154. // Handle WININET events...
  155. //
  156. switch (nCmdID)
  157. {
  158. case INETEVT_RAS_CONNECT:
  159. ASSERT(VT_BSTR == pvaIn->vt);
  160. hr = WininetRasConnect(pvaIn->bstrVal);
  161. break;
  162. case INETEVT_RAS_DISCONNECT:
  163. ASSERT(VT_BSTR == pvaIn->vt);
  164. hr = WininetRasDisconnect(pvaIn->bstrVal);
  165. break;
  166. case INETEVT_ONLINE:
  167. hr = WininetOnline();
  168. break;
  169. case INETEVT_OFFLINE:
  170. hr = WininetOffline();
  171. break;
  172. case INETEVT_LOGON:
  173. ASSERT(VT_BSTR == pvaIn->vt);
  174. hr = WininetLogon(pvaIn->bstrVal);
  175. break;
  176. case INETEVT_LOGOFF:
  177. //ASSERT(VT_BSTR == pvaIn->vt);
  178. //hr = WininetLogoff(pvaIn->bstrVal);
  179. hr = WininetLogoff(SENS_BSTR("<Not Available>"));
  180. break;
  181. } // switch
  182. return S_OK;
  183. }
  184. HRESULT
  185. WininetRasConnect(
  186. BSTR bstrPhonebookEntry
  187. )
  188. /*++
  189. Routine Description:
  190. Arguments:
  191. Return Value:
  192. --*/
  193. {
  194. HRESULT hr;
  195. ULONG ulIgnore;
  196. SENSEVENT_RAS Data;
  197. hr = S_OK;
  198. SensPrintA(SENS_INFO, ("WininetRasConnect() - RAS Connect Event!\n"));
  199. Data.eType = SENS_EVENT_RAS_CONNECT;
  200. Data.hConnection = NULL;
  201. SensFireEvent(&Data);
  202. // Do necessary work here
  203. EvaluateConnectivity(TYPE_WAN);
  204. return hr;
  205. }
  206. HRESULT
  207. WininetRasDisconnect(
  208. BSTR bstrPhonebookEntry
  209. )
  210. /*++
  211. Routine Description:
  212. Arguments:
  213. Return Value:
  214. --*/
  215. {
  216. HRESULT hr;
  217. ULONG ulIgnore;
  218. SENSEVENT_RAS Data;
  219. hr = S_OK;
  220. SensPrintA(SENS_INFO, ("WininetRasDisconnect() - RAS Disconnect Event!\n"));
  221. Data.eType = SENS_EVENT_RAS_DISCONNECT;
  222. Data.hConnection = NULL;
  223. SensFireEvent(&Data);
  224. // Do necessary work here
  225. EvaluateConnectivity(TYPE_WAN);
  226. return hr;
  227. }
  228. HRESULT
  229. WininetOnline(
  230. void
  231. )
  232. /*++
  233. Routine Description:
  234. Arguments:
  235. Return Value:
  236. --*/
  237. {
  238. HRESULT hr;
  239. hr = S_OK;
  240. return hr;
  241. }
  242. HRESULT
  243. WininetOffline(
  244. void
  245. )
  246. /*++
  247. Routine Description:
  248. Arguments:
  249. Return Value:
  250. --*/
  251. {
  252. HRESULT hr;
  253. hr = S_OK;
  254. return hr;
  255. }
  256. HRESULT
  257. WininetLogon(
  258. BSTR bstrUserName
  259. )
  260. /*++
  261. Routine Description:
  262. Arguments:
  263. Return Value:
  264. --*/
  265. {
  266. HRESULT hr;
  267. SENS_NOTIFY_WINLOGON Data;
  268. hr = S_OK;
  269. //
  270. // Setup the data.
  271. //
  272. memset(&Data.Info, 0x0, sizeof(SENS_NOTIFY_WINLOGON));
  273. Data.eType = SENS_EVENT_LOGON;
  274. Data.Info.Size = sizeof(WINLOGON_INFO);
  275. Data.Info.Flags = 0x0;
  276. Data.Info.UserName = bstrUserName;
  277. Data.Info.Domain = NULL;
  278. Data.Info.WindowStation = NULL;
  279. Data.Info.hToken = NULL;;
  280. // First order of business - start OneStop if necessary.
  281. if (IsAutoSyncEnabled(NULL, AUTOSYNC_ON_STARTSHELL))
  282. {
  283. hr = SensNotifyOneStop(NULL, SYNC_MANAGER_LOGON, FALSE);
  284. LogMessage((SENSLOGN "SensNotifyOneStop() returned 0x%x\n", hr));
  285. }
  286. // Fire the event.
  287. SensFireEvent(&Data);
  288. return hr;
  289. }
  290. HRESULT
  291. WininetLogoff(
  292. BSTR bstrUserName
  293. )
  294. /*++
  295. Routine Description:
  296. Arguments:
  297. Return Value:
  298. --*/
  299. {
  300. HRESULT hr;
  301. SENS_NOTIFY_WINLOGON Data;
  302. hr = S_OK;
  303. //
  304. // Setup the data.
  305. //
  306. memset(&Data.Info, 0x0, sizeof(SENS_NOTIFY_WINLOGON));
  307. Data.eType = SENS_EVENT_LOGOFF;
  308. Data.Info.Size = sizeof(WINLOGON_INFO);
  309. Data.Info.Flags = 0x0;
  310. Data.Info.UserName = bstrUserName;
  311. Data.Info.Domain = NULL;
  312. Data.Info.WindowStation = NULL;
  313. Data.Info.hToken = NULL;;
  314. // First order of business - start OneStop if necessary.
  315. if (IsAutoSyncEnabled(NULL, AUTOSYNC_ON_LOGOFF))
  316. {
  317. hr = SensNotifyOneStop(NULL, SYNC_MANAGER_LOGOFF, FALSE);
  318. LogMessage((SENSLOGN "SensNotifyOneStop() returned 0x%x\n", hr));
  319. }
  320. // Fire the event.
  321. SensFireEvent(&Data);
  322. return hr;
  323. }