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.

167 lines
4.3 KiB

  1. // SessionResolver.h : Declaration of the CSessionResolver
  2. #ifndef __SESSIONRESOLVER_H_
  3. #define __SESSIONRESOLVER_H_
  4. #include "resource.h" // main symbols
  5. #include <io.h>
  6. #include <fcntl.h>
  7. #include <stdio.h>
  8. #include <sys/types.h>
  9. #include <sys/stat.h>
  10. #define DBG_MSG_DEST_FILE 0x020
  11. extern int gDbgFlag, iDbgFileHandle;
  12. typedef struct _SPLASHLIST
  13. {
  14. void *next;
  15. int refcount;
  16. SID Sid;
  17. } SPLASHLIST, *PSPLASHLIST;
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CSessionResolver
  20. class ATL_NO_VTABLE CSessionResolver :
  21. public CComObjectRootEx<CComSingleThreadModel>,
  22. public CComCoClass<CSessionResolver, &CLSID_SessionResolver>,
  23. public IDispatchImpl<ISAFRemoteDesktopCallback, &IID_ISAFRemoteDesktopCallback, &LIBID_SAFSESSIONRESOLVERLib>
  24. {
  25. public:
  26. CSessionResolver()
  27. {
  28. CRegKey hkSpew;
  29. // initialize our defaults
  30. m_iWaitDuration = 300 * 1000; // 5 minute timeout
  31. #ifdef _PERF_OPTIMIZATIONS
  32. m_bstrResolveURL = OLESTR("hcp://system/Remote%20Assistance/RAStartPage.htm");
  33. m_bstrConnectURL = OLESTR("hcp://system/Remote%20Assistance/RAStartPage.htm");
  34. m_bstrRemoteURL = OLESTR("hcp://system/Remote%20Assistance/RAStartPage.htm");
  35. #else
  36. m_bstrResolveURL = OLESTR("hcp://CN=Microsoft%20Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance/RAStartPage.htm");
  37. m_bstrConnectURL = OLESTR("hcp://CN=Microsoft%20Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance/RAStartPage.htm");
  38. m_bstrRemoteURL = OLESTR("hcp://CN=Microsoft%20Corporation,L=Redmond,S=Washington,C=US/Remote%20Assistance/RAStartPage.htm");
  39. #endif
  40. m_lSessionTag = 0;
  41. gDbgFlag = 3;
  42. iDbgFileHandle = 0;
  43. if (ERROR_SUCCESS == hkSpew.Open(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\PCHealth\\HelpCtr\\SAFSessionResolver", KEY_READ))
  44. {
  45. DWORD dwLen = sizeof(gDbgFlag);
  46. hkSpew.QueryValue((LPTSTR)&gDbgFlag, L"DebugSpew", &dwLen);
  47. }
  48. if (gDbgFlag & DBG_MSG_DEST_FILE)
  49. {
  50. WCHAR szLogfileName[MAX_PATH];
  51. GetSystemDirectory(szLogfileName, sizeof(szLogfileName)/sizeof(szLogfileName[0]));
  52. wcscat(szLogfileName, L"\\safrslv.log");
  53. iDbgFileHandle = _wopen(szLogfileName, _O_APPEND | _O_BINARY | _O_RDWR, 0);
  54. if (-1 != iDbgFileHandle)
  55. {
  56. OutputDebugStringA("opened debug log file\n");
  57. }
  58. else
  59. {
  60. unsigned char UniCode[2] = {0xff, 0xfe};
  61. // we must create the file
  62. OutputDebugStringA("must create debug log file");
  63. iDbgFileHandle = _wopen(szLogfileName, _O_BINARY | _O_CREAT | _O_RDWR, _S_IREAD | _S_IWRITE);
  64. if (-1 != iDbgFileHandle)
  65. _write(iDbgFileHandle, &UniCode, sizeof(UniCode));
  66. else
  67. {
  68. OutputDebugStringA("ERROR: failed to create debug log file");
  69. iDbgFileHandle = 0;
  70. }
  71. }
  72. }
  73. InitializeCriticalSection(&m_CritSec);
  74. m_pSplash = (SPLASHLIST *)LocalAlloc(LMEM_FIXED, sizeof(SPLASHLIST));
  75. if (m_pSplash)
  76. {
  77. // make certain that we start the splash list with an empty
  78. // SID.
  79. ZeroMemory(m_pSplash, sizeof(SPLASHLIST));
  80. }
  81. }
  82. ~CSessionResolver()
  83. {
  84. m_bstrResolveURL.Empty();
  85. m_bstrConnectURL.Empty();
  86. m_bstrRemoteURL.Empty();
  87. DeleteCriticalSection(&m_CritSec);
  88. PSPLASHLIST lpWalker, lpNext;
  89. lpWalker = m_pSplash;
  90. while (lpWalker)
  91. {
  92. lpNext = (SPLASHLIST *)lpWalker->next;
  93. LocalFree(lpWalker);
  94. lpWalker = lpNext;
  95. }
  96. if (iDbgFileHandle)
  97. _close(iDbgFileHandle);
  98. iDbgFileHandle = 0;
  99. }
  100. DECLARE_REGISTRY_RESOURCEID(IDR_SESSIONRESOLVER)
  101. DECLARE_NOT_AGGREGATABLE(CSessionResolver)
  102. DECLARE_PROTECT_FINAL_CONSTRUCT()
  103. BEGIN_COM_MAP(CSessionResolver)
  104. COM_INTERFACE_ENTRY(ISAFRemoteDesktopCallback)
  105. COM_INTERFACE_ENTRY(IDispatch)
  106. END_COM_MAP()
  107. public:
  108. //
  109. // ISAFRemoteDesktopCallback Methods
  110. //
  111. STDMETHOD(OnDisconnect)(
  112. /*[in]*/BSTR connectParms,
  113. /*[in]*/BSTR userSID,
  114. /*[in]*/long sessionID
  115. );
  116. STDMETHOD(ResolveUserSessionID)(
  117. /*[in]*/BSTR connectParms,
  118. /*[in]*/BSTR userSID,
  119. /*[in]*/ BSTR expertHelpBlob,
  120. /*[in]*/ BSTR userHelpBlob,
  121. /*[in, out, retval]*/long *sessionID,
  122. /*[in]*/DWORD dwPID
  123. ,/*[out]*/ULONG_PTR* hHelpCtr
  124. ,/*[out, retval]*/int *result
  125. );
  126. private:
  127. int m_iWaitDuration;
  128. int m_iDbgFlag;
  129. long m_lSessionTag;
  130. CRITICAL_SECTION m_CritSec;
  131. PSPLASHLIST m_pSplash;
  132. CComBSTR m_bstrResolveURL;
  133. CComBSTR m_bstrConnectURL;
  134. CComBSTR m_bstrRemoteURL;
  135. };
  136. #endif //__SESSIONRESOLVER_H_