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.

263 lines
8.5 KiB

  1. /*===================================================================
  2. Microsoft Denali
  3. Microsoft Confidential.
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Error handling
  6. File: Error.h
  7. Owner: AndrewS
  8. Include file for general error reporting routines for Denali.
  9. ===================================================================*/
  10. #ifndef __ERROR_H
  11. #define __ERROR_H
  12. #include "hitobj.h"
  13. #include "scrptmgr.h"
  14. #define MAX_RESSTRINGSIZE 1024
  15. // bug 840: must use these in both HandleErrorSz and CTemplate
  16. #define SZ_BREAKBOLD "<BR><B>"
  17. #define SZ_UNBREAKBOLD "<BR></B>"
  18. const UINT CCH_BREAKBOLD = strlen(SZ_BREAKBOLD);
  19. const UINT CCH_UNBREAKBOLD = strlen(SZ_UNBREAKBOLD);
  20. /* format of default mask
  21. 32 bits
  22. 31 16 8 4 0
  23. bit 0 - 4 default sink/output places.
  24. bit 0 NT Event Log
  25. bit 1 IIS log
  26. bit 2 Browser
  27. bit 3 Reserved
  28. bit 5 - 8 default predefined messages.(from registry)
  29. bit 5 use generic AccessDenied Message
  30. bit 6 use generic ScriptError Message
  31. bit 7 - 8 Reserved
  32. bit 9 - 10 to browser templates.(4 templates available)
  33. 0x00 Default Script Template
  34. 0x01 Empty Template/No Template
  35. 0x10 System Template(mimic IIS style to Browser on HTTP errors, 204, 404, 500)
  36. 0x11 Reserved
  37. bit 11 - 31 Reserved
  38. */
  39. #define ERR_LOGTONT 0x00000001
  40. #define ERR_LOGTOIIS 0x00000002
  41. #define ERR_LOGTOBROWSER 0x00000004
  42. //Format(Script style is default, SYS style is for System error, 204, 404 and 500)
  43. #define ERR_FMT_SCRIPT 0x00000000
  44. #define ERR_FMT_SYS 0x00000200
  45. #define ERR_SetNoLogtoNT(x) ((x) & 0xfffffffe)
  46. #define ERR_SetNoLogtoIIS(x) ((x) & 0xfffffffd)
  47. #define ERR_SetNoLogtoBrowser(x) ((x) & 0xfffffffb)
  48. #define ERR_SetLogtoNT(x) ((x) | ERR_LOGTONT)
  49. #define ERR_SetLogtoIIS(x) ((x) | ERR_LOGTOIIS)
  50. #define ERR_SetLogtoBrowser(x) ((x) | ERR_LOGTOBROWSER)
  51. #define ERR_FLogtoNT(x) ((x) & ERR_LOGTONT)
  52. #define ERR_FLogtoIIS(x) ((x) & ERR_LOGTOIIS)
  53. #define ERR_FLogtoBrowser(x) ((x) & ERR_LOGTOBROWSER)
  54. #define ERR_FIsSysFormat(x) ((x) & ERR_FMT_SYS)
  55. #define ERR_SetSysFormat(x) ((x) | ERR_FMT_SYS)
  56. //The order of the index is the order we send to the browser.(exclude header).
  57. #define Im_szEngine 0
  58. #define Im_szErrorCode 1
  59. #define Im_szShortDescription 2
  60. #define Im_szFileName 3
  61. #define Im_szLineNum 4
  62. #define Im_szCode 5
  63. #define Im_szLongDescription 6
  64. #define Im_szHeader 7
  65. #define Im_szItemMAX 8
  66. // ASP HTTP sub-error codes for custom 500 errors
  67. #define SUBERRORCODE500_SERVER_ERROR 0
  68. #define SUBERRORCODE500_SHUTTING_DOWN 11
  69. #define SUBERRORCODE500_RESTARTING_APP 12
  70. #define SUBERRORCODE500_SERVER_TOO_BUSY 13
  71. #define SUBERRORCODE500_INVALID_APP 14
  72. #define SUBERRORCODE500_GLOBALASA_FORBIDDEN 15
  73. class CErrInfo
  74. {
  75. friend HRESULT ErrHandleInit(void);
  76. friend HRESULT ErrHandleUnInit(void);
  77. friend HRESULT GetSpecificError(CErrInfo *pErrInfo,
  78. HRESULT hrError);
  79. friend HRESULT HandleSysError( DWORD dwHttpError,
  80. DWORD dwHttpSubError,
  81. UINT ErrorID,
  82. UINT ErrorHeaderID,
  83. CIsapiReqInfo *pIReq,
  84. CHitObj *pHitObj);
  85. friend HRESULT HandleOOMError( CIsapiReqInfo *pIReq,
  86. CHitObj *pHitObj);
  87. friend HRESULT HandleError( CHAR *szShortDes,
  88. CHAR *szLongDes,
  89. DWORD mask,
  90. CHAR *szFileName,
  91. CHAR *szLineNum,
  92. CHAR *szEngine,
  93. CHAR *szErrCode,
  94. CIsapiReqInfo *pIReq,
  95. CHitObj *pHitObj);
  96. friend HRESULT HandleError( IActiveScriptError *pscripterror,
  97. CTemplate *pTemplate,
  98. DWORD dwEngineID,
  99. CIsapiReqInfo *pIReq,
  100. CHitObj *pHitObj);
  101. friend HRESULT HandleError( UINT ErrorID,
  102. CHAR *szFileName,
  103. CHAR *szLineNum,
  104. CHAR *szEngine,
  105. CHAR *szErrCode,
  106. CHAR *szLongDes,
  107. CIsapiReqInfo *pIReq,
  108. CHitObj *pHitObj,
  109. va_list *pArgs = NULL);
  110. public:
  111. CErrInfo();
  112. inline LPSTR GetItem(DWORD iItem) { return m_szItem[iItem]; }
  113. inline void GetLineInfo(BSTR *pbstrLineText, int *pnColumn)
  114. { *pbstrLineText = m_bstrLineText, *pnColumn = m_nColumn; }
  115. private:
  116. //sink, either via CResponse(also use CIsapiReqInfo), or via WAM_EXEC_INFO
  117. CIsapiReqInfo *m_pIReq;
  118. CHitObj *m_pHitObj;
  119. // HTTP error code (404, 500, etc.) and sub error code
  120. DWORD m_dwHttpErrorCode;
  121. DWORD m_dwHttpSubErrorCode;
  122. //mask
  123. DWORD m_dwMask;
  124. //data
  125. LPSTR m_szItem[Im_szItemMAX];
  126. //line data (don't use m_szItem[] because data is BSTR
  127. BSTR m_bstrLineText;
  128. int m_nColumn;
  129. HRESULT LogError();
  130. HRESULT LogError(DWORD dwMask, LPSTR *szErrorString);
  131. HRESULT LogErrortoNTEventLog(BOOL, BOOL);
  132. HRESULT LogErrortoIISLog(BOOL *, BOOL *);
  133. HRESULT LogErrortoBrowserWrapper();
  134. HRESULT LogErrortoBrowser(CResponse *pResponse);
  135. HRESULT LogErrortoBrowser(CIsapiReqInfo *pIReq);
  136. HRESULT LogCustomErrortoBrowser(CIsapiReqInfo *pIReq, BOOL *pfCustomErrorProcessed);
  137. void WriteHTMLEncodedErrToBrowser(const CHAR *StrIn, CResponse *pResponse, CIsapiReqInfo *pIReq);
  138. HRESULT WriteCustomFileError(CIsapiReqInfo *pIReq, TCHAR *szPath, TCHAR *szMimeType);
  139. HRESULT WriteCustomURLError(CIsapiReqInfo *pIReq, TCHAR *szURL);
  140. HRESULT ParseResourceString(CHAR *sz);
  141. };
  142. //Error Handling APIs
  143. //Case 1.a: Runtime Script Error(From Denali, VBS, JavaScript, or anyother Engines).
  144. //example. Called by OnScriptError.
  145. HRESULT HandleError( IActiveScriptError *pscripterror,
  146. CTemplate *pTemplate,
  147. DWORD dwEngineID,
  148. CIsapiReqInfo *pIReq,
  149. CHitObj *pHitObj );
  150. //Case 1.b: Runtime Script Error(From Denali, VBS, JavaScript, or anyother Engines).
  151. // Show error in debugger rather than the standard error logging.
  152. HRESULT DebugError( IActiveScriptError *pScriptError, CTemplate *pTemplate, DWORD dwEngineID, IDebugApplication *pDebugApp);
  153. //Case 2: Compiling time Script Error,
  154. //Also, this function is the most generic HandleError.
  155. HRESULT HandleError( CHAR *szShortDes,
  156. CHAR *szLongDes,
  157. DWORD dwMask,
  158. CHAR *szFileName,
  159. CHAR *szLineNum,
  160. CHAR *szEngine,
  161. CHAR *szErrCode,
  162. CIsapiReqInfo *pIReq,
  163. CHitObj *pHitObj);
  164. //Case 3: Predefined Error ID
  165. HRESULT HandleError( UINT ErrorID,
  166. CHAR *szFileName,
  167. CHAR *szLineNum,
  168. CHAR *szEngine,
  169. CHAR *szErrCode,
  170. CHAR *szLongDes,
  171. CIsapiReqInfo *pIReq,
  172. CHitObj *pHitObj,
  173. va_list *pArgs);
  174. //Case 4: SystemDefined Error(so far, only 204, 404, and 500 can use this call)
  175. // Implementation of this call will first send out the header, if ErrorHeaderID is not 0.
  176. HRESULT HandleSysError( DWORD dwHttpError,
  177. DWORD dwHttpSubError,
  178. UINT ErrorID,
  179. UINT ErrorHeaderID,
  180. CIsapiReqInfo *pIReq,
  181. CHitObj *pHitObj);
  182. // 500 Error processing calls HandleSysError()
  183. HRESULT Handle500Error( UINT ErrorID, CIsapiReqInfo *pIReq);
  184. //OOM, special attention, because Heap is full, and therefore, no dynamic allocation
  185. HRESULT HandleOOMError( CIsapiReqInfo *pIReq,
  186. CHitObj *pHitObj);
  187. //FileName missing
  188. // The caller has no file name, nor any other info about where or when
  189. // the error occurred. Trys to get the filename from the hitobj
  190. VOID HandleErrorMissingFilename(UINT errorID,
  191. CHitObj *pHitObj,
  192. BOOL fVarArgs = FALSE,
  193. ...);
  194. //The following 2 calls are discouraged for error-handling usage.
  195. //Use one of the Error Handling APIs instead.
  196. //Ok when loading other strings from resource file.
  197. INT CchLoadStringOfId(UINT id, CHAR *sz, INT cchMax);
  198. INT CwchLoadStringOfId(UINT id, WCHAR *sz, INT cchMax);
  199. HRESULT ErrHandleInit(void);
  200. HRESULT ErrHandleUnInit(void);
  201. HRESULT LoadErrResString(UINT ErrID/*IN*/, DWORD *dwMask, CHAR *szErrorCode, CHAR *szShortDes, CHAR *LongDes);
  202. CHAR *SzScodeToErrorCode(HRESULT hrError);
  203. BOOL HResultToWsz(HRESULT hrIn, WCHAR *wszOut, DWORD cdwOut);
  204. BOOL HResultToSz(HRESULT hrIn, CHAR *szOut, DWORD cdwOut);
  205. #endif __ERROR_H