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.

246 lines
8.3 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 2001 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: URLLogging.h
  6. //
  7. // Description:
  8. //
  9. // URL logging utility class
  10. // This class helps you construct the server ping URL and
  11. // then send the ping to the designed server.
  12. //
  13. // The default base URL is defined in IUIdent, under section [IUPingServer]
  14. // and entry is "ServerUrl".
  15. //
  16. // This class implements single-thread version only. So it is suitable
  17. // to call it at operation level, i.e., create a separate object
  18. // for each operation in a single thread.
  19. //
  20. // The ping string send to the ping server has the following format:
  21. // /wutrack.bin
  22. // ?U=<user>
  23. // &C=<client>
  24. // &A=<activity>
  25. // &I=<item>
  26. // &D=<device>
  27. // &P=<platform>
  28. // &L=<language>
  29. // &S=<status>
  30. // &E=<error>
  31. // &M=<message>
  32. // &X=<proxy>
  33. // where
  34. // <user> a static 128-bit value that unique-ifies each copy
  35. // of Windows installed. The class will automatically
  36. // reuse one previously assigned to the running OS; or
  37. // will generate one if it does not exist.
  38. // <client> a string that identifies the entity that performed
  39. // activity <activity>. Here are the possible values
  40. // and their meanings:
  41. // "iu" IU control
  42. // "au" Automatic Updates
  43. // "du" Dynamic Update
  44. // "CDM" Code Download Manager
  45. // "IU_SITE" IU Consumer site
  46. // "IU_Corp" IU Catalog site
  47. // <activity> a letter that identifies the activity performed.
  48. // Here are the possible values and their meanings:
  49. // "n" IU control initization
  50. // "d" detection
  51. // "s" self-update
  52. // "w" download
  53. // "i" installation
  54. // <item> a string that identifies an update item.
  55. // <device> a string that identifies either a device's PNPID when
  56. // device driver not found during detection; or a
  57. // PNPID/CompatID used by item <item> for activity
  58. // <activity> if the item is a device driver.
  59. // <platform> a string that identifies the platform of the running
  60. // OS and processor architecture. The class will
  61. // compute this value for the pingback.
  62. // <language> a string that identifies the language of the OS
  63. // binaries. The class will compute this value for the
  64. // pingback.
  65. // <status> a letter that specifies the status that activity
  66. // <activity> reached. Here are the possible values and
  67. // their meanings:
  68. // "s" succeeded
  69. // "r" succeeded (reboot required)
  70. // "f" failed
  71. // "c" cancelled by user
  72. // "d" declined by user
  73. // "n" no items
  74. // "p" pending
  75. // <error> a 32-bit error code in hex (w/o "0x" as prefix).
  76. // <message> a string that provides additional information for the
  77. // status <status>.
  78. // <proxy> a 32-bit random value in hex for overriding proxy
  79. // caching. This class will compute this value for
  80. // each pingback.
  81. //
  82. //=======================================================================
  83. #pragma once
  84. typedef CHAR URLLOGPROGRESS;
  85. typedef CHAR URLLOGDESTINATION;
  86. typedef TCHAR URLLOGACTIVITY;
  87. typedef TCHAR URLLOGSTATUS;
  88. #define URLLOGPROGRESS_ToBeSent ((CHAR) 0)
  89. #define URLLOGPROGRESS_Sent ((CHAR) -1)
  90. #define URLLOGDESTINATION_DEFAULT ((CHAR) '?')
  91. #define URLLOGDESTINATION_LIVE ((CHAR) 'l')
  92. #define URLLOGDESTINATION_CORPWU ((CHAR) 'c')
  93. #define URLLOGACTIVITY_Initialization ((URLLOGACTIVITY) L'n')
  94. #define URLLOGACTIVITY_Detection ((URLLOGACTIVITY) L'd')
  95. #define URLLOGACTIVITY_SelfUpdate ((URLLOGACTIVITY) L's')
  96. #define URLLOGACTIVITY_Download ((URLLOGACTIVITY) L'w')
  97. #define URLLOGACTIVITY_Installation ((URLLOGACTIVITY) L'i')
  98. #define URLLOGSTATUS_Success ((URLLOGSTATUS) L's')
  99. #define URLLOGSTATUS_Reboot ((URLLOGSTATUS) L'r')
  100. #define URLLOGSTATUS_Failed ((URLLOGSTATUS) L'f')
  101. #define URLLOGSTATUS_Cancelled ((URLLOGSTATUS) L'c')
  102. #define URLLOGSTATUS_Declined ((URLLOGSTATUS) L'd')
  103. #define URLLOGSTATUS_NoItems ((URLLOGSTATUS) L'n')
  104. #define URLLOGSTATUS_Pending ((URLLOGSTATUS) L'p')
  105. typedef struct tagURLENTRYHEADER
  106. {
  107. URLLOGPROGRESS progress; // Whether this entry has been sent
  108. URLLOGDESTINATION destination;
  109. WORD wRequestSize; // in WCHARs
  110. WORD wServerUrlLen; // in WCHARs
  111. } ULENTRYHEADER, PULENTRYHEADER;
  112. class CUrlLog
  113. {
  114. public:
  115. CUrlLog(void);
  116. CUrlLog(
  117. LPCTSTR ptszClientName,
  118. LPCTSTR ptszLiveServerUrl, // from iuident
  119. LPCTSTR ptszCorpServerUrl); // from Federated WU domain policy
  120. ~CUrlLog(void);
  121. BOOL SetDefaultClientName(LPCTSTR ptszClientName);
  122. inline BOOL SetLiveServerUrl(LPCTSTR ptszLiveServerUrl)
  123. {
  124. return SetServerUrl(ptszLiveServerUrl, m_ptszLiveServerUrl);
  125. }
  126. inline BOOL SetCorpServerUrl(LPCTSTR ptszCorpServerUrl)
  127. {
  128. return SetServerUrl(ptszCorpServerUrl, m_ptszCorpServerUrl);
  129. }
  130. HRESULT Ping(
  131. BOOL fOnline, // online or offline ping
  132. URLLOGDESTINATION destination, // live or corp WU ping server
  133. PHANDLE phQuitEvents, // ptr to handles for cancelling the operation
  134. UINT nQuitEventCount, // number of handles
  135. URLLOGACTIVITY activity, // activity code
  136. URLLOGSTATUS status, // status code
  137. DWORD dwError = 0x0, // error code
  138. LPCTSTR ptszItemID = NULL, // uniquely identify an item
  139. LPCTSTR ptszDeviceID = NULL, // PNPID or CompatID
  140. LPCTSTR tszMessage = NULL, // additional info
  141. LPCTSTR ptszClientName = NULL); // client name string
  142. // Send all pending (offline) ping requests to server
  143. HRESULT Flush(PHANDLE phQuitEvents, UINT nQuitEventCount);
  144. protected:
  145. LPTSTR m_ptszLiveServerUrl;
  146. LPTSTR m_ptszCorpServerUrl;
  147. private:
  148. TCHAR m_tszLogFile[MAX_PATH];
  149. // TCHAR m_tszTmpLogFile[MAX_PATH];
  150. TCHAR m_tszDefaultClientName[64];
  151. TCHAR m_tszPlatform[8+1+8+1+8+1+8+1+4+1+4+1+4 + 1];
  152. TCHAR m_tszLanguage[8+1+8 + 1]; // according to RFC1766
  153. TCHAR m_tszPingID[sizeof(UUID) * 2 + 1];
  154. // Common init routine
  155. void Init(void);
  156. // Set URL for live or corp WU ping server
  157. BOOL SetServerUrl(LPCTSTR ptszUrl, LPTSTR & ptszServerUrl);
  158. // Obtain file names for offline ping
  159. void GetLogFileName(void);
  160. // Obtain the existing ping ID from the registry, or generate one if not available.
  161. void LookupPingID(void);
  162. // Obtain platfrom info for ping
  163. void LookupPlatform(void);
  164. // Obtain system language info for ping
  165. void LookupSystemLanguage(void);
  166. // Construct a URL used to ping server
  167. HRESULT MakePingUrl(
  168. LPTSTR ptszUrl, // buffer to receive result
  169. int cChars, // the number of chars this buffer can take, including ending null
  170. LPCTSTR ptszBaseUrl, // server URL
  171. LPCTSTR ptszClientName, // which client called
  172. URLLOGACTIVITY activity,
  173. LPCTSTR ptszItemID,
  174. LPCTSTR ptszDeviceID,
  175. URLLOGSTATUS status,
  176. DWORD dwError, // result of download. SUCCESS if S_OK or ERROR_SUCCESS
  177. LPCTSTR ptszMessage);
  178. // Ping server to report status
  179. HRESULT PingStatus(URLLOGDESTINATION destination, LPCTSTR ptszUrl, PHANDLE phQuitEvents, UINT nQuitEventCount) const;
  180. // Read a ping entry from the given file handle
  181. HRESULT ReadEntry(HANDLE hFile, ULENTRYHEADER & ulentryheader, LPWSTR pwszBuffer, DWORD dwBufferSize) const;
  182. // Save a ping entry into the log file
  183. HRESULT SaveEntry(ULENTRYHEADER & ulentryheader, LPCWSTR pwszString) const;
  184. };
  185. // Escape unsafe chars in a TCHAR string
  186. BOOL EscapeString(
  187. LPCTSTR ptszUnescaped,
  188. LPTSTR ptszBuffer,
  189. DWORD dwCharsInBuffer);
  190. // ----------------------------------------------------------------------------------
  191. // IsConnected()
  192. // detect if there is a connection currently that can be used to
  193. // connect to Windows Update site.
  194. // If yes, we activate the shedule DLL
  195. //
  196. // Input : ptszUrl - Url containing host name to check for connection
  197. // fLive - whether the destination is the live site
  198. // Output: None
  199. // Return: TRUE if we are connected and we can reach the web site.
  200. // FALSE if we cannot reach the site or we are not connected.
  201. // ----------------------------------------------------------------------------------
  202. BOOL IsConnected(LPCTSTR ptszUrl, BOOL fLive);
  203. // ----------------------------------------------------------------------------------
  204. // MakeUUID()
  205. // create a UUID that is not linked to MAC address of a NIC, if any, on the
  206. // system.
  207. //
  208. // Input : pUuid - ptr to the UUID structure to hold the returning value.
  209. // ----------------------------------------------------------------------------------
  210. void MakeUUID(UUID* pUuid);