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.

3582 lines
90 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. inetdbg.cxx
  5. Abstract:
  6. Debugging functions for internet DLL
  7. Contents:
  8. InternetDebugInitialize
  9. InternetDebugTerminate
  10. InternetGetDebugInfo
  11. InternetSetDebugInfo
  12. InternetOpenDebugFile
  13. InternetReopenDebugFile
  14. InternetCloseDebugFile
  15. InternetFlushDebugFile
  16. InternetDebugSetControlFlags
  17. InternetDebugResetControlFlags
  18. InternetDebugEnter
  19. InternetDebugLeave
  20. InternetDebugError
  21. InternetDebugPrint
  22. (InternetDebugPrintString)
  23. InternetDebugPrintf
  24. InternetDebugOut
  25. InternetDebugDump
  26. InternetDebugDumpFormat
  27. InternetAssert
  28. InternetGetDebugVariable
  29. (InternetGetDebugVariableString)
  30. InternetMapError
  31. InternetMapStatus
  32. InternetMapOption
  33. InternetMapHttpOption
  34. InternetMapHttpState
  35. InternetMapHttpStateFlag
  36. InternetMapAsyncRequest
  37. InternetMapHandleType
  38. InternetMapScheme
  39. InternetMapOpenType
  40. InternetMapService
  41. (ExtractFileName)
  42. (SetDebugPrefix)
  43. SourceFilename
  44. InitSymLib
  45. TermSymLib
  46. GetDebugSymbol
  47. x86SleazeCallStack
  48. x86SleazeCallersAddress
  49. Author:
  50. Richard L Firth (rfirth) 13-Feb-1995
  51. Environment:
  52. Win32(s) user-mode DLL
  53. Revision History:
  54. 13-Feb-1995 rfirth
  55. Created
  56. --*/
  57. #include <wininetp.h>
  58. #include <ntverp.h>
  59. #ifdef WINHTTP_FOR_MSMXL
  60. #include <ieverp.h>
  61. #endif
  62. #include "rprintf.h"
  63. #include <imagehlp.h>
  64. #ifdef ENABLE_DEBUG
  65. //
  66. // private manifests
  67. //
  68. #define SWITCH_VARIABLE_NAME "WinHttpDebugging"
  69. #define CONTROL_VARIABLE_NAME "WinHttpControl"
  70. #define CATEGORY_VARIABLE_NAME "WinHttpCategory"
  71. #define ERROR_VARIABLE_NAME "WinHttpError"
  72. #define BREAK_VARIABLE_NAME "WinHttpBreak"
  73. //#define DEFAULT_LOG_VARIABLE_NAME "WinHttpxLog"
  74. #define CHECK_LIST_VARIABLE_NAME "WinHttpCheckSerializedList"
  75. #define LOG_FILE_VARIABLE_NAME "WinHttpLogFile"
  76. #define INDENT_VARIABLE_NAME "WinHttpLogIndent"
  77. #define DEFAULT_LOG_FILE_NAME "WINHTTP5.LOG"
  78. #define ENVIRONMENT_VARIABLE_BUFFER_LENGTH 80
  79. #define PRINTF_STACK_BUFFER_LENGTH (4 K)
  80. //
  81. // private macros
  82. //
  83. #define CASE_OF(constant) case constant: return # constant
  84. //
  85. // private prototypes
  86. //
  87. PRIVATE
  88. VOID
  89. InternetDebugPrintString(
  90. IN LPSTR String
  91. );
  92. PRIVATE
  93. VOID
  94. InternetGetDebugVariableString(
  95. IN LPSTR lpszVariableName,
  96. OUT LPSTR lpszVariable,
  97. IN DWORD dwVariableLen
  98. );
  99. PRIVATE
  100. LPSTR
  101. ExtractFileName(
  102. IN LPSTR Module,
  103. OUT LPSTR Buf
  104. );
  105. PRIVATE
  106. LPSTR
  107. SetDebugPrefix(
  108. IN LPSTR Buffer
  109. );
  110. //
  111. //
  112. // these variables are employed in macros, so must be public
  113. //
  114. PUBLIC DWORD InternetDebugErrorLevel = DBG_ERROR;
  115. PUBLIC DWORD InternetDebugControlFlags = DBG_NO_DEBUG;
  116. PUBLIC DWORD InternetDebugCategoryFlags = 0;
  117. PUBLIC DWORD InternetDebugBreakFlags = 0;
  118. //
  119. // these variables are only accessed in this module, so can be private
  120. //
  121. PRIVATE int InternetDebugIndentIncrement = 2;
  122. PRIVATE HANDLE InternetDebugFileHandle = INVALID_HANDLE_VALUE;
  123. PRIVATE char InternetDebugFilename[MAX_PATH + 1] = DEFAULT_LOG_FILE_NAME;
  124. PRIVATE BOOL InternetDebugEnabled = TRUE;
  125. PRIVATE DWORD InternetDebugStartTime = 0;
  126. extern "C" {
  127. BOOL UrlcacheDebugEnabled = FALSE;
  128. #if defined(UNIX) && defined(ux10)
  129. /* Temporary fix for Apogee Compiler bug on HP only */
  130. extern BOOL fCheckEntryOnList;
  131. #else
  132. BOOL fCheckEntryOnList;
  133. #endif /* UNIX */
  134. }
  135. //
  136. // high frequency performance counter globals
  137. //
  138. PRIVATE LONGLONG ftInit; // initial local time
  139. PRIVATE LONGLONG pcInit; // initial perf counter
  140. PRIVATE LONGLONG pcFreq; // perf counter frequency
  141. //
  142. // functions
  143. //
  144. VOID
  145. InternetDebugInitialize(
  146. VOID
  147. )
  148. /*++
  149. Routine Description:
  150. reads environment INETDBG flags and opens debug log file if required
  151. Arguments:
  152. None.
  153. Return Value:
  154. None.
  155. --*/
  156. {
  157. #ifndef WININET_SERVER_CORE
  158. //
  159. // ensure registry key open (normally done in GlobalDataInitialize() later)
  160. //
  161. #endif //!WININET_SERVER_CORE
  162. OpenInternetSettingsKey();
  163. //
  164. // record the starting tick count for cumulative deltas
  165. //
  166. InternetDebugStartTime = GetTickCountWrap();
  167. if (QueryPerformanceFrequency ((LARGE_INTEGER *) &pcFreq) && pcFreq) {
  168. QueryPerformanceCounter ((LARGE_INTEGER *) &pcInit);
  169. SYSTEMTIME st;
  170. GetLocalTime (&st);
  171. SystemTimeToFileTime (&st, (FILETIME *) &ftInit);
  172. }
  173. //
  174. // check see if there are any debug variable overrides in the environment
  175. // or the registry. If "WinHttpLog=<!0>" is set then we use the flags that
  176. // are most commonly used to generate WININET.LOG, with no console or
  177. // debugger output. We allow the other variables to be overridden
  178. //
  179. char WinHttpVer[16] = {0};
  180. BOOL defaultDebugVariables = FALSE;
  181. rsprintf(WinHttpVer,
  182. "WinHttp%dLog",
  183. InternetVersionInfo.dwMajorVersion);
  184. InternetGetDebugVariable(WinHttpVer, (LPDWORD)&defaultDebugVariables);
  185. if (!defaultDebugVariables)
  186. {
  187. InternetGetDebugVariable(SWITCH_VARIABLE_NAME, (LPDWORD)&defaultDebugVariables);
  188. }
  189. if (defaultDebugVariables) {
  190. InternetDebugEnabled = TRUE;
  191. InternetDebugControlFlags = INTERNET_DEBUG_CONTROL_DEFAULT;
  192. InternetDebugCategoryFlags = INTERNET_DEBUG_CATEGORY_DEFAULT;
  193. InternetDebugErrorLevel = INTERNET_DEBUG_ERROR_LEVEL_DEFAULT;
  194. InternetDebugBreakFlags = 0;
  195. }
  196. // InternetGetDebugVariable(SWITCH_VARIABLE_NAME, (LPDWORD)&InternetDebugEnabled);
  197. InternetGetDebugVariable(CONTROL_VARIABLE_NAME, &InternetDebugControlFlags);
  198. InternetGetDebugVariable(CATEGORY_VARIABLE_NAME, &InternetDebugCategoryFlags);
  199. InternetGetDebugVariable(ERROR_VARIABLE_NAME, &InternetDebugErrorLevel);
  200. InternetGetDebugVariable(BREAK_VARIABLE_NAME, &InternetDebugBreakFlags);
  201. InternetGetDebugVariable(CHECK_LIST_VARIABLE_NAME, (LPDWORD)&fCheckEntryOnList);
  202. InternetGetDebugVariable(INDENT_VARIABLE_NAME, (LPDWORD)&InternetDebugIndentIncrement);
  203. InternetGetDebugVariableString(LOG_FILE_VARIABLE_NAME,
  204. InternetDebugFilename,
  205. sizeof(InternetDebugFilename)
  206. );
  207. UrlcacheDebugEnabled = InternetDebugEnabled &&
  208. (InternetDebugCategoryFlags & DBG_CACHE);
  209. if ((InternetDebugIndentIncrement < 0) || (InternetDebugIndentIncrement > 32)) {
  210. InternetDebugIndentIncrement = 2;
  211. }
  212. //
  213. // quit now if debugging is disabled
  214. //
  215. if (!InternetDebugEnabled) {
  216. InternetDebugControlFlags |= (DBG_NO_DEBUG | DBG_NO_DATA_DUMP);
  217. return;
  218. }
  219. //
  220. // if we want to write debug output to file, open WININET.LOG in the current
  221. // directory. Open it in text mode, for write-only (by this process)
  222. //
  223. if (InternetDebugControlFlags & DBG_TO_FILE) {
  224. if (!InternetReopenDebugFile(InternetDebugFilename)) {
  225. InternetDebugControlFlags &= ~DBG_TO_FILE;
  226. }
  227. }
  228. //
  229. // install the debug exception handler
  230. //
  231. SetExceptionHandler();
  232. }
  233. VOID
  234. InternetDebugTerminate(
  235. VOID
  236. )
  237. /*++
  238. Routine Description:
  239. Performs any required debug termination
  240. Arguments:
  241. None.
  242. Return Value:
  243. None.
  244. --*/
  245. {
  246. if (InternetDebugControlFlags & DBG_TO_FILE) {
  247. InternetCloseDebugFile();
  248. }
  249. InternetDebugControlFlags = DBG_NO_DEBUG;
  250. CloseInternetSettingsKey();
  251. }
  252. DWORD
  253. InternetGetDebugInfo(
  254. OUT LPINTERNET_DEBUG_INFO lpBuffer,
  255. IN OUT LPDWORD lpdwBufferLength
  256. )
  257. /*++
  258. Routine Description:
  259. Returns the internal debug variables
  260. Arguments:
  261. lpBuffer - pointer to structure that receives the variables
  262. lpdwBufferLength - IN: Length of buffer
  263. OUT: length of returned data if successful, else
  264. required length of buffer
  265. Return Value:
  266. DWORD
  267. Success - ERROR_SUCCESS;
  268. Failure - ERROR_INSUFFICIENT_BUFFER
  269. --*/
  270. {
  271. DWORD requiredLength;
  272. DWORD error;
  273. int filenameLength;
  274. filenameLength = ((InternetDebugFileHandle != INVALID_HANDLE_VALUE)
  275. ? strlen(InternetDebugFilename) : 0) + 1;
  276. requiredLength = sizeof(*lpBuffer) + filenameLength;
  277. if ((lpBuffer != NULL) && (*lpdwBufferLength >= requiredLength)) {
  278. lpBuffer->ErrorLevel = InternetDebugErrorLevel;
  279. lpBuffer->ControlFlags = InternetDebugControlFlags;
  280. lpBuffer->CategoryFlags = InternetDebugCategoryFlags;
  281. lpBuffer->BreakFlags = InternetDebugBreakFlags;
  282. lpBuffer->IndentIncrement = InternetDebugIndentIncrement;
  283. if (InternetDebugFileHandle != INVALID_HANDLE_VALUE) {
  284. memcpy(lpBuffer->Filename, InternetDebugFilename, filenameLength);
  285. } else {
  286. lpBuffer->Filename[0] = '\0';
  287. }
  288. error = ERROR_SUCCESS;
  289. } else {
  290. error = ERROR_INSUFFICIENT_BUFFER;
  291. }
  292. *lpdwBufferLength = requiredLength;
  293. return error;
  294. }
  295. DWORD
  296. InternetSetDebugInfo(
  297. IN LPINTERNET_DEBUG_INFO lpBuffer,
  298. IN DWORD dwBufferLength
  299. )
  300. /*++
  301. Routine Description:
  302. Sets the internal debugging variables to the values in the buffer. To make
  303. incrmental changes, the caller must first read the variables, change the
  304. bits they're interested in, then change the whole lot at one go
  305. Arguments:
  306. lpBuffer - pointer to structure that contains the variables
  307. dwBufferLength - size of lpBuffer. Ignored
  308. Return Value:
  309. DWORD
  310. Success - ERROR_SUCCESS
  311. Failure -
  312. --*/
  313. {
  314. InternetDebugErrorLevel = lpBuffer->ErrorLevel;
  315. InternetDebugCategoryFlags = lpBuffer->CategoryFlags;
  316. InternetDebugControlFlags = lpBuffer->ControlFlags;
  317. InternetDebugBreakFlags = lpBuffer->BreakFlags;
  318. InternetDebugIndentIncrement = lpBuffer->IndentIncrement;
  319. //
  320. // handle the debug file. If we get an empty string, then (if we are logging
  321. // to a file), close the file.
  322. //
  323. // If the filename is exactly the same as we're already using, then the
  324. // caller doesn't want to change the log file
  325. //
  326. // If the filename is different, then we are being asked to create a new log
  327. // file: close the old and open the new. If we cannot open the new file then
  328. // set the filename to the NUL string in the debug buffer
  329. //
  330. if (lpBuffer->Filename[0]) {
  331. if (strcmp(InternetDebugFilename, lpBuffer->Filename) != 0) {
  332. InternetCloseDebugFile();
  333. InternetReopenDebugFile(lpBuffer->Filename);
  334. if (InternetDebugFileHandle != INVALID_HANDLE_VALUE) {
  335. strcpy(InternetDebugFilename, lpBuffer->Filename);
  336. } else {
  337. lpBuffer->Filename[0] = '\0';
  338. }
  339. }
  340. } else {
  341. InternetCloseDebugFile();
  342. }
  343. return ERROR_SUCCESS;
  344. }
  345. BOOL
  346. InternetOpenDebugFile(
  347. VOID
  348. )
  349. /*++
  350. Routine Description:
  351. Opens debug filename if not already open. Use InternetDebugFilename
  352. Arguments:
  353. None.
  354. Return Value:
  355. BOOL
  356. TRUE - file was opened
  357. FALSE - file not opened (already open or error)
  358. --*/
  359. {
  360. if (InternetDebugFileHandle == INVALID_HANDLE_VALUE) {
  361. InternetDebugFileHandle = CreateFile(
  362. InternetDebugFilename,
  363. GENERIC_WRITE,
  364. FILE_SHARE_READ,
  365. NULL, // lpSecurityAttributes
  366. (InternetDebugControlFlags & DBG_APPEND_FILE)
  367. ? OPEN_ALWAYS
  368. : CREATE_ALWAYS,
  369. FILE_ATTRIBUTE_NORMAL
  370. | FILE_FLAG_SEQUENTIAL_SCAN
  371. | ((InternetDebugControlFlags & DBG_FLUSH_OUTPUT)
  372. ? FILE_FLAG_WRITE_THROUGH
  373. : 0),
  374. NULL
  375. );
  376. return InternetDebugFileHandle != INVALID_HANDLE_VALUE;
  377. }
  378. return FALSE;
  379. }
  380. BOOL
  381. InternetReopenDebugFile(
  382. IN LPSTR Filename
  383. )
  384. /*++
  385. Routine Description:
  386. (Re)opens a debug log file. Closes the current one if it is open
  387. Arguments:
  388. Filename - new file to open
  389. Return Value:
  390. None.
  391. --*/
  392. {
  393. if (InternetDebugFileHandle != INVALID_HANDLE_VALUE) {
  394. InternetCloseDebugFile();
  395. }
  396. if (Filename && *Filename) {
  397. InternetDebugFileHandle = CreateFile(
  398. Filename,
  399. GENERIC_WRITE,
  400. FILE_SHARE_READ,
  401. NULL, // lpSecurityAttributes
  402. (InternetDebugControlFlags & DBG_APPEND_FILE)
  403. ? OPEN_ALWAYS
  404. : CREATE_ALWAYS,
  405. FILE_ATTRIBUTE_NORMAL
  406. | FILE_FLAG_SEQUENTIAL_SCAN
  407. | ((InternetDebugControlFlags & DBG_FLUSH_OUTPUT)
  408. ? FILE_FLAG_WRITE_THROUGH
  409. : 0),
  410. NULL
  411. );
  412. //
  413. // put our start info in the log file. Mainly useful when we're
  414. // appending to the file
  415. //
  416. if (InternetDebugFileHandle != INVALID_HANDLE_VALUE) {
  417. SYSTEMTIME currentTime;
  418. char filespec[MAX_PATH + 1];
  419. LPSTR filename;
  420. if (GetModuleFileName(NULL, filespec, sizeof(filespec))) {
  421. filename = strrchr(filespec, '\\');
  422. if (filename != NULL) {
  423. ++filename;
  424. } else {
  425. filename = filespec;
  426. }
  427. } else {
  428. filename = "";
  429. }
  430. InternetDebugGetLocalTime(&currentTime, NULL);
  431. InternetDebugPrintf("\n"
  432. ">>>> WinHttpX Version %d.%d Build %s.%d " __DATE__ " " __TIME__ "\n"
  433. ">>>> Process %s [%d (%#x)] started at %02d:%02d:%02d.%03d %02d/%02d/%d\n",
  434. InternetVersionInfo.dwMajorVersion,
  435. InternetVersionInfo.dwMinorVersion,
  436. #ifdef WINHTTP_FOR_MSXML // fix MSXML build
  437. "5.00",
  438. #else
  439. VER_PRODUCTVERSION_STRING,
  440. #endif
  441. InternetBuildNumber,
  442. filename,
  443. GetCurrentProcessId(),
  444. GetCurrentProcessId(),
  445. currentTime.wHour,
  446. currentTime.wMinute,
  447. currentTime.wSecond,
  448. currentTime.wMilliseconds,
  449. currentTime.wMonth,
  450. currentTime.wDay,
  451. currentTime.wYear
  452. );
  453. InternetDebugPrintf(">>>> Command line = %q\n", GetCommandLine());
  454. InternetDebugPrintf("\n"
  455. " InternetDebugErrorLevel = %s [%d]\n"
  456. " InternetDebugControlFlags = %#08x\n"
  457. " InternetDebugCategoryFlags = %#08x\n"
  458. " InternetDebugBreakFlags = %#08x\n"
  459. " InternetDebugIndentIncrement = %d\n"
  460. "\n",
  461. (InternetDebugErrorLevel == DBG_INFO) ? "Info"
  462. : (InternetDebugErrorLevel == DBG_WARNING) ? "Warning"
  463. : (InternetDebugErrorLevel == DBG_ERROR) ? "Error"
  464. : (InternetDebugErrorLevel == DBG_FATAL) ? "Fatal"
  465. : (InternetDebugErrorLevel == DBG_ALWAYS) ? "Always"
  466. : "?",
  467. InternetDebugErrorLevel,
  468. InternetDebugControlFlags,
  469. InternetDebugCategoryFlags,
  470. InternetDebugBreakFlags,
  471. InternetDebugIndentIncrement
  472. );
  473. return TRUE;
  474. }
  475. }
  476. return FALSE;
  477. }
  478. VOID
  479. InternetCloseDebugFile(
  480. VOID
  481. )
  482. /*++
  483. Routine Description:
  484. Closes the current debug log file
  485. Arguments:
  486. None.
  487. Return Value:
  488. None.
  489. --*/
  490. {
  491. if (InternetDebugFileHandle != INVALID_HANDLE_VALUE) {
  492. if (InternetDebugControlFlags & DBG_FLUSH_OUTPUT) {
  493. InternetFlushDebugFile();
  494. }
  495. CloseHandle(InternetDebugFileHandle);
  496. InternetDebugFileHandle = INVALID_HANDLE_VALUE;
  497. }
  498. }
  499. VOID
  500. InternetFlushDebugFile(
  501. VOID
  502. )
  503. /*++
  504. Routine Description:
  505. description-of-function.
  506. Arguments:
  507. None.
  508. Return Value:
  509. None.
  510. --*/
  511. {
  512. if (InternetDebugFileHandle != INVALID_HANDLE_VALUE) {
  513. FlushFileBuffers(InternetDebugFileHandle);
  514. }
  515. }
  516. VOID
  517. InternetDebugSetControlFlags(
  518. IN DWORD dwFlags
  519. )
  520. /*++
  521. Routine Description:
  522. Sets debug control flags
  523. Arguments:
  524. dwFlags - flags to set
  525. Return Value:
  526. None.
  527. --*/
  528. {
  529. InternetDebugControlFlags |= dwFlags;
  530. }
  531. VOID
  532. InternetDebugResetControlFlags(
  533. IN DWORD dwFlags
  534. )
  535. /*++
  536. Routine Description:
  537. Resets debug control flags
  538. Arguments:
  539. dwFlags - flags to reset
  540. Return Value:
  541. None.
  542. --*/
  543. {
  544. InternetDebugControlFlags &= ~dwFlags;
  545. }
  546. VOID
  547. InternetDebugEnter(
  548. IN DWORD Category,
  549. IN DEBUG_FUNCTION_RETURN_TYPE ReturnType,
  550. IN LPCSTR Function,
  551. IN LPCSTR ParameterList OPTIONAL,
  552. IN ...
  553. )
  554. /*++
  555. Routine Description:
  556. Creates an INTERNET_DEBUG_RECORD for the current function and adds it to
  557. the per-thread (debug) call-tree
  558. Arguments:
  559. Category - category flags, e.g. DBG_FTP
  560. ReturnType - type of data it returns
  561. Function - name of the function. Must be global, static string
  562. ParameterList - string describing parameters to function, or NULL if none
  563. ... - parameters to function
  564. Return Value:
  565. None.
  566. --*/
  567. {
  568. LPINTERNET_THREAD_INFO pThreadInfo;
  569. LPINTERNET_DEBUG_RECORD pRecord;
  570. if (InternetDebugControlFlags & DBG_NO_DEBUG) {
  571. return;
  572. }
  573. pThreadInfo = InternetGetThreadInfo();
  574. //INET_ASSERT(pThreadInfo != NULL);
  575. if (!pThreadInfo) {
  576. return;
  577. }
  578. pRecord = NEW(INTERNET_DEBUG_RECORD);
  579. //INET_ASSERT(pRecord != NULL);
  580. if (!pRecord) {
  581. return;
  582. }
  583. pRecord->Stack = pThreadInfo->Stack;
  584. pRecord->Category = Category;
  585. pRecord->ReturnType = ReturnType;
  586. pRecord->Function = Function;
  587. pRecord->LastTime = GetTickCountWrap();
  588. pThreadInfo->Stack = pRecord;
  589. ++pThreadInfo->CallDepth;
  590. //
  591. // if the function's category (FTP, GOPHER, HTTP) is selected in the
  592. // category flags, then we dump the function entry information
  593. //
  594. if (InternetDebugCategoryFlags & Category) {
  595. char buf[4096];
  596. LPSTR bufptr;
  597. bufptr = buf;
  598. bufptr += rsprintf(bufptr, "%s(", Function);
  599. if (ARGUMENT_PRESENT(ParameterList)) {
  600. va_list parms;
  601. va_start(parms, ParameterList);
  602. bufptr += _sprintf(bufptr, (char*)ParameterList, parms);
  603. va_end(parms);
  604. }
  605. rsprintf(bufptr, ")\n");
  606. InternetDebugPrintString(buf);
  607. //
  608. // only increase the indentation if we will display debug information
  609. // for this category
  610. //
  611. pThreadInfo->IndentIncrement += InternetDebugIndentIncrement;
  612. }
  613. }
  614. VOID
  615. InternetDebugLeave(
  616. IN DWORD_PTR Variable,
  617. IN LPCSTR Filename,
  618. IN DWORD LineNumber
  619. )
  620. /*++
  621. Routine Description:
  622. Destroys the INTERNET_DEBUG_RECORD for the current function and dumps info
  623. about what the function is returning, if requested to do so
  624. Arguments:
  625. Variable - variable containing value being returned by function
  626. Filename - name of file where DEBUG_LEAVE() invoked
  627. LineNumber - and line number in Filename
  628. Return Value:
  629. None.
  630. --*/
  631. {
  632. LPINTERNET_THREAD_INFO pThreadInfo;
  633. LPINTERNET_DEBUG_RECORD pRecord;
  634. LPSTR format;
  635. LPSTR errstr;
  636. BOOL noVar;
  637. char formatBuf[128];
  638. DWORD lastError;
  639. char hexnumBuf[15];
  640. if (InternetDebugControlFlags & DBG_NO_DEBUG) {
  641. return;
  642. }
  643. //
  644. // seems that something in this path can nuke the last error, so we must
  645. // refresh it
  646. //
  647. lastError = GetLastError();
  648. pThreadInfo = InternetGetThreadInfo();
  649. //INET_ASSERT(pThreadInfo != NULL);
  650. if (!pThreadInfo) {
  651. return;
  652. }
  653. pRecord = pThreadInfo->Stack;
  654. //INET_ASSERT(pRecord != NULL);
  655. if (!pRecord) {
  656. return;
  657. }
  658. //
  659. // we are about to output a diagnostic message to the debug log, debugger,
  660. // or console. First check that we are required to display messages at
  661. // this level. The level for function ENTER and LEAVE is INFO
  662. //
  663. if (InternetDebugErrorLevel <= DBG_INFO) {
  664. //
  665. // only display the string and reduce the indent if we are requested
  666. // for information about this category
  667. //
  668. errstr = NULL;
  669. noVar = FALSE;
  670. if (InternetDebugCategoryFlags & pRecord->Category) {
  671. switch (pRecord->ReturnType) {
  672. case None:
  673. format = "%s() returning VOID";
  674. noVar = TRUE;
  675. break;
  676. case Bool:
  677. Variable = (DWORD_PTR)(Variable ? "TRUE" : "FALSE");
  678. //
  679. // *** FALL THROUGH ***
  680. //
  681. case String:
  682. format = "%s() returning %s";
  683. break;
  684. case Int:
  685. format = "%s() returning %d";
  686. break;
  687. case Dword:
  688. format = "%s() returning %u";
  689. errstr = InternetMapError((DWORD)Variable);
  690. if (errstr != NULL) {
  691. if (*errstr == '?') {
  692. rsprintf(hexnumBuf, "%#x", Variable);
  693. errstr = hexnumBuf;
  694. format = "%s() returning %u [?] (%s)";
  695. } else {
  696. format = "%s() returning %u [%s]";
  697. }
  698. }
  699. break;
  700. case Handle:
  701. case Pointer:
  702. if (Variable == 0) {
  703. format = "%s() returning NULL";
  704. noVar = TRUE;
  705. } else {
  706. if (pRecord->ReturnType == Handle) {
  707. format = "%s() returning handle %#x";
  708. } else {
  709. format = "%s() returning %#x";
  710. }
  711. }
  712. break;
  713. default:
  714. INET_ASSERT(FALSE);
  715. break;
  716. }
  717. pThreadInfo->IndentIncrement -= InternetDebugIndentIncrement;
  718. if (pThreadInfo->IndentIncrement < 0) {
  719. pThreadInfo->IndentIncrement = 0;
  720. }
  721. //
  722. // add line number info, if requested
  723. //
  724. strcpy(formatBuf, format);
  725. if (!(InternetDebugControlFlags & DBG_NO_LINE_NUMBER)) {
  726. strcat(formatBuf, " (line %d)");
  727. }
  728. strcat(formatBuf, "\n");
  729. //
  730. // output an empty line if we are required to separate API calls in
  731. // the log. Only do this if this is an API level function, and it
  732. // is the top-level function
  733. //
  734. if ((InternetDebugControlFlags & DBG_SEPARATE_APIS)
  735. && (pRecord->Stack == NULL)) {
  736. strcat(formatBuf, "\n");
  737. }
  738. //
  739. // dump the line, depending on requirements and number of arguments
  740. //
  741. if (noVar) {
  742. InternetDebugPrint(formatBuf,
  743. pRecord->Function,
  744. LineNumber
  745. );
  746. } else if (errstr != NULL) {
  747. InternetDebugPrint(formatBuf,
  748. pRecord->Function,
  749. Variable,
  750. errstr,
  751. LineNumber
  752. );
  753. } else {
  754. InternetDebugPrint(formatBuf,
  755. pRecord->Function,
  756. Variable,
  757. LineNumber
  758. );
  759. }
  760. /*
  761. //
  762. // output an empty line if we are required to separate API calls in
  763. // the log. Only do this if this is an API level function, and it
  764. // is the top-level function
  765. //
  766. if ((InternetDebugControlFlags & DBG_SEPARATE_APIS)
  767. && (pRecord->Stack == NULL)) {
  768. //
  769. // don't call InternetDebugPrint - we don't need timing, thread,
  770. // level etc. information just for the separator
  771. //
  772. InternetDebugOut("\n", FALSE);
  773. }
  774. */
  775. }
  776. }
  777. //
  778. // regardless of whether we are outputting debug info for this category,
  779. // remove the debug record and reduce the call-depth
  780. //
  781. --pThreadInfo->CallDepth;
  782. pThreadInfo->Stack = pRecord->Stack;
  783. DEL(pRecord);
  784. //
  785. // refresh the last error, in case it was nuked
  786. //
  787. SetLastError(lastError);
  788. }
  789. VOID
  790. InternetDebugError(
  791. IN DWORD Error
  792. )
  793. /*++
  794. Routine Description:
  795. Used to display that a function is returning an error. We try to display a
  796. symbolic name for the error too (as when we are returning a DWORD from a
  797. function, using DEBUG_LEAVE)
  798. Displays a string of the form:
  799. Foo() returning error 87 [ERROR_INVALID_PARAMETER]
  800. Arguments:
  801. Error - the error code
  802. Return Value:
  803. None.
  804. --*/
  805. {
  806. LPINTERNET_THREAD_INFO pThreadInfo;
  807. LPINTERNET_DEBUG_RECORD pRecord;
  808. LPSTR errstr;
  809. DWORD lastError;
  810. char hexnumBuf[15];
  811. if (InternetDebugControlFlags & DBG_NO_DEBUG) {
  812. return;
  813. }
  814. //
  815. // seems that something in this path can nuke the last error, so we must
  816. // refresh it
  817. //
  818. lastError = GetLastError();
  819. pThreadInfo = InternetGetThreadInfo();
  820. //INET_ASSERT(pThreadInfo != NULL);
  821. INET_ASSERT(GetLastError() == lastError);
  822. if (pThreadInfo == NULL) {
  823. return;
  824. }
  825. pRecord = pThreadInfo->Stack;
  826. //INET_ASSERT(pRecord != NULL);
  827. if (pRecord == NULL) {
  828. return;
  829. }
  830. errstr = InternetMapError(Error);
  831. if ((errstr == NULL) || (*errstr == '?')) {
  832. rsprintf(hexnumBuf, "%#x", Error);
  833. errstr = hexnumBuf;
  834. }
  835. InternetDebugPrint("%s() returning %d [%s]\n",
  836. pRecord->Function,
  837. Error,
  838. errstr
  839. );
  840. //
  841. // refresh the last error, in case it was nuked
  842. //
  843. SetLastError(lastError);
  844. }
  845. VOID
  846. InternetDebugPrint(
  847. IN LPSTR Format,
  848. ...
  849. )
  850. /*++
  851. Routine Description:
  852. Internet equivalent of printf()
  853. Arguments:
  854. Format - printf format string
  855. ... - any extra args
  856. Return Value:
  857. None.
  858. --*/
  859. {
  860. if (InternetDebugControlFlags & DBG_NO_DEBUG) {
  861. return;
  862. }
  863. char buf[PRINTF_STACK_BUFFER_LENGTH];
  864. LPSTR bufptr;
  865. bufptr = SetDebugPrefix(buf);
  866. if (bufptr == NULL) {
  867. return;
  868. }
  869. //
  870. // now append the string that the DEBUG_PRINT originally gave us
  871. //
  872. va_list list;
  873. va_start(list, Format);
  874. _sprintf(bufptr, Format, list);
  875. va_end(list);
  876. InternetDebugOut(buf, FALSE);
  877. }
  878. VOID
  879. InternetDebugPrintValist(
  880. IN LPSTR Format,
  881. va_list list
  882. )
  883. /*++
  884. Routine Description:
  885. Internet equivalent of printf(), but takes valist as the args
  886. Arguments:
  887. Format - printf format string
  888. list - stack frame of variable arguments
  889. Return Value:
  890. None.
  891. --*/
  892. {
  893. if (InternetDebugControlFlags & DBG_NO_DEBUG) {
  894. return;
  895. }
  896. char buf[PRINTF_STACK_BUFFER_LENGTH];
  897. LPSTR bufptr;
  898. bufptr = SetDebugPrefix(buf);
  899. if (bufptr == NULL) {
  900. return;
  901. }
  902. _sprintf(bufptr, Format, list);
  903. InternetDebugOut(buf, FALSE);
  904. }
  905. PRIVATE
  906. VOID
  907. InternetDebugPrintString(
  908. IN LPSTR String
  909. )
  910. /*++
  911. Routine Description:
  912. Same as InternetDebugPrint(), except we perform no expansion on the string
  913. Arguments:
  914. String - already formatted string (may contain %s)
  915. Return Value:
  916. None.
  917. --*/
  918. {
  919. if (InternetDebugControlFlags & DBG_NO_DEBUG) {
  920. return;
  921. }
  922. char buf[PRINTF_STACK_BUFFER_LENGTH];
  923. LPSTR bufptr;
  924. bufptr = SetDebugPrefix(buf);
  925. if (bufptr == NULL) {
  926. return;
  927. }
  928. //
  929. // now append the string that the DEBUG_PRINT originally gave us
  930. //
  931. strcpy(bufptr, String);
  932. InternetDebugOut(buf, FALSE);
  933. }
  934. VOID
  935. InternetDebugPrintf(
  936. IN LPSTR Format,
  937. IN ...
  938. )
  939. /*++
  940. Routine Description:
  941. Same as InternetDebugPrint(), but we don't access the per-thread info
  942. (because we may not have any)
  943. Arguments:
  944. Format - printf format string
  945. ... - any extra args
  946. Return Value:
  947. None.
  948. --*/
  949. {
  950. if (InternetDebugControlFlags & DBG_NO_DEBUG) {
  951. return;
  952. }
  953. va_list list;
  954. char buf[PRINTF_STACK_BUFFER_LENGTH];
  955. va_start(list, Format);
  956. _sprintf(buf, Format, list);
  957. va_end(list);
  958. InternetDebugOut(buf, FALSE);
  959. }
  960. VOID
  961. InternetDebugOut(
  962. IN LPSTR Buffer,
  963. IN BOOL Assert
  964. )
  965. /*++
  966. Routine Description:
  967. Writes a string somewhere - to the debug log file, to the console, or via
  968. the debugger, or any combination
  969. Arguments:
  970. Buffer - pointer to formatted buffer to write
  971. Assert - TRUE if this function is being called from InternetAssert(), in
  972. which case we *always* write to the debugger. Of course, there
  973. may be no debugger attached, in which case no action is taken
  974. Return Value:
  975. None.
  976. --*/
  977. {
  978. int buflen;
  979. DWORD written;
  980. buflen = strlen(Buffer);
  981. if ((InternetDebugControlFlags & DBG_TO_FILE)
  982. && (InternetDebugFileHandle != INVALID_HANDLE_VALUE)) {
  983. WriteFile(InternetDebugFileHandle, Buffer, buflen, &written, NULL);
  984. if (InternetDebugControlFlags & DBG_FLUSH_OUTPUT) {
  985. InternetFlushDebugFile();
  986. }
  987. }
  988. if (InternetDebugControlFlags & DBG_TO_CONSOLE) {
  989. WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),
  990. Buffer,
  991. buflen,
  992. &written,
  993. 0
  994. );
  995. }
  996. if (Assert || (InternetDebugControlFlags & DBG_TO_DEBUGGER)) {
  997. OutputDebugString(Buffer);
  998. }
  999. }
  1000. VOID
  1001. InternetDebugDump(
  1002. IN LPSTR Text,
  1003. IN LPBYTE Address,
  1004. IN DWORD Size
  1005. )
  1006. /*++
  1007. Routine Description:
  1008. Dumps Size bytes at Address, in the time-honoured debug tradition
  1009. Arguments:
  1010. Text - to display before dumping data
  1011. Address - start of buffer
  1012. Size - number of bytes
  1013. Return Value:
  1014. None.
  1015. --*/
  1016. {
  1017. //
  1018. // if flags say no data dumps then quit
  1019. //
  1020. if (InternetDebugControlFlags & (DBG_NO_DEBUG | DBG_NO_DATA_DUMP)) {
  1021. return;
  1022. }
  1023. //
  1024. // display the introduction text, if any
  1025. //
  1026. if (Text) {
  1027. if (InternetDebugControlFlags & DBG_INDENT_DUMP) {
  1028. InternetDebugPrint(Text);
  1029. } else {
  1030. InternetDebugOut(Text, FALSE);
  1031. }
  1032. }
  1033. char buf[128];
  1034. //
  1035. // display a line telling us how much data there is, if requested to
  1036. //
  1037. if (InternetDebugControlFlags & DBG_DUMP_LENGTH) {
  1038. rsprintf(buf, "%d (%#x) bytes @ %#x\n", Size, Size, Address);
  1039. if (InternetDebugControlFlags & DBG_INDENT_DUMP) {
  1040. InternetDebugPrintString(buf);
  1041. } else {
  1042. InternetDebugOut(buf, FALSE);
  1043. }
  1044. }
  1045. //
  1046. // dump out the data, debug style
  1047. //
  1048. while (Size) {
  1049. int len = InternetDebugDumpFormat(Address, Size, sizeof(BYTE), buf);
  1050. //
  1051. // if we are to indent the data to the current level, then display the
  1052. // buffer via InternetDebugPrint() which will apply all the thread id,
  1053. // indentation, and other options selected, else just display the data
  1054. // via InternetDebugOut(), which will simply send it to the output media
  1055. //
  1056. if (InternetDebugControlFlags & DBG_INDENT_DUMP) {
  1057. InternetDebugPrintString(buf);
  1058. } else {
  1059. InternetDebugOut(buf, FALSE);
  1060. }
  1061. Address += len;
  1062. Size -= len;
  1063. }
  1064. }
  1065. DWORD
  1066. InternetDebugDumpFormat(
  1067. IN LPBYTE Address,
  1068. IN DWORD Size,
  1069. IN DWORD ElementSize,
  1070. OUT LPSTR Buffer
  1071. )
  1072. /*++
  1073. Routine Description:
  1074. Formats Size bytes at Address, in the time-honoured debug tradition, for
  1075. data dump purposes
  1076. Arguments:
  1077. Address - start of buffer
  1078. Size - number of bytes
  1079. ElementSize - size of each word element in bytes
  1080. Buffer - pointer to output buffer, assumed to be large enough
  1081. Return Value:
  1082. DWORD - number of bytes formatted
  1083. --*/
  1084. {
  1085. //
  1086. // we (currently) only understand DWORD, WORD and BYTE dumps
  1087. //
  1088. if ((ElementSize != sizeof(DWORD)) && (ElementSize != sizeof(WORD))) {
  1089. ElementSize = sizeof(BYTE);
  1090. }
  1091. static char spaces[] = " "; // 15 * 3 + 2
  1092. int i, len;
  1093. len = min(Size, 16);
  1094. rsprintf(Buffer, "%08x ", Address);
  1095. //
  1096. // dump the hex representation of each character or word - up to 16 per line
  1097. //
  1098. DWORD offset = 10;
  1099. for (i = 0; i < len; i += ElementSize) {
  1100. DWORD value;
  1101. LPSTR formatString;
  1102. switch (ElementSize) {
  1103. case 4:
  1104. formatString = "%08x ";
  1105. value = *(LPDWORD)&Address[i];
  1106. break;
  1107. case 2:
  1108. formatString = "%04x ";
  1109. value = *(LPWORD)&Address[i] & 0xffff;
  1110. break;
  1111. default:
  1112. formatString = ((i & 15) == 7) ? "%02.2x-" : "%02.2x ";
  1113. value = Address[i] & 0xff;
  1114. break;
  1115. }
  1116. rsprintf(&Buffer[offset], formatString, value);
  1117. offset += ElementSize * 2 + 1;
  1118. }
  1119. //
  1120. // write as many spaces as required to tab to ASCII field
  1121. //
  1122. memcpy(&Buffer[offset], spaces, (16 - len) * 3 + 2);
  1123. offset += (16 - len) * 3 + 2;
  1124. //
  1125. // dump ASCII representation of each character
  1126. //
  1127. for (i = 0; i < len; ++i) {
  1128. char ch;
  1129. ch = Address[i];
  1130. Buffer[offset + i] = ((ch < 32) || (ch > 127)) ? '.' : ch;
  1131. }
  1132. Buffer[offset + i++] = '\r';
  1133. Buffer[offset + i++] = '\n';
  1134. Buffer[offset + i] = '\0';
  1135. return len;
  1136. }
  1137. VOID
  1138. InternetAssert(
  1139. IN LPSTR Assertion,
  1140. IN LPSTR FileName,
  1141. IN DWORD LineNumber
  1142. )
  1143. /*++
  1144. Routine Description:
  1145. displays assertion message at debugger and raised breakpoint exception
  1146. Arguments:
  1147. Assertion - string describing assertion which failed
  1148. FileName - module where assertion failure occurred
  1149. LineNumber - at this line number
  1150. Return Value:
  1151. None.
  1152. --*/
  1153. {
  1154. char buffer[512];
  1155. rsprintf(buffer,
  1156. "\n"
  1157. "*** WinHttp Assertion failed: %s\n"
  1158. "*** Source file: %s\n"
  1159. "*** Source line: %d\n"
  1160. "*** Thread %08x\n"
  1161. "\n",
  1162. Assertion,
  1163. FileName,
  1164. LineNumber,
  1165. GetCurrentThreadId()
  1166. );
  1167. InternetDebugOut(buffer, TRUE);
  1168. //
  1169. // break to the debugger, unless it is requested that we don't
  1170. //
  1171. if (!(InternetDebugControlFlags & DBG_NO_ASSERT_BREAK)) {
  1172. DebugBreak();
  1173. }
  1174. }
  1175. VOID
  1176. InternetGetDebugVariable(
  1177. IN LPSTR lpszVariableName,
  1178. OUT LPDWORD lpdwVariable
  1179. )
  1180. /*++
  1181. Routine Description:
  1182. Get debug variable. First examine environment, then registry
  1183. Arguments:
  1184. lpszVariableName - variable name
  1185. lpdwVariable - returned variable
  1186. Return Value:
  1187. None.
  1188. --*/
  1189. {
  1190. DWORD len;
  1191. char varbuf[ENVIRONMENT_VARIABLE_BUFFER_LENGTH];
  1192. //
  1193. // get the debug variables first from the environment, then - if not there -
  1194. // from the registry
  1195. //
  1196. len = GetEnvironmentVariable(lpszVariableName, varbuf, sizeof(varbuf));
  1197. if (len && len < sizeof(varbuf)) {
  1198. *lpdwVariable = (DWORD)strtoul(varbuf, NULL, 0);
  1199. } else {
  1200. InternetReadRegistryDword(lpszVariableName, lpdwVariable);
  1201. }
  1202. }
  1203. PRIVATE
  1204. VOID
  1205. InternetGetDebugVariableString(
  1206. IN LPSTR lpszVariableName,
  1207. OUT LPSTR lpszVariable,
  1208. IN DWORD dwVariableLen
  1209. )
  1210. /*++
  1211. Routine Description:
  1212. Get debug variable string. First examine environment, then registry
  1213. Arguments:
  1214. lpszVariableName - variable name
  1215. lpszVariable - returned string variable
  1216. dwVariableLen - size of buffer
  1217. Return Value:
  1218. None.
  1219. --*/
  1220. {
  1221. if (GetEnvironmentVariable(lpszVariableName, lpszVariable, dwVariableLen) == 0) {
  1222. char buf[MAX_PATH + 1];
  1223. DWORD len = min(sizeof(buf), dwVariableLen);
  1224. if (InternetReadRegistryString(lpszVariableName, buf, &len) == ERROR_SUCCESS) {
  1225. memcpy(lpszVariable, buf, len + 1);
  1226. }
  1227. }
  1228. }
  1229. LPSTR
  1230. InternetMapChunkToken(
  1231. IN CHUNK_TOKEN_VALUE eToken
  1232. )
  1233. {
  1234. switch(eToken)
  1235. {
  1236. CASE_OF(CHUNK_TOKEN_DIGIT);
  1237. CASE_OF(CHUNK_TOKEN_DATA);
  1238. CASE_OF(CHUNK_TOKEN_COLON);
  1239. CASE_OF(CHUNK_TOKEN_CR);
  1240. CASE_OF(CHUNK_TOKEN_LF);
  1241. default:
  1242. return "?";
  1243. }
  1244. }
  1245. LPSTR
  1246. InternetMapChunkState(
  1247. IN CHUNK_DECODE_STATE eState
  1248. )
  1249. {
  1250. switch(eState)
  1251. {
  1252. CASE_OF(CHUNK_DECODE_STATE_START);
  1253. CASE_OF(CHUNK_DECODE_STATE_SIZE);
  1254. CASE_OF(CHUNK_DECODE_STATE_SIZE_CRLF);
  1255. CASE_OF(CHUNK_DECODE_STATE_EXT);
  1256. CASE_OF(CHUNK_DECODE_STATE_DATA);
  1257. CASE_OF(CHUNK_DECODE_STATE_DATA_CRLF);
  1258. CASE_OF(CHUNK_DECODE_STATE_FOOTER_NAME);
  1259. CASE_OF(CHUNK_DECODE_STATE_FOOTER_VALUE);
  1260. CASE_OF(CHUNK_DECODE_STATE_FINAL_CRLF);
  1261. CASE_OF(CHUNK_DECODE_STATE_ERROR);
  1262. default:
  1263. return "?";
  1264. }
  1265. }
  1266. LPSTR
  1267. InternetMapError(
  1268. IN DWORD Error
  1269. )
  1270. /*++
  1271. Routine Description:
  1272. Map error code to string. Try to get all errors that might ever be returned
  1273. by an Internet function
  1274. Arguments:
  1275. Error - code to map
  1276. Return Value:
  1277. LPSTR - pointer to symbolic error name
  1278. --*/
  1279. {
  1280. switch (Error) {
  1281. //
  1282. // WINERROR errors
  1283. //
  1284. CASE_OF(ERROR_SUCCESS);
  1285. CASE_OF(ERROR_INVALID_FUNCTION);
  1286. CASE_OF(ERROR_FILE_NOT_FOUND);
  1287. CASE_OF(ERROR_PATH_NOT_FOUND);
  1288. CASE_OF(ERROR_TOO_MANY_OPEN_FILES);
  1289. CASE_OF(ERROR_ACCESS_DENIED);
  1290. CASE_OF(ERROR_INVALID_HANDLE);
  1291. CASE_OF(ERROR_ARENA_TRASHED);
  1292. CASE_OF(ERROR_NOT_ENOUGH_MEMORY);
  1293. CASE_OF(ERROR_INVALID_BLOCK);
  1294. CASE_OF(ERROR_BAD_ENVIRONMENT);
  1295. CASE_OF(ERROR_BAD_FORMAT);
  1296. CASE_OF(ERROR_INVALID_ACCESS);
  1297. CASE_OF(ERROR_INVALID_DATA);
  1298. CASE_OF(ERROR_OUTOFMEMORY);
  1299. CASE_OF(ERROR_INVALID_DRIVE);
  1300. CASE_OF(ERROR_CURRENT_DIRECTORY);
  1301. CASE_OF(ERROR_NOT_SAME_DEVICE);
  1302. CASE_OF(ERROR_NO_MORE_FILES);
  1303. CASE_OF(ERROR_WRITE_PROTECT);
  1304. CASE_OF(ERROR_BAD_UNIT);
  1305. CASE_OF(ERROR_NOT_READY);
  1306. CASE_OF(ERROR_BAD_COMMAND);
  1307. CASE_OF(ERROR_CRC);
  1308. CASE_OF(ERROR_BAD_LENGTH);
  1309. CASE_OF(ERROR_SEEK);
  1310. CASE_OF(ERROR_NOT_DOS_DISK);
  1311. CASE_OF(ERROR_SECTOR_NOT_FOUND);
  1312. CASE_OF(ERROR_OUT_OF_PAPER);
  1313. CASE_OF(ERROR_WRITE_FAULT);
  1314. CASE_OF(ERROR_READ_FAULT);
  1315. CASE_OF(ERROR_GEN_FAILURE);
  1316. CASE_OF(ERROR_SHARING_VIOLATION);
  1317. CASE_OF(ERROR_LOCK_VIOLATION);
  1318. CASE_OF(ERROR_WRONG_DISK);
  1319. CASE_OF(ERROR_SHARING_BUFFER_EXCEEDED);
  1320. CASE_OF(ERROR_HANDLE_EOF);
  1321. CASE_OF(ERROR_HANDLE_DISK_FULL);
  1322. CASE_OF(ERROR_NOT_SUPPORTED);
  1323. CASE_OF(ERROR_REM_NOT_LIST);
  1324. CASE_OF(ERROR_DUP_NAME);
  1325. CASE_OF(ERROR_BAD_NETPATH);
  1326. CASE_OF(ERROR_NETWORK_BUSY);
  1327. CASE_OF(ERROR_DEV_NOT_EXIST);
  1328. CASE_OF(ERROR_TOO_MANY_CMDS);
  1329. CASE_OF(ERROR_ADAP_HDW_ERR);
  1330. CASE_OF(ERROR_BAD_NET_RESP);
  1331. CASE_OF(ERROR_UNEXP_NET_ERR);
  1332. CASE_OF(ERROR_BAD_REM_ADAP);
  1333. CASE_OF(ERROR_PRINTQ_FULL);
  1334. CASE_OF(ERROR_NO_SPOOL_SPACE);
  1335. CASE_OF(ERROR_PRINT_CANCELLED);
  1336. CASE_OF(ERROR_NETNAME_DELETED);
  1337. CASE_OF(ERROR_NETWORK_ACCESS_DENIED);
  1338. CASE_OF(ERROR_BAD_DEV_TYPE);
  1339. CASE_OF(ERROR_BAD_NET_NAME);
  1340. CASE_OF(ERROR_TOO_MANY_NAMES);
  1341. CASE_OF(ERROR_TOO_MANY_SESS);
  1342. CASE_OF(ERROR_SHARING_PAUSED);
  1343. CASE_OF(ERROR_REQ_NOT_ACCEP);
  1344. CASE_OF(ERROR_REDIR_PAUSED);
  1345. CASE_OF(ERROR_FILE_EXISTS);
  1346. CASE_OF(ERROR_CANNOT_MAKE);
  1347. CASE_OF(ERROR_FAIL_I24);
  1348. CASE_OF(ERROR_OUT_OF_STRUCTURES);
  1349. CASE_OF(ERROR_ALREADY_ASSIGNED);
  1350. CASE_OF(ERROR_INVALID_PASSWORD);
  1351. CASE_OF(ERROR_INVALID_PARAMETER);
  1352. CASE_OF(ERROR_NET_WRITE_FAULT);
  1353. CASE_OF(ERROR_NO_PROC_SLOTS);
  1354. CASE_OF(ERROR_TOO_MANY_SEMAPHORES);
  1355. CASE_OF(ERROR_EXCL_SEM_ALREADY_OWNED);
  1356. CASE_OF(ERROR_SEM_IS_SET);
  1357. CASE_OF(ERROR_TOO_MANY_SEM_REQUESTS);
  1358. CASE_OF(ERROR_INVALID_AT_INTERRUPT_TIME);
  1359. CASE_OF(ERROR_SEM_OWNER_DIED);
  1360. CASE_OF(ERROR_SEM_USER_LIMIT);
  1361. CASE_OF(ERROR_DISK_CHANGE);
  1362. CASE_OF(ERROR_DRIVE_LOCKED);
  1363. CASE_OF(ERROR_BROKEN_PIPE);
  1364. CASE_OF(ERROR_OPEN_FAILED);
  1365. CASE_OF(ERROR_BUFFER_OVERFLOW);
  1366. CASE_OF(ERROR_DISK_FULL);
  1367. CASE_OF(ERROR_NO_MORE_SEARCH_HANDLES);
  1368. CASE_OF(ERROR_INVALID_TARGET_HANDLE);
  1369. CASE_OF(ERROR_INVALID_CATEGORY);
  1370. CASE_OF(ERROR_INVALID_VERIFY_SWITCH);
  1371. CASE_OF(ERROR_BAD_DRIVER_LEVEL);
  1372. CASE_OF(ERROR_CALL_NOT_IMPLEMENTED);
  1373. CASE_OF(ERROR_SEM_TIMEOUT);
  1374. CASE_OF(ERROR_INSUFFICIENT_BUFFER);
  1375. CASE_OF(ERROR_INVALID_NAME);
  1376. CASE_OF(ERROR_INVALID_LEVEL);
  1377. CASE_OF(ERROR_NO_VOLUME_LABEL);
  1378. CASE_OF(ERROR_MOD_NOT_FOUND);
  1379. CASE_OF(ERROR_PROC_NOT_FOUND);
  1380. CASE_OF(ERROR_WAIT_NO_CHILDREN);
  1381. CASE_OF(ERROR_CHILD_NOT_COMPLETE);
  1382. CASE_OF(ERROR_DIRECT_ACCESS_HANDLE);
  1383. CASE_OF(ERROR_NEGATIVE_SEEK);
  1384. CASE_OF(ERROR_SEEK_ON_DEVICE);
  1385. CASE_OF(ERROR_DIR_NOT_ROOT);
  1386. CASE_OF(ERROR_DIR_NOT_EMPTY);
  1387. CASE_OF(ERROR_PATH_BUSY);
  1388. CASE_OF(ERROR_SYSTEM_TRACE);
  1389. CASE_OF(ERROR_INVALID_EVENT_COUNT);
  1390. CASE_OF(ERROR_TOO_MANY_MUXWAITERS);
  1391. CASE_OF(ERROR_INVALID_LIST_FORMAT);
  1392. CASE_OF(ERROR_BAD_ARGUMENTS);
  1393. CASE_OF(ERROR_BAD_PATHNAME);
  1394. CASE_OF(ERROR_BUSY);
  1395. CASE_OF(ERROR_CANCEL_VIOLATION);
  1396. CASE_OF(ERROR_ALREADY_EXISTS);
  1397. CASE_OF(ERROR_FILENAME_EXCED_RANGE);
  1398. CASE_OF(ERROR_LOCKED);
  1399. CASE_OF(ERROR_NESTING_NOT_ALLOWED);
  1400. CASE_OF(ERROR_BAD_PIPE);
  1401. CASE_OF(ERROR_PIPE_BUSY);
  1402. CASE_OF(ERROR_NO_DATA);
  1403. CASE_OF(ERROR_PIPE_NOT_CONNECTED);
  1404. CASE_OF(ERROR_MORE_DATA);
  1405. CASE_OF(ERROR_NO_MORE_ITEMS);
  1406. CASE_OF(ERROR_NOT_OWNER);
  1407. CASE_OF(ERROR_PARTIAL_COPY);
  1408. CASE_OF(ERROR_MR_MID_NOT_FOUND);
  1409. CASE_OF(ERROR_INVALID_ADDRESS);
  1410. CASE_OF(ERROR_PIPE_CONNECTED);
  1411. CASE_OF(ERROR_PIPE_LISTENING);
  1412. CASE_OF(ERROR_OPERATION_ABORTED);
  1413. CASE_OF(ERROR_IO_INCOMPLETE);
  1414. CASE_OF(ERROR_IO_PENDING);
  1415. CASE_OF(ERROR_NOACCESS);
  1416. CASE_OF(ERROR_STACK_OVERFLOW);
  1417. CASE_OF(ERROR_INVALID_FLAGS);
  1418. CASE_OF(ERROR_NO_TOKEN);
  1419. CASE_OF(ERROR_BADDB);
  1420. CASE_OF(ERROR_BADKEY);
  1421. CASE_OF(ERROR_CANTOPEN);
  1422. CASE_OF(ERROR_CANTREAD);
  1423. CASE_OF(ERROR_CANTWRITE);
  1424. CASE_OF(ERROR_REGISTRY_RECOVERED);
  1425. CASE_OF(ERROR_REGISTRY_CORRUPT);
  1426. CASE_OF(ERROR_REGISTRY_IO_FAILED);
  1427. CASE_OF(ERROR_NOT_REGISTRY_FILE);
  1428. CASE_OF(ERROR_KEY_DELETED);
  1429. CASE_OF(ERROR_CIRCULAR_DEPENDENCY);
  1430. CASE_OF(ERROR_SERVICE_NOT_ACTIVE);
  1431. CASE_OF(ERROR_DLL_INIT_FAILED);
  1432. CASE_OF(ERROR_CANCELLED);
  1433. CASE_OF(ERROR_BAD_USERNAME);
  1434. CASE_OF(ERROR_LOGON_FAILURE);
  1435. CASE_OF(WAIT_FAILED);
  1436. //CASE_OF(WAIT_ABANDONED_0);
  1437. CASE_OF(WAIT_TIMEOUT);
  1438. CASE_OF(WAIT_IO_COMPLETION);
  1439. //CASE_OF(STILL_ACTIVE);
  1440. CASE_OF(RPC_S_INVALID_STRING_BINDING);
  1441. CASE_OF(RPC_S_WRONG_KIND_OF_BINDING);
  1442. CASE_OF(RPC_S_INVALID_BINDING);
  1443. CASE_OF(RPC_S_PROTSEQ_NOT_SUPPORTED);
  1444. CASE_OF(RPC_S_INVALID_RPC_PROTSEQ);
  1445. CASE_OF(RPC_S_INVALID_STRING_UUID);
  1446. CASE_OF(RPC_S_INVALID_ENDPOINT_FORMAT);
  1447. CASE_OF(RPC_S_INVALID_NET_ADDR);
  1448. CASE_OF(RPC_S_NO_ENDPOINT_FOUND);
  1449. CASE_OF(RPC_S_INVALID_TIMEOUT);
  1450. CASE_OF(RPC_S_OBJECT_NOT_FOUND);
  1451. CASE_OF(RPC_S_ALREADY_REGISTERED);
  1452. CASE_OF(RPC_S_TYPE_ALREADY_REGISTERED);
  1453. CASE_OF(RPC_S_ALREADY_LISTENING);
  1454. CASE_OF(RPC_S_NO_PROTSEQS_REGISTERED);
  1455. CASE_OF(RPC_S_NOT_LISTENING);
  1456. CASE_OF(RPC_S_UNKNOWN_MGR_TYPE);
  1457. CASE_OF(RPC_S_UNKNOWN_IF);
  1458. CASE_OF(RPC_S_NO_BINDINGS);
  1459. CASE_OF(RPC_S_NO_PROTSEQS);
  1460. CASE_OF(RPC_S_CANT_CREATE_ENDPOINT);
  1461. CASE_OF(RPC_S_OUT_OF_RESOURCES);
  1462. CASE_OF(RPC_S_SERVER_UNAVAILABLE);
  1463. CASE_OF(RPC_S_SERVER_TOO_BUSY);
  1464. CASE_OF(RPC_S_INVALID_NETWORK_OPTIONS);
  1465. CASE_OF(RPC_S_NO_CALL_ACTIVE);
  1466. CASE_OF(RPC_S_CALL_FAILED);
  1467. CASE_OF(RPC_S_CALL_FAILED_DNE);
  1468. CASE_OF(RPC_S_PROTOCOL_ERROR);
  1469. CASE_OF(RPC_S_UNSUPPORTED_TRANS_SYN);
  1470. CASE_OF(RPC_S_UNSUPPORTED_TYPE);
  1471. CASE_OF(RPC_S_INVALID_TAG);
  1472. CASE_OF(RPC_S_INVALID_BOUND);
  1473. CASE_OF(RPC_S_NO_ENTRY_NAME);
  1474. CASE_OF(RPC_S_INVALID_NAME_SYNTAX);
  1475. CASE_OF(RPC_S_UNSUPPORTED_NAME_SYNTAX);
  1476. CASE_OF(RPC_S_UUID_NO_ADDRESS);
  1477. CASE_OF(RPC_S_DUPLICATE_ENDPOINT);
  1478. CASE_OF(RPC_S_UNKNOWN_AUTHN_TYPE);
  1479. CASE_OF(RPC_S_MAX_CALLS_TOO_SMALL);
  1480. CASE_OF(RPC_S_STRING_TOO_LONG);
  1481. CASE_OF(RPC_S_PROTSEQ_NOT_FOUND);
  1482. CASE_OF(RPC_S_PROCNUM_OUT_OF_RANGE);
  1483. CASE_OF(RPC_S_BINDING_HAS_NO_AUTH);
  1484. CASE_OF(RPC_S_UNKNOWN_AUTHN_SERVICE);
  1485. CASE_OF(RPC_S_UNKNOWN_AUTHN_LEVEL);
  1486. CASE_OF(RPC_S_INVALID_AUTH_IDENTITY);
  1487. CASE_OF(RPC_S_UNKNOWN_AUTHZ_SERVICE);
  1488. CASE_OF(EPT_S_INVALID_ENTRY);
  1489. CASE_OF(EPT_S_CANT_PERFORM_OP);
  1490. CASE_OF(EPT_S_NOT_REGISTERED);
  1491. CASE_OF(RPC_S_NOTHING_TO_EXPORT);
  1492. CASE_OF(RPC_S_INCOMPLETE_NAME);
  1493. CASE_OF(RPC_S_INVALID_VERS_OPTION);
  1494. CASE_OF(RPC_S_NO_MORE_MEMBERS);
  1495. CASE_OF(RPC_S_NOT_ALL_OBJS_UNEXPORTED);
  1496. CASE_OF(RPC_S_INTERFACE_NOT_FOUND);
  1497. CASE_OF(RPC_S_ENTRY_ALREADY_EXISTS);
  1498. CASE_OF(RPC_S_ENTRY_NOT_FOUND);
  1499. CASE_OF(RPC_S_NAME_SERVICE_UNAVAILABLE);
  1500. CASE_OF(RPC_S_INVALID_NAF_ID);
  1501. CASE_OF(RPC_S_CANNOT_SUPPORT);
  1502. CASE_OF(RPC_S_NO_CONTEXT_AVAILABLE);
  1503. CASE_OF(RPC_S_INTERNAL_ERROR);
  1504. CASE_OF(RPC_S_ZERO_DIVIDE);
  1505. CASE_OF(RPC_S_ADDRESS_ERROR);
  1506. CASE_OF(RPC_S_FP_DIV_ZERO);
  1507. CASE_OF(RPC_S_FP_UNDERFLOW);
  1508. CASE_OF(RPC_S_FP_OVERFLOW);
  1509. CASE_OF(RPC_X_NO_MORE_ENTRIES);
  1510. CASE_OF(RPC_X_SS_CHAR_TRANS_OPEN_FAIL);
  1511. CASE_OF(RPC_X_SS_CHAR_TRANS_SHORT_FILE);
  1512. CASE_OF(RPC_X_SS_IN_NULL_CONTEXT);
  1513. CASE_OF(RPC_X_SS_CONTEXT_DAMAGED);
  1514. CASE_OF(RPC_X_SS_HANDLES_MISMATCH);
  1515. CASE_OF(RPC_X_SS_CANNOT_GET_CALL_HANDLE);
  1516. CASE_OF(RPC_X_NULL_REF_POINTER);
  1517. CASE_OF(RPC_X_ENUM_VALUE_OUT_OF_RANGE);
  1518. CASE_OF(RPC_X_BYTE_COUNT_TOO_SMALL);
  1519. CASE_OF(RPC_X_BAD_STUB_DATA);
  1520. //
  1521. // WINHTTP errors
  1522. //
  1523. CASE_OF(ERROR_WINHTTP_OUT_OF_HANDLES);
  1524. CASE_OF(ERROR_WINHTTP_TIMEOUT);
  1525. CASE_OF(ERROR_WINHTTP_INTERNAL_ERROR);
  1526. CASE_OF(ERROR_WINHTTP_INVALID_URL);
  1527. CASE_OF(ERROR_WINHTTP_UNRECOGNIZED_SCHEME);
  1528. CASE_OF(ERROR_WINHTTP_NAME_NOT_RESOLVED);
  1529. CASE_OF(ERROR_WINHTTP_INVALID_OPTION);
  1530. CASE_OF(ERROR_WINHTTP_OPTION_NOT_SETTABLE);
  1531. CASE_OF(ERROR_WINHTTP_SHUTDOWN);
  1532. CASE_OF(ERROR_WINHTTP_INCORRECT_PASSWORD);
  1533. CASE_OF(ERROR_WINHTTP_LOGIN_FAILURE);
  1534. CASE_OF(ERROR_WINHTTP_OPERATION_CANCELLED);
  1535. CASE_OF(ERROR_WINHTTP_INCORRECT_HANDLE_TYPE);
  1536. CASE_OF(ERROR_WINHTTP_INCORRECT_HANDLE_STATE);
  1537. CASE_OF(ERROR_WINHTTP_CANNOT_CONNECT);
  1538. CASE_OF(ERROR_WINHTTP_CONNECTION_ERROR);
  1539. CASE_OF(ERROR_WINHTTP_FORCE_RETRY);
  1540. CASE_OF(ERROR_WINHTTP_CLIENT_AUTH_CERT_NEEDED);
  1541. CASE_OF(ERROR_WINHTTP_NOT_INITIALIZED);
  1542. CASE_OF(ERROR_WINHTTP_SECURE_FAILURE);
  1543. CASE_OF(ERROR_HTTP_HEADER_NOT_FOUND);
  1544. CASE_OF(ERROR_HTTP_INVALID_SERVER_RESPONSE);
  1545. CASE_OF(ERROR_HTTP_INVALID_QUERY_REQUEST);
  1546. CASE_OF(ERROR_HTTP_HEADER_ALREADY_EXISTS);
  1547. CASE_OF(ERROR_HTTP_REDIRECT_FAILED);
  1548. CASE_OF(ERROR_HTTP_NOT_REDIRECTED);
  1549. //
  1550. // SSPI errors
  1551. //
  1552. CASE_OF(SEC_E_INSUFFICIENT_MEMORY);
  1553. CASE_OF(SEC_E_INVALID_HANDLE);
  1554. CASE_OF(SEC_E_UNSUPPORTED_FUNCTION);
  1555. CASE_OF(SEC_E_TARGET_UNKNOWN);
  1556. CASE_OF(SEC_E_INTERNAL_ERROR);
  1557. CASE_OF(SEC_E_SECPKG_NOT_FOUND);
  1558. CASE_OF(SEC_E_NOT_OWNER);
  1559. CASE_OF(SEC_E_CANNOT_INSTALL);
  1560. CASE_OF(SEC_E_INVALID_TOKEN);
  1561. CASE_OF(SEC_E_CANNOT_PACK);
  1562. CASE_OF(SEC_E_QOP_NOT_SUPPORTED);
  1563. CASE_OF(SEC_E_NO_IMPERSONATION);
  1564. CASE_OF(SEC_E_LOGON_DENIED);
  1565. CASE_OF(SEC_E_UNKNOWN_CREDENTIALS);
  1566. CASE_OF(SEC_E_NO_CREDENTIALS);
  1567. CASE_OF(SEC_E_MESSAGE_ALTERED);
  1568. CASE_OF(SEC_E_OUT_OF_SEQUENCE);
  1569. CASE_OF(SEC_E_NO_AUTHENTICATING_AUTHORITY);
  1570. CASE_OF(SEC_I_CONTINUE_NEEDED);
  1571. CASE_OF(SEC_I_COMPLETE_NEEDED);
  1572. CASE_OF(SEC_I_COMPLETE_AND_CONTINUE);
  1573. CASE_OF(SEC_I_LOCAL_LOGON);
  1574. CASE_OF(SEC_E_BAD_PKGID);
  1575. CASE_OF(SEC_E_CONTEXT_EXPIRED);
  1576. CASE_OF(SEC_E_INCOMPLETE_MESSAGE);
  1577. //
  1578. // WINSOCK errors
  1579. //
  1580. CASE_OF(WSAEINTR);
  1581. CASE_OF(WSAEBADF);
  1582. CASE_OF(WSAEACCES);
  1583. CASE_OF(WSAEFAULT);
  1584. CASE_OF(WSAEINVAL);
  1585. CASE_OF(WSAEMFILE);
  1586. CASE_OF(WSAEWOULDBLOCK);
  1587. CASE_OF(WSAEINPROGRESS);
  1588. CASE_OF(WSAEALREADY);
  1589. CASE_OF(WSAENOTSOCK);
  1590. CASE_OF(WSAEDESTADDRREQ);
  1591. CASE_OF(WSAEMSGSIZE);
  1592. CASE_OF(WSAEPROTOTYPE);
  1593. CASE_OF(WSAENOPROTOOPT);
  1594. CASE_OF(WSAEPROTONOSUPPORT);
  1595. CASE_OF(WSAESOCKTNOSUPPORT);
  1596. CASE_OF(WSAEOPNOTSUPP);
  1597. CASE_OF(WSAEPFNOSUPPORT);
  1598. CASE_OF(WSAEAFNOSUPPORT);
  1599. CASE_OF(WSAEADDRINUSE);
  1600. CASE_OF(WSAEADDRNOTAVAIL);
  1601. CASE_OF(WSAENETDOWN);
  1602. CASE_OF(WSAENETUNREACH);
  1603. CASE_OF(WSAENETRESET);
  1604. CASE_OF(WSAECONNABORTED);
  1605. CASE_OF(WSAECONNRESET);
  1606. CASE_OF(WSAENOBUFS);
  1607. CASE_OF(WSAEISCONN);
  1608. CASE_OF(WSAENOTCONN);
  1609. CASE_OF(WSAESHUTDOWN);
  1610. CASE_OF(WSAETOOMANYREFS);
  1611. CASE_OF(WSAETIMEDOUT);
  1612. CASE_OF(WSAECONNREFUSED);
  1613. CASE_OF(WSAELOOP);
  1614. CASE_OF(WSAENAMETOOLONG);
  1615. CASE_OF(WSAEHOSTDOWN);
  1616. CASE_OF(WSAEHOSTUNREACH);
  1617. CASE_OF(WSAENOTEMPTY);
  1618. CASE_OF(WSAEPROCLIM);
  1619. CASE_OF(WSAEUSERS);
  1620. CASE_OF(WSAEDQUOT);
  1621. CASE_OF(WSAESTALE);
  1622. CASE_OF(WSAEREMOTE);
  1623. CASE_OF(WSAEDISCON);
  1624. CASE_OF(WSASYSNOTREADY);
  1625. CASE_OF(WSAVERNOTSUPPORTED);
  1626. CASE_OF(WSANOTINITIALISED);
  1627. CASE_OF(WSAHOST_NOT_FOUND);
  1628. CASE_OF(WSATRY_AGAIN);
  1629. CASE_OF(WSANO_RECOVERY);
  1630. CASE_OF(WSANO_DATA);
  1631. #if 0
  1632. //
  1633. // RAS errors
  1634. //
  1635. CASE_OF(PENDING);
  1636. CASE_OF(ERROR_INVALID_PORT_HANDLE);
  1637. CASE_OF(ERROR_PORT_ALREADY_OPEN);
  1638. CASE_OF(ERROR_BUFFER_TOO_SMALL);
  1639. CASE_OF(ERROR_WRONG_INFO_SPECIFIED);
  1640. CASE_OF(ERROR_CANNOT_SET_PORT_INFO);
  1641. CASE_OF(ERROR_PORT_NOT_CONNECTED);
  1642. CASE_OF(ERROR_EVENT_INVALID);
  1643. CASE_OF(ERROR_DEVICE_DOES_NOT_EXIST);
  1644. CASE_OF(ERROR_BUFFER_INVALID);
  1645. CASE_OF(ERROR_ROUTE_NOT_AVAILABLE);
  1646. CASE_OF(ERROR_ROUTE_NOT_ALLOCATED);
  1647. CASE_OF(ERROR_INVALID_COMPRESSION_SPECIFIED);
  1648. CASE_OF(ERROR_OUT_OF_BUFFERS);
  1649. CASE_OF(ERROR_PORT_NOT_FOUND);
  1650. CASE_OF(ERROR_ASYNC_REQUEST_PENDING);
  1651. CASE_OF(ERROR_ALREADY_DISCONNECTING);
  1652. CASE_OF(ERROR_PORT_NOT_OPEN);
  1653. CASE_OF(ERROR_PORT_DISCONNECTED);
  1654. CASE_OF(ERROR_NO_ENDPOINTS);
  1655. CASE_OF(ERROR_CANNOT_OPEN_PHONEBOOK);
  1656. CASE_OF(ERROR_CANNOT_LOAD_PHONEBOOK);
  1657. CASE_OF(ERROR_CANNOT_FIND_PHONEBOOK_ENTRY);
  1658. CASE_OF(ERROR_CANNOT_WRITE_PHONEBOOK);
  1659. CASE_OF(ERROR_CORRUPT_PHONEBOOK);
  1660. CASE_OF(ERROR_CANNOT_LOAD_STRING);
  1661. CASE_OF(ERROR_KEY_NOT_FOUND);
  1662. CASE_OF(ERROR_DISCONNECTION);
  1663. CASE_OF(ERROR_REMOTE_DISCONNECTION);
  1664. CASE_OF(ERROR_HARDWARE_FAILURE);
  1665. CASE_OF(ERROR_USER_DISCONNECTION);
  1666. CASE_OF(ERROR_INVALID_SIZE);
  1667. CASE_OF(ERROR_PORT_NOT_AVAILABLE);
  1668. CASE_OF(ERROR_CANNOT_PROJECT_CLIENT);
  1669. CASE_OF(ERROR_UNKNOWN);
  1670. CASE_OF(ERROR_WRONG_DEVICE_ATTACHED);
  1671. CASE_OF(ERROR_BAD_STRING);
  1672. CASE_OF(ERROR_REQUEST_TIMEOUT);
  1673. CASE_OF(ERROR_CANNOT_GET_LANA);
  1674. CASE_OF(ERROR_NETBIOS_ERROR);
  1675. CASE_OF(ERROR_SERVER_OUT_OF_RESOURCES);
  1676. CASE_OF(ERROR_NAME_EXISTS_ON_NET);
  1677. CASE_OF(ERROR_SERVER_GENERAL_NET_FAILURE);
  1678. CASE_OF(WARNING_MSG_ALIAS_NOT_ADDED);
  1679. CASE_OF(ERROR_AUTH_INTERNAL);
  1680. CASE_OF(ERROR_RESTRICTED_LOGON_HOURS);
  1681. CASE_OF(ERROR_ACCT_DISABLED);
  1682. CASE_OF(ERROR_PASSWD_EXPIRED);
  1683. CASE_OF(ERROR_NO_DIALIN_PERMISSION);
  1684. CASE_OF(ERROR_SERVER_NOT_RESPONDING);
  1685. CASE_OF(ERROR_FROM_DEVICE);
  1686. CASE_OF(ERROR_UNRECOGNIZED_RESPONSE);
  1687. CASE_OF(ERROR_MACRO_NOT_FOUND);
  1688. CASE_OF(ERROR_MACRO_NOT_DEFINED);
  1689. CASE_OF(ERROR_MESSAGE_MACRO_NOT_FOUND);
  1690. CASE_OF(ERROR_DEFAULTOFF_MACRO_NOT_FOUND);
  1691. CASE_OF(ERROR_FILE_COULD_NOT_BE_OPENED);
  1692. CASE_OF(ERROR_DEVICENAME_TOO_LONG);
  1693. CASE_OF(ERROR_DEVICENAME_NOT_FOUND);
  1694. CASE_OF(ERROR_NO_RESPONSES);
  1695. CASE_OF(ERROR_NO_COMMAND_FOUND);
  1696. CASE_OF(ERROR_WRONG_KEY_SPECIFIED);
  1697. CASE_OF(ERROR_UNKNOWN_DEVICE_TYPE);
  1698. CASE_OF(ERROR_ALLOCATING_MEMORY);
  1699. CASE_OF(ERROR_PORT_NOT_CONFIGURED);
  1700. CASE_OF(ERROR_DEVICE_NOT_READY);
  1701. CASE_OF(ERROR_READING_INI_FILE);
  1702. CASE_OF(ERROR_NO_CONNECTION);
  1703. CASE_OF(ERROR_BAD_USAGE_IN_INI_FILE);
  1704. CASE_OF(ERROR_READING_SECTIONNAME);
  1705. CASE_OF(ERROR_READING_DEVICETYPE);
  1706. CASE_OF(ERROR_READING_DEVICENAME);
  1707. CASE_OF(ERROR_READING_USAGE);
  1708. CASE_OF(ERROR_READING_MAXCONNECTBPS);
  1709. CASE_OF(ERROR_READING_MAXCARRIERBPS);
  1710. CASE_OF(ERROR_LINE_BUSY);
  1711. CASE_OF(ERROR_VOICE_ANSWER);
  1712. CASE_OF(ERROR_NO_ANSWER);
  1713. CASE_OF(ERROR_NO_CARRIER);
  1714. CASE_OF(ERROR_NO_DIALTONE);
  1715. CASE_OF(ERROR_IN_COMMAND);
  1716. CASE_OF(ERROR_WRITING_SECTIONNAME);
  1717. CASE_OF(ERROR_WRITING_DEVICETYPE);
  1718. CASE_OF(ERROR_WRITING_DEVICENAME);
  1719. CASE_OF(ERROR_WRITING_MAXCONNECTBPS);
  1720. CASE_OF(ERROR_WRITING_MAXCARRIERBPS);
  1721. CASE_OF(ERROR_WRITING_USAGE);
  1722. CASE_OF(ERROR_WRITING_DEFAULTOFF);
  1723. CASE_OF(ERROR_READING_DEFAULTOFF);
  1724. CASE_OF(ERROR_EMPTY_INI_FILE);
  1725. CASE_OF(ERROR_AUTHENTICATION_FAILURE);
  1726. CASE_OF(ERROR_PORT_OR_DEVICE);
  1727. CASE_OF(ERROR_NOT_BINARY_MACRO);
  1728. CASE_OF(ERROR_DCB_NOT_FOUND);
  1729. CASE_OF(ERROR_STATE_MACHINES_NOT_STARTED);
  1730. CASE_OF(ERROR_STATE_MACHINES_ALREADY_STARTED);
  1731. CASE_OF(ERROR_PARTIAL_RESPONSE_LOOPING);
  1732. CASE_OF(ERROR_UNKNOWN_RESPONSE_KEY);
  1733. CASE_OF(ERROR_RECV_BUF_FULL);
  1734. CASE_OF(ERROR_CMD_TOO_LONG);
  1735. CASE_OF(ERROR_UNSUPPORTED_BPS);
  1736. CASE_OF(ERROR_UNEXPECTED_RESPONSE);
  1737. CASE_OF(ERROR_INTERACTIVE_MODE);
  1738. CASE_OF(ERROR_BAD_CALLBACK_NUMBER);
  1739. CASE_OF(ERROR_INVALID_AUTH_STATE);
  1740. CASE_OF(ERROR_WRITING_INITBPS);
  1741. CASE_OF(ERROR_X25_DIAGNOSTIC);
  1742. CASE_OF(ERROR_ACCT_EXPIRED);
  1743. CASE_OF(ERROR_CHANGING_PASSWORD);
  1744. CASE_OF(ERROR_OVERRUN);
  1745. CASE_OF(ERROR_RASMAN_CANNOT_INITIALIZE);
  1746. CASE_OF(ERROR_BIPLEX_PORT_NOT_AVAILABLE);
  1747. CASE_OF(ERROR_NO_ACTIVE_ISDN_LINES);
  1748. CASE_OF(ERROR_NO_ISDN_CHANNELS_AVAILABLE);
  1749. CASE_OF(ERROR_TOO_MANY_LINE_ERRORS);
  1750. CASE_OF(ERROR_IP_CONFIGURATION);
  1751. CASE_OF(ERROR_NO_IP_ADDRESSES);
  1752. CASE_OF(ERROR_PPP_TIMEOUT);
  1753. CASE_OF(ERROR_PPP_REMOTE_TERMINATED);
  1754. CASE_OF(ERROR_PPP_NO_PROTOCOLS_CONFIGURED);
  1755. CASE_OF(ERROR_PPP_NO_RESPONSE);
  1756. CASE_OF(ERROR_PPP_INVALID_PACKET);
  1757. CASE_OF(ERROR_PHONE_NUMBER_TOO_LONG);
  1758. CASE_OF(ERROR_IPXCP_NO_DIALOUT_CONFIGURED);
  1759. CASE_OF(ERROR_IPXCP_NO_DIALIN_CONFIGURED);
  1760. CASE_OF(ERROR_IPXCP_DIALOUT_ALREADY_ACTIVE);
  1761. CASE_OF(ERROR_ACCESSING_TCPCFGDLL);
  1762. CASE_OF(ERROR_NO_IP_RAS_ADAPTER);
  1763. CASE_OF(ERROR_SLIP_REQUIRES_IP);
  1764. CASE_OF(ERROR_PROJECTION_NOT_COMPLETE);
  1765. CASE_OF(ERROR_PROTOCOL_NOT_CONFIGURED);
  1766. CASE_OF(ERROR_PPP_NOT_CONVERGING);
  1767. CASE_OF(ERROR_PPP_CP_REJECTED);
  1768. CASE_OF(ERROR_PPP_LCP_TERMINATED);
  1769. CASE_OF(ERROR_PPP_REQUIRED_ADDRESS_REJECTED);
  1770. CASE_OF(ERROR_PPP_NCP_TERMINATED);
  1771. CASE_OF(ERROR_PPP_LOOPBACK_DETECTED);
  1772. CASE_OF(ERROR_PPP_NO_ADDRESS_ASSIGNED);
  1773. CASE_OF(ERROR_CANNOT_USE_LOGON_CREDENTIALS);
  1774. CASE_OF(ERROR_TAPI_CONFIGURATION);
  1775. CASE_OF(ERROR_NO_LOCAL_ENCRYPTION);
  1776. CASE_OF(ERROR_NO_REMOTE_ENCRYPTION);
  1777. CASE_OF(ERROR_REMOTE_REQUIRES_ENCRYPTION);
  1778. CASE_OF(ERROR_IPXCP_NET_NUMBER_CONFLICT);
  1779. CASE_OF(ERROR_INVALID_SMM);
  1780. CASE_OF(ERROR_SMM_UNINITIALIZED);
  1781. CASE_OF(ERROR_NO_MAC_FOR_PORT);
  1782. CASE_OF(ERROR_SMM_TIMEOUT);
  1783. CASE_OF(ERROR_BAD_PHONE_NUMBER);
  1784. CASE_OF(ERROR_WRONG_MODULE);
  1785. CASE_OF(ERROR_INVALID_CALLBACK_NUMBER);
  1786. CASE_OF(ERROR_SCRIPT_SYNTAX);
  1787. #endif // 0
  1788. default:
  1789. return "?";
  1790. }
  1791. }
  1792. LPSTR
  1793. InternetMapStatus(
  1794. IN DWORD Status
  1795. )
  1796. /*++
  1797. Routine Description:
  1798. Convert WINHTTP_CALLBACK_STATUS_ value to symbolic name
  1799. Arguments:
  1800. Status - to map
  1801. Return Value:
  1802. LPSTR - pointer to symbolic name, or "?" if unknown
  1803. --*/
  1804. {
  1805. switch (Status) {
  1806. CASE_OF(WINHTTP_CALLBACK_STATUS_RESOLVING_NAME);
  1807. CASE_OF(WINHTTP_CALLBACK_STATUS_NAME_RESOLVED);
  1808. CASE_OF(WINHTTP_CALLBACK_STATUS_CONNECTING_TO_SERVER);
  1809. CASE_OF(WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER);
  1810. CASE_OF(WINHTTP_CALLBACK_STATUS_SENDING_REQUEST);
  1811. CASE_OF(WINHTTP_CALLBACK_STATUS_REQUEST_SENT);
  1812. CASE_OF(WINHTTP_CALLBACK_STATUS_RECEIVING_RESPONSE);
  1813. CASE_OF(WINHTTP_CALLBACK_STATUS_RESPONSE_RECEIVED);
  1814. CASE_OF(WINHTTP_CALLBACK_STATUS_CLOSING_CONNECTION);
  1815. CASE_OF(WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED);
  1816. CASE_OF(WINHTTP_CALLBACK_STATUS_HANDLE_CREATED);
  1817. CASE_OF(WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING);
  1818. CASE_OF(WINHTTP_CALLBACK_STATUS_REQUEST_COMPLETE);
  1819. CASE_OF(WINHTTP_CALLBACK_STATUS_REDIRECT);
  1820. CASE_OF(WINHTTP_CALLBACK_STATUS_INTERMEDIATE_RESPONSE);
  1821. CASE_OF(WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE);
  1822. CASE_OF(WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE);
  1823. CASE_OF(WINHTTP_CALLBACK_STATUS_READ_COMPLETE);
  1824. CASE_OF(WINHTTP_CALLBACK_STATUS_WRITE_COMPLETE);
  1825. CASE_OF(WINHTTP_CALLBACK_STATUS_REQUEST_ERROR);
  1826. }
  1827. return "?";
  1828. }
  1829. LPSTR
  1830. InternetMapSSPIError(
  1831. IN DWORD Status
  1832. )
  1833. /*++
  1834. Routine Description:
  1835. Convert a SSL/PCT SSPI Error Code to a string.
  1836. Arguments:
  1837. Status - to map
  1838. Return Value:
  1839. LPSTR - pointer to symbolic name, or "?" if unknown
  1840. --*/
  1841. {
  1842. switch (Status) {
  1843. CASE_OF(STATUS_SUCCESS);
  1844. CASE_OF(SEC_E_INSUFFICIENT_MEMORY );
  1845. CASE_OF(SEC_E_INVALID_HANDLE );
  1846. CASE_OF(SEC_E_UNSUPPORTED_FUNCTION );
  1847. CASE_OF(SEC_E_TARGET_UNKNOWN );
  1848. CASE_OF(SEC_E_INTERNAL_ERROR );
  1849. CASE_OF(SEC_E_SECPKG_NOT_FOUND );
  1850. CASE_OF(SEC_E_NOT_OWNER );
  1851. CASE_OF(SEC_E_CANNOT_INSTALL );
  1852. CASE_OF(SEC_E_INVALID_TOKEN );
  1853. CASE_OF(SEC_E_CANNOT_PACK );
  1854. CASE_OF(SEC_E_QOP_NOT_SUPPORTED );
  1855. CASE_OF(SEC_E_NO_IMPERSONATION );
  1856. CASE_OF(SEC_E_LOGON_DENIED );
  1857. CASE_OF(SEC_E_UNKNOWN_CREDENTIALS );
  1858. CASE_OF(SEC_E_NO_CREDENTIALS );
  1859. CASE_OF(SEC_E_MESSAGE_ALTERED );
  1860. CASE_OF(SEC_E_OUT_OF_SEQUENCE );
  1861. CASE_OF(SEC_E_NO_AUTHENTICATING_AUTHORITY);
  1862. CASE_OF(SEC_I_CONTINUE_NEEDED );
  1863. CASE_OF(SEC_I_COMPLETE_NEEDED );
  1864. CASE_OF(SEC_I_COMPLETE_AND_CONTINUE );
  1865. CASE_OF(SEC_I_LOCAL_LOGON );
  1866. CASE_OF(SEC_E_BAD_PKGID );
  1867. CASE_OF(SEC_E_CONTEXT_EXPIRED );
  1868. CASE_OF(SEC_E_INCOMPLETE_MESSAGE );
  1869. // CASE_OF(SEC_E_NO_SPM );
  1870. // CASE_OF(SEC_E_NOT_SUPPORTED );
  1871. }
  1872. return "?";
  1873. }
  1874. LPSTR
  1875. InternetMapHttpOption(
  1876. IN DWORD Option
  1877. )
  1878. /*++
  1879. Routine Description:
  1880. Convert HTTP_QUERY_ option value to symbolic name
  1881. Arguments:
  1882. Option - to map
  1883. Return Value:
  1884. LPSTR - pointer to symbolic name, or "?" if unknown
  1885. --*/
  1886. {
  1887. switch (Option) {
  1888. CASE_OF(HTTP_QUERY_MIME_VERSION); // 0
  1889. CASE_OF(HTTP_QUERY_CONTENT_TYPE); // 1
  1890. CASE_OF(HTTP_QUERY_CONTENT_TRANSFER_ENCODING); // 2
  1891. CASE_OF(HTTP_QUERY_CONTENT_ID); // 3
  1892. CASE_OF(HTTP_QUERY_CONTENT_DESCRIPTION); // 4
  1893. CASE_OF(HTTP_QUERY_CONTENT_LENGTH); // 5
  1894. CASE_OF(HTTP_QUERY_CONTENT_LANGUAGE); // 6
  1895. CASE_OF(HTTP_QUERY_ALLOW); // 7
  1896. CASE_OF(HTTP_QUERY_PUBLIC); // 8
  1897. CASE_OF(HTTP_QUERY_DATE); // 9
  1898. CASE_OF(HTTP_QUERY_EXPIRES); // 10
  1899. CASE_OF(HTTP_QUERY_LAST_MODIFIED); // 11
  1900. CASE_OF(HTTP_QUERY_MESSAGE_ID); // 12
  1901. CASE_OF(HTTP_QUERY_URI); // 13
  1902. CASE_OF(HTTP_QUERY_DERIVED_FROM); // 14
  1903. CASE_OF(HTTP_QUERY_COST); // 15
  1904. CASE_OF(HTTP_QUERY_LINK); // 16
  1905. CASE_OF(HTTP_QUERY_PRAGMA); // 17
  1906. CASE_OF(HTTP_QUERY_VERSION); // 18
  1907. CASE_OF(HTTP_QUERY_STATUS_CODE); // 19
  1908. CASE_OF(HTTP_QUERY_STATUS_TEXT); // 20
  1909. CASE_OF(HTTP_QUERY_RAW_HEADERS); // 21
  1910. CASE_OF(HTTP_QUERY_RAW_HEADERS_CRLF); // 22
  1911. CASE_OF(HTTP_QUERY_CONNECTION); // 23
  1912. CASE_OF(HTTP_QUERY_ACCEPT); // 24
  1913. CASE_OF(HTTP_QUERY_ACCEPT_CHARSET); // 25
  1914. CASE_OF(HTTP_QUERY_ACCEPT_ENCODING); // 26
  1915. CASE_OF(HTTP_QUERY_ACCEPT_LANGUAGE); // 27
  1916. CASE_OF(HTTP_QUERY_AUTHORIZATION); // 28
  1917. CASE_OF(HTTP_QUERY_CONTENT_ENCODING); // 29
  1918. CASE_OF(HTTP_QUERY_FORWARDED); // 30
  1919. CASE_OF(HTTP_QUERY_FROM); // 31
  1920. CASE_OF(HTTP_QUERY_IF_MODIFIED_SINCE); // 32
  1921. CASE_OF(HTTP_QUERY_LOCATION); // 33
  1922. CASE_OF(HTTP_QUERY_ORIG_URI); // 34
  1923. CASE_OF(HTTP_QUERY_REFERER); // 35
  1924. CASE_OF(HTTP_QUERY_RETRY_AFTER); // 36
  1925. CASE_OF(HTTP_QUERY_SERVER); // 37
  1926. CASE_OF(HTTP_QUERY_TITLE); // 38
  1927. CASE_OF(HTTP_QUERY_USER_AGENT); // 39
  1928. CASE_OF(HTTP_QUERY_WWW_AUTHENTICATE); // 40
  1929. CASE_OF(HTTP_QUERY_PROXY_AUTHENTICATE); // 41
  1930. CASE_OF(HTTP_QUERY_ACCEPT_RANGES); // 42
  1931. CASE_OF(HTTP_QUERY_SET_COOKIE); // 43
  1932. CASE_OF(HTTP_QUERY_COOKIE); // 44
  1933. CASE_OF(HTTP_QUERY_REQUEST_METHOD); // 45
  1934. CASE_OF(HTTP_QUERY_REFRESH); // 46
  1935. CASE_OF(HTTP_QUERY_CONTENT_DISPOSITION); // 47
  1936. CASE_OF(HTTP_QUERY_AGE); // 48
  1937. CASE_OF(HTTP_QUERY_CACHE_CONTROL); // 49
  1938. CASE_OF(HTTP_QUERY_CONTENT_BASE); // 50
  1939. CASE_OF(HTTP_QUERY_CONTENT_LOCATION); // 51
  1940. CASE_OF(HTTP_QUERY_CONTENT_MD5); // 52
  1941. CASE_OF(HTTP_QUERY_CONTENT_RANGE); // 53
  1942. CASE_OF(HTTP_QUERY_ETAG); // 54
  1943. CASE_OF(HTTP_QUERY_HOST); // 55
  1944. CASE_OF(HTTP_QUERY_IF_MATCH); // 56
  1945. CASE_OF(HTTP_QUERY_IF_NONE_MATCH); // 57
  1946. CASE_OF(HTTP_QUERY_IF_RANGE); // 58
  1947. CASE_OF(HTTP_QUERY_IF_UNMODIFIED_SINCE); // 59
  1948. CASE_OF(HTTP_QUERY_MAX_FORWARDS); // 60
  1949. CASE_OF(HTTP_QUERY_PROXY_AUTHORIZATION); // 61
  1950. CASE_OF(HTTP_QUERY_RANGE); // 62
  1951. CASE_OF(HTTP_QUERY_TRANSFER_ENCODING); // 63
  1952. CASE_OF(HTTP_QUERY_UPGRADE); // 64
  1953. CASE_OF(HTTP_QUERY_VARY); // 65
  1954. CASE_OF(HTTP_QUERY_VIA); // 66
  1955. CASE_OF(HTTP_QUERY_WARNING); // 67
  1956. CASE_OF(HTTP_QUERY_EXPECT); // 68
  1957. CASE_OF(HTTP_QUERY_PROXY_CONNECTION); // 69
  1958. CASE_OF(HTTP_QUERY_UNLESS_MODIFIED_SINCE); // 70
  1959. CASE_OF(HTTP_QUERY_ECHO_REQUEST); // 71
  1960. CASE_OF(HTTP_QUERY_ECHO_REPLY); // 72
  1961. CASE_OF(HTTP_QUERY_ECHO_HEADERS); // 73
  1962. CASE_OF(HTTP_QUERY_ECHO_HEADERS_CRLF); // 74
  1963. CASE_OF(HTTP_QUERY_CUSTOM); // 65535
  1964. }
  1965. return "?";
  1966. }
  1967. LPSTR
  1968. InternetMapHttpState(
  1969. IN WORD State
  1970. )
  1971. /*++
  1972. Routine Description:
  1973. Convert HTTPREQ_STATE_ to symbolic name
  1974. Arguments:
  1975. State - to map
  1976. Return Value:
  1977. LPSTR
  1978. --*/
  1979. {
  1980. switch (State & ~HTTPREQ_FLAG_MASK)
  1981. {
  1982. CASE_OF(HttpRequestStateCreating);
  1983. CASE_OF(HttpRequestStateOpen);
  1984. CASE_OF(HttpRequestStateRequest);
  1985. CASE_OF(HttpRequestStateResponse);
  1986. CASE_OF(HttpRequestStateObjectData);
  1987. CASE_OF(HttpRequestStateError);
  1988. CASE_OF(HttpRequestStateClosing);
  1989. CASE_OF(HttpRequestStateReopen);
  1990. }
  1991. return "?";
  1992. }
  1993. LPSTR
  1994. InternetMapHttpStateFlag(
  1995. IN WORD Flag
  1996. )
  1997. /*++
  1998. Routine Description:
  1999. Convert HTTPREQ_STATE_ flag to symbolic name
  2000. Arguments:
  2001. Flag - to map
  2002. Return Value:
  2003. LPSTR
  2004. --*/
  2005. {
  2006. switch (Flag & ~HTTPREQ_FLAG_MASK)
  2007. {
  2008. case HTTPREQ_STATE_ANYTHING_OK:
  2009. return "ANYTHING";
  2010. case HTTPREQ_STATE_CLOSE_OK:
  2011. return "CLOSE";
  2012. case HTTPREQ_STATE_ADD_OK:
  2013. return "ADD";
  2014. case HTTPREQ_STATE_SEND_OK:
  2015. return "SEND";
  2016. case HTTPREQ_STATE_READ_OK:
  2017. return "READ";
  2018. case HTTPREQ_STATE_QUERY_REQUEST_OK:
  2019. return "QUERY_REQUEST";
  2020. case HTTPREQ_STATE_QUERY_RESPONSE_OK:
  2021. return "QUERY_RESPONSE";
  2022. case HTTPREQ_STATE_REUSE_OK:
  2023. return "REUSE";
  2024. }
  2025. return "?";
  2026. }
  2027. LPSTR
  2028. InternetMapAsyncRequest(
  2029. IN AR_TYPE Type
  2030. )
  2031. /*++
  2032. Routine Description:
  2033. Convert AR_TYPE to symbolic name
  2034. Arguments:
  2035. Type - Async request type
  2036. Return Value:
  2037. LPSTR - pointer to symbolic name, or "?" if unknown
  2038. --*/
  2039. {
  2040. switch (Type) {
  2041. CASE_OF(AR_INTERNET_CONNECT);
  2042. CASE_OF(AR_INTERNET_OPEN_URL);
  2043. CASE_OF(AR_INTERNET_READ_FILE);
  2044. CASE_OF(AR_INTERNET_WRITE_FILE);
  2045. CASE_OF(AR_INTERNET_QUERY_DATA_AVAILABLE);
  2046. CASE_OF(AR_INTERNET_FIND_NEXT_FILE);
  2047. CASE_OF(AR_FTP_FIND_FIRST_FILE);
  2048. CASE_OF(AR_FTP_GET_FILE);
  2049. CASE_OF(AR_FTP_PUT_FILE);
  2050. CASE_OF(AR_FTP_DELETE_FILE);
  2051. CASE_OF(AR_FTP_RENAME_FILE);
  2052. CASE_OF(AR_FTP_OPEN_FILE);
  2053. CASE_OF(AR_FTP_CREATE_DIRECTORY);
  2054. CASE_OF(AR_FTP_REMOVE_DIRECTORY);
  2055. CASE_OF(AR_FTP_SET_CURRENT_DIRECTORY);
  2056. CASE_OF(AR_FTP_GET_CURRENT_DIRECTORY);
  2057. CASE_OF(AR_GOPHER_FIND_FIRST_FILE);
  2058. CASE_OF(AR_GOPHER_OPEN_FILE);
  2059. CASE_OF(AR_GOPHER_GET_ATTRIBUTE);
  2060. CASE_OF(AR_HTTP_SEND_REQUEST);
  2061. CASE_OF(AR_HTTP_BEGIN_SEND_REQUEST);
  2062. CASE_OF(AR_HTTP_END_SEND_REQUEST);
  2063. CASE_OF(AR_READ_PREFETCH);
  2064. CASE_OF(AR_SYNC_EVENT);
  2065. CASE_OF(AR_TIMER_EVENT);
  2066. CASE_OF(AR_HTTP_REQUEST1);
  2067. CASE_OF(AR_FILE_IO);
  2068. CASE_OF(AR_INTERNET_READ_FILE_EX);
  2069. }
  2070. return "?";
  2071. }
  2072. LPSTR
  2073. InternetMapHandleType(
  2074. IN DWORD HandleType
  2075. )
  2076. /*++
  2077. Routine Description:
  2078. Map handle type to symbolic name
  2079. Arguments:
  2080. HandleType - from handle object
  2081. Return Value:
  2082. LPSTR
  2083. --*/
  2084. {
  2085. switch (HandleType) {
  2086. CASE_OF(TypeGenericHandle);
  2087. CASE_OF(TypeInternetHandle);
  2088. CASE_OF(TypeFtpConnectHandle);
  2089. CASE_OF(TypeFtpFindHandle);
  2090. CASE_OF(TypeFtpFindHandleHtml);
  2091. CASE_OF(TypeFtpFileHandle);
  2092. CASE_OF(TypeFtpFileHandleHtml);
  2093. CASE_OF(TypeGopherConnectHandle);
  2094. CASE_OF(TypeGopherFindHandle);
  2095. CASE_OF(TypeGopherFindHandleHtml);
  2096. CASE_OF(TypeGopherFileHandle);
  2097. CASE_OF(TypeGopherFileHandleHtml);
  2098. CASE_OF(TypeHttpConnectHandle);
  2099. CASE_OF(TypeHttpRequestHandle);
  2100. CASE_OF(TypeFileRequestHandle);
  2101. CASE_OF(TypeWildHandle);
  2102. }
  2103. return "?";
  2104. }
  2105. LPSTR
  2106. InternetMapScheme(
  2107. IN INTERNET_SCHEME Scheme
  2108. )
  2109. /*++
  2110. Routine Description:
  2111. Maps INTERNET_SCHEME_ to symbolic name
  2112. Arguments:
  2113. Scheme - to map
  2114. Return Value:
  2115. LPSTR
  2116. --*/
  2117. {
  2118. switch (Scheme) {
  2119. CASE_OF(INTERNET_SCHEME_UNKNOWN);
  2120. CASE_OF(INTERNET_SCHEME_DEFAULT);
  2121. CASE_OF(INTERNET_SCHEME_HTTP);
  2122. CASE_OF(INTERNET_SCHEME_HTTPS);
  2123. }
  2124. return "?";
  2125. }
  2126. LPSTR
  2127. InternetMapOpenType(
  2128. IN DWORD OpenType
  2129. )
  2130. /*++
  2131. Routine Description:
  2132. Maps INTERNET_OPEN_TYPE_ to symbolic name
  2133. Arguments:
  2134. OpenType - to map
  2135. Return Value:
  2136. LPSTR
  2137. --*/
  2138. {
  2139. switch (OpenType) {
  2140. CASE_OF(INTERNET_OPEN_TYPE_DIRECT);
  2141. CASE_OF(INTERNET_OPEN_TYPE_PROXY);
  2142. CASE_OF(INTERNET_OPEN_TYPE_PRECONFIG);
  2143. }
  2144. return "?";
  2145. }
  2146. LPSTR
  2147. InternetMapService(
  2148. IN DWORD Service
  2149. )
  2150. /*++
  2151. Routine Description:
  2152. Maps INTERNET_SERVICE_ to symbolic name
  2153. Arguments:
  2154. Service - to map
  2155. Return Value:
  2156. LPSTR
  2157. --*/
  2158. {
  2159. switch (Service)
  2160. {
  2161. CASE_OF(INTERNET_SERVICE_HTTP);
  2162. }
  2163. return "?";
  2164. }
  2165. //
  2166. // private functions
  2167. //
  2168. PRIVATE
  2169. LPSTR
  2170. ExtractFileName(
  2171. IN LPSTR Module,
  2172. OUT LPSTR Buf
  2173. )
  2174. {
  2175. LPSTR filename;
  2176. LPSTR extension;
  2177. int len;
  2178. filename = strrchr(Module, '\\');
  2179. extension = strrchr(Module, '.');
  2180. if (filename) {
  2181. ++filename;
  2182. } else {
  2183. filename = Module;
  2184. }
  2185. if (!extension) {
  2186. extension = filename + strlen(filename);
  2187. }
  2188. len = (int) (extension - filename);
  2189. memcpy(Buf, filename, len);
  2190. Buf[len] = '\0';
  2191. return Buf;
  2192. }
  2193. PRIVATE
  2194. LPSTR
  2195. SetDebugPrefix(
  2196. IN LPSTR Buffer
  2197. )
  2198. {
  2199. LPINTERNET_THREAD_INFO lpThreadInfo = InternetGetThreadInfo();
  2200. //INET_ASSERT(lpThreadInfo != NULL);
  2201. if (!lpThreadInfo) {
  2202. return NULL;
  2203. }
  2204. LPINTERNET_DEBUG_RECORD lpRecord;
  2205. lpRecord = lpThreadInfo->Stack;
  2206. if (InternetDebugControlFlags & DBG_ENTRY_TIME) {
  2207. if ((InternetDebugControlFlags & (DBG_DELTA_TIME | DBG_CUMULATIVE_TIME))
  2208. && lpRecord) {
  2209. DWORD ticks;
  2210. DWORD ticksNow;
  2211. ticksNow = GetTickCountWrap();
  2212. ticks = ticksNow - ((InternetDebugControlFlags & DBG_CUMULATIVE_TIME)
  2213. ? InternetDebugStartTime
  2214. : lpRecord->LastTime);
  2215. Buffer += rsprintf(Buffer,
  2216. "% 5d.%3d ",
  2217. ticks / 1000,
  2218. ticks % 1000
  2219. );
  2220. if (InternetDebugControlFlags & DBG_DELTA_TIME) {
  2221. lpRecord->LastTime = ticksNow;
  2222. }
  2223. } else {
  2224. SYSTEMTIME timeNow;
  2225. InternetDebugGetLocalTime(&timeNow, NULL);
  2226. Buffer += rsprintf(Buffer,
  2227. "%02d:%02d:%02d.%03d ",
  2228. timeNow.wHour,
  2229. timeNow.wMinute,
  2230. timeNow.wSecond,
  2231. timeNow.wMilliseconds
  2232. );
  2233. }
  2234. }
  2235. /*
  2236. if (InternetDebugControlFlags & DBG_LEVEL_INDICATOR) {
  2237. Buffer += rsprintf(Buffer, );
  2238. }
  2239. */
  2240. if (InternetDebugControlFlags & DBG_THREAD_INFO) {
  2241. //
  2242. // thread id
  2243. //
  2244. Buffer += rsprintf(Buffer, "%08x", lpThreadInfo->ThreadId);
  2245. //
  2246. // INTERNET_THREAD_INFO address
  2247. //
  2248. if (InternetDebugControlFlags & DBG_THREAD_INFO_ADR) {
  2249. Buffer += rsprintf(Buffer, ":%08x", lpThreadInfo);
  2250. }
  2251. //
  2252. // ARB address
  2253. //
  2254. //if (InternetDebugControlFlags & DBG_ARB_ADDR) {
  2255. // Buffer += rsprintf(Buffer, ":%08x", lpThreadInfo->lpArb);
  2256. //}
  2257. //
  2258. // FIBER address
  2259. //
  2260. //if (InternetDebugControlFlags & DBG_FIBER_INFO) {
  2261. //
  2262. // LPVOID p;
  2263. //
  2264. // p = (lpThreadInfo->lpArb != NULL)
  2265. // ? lpThreadInfo->lpArb->Header.lpFiber
  2266. // : NULL
  2267. // ;
  2268. // Buffer += rsprintf(Buffer, ":%08x", p);
  2269. //}
  2270. //
  2271. // async ID
  2272. //
  2273. if (InternetDebugControlFlags & DBG_ASYNC_ID) {
  2274. if (lpThreadInfo->IsAsyncWorkerThread) {
  2275. Buffer += rsprintf(Buffer, ":<--->");
  2276. } else if (lpThreadInfo->InCallback) {
  2277. //
  2278. // async worker thread calling back into the app; any WinInet
  2279. // API requests during this time treated as though from the
  2280. // app context
  2281. //
  2282. Buffer += rsprintf(Buffer, ":<c-b>");
  2283. }
  2284. else
  2285. {
  2286. //
  2287. // this is an app thread
  2288. //
  2289. Buffer += rsprintf(Buffer, ":<app>");
  2290. }
  2291. }
  2292. //
  2293. // request handle
  2294. //
  2295. if (InternetDebugControlFlags & DBG_REQUEST_HANDLE) {
  2296. Buffer += rsprintf(Buffer, ":%6X", lpThreadInfo->hObject);
  2297. }
  2298. *Buffer++ = ' ';
  2299. }
  2300. if (InternetDebugControlFlags & DBG_CALL_DEPTH) {
  2301. Buffer += rsprintf(Buffer, "%03d ", lpThreadInfo->CallDepth);
  2302. }
  2303. for (int i = 0; i < lpThreadInfo->IndentIncrement; ++i) {
  2304. *Buffer++ = ' ';
  2305. }
  2306. //
  2307. // if we are not debugging the category - i.e we got here via a requirement
  2308. // to display an error, or we are in a function that does not have a
  2309. // DEBUG_ENTER - then prefix the string with the current function name
  2310. // (obviously misleading if the function doesn't have a DEBUG_ENTER)
  2311. //
  2312. if (lpRecord != NULL) {
  2313. if (!(lpRecord->Category & InternetDebugCategoryFlags)) {
  2314. Buffer += rsprintf(Buffer, "%s(): ", lpRecord->Function);
  2315. }
  2316. }
  2317. return Buffer;
  2318. }
  2319. int dprintf(char * format, ...) {
  2320. va_list args;
  2321. char buf[PRINTF_STACK_BUFFER_LENGTH];
  2322. int n;
  2323. va_start(args, format);
  2324. n = _sprintf(buf, format, args);
  2325. va_end(args);
  2326. OutputDebugString(buf);
  2327. return n;
  2328. }
  2329. LPSTR
  2330. SourceFilename(
  2331. LPSTR Filespec
  2332. )
  2333. {
  2334. if (!Filespec) {
  2335. return "?";
  2336. }
  2337. LPSTR p;
  2338. if (p = strrchr(Filespec, '\\')) {
  2339. //
  2340. // we want e.g. common\debugmem.cxx, but get
  2341. // common\..\win32\debugmem.cxx. Bah!
  2342. //
  2343. //LPSTR q;
  2344. //
  2345. //if (q = strrchr(p - 1, '\\')) {
  2346. // p = q;
  2347. //}
  2348. }
  2349. return p ? p + 1 : Filespec;
  2350. }
  2351. typedef BOOL (* SYMINITIALIZE)(HANDLE, LPSTR, BOOL);
  2352. typedef BOOL (* SYMLOADMODULE)(HANDLE, HANDLE, PSTR, PSTR, DWORD, DWORD);
  2353. typedef BOOL (* SYMGETSYMFROMADDR)(HANDLE, DWORD, PDWORD, PIMAGEHLP_SYMBOL);
  2354. typedef BOOL (* SYMCLEANUP)(HANDLE);
  2355. PRIVATE HMODULE hSymLib = NULL;
  2356. PRIVATE SYMINITIALIZE pSymInitialize = NULL;
  2357. PRIVATE SYMLOADMODULE pSymLoadModule = NULL;
  2358. PRIVATE SYMGETSYMFROMADDR pSymGetSymFromAddr = NULL;
  2359. PRIVATE SYMCLEANUP pSymCleanup = NULL;
  2360. VOID
  2361. InitSymLib(
  2362. VOID
  2363. )
  2364. {
  2365. if (hSymLib == NULL) {
  2366. hSymLib = LoadLibrary("IMAGEHLP.DLL");
  2367. if (hSymLib != NULL) {
  2368. pSymInitialize = (SYMINITIALIZE)GetProcAddress(hSymLib,
  2369. "SymInitialize"
  2370. );
  2371. pSymLoadModule = (SYMLOADMODULE)GetProcAddress(hSymLib,
  2372. "SymLoadModule"
  2373. );
  2374. pSymGetSymFromAddr = (SYMGETSYMFROMADDR)GetProcAddress(hSymLib,
  2375. "SymGetSymFromAddr"
  2376. );
  2377. pSymCleanup = (SYMCLEANUP)GetProcAddress(hSymLib,
  2378. "SymCleanup"
  2379. );
  2380. if (!pSymInitialize
  2381. || !pSymLoadModule
  2382. || !pSymGetSymFromAddr
  2383. || !pSymCleanup) {
  2384. FreeLibrary(hSymLib);
  2385. hSymLib = NULL;
  2386. pSymInitialize = NULL;
  2387. pSymLoadModule = NULL;
  2388. pSymGetSymFromAddr = NULL;
  2389. pSymCleanup = NULL;
  2390. return;
  2391. }
  2392. }
  2393. pSymInitialize(GetCurrentProcess(), NULL, FALSE);
  2394. //SymInitialize(GetCurrentProcess(), NULL, TRUE);
  2395. pSymLoadModule(GetCurrentProcess(), NULL, "WININET.DLL", "WININET", 0, 0);
  2396. }
  2397. }
  2398. VOID
  2399. TermSymLib(
  2400. VOID
  2401. )
  2402. {
  2403. if (pSymCleanup) {
  2404. pSymCleanup(GetCurrentProcess());
  2405. FreeLibrary(hSymLib);
  2406. }
  2407. }
  2408. LPSTR
  2409. GetDebugSymbol(
  2410. DWORD Address,
  2411. LPDWORD Offset
  2412. )
  2413. {
  2414. *Offset = Address;
  2415. if (!pSymGetSymFromAddr) {
  2416. return "";
  2417. }
  2418. //
  2419. // BUGBUG - only one caller at a time please
  2420. //
  2421. static char symBuf[512];
  2422. //((PIMAGEHLP_SYMBOL)symBuf)->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL);
  2423. ((PIMAGEHLP_SYMBOL)symBuf)->SizeOfStruct = sizeof(symBuf);
  2424. ((PIMAGEHLP_SYMBOL)symBuf)->MaxNameLength = sizeof(symBuf) - sizeof(IMAGEHLP_SYMBOL);
  2425. if (!pSymGetSymFromAddr(GetCurrentProcess(),
  2426. Address,
  2427. Offset,
  2428. (PIMAGEHLP_SYMBOL)symBuf)) {
  2429. ((PIMAGEHLP_SYMBOL)symBuf)->Name[0] = '\0';
  2430. }
  2431. return ((PIMAGEHLP_SYMBOL)symBuf)->Name;
  2432. }
  2433. #ifndef DONT_RIP
  2434. BOOL fRip = TRUE;
  2435. #else
  2436. BOOL fRip = FALSE;
  2437. #endif
  2438. #define _TEXTW(x) L##x
  2439. #define TEXTW(x) _TEXTW(x)
  2440. #define SZ_MODULE "WINHTTP5"
  2441. #define ARRAYSIZE(pArray) (sizeof(pArray)/sizeof(pArray[0]))
  2442. EXTERN_C const CHAR FAR c_szRipNoFn[] = SZ_MODULE " RIP at %s, line %d: (%s)\r\n";
  2443. EXTERN_C const WCHAR FAR c_wszRipNoFn[] = TEXTW(SZ_MODULE) L" RIP at %s, line %d: (%s)\r\n";
  2444. static
  2445. LPCSTR
  2446. _PathFindFileNameA(
  2447. LPCSTR pPath)
  2448. {
  2449. LPCSTR pT;
  2450. for (pT = pPath; *pPath; pPath = CharNextA(pPath)) {
  2451. if ((pPath[0] == '\\' || pPath[0] == ':' || pPath[0] == '/')
  2452. && pPath[1] && pPath[1] != '\\' && pPath[1] != '/')
  2453. pT = pPath + 1;
  2454. }
  2455. return pT;
  2456. }
  2457. static
  2458. LPCWSTR
  2459. _PathFindFileNameW(
  2460. LPCWSTR pPath)
  2461. {
  2462. LPCWSTR pT;
  2463. for (pT = pPath; *pPath; pPath++) {
  2464. if ((pPath[0] == TEXTW('\\') || pPath[0] == TEXTW(':') || pPath[0] == TEXTW('/'))
  2465. && pPath[1] && pPath[1] != TEXTW('\\') && pPath[1] != TEXTW('/'))
  2466. pT = pPath + 1;
  2467. }
  2468. return pT;
  2469. }
  2470. /*----------------------------------------------------------
  2471. Purpose: This function converts a multi-byte string to a
  2472. wide-char string.
  2473. If pszBuf is non-NULL and the converted string can fit in
  2474. pszBuf, then *ppszWide will point to the given buffer.
  2475. Otherwise, this function will allocate a buffer that can
  2476. hold the converted string.
  2477. If pszAnsi is NULL, then *ppszWide will be freed. Note
  2478. that pszBuf must be the same pointer between the call
  2479. that converted the string and the call that frees the
  2480. string.
  2481. Returns: TRUE
  2482. FALSE (if out of memory)
  2483. */
  2484. BOOL
  2485. UnicodeFromAnsi(
  2486. LPWSTR * ppwszWide,
  2487. LPCSTR pszAnsi, // NULL to clean up
  2488. LPWSTR pwszBuf,
  2489. int cchBuf)
  2490. {
  2491. BOOL bRet;
  2492. // Convert the string?
  2493. if (pszAnsi)
  2494. {
  2495. // Yes; determine the converted string length
  2496. int cch;
  2497. LPWSTR pwsz;
  2498. int cchAnsi = lstrlenA(pszAnsi)+1;
  2499. cch = MultiByteToWideChar(CP_ACP, 0, pszAnsi, cchAnsi, NULL, 0);
  2500. // String too big, or is there no buffer?
  2501. if (cch > cchBuf || NULL == pwszBuf)
  2502. {
  2503. // Yes; allocate space
  2504. cchBuf = cch + 1;
  2505. pwsz = (LPWSTR)LocalAlloc(LPTR, ((cchBuf)*sizeof(WCHAR)));
  2506. }
  2507. else
  2508. {
  2509. // No; use the provided buffer
  2510. pwsz = pwszBuf;
  2511. }
  2512. if (pwsz)
  2513. {
  2514. // Convert the string
  2515. cch = MultiByteToWideChar(CP_ACP, 0, pszAnsi, cchAnsi, pwsz, cchBuf);
  2516. bRet = (0 < cch);
  2517. }
  2518. else
  2519. {
  2520. bRet = FALSE;
  2521. }
  2522. *ppwszWide = pwsz;
  2523. }
  2524. else
  2525. {
  2526. // No; was this buffer allocated?
  2527. if (*ppwszWide && pwszBuf != *ppwszWide)
  2528. {
  2529. // Yes; clean up
  2530. LocalFree((HLOCAL)*ppwszWide);
  2531. *ppwszWide = NULL;
  2532. }
  2533. bRet = TRUE;
  2534. }
  2535. return bRet;
  2536. }
  2537. /*----------------------------------------------------------
  2538. Purpose: Displays a RIP string.
  2539. Returns: TRUE to debugbreak
  2540. */
  2541. BOOL
  2542. CcshellRipA(
  2543. LPCSTR pszFile,
  2544. int line,
  2545. LPCSTR pszEval,
  2546. BOOL bBreakInside)
  2547. {
  2548. BOOL bRet = FALSE;
  2549. LPCSTR psz;
  2550. CHAR ach[256];
  2551. psz = _PathFindFileNameA(pszFile);
  2552. wsprintfA(ach, c_szRipNoFn, psz, line, pszEval);
  2553. OutputDebugStringA(ach);
  2554. if (fRip)
  2555. {
  2556. if (bBreakInside)
  2557. {
  2558. // !!! RIP !!!! RIP !!!! RIP !!!
  2559. // MSDEV USERS: This is not the real RIP. Hit
  2560. // Shift-F11 to jump back to the caller.
  2561. SH_DEBUG_BREAK; // ASSERT
  2562. // !!! RIP !!!! RIP !!!! RIP !!!
  2563. }
  2564. else
  2565. bRet = TRUE;
  2566. }
  2567. return bRet;
  2568. }
  2569. /*----------------------------------------------------------
  2570. Purpose: Displays a RIP string.
  2571. */
  2572. BOOL
  2573. CcshellRipW(
  2574. LPCWSTR pszFile,
  2575. int line,
  2576. LPCWSTR pszEval,
  2577. BOOL bBreakInside)
  2578. {
  2579. BOOL bRet = FALSE;
  2580. LPCWSTR psz;
  2581. WCHAR ach[256];
  2582. psz = _PathFindFileNameW(pszFile);
  2583. // If psz == NULL, CharPrevW failed which implies we are running on Win95.
  2584. // We can get this if we get an assert in some of the W functions in
  2585. // shlwapi... Call the A version of assert...
  2586. if (!psz)
  2587. {
  2588. char szFile[MAX_PATH];
  2589. char szEval[256]; // since the total output is thhis size should be enough...
  2590. WideCharToMultiByte(CP_ACP, 0, pszFile, -1, szFile, ARRAYSIZE(szFile), NULL, NULL);
  2591. WideCharToMultiByte(CP_ACP, 0, pszEval, -1, szEval, ARRAYSIZE(szEval), NULL, NULL);
  2592. return CcshellRipA(szFile, line, szEval, bBreakInside);
  2593. }
  2594. wsprintfW(ach, c_wszRipNoFn, psz, line, pszEval);
  2595. OutputDebugStringW(ach);
  2596. if (fRip)
  2597. {
  2598. if (bBreakInside)
  2599. {
  2600. // !!! RIP !!!! RIP !!!! RIP !!!
  2601. // MSDEV USERS: This is not the real assert. Hit
  2602. // Shift-F11 to jump back to the caller.
  2603. SH_DEBUG_BREAK; // ASSERT
  2604. // !!! RIP !!!! RIP !!!! RIP !!!
  2605. }
  2606. else
  2607. bRet = TRUE;
  2608. }
  2609. return bRet;
  2610. }
  2611. EXTERN_C const CHAR FAR c_szRipMsg[] = SZ_MODULE " RIP: ";
  2612. EXTERN_C const CHAR FAR c_szNewline[] = "\n";
  2613. BOOL
  2614. __cdecl
  2615. CcshellRipMsgA(
  2616. BOOL f,
  2617. LPCSTR pszMsg, ...)
  2618. {
  2619. CHAR ach[1024+40];
  2620. va_list vArgs;
  2621. if (!f)
  2622. {
  2623. OutputDebugStringA(c_szRipMsg);
  2624. va_start(vArgs, pszMsg);
  2625. wvsprintfA(ach, pszMsg, vArgs);
  2626. va_end(vArgs);
  2627. OutputDebugStringA(ach);
  2628. OutputDebugStringA(c_szNewline);
  2629. if (fRip)
  2630. {
  2631. // MSDEV USERS: This is not the real assert. Hit
  2632. // Shift-F11 to jump back to the caller.
  2633. SH_DEBUG_BREAK; // ASSERT
  2634. }
  2635. }
  2636. return FALSE;
  2637. }
  2638. BOOL
  2639. __cdecl
  2640. CcshellRipMsgW(
  2641. BOOL f,
  2642. LPCSTR pszMsg, ...) // (this is deliberately CHAR)
  2643. {
  2644. WCHAR ach[1024+40];
  2645. va_list vArgs;
  2646. if (!f)
  2647. {
  2648. LPWSTR pwsz;
  2649. WCHAR wszBuf[128];
  2650. OutputDebugStringA(c_szRipMsg);
  2651. // (We convert the string, rather than simply input an
  2652. // LPCWSTR parameter, so the caller doesn't have to wrap
  2653. // all the string constants with the TEXT() macro.)
  2654. ach[0] = L'\0'; // In case this fails
  2655. if (UnicodeFromAnsi(&pwsz, pszMsg, wszBuf, ARRAYSIZE(wszBuf)))
  2656. {
  2657. va_start(vArgs, pszMsg);
  2658. wvsprintfW(ach, pwsz, vArgs);
  2659. va_end(vArgs);
  2660. UnicodeFromAnsi(&pwsz, NULL, wszBuf, 0);
  2661. }
  2662. OutputDebugStringW(ach);
  2663. OutputDebugStringA(c_szNewline);
  2664. if (fRip)
  2665. {
  2666. // MSDEV USERS: This is not the real assert. Hit
  2667. // Shift-F11 to jump back to the caller.
  2668. SH_DEBUG_BREAK; // ASSERT
  2669. }
  2670. }
  2671. return FALSE;
  2672. }
  2673. #if defined(i386)
  2674. VOID
  2675. x86SleazeCallStack(
  2676. OUT LPVOID * lplpvStack,
  2677. IN DWORD dwStackCount,
  2678. IN LPVOID * Ebp
  2679. )
  2680. /*++
  2681. Routine Description:
  2682. Similar to x86SleazeCallersAddress but gathers a variable number of return
  2683. addresses. We assume all functions have stack frame
  2684. Arguments:
  2685. lplpvStack - pointer to returned array of caller's addresses
  2686. dwStackCount - number of elements in lplpvStack
  2687. Ebp - starting Ebp if not 0, else use current stack
  2688. Return Value:
  2689. None.
  2690. --*/
  2691. {
  2692. DWORD my_esp;
  2693. _asm mov my_esp, esp;
  2694. __try {
  2695. if (Ebp == 0) {
  2696. Ebp = (LPVOID *)(&lplpvStack - 2);
  2697. }
  2698. while (dwStackCount--) {
  2699. if (((DWORD)Ebp > my_esp + 0x10000) || ((DWORD)Ebp < my_esp - 0x10000)) {
  2700. break;
  2701. }
  2702. *lplpvStack++ = *(Ebp + 1);
  2703. Ebp = (LPVOID *)*Ebp;
  2704. if (((DWORD)Ebp <= 0x10000)
  2705. || ((DWORD)Ebp >= 0x80000000)
  2706. || ((DWORD)Ebp & 3)
  2707. || ((DWORD)Ebp > my_esp + 0x10000)
  2708. || ((DWORD)Ebp < my_esp - 0x10000)) {
  2709. break;
  2710. }
  2711. }
  2712. } __except(EXCEPTION_EXECUTE_HANDLER) {
  2713. }
  2714. }
  2715. VOID
  2716. x86SleazeCallersAddress(
  2717. LPVOID* pCaller,
  2718. LPVOID* pCallersCaller
  2719. )
  2720. /*++
  2721. Routine Description:
  2722. This is a sleazy function that reads return addresses out of the stack/
  2723. frame pointer (ebp). We pluck out the return address of the function
  2724. that called THE FUNCTION THAT CALLED THIS FUNCTION, and the caller of
  2725. that function. Returning the return address of the function that called
  2726. this function is not interesting to that caller (almost worthy of Sir
  2727. Humphrey Appleby isn't it?)
  2728. Assumes:
  2729. my ebp => | caller's ebp |
  2730. | caller's eip |
  2731. | arg #1 | (pCaller)
  2732. | arg #2 | (pCallersCaller
  2733. Arguments:
  2734. pCaller - place where we return addres of function that called
  2735. the function that called this function
  2736. pCallersCaller - place where we return caller of above
  2737. Return Value:
  2738. None.
  2739. --*/
  2740. {
  2741. //
  2742. // this only works on x86 and only if not fpo functions!
  2743. //
  2744. LPVOID* ebp;
  2745. ebp = (PVOID*)&pCaller - 2; // told you it was sleazy
  2746. ebp = (PVOID*)*(PVOID*)ebp;
  2747. *pCaller = *(ebp + 1);
  2748. ebp = (PVOID*)*(PVOID*)ebp;
  2749. *pCallersCaller = *(ebp + 1);
  2750. }
  2751. #endif // defined(i386)
  2752. #endif // ENABLE_DEBUG
  2753. INTERNETAPI
  2754. BOOL
  2755. WINAPI
  2756. InternetDebugGetLocalTime(
  2757. OUT SYSTEMTIME * pstLocalTime,
  2758. OUT DWORD * pdwMicroSec
  2759. )
  2760. {
  2761. #ifndef ENABLE_DEBUG
  2762. // QUICK HACK TO KEEP THINGS CLEAN AND STILL MEASURE WITH HIGH PERFORMANCE
  2763. // COUNTER
  2764. static BOOL pcTested = FALSE;
  2765. static LONGLONG ftInit; // initial local time
  2766. static LONGLONG pcInit; // initial perf counter
  2767. static LONGLONG pcFreq; // perf counter frequency
  2768. if (!pcTested)
  2769. {
  2770. pcTested = TRUE;
  2771. if (QueryPerformanceFrequency ((LARGE_INTEGER *) &pcFreq) && pcFreq)
  2772. {
  2773. QueryPerformanceCounter ((LARGE_INTEGER *) &pcInit);
  2774. SYSTEMTIME st;
  2775. GetLocalTime (&st);
  2776. SystemTimeToFileTime (&st, (FILETIME *) &ftInit);
  2777. }
  2778. }
  2779. if (!pcFreq)
  2780. GetLocalTime (pstLocalTime);
  2781. else
  2782. {
  2783. LONGLONG pcCurrent, ftCurrent;
  2784. QueryPerformanceCounter ((LARGE_INTEGER *) &pcCurrent);
  2785. ftCurrent = ftInit + ((10000000 * (pcCurrent - pcInit)) / pcFreq);
  2786. FileTimeToSystemTime ((FILETIME *) &ftCurrent, pstLocalTime);
  2787. }
  2788. return TRUE;
  2789. #else
  2790. if (!pcFreq)
  2791. GetLocalTime (pstLocalTime);
  2792. else
  2793. {
  2794. LONGLONG pcCurrent, ftCurrent;
  2795. QueryPerformanceCounter ((LARGE_INTEGER *) &pcCurrent);
  2796. ftCurrent = ftInit + ((10000000 * (pcCurrent - pcInit)) / pcFreq);
  2797. FileTimeToSystemTime ((FILETIME *) &ftCurrent, pstLocalTime);
  2798. }
  2799. return TRUE;
  2800. #endif // ENABLE_DEBUG
  2801. }