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.

246 lines
5.7 KiB

  1. #include "precomp.hxx"
  2. #define DLL_IMPLEMENTATION
  3. #include <initguid.h>
  4. #include <ilogobj.hxx>
  5. #include <http.h>
  6. #include <httpp.h>
  7. #include "logging.h"
  8. #include "colog.hxx"
  9. DECLARE_DEBUG_PRINTS_OBJECT();
  10. DECLARE_DEBUG_VARIABLE();
  11. DECLARE_PLATFORM_TYPE();
  12. #define LOGGING_SIGNATURE 'GGOL'
  13. #define LOGGING_SIGNATURE_FREE 'fgol'
  14. CHAR g_pszComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  15. LOGGING::LOGGING()
  16. : m_fUlLogType (FALSE),
  17. m_pComponent (NULL),
  18. m_cRefs (1),
  19. m_Signature (LOGGING_SIGNATURE)
  20. {}
  21. LOGGING::~LOGGING()
  22. {
  23. m_Signature = LOGGING_SIGNATURE_FREE;
  24. //
  25. // end of logging object
  26. //
  27. if (m_pComponent != NULL)
  28. {
  29. m_pComponent->TerminateLog();
  30. m_pComponent->Release();
  31. m_pComponent = NULL;
  32. }
  33. }
  34. VOID LOGGING::AddRef()
  35. {
  36. InterlockedIncrement(&m_cRefs);
  37. }
  38. VOID LOGGING::Release()
  39. {
  40. DBG_ASSERT(m_cRefs > 0);
  41. if (InterlockedDecrement(&m_cRefs) == 0)
  42. {
  43. delete this;
  44. }
  45. }
  46. HRESULT LOGGING::ActivateLogging(IN LPCSTR pszInstanceName,
  47. IN LPCWSTR pszMetabasePath,
  48. IN IMSAdminBase *pMDObject,
  49. IN BOOL fDoCentralBinaryLogging)
  50. {
  51. HRESULT hr = S_OK;
  52. DWORD cbSize;
  53. STACK_STRU (strPlugin, 64);
  54. BOOL fInitializedLog = FALSE;
  55. STACK_STRA (strMetabasePath, 24);
  56. MB mb(pMDObject);
  57. if (!mb.Open(pszMetabasePath))
  58. {
  59. hr = HRESULT_FROM_WIN32(GetLastError());
  60. goto Exit;
  61. }
  62. //
  63. // If Logging is disabled, bail
  64. //
  65. DWORD dwLogType;
  66. if (mb.GetDword(L"", MD_LOG_TYPE, IIS_MD_UT_SERVER, &dwLogType))
  67. {
  68. if (dwLogType == MD_LOG_TYPE_DISABLED)
  69. {
  70. DBGPRINTF((DBG_CONTEXT, "Site %S has logging disabled\n",
  71. pszInstanceName));
  72. hr = S_OK;
  73. goto Exit;
  74. }
  75. }
  76. if (fDoCentralBinaryLogging)
  77. {
  78. m_fUlLogType = TRUE;
  79. hr = S_OK;
  80. goto Exit;
  81. }
  82. if (!mb.GetStr(L"", MD_LOG_PLUGIN_ORDER, IIS_MD_UT_SERVER, &strPlugin))
  83. {
  84. hr = HRESULT_FROM_WIN32(GetLastError());
  85. goto Exit;
  86. }
  87. mb.Close();
  88. //
  89. // Check if it is one of the built-in logging type handled by UL
  90. //
  91. if (!_wcsicmp(strPlugin.QueryStr(), NCSALOG_CLSID) ||
  92. !_wcsicmp(strPlugin.QueryStr(), ASCLOG_CLSID) ||
  93. !_wcsicmp(strPlugin.QueryStr(), EXTLOG_CLSID))
  94. {
  95. m_fUlLogType = TRUE;
  96. hr = S_OK;
  97. goto Exit;
  98. }
  99. m_fUlLogType = FALSE;
  100. //
  101. // It is custom/ODBC logging. We handle it in usermode
  102. //
  103. CLSID clsid;
  104. if (FAILED(hr = CLSIDFromString(strPlugin.QueryStr(), &clsid)))
  105. {
  106. DBGPRINTF((DBG_CONTEXT, "Could not convert string %S to CLSID\n",
  107. strPlugin.QueryStr()));
  108. goto Exit;
  109. }
  110. LPUNKNOWN punk;
  111. if (FAILED(hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER,
  112. IID_IUnknown, (void **)&punk)))
  113. {
  114. DBGPRINTF((DBG_CONTEXT, "Could not create instance of %S\n",
  115. strPlugin.QueryStr()));
  116. goto Exit;
  117. }
  118. hr = punk->QueryInterface(IID_ILogPlugin, (void **)&m_pComponent);
  119. punk->Release();
  120. if (FAILED(hr))
  121. {
  122. DBGPRINTF((DBG_CONTEXT, "Failed to get interface for %S\n",
  123. strPlugin.QueryStr()));
  124. goto Exit;
  125. }
  126. if (FAILED(hr = strMetabasePath.CopyW(pszMetabasePath)))
  127. {
  128. goto Exit;
  129. }
  130. if (FAILED(hr = m_pComponent->InitializeLog(pszInstanceName,
  131. strMetabasePath.QueryStr(),
  132. (PCHAR)pMDObject)))
  133. {
  134. goto Exit;
  135. }
  136. fInitializedLog = TRUE;
  137. //
  138. // Make it at least MAX_PATH before the first call
  139. //
  140. if (!m_mszExtraLoggingFields.Resize(MAX_PATH))
  141. {
  142. hr = HRESULT_FROM_WIN32(GetLastError());
  143. goto Exit;
  144. }
  145. cbSize = m_mszExtraLoggingFields.QuerySize();
  146. if (FAILED(m_pComponent->QueryExtraLoggingFields(
  147. &cbSize,
  148. m_mszExtraLoggingFields.QueryStr())))
  149. {
  150. if (!m_mszExtraLoggingFields.Resize(cbSize))
  151. {
  152. hr = HRESULT_FROM_WIN32(GetLastError());
  153. goto Exit;
  154. }
  155. cbSize = m_mszExtraLoggingFields.QuerySize();
  156. if (FAILED(hr = m_pComponent->QueryExtraLoggingFields(
  157. &cbSize,
  158. m_mszExtraLoggingFields.QueryStr())))
  159. {
  160. goto Exit;
  161. }
  162. }
  163. m_mszExtraLoggingFields.RecalcLen();
  164. Exit:
  165. if (FAILED(hr))
  166. {
  167. if (m_pComponent != NULL)
  168. {
  169. if (fInitializedLog)
  170. {
  171. m_pComponent->TerminateLog();
  172. }
  173. m_pComponent->Release();
  174. m_pComponent = NULL;
  175. }
  176. m_fUlLogType = FALSE;
  177. }
  178. return hr;
  179. }
  180. void LOGGING::LogInformation(
  181. IN LOG_CONTEXT *pInetLogInfo)
  182. {
  183. CInetLogInformation inetLog;
  184. inetLog.CanonicalizeLogRecord(pInetLogInfo);
  185. m_pComponent->LogInformation(&inetLog);
  186. }
  187. // static
  188. HRESULT LOGGING::Initialize()
  189. /*++
  190. Routine Description:
  191. Initialize the logging object by loading the ComLog dll and
  192. set up all the dll entry point
  193. Return Value:
  194. HRESULT
  195. --*/
  196. {
  197. DWORD cbSize = sizeof g_pszComputerName;
  198. if (!GetComputerNameA(g_pszComputerName, &cbSize))
  199. {
  200. strcpy(g_pszComputerName, "<Server>");
  201. }
  202. return S_OK;
  203. }
  204. // static
  205. VOID LOGGING::Terminate()
  206. {
  207. // nothing to do now
  208. }