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.

229 lines
4.6 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: statusping.cpp
  6. //
  7. // Creator: PeterWi
  8. //
  9. // Purpose: status ping back functions
  10. //
  11. //=======================================================================
  12. #include "pch.h"
  13. #pragma hdrstop
  14. PingStatus gPingStatus;
  15. void PingStatus::ReadLiveServerUrlFromIdent(void)
  16. {
  17. LPTSTR ptszLiveServerUrl;
  18. if (NULL != (ptszLiveServerUrl = (TCHAR*) malloc(sizeof(TCHAR) * INTERNET_MAX_URL_LENGTH)))
  19. {
  20. TCHAR tszIdentFile[MAX_PATH];
  21. if (SUCCEEDED(GetDownloadPath(tszIdentFile, ARRAYSIZE(tszIdentFile))) &&
  22. SUCCEEDED(PathCchAppend(tszIdentFile, ARRAYSIZE(tszIdentFile), IDENTTXT)))
  23. {
  24. DWORD dwStrLen = GetPrivateProfileString(
  25. _T("IUPingServer"),
  26. _T("ServerUrl"),
  27. _T(""),
  28. ptszLiveServerUrl,
  29. INTERNET_MAX_URL_LENGTH,
  30. tszIdentFile);
  31. if (0 != dwStrLen &&
  32. INTERNET_MAX_URL_LENGTH-1 != dwStrLen) // do this until there's a better way to check for errors
  33. {
  34. (void) SetLiveServerUrl(ptszLiveServerUrl);
  35. }
  36. else
  37. {
  38. DEBUGMSG("PingStatus::ReadLiveServerUrlFromIdent() failed to read server URL from ident");
  39. }
  40. }
  41. free(ptszLiveServerUrl);
  42. }
  43. }
  44. void PingStatus::PingDetectionSuccess(
  45. BOOL fOnline,
  46. UINT cItems)
  47. {
  48. TCHAR tszMessage[30];
  49. (void) StringCchPrintfEx(tszMessage, ARRAYSIZE(tszMessage), NULL, NULL, MISTSAFE_STRING_FLAGS, _T("items=%u"), cItems);
  50. _Ping(
  51. fOnline,
  52. URLLOGACTIVITY_Detection,
  53. URLLOGSTATUS_Success,
  54. 0,
  55. tszMessage,
  56. NULL,
  57. NULL);
  58. }
  59. void PingStatus::PingDetectionFailure(
  60. BOOL fOnline,
  61. DWORD dwError,
  62. LPCTSTR ptszMessage)
  63. {
  64. _Ping(
  65. fOnline,
  66. URLLOGACTIVITY_Detection,
  67. URLLOGSTATUS_Failed,
  68. dwError,
  69. ptszMessage,
  70. NULL,
  71. NULL);
  72. }
  73. void PingStatus::PingDownload(
  74. BOOL fOnline,
  75. URLLOGSTATUS status,
  76. DWORD dwError,
  77. LPCTSTR ptszItemID,
  78. LPCTSTR ptszDeviceID,
  79. LPCTSTR ptszMessage)
  80. {
  81. switch (status)
  82. {
  83. case URLLOGSTATUS_Success:
  84. case URLLOGSTATUS_Failed:
  85. case URLLOGSTATUS_Declined:
  86. break;
  87. default:
  88. DEBUGMSG("ERROR: PingDownload() invalid parameter");
  89. return;
  90. }
  91. _Ping(
  92. fOnline,
  93. URLLOGACTIVITY_Download,
  94. status,
  95. dwError,
  96. ptszMessage,
  97. ptszItemID,
  98. ptszDeviceID);
  99. }
  100. void PingStatus::PingDeclinedItem(
  101. BOOL fOnline,
  102. URLLOGACTIVITY activity,
  103. LPCTSTR ptszItemID)
  104. {
  105. switch (activity)
  106. {
  107. case URLLOGACTIVITY_Download:
  108. case URLLOGACTIVITY_Installation:
  109. break;
  110. default:
  111. DEBUGMSG("ERROR: PingDeclinedItem() invalid activity code");
  112. return;
  113. }
  114. if (NULL == ptszItemID)
  115. {
  116. DEBUGMSG("ERROR: PingDeclinedItem() invalid item ID");
  117. return;
  118. }
  119. _Ping(
  120. fOnline,
  121. activity,
  122. URLLOGSTATUS_Declined,
  123. 0x0,
  124. NULL,
  125. ptszItemID,
  126. NULL);
  127. }
  128. ///////////////////////////////////////////////////////////////////////////////////
  129. // status: IN ping status code
  130. // dwError: IN error code
  131. ///////////////////////////////////////////////////////////////////////////////////
  132. void PingStatus::PingSelfUpdate(
  133. BOOL fOnline,
  134. URLLOGSTATUS status,
  135. DWORD dwError)
  136. {
  137. const TCHAR WUAUENGFILE[] = _T("wuaueng.dll");
  138. TCHAR tszFileVer[30];
  139. HRESULT hr;
  140. size_t cchVerLen;
  141. LPTSTR ptszFileVersion;
  142. switch (status)
  143. {
  144. case URLLOGSTATUS_Success:
  145. case URLLOGSTATUS_Failed:
  146. case URLLOGSTATUS_Pending:
  147. break;
  148. default:
  149. DEBUGMSG("ERROR: PingSelfUpdate() invalid parameter");
  150. return;
  151. }
  152. if (FAILED(hr = StringCchCopyEx(
  153. tszFileVer,
  154. ARRAYSIZE(tszFileVer),
  155. _T("ver="),
  156. &ptszFileVersion,
  157. &cchVerLen,
  158. MISTSAFE_STRING_FLAGS)) ||
  159. FAILED(hr = GetFileVersionStr(
  160. WUAUENGFILE,
  161. ptszFileVersion,
  162. cchVerLen)))
  163. {
  164. DEBUGMSG("ERROR: PingSelfUpdate() GetFileVersionStr() failed.");
  165. return;
  166. }
  167. _Ping(
  168. fOnline,
  169. URLLOGACTIVITY_SelfUpdate,
  170. status,
  171. dwError,
  172. tszFileVer,
  173. NULL, // no item
  174. NULL); // no device
  175. }
  176. //----------------------------------------------------------------------
  177. //
  178. // private function to gather common info and perform ping
  179. //
  180. //----------------------------------------------------------------------
  181. void PingStatus::_Ping(
  182. BOOL fOnline,
  183. URLLOGACTIVITY activity,
  184. URLLOGSTATUS status,
  185. DWORD dwError,
  186. LPCTSTR ptszMessage,
  187. LPCTSTR ptszItemID,
  188. LPCTSTR ptszDeviceID)
  189. {
  190. HRESULT hr = CUrlLog::Ping(
  191. fOnline,
  192. URLLOGDESTINATION_DEFAULT,
  193. &ghServiceFinished,
  194. 1,
  195. activity,
  196. status,
  197. dwError,
  198. ptszItemID,
  199. ptszDeviceID,
  200. ptszMessage); // use default base URL and client name
  201. if (FAILED(hr))
  202. {
  203. DEBUGMSG("PingStatus::_Ping() failed to send/queue the request");
  204. }
  205. }