Source code of Windows XP (NT5)
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.

231 lines
5.1 KiB

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