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.

256 lines
7.5 KiB

  1. //***************************************************************************
  2. //
  3. // PROVLOG.CPP
  4. //
  5. // Module: OLE MS PROVIDER FRAMEWORK
  6. //
  7. // Copyright (c) 1996-2001 Microsoft Corporation, All Rights Reserved
  8. //
  9. //***************************************************************************
  10. #include <precomp.h>
  11. #include <wbemutil.h>
  12. #include <provimex.h>
  13. #include <provexpt.h>
  14. #include <provstd.h>
  15. #include <provmt.h>
  16. #include <string.h>
  17. #include <tchar.h>
  18. #include <strsafe.h>
  19. #include <provlog.h>
  20. #include <provevt.h>
  21. #include <Allocator.h>
  22. #include <Algorithms.h>
  23. #include <Allocator.cpp>
  24. WmiAllocator g_Allocator ;
  25. #define MAX_MESSAGE_SIZE 1024
  26. #define HALF_MAX_MESSAGE_SIZE 512
  27. #define TRUNCATE_T _T(" * string was truncated ! *\n")
  28. #define TRUNCATE_W L" * string was truncated ! *\n"
  29. #define TRUNCATE_A " * string was truncated ! *\n"
  30. long ProvDebugLog::s_ReferenceCount = 0 ;
  31. ProvDebugLog ProvDebugLog::s_aLogs[LOG_MAX_PROV] =
  32. {
  33. ProvDebugLog(LOG_WBEMCORE),
  34. ProvDebugLog(LOG_WINMGMT),
  35. ProvDebugLog(LOG_ESS),
  36. ProvDebugLog(LOG_WBEMPROX),
  37. ProvDebugLog(LOG_WBEMSTUB),
  38. ProvDebugLog(LOG_QUERY),
  39. ProvDebugLog(LOG_MOFCOMP),
  40. ProvDebugLog(LOG_EVENTLOG),
  41. ProvDebugLog(LOG_WBEMDISP),
  42. ProvDebugLog(LOG_STDPROV),
  43. ProvDebugLog(LOG_WIMPROV),
  44. ProvDebugLog(LOG_WMIOLEDB),
  45. ProvDebugLog(LOG_WMIADAP),
  46. ProvDebugLog(LOG_REPDRV),
  47. ProvDebugLog(LOG_PROVSS),
  48. ProvDebugLog(LOG_EVTPROV),
  49. ProvDebugLog(LOG_VIEWPROV),
  50. ProvDebugLog(LOG_DSPROV),
  51. ProvDebugLog(LOG_SNMPPROV),
  52. ProvDebugLog(LOG_PROVTHRD)
  53. };
  54. ProvDebugLog * ProvDebugLog::s_ProvDebugLog = ProvDebugLog::GetProvDebugLog(LOG_PROVTHRD);
  55. void ProvDebugLog :: Write ( const TCHAR *a_DebugFormatString , ... )
  56. {
  57. TCHAR t_OutputDebugString [ MAX_MESSAGE_SIZE ] ;
  58. va_list t_VarArgList ;
  59. va_start(t_VarArgList,a_DebugFormatString);
  60. HRESULT t_Result = StringCchVPrintf(t_OutputDebugString , MAX_MESSAGE_SIZE , a_DebugFormatString , t_VarArgList );
  61. if ( FAILED ( t_Result ) )
  62. {
  63. if ( t_Result == STRSAFE_E_INSUFFICIENT_BUFFER )
  64. {
  65. StringCchCopy ( &t_OutputDebugString [ MAX_MESSAGE_SIZE - (lstrlen (TRUNCATE_T)+1) ], lstrlen(TRUNCATE_T)+1, TRUNCATE_T );
  66. t_OutputDebugString [ MAX_MESSAGE_SIZE - 1 ] = ( TCHAR ) 0 ;
  67. }
  68. }
  69. va_end(t_VarArgList);
  70. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  71. }
  72. void ProvDebugLog :: WriteW ( const WCHAR *a_DebugFormatString , ... )
  73. {
  74. WCHAR t_OutputDebugString [ MAX_MESSAGE_SIZE ] ;
  75. va_list t_VarArgList ;
  76. va_start(t_VarArgList,a_DebugFormatString);
  77. HRESULT t_Result = StringCchVPrintfW(t_OutputDebugString , MAX_MESSAGE_SIZE , a_DebugFormatString , t_VarArgList );
  78. if ( FAILED ( t_Result ) )
  79. {
  80. if ( t_Result == STRSAFE_E_INSUFFICIENT_BUFFER )
  81. {
  82. StringCchCopyW ( &t_OutputDebugString [ MAX_MESSAGE_SIZE - (wcslen (TRUNCATE_W)+1) ], wcslen(TRUNCATE_W)+1, TRUNCATE_W );
  83. t_OutputDebugString [ MAX_MESSAGE_SIZE - 1 ] = ( TCHAR ) 0 ;
  84. }
  85. }
  86. va_end(t_VarArgList);
  87. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  88. }
  89. void ProvDebugLog :: WriteA ( const char *a_DebugFormatString , ... )
  90. {
  91. char t_OutputDebugString [ MAX_MESSAGE_SIZE ] ;
  92. va_list t_VarArgList ;
  93. va_start(t_VarArgList,a_DebugFormatString);
  94. HRESULT t_Result = StringCchVPrintfA(t_OutputDebugString , MAX_MESSAGE_SIZE , a_DebugFormatString , t_VarArgList );
  95. if ( FAILED ( t_Result ) )
  96. {
  97. if ( t_Result == STRSAFE_E_INSUFFICIENT_BUFFER )
  98. {
  99. StringCchCopyA ( &t_OutputDebugString [ MAX_MESSAGE_SIZE - (strlen (TRUNCATE_A)+1) ], strlen(TRUNCATE_A)+1, TRUNCATE_A );
  100. t_OutputDebugString [ MAX_MESSAGE_SIZE - 1 ] = ( char ) 0 ;
  101. }
  102. }
  103. va_end(t_VarArgList);
  104. DebugTrace(m_Caller,"%s",t_OutputDebugString);
  105. }
  106. void ProvDebugLog :: WriteFileAndLine ( const wchar_t *a_File , const ULONG a_Line , const wchar_t *a_DebugFormatString , ... )
  107. {
  108. wchar_t t_OutputDebugString [ MAX_MESSAGE_SIZE ] ;
  109. StringCchPrintf ( t_OutputDebugString , HALF_MAX_MESSAGE_SIZE , _TEXT("%s:%d\r\n"),a_File,a_Line ) ;
  110. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  111. va_list t_VarArgList ;
  112. va_start(t_VarArgList,a_DebugFormatString);
  113. HRESULT t_Result = StringCchVPrintf(t_OutputDebugString , MAX_MESSAGE_SIZE , a_DebugFormatString , t_VarArgList );
  114. if ( FAILED ( t_Result ) )
  115. {
  116. if ( t_Result == STRSAFE_E_INSUFFICIENT_BUFFER )
  117. {
  118. StringCchCopy ( &t_OutputDebugString [ MAX_MESSAGE_SIZE - (lstrlen (TRUNCATE_T)+1) ], lstrlen(TRUNCATE_T)+1, TRUNCATE_T );
  119. t_OutputDebugString [ MAX_MESSAGE_SIZE - 1 ] = ( TCHAR ) 0 ;
  120. }
  121. }
  122. va_end(t_VarArgList);
  123. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  124. }
  125. void ProvDebugLog :: WriteFileAndLine ( const char *a_File , const ULONG a_Line , const wchar_t *a_DebugFormatString , ... )
  126. {
  127. wchar_t t_OutputDebugString [ MAX_MESSAGE_SIZE ] ;
  128. StringCchPrintf ( t_OutputDebugString , HALF_MAX_MESSAGE_SIZE , _TEXT("%S:%d\r\n"),a_File,a_Line ) ;
  129. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  130. va_list t_VarArgList ;
  131. va_start(t_VarArgList,a_DebugFormatString);
  132. HRESULT t_Result = StringCchVPrintf(t_OutputDebugString , MAX_MESSAGE_SIZE , a_DebugFormatString , t_VarArgList );
  133. if ( FAILED ( t_Result ) )
  134. {
  135. if ( t_Result == STRSAFE_E_INSUFFICIENT_BUFFER )
  136. {
  137. StringCchCopy ( &t_OutputDebugString [ MAX_MESSAGE_SIZE - (lstrlen (TRUNCATE_T)+1) ], lstrlen(TRUNCATE_T)+1, TRUNCATE_T );
  138. t_OutputDebugString [ MAX_MESSAGE_SIZE - 1 ] = ( TCHAR ) 0 ;
  139. }
  140. }
  141. va_end(t_VarArgList);
  142. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  143. }
  144. void ProvDebugLog :: WriteFileAndLineW ( const WCHAR *a_File , const ULONG a_Line , const WCHAR *a_DebugFormatString , ... )
  145. {
  146. WCHAR t_OutputDebugString [ MAX_MESSAGE_SIZE ] ;
  147. StringCchPrintf ( t_OutputDebugString , HALF_MAX_MESSAGE_SIZE , _TEXT("%S:%d\r\n"),a_File,a_Line ) ;
  148. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  149. va_list t_VarArgList ;
  150. va_start(t_VarArgList,a_DebugFormatString);
  151. HRESULT t_Result = StringCchVPrintfW(t_OutputDebugString , MAX_MESSAGE_SIZE , a_DebugFormatString , t_VarArgList );
  152. if ( FAILED ( t_Result ) )
  153. {
  154. if ( t_Result == STRSAFE_E_INSUFFICIENT_BUFFER )
  155. {
  156. StringCchCopyW ( &t_OutputDebugString [ MAX_MESSAGE_SIZE - (wcslen (TRUNCATE_W)+1) ], wcslen(TRUNCATE_W)+1, TRUNCATE_W );
  157. t_OutputDebugString [ MAX_MESSAGE_SIZE - 1 ] = ( wchar_t ) 0 ;
  158. }
  159. }
  160. va_end(t_VarArgList);
  161. DebugTrace(m_Caller,"%S",t_OutputDebugString);
  162. }
  163. void ProvDebugLog :: WriteFileAndLineA ( const char *a_File , const ULONG a_Line , const char *a_DebugFormatString , ... )
  164. {
  165. char t_OutputDebugString [ MAX_MESSAGE_SIZE ] ;
  166. StringCchPrintfA( t_OutputDebugString , HALF_MAX_MESSAGE_SIZE , "%s:%d\r\n",a_File,a_Line ) ;
  167. DebugTrace(m_Caller,"%s",t_OutputDebugString);
  168. va_list t_VarArgList ;
  169. va_start(t_VarArgList,a_DebugFormatString);
  170. HRESULT t_Result = StringCchVPrintfA(t_OutputDebugString , MAX_MESSAGE_SIZE , a_DebugFormatString , t_VarArgList );
  171. if ( FAILED ( t_Result ) )
  172. {
  173. if ( t_Result == STRSAFE_E_INSUFFICIENT_BUFFER )
  174. {
  175. StringCchCopyA ( &t_OutputDebugString [ MAX_MESSAGE_SIZE - (strlen (TRUNCATE_A)+1) ], strlen(TRUNCATE_A)+1, TRUNCATE_A );
  176. t_OutputDebugString [ MAX_MESSAGE_SIZE - 1 ] = ( char ) 0 ;
  177. }
  178. }
  179. va_end(t_VarArgList);
  180. DebugTrace(m_Caller,"%s",t_OutputDebugString);
  181. }
  182. BOOL ProvDebugLog :: Startup ()
  183. {
  184. InterlockedIncrement(&s_ReferenceCount);
  185. return TRUE ;
  186. }
  187. void ProvDebugLog :: Closedown ()
  188. {
  189. InterlockedDecrement(&s_ReferenceCount);
  190. }