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.

573 lines
22 KiB

  1. #define INC_OLE2
  2. #define _SHDOCVW_
  3. #ifdef UNICODE
  4. #define POST_IE5_BETA
  5. #include <w95wraps.h>
  6. #endif
  7. #include <windows.h>
  8. #include <windowsx.h>
  9. #include <ccstock.h>
  10. #include <ole2.h>
  11. #include <ole2ver.h>
  12. #include <oleauto.h>
  13. #include <docobj.h>
  14. #include <shlwapi.h>
  15. #include <wininet.h> // INTERNET_MAX_URL_LENGTH. Must be before shlobjp.h!
  16. #include <winineti.h>
  17. #include <shlobj.h>
  18. #include <inetsdk.h>
  19. #include <intshcut.h>
  20. #include <mshtml.h>
  21. #include <notftn.h>
  22. #include <webcheck.h>
  23. #include <exdisp.h>
  24. #include <inetreg.h>
  25. #include <advpub.h>
  26. #include <htiframe.h>
  27. #include <ieguidp.h>
  28. #include <lmcons.h> // for UNLEN/PWLEN
  29. #include <ipexport.h> // for ping
  30. #include <icmpapi.h> // for ping
  31. #include <mobsync.h>
  32. #include <mobsyncp.h>
  33. #undef MAX_STATUS // goofy
  34. #include "debug.h"
  35. #include "resource.h"
  36. #include "rsrchdr.h"
  37. #include "shfusion.h"
  38. #include "pstore.h"
  39. #include <shdocvw.h> // to get SHRestricted2*
  40. #include <dwnnot.h> // IDownloadNotify
  41. #include <malloc.h> // TSTR_ALIGNED_STACK_COPY
  42. #pragma warning(3:4701) // local may be used w/o init
  43. #pragma warning(3:4702) // Unreachable code
  44. #pragma warning(3:4705) // Statement has no effect
  45. #pragma warning(3:4706) // assignment w/i conditional expression
  46. #pragma warning(3:4709) // command operator w/o index expression
  47. // How user of CUrlDownload receives notifications from it.
  48. class CUrlDownloadSink
  49. {
  50. public:
  51. virtual HRESULT OnDownloadComplete(UINT iID, int iError) = 0;
  52. virtual HRESULT OnAuthenticate(HWND *phwnd, LPWSTR *ppszUsername, LPWSTR *ppszPassword)
  53. { return E_NOTIMPL; }
  54. virtual HRESULT OnClientPull(UINT iID, LPCWSTR pwszOldURL, LPCWSTR pwszNewURL)
  55. { return S_OK; }
  56. virtual HRESULT OnOleCommandTargetExec(const GUID *pguidCmdGroup, DWORD nCmdID,
  57. DWORD nCmdexecopt, VARIANTARG *pvarargIn,
  58. VARIANTARG *pvarargOut)
  59. { return OLECMDERR_E_NOTSUPPORTED; }
  60. // returns free threaded callback interface
  61. // If you use this, make your implementation of IDownloadNotify fast
  62. virtual HRESULT GetDownloadNotify(IDownloadNotify **ppOut)
  63. { return E_NOTIMPL; }
  64. };
  65. class CUrlDownload;
  66. #include "filetime.h"
  67. #include "offline.h"
  68. #include "utils.h"
  69. #include "delagent.h"
  70. #include "cdfagent.h"
  71. #include "webcrawl.h"
  72. #include "trkcache.h"
  73. #include "postagnt.h"
  74. #include "cdlagent.h"
  75. // Note: dialmon.h changes winver to 0x400
  76. #include "dialmon.h"
  77. #ifndef GUIDSTR_MAX
  78. // GUIDSTR_MAX is 39 and includes the terminating zero.
  79. // == Copied from OLE source code =================================
  80. // format for string form of GUID is (leading identifier ????)
  81. // ????{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}
  82. #define GUIDSTR_MAX (1+ 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1 + 1)
  83. // ================================================================
  84. #endif
  85. // Trace and debug flags
  86. #define TF_WEBCHECKCORE 0x00001000
  87. //#define TF_SCHEDULER 0x00002000
  88. #define TF_WEBCRAWL 0x00004000
  89. #define TF_SEPROX 0x00008000
  90. #define TF_CDFAGENT 0x00010000
  91. #define TF_STRINGLIST 0x00020000
  92. #define TF_URLDOWNLOAD 0x00040000
  93. #define TF_DOWNLD 0x00080000
  94. #define TF_DIALMON 0x00100000
  95. #define TF_MAILAGENT 0x00200000
  96. //#define TF_TRAYAGENT 0x00400000
  97. #define TF_SUBSFOLDER 0x00800000
  98. #define TF_MEMORY 0x01000000
  99. #define TF_UPDATEAGENT 0x02000000
  100. #define TF_POSTAGENT 0x04000000
  101. #define TF_DELAGENT 0x08000000
  102. #define TF_TRACKCACHE 0x10000000
  103. #define TF_SYNCMGR 0x20000000
  104. #define TF_THROTTLER 0x40000000
  105. #define TF_ADMIN 0x80000000 // Admin and IE upgrade
  106. #define PSM_QUERYSIBLINGS_WPARAM_RESCHEDULE 0XF000
  107. #undef DBG
  108. #define DBG(sz) TraceMsg(TF_THISMODULE, sz)
  109. #define DBG2(sz1, sz2) TraceMsg(TF_THISMODULE, sz1, sz2)
  110. #define DBG_WARN(sz) TraceMsg(TF_WARNING, sz)
  111. #define DBG_WARN2(sz1, sz2) TraceMsg(TF_WARNING, sz1, sz2)
  112. #ifdef DEBUG
  113. #define DBGASSERT(expr,sz) do { if (!(expr)) TraceMsg(TF_WARNING, (sz)); } while (0)
  114. #define DBGIID(sz,iid) DumpIID(sz,iid)
  115. #else
  116. #define DBGASSERT(expr,sz) ((void)0)
  117. #define DBGIID(sz,iid) ((void)0)
  118. #endif
  119. // shorthand
  120. #ifndef SAFERELEASE
  121. #define SAFERELEASE(p) if ((p) != NULL) { (p)->Release(); (p) = NULL; } else
  122. #endif
  123. #ifndef ATOMICRELEASE
  124. #define ATOMICRELEASET(p,type) { type* punkT=p; p=NULL; punkT->Release(); }
  125. #define ATOMICRELEASE(p) ATOMICRELEASET(p, IUnknown)
  126. #endif
  127. #ifndef SAFEFREEBSTR
  128. #define SAFEFREEBSTR(p) if ((p) != NULL) { SysFreeString(p); (p) = NULL; } else
  129. #endif
  130. #ifndef SAFEFREEOLESTR
  131. #define SAFEFREEOLESTR(p) if ((p) != NULL) { CoTaskMemFree(p); (p) = NULL; } else
  132. #endif
  133. #ifndef SAFELOCALFREE
  134. #define SAFELOCALFREE(p) if ((p) != NULL) { MemFree(p); (p) = NULL; } else
  135. #endif
  136. #ifndef SAFEDELETE
  137. #define SAFEDELETE(p) if ((p) != NULL) { delete (p); (p) = NULL; } else
  138. #endif
  139. // MAX_WEBCRAWL_LEVELS is the max crawl depth for site subscriptions
  140. // MAX_CDF_CRAWL_LEVELS is the max crawl depth for the "LEVEL" attrib value for CDFs
  141. #define MAX_WEBCRAWL_LEVELS 3
  142. #define MAX_CDF_CRAWL_LEVELS 3
  143. #define MY_MAX_CACHE_ENTRY_INFO 6144
  144. //
  145. // Define the location of the webcheck registry key.
  146. //
  147. #define WEBCHECK_REGKEY TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Webcheck")
  148. #define WEBCHECK_REGKEY_NOTF TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Webcheck\\Notification Handlers")
  149. #define WEBCHECK_REGKEY_STORE (WEBCHECK_REGKEY TEXT("\\Store.1"))
  150. //
  151. // Registry Keys
  152. //
  153. extern const TCHAR c_szRegKey[]; // registry key for webcheck stuff
  154. extern const TCHAR c_szRegKeyUsernames[]; // registry key for webcheck stuff
  155. extern const TCHAR c_szRegKeyPasswords[]; // registry key for webcheck stuff
  156. extern const TCHAR c_szRegKeyStore[];
  157. extern const TCHAR c_szRegPathInternetSettings[];
  158. // extern const TCHAR c_szRegKeyRestrictions[]; // HKCU\Policies\...\Infodelivery\Restrictions
  159. // extern const TCHAR c_szRegKeyModifications[]; // HKCU\Policies\...\Infodelivery\Modification
  160. // extern const TCHAR c_szRegKeyCompletedMods[]; // HKCU\Policies\...\Infodelivery\CompletedModifications
  161. //
  162. // Registry Values
  163. //
  164. extern const TCHAR c_szNoChannelLogging[];
  165. //
  166. // Globals
  167. //
  168. extern HINSTANCE g_hInst; // dll instance
  169. extern ULONG g_cLock; // outstanding locks
  170. extern ULONG g_cObj; // outstanding objects
  171. extern BOOL g_fIsWinNT; // are we on winNT? Always initialized.
  172. extern BOOL g_fIsWinNT5; // are we on winNT5? Always initialized.
  173. extern BOOL g_fIsMillennium; // are we on Millennium?
  174. extern const TCHAR c_szEnable[]; // enable unattended dialup
  175. extern const TCHAR c_szStrEmpty[];
  176. inline ULONG DllLock() { return InterlockedIncrement((LONG *)&g_cLock); }
  177. inline ULONG DllUnlock() { return InterlockedDecrement((LONG *)&g_cLock); }
  178. inline ULONG DllGetLock() { return g_cLock; }
  179. inline ULONG DllAddRef() { return InterlockedIncrement((LONG *)&g_cObj); }
  180. inline ULONG DllRelease() { return InterlockedDecrement((LONG *)&g_cObj); }
  181. inline ULONG DllGetRef() { return g_cObj; }
  182. //
  183. // Subscription property names; webcheck.cpp
  184. //
  185. // Agent Start
  186. extern const WCHAR c_szPropURL[]; // BSTR
  187. extern const WCHAR c_szPropName[]; // BSTR; friendly name
  188. extern const WCHAR c_szPropAgentFlags[]; // I4
  189. extern const WCHAR c_szPropCrawlLevels[]; // I4; webcrawler
  190. extern const WCHAR c_szPropCrawlFlags[]; // I4; webcrawler
  191. extern const WCHAR c_szPropCrawlMaxSize[]; // I4; webcrawler (in KB)
  192. extern const WCHAR c_szPropCrawlChangesOnly[]; // BOOL
  193. extern const WCHAR c_szPropChangeCode[]; // I4 or CY
  194. extern const WCHAR c_szPropEmailNotf[]; // BOOL;
  195. extern const WCHAR c_szPropCrawlUsername[]; // BSTR
  196. extern const WCHAR c_szPropCrawlLocalDest[]; // BSTR
  197. extern const WCHAR c_szPropEnableShortcutGleam[]; // I4
  198. extern const WCHAR c_szPropChannelFlags[]; // I4; channel agent specific flags
  199. extern const WCHAR c_szPropChannel[]; // I4; indicates a channel
  200. extern const WCHAR c_szPropDesktopComponent[]; // I4; indicates a desktop component
  201. // set by agents in Agent Start
  202. extern const WCHAR c_szPropCrawlGroupID[]; // cache group ID
  203. extern const WCHAR c_szPropCrawlNewGroupID[]; // ID for new (existing) cache group
  204. extern const WCHAR c_szPropCrawlActualSize[]; // in KB
  205. extern const WCHAR c_szPropActualProgressMax[]; // Progress Max at end of last update
  206. extern const WCHAR c_szStartCookie[]; // The cookie of Start Notification.
  207. extern const WCHAR c_szPropStatusCode[]; // SCODE
  208. extern const WCHAR c_szPropStatusString[]; // BSTR (sentence)
  209. extern const WCHAR c_szPropCompletionTime[]; // DATE
  210. extern const WCHAR c_szPropPassword[]; // BSTR
  211. // End Report
  212. extern const WCHAR c_szPropEmailURL[]; // BSTR
  213. extern const WCHAR c_szPropEmailFlags[]; // I4
  214. extern const WCHAR c_szPropEmailTitle[]; // BSTR
  215. extern const WCHAR c_szPropEmailAbstract[]; // BSTR
  216. extern const WCHAR c_szPropCharSet[]; // BSTR
  217. // Tray Agent Properties
  218. extern const WCHAR c_szPropGuidsArr[]; // SAFEARRAY for a list of GUIDs
  219. // Initial cookie used in AGENT_INIT notification.
  220. extern const WCHAR c_szInitCookie[]; // The cookie of Start Notification.
  221. // Tracking
  222. extern const WCHAR c_szTrackingCookie[]; // Channel identity
  223. extern const WCHAR c_szTrackingPostURL[]; // tracking post url
  224. extern const WCHAR c_szPostingRetry[]; //
  225. extern const WCHAR c_szPostHeader[]; // specify encoding method of postdata
  226. extern const WCHAR c_szPostPurgeTime[]; // DATE
  227. //
  228. // Mail agent flags for the c_szPropEmailFlags property
  229. //
  230. enum MAILAGENT_FLAGS {
  231. MAILAGENT_FLAG_CUSTOM_MSG = 0x1
  232. };
  233. //
  234. // Mail functions
  235. //
  236. HRESULT SendEmailFromItem(ISubscriptionItem *pItem);
  237. HRESULT MimeOleEncodeStreamQP(IStream *pstmIn, IStream *pstmOut);
  238. void ReadDefaultSMTPServer(LPTSTR pszBuf, UINT cch);
  239. void ReadDefaultEmail(LPTSTR pszBuf, UINT cch);
  240. // utils.cpp
  241. interface IChannelMgrPriv;
  242. HRESULT GetChannelPath(LPCTSTR pszURL, LPTSTR pszPath, int cch, IChannelMgrPriv** ppIChannelMgrPriv);
  243. //
  244. // Timer id's for scheduler and dialmon
  245. //
  246. #define TIMER_ID_DIALMON_IDLE 2 // every minute while connected
  247. #define TIMER_ID_DIALMON_SEC 3 // every second for 30 seconds
  248. #define TIMER_ID_DBL_CLICK 4 // did the user single or double click
  249. #define TIMER_ID_USER_IDLE 5 // used to detect user idle on system
  250. // Custom schedule dialog proc
  251. BOOL CALLBACK CustomDlg(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  252. int SGMessageBox(HWND, UINT, UINT);
  253. //
  254. // Dialmon messages - send to scheduler window by various pieces of the system
  255. // to tell us when dialup related stuff happens
  256. //
  257. #define WM_DIALMON_FIRST WM_USER+100
  258. #define WM_WINSOCK_ACTIVITY WM_DIALMON_FIRST + 0
  259. #define WM_REFRESH_SETTINGS WM_DIALMON_FIRST + 1
  260. #define WM_SET_CONNECTOID_NAME WM_DIALMON_FIRST + 2
  261. #define WM_IEXPLORER_EXITING WM_DIALMON_FIRST + 3
  262. // new set of Dialmon messages to support timeout for Mars + any other apps.
  263. #define WM_DIALMON_HOOK WM_DIALMON_FIRST + 4
  264. #define WM_DIALMON_UNHOOK WM_DIALMON_FIRST + 5
  265. #define WM_CANHANGUP WM_DIALMON_FIRST + 6
  266. #define WM_CONFIRM_HANGUP WM_DIALMON_FIRST + 7
  267. #define WM_DENY_HANGUP WM_DIALMON_FIRST + 8
  268. #define WM_HANGING_UP WM_DIALMON_FIRST + 9
  269. // maximum number of application processes using dialmon at the same time.
  270. #define MAX_DIALMON_HANDLES 10
  271. // message used to report user mouse or kbd activity
  272. // Note: sage.vxd uses this value and we can't change it.
  273. #define WM_USER_ACTIVITY WM_USER+5
  274. // message sent by loadwc requesting a dynaload of sens/lce.
  275. #define WM_LOAD_SENSLCE WM_USER+200
  276. #define WM_IS_SENSLCE_LOADED WM_USER+201
  277. //
  278. // Random subscription defaults
  279. //
  280. #define DEFAULTLEVEL 0
  281. #define DEFAULTFLAGS (WEBCRAWL_GET_IMAGES | WEBCRAWL_LINKS_ELSEWHERE | WEBCRAWL_GET_CONTROLS)
  282. #define IsNativeAgent(CLSIDAGENT) (((CLSIDAGENT) == CLSID_WebCrawlerAgent) || ((CLSIDAGENT) == CLSID_ChannelAgent))
  283. #define IS_VALID_SUBSCRIPTIONTYPE(st) ((st == SUBSTYPE_URL) || (st == SUBSTYPE_CHANNEL) || (st == SUBSTYPE_DESKTOPCHANNEL) || (st == SUBSTYPE_DESKTOPURL))
  284. //
  285. // Useful functions
  286. //
  287. int MyOleStrToStrN(LPTSTR psz, int cchMultiByte, LPCOLESTR pwsz);
  288. int MyStrToOleStrN(LPOLESTR pwsz, int cchWideChar, LPCTSTR psz);
  289. void DumpIID(LPCSTR psz, REFIID riid);
  290. // String comparison routines ; assume 8-bit characters. Return 0 or nonzero.
  291. // Will work correctly if one or both strings are entirely 8-bit characters.
  292. int MyAsciiCmpW(LPCWSTR pwsz1, LPCWSTR pwsz2);
  293. int MyAsciiCmpNIW(LPCWSTR pwsz1, LPCWSTR pwsz2, int iLen);
  294. inline
  295. int MyAsciiCmpNW(LPCWSTR pwsz1, LPCWSTR pwsz2, int iLen)
  296. { return memcmp(pwsz1, pwsz2, iLen*sizeof(WCHAR)); }
  297. // Implementation in CDFagent.cpp
  298. HRESULT XMLScheduleElementToTaskTrigger(IXMLElement *pRootEle, TASK_TRIGGER *ptt);
  299. HRESULT ScheduleToTaskTrigger(TASK_TRIGGER *ptt, SYSTEMTIME *pstStartDate, SYSTEMTIME *pstEndDate,
  300. long lInterval, long lEarliest, long lLatest, int iZone=9999);
  301. // Admin related functions
  302. HRESULT ProcessInfodeliveryPolicies(void);
  303. #ifndef ARRAYSIZE
  304. #define ARRAYSIZE(a) (sizeof(a) / sizeof(a[0]))
  305. #endif
  306. // IE 5 versions - sans notfmgr support
  307. HRESULT ReadDWORD (ISubscriptionItem *pItem, LPCWSTR szName, DWORD *pdwRet);
  308. HRESULT ReadLONGLONG (ISubscriptionItem *pItem, LPCWSTR szName, LONGLONG *pllRet);
  309. HRESULT ReadGUID (ISubscriptionItem *pItem, LPCWSTR szName, GUID *);
  310. HRESULT ReadDATE (ISubscriptionItem *pItem, LPCWSTR szName, DATE *dtVal);
  311. HRESULT ReadBool (ISubscriptionItem *pItem, LPCWSTR szName, VARIANT_BOOL *pBoolRet);
  312. HRESULT ReadBSTR (ISubscriptionItem *pItem, LPCWSTR szName, BSTR *bstrRet);
  313. HRESULT ReadOLESTR (ISubscriptionItem *pItem, LPCWSTR szName, LPWSTR *pszRet);
  314. HRESULT ReadAnsiSTR (ISubscriptionItem *pItem, LPCWSTR szName, LPSTR *ppszRet);
  315. HRESULT ReadSCODE (ISubscriptionItem *pItem, LPCWSTR szName, SCODE *pscRet);
  316. HRESULT ReadVariant (ISubscriptionItem *pItem, LPCWSTR szName, VARIANT *pvarRet);
  317. HRESULT WriteDWORD (ISubscriptionItem *pItem, LPCWSTR szName, DWORD dwVal);
  318. HRESULT WriteLONGLONG (ISubscriptionItem *pItem, LPCWSTR szName, LONGLONG llVal);
  319. HRESULT WriteGUID (ISubscriptionItem *pItem, LPCWSTR szName, GUID *);
  320. HRESULT WriteDATE (ISubscriptionItem *pItem, LPCWSTR szName, DATE *dtVal);
  321. HRESULT WriteOLESTR (ISubscriptionItem *pItem, LPCWSTR szName, LPCWSTR szVal);
  322. HRESULT WriteResSTR (ISubscriptionItem *pItem, LPCWSTR szName, UINT uID);
  323. HRESULT WriteAnsiSTR (ISubscriptionItem *pItem, LPCWSTR szName, LPCSTR szVal);
  324. HRESULT WriteSCODE (ISubscriptionItem *pItem, LPCWSTR szName, SCODE scVal);
  325. HRESULT WriteEMPTY (ISubscriptionItem *pItem, LPCWSTR szName);
  326. HRESULT WriteVariant (ISubscriptionItem *pItem, LPCWSTR szName, VARIANT *pvarVal);
  327. #ifdef UNICODE
  328. #define ReadTSTR ReadOLESTR
  329. #define WriteTSTR WriteOLESTR
  330. #else
  331. #define ReadTSTR ReadAnsiSTR
  332. #define WriteTSTR WriteAnsiSTR
  333. #endif
  334. HRESULT WritePassword (ISubscriptionItem *pItem, BSTR szPassword);
  335. HRESULT ReadPassword (ISubscriptionItem *pItem, BSTR *ppszPassword);
  336. // WEBCRAWL.CPP helper functions
  337. // Do cool stuff to a single URL in the cache. Make sticky, get size, put in group...
  338. // Returns E_OUTOFMEMORY if make sticky fails
  339. HRESULT GetUrlInfoAndMakeSticky(
  340. LPCTSTR pszBaseUrl, // Base URL. May be NULL if pszThisUrl is absolute
  341. LPCTSTR pszThisUrl, // Absolute or relative url
  342. LPINTERNET_CACHE_ENTRY_INFO lpCacheEntryInfo, // Required
  343. DWORD dwBufSize, // Size of *lpCacheEntryInfo
  344. GROUPID llCacheGroupID); // Group ID ; may be 0
  345. // PreCheckUrlForChange and PostCheckUrlForChange are documented in webcrawl.cpp
  346. HRESULT PreCheckUrlForChange(LPCTSTR lpURL, VARIANT *pvarChange, BOOL *pfGetContent);
  347. HRESULT PostCheckUrlForChange(VARIANT *pvarChange,
  348. LPINTERNET_CACHE_ENTRY_INFO lpInfo, FILETIME ftNewLastModified);
  349. HRESULT WriteCookieToInetDB(LPCTSTR pszURL, SUBSCRIPTIONCOOKIE *pCookie, BOOL bRemove);
  350. HRESULT ReadCookieFromInetDB(LPCTSTR pszURL, SUBSCRIPTIONCOOKIE *pCookie);
  351. #define MAX_RES_STRING_LEN 128 // max resource string len for WriteStringRes
  352. // IntSite helper function
  353. HRESULT IntSiteHelper(LPCTSTR pszURL, const PROPSPEC *pReadPropspec,
  354. PROPVARIANT *pReadPropvar, UINT uPropVarArraySize, BOOL fWrite);
  355. extern const PROPSPEC c_rgPropRead[];
  356. #define PROP_SUBSCRIPTION 0
  357. #define PROP_FLAGS 1
  358. #define PROP_TRACKING 2
  359. #define PROP_CODEPAGE 3
  360. //=============================================================================
  361. // Helper class for aggregation. Inherit from this like another interface, then
  362. // implement InnerQI and include IMPLEMENT_DELEGATE_UNKNOWN in your class declaration
  363. class CInnerUnknown
  364. {
  365. public:
  366. CInnerUnknown() { m_cRef = 1; m_punkOuter=(IUnknown *)(CInnerUnknown *)this; }
  367. void InitAggregation(IUnknown *punkOuter, IUnknown **punkInner)
  368. {
  369. if (punkOuter)
  370. {
  371. m_punkOuter = punkOuter;
  372. *punkInner = (IUnknown *)(CInnerUnknown *)this;
  373. }
  374. }
  375. virtual HRESULT STDMETHODCALLTYPE InnerQI(REFIID riid, void **ppunk) = 0;
  376. virtual ULONG STDMETHODCALLTYPE InnerAddRef() { return ++m_cRef; }
  377. virtual ULONG STDMETHODCALLTYPE InnerRelease() = 0;
  378. protected:
  379. long m_cRef;
  380. IUnknown *m_punkOuter;
  381. };
  382. #define IMPLEMENT_DELEGATE_UNKNOWN() \
  383. STDMETHODIMP QueryInterface(REFIID riid, void **ppunk) \
  384. { return m_punkOuter->QueryInterface(riid, ppunk); } \
  385. STDMETHODIMP_(ULONG) AddRef() { return m_punkOuter->AddRef(); } \
  386. STDMETHODIMP_(ULONG) Release() { return m_punkOuter->Release(); } \
  387. STDMETHODIMP_(ULONG) InnerRelease() { \
  388. if (0L != --m_cRef) return m_cRef; \
  389. delete this; \
  390. return 0L; }
  391. // end aggregation helpers
  392. //=============================================================================
  393. // Registry helper functions
  394. BOOL ReadRegValue(HKEY hkeyRoot, const TCHAR *pszKey, const TCHAR *pszValue,
  395. void *pData, DWORD dwBytes);
  396. BOOL WriteRegValue(HKEY hkeyRoot, const TCHAR *pszKey, const TCHAR *pszValue,
  397. void *pData, DWORD dwBytes, DWORD dwType);
  398. DWORD ReadRegDWORD(HKEY hkeyRoot, const TCHAR *pszKey, const TCHAR *pszValue);
  399. // Event logging function
  400. DWORD __cdecl LogEvent(LPTSTR pszEvent, ...);
  401. // Thread proc for firing up sens and lce
  402. DWORD WINAPI ExternalsThread(LPVOID lpData);
  403. // Used to set syncmgr "warning" level
  404. #define INET_E_AGENT_WARNING 0x800C0FFE
  405. //
  406. // Main WebCheck class
  407. //
  408. class CWebCheck : public IOleCommandTarget
  409. {
  410. protected:
  411. ULONG m_cRef;
  412. public:
  413. CWebCheck(void);
  414. ~CWebCheck(void);
  415. // IUnknown members
  416. STDMETHODIMP QueryInterface(REFIID, void **);
  417. STDMETHODIMP_(ULONG) AddRef(void);
  418. STDMETHODIMP_(ULONG) Release(void);
  419. // IWebCheck members
  420. STDMETHODIMP StartService(BOOL fForceExternals);
  421. STDMETHODIMP StopService(void);
  422. // IOleCommandTarget members
  423. STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup,
  424. ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText);
  425. STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
  426. DWORD nCmdexecopt, VARIANTARG *pvaIn,
  427. VARIANTARG *pvaOut);
  428. // External handling members
  429. BOOL ShouldLoadExternals(void);
  430. BOOL AreExternalsLoaded(void);
  431. void LoadExternals(void);
  432. void UnloadExternals(void);
  433. // thread for handling external bits
  434. HANDLE _hThread;
  435. // events to synchronize with external thread
  436. HANDLE _hTerminateEvent;
  437. };
  438. //
  439. // CMemStream class
  440. //
  441. class CMemStream
  442. {
  443. protected:
  444. IStream * m_pstm;
  445. BOOL m_fDirty;
  446. BOOL m_fError;
  447. public:
  448. BOOL m_fNewStream;
  449. public:
  450. CMemStream(BOOL fNewStream=TRUE);
  451. ~CMemStream();
  452. BOOL IsError() { return m_fError; }
  453. HRESULT Read(void *pv, ULONG cb, ULONG *cbRead);
  454. HRESULT Write(void *pv, ULONG cb, ULONG *cbWritten);
  455. HRESULT Seek(long lMove, DWORD dwOrigin, DWORD *dwNewPos);
  456. HRESULT SaveToStream(IUnknown *punk);
  457. HRESULT LoadFromStream(IUnknown **ppunk);
  458. HRESULT CopyToStream(IStream *pStm);
  459. };
  460. extern BOOL IsGlobalOffline(void);
  461. extern void SetGlobalOffline(BOOL fOffline);
  462. #define MemAlloc LocalAlloc
  463. #define MemFree LocalFree
  464. #define MemReAlloc LocalReAlloc
  465. typedef HRESULT (* CREATEPROC)(IUnknown *, IUnknown **);
  466. // Helper functions to read and write passwords to an encrypted store.
  467. STDAPI ReadNotificationPassword(LPCWSTR wszUrl, BSTR * pbstrPassword);
  468. STDAPI WriteNotificationPassword(LPCWSTR wszUrl, BSTR bstrPassword);
  469. // dialmon functions
  470. BOOL DialmonInit(void);
  471. void DialmonShutdown(void);
  472. // LCE dynaload entry points
  473. typedef HRESULT (* LCEREGISTER)(HMODULE);
  474. typedef HRESULT (* LCEUNREGISTER)(HMODULE);
  475. typedef HRESULT (* LCESTART)(void);
  476. typedef HRESULT (* LCESTOP)(void);
  477. // SENS dynaload entry points
  478. typedef HRESULT (* SENSREGISTER)(void);
  479. typedef BOOL (* SENSSTART)(void);
  480. typedef BOOL (* SENSSTOP)(void);
  481. // event dispatching
  482. DWORD DispatchEvent(DWORD dwEvent, LPWSTR pwsEventDesc, DWORD dwEventData);