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.

294 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. SceLogException.cpp
  5. Abstract:
  6. implementation of class SceLogException
  7. SceLogException is the exception class used internally
  8. within the SecMan dll. SecLogExceptions can be thrown
  9. and additional debug information can be added to
  10. the SecLogException each time it is caught.
  11. Author:
  12. Steven Chan (t-schan) July 2002
  13. --*/
  14. #ifdef UNICODE
  15. #define _UNICODE
  16. #endif
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windows.h>
  21. #include <iostream.h>
  22. #include "SceLogException.h"
  23. SceLogException::SceLogException(
  24. IN SXERROR ErrorType,
  25. IN PCWSTR szDebugInfo OPTIONAL,
  26. IN PCWSTR szMoreInfo OPTIONAL,
  27. IN DWORD dwErrorCode
  28. )
  29. /*++
  30. Routine Description:
  31. Constructor for SceLogException
  32. Arguments:
  33. ErrorType: Type of the error
  34. szDebugInfo: Info to add to the exception for debugging
  35. szMoreInfo: Any additional info to be added
  36. dwErrorCode: Code of the error that caused this excetion. If
  37. there is no code, this should be 0.
  38. Return Value:
  39. none
  40. --*/
  41. {
  42. this->ErrorType = ErrorType;
  43. this->dwErrorCode = dwErrorCode;
  44. if (szDebugInfo!=NULL) {
  45. this->szDebugInfo = new WCHAR[wcslen(szDebugInfo)+1];
  46. wcscpy(this->szDebugInfo, szDebugInfo);
  47. } else {
  48. szDebugInfo=NULL;
  49. }
  50. if (szMoreInfo!=NULL) {
  51. this->szMoreInfo = new WCHAR[wcslen(szMoreInfo)+1];
  52. wcscpy(this->szMoreInfo, szMoreInfo);
  53. } else {
  54. szDebugInfo=NULL;
  55. }
  56. }
  57. SceLogException::~SceLogException()
  58. /*++
  59. Routine Description:
  60. destructor for SceLogException
  61. Arguments:
  62. none
  63. Return Value:
  64. none
  65. --*/
  66. {
  67. if (NULL!=szDebugInfo) {
  68. delete szDebugInfo;
  69. }
  70. if (NULL!=szMoreInfo) {
  71. delete szMoreInfo;
  72. }
  73. if (NULL!=szArea) {
  74. delete szArea;
  75. }
  76. if (NULL!=szSettingName) {
  77. delete szSettingName;
  78. }
  79. }
  80. void
  81. SceLogException::ChangeType(
  82. IN SXERROR ErrorType
  83. )
  84. /*++
  85. Routine Description:
  86. changes the type of the error
  87. Arguments:
  88. ErrorType: Type to change to
  89. Return Value:
  90. none
  91. --*/
  92. {
  93. this->ErrorType=ErrorType;
  94. }
  95. void
  96. SceLogException::AddDebugInfo(
  97. IN PCWSTR szDebugInfo
  98. )
  99. /*++
  100. Routine Description:
  101. appends more debug info to whatever is already present
  102. a new line is added between the old info and the new string
  103. Arguments:
  104. szDebugInfo: string to append
  105. Return Value:
  106. none
  107. --*/
  108. {
  109. if (szDebugInfo!=NULL) {
  110. if (this->szDebugInfo==NULL) {
  111. this->szDebugInfo = new WCHAR[wcslen(szDebugInfo)+1];
  112. if (this->szDebugInfo!=NULL) {
  113. wcscpy(this->szDebugInfo, szDebugInfo);
  114. }
  115. } else {
  116. PWSTR szTmp = this->szDebugInfo;
  117. this->szDebugInfo = new WCHAR[wcslen(szDebugInfo) + wcslen(szTmp) + 3];
  118. if (this->szDebugInfo!=NULL) {
  119. wcscpy(this->szDebugInfo, szDebugInfo);
  120. wcscat(this->szDebugInfo, L"\n\r");
  121. wcscat(this->szDebugInfo, szTmp);
  122. }
  123. delete szTmp;
  124. }
  125. }
  126. }
  127. void
  128. SceLogException::SetSettingName(
  129. IN PCWSTR szSettingName
  130. )
  131. /*++
  132. Routine Description:
  133. set the name of the setting where this error occured
  134. Arguments:
  135. szSettingName: setting name
  136. Return Value:
  137. none
  138. --*/
  139. {
  140. delete this->szSettingName;
  141. if (szSettingName!=NULL) {
  142. this->szSettingName = new WCHAR[wcslen(szSettingName)+1];
  143. if (this->szSettingName!=NULL) {
  144. wcscpy(this->szSettingName, szSettingName);
  145. }
  146. } else {
  147. szSettingName=NULL;
  148. }
  149. }
  150. void
  151. SceLogException::SetArea(
  152. IN PCWSTR szArea
  153. )
  154. /*++
  155. Routine Description:
  156. sets the name of the analysis area in which this error occured
  157. Arguments:
  158. szArea: name of analysis area
  159. Return Value:
  160. none
  161. --*/
  162. {
  163. delete this->szArea;
  164. if (szArea!=NULL) {
  165. this->szArea = new WCHAR[wcslen(szArea)+1];
  166. if (this->szArea!=NULL) {
  167. wcscpy(this->szArea, szArea);
  168. }
  169. } else {
  170. szSettingName=NULL;
  171. }
  172. }
  173. void
  174. SceLogException::AddMoreInfo(
  175. IN PCWSTR szMoreInfo
  176. )
  177. /*++
  178. Routine Description:
  179. appends more supplementary info to whatever is already present
  180. a new line is added between the old info and the new string
  181. Arguments:
  182. szMoreInfo: string to append
  183. Return Value:
  184. none
  185. --*/
  186. {
  187. if (szMoreInfo!=NULL) {
  188. if (this->szMoreInfo==NULL) {
  189. this->szMoreInfo = new WCHAR[wcslen(szMoreInfo)+1];
  190. if (szMoreInfo!=NULL) {
  191. wcscpy(this->szMoreInfo, szMoreInfo);
  192. }
  193. } else {
  194. PWSTR szTmp = this->szMoreInfo;
  195. this->szMoreInfo = new WCHAR[wcslen(szMoreInfo) + wcslen(szTmp) + 3];
  196. if (this->szMoreInfo!=NULL) {
  197. wcscpy(this->szMoreInfo, szMoreInfo);
  198. wcscat(this->szMoreInfo, L"\n\r");
  199. wcscat(this->szMoreInfo, szTmp);
  200. }
  201. delete szTmp;
  202. }
  203. }
  204. }