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.

2168 lines
53 KiB

  1. // Report User mode faults
  2. #include "Main.h"
  3. #include "WinMessages.h"
  4. #include "CuserList.h"
  5. #include "UserMode.h"
  6. #include "ReportFault.h"
  7. #define INTERNAL_SERVER _T("officewatson")
  8. #define LIVE_SERVER _T("watson.microsoft.com")
  9. #ifdef DEBUG
  10. #define DEFAULT_SERVER INTERNAL_SERVER
  11. #else
  12. #define DEFAULT_SERVER LIVE_SERVER
  13. #endif
  14. typedef struct strStage3Data
  15. {
  16. TCHAR szServerName[MAX_PATH];
  17. TCHAR szFileName[MAX_PATH];
  18. } STAGE3DATA;
  19. typedef struct strThreadParams
  20. {
  21. BOOL bSelected;
  22. HWND hListView;
  23. HWND hwnd;
  24. } THREAD_PARAMS, *PTHREAD_PARAMS;
  25. typedef struct strStage4Data
  26. {
  27. TCHAR szServerName[MAX_PATH];
  28. TCHAR szUrl[MAX_PATH];
  29. } STAGE4DATA;
  30. HANDLE g_hUserStopEvent = NULL;
  31. THREAD_PARAMS ThreadParams;
  32. extern CUserList cUserData;
  33. extern HINSTANCE g_hinst;
  34. extern CUserList cUserList;
  35. extern TCHAR CerRoot[MAX_PATH];
  36. extern HWND hUserMode;
  37. /*----------------------------------------------------------------------------
  38. FMicrosoftComURL
  39. Returns TRUE if we think the sz is a URL to a microsoft.com web site
  40. ----------------------------------------------------------------- MRuhlen --*/
  41. BOOL FMicrosoftComURL(TCHAR *sz)
  42. {
  43. TCHAR *pch;
  44. if (sz == NULL || _tcslen(sz) < 20) // "http://microsoft.com
  45. return FALSE;
  46. if (_tcsncicmp(sz, szHttpPrefix, _tcslen(szHttpPrefix)))
  47. return FALSE;
  48. pch = sz + _tcslen(szHttpPrefix);
  49. while (*pch != _T('/') && *pch != _T('\0'))
  50. pch++;
  51. if (*pch == _T('\0'))
  52. return FALSE;
  53. // found the end of the server name
  54. if (_tcsncicmp(pch - strlen(_T(".microsoft.com")), _T(".microsoft.com"),_tcslen(_T(".microsoft.com"))
  55. ) &&
  56. _tcsncicmp(pch - strlen(_T("/microsoft.com")), _T("/microsoft.com"),_tcslen(_T("/microsoft.com"))
  57. ) &&
  58. _tcsncicmp(pch - _tcslen(_T(".msn.com")), _T(".msn.com") ,_tcslen(_T(".msn.com"))
  59. )
  60. #ifdef DEBUG
  61. && _tcsncicmp(pch - _tcslen(_T("officewatson")), _T("officewatson") ,_tcslen(_T("officewatson")))
  62. #endif
  63. )
  64. return FALSE;
  65. return TRUE;
  66. }
  67. //----------------Response Parsing Routines. -------------------------------------------
  68. BOOL
  69. ParseStage1File(BYTE *Stage1HtmlContents,
  70. PSTATUS_FILE StatusContents)
  71. /*++
  72. Routine Description:
  73. This routine Parses the Response from the Stage1 url query.
  74. Arguments:
  75. ResponseUrl - Microsoft response for the recently submitted dump file.
  76. Return value:
  77. Does not return a value
  78. ++*/
  79. {
  80. BOOL bStatus = FALSE;
  81. TCHAR *Temp = NULL;
  82. TCHAR *Destination = NULL;
  83. DWORD charcount = 0;
  84. if ( (!Stage1HtmlContents) || (!StatusContents))
  85. {
  86. goto ERRORS;
  87. }
  88. // Clear out the requested data items from the status file.
  89. // We don't need them anymore since there is a stage 1 page available.
  90. if (StringCbCopy(StatusContents->Response, sizeof StatusContents->Response, _T("\0"))!= S_OK)
  91. {
  92. goto ERRORS;
  93. }
  94. if (StringCbCopy(StatusContents->BucketID, sizeof StatusContents->BucketID, _T("\0"))!= S_OK)
  95. {
  96. goto ERRORS;
  97. }
  98. if (StringCbCopy(StatusContents->RegKey, sizeof StatusContents->RegKey, _T("\0"))!= S_OK)
  99. {
  100. goto ERRORS;
  101. }
  102. if (StringCbCopy(StatusContents->iData, sizeof StatusContents->iData, _T("\0"))!= S_OK)
  103. {
  104. goto ERRORS;
  105. }
  106. if (StringCbCopy(StatusContents->GetFile, sizeof StatusContents->GetFile, _T("\0"))!= S_OK)
  107. {
  108. goto ERRORS;
  109. }
  110. if (StringCbCopy(StatusContents->GetFileVersion, sizeof StatusContents->GetFileVersion, _T("\0"))!= S_OK)
  111. {
  112. goto ERRORS;
  113. }
  114. if (StringCbCopy(StatusContents->fDoc, sizeof StatusContents->fDoc, _T("\0"))!= S_OK)
  115. {
  116. goto ERRORS;
  117. }
  118. if (StringCbCopy(StatusContents->WQL, sizeof StatusContents->WQL, _T("\0"))!= S_OK)
  119. {
  120. goto ERRORS;
  121. }
  122. if (StringCbCopy(StatusContents->MemoryDump, sizeof StatusContents->MemoryDump, _T("\0"))!= S_OK)
  123. {
  124. goto ERRORS;
  125. }
  126. // Lets get the bucketid
  127. Temp = _tcsstr((TCHAR *)Stage1HtmlContents, _T("Bucket="));
  128. if (Temp)
  129. {
  130. Temp += _tcslen(_T("Bucket="));
  131. Destination = StatusContents->BucketID;
  132. charcount = sizeof StatusContents->BucketID / sizeof TCHAR - sizeof TCHAR ;
  133. while ( (charcount > 0) &&
  134. (*Temp != _T(' ')) &&
  135. (*Temp != _T('\0')) &&
  136. (*Temp != _T('\r')))
  137. {
  138. -- charcount;
  139. *Destination = *Temp;
  140. ++Destination;
  141. ++Temp;
  142. }
  143. *Destination = _T('\0');
  144. bStatus= TRUE;
  145. }
  146. else
  147. {
  148. goto ERRORS;
  149. }
  150. // Now for the Response
  151. Temp = _tcsstr( (TCHAR *)Stage1HtmlContents, _T("Response="));
  152. if (Temp)
  153. {
  154. Temp += _tcslen(_T("Response="));
  155. Destination = StatusContents->Response;
  156. if (!FMicrosoftComURL(Temp))
  157. {
  158. if (StringCbCopy(StatusContents->Response, sizeof StatusContents->Response, _T("1")) != S_OK)
  159. {
  160. goto ERRORS;
  161. }
  162. }
  163. else
  164. {
  165. charcount = sizeof StatusContents->Response / sizeof TCHAR - sizeof TCHAR ;
  166. while ( (charcount > 0) &&
  167. (*Temp != _T(' ')) &&
  168. (*Temp != _T('\0')) &&
  169. (*Temp != _T('\r')))
  170. {
  171. -- charcount;
  172. *Destination = *Temp;
  173. ++Destination;
  174. ++Temp;
  175. bStatus = TRUE;
  176. }
  177. *Destination = _T('\0');
  178. }
  179. }
  180. if (StringCbCopy(StatusContents->iData, sizeof StatusContents->iData, _T("0\0"))!= S_OK)
  181. {
  182. goto ERRORS;
  183. }
  184. ERRORS:
  185. return bStatus;
  186. }
  187. BOOL
  188. ParseStage2File(BYTE *Stage2HtmlContents,
  189. PSTATUS_FILE StatusContents,
  190. STAGE3DATA *Stage3Data,
  191. STAGE4DATA *Stage4Data)
  192. /*++
  193. Routine Description:
  194. This routing parses the contents of the html file returned by the process stage2
  195. function into the UserData.Status data structure. see CUserList.h for the definition
  196. of this structure. And Usermode.h for the definition of the Prefix values used to parse
  197. the Stage2HtmlContents buffer.
  198. Arguments:
  199. Stage2HtmlContents - The contents of this file will constitute the contents of the new status.txt file.
  200. - See Spec for details on value meaning and usage.
  201. Sample file:
  202. Tracking=YES
  203. URLLaunch=asfsafsafsafsafsafdsdafsafsadf
  204. NoSecondLevelCollection=NO
  205. NoFileCollection=NO
  206. Bucket=985561
  207. Response=http://www.microsoft.com/ms.htm?iBucketTable=1&iBucket=985561&Cab=29728988.cab
  208. fDoc=NO
  209. iData=1
  210. GetFile=c:\errorlog.log
  211. MemoryDump=NO
  212. // Stage3 data
  213. DumpFile=/Upload/66585585.cab
  214. DumpServer=watson5.watson.microsoft.com
  215. // Stage4 data
  216. ResponseServer=watson5.watson.microsoft.com
  217. ResponseURL=/dw/StageFour.asp?iBucket=985561&Cab=/Upload/66585585.cab&Hang=0&Restricted=1&CorpWatson=1
  218. Return value:
  219. Returns True on success and FALSE if there were problems.
  220. ++*/
  221. {
  222. BOOL bStatus = TRUE;
  223. TCHAR *Temp;
  224. TCHAR *Dest;
  225. int CharCount = 0;
  226. // TCHAR szStage3Server[MAX_PATH];
  227. // TCHAR szStage3FileName[MAX_PATH];
  228. // TCHAR szStage4Server[MAX_PATH];
  229. // TCHAR szStage4URL [MAX_PATH];
  230. if (StringCbCopy(StatusContents->Response, sizeof StatusContents->Response, _T("\0"))!= S_OK)
  231. {
  232. goto ERRORS;
  233. }
  234. if (StringCbCopy(StatusContents->BucketID, sizeof StatusContents->BucketID, _T("\0"))!= S_OK)
  235. {
  236. goto ERRORS;
  237. }
  238. if (StringCbCopy(StatusContents->RegKey, sizeof StatusContents->RegKey, _T("\0"))!= S_OK)
  239. {
  240. goto ERRORS;
  241. }
  242. if (StringCbCopy(StatusContents->iData, sizeof StatusContents->iData, _T("\0"))!= S_OK)
  243. {
  244. goto ERRORS;
  245. }
  246. if (StringCbCopy(StatusContents->GetFile, sizeof StatusContents->GetFile, _T("\0"))!= S_OK)
  247. {
  248. goto ERRORS;
  249. }
  250. if (StringCbCopy(StatusContents->GetFileVersion, sizeof StatusContents->GetFileVersion, _T("\0"))!= S_OK)
  251. {
  252. goto ERRORS;
  253. }
  254. if (StringCbCopy(StatusContents->fDoc, sizeof StatusContents->fDoc, _T("\0"))!= S_OK)
  255. {
  256. goto ERRORS;
  257. }
  258. if (StringCbCopy(StatusContents->WQL, sizeof StatusContents->WQL, _T("\0"))!= S_OK)
  259. {
  260. goto ERRORS;
  261. }
  262. if (StringCbCopy(StatusContents->MemoryDump, sizeof StatusContents->MemoryDump, _T("\0"))!= S_OK)
  263. {
  264. goto ERRORS;
  265. }
  266. /*********** Get the Tracking Status ******************/
  267. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, TRACKING_PREFIX);
  268. if (Temp)
  269. {
  270. Dest = StatusContents->Tracking;
  271. Temp += _tcslen (TRACKING_PREFIX);
  272. CharCount = sizeof StatusContents->Tracking / sizeof TCHAR - sizeof TCHAR ;
  273. while ( (CharCount > 0) && (*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  274. {
  275. -- CharCount;
  276. *Dest = *Temp;
  277. ++Dest;
  278. ++Temp;
  279. }
  280. *Dest = _T('\0');
  281. }
  282. /*********** Get the Stage3 Server Name *****************************/
  283. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, STAGE3_SERVER_PREFIX);
  284. if (Temp)
  285. {
  286. Dest = Stage3Data->szServerName;
  287. Temp += _tcslen (STAGE3_SERVER_PREFIX);
  288. CharCount = sizeof Stage3Data->szServerName / sizeof TCHAR - sizeof TCHAR ;
  289. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  290. {
  291. -- CharCount;
  292. *Dest = *Temp;
  293. ++Dest;
  294. ++Temp;
  295. }
  296. *Dest = _T('\0');
  297. //MessageBox(NULL, Stage3Data->szServerName, "Stage3 Server", MB_OK);
  298. }
  299. /************ Get the name to upload the dump file as in Stage3 ***************/
  300. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, STAGE3_FILENAME_PREFIX);
  301. if (Temp)
  302. {
  303. Dest = Stage3Data->szFileName;
  304. Temp += _tcslen (STAGE3_FILENAME_PREFIX);
  305. CharCount = sizeof Stage3Data->szFileName / sizeof TCHAR - sizeof TCHAR ;
  306. while ((CharCount > 0) && (*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  307. {
  308. -- CharCount;
  309. *Dest = *Temp;
  310. ++Dest;
  311. ++Temp;
  312. }
  313. *Dest = _T('\0');
  314. // MessageBox(NULL, Stage3Data->szFileName, "Stage3 FileName", MB_OK);
  315. }
  316. /************ Get the Stage4 ResponseServer name ***************/
  317. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, STAGE4_SERVER_PREFIX);
  318. if (Temp)
  319. {
  320. Dest = Stage4Data->szServerName;
  321. Temp += _tcslen (STAGE4_SERVER_PREFIX);
  322. CharCount = sizeof Stage4Data->szServerName / sizeof TCHAR - sizeof TCHAR ;
  323. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  324. {
  325. -- CharCount;
  326. *Dest = *Temp;
  327. ++Dest;
  328. ++Temp;
  329. }
  330. *Dest = _T('\0');
  331. }
  332. /************ Get the Stage4 Response url ***************/
  333. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, STAGE4_URL_PREFIX);
  334. if (Temp)
  335. {
  336. Dest = Stage4Data->szUrl;
  337. Temp += _tcslen (STAGE4_URL_PREFIX);
  338. CharCount = sizeof Stage4Data->szUrl / sizeof TCHAR - sizeof TCHAR ;
  339. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  340. {
  341. -- CharCount;
  342. *Dest = *Temp;
  343. ++Dest;
  344. ++Temp;
  345. }
  346. *Dest = _T('\0');
  347. }
  348. /************ Get the bucketID ***************/
  349. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, BUCKET_PREFIX);
  350. if (Temp)
  351. {
  352. if ( *(Temp-1) == _T('i'))
  353. {
  354. // Find the next occurrence
  355. Temp += _tcslen (BUCKET_PREFIX);
  356. Temp = _tcsstr(Temp, BUCKET_PREFIX);
  357. if (Temp)
  358. {
  359. Dest = StatusContents->BucketID;
  360. Temp += _tcslen (BUCKET_PREFIX);
  361. CharCount = sizeof StatusContents->BucketID / sizeof TCHAR - sizeof TCHAR ;
  362. while ((CharCount > 0) && (*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  363. {
  364. -- CharCount;
  365. *Dest = *Temp;
  366. ++Dest;
  367. ++Temp;
  368. }
  369. *Dest = _T('\0');
  370. }
  371. else
  372. {
  373. if (StringCbCopy(StatusContents->BucketID, sizeof StatusContents->BucketID, _T("\0"))!= S_OK)
  374. {
  375. bStatus = FALSE;
  376. goto ERRORS;
  377. }
  378. }
  379. }
  380. else
  381. {
  382. Dest = StatusContents->BucketID;
  383. Temp += _tcslen (BUCKET_PREFIX);
  384. CharCount = sizeof StatusContents->BucketID / sizeof TCHAR - sizeof TCHAR ;
  385. while ((CharCount > 0) && (*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  386. {
  387. -- CharCount;
  388. *Dest = *Temp;
  389. ++Dest;
  390. ++Temp;
  391. }
  392. *Dest = _T('\0');
  393. }
  394. // MessageBox(NULL, szStage3Server, "Stage3 Server", MB_OK);
  395. }
  396. else
  397. {
  398. if (StringCbCopy(StatusContents->BucketID, sizeof StatusContents->BucketID, _T("\0"))!= S_OK)
  399. {
  400. bStatus = FALSE;
  401. goto ERRORS;
  402. }
  403. }
  404. /************ Get the Microsoft Response ***************/
  405. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, RESPONSE_PREFIX);
  406. if (Temp)
  407. {
  408. Dest = StatusContents->Response;
  409. Temp += _tcslen (RESPONSE_PREFIX);
  410. if (!FMicrosoftComURL(Temp))
  411. {
  412. if (StringCbCopy(StatusContents->Response, sizeof StatusContents->Response, _T("1")) != S_OK)
  413. {
  414. goto ERRORS;
  415. }
  416. }
  417. else
  418. {
  419. CharCount = sizeof StatusContents->Response / sizeof TCHAR - sizeof TCHAR ;
  420. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  421. {
  422. -- CharCount;
  423. *Dest = *Temp;
  424. ++Dest;
  425. ++Temp;
  426. }
  427. *Dest = _T('\0');
  428. }
  429. //MessageBox(NULL, szStage3Server, "Stage3 Server", MB_OK);
  430. }
  431. else
  432. {
  433. if (StringCbCopy(StatusContents->Response, sizeof StatusContents->Response, _T("\0"))!= S_OK)
  434. {
  435. bStatus = FALSE;
  436. goto ERRORS;
  437. }
  438. }
  439. /************ Get the Regkey data Item ***************/
  440. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, REGKEY_PREFIX);
  441. if (Temp)
  442. {
  443. Dest = StatusContents->RegKey;
  444. Temp += _tcslen (REGKEY_PREFIX);
  445. CharCount = sizeof StatusContents->RegKey / sizeof TCHAR - sizeof TCHAR ;
  446. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  447. {
  448. -- CharCount;
  449. *Dest = *Temp;
  450. ++Dest;
  451. ++Temp;
  452. }
  453. }
  454. else
  455. {
  456. if (StringCbCopy(StatusContents->RegKey, sizeof StatusContents->RegKey, _T("\0"))!= S_OK)
  457. {
  458. bStatus = FALSE;
  459. goto ERRORS;
  460. }
  461. }
  462. /************ Get the idata value ***************/
  463. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, IDATA_PREFIX);
  464. if (Temp)
  465. {
  466. Dest = StatusContents->iData;
  467. Temp += _tcslen (IDATA_PREFIX);
  468. CharCount = sizeof StatusContents->iData / sizeof TCHAR - sizeof TCHAR ;
  469. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  470. {
  471. -- CharCount;
  472. *Dest = *Temp;
  473. ++Dest;
  474. ++Temp;
  475. }
  476. *Dest = _T('\0');
  477. }
  478. else
  479. {
  480. if (StringCbCopy(StatusContents->iData, sizeof StatusContents->iData, _T("0\0"))!= S_OK)
  481. {
  482. bStatus = FALSE;
  483. goto ERRORS;
  484. }
  485. }
  486. /************ Get the list of files that need to be collected. ***************/
  487. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, GETFILE_PREFIX);
  488. if (Temp)
  489. {
  490. Dest = StatusContents->GetFile;
  491. Temp += _tcslen (GETFILE_PREFIX);
  492. CharCount = sizeof StatusContents->GetFile / sizeof TCHAR - sizeof TCHAR ;
  493. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  494. {
  495. -- CharCount;
  496. *Dest = *Temp;
  497. ++Dest;
  498. ++Temp;
  499. }
  500. *Dest = _T('\0');
  501. }
  502. else
  503. {
  504. if (StringCbCopy(StatusContents->GetFile, sizeof StatusContents->GetFile, _T("\0"))!= S_OK)
  505. {
  506. bStatus = FALSE;
  507. goto ERRORS;
  508. }
  509. }
  510. /************ Get the collect file version data to be collected ***************/
  511. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, GETFILEVER_PREFIX);
  512. if (Temp)
  513. {
  514. Dest = StatusContents->GetFileVersion;
  515. Temp += _tcslen (GETFILEVER_PREFIX);
  516. CharCount = sizeof StatusContents->GetFileVersion / sizeof TCHAR - sizeof TCHAR ;
  517. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  518. {
  519. -- CharCount;
  520. *Dest = *Temp;
  521. ++Dest;
  522. ++Temp;
  523. }
  524. *Dest = _T('\0');
  525. }
  526. else
  527. {
  528. if (StringCbCopy(StatusContents->GetFileVersion, sizeof StatusContents->GetFileVersion, _T("\0"))!= S_OK)
  529. {
  530. bStatus = FALSE;
  531. goto ERRORS;
  532. }
  533. }
  534. /************ Get the fDoc Setting ***************/
  535. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, FDOC_PREFIX);
  536. if (Temp)
  537. {
  538. Dest = StatusContents->fDoc ;
  539. Temp += _tcslen (FDOC_PREFIX);
  540. CharCount = sizeof StatusContents->fDoc / sizeof TCHAR - sizeof TCHAR ;
  541. while ((CharCount > 0) && (*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  542. {
  543. -- CharCount ;
  544. *Dest = *Temp;
  545. ++Dest;
  546. ++Temp;
  547. }
  548. *Dest = _T('\0');
  549. }
  550. else
  551. {
  552. if (StringCbCopy(StatusContents->fDoc, sizeof StatusContents->fDoc, _T("\0"))!= S_OK)
  553. {
  554. bStatus = FALSE;
  555. goto ERRORS;
  556. }
  557. }
  558. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, MEMDUMP_PREFIX);
  559. if (Temp)
  560. {
  561. Dest = StatusContents->MemoryDump ;
  562. Temp += _tcslen (MEMDUMP_PREFIX);
  563. CharCount = sizeof StatusContents->MemoryDump / sizeof TCHAR - sizeof TCHAR ;
  564. while ( (CharCount > 0) &&(*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  565. {
  566. -- CharCount;
  567. *Dest = *Temp;
  568. ++Dest;
  569. ++Temp;
  570. }
  571. *Dest = _T('\0');
  572. }
  573. else
  574. {
  575. if (StringCbCopy(StatusContents->MemoryDump, sizeof StatusContents->MemoryDump, _T("\0"))!= S_OK)
  576. {
  577. bStatus = FALSE;
  578. goto ERRORS;
  579. }
  580. }
  581. /************ Get the WQL Setting ***************/
  582. Temp = _tcsstr((TCHAR *) Stage2HtmlContents, WQL_PREFIX);
  583. if (Temp)
  584. {
  585. Dest = StatusContents->WQL ;
  586. Temp += _tcslen (WQL_PREFIX);
  587. CharCount = sizeof StatusContents->WQL / sizeof TCHAR - sizeof TCHAR ;
  588. while ((CharCount > 0) && (*Temp != _T('\0') ) && (*Temp != _T('\n')) && (*Temp != _T('\r')) )
  589. {
  590. -- CharCount ;
  591. *Dest = *Temp;
  592. ++Dest;
  593. ++Temp;
  594. }
  595. *Dest = _T('\0');
  596. }
  597. else
  598. {
  599. if (StringCbCopy(StatusContents->WQL, sizeof StatusContents->WQL, _T("\0"))!= S_OK)
  600. {
  601. bStatus = FALSE;
  602. goto ERRORS;
  603. }
  604. }
  605. ERRORS:
  606. ;
  607. return bStatus;
  608. }
  609. //----------------------- Stage 1-4 Processing routines --------------------------------
  610. BOOL
  611. ProcessStage1(TCHAR *Stage1URL,
  612. PSTATUS_FILE StatusContents)
  613. /*++
  614. Routine Description:
  615. Parses the ASP page returned by the Stage1 URL if it exists.
  616. Arguments:
  617. Stage1Url - URL that points to the static Htm page for this bucket.
  618. Return value:
  619. TRUE - We found the page and we are done.
  620. FALSE - The page was not found and we need to continue on to Stage2
  621. ++*/
  622. {
  623. HINTERNET hSession = NULL;
  624. HINTERNET hConnect = NULL;
  625. DWORD dwBytesRead = 0;
  626. int ErrorCode = 0; // Set to true if the page exists and the
  627. // contents were successfully parsed.
  628. BYTE *Buffer = NULL;
  629. DWORD dwBufferSize = 0;
  630. // BYTE *BufferPos = NULL;
  631. BYTE *NewBuffer = NULL;
  632. DWORD ResponseCode = 0;
  633. DWORD index = 0;
  634. DWORD ResLength = 255;
  635. hSession = InternetOpen(_T("Microsoft CER"),
  636. INTERNET_OPEN_TYPE_PRECONFIG,
  637. NULL,
  638. NULL,
  639. 0);
  640. if (hSession)
  641. {
  642. // Connect to the stage1 url
  643. // If the Stage1 URL page exists read
  644. // 1. read the page
  645. // 2. Parse the page contents for the bucketid and the response URL.
  646. hConnect = InternetOpenUrl(hSession,
  647. Stage1URL,
  648. NULL,
  649. NULL,
  650. INTERNET_FLAG_RELOAD,
  651. NULL);
  652. if (hConnect)
  653. {
  654. // Check the HTTP Header return code.
  655. HttpQueryInfo(hConnect,
  656. HTTP_QUERY_STATUS_CODE |HTTP_QUERY_FLAG_NUMBER,
  657. &ResponseCode,
  658. &ResLength,
  659. &index);
  660. if ( (ResponseCode < 200 ) || (ResponseCode > 299))
  661. {
  662. ErrorCode = -2;
  663. //MessageBox(hUserMode, _T("Failed to connect to the Internet.\r\nPlease verify your Internet connection."),NULL, MB_OK);
  664. goto ERRORS;
  665. }
  666. // Allocate the buffer Memory
  667. Buffer = (BYTE*) malloc (READFILE_BUFFER_INCREMENT);
  668. if (Buffer)
  669. {
  670. ZeroMemory(Buffer,READFILE_BUFFER_INCREMENT);
  671. do
  672. {
  673. dwBytesRead = 0;
  674. InternetReadFile( hConnect,
  675. Buffer,
  676. READFILE_BUFFER_INCREMENT,
  677. &dwBytesRead);
  678. dwBufferSize += dwBytesRead;
  679. if (dwBytesRead == READFILE_BUFFER_INCREMENT)
  680. {
  681. // Ok we filled up a buffer allocate a new one
  682. NewBuffer = (BYTE *) malloc (dwBufferSize + READFILE_BUFFER_INCREMENT);
  683. if (NewBuffer)
  684. {
  685. ZeroMemory (NewBuffer, dwBufferSize + READFILE_BUFFER_INCREMENT);
  686. memcpy(NewBuffer,Buffer, dwBufferSize);
  687. free(Buffer);
  688. Buffer = NewBuffer;
  689. }
  690. else
  691. {
  692. free(Buffer);
  693. Buffer = NULL;
  694. goto ERRORS;
  695. }
  696. }
  697. } while (dwBytesRead > 0);
  698. if (dwBufferSize > 0)
  699. {
  700. if (ParseStage1File(Buffer, StatusContents))
  701. {
  702. ErrorCode = 1;
  703. }
  704. }
  705. }
  706. }
  707. else
  708. {
  709. ErrorCode = -1;
  710. MessageBox(hUserMode, _T("Failed to connect to the Internet.\r\nPlease verify your Internet connection."),NULL, MB_OK);
  711. }
  712. }
  713. else
  714. {
  715. ErrorCode = -1;
  716. MessageBox(hUserMode, _T("Failed to connect to the Internet.\r\nPlease verify your Internet connection."),NULL, MB_OK);
  717. }
  718. ERRORS:
  719. // Cleanup
  720. if (Buffer)
  721. free (Buffer);
  722. if (hConnect)
  723. InternetCloseHandle(hConnect);
  724. if (hSession)
  725. InternetCloseHandle(hSession);
  726. return ErrorCode;
  727. }
  728. BOOL
  729. ProcessStage2(TCHAR *Stage2URL,
  730. BOOL b64Bit,
  731. PSTATUS_FILE StatusContents,
  732. STAGE3DATA *Stage3Data,
  733. STAGE4DATA *Stage4Data)
  734. /*++
  735. Routine Description:
  736. Parses the ASP page returned by the Stage2 URL.
  737. Data the Page Contains:
  738. a)Does Microsoft need more data.
  739. b)What to name the dumpfile
  740. c)Where to upload the dumpfile
  741. d)The stage4 response server.
  742. e)The data to be added to the cab
  743. f)The stage4 url to use.
  744. g)The bucketID
  745. f)The response URL for this bucket.
  746. // Sample file Contents:
  747. Stage2 Response:
  748. iData=1
  749. DumpFile=/Upload/66585585.cab
  750. DumpServer=watson5.watson.microsoft.com
  751. ResponseServer=watson5.watson.microsoft.com
  752. GetFile=c:\errorlog.log
  753. ResponseURL=
  754. /dw/StageFour.asp?iBucket=985561&Cab=/Upload/66585585.cab&Hang=0&Restricted=1&CorpWatson=1
  755. Bucket=985561
  756. Response=http://www.microsoft.com/ms.htm?iBucketTable=1&iBucket=985561&Cab=66585585.cab
  757. Arguments:
  758. Stage2Url - URL that points to the static Htm page for this bucket.
  759. Return value:
  760. TRUE - We Successfully Processed Stage2 move on to stage3.
  761. FALSE - There was an error processing the file move on to the next cab.
  762. ++*/
  763. {
  764. HINTERNET hSession = NULL;
  765. HINTERNET hConnect = NULL;
  766. DWORD dwBytesRead = 0;
  767. BOOL bStage2Success = FALSE; // Set to true if the page exists and the
  768. // contents were successfully parsed.
  769. BYTE *Buffer = NULL;
  770. DWORD dwBufferSize = 0;
  771. // BYTE *BufferPos = NULL;
  772. BYTE *NewBuffer = NULL;
  773. int ResponseCode = 0;
  774. DWORD index = 0;
  775. DWORD ResLength = 255;
  776. hSession = InternetOpen(_T("Microsoft CER"),
  777. INTERNET_OPEN_TYPE_PRECONFIG,
  778. NULL,
  779. NULL,
  780. 0);
  781. if (hSession)
  782. {
  783. // Connect to the stage1 url
  784. // If the Stage1 URL page exists read
  785. // 1. read the page
  786. // 2. Parse the page contents for the bucketid and the response URL.
  787. hConnect = InternetOpenUrl( hSession,
  788. Stage2URL,
  789. NULL,
  790. NULL,
  791. INTERNET_FLAG_RELOAD,
  792. NULL);
  793. if (hConnect)
  794. {
  795. HttpQueryInfo(hConnect,
  796. HTTP_QUERY_STATUS_CODE |HTTP_QUERY_FLAG_NUMBER,
  797. &ResponseCode,
  798. &ResLength,
  799. &index);
  800. if ( (ResponseCode < 200 ) || (ResponseCode > 299))
  801. {
  802. bStage2Success = FALSE;
  803. MessageBox(hUserMode, _T("Failed to connect to the Internet.\r\nPlease verify your Internet connection."),NULL, MB_OK);
  804. goto ERRORS;
  805. }
  806. // Allocate the buffer Memory
  807. Buffer = (BYTE*) malloc (READFILE_BUFFER_INCREMENT);
  808. if (Buffer)
  809. {
  810. ZeroMemory(Buffer, READFILE_BUFFER_INCREMENT);
  811. do
  812. {
  813. dwBytesRead = 0;
  814. InternetReadFile(hConnect,
  815. Buffer + dwBufferSize,
  816. READFILE_BUFFER_INCREMENT,
  817. &dwBytesRead);
  818. dwBufferSize += dwBytesRead;
  819. if (dwBytesRead == READFILE_BUFFER_INCREMENT)
  820. {
  821. // Ok we filled up a buffer allocate a new one
  822. NewBuffer = (BYTE *) malloc (dwBufferSize + READFILE_BUFFER_INCREMENT);
  823. if (NewBuffer)
  824. {
  825. ZeroMemory (NewBuffer, dwBufferSize + READFILE_BUFFER_INCREMENT);
  826. memcpy(NewBuffer,Buffer, dwBufferSize);
  827. free(Buffer);
  828. Buffer = NewBuffer;
  829. }
  830. else
  831. {
  832. free(Buffer);
  833. Buffer = NULL;
  834. goto ERRORS;
  835. }
  836. }
  837. } while (dwBytesRead > 0);
  838. if ((dwBufferSize > 0) && (Buffer[0] != _T('\0')))
  839. {
  840. //MessageBox(NULL, (TCHAR*) Buffer, "Stage2 Response", MB_OK);
  841. if (ParseStage2File(Buffer, StatusContents, Stage3Data, Stage4Data))
  842. {
  843. bStage2Success = TRUE;
  844. }
  845. }
  846. }
  847. }
  848. else
  849. {
  850. MessageBox(hUserMode, _T("Failed to connect to the Internet.\r\nPlease verify your Internet connection."),NULL, MB_OK);
  851. bStage2Success = FALSE;
  852. goto ERRORS;
  853. }
  854. }
  855. else
  856. {
  857. MessageBox(hUserMode, _T("Failed to connect to the Internet.\r\nPlease verify your Internet connection."),NULL, MB_OK);
  858. bStage2Success = FALSE;
  859. }
  860. ERRORS:
  861. // Cleanup
  862. if (Buffer)
  863. free(Buffer);
  864. if (hConnect)
  865. InternetCloseHandle(hConnect);
  866. if (hSession)
  867. InternetCloseHandle(hSession);
  868. return bStage2Success;
  869. }
  870. BOOL
  871. ProcessStage3(TCHAR *szStage3FilePath, STAGE3DATA *Stage3Data)
  872. /*++
  873. Routine Description:
  874. Builds and uploads the dumpfile cab.
  875. Arguments:
  876. Stage3Url Url Contains location to upload dumpfile to.
  877. Return value:
  878. TRUE - We Successfully uploaded the file
  879. FALSE - An error occurred and the dumpfile was not successfully uploaded.
  880. ++*/
  881. {
  882. static const TCHAR *pszAccept[] = {_T("*.*"), 0};
  883. BOOL bRet = FALSE;
  884. // BOOL UploadSuccess = FALSE;
  885. DWORD dwBytesRead = 0;
  886. DWORD dwBytesWritten = 0;
  887. DWORD ResponseCode = 0;
  888. DWORD ResLength = 255;
  889. DWORD index = 0;
  890. DWORD ErrorCode = 0;
  891. HINTERNET hSession = NULL;
  892. HINTERNET hConnect = NULL;
  893. HINTERNET hRequest = NULL;
  894. INTERNET_BUFFERS BufferIn = {0};
  895. HANDLE hFile = INVALID_HANDLE_VALUE;
  896. BYTE *pBuffer = NULL;
  897. // HRESULT hResult = S_OK;
  898. BOOL bStatus = FALSE;
  899. hSession = InternetOpen( _T("Microsoft CER"),
  900. INTERNET_OPEN_TYPE_PRECONFIG,
  901. NULL,
  902. NULL,
  903. 0);
  904. if (!hSession)
  905. {
  906. ErrorCode = GetLastError();
  907. goto cleanup;
  908. }
  909. hConnect = InternetConnect(hSession,
  910. Stage3Data->szServerName,
  911. INTERNET_DEFAULT_HTTPS_PORT,
  912. NULL,
  913. NULL,
  914. INTERNET_SERVICE_HTTP,
  915. 0,
  916. NULL);
  917. if (!hConnect)
  918. {
  919. ErrorCode = GetLastError();
  920. goto cleanup;
  921. }
  922. hRequest = HttpOpenRequest( hConnect,
  923. _T("PUT"),
  924. Stage3Data->szFileName,
  925. NULL,
  926. NULL,
  927. pszAccept,
  928. INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_SECURE,
  929. 0);
  930. if (hRequest)
  931. {
  932. hFile = CreateFile( szStage3FilePath,
  933. GENERIC_READ,
  934. FILE_SHARE_READ,
  935. NULL,
  936. OPEN_EXISTING,
  937. FILE_ATTRIBUTE_NORMAL,
  938. NULL);
  939. if (hFile != INVALID_HANDLE_VALUE)
  940. {
  941. // Clear the buffer
  942. if ( (pBuffer = (BYTE *)malloc (70000)) != NULL)
  943. {
  944. BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );
  945. BufferIn.Next = NULL;
  946. BufferIn.lpcszHeader = NULL;
  947. BufferIn.dwHeadersLength = 0;
  948. BufferIn.dwHeadersTotal = 0;
  949. BufferIn.lpvBuffer = NULL;
  950. BufferIn.dwBufferLength = 0;
  951. BufferIn.dwOffsetLow = 0;
  952. BufferIn.dwOffsetHigh = 0;
  953. BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
  954. FillMemory(pBuffer, 70000,'\0'); // Fill buffer with data
  955. // DWORD dwBuffLen = sizeof DWORD;
  956. if(!HttpSendRequestEx( hRequest,
  957. &BufferIn,
  958. NULL,
  959. HSR_INITIATE,
  960. 0))
  961. {
  962. ;
  963. }
  964. else
  965. {
  966. do
  967. {
  968. dwBytesRead = 0;
  969. bRet = ReadFile(hFile,
  970. pBuffer,
  971. 70000,
  972. &dwBytesRead,
  973. NULL);
  974. if (bRet != 0)
  975. {
  976. bRet = InternetWriteFile(hRequest,
  977. pBuffer,
  978. dwBytesRead,
  979. &dwBytesWritten);
  980. if ( (!bRet) || (dwBytesWritten==0) )
  981. {
  982. ;
  983. }
  984. }
  985. } while (dwBytesRead == 70000);
  986. CloseHandle(hFile);
  987. hFile = INVALID_HANDLE_VALUE;
  988. bRet = HttpEndRequest( hRequest,
  989. NULL,
  990. 0,
  991. 0);
  992. if (bRet)
  993. {
  994. ResponseCode = 0;
  995. HttpQueryInfo(hRequest,
  996. HTTP_QUERY_STATUS_CODE |HTTP_QUERY_FLAG_NUMBER,
  997. &ResponseCode,
  998. &ResLength,
  999. &index);
  1000. if ( (ResponseCode == 200) || (ResponseCode == 201))
  1001. {
  1002. ErrorCode = 0;
  1003. bStatus = TRUE;
  1004. }
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. cleanup:
  1011. // Clean up
  1012. if (hFile!= INVALID_HANDLE_VALUE)
  1013. {
  1014. CloseHandle (hFile);
  1015. hFile = INVALID_HANDLE_VALUE;
  1016. }
  1017. if (hSession)
  1018. {
  1019. InternetCloseHandle(hSession);
  1020. hSession = NULL;
  1021. }
  1022. if (hConnect)
  1023. {
  1024. InternetCloseHandle(hConnect);
  1025. hConnect = NULL;
  1026. }
  1027. if (hRequest)
  1028. {
  1029. InternetCloseHandle(hRequest);
  1030. hRequest = NULL;
  1031. }
  1032. if (pBuffer)
  1033. {
  1034. free (pBuffer);
  1035. pBuffer = NULL;
  1036. }
  1037. return bStatus;
  1038. }
  1039. BOOL
  1040. ProcessStage4(STAGE4DATA *Stage4Data)
  1041. /*++
  1042. Routine Description:
  1043. Sends the Cab Name and bucket number to the Watson server.
  1044. The watson server then:
  1045. 1) Archives the cab
  1046. 2) Adds a record to cab table.
  1047. 3) Decrements DataWanted count.
  1048. 4) if DataWanted hits 0 Creates a static htm page.
  1049. 5) in the case of shutdown and appcompat reports returns the
  1050. url to launch the OCA site to process the file. ( Not used for CER )
  1051. Arguments:
  1052. Stage4 - URL Contains the Bucketid and cabname to archive
  1053. Return value:
  1054. TRUE - We successfully completed stage4
  1055. FALSE - We failed to process Stage4
  1056. ++*/
  1057. {
  1058. HINTERNET hSession = NULL;
  1059. HINTERNET hConnect = NULL;
  1060. BOOL bStage4Success = FALSE; // Set to true if the page exists and the
  1061. // contents were successfully parsed.
  1062. TCHAR szStage4URL[MAX_PATH];
  1063. if (StringCbPrintf(szStage4URL,
  1064. sizeof szStage4URL,
  1065. _T("https://%s%s"),
  1066. Stage4Data->szServerName,
  1067. Stage4Data->szUrl)
  1068. != S_OK)
  1069. {
  1070. goto ERRORS;
  1071. }
  1072. hSession = InternetOpen(_T("Microsoft CER"),
  1073. INTERNET_OPEN_TYPE_PRECONFIG,
  1074. NULL,
  1075. NULL,
  1076. 0);
  1077. if (hSession)
  1078. {
  1079. hConnect = InternetOpenUrl(hSession, szStage4URL, NULL, NULL, 0, NULL);
  1080. if (hConnect)
  1081. {
  1082. // We are done there is no response from stage 4
  1083. // That we need to parse.
  1084. bStage4Success = TRUE;
  1085. }
  1086. }
  1087. ERRORS:
  1088. // Cleanup
  1089. if (hConnect)
  1090. InternetCloseHandle(hConnect);
  1091. if (hSession)
  1092. InternetCloseHandle(hSession);
  1093. return bStage4Success;
  1094. }
  1095. BOOL
  1096. WriteStatusFile(PUSER_DATA UserData)
  1097. /*++
  1098. Routine Description:
  1099. This routine renames a proccessed cab file from .cab to .old
  1100. Arguments:
  1101. ResponseUrl - Microsoft response for the recently submitted dump file.
  1102. Return value:
  1103. Does not return a value
  1104. ++*/
  1105. {
  1106. BOOL bStatus = FALSE;
  1107. // move the existing status file to .old
  1108. TCHAR szFileNameOld[MAX_PATH];
  1109. TCHAR *Temp;
  1110. TCHAR Buffer[1024];
  1111. HANDLE hFile = INVALID_HANDLE_VALUE;
  1112. DWORD dwWritten = 0;
  1113. if (StringCbCopy(szFileNameOld,sizeof szFileNameOld, UserData->StatusPath) != S_OK)
  1114. {
  1115. goto ERRORS;
  1116. }
  1117. Temp = szFileNameOld;
  1118. Temp += _tcslen(szFileNameOld) * sizeof TCHAR;
  1119. while ( (*Temp != _T('.')) && (Temp != szFileNameOld))
  1120. {
  1121. Temp --;
  1122. }
  1123. if (Temp == szFileNameOld)
  1124. {
  1125. goto ERRORS;
  1126. }
  1127. else
  1128. {
  1129. if (StringCbCopy (Temp,sizeof szFileNameOld , _T(".old")) != S_OK)
  1130. {
  1131. goto ERRORS;
  1132. }
  1133. if (PathFileExists(UserData->StatusPath))
  1134. {
  1135. MoveFileEx(UserData->StatusPath, szFileNameOld, TRUE);
  1136. }
  1137. // create a new status file.
  1138. hFile = CreateFile(UserData->StatusPath, GENERIC_WRITE, NULL, NULL,CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
  1139. // Write the StatusContents data to the new status file
  1140. if (_tcscmp (UserData->Status.Tracking, _T("\0")))
  1141. {
  1142. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Tracking=%s\r\n"), UserData->Status.Tracking) != S_OK)
  1143. {
  1144. goto ERRORS;
  1145. }
  1146. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1147. }
  1148. // Write the StatusContents data to the new status file
  1149. if (_tcscmp (UserData->Status.CrashPerBucketCount, _T("\0")))
  1150. {
  1151. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Crashes per bucket=%s\r\n"), UserData->Status.CrashPerBucketCount) != S_OK)
  1152. {
  1153. goto ERRORS;
  1154. }
  1155. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1156. }
  1157. // Write the StatusContents data to the new status file
  1158. if (_tcscmp (UserData->Status.UrlToLaunch, _T("\0")))
  1159. {
  1160. if (StringCbPrintf(Buffer, sizeof Buffer, _T("URLLaunch=%s\r\n"), UserData->Status.UrlToLaunch) != S_OK)
  1161. {
  1162. goto ERRORS;
  1163. }
  1164. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1165. }
  1166. // Write the StatusContents data to the new status file
  1167. if (_tcscmp (UserData->Status.SecondLevelData, _T("\0")))
  1168. {
  1169. if (StringCbPrintf(Buffer, sizeof Buffer, _T("NoSecondLevelCollection=%s\r\n"), UserData->Status.SecondLevelData) != S_OK)
  1170. {
  1171. goto ERRORS;
  1172. }
  1173. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1174. }
  1175. // Write the StatusContents data to the new status file
  1176. if (_tcscmp (UserData->Status.FileCollection, _T("\0")))
  1177. {
  1178. if (StringCbPrintf(Buffer, sizeof Buffer, _T("NoFileCollection=%s\r\n"), UserData->Status.FileCollection) != S_OK)
  1179. {
  1180. goto ERRORS;
  1181. }
  1182. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1183. }
  1184. // Write the StatusContents data to the new status file
  1185. if (_tcscmp (UserData->Status.Response, _T("\0")))
  1186. {
  1187. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Response=%s\r\n"), UserData->Status.Response) != S_OK)
  1188. {
  1189. goto ERRORS;
  1190. }
  1191. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1192. }
  1193. // Write the StatusContents data to the new status file
  1194. if (_tcscmp (UserData->Status.BucketID, _T("\0")))
  1195. {
  1196. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Bucket=%s\r\n"), UserData->Status.BucketID) != S_OK)
  1197. {
  1198. goto ERRORS;
  1199. }
  1200. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1201. }
  1202. // Write the StatusContents data to the new status file
  1203. if (_tcscmp (UserData->Status.RegKey, _T("\0")))
  1204. {
  1205. if (StringCbPrintf(Buffer, sizeof Buffer, _T("RegKey=%s\r\n"), UserData->Status.RegKey) != S_OK)
  1206. {
  1207. goto ERRORS;
  1208. }
  1209. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1210. }
  1211. // Write the StatusContents data to the new status file
  1212. if (_tcscmp (UserData->Status.iData, _T("\0")))
  1213. {
  1214. if (StringCbPrintf(Buffer, sizeof Buffer, _T("iData=%s\r\n"),UserData->Status.iData) != S_OK)
  1215. {
  1216. goto ERRORS;
  1217. }
  1218. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1219. }
  1220. // Write the StatusContents data to the new status file
  1221. if (_tcscmp (UserData->Status.WQL, _T("\0")))
  1222. {
  1223. if (StringCbPrintf(Buffer, sizeof Buffer, _T("WQL=%s\r\n"), UserData->Status.WQL) != S_OK)
  1224. {
  1225. goto ERRORS;
  1226. }
  1227. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1228. }
  1229. // Write the StatusContents data to the new status file
  1230. if (_tcscmp (UserData->Status.GetFile, _T("\0")))
  1231. {
  1232. if (StringCbPrintf(Buffer, sizeof Buffer, _T("GetFile=%s\r\n"), UserData->Status.GetFile) != S_OK)
  1233. {
  1234. goto ERRORS;
  1235. }
  1236. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1237. }
  1238. // Write the StatusContents data to the new status file
  1239. if (_tcscmp (UserData->Status.GetFileVersion, _T("\0")))
  1240. {
  1241. if (StringCbPrintf(Buffer, sizeof Buffer, _T("GetFileVersion=%s\r\n"), UserData->Status.GetFileVersion) != S_OK)
  1242. {
  1243. goto ERRORS;
  1244. }
  1245. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1246. }
  1247. if (_tcscmp (UserData->Status.AllowResponse, _T("\0")))
  1248. {
  1249. if (StringCbPrintf(Buffer, sizeof Buffer, _T("NoExternalURL=%s\r\n"), UserData->Status.AllowResponse) != S_OK)
  1250. {
  1251. goto ERRORS;
  1252. }
  1253. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1254. }
  1255. if (_tcscmp (UserData->Status.MemoryDump, _T("\0")))
  1256. {
  1257. if (StringCbPrintf(Buffer, sizeof Buffer, _T("MemoryDump=%s\r\n"), UserData->Status.MemoryDump) != S_OK)
  1258. {
  1259. goto ERRORS;
  1260. }
  1261. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1262. }
  1263. // Close the new status file
  1264. CloseHandle(hFile);
  1265. hFile = INVALID_HANDLE_VALUE;
  1266. // if all ok delete the old status file.
  1267. //DeleteFile(szFileNameOld);
  1268. }
  1269. ERRORS:
  1270. if (hFile != INVALID_HANDLE_VALUE)
  1271. {
  1272. CloseHandle(hFile);
  1273. }
  1274. return bStatus;
  1275. }
  1276. void
  1277. RenameUmCabToOld(TCHAR *szFileName)
  1278. /*++
  1279. Routine Description:
  1280. This routine renames a proccessed cab file from .cab to .old
  1281. Arguments:
  1282. ResponseUrl - Microsoft response for the recently submitted dump file.
  1283. Return value:
  1284. Does not return a value
  1285. ++*/
  1286. {
  1287. TCHAR szFileNameOld[MAX_PATH];
  1288. TCHAR *Temp;
  1289. if (StringCbCopy(szFileNameOld,sizeof szFileNameOld, szFileName) != S_OK)
  1290. {
  1291. goto ERRORS;
  1292. }
  1293. Temp = szFileNameOld;
  1294. Temp += _tcslen(szFileNameOld) * sizeof TCHAR;
  1295. while ( (*Temp != _T('.')) && (Temp != szFileNameOld))
  1296. {
  1297. Temp --;
  1298. }
  1299. if (Temp == szFileNameOld)
  1300. {
  1301. // Abort since we did not find the .cab extension.
  1302. goto ERRORS;
  1303. }
  1304. else
  1305. {
  1306. if (StringCbCopy (Temp,sizeof szFileNameOld , _T(".old")) != S_OK)
  1307. {
  1308. goto ERRORS;
  1309. }
  1310. MoveFileEx(szFileName, szFileNameOld, TRUE);
  1311. }
  1312. ERRORS:
  1313. return;
  1314. }
  1315. BOOL
  1316. RenameAllCabsToOld(TCHAR *szPath)
  1317. /*++
  1318. Routine Description:
  1319. This routine renames a proccessed cab file from .cab to .old
  1320. Arguments:
  1321. ResponseUrl - Microsoft response for the recently submitted dump file.
  1322. Return value:
  1323. Does not return a value
  1324. ++*/
  1325. {
  1326. WIN32_FIND_DATA FindData;
  1327. HANDLE hFind = INVALID_HANDLE_VALUE;
  1328. TCHAR szSearchPath[MAX_PATH];
  1329. TCHAR szFilePath[MAX_PATH];
  1330. if (!szPath)
  1331. {
  1332. return FALSE;
  1333. }
  1334. if (StringCbPrintf(szSearchPath, sizeof szSearchPath, _T("%s\\*.cab"), szPath) != S_OK)
  1335. {
  1336. return FALSE;
  1337. }
  1338. // find first find next loop
  1339. hFind = FindFirstFile(szSearchPath, &FindData);
  1340. if (hFind != INVALID_HANDLE_VALUE)
  1341. {
  1342. // Build file path
  1343. do
  1344. {
  1345. if (StringCbPrintf(szFilePath, sizeof szFilePath, _T("%s\\%s"),szPath, FindData.cFileName) != S_OK)
  1346. {
  1347. FindClose (hFind);
  1348. return FALSE;
  1349. }
  1350. RenameUmCabToOld(szFilePath);
  1351. }while (FindNextFile(hFind, &FindData));
  1352. FindClose(hFind);
  1353. }
  1354. return TRUE;
  1355. }
  1356. BOOL WriteRepCountFile(TCHAR *FilePath, int Count)
  1357. {
  1358. HANDLE hFile = INVALID_HANDLE_VALUE;
  1359. TCHAR Buffer[100];
  1360. BOOL Status = FALSE;
  1361. DWORD dwWritten = 0;
  1362. ZeroMemory(Buffer, sizeof Buffer);
  1363. hFile = CreateFile(FilePath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,NULL);
  1364. if (hFile != INVALID_HANDLE_VALUE)
  1365. {
  1366. if (StringCbPrintf(Buffer,sizeof Buffer, _T("ReportedCount=%d"), Count) == S_OK)
  1367. {
  1368. if (WriteFile(hFile, Buffer, _tcslen (Buffer) * sizeof TCHAR, &dwWritten, NULL))
  1369. {
  1370. Status = TRUE;
  1371. }
  1372. else
  1373. {
  1374. Status = FALSE;
  1375. }
  1376. }
  1377. else
  1378. {
  1379. Status = FALSE;
  1380. }
  1381. CloseHandle (hFile);
  1382. hFile = INVALID_HANDLE_VALUE;
  1383. }
  1384. return Status;
  1385. }
  1386. //----------------------- User Mode Reporting Control Function --------------------------------
  1387. DWORD WINAPI UserUploadThreadProc (void *ThreadParam)
  1388. /*++
  1389. Routine Description:
  1390. This routine renames a proccessed cab file from .cab to .old
  1391. Arguments:
  1392. ResponseUrl - Microsoft response for the recently submitted dump file.
  1393. Return value:
  1394. Does not return a value
  1395. ++*/
  1396. {
  1397. TCHAR Stage1URL[1024];
  1398. TCHAR Stage2URL[1024];
  1399. // TCHAR Stage3Request[1024];
  1400. TCHAR Stage4Request[1024];
  1401. TCHAR szSearchPath[MAX_PATH];
  1402. TCHAR szStage3FilePath[MAX_PATH];
  1403. TCHAR szDestFileName[MAX_PATH];
  1404. PTHREAD_PARAMS pParams = NULL;
  1405. WIN32_FIND_DATA FindData;
  1406. HANDLE hFind = INVALID_HANDLE_VALUE;
  1407. PUSER_DATA pUserData = NULL;
  1408. BOOL bContinue = FALSE;
  1409. BOOL bEOF = FALSE;
  1410. int iCabCount = 0;
  1411. STAGE3DATA Stage3Data;
  1412. STAGE4DATA Stage4Data;
  1413. int iBucketCount = 0;
  1414. BOOL bDone = FALSE;
  1415. HANDLE hEvent = NULL;
  1416. USER_DATA UserData;
  1417. int i = 0;
  1418. int iIndex = 0;
  1419. TCHAR ProcessText[MAX_PATH];
  1420. LVITEM lvi;
  1421. TCHAR *Source = NULL;
  1422. TCHAR Stage1Part1[1000];
  1423. int iResult = 0;
  1424. int iCount = 0;
  1425. BOOL bResult = FALSE;
  1426. BOOL bSyncForSolution = FALSE;
  1427. ZeroMemory (Stage1URL, sizeof Stage1URL);
  1428. ZeroMemory (Stage2URL, sizeof Stage2URL);
  1429. ZeroMemory (ProcessText, sizeof ProcessText);
  1430. ZeroMemory (Stage4Request, sizeof Stage4Request);
  1431. ZeroMemory (szSearchPath, sizeof szSearchPath);
  1432. ZeroMemory (szStage3FilePath, sizeof szStage3FilePath);
  1433. ZeroMemory (szDestFileName, sizeof szDestFileName);
  1434. ZeroMemory (Stage1Part1, sizeof Stage1Part1);
  1435. pParams = (PTHREAD_PARAMS) ThreadParam;
  1436. hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("StopUserUpload"));
  1437. if (!hEvent)
  1438. {
  1439. goto ERRORS;
  1440. }
  1441. if ( pParams->bSelected)
  1442. {
  1443. // We are uploading a subset of the total buckets
  1444. iBucketCount = ListView_GetSelectedCount(pParams->hListView);
  1445. if (iBucketCount <= 0)
  1446. {
  1447. goto ERRORS;
  1448. }
  1449. else
  1450. {
  1451. // Set the PB Range to the count of selected items
  1452. SendDlgItemMessage(pParams->hwnd,IDC_TOTAL_PROGRESS, PBM_SETRANGE,0, MAKELPARAM(0, iBucketCount));
  1453. SendDlgItemMessage(pParams->hwnd,IDC_TOTAL_PROGRESS, PBM_SETSTEP,1,0);
  1454. }
  1455. }
  1456. else
  1457. {
  1458. cUserData.ResetCurrPos();
  1459. cUserData.GetNextEntry(&UserData, &bEOF);
  1460. if (!bEOF )
  1461. {
  1462. do
  1463. {
  1464. ++iBucketCount;
  1465. } while (cUserData.GetNextEntry(&UserData, &bEOF));
  1466. cUserData.ResetCurrPos();
  1467. SendDlgItemMessage(pParams->hwnd,IDC_TOTAL_PROGRESS, PBM_SETRANGE,0, MAKELPARAM(0, iBucketCount));
  1468. SendDlgItemMessage(pParams->hwnd,IDC_TOTAL_PROGRESS, PBM_SETSTEP,1,0);
  1469. }
  1470. else
  1471. goto ERRORS; // No buckets to upload
  1472. }
  1473. iIndex = -1;
  1474. do
  1475. {
  1476. if (!PathIsDirectory(CerRoot))
  1477. {
  1478. MessageBox(pParams->hwnd, _T("Reporting to Microsoft failed.\r\nUnable to connect to CER tree."), NULL,MB_OK);
  1479. goto ERRORS;
  1480. }
  1481. if (WaitForSingleObject(hEvent, 50) == WAIT_OBJECT_0)
  1482. {
  1483. bDone = TRUE;
  1484. goto ERRORS;
  1485. }
  1486. if (!pParams->bSelected)
  1487. {
  1488. bEOF = FALSE;
  1489. cUserData.GetNextEntryNoMove(&UserData, &bEOF);
  1490. pUserData = &UserData;
  1491. }
  1492. else
  1493. {
  1494. if (iBucketCount <= 0)
  1495. {
  1496. goto ERRORS; // Were done
  1497. }
  1498. --iBucketCount;
  1499. // get the next index from the list view and decrement iBucketCount
  1500. iIndex = ListView_GetNextItem(pParams->hListView,iIndex, LVNI_SELECTED);
  1501. ZeroMemory(&lvi, sizeof LVITEM);
  1502. lvi.iItem = iIndex;
  1503. lvi.mask = LVIF_PARAM ;
  1504. ListView_GetItem(pParams->hListView,&lvi);
  1505. iIndex = lvi.lParam;
  1506. pUserData = cUserData.GetEntry(iIndex);
  1507. if (!pUserData)
  1508. {
  1509. goto Done;
  1510. }
  1511. }
  1512. if (StringCbPrintf(szSearchPath, sizeof szSearchPath,_T("%s\\*.cab"),pUserData->BucketPath) != S_OK)
  1513. {
  1514. goto ERRORS;
  1515. }
  1516. if (StringCbPrintf(ProcessText, sizeof ProcessText, _T("Processing Bucket: %s"), pUserData->BucketPath) != S_OK)
  1517. {
  1518. goto ERRORS;
  1519. }
  1520. SetDlgItemText(pParams->hwnd, IDC_CAB_TEXT, ProcessText);
  1521. bSyncForSolution = FALSE;
  1522. // Get the cab count
  1523. hFind = FindFirstFile(szSearchPath, &FindData);
  1524. if (hFind != INVALID_HANDLE_VALUE)
  1525. {
  1526. do
  1527. {
  1528. ++iCabCount;
  1529. } while (FindNextFile(hFind, &FindData));
  1530. FindClose(hFind);
  1531. // Set Bucket PB range to iCabCount or 100 if iCabCount > 100
  1532. SendDlgItemMessage(pParams->hwnd,IDC_FILE_PROGRESS, PBM_SETRANGE,0, MAKELPARAM(0, iCabCount));
  1533. SendDlgItemMessage(pParams->hwnd,IDC_FILE_PROGRESS, PBM_SETSTEP,1,0);
  1534. }
  1535. else
  1536. {
  1537. // Done with bucket
  1538. bSyncForSolution = TRUE;
  1539. SendDlgItemMessage(pParams->hwnd ,IDC_TOTAL_PROGRESS, PBM_STEPIT, 0,0);
  1540. //goto Done;
  1541. }
  1542. // Build Stage 1 url
  1543. /* if (StringCbPrintf(Stage1URL,
  1544. sizeof Stage1URL,
  1545. _T("http://%s%s/%s/%s/%s/%s/%s.htm"),
  1546. DEFAULT_SERVER,
  1547. PARTIALURL_STAGE_ONE,
  1548. pUserData->AppName,
  1549. pUserData->AppVer,
  1550. pUserData->ModName,
  1551. pUserData->ModVer,
  1552. pUserData->Offset) != S_OK)
  1553. {
  1554. goto ERRORS;
  1555. }
  1556. */
  1557. ZeroMemory (Stage1Part1, sizeof Stage1Part1);
  1558. if (StringCbPrintf(Stage1Part1, sizeof Stage1Part1, _T("/%s/%s/%s/%s/%s"),
  1559. pUserData->AppName,
  1560. pUserData->AppVer,
  1561. pUserData->ModName,
  1562. pUserData->ModVer,
  1563. pUserData->Offset) != S_OK)
  1564. {
  1565. goto ERRORS;
  1566. }
  1567. Source = Stage1Part1;
  1568. while (*Source != _T('\0'))
  1569. {
  1570. if (*Source == _T('.'))
  1571. {
  1572. *Source = _T('_');
  1573. }
  1574. ++Source;
  1575. }
  1576. // Now build the rest of the url
  1577. if (StringCbPrintf(Stage1URL, sizeof Stage1URL, _T("http://%s%s%s.htm?CER=15"), DEFAULT_SERVER,PARTIALURL_STAGE_ONE, Stage1Part1 ) != S_OK)
  1578. {
  1579. goto ERRORS;
  1580. }
  1581. // GetStage1 Response
  1582. iResult = ProcessStage1(Stage1URL, &(pUserData->Status));
  1583. ++ pUserData->iReportedCount;
  1584. if (iResult == 1 )
  1585. {
  1586. // we are done.
  1587. // rename all of the cabs in this bucket to .old and Update the status.txt
  1588. RenameAllCabsToOld(pUserData->BucketPath);
  1589. if (StringCbCopy(pUserData->CabCount, sizeof pUserData->CabCount, _T("0"))!= S_OK)
  1590. {
  1591. goto ERRORS;
  1592. }
  1593. WriteStatusFile(pUserData);
  1594. goto Done;
  1595. }
  1596. if (iResult == -1)
  1597. {
  1598. goto ERRORS;
  1599. }
  1600. if (!bSyncForSolution)
  1601. {
  1602. if (!PathIsDirectory(CerRoot))
  1603. {
  1604. MessageBox(pParams->hwnd, _T("Reporting to Microsoft failed.\r\nUnable to connect to CER tree."), NULL,MB_OK);
  1605. goto ERRORS;
  1606. }
  1607. hFind = FindFirstFile(szSearchPath, &FindData);
  1608. if (hFind == INVALID_HANDLE_VALUE)
  1609. {
  1610. // No need to continue there are no cabs to upload.
  1611. goto Done;
  1612. }
  1613. // Build Stage 2 Url
  1614. if (!pUserData->Is64Bit)
  1615. {
  1616. // if 32 bit use this one.
  1617. // Get Stage 2 response
  1618. if (StringCbPrintf(Stage2URL,
  1619. sizeof Stage2URL,
  1620. _T("https://%s%s?szAppName=%s&szAppVer=%s&szModName=%s&szModVer=%s&offset=%s&szBuiltBy=CORPWATSON"),
  1621. DEFAULT_SERVER,
  1622. PARTIALURL_STAGE_TWO_32,
  1623. pUserData->AppName,
  1624. pUserData->AppVer,
  1625. pUserData->ModName,
  1626. pUserData->ModVer,
  1627. pUserData->Offset) != S_OK)
  1628. {
  1629. goto ERRORS;
  1630. }
  1631. }
  1632. else
  1633. {
  1634. // If 64Bit Use this one.
  1635. if (StringCbPrintf(Stage2URL,
  1636. sizeof Stage2URL,
  1637. _T("https://%s%s?szAppName=%s&szAppVer=%s&szModName=%s&szModVer=%s&offset=%s&szBuiltBy=CORPWATSON"),
  1638. DEFAULT_SERVER,
  1639. PARTIALURL_STAGE_TWO_64,
  1640. pUserData->AppName,
  1641. pUserData->AppVer,
  1642. pUserData->ModName,
  1643. pUserData->ModVer,
  1644. pUserData->Offset) != S_OK)
  1645. {
  1646. goto ERRORS;
  1647. }
  1648. }
  1649. ZeroMemory (&Stage3Data, sizeof Stage3Data);
  1650. ZeroMemory (&Stage4Data, sizeof Stage4Data);
  1651. if (ProcessStage2(Stage2URL,TRUE, &(pUserData->Status), &Stage3Data, &Stage4Data ))
  1652. {
  1653. do
  1654. {
  1655. if (!PathIsDirectory(CerRoot))
  1656. {
  1657. MessageBox(pParams->hwnd, _T("Reporting to Microsoft failed.\r\nUnable to connect to CER tree."), NULL,MB_OK);
  1658. goto ERRORS;
  1659. }
  1660. if (WaitForSingleObject(hEvent, 50) == WAIT_OBJECT_0)
  1661. {
  1662. bDone = TRUE;
  1663. goto ERRORS;
  1664. }
  1665. // Build Stage3 Strings
  1666. WriteStatusFile(pUserData);
  1667. if (StringCbPrintf(szStage3FilePath, sizeof szStage3FilePath, _T("%s\\%s"), pUserData->BucketPath, FindData.cFileName) != S_OK)
  1668. {
  1669. goto ERRORS;
  1670. }
  1671. // Get the next cab and move on to stage3
  1672. if (!_tcscmp(Stage3Data.szServerName, _T("\0")))
  1673. {
  1674. // We are done with this bucket
  1675. RenameAllCabsToOld(pUserData->BucketPath);
  1676. if (StringCbCopy(pUserData->CabCount, sizeof pUserData->CabCount, _T("0"))!= S_OK)
  1677. {
  1678. goto ERRORS;
  1679. }
  1680. bContinue = FALSE;
  1681. goto Done; // Jump to the end of the loop
  1682. }
  1683. if (ProcessStage3(szStage3FilePath, &Stage3Data))
  1684. {
  1685. // We successfully uploaded the cab rename it and move on to stage4
  1686. RenameUmCabToOld(szStage3FilePath);
  1687. i = _ttoi(pUserData->CabCount);
  1688. if ( i > 0)
  1689. {
  1690. _itot (i-1, pUserData->CabCount, 10);
  1691. }
  1692. ProcessStage4(&Stage4Data);
  1693. }
  1694. ZeroMemory (&Stage3Data, sizeof Stage3Data);
  1695. ZeroMemory (&Stage4Data, sizeof Stage4Data);
  1696. bResult = FALSE;
  1697. bResult = ProcessStage2(Stage2URL,TRUE, &(pUserData->Status), &Stage3Data, &Stage4Data );
  1698. if (bResult)
  1699. {
  1700. WriteStatusFile(pUserData);
  1701. if (_tcscmp(Stage3Data.szServerName, _T("\0")))
  1702. {
  1703. iResult = ProcessStage1(Stage1URL, &(pUserData->Status));
  1704. ++ pUserData->iReportedCount;
  1705. if (iResult == 1 )
  1706. {
  1707. // we are done.
  1708. // rename all of the cabs in this bucket to .old and Update the status.txt
  1709. RenameAllCabsToOld(pUserData->BucketPath);
  1710. if (StringCbCopy(pUserData->CabCount, sizeof pUserData->CabCount, _T("0"))!= S_OK)
  1711. {
  1712. goto ERRORS;
  1713. }
  1714. WriteStatusFile(pUserData);
  1715. goto Done;
  1716. }
  1717. if (iResult == -1)
  1718. {
  1719. goto ERRORS;
  1720. }
  1721. bContinue = TRUE;
  1722. }
  1723. else
  1724. {
  1725. bContinue = FALSE;
  1726. }
  1727. }
  1728. // Do we need to do this each time?
  1729. SendDlgItemMessage(pParams->hwnd ,IDC_FILE_PROGRESS, PBM_STEPIT, 0,0);
  1730. }while( (bResult) && (bContinue) && FindNextFile(hFind, &FindData) ) ;
  1731. FindClose(hFind);
  1732. if (!bResult)
  1733. goto Done;
  1734. SendDlgItemMessage(pParams->hwnd ,IDC_TOTAL_PROGRESS, PBM_STEPIT, 0,0);
  1735. if (!bContinue)
  1736. {
  1737. // Microsoft doesn't want anymore cabs.
  1738. // Rename the remaining cabs to .old
  1739. RenameAllCabsToOld(pUserData->BucketPath);
  1740. if (StringCbCopy(pUserData->CabCount, sizeof pUserData->CabCount, _T("0"))!= S_OK)
  1741. {
  1742. goto ERRORS;
  1743. }
  1744. }
  1745. }
  1746. if (WaitForSingleObject(hEvent, 50) == WAIT_OBJECT_0)
  1747. {
  1748. bDone = TRUE;
  1749. }
  1750. }
  1751. Done:
  1752. // Now that we are done with the stage 1 - 4 processing for new dumps.
  1753. // Hit the Stage 1 url for this bucket pUserData->HitCount - pUserData->Reported count times
  1754. // This will ensure that we have an accurate count of how many times this issue has been encountered.
  1755. iCount = (_ttoi(pUserData->Hits) - pUserData->iReportedCount);
  1756. if (iCount > 0)
  1757. {
  1758. for (int Counter = 0; Counter < iCount; Counter++)
  1759. {
  1760. iResult = ProcessStage1(Stage1URL, &(pUserData->Status));
  1761. // We don't care if it succeeded or not we just want to bump up the counts.
  1762. ++ pUserData->iReportedCount;
  1763. }
  1764. }
  1765. WriteRepCountFile(pUserData->ReportedCountPath, pUserData->iReportedCount);
  1766. if (!pParams->bSelected)
  1767. {
  1768. // Write back the new data for this bucket
  1769. cUserData.SetCurrentEntry(&UserData);
  1770. cUserData.MoveNext(&bEOF);
  1771. }
  1772. } while ( (!bEOF) && (iBucketCount > 0) && (!bDone));
  1773. ERRORS:
  1774. PostMessage(pParams->hwnd, WmSyncDone, FALSE, 0);
  1775. if (hEvent)
  1776. {
  1777. CloseHandle(hEvent);
  1778. hEvent = NULL;
  1779. }
  1780. return 0;
  1781. }
  1782. void OnUserSubmitDlgInit(HWND hwnd)
  1783. /*++
  1784. Routine Description:
  1785. This routine renames a proccessed cab file from .cab to .old
  1786. Arguments:
  1787. ResponseUrl - Microsoft response for the recently submitted dump file.
  1788. Return value:
  1789. Does not return a value
  1790. ++*/
  1791. {
  1792. // create a thread to process the uploads
  1793. HANDLE hThread;
  1794. ThreadParams.hwnd = hwnd;
  1795. hThread = CreateThread(NULL, 0,UserUploadThreadProc , &ThreadParams, 0 , NULL );
  1796. CloseHandle(hThread);
  1797. }
  1798. LRESULT CALLBACK
  1799. UserSubmitDlgProc(
  1800. HWND hwnd,
  1801. UINT iMsg,
  1802. WPARAM wParam,
  1803. LPARAM lParam
  1804. )
  1805. /*++
  1806. Routine Description:
  1807. This routine renames a proccessed cab file from .cab to .old
  1808. Arguments:
  1809. ResponseUrl - Microsoft response for the recently submitted dump file.
  1810. Return value:
  1811. Does not return a value
  1812. ++*/
  1813. {
  1814. // int CurrentPos = 0;
  1815. //HWND Parent = GetParent(hwnd);
  1816. switch (iMsg)
  1817. {
  1818. case WM_INITDIALOG:
  1819. // Start the upload process in a new thread.
  1820. // Report results using WM_FILEDONE
  1821. // CreateEvent();
  1822. SendDlgItemMessage(hwnd ,IDC_TOTAL_PROGRESS, PBM_SETSTEP, MAKELONG( 1,0),0);
  1823. CenterDialogInParent(hwnd);
  1824. SendDlgItemMessage(hwnd ,IDC_FILE_PROGRESS, PBM_SETSTEP, MAKELONG( 1,0),0);
  1825. g_hUserStopEvent = CreateEvent(NULL, FALSE, FALSE, _T("StopUserUpload"));
  1826. if (!g_hUserStopEvent)
  1827. {
  1828. // Now What
  1829. }
  1830. PostMessage(hwnd, WmSyncStart, FALSE, 0);
  1831. //OnSubmitDlgInit(hwnd);
  1832. return TRUE;
  1833. case WmSyncStart:
  1834. OnUserSubmitDlgInit(hwnd);
  1835. return TRUE;
  1836. case WmSetStatus:
  1837. return TRUE;
  1838. case WmSyncDone:
  1839. if (g_hUserStopEvent)
  1840. {
  1841. SetEvent(g_hUserStopEvent);
  1842. CloseHandle(g_hUserStopEvent);
  1843. g_hUserStopEvent = NULL;
  1844. }
  1845. EndDialog(hwnd, 1);
  1846. return TRUE;
  1847. case WM_DESTROY:
  1848. if (g_hUserStopEvent)
  1849. {
  1850. SetEvent(g_hUserStopEvent);
  1851. CloseHandle(g_hUserStopEvent);
  1852. g_hUserStopEvent = NULL;
  1853. }
  1854. else
  1855. {
  1856. EndDialog(hwnd, 1);
  1857. }
  1858. return TRUE;
  1859. case WM_COMMAND:
  1860. switch (LOWORD(wParam))
  1861. {
  1862. case IDCANCEL:
  1863. if (g_hUserStopEvent)
  1864. {
  1865. SetEvent(g_hUserStopEvent);
  1866. CloseHandle(g_hUserStopEvent);
  1867. g_hUserStopEvent = NULL;
  1868. }
  1869. else
  1870. {
  1871. EndDialog(hwnd, 1);
  1872. }
  1873. break;
  1874. }
  1875. }
  1876. return FALSE;
  1877. }
  1878. BOOL
  1879. ReportUserModeFault(HWND hwnd, BOOL bSelected,HWND hList)
  1880. /*++
  1881. Routine Description:
  1882. This routine renames a proccessed cab file from .cab to .old
  1883. Arguments:
  1884. ResponseUrl - Microsoft response for the recently submitted dump file.
  1885. Return value:
  1886. Does not return a value
  1887. ++*/
  1888. {
  1889. ThreadParams.bSelected = bSelected;
  1890. ThreadParams.hListView = hList;
  1891. if (!DialogBox(g_hinst,MAKEINTRESOURCE(IDD_USERMODE_SYNC ), hwnd, (DLGPROC) UserSubmitDlgProc))
  1892. {
  1893. // Failed somewhere to upload the user mode files to Microsoft.
  1894. // What error do we want to give to the User.
  1895. return FALSE;
  1896. }
  1897. return TRUE;
  1898. }