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.

242 lines
7.8 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // File Name: fxocDbg.cpp
  4. //
  5. // Abstract: This provides the debug routines used in the FaxOCM
  6. // code base.
  7. //
  8. // Environment: Windows XP / User Mode
  9. //
  10. // Copyright (c) 2000 Microsoft Corporation
  11. //
  12. // Revision History:
  13. //
  14. // Date: Developer: Comments:
  15. // ----- ---------- ---------
  16. // 15-Mar-2000 Oren Rosenbloom (orenr) Created
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "faxocm.h"
  19. #pragma hdrstop
  20. #define prv_SECTION_FAXOCMDEBUG _T("FaxOcmDebug")
  21. #define prv_KEY_DEBUGLEVEL _T("DebugLevel")
  22. #define prv_KEY_DEBUGFORMAT _T("DebugFormat")
  23. #define prv_DEBUG_FILE_NAME _T("%windir%\\FaxSetup.log")
  24. ///////////////////////////////
  25. // prv_OC_Function
  26. //
  27. // Type containing text description
  28. // of stage of OC Manager
  29. // setup.
  30. //
  31. typedef struct prv_OC_Function
  32. {
  33. UINT uiFunction;
  34. TCHAR *pszFunctionDesc;
  35. } prv_OC_Function;
  36. ///////////////////////////////
  37. // prv_OC_FunctionTable
  38. //
  39. // This table contains the various
  40. // stages of the OC Manager setup,
  41. // and their text equivalent. This
  42. // allows us to output to debug the
  43. // stage of setup, rather than the
  44. // numerical equivalent.
  45. //
  46. //
  47. static prv_OC_Function prv_OC_FunctionTable[] =
  48. {
  49. {OC_PREINITIALIZE, _T("OC_PREINITIALIZE")},
  50. {OC_INIT_COMPONENT, _T("OC_INIT_COMPONENT")},
  51. {OC_SET_LANGUAGE, _T("OC_SET_LANGUAGE")},
  52. {OC_QUERY_IMAGE, _T("OC_QUERY_IMAGE")},
  53. {OC_REQUEST_PAGES, _T("OC_REQUEST_PAGES")},
  54. {OC_QUERY_CHANGE_SEL_STATE, _T("OC_QUERY_CHANGE_SEL_STATE")},
  55. {OC_CALC_DISK_SPACE, _T("OC_CALC_DISK_SPACE")},
  56. {OC_QUEUE_FILE_OPS, _T("OC_QUEUE_FILE_OPS")},
  57. {OC_NOTIFICATION_FROM_QUEUE, _T("OC_NOTIFICATION_FROM_QUEUE")},
  58. {OC_QUERY_STEP_COUNT, _T("OC_QUERY_STEP_COUNT")},
  59. {OC_COMPLETE_INSTALLATION, _T("OC_COMPLETE_INSTALLATION")},
  60. {OC_CLEANUP, _T("OC_CLEANUP")},
  61. {OC_QUERY_STATE, _T("OC_QUERY_STATE")},
  62. {OC_NEED_MEDIA, _T("OC_NEED_MEDIA")},
  63. {OC_ABOUT_TO_COMMIT_QUEUE, _T("OC_ABOUT_TO_COMMIT_QUEUE")},
  64. {OC_QUERY_SKIP_PAGE, _T("OC_QUERY_SKIP_PAGE")},
  65. {OC_WIZARD_CREATED, _T("OC_WIZARD_CREATED")},
  66. {OC_FILE_BUSY, _T("OC_FILE_BUSY")},
  67. {OC_EXTRA_ROUTINES, _T("OC_EXTRA_ROUTINES")}
  68. };
  69. #define NUM_OC_FUNCTIONS (sizeof(prv_OC_FunctionTable) / sizeof(prv_OC_FunctionTable[0]))
  70. ////////////////////////////////
  71. // fxocDbg_InitDebug
  72. //
  73. // Initialize the FaxOcm
  74. // debug subsystem.
  75. //
  76. // We can be turned on either
  77. // via the [FaxOcmDebug] section
  78. // in the faxsetup.inf, or via the
  79. // the "DebugLevelEx" and "DebugFormatEx"
  80. // under HKLM\Software\Microsoft\Fax
  81. // If both are specified, the registry wins.
  82. //
  83. // In faxocm.inf, we look for
  84. // [FaxOcmDebug]
  85. // ============================
  86. // [DebugLevel] can be one of the following:
  87. // 0 - no debug output
  88. // 1 - see errors only
  89. // 2 - see errors & warnings
  90. // 3 - see all the debug output
  91. //
  92. // [DebugFormat] can be one of the following:
  93. // 0 - print to std output
  94. // 1 - print to file ("FaxSetup.log" in %windir%\system32 directory)
  95. // 2 - print to both
  96. // ============================
  97. //
  98. // Params:
  99. // - hFaxSetupInfHandle - handle to faxsetup.inf
  100. // if applicable.
  101. // Returns:
  102. // - void.
  103. //
  104. void fxocDbg_Init(HINF hFaxSetupInfHandle)
  105. {
  106. BOOL bSuccess = FALSE;
  107. INFCONTEXT Context;
  108. INT iDebugLevel = 0;
  109. INT iDebugFormat = 0;
  110. DBG_ENTER(_T("fxocDbg_Init"),bSuccess);
  111. memset(&Context, 0, sizeof(Context));
  112. if (hFaxSetupInfHandle)
  113. {
  114. // initialize via the INF file.
  115. // We are looking for:
  116. // [FaxOcmDebug]
  117. // DebugLevel = x (0 -> no debug, up to and including 3->full debug)
  118. // find the section in the INF file and the DebugLevel key.
  119. bSuccess = ::SetupFindFirstLine(hFaxSetupInfHandle,
  120. prv_SECTION_FAXOCMDEBUG,
  121. prv_KEY_DEBUGLEVEL,
  122. &Context);
  123. if (bSuccess)
  124. {
  125. // we found the DebugLevel key, so get its value.
  126. bSuccess = ::SetupGetIntField(&Context, 1, &iDebugLevel);
  127. if (bSuccess)
  128. {
  129. iDebugLevel = max(iDebugLevel,0);
  130. iDebugLevel = min(iDebugLevel,3);
  131. if (!IS_DEBUG_SESSION_FROM_REG)
  132. {
  133. switch (iDebugLevel)
  134. {
  135. case 0: SET_DEBUG_MASK(ASSERTION_FAILED);
  136. break;
  137. case 1: SET_DEBUG_MASK(DBG_ERRORS_ONLY);
  138. break;
  139. case 2: SET_DEBUG_MASK(DBG_ERRORS_WARNINGS);
  140. break;
  141. case 3: SET_DEBUG_MASK(DBG_ALL);
  142. break;
  143. }
  144. }
  145. }
  146. }
  147. memset(&Context, 0, sizeof(Context));
  148. // find the section in the INF file and the DebugFormat key.
  149. bSuccess = ::SetupFindFirstLine(hFaxSetupInfHandle,
  150. prv_SECTION_FAXOCMDEBUG,
  151. prv_KEY_DEBUGFORMAT,
  152. &Context);
  153. if (bSuccess)
  154. {
  155. // we found the DebugLevel key, so get its value.
  156. bSuccess = ::SetupGetIntField(&Context, 1, &iDebugFormat);
  157. if (bSuccess)
  158. {
  159. iDebugLevel = max(iDebugFormat,0);
  160. iDebugLevel = min(iDebugFormat,2);
  161. if (!IS_DEBUG_SESSION_FROM_REG)
  162. {
  163. switch (iDebugFormat)
  164. {
  165. case 0: SET_FORMAT_MASK(DBG_PRNT_ALL_TO_STD);
  166. break;
  167. case 1: SET_FORMAT_MASK(DBG_PRNT_ALL_TO_FILE);
  168. OPEN_DEBUG_LOG_FILE(prv_DEBUG_FILE_NAME);
  169. SET_DEBUG_FLUSH(FALSE);
  170. break;
  171. case 2: SET_FORMAT_MASK(DBG_PRNT_ALL);
  172. OPEN_DEBUG_LOG_FILE(prv_DEBUG_FILE_NAME);
  173. SET_DEBUG_FLUSH(FALSE);
  174. break;
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. ////////////////////////////////
  182. // fxocDbg_TermDebug
  183. //
  184. // Terminate the debug subsystem
  185. //
  186. // Params:
  187. // - void.
  188. // Returns:
  189. // - void.
  190. //
  191. void fxocDbg_Term(void)
  192. {
  193. DBG_ENTER(_T("fxocDbg_Term"));
  194. CLOSE_DEBUG_LOG_FILE;
  195. }
  196. ///////////////////////////////
  197. // fxocDbg_GetOcFunction
  198. //
  199. // This looks up the uiFunction
  200. // in the prv_OC_Function table
  201. // defined above and returns a
  202. // pointer to the text equivalent.
  203. //
  204. // Params:
  205. // - uiFunction - function OC Manager wants us to perform.
  206. // Returns:
  207. // - text equivalent of uiFunction.
  208. //
  209. //
  210. const TCHAR* fxocDbg_GetOcFunction(UINT uiFunction)
  211. {
  212. TCHAR *pszString = _T("");
  213. // NOTE: This function assumes that the table above contains a
  214. // numerically sorted array with the numerical value of
  215. // "uiFunction" equal to its index position in the
  216. // prv_OC_FunctionTable array. We assume this for performance
  217. // purposes.
  218. if (uiFunction < NUM_OC_FUNCTIONS)
  219. {
  220. pszString = prv_OC_FunctionTable[uiFunction].pszFunctionDesc;
  221. }
  222. return pszString;
  223. }