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.

515 lines
11 KiB

  1. /*++
  2. Copyright (c) 1995-1996 Microsoft Corporation
  3. Module Name :
  4. Logging.cxx
  5. Abstract:
  6. Server Side logging object
  7. It is just a thin layer to call COMLOG
  8. Author:
  9. Terence Kwan ( terryk ) 18-Sep-1996
  10. Project:
  11. IIS Logging 3.0
  12. --*/
  13. #include "server.hxx"
  14. #define SZ_COMLOG_DLL "iscomlog.dll"
  15. //
  16. // Global dll entry points
  17. //
  18. P_ComLogInitializeLog LOGGING::m_ComLogInitializeLog = NULL;
  19. P_ComLogTerminateLog LOGGING::m_ComLogTerminateLog = NULL;
  20. P_ComLogLogInformation LOGGING::m_ComLogLogInformation = NULL;
  21. P_ComLogGetConfig LOGGING::m_ComLogGetConfig = NULL;
  22. P_ComLogSetConfig LOGGING::m_ComLogSetConfig = NULL;
  23. P_ComLogQueryExtraLogFields LOGGING::m_ComLogQueryExtraLogFields = NULL;
  24. P_ComLogNotifyChange LOGGING::m_ComLogNotifyChange = NULL;
  25. P_ComLogCustomInformation LOGGING::m_ComLogCustomInformation = NULL;
  26. //
  27. // initialize comlog modules
  28. //
  29. HINSTANCE LOGGING::m_hComLogDLL = NULL;
  30. P_ComLogDllStartup LOGGING::m_ComLogDllStartup = NULL;
  31. P_ComLogDllCleanUp LOGGING::m_ComLogDllCleanUp = NULL;
  32. HANDLE Dummy_ComLogInitializeLog( LPCSTR, LPCSTR, LPVOID )
  33. {
  34. return(NULL);
  35. }
  36. DWORD
  37. Dummy_ComLogTerminateLog(
  38. IN HANDLE
  39. )
  40. {
  41. return(ERROR_PROC_NOT_FOUND);
  42. }
  43. DWORD
  44. Dummy_ComLogLogInformation(
  45. HANDLE,
  46. const INETLOG_INFORMATION *
  47. )
  48. {
  49. return(ERROR_PROC_NOT_FOUND);
  50. }
  51. DWORD Dummy_ComLogGetConfig( HANDLE, INETLOG_CONFIGURATIONA * )
  52. {
  53. return(ERROR_PROC_NOT_FOUND);
  54. }
  55. DWORD Dummy_ComLogSetConfig( HANDLE, const INETLOG_CONFIGURATIONA * )
  56. {
  57. return(ERROR_PROC_NOT_FOUND);
  58. }
  59. DWORD
  60. Dummy_ComLogQueryExtraLogFields(
  61. HANDLE,
  62. PCHAR,
  63. PDWORD
  64. )
  65. {
  66. return(ERROR_PROC_NOT_FOUND);
  67. }
  68. DWORD Dummy_ComLogDllCleanUp()
  69. {
  70. return(ERROR_PROC_NOT_FOUND);
  71. }
  72. DWORD Dummy_ComLogNotifyChange( HANDLE )
  73. {
  74. return(ERROR_PROC_NOT_FOUND);
  75. }
  76. DWORD
  77. Dummy_ComLogCustomInformation(
  78. IN HANDLE,
  79. IN DWORD,
  80. IN PCUSTOM_LOG_DATA,
  81. IN LPSTR
  82. )
  83. {
  84. return(ERROR_PROC_NOT_FOUND);
  85. }
  86. /* ------------------------------------------------------------------------------ */
  87. LOGGING::LOGGING(
  88. VOID
  89. )
  90. /*++
  91. Routine Description:
  92. Contructor for the logging object.
  93. Arguments:
  94. lpszInstanceName - name of the instance. ie, w3svc
  95. dwInstanceId - id of the instance
  96. Return Value:
  97. --*/
  98. {
  99. m_Handle = NULL;
  100. m_fRequiredExtraLoggingFields = FALSE;
  101. m_szExtraLoggingFields[0] = '\0';
  102. m_fMetabaseModified = FALSE;
  103. }
  104. LOGGING::~LOGGING()
  105. /*++
  106. Routine Description:
  107. Destructor for the logging object.
  108. Arguments:
  109. Return Value:
  110. --*/
  111. {
  112. //
  113. // end of logging object
  114. //
  115. ShutdownLogging();
  116. }
  117. BOOL
  118. LOGGING::ActivateLogging(
  119. IN LPCSTR pszServiceName,
  120. IN DWORD dwInstanceId,
  121. IN LPCSTR pszMetabasePath,
  122. IN LPVOID pvIMDCOM
  123. )
  124. {
  125. CHAR tmpBuf[MAX_PATH];
  126. LockExclusive();
  127. wsprintf(tmpBuf,"%s%u", pszServiceName, dwInstanceId);
  128. m_strInstanceName.Copy(tmpBuf);
  129. m_strMetabasePath.Copy(pszMetabasePath);
  130. m_pvIMDCOM = pvIMDCOM;
  131. ShutdownLogging(); // Shut down all previous handles.
  132. if ( m_ComLogInitializeLog != NULL ) {
  133. m_Handle = (*m_ComLogInitializeLog)(
  134. m_strInstanceName.QueryStr(),
  135. m_strMetabasePath.QueryStr(),
  136. pvIMDCOM
  137. );
  138. }
  139. if (m_Handle != NULL ) {
  140. DWORD cbSize = sizeof(m_szExtraLoggingFields);
  141. (*m_ComLogQueryExtraLogFields)(
  142. m_Handle,
  143. m_szExtraLoggingFields,
  144. &cbSize
  145. );
  146. m_fRequiredExtraLoggingFields =
  147. (m_szExtraLoggingFields[0] != '\0');
  148. }
  149. Unlock();
  150. return TRUE;
  151. } // LOGGING::ActivateLogging
  152. BOOL
  153. LOGGING::ShutdownLogging()
  154. /*++
  155. Routine Description:
  156. Terminate the log configuration information.
  157. Arguments:
  158. Return Value:
  159. err - error code.
  160. It will return NERR_Success if no error
  161. --*/
  162. {
  163. // if we have not terminated yet, terminate it
  164. LockExclusive();
  165. if (m_Handle != NULL)
  166. {
  167. (*m_ComLogTerminateLog)( m_Handle );
  168. m_Handle = NULL;
  169. }
  170. Unlock();
  171. return(TRUE);
  172. }
  173. BOOL
  174. LOGGING::NotifyChange(
  175. DWORD PropertyID
  176. )
  177. /*++
  178. Routine Description:
  179. Notify change in the log configuration information.
  180. Arguments:
  181. PropertyID - property ID, or zero to signal end of changes
  182. Return Value:
  183. err - error code.
  184. It will return NERR_Success if no error
  185. --*/
  186. {
  187. LockExclusive();
  188. if ( ((PropertyID >= IIS_MD_LOG_BASE) && (PropertyID <= IIS_MD_LOG_LAST)) ||
  189. ((PropertyID >= IIS_MD_LOGCUSTOM_BASE) && (PropertyID <= IIS_MD_LOGCUSTOM_LAST))
  190. )
  191. {
  192. m_fMetabaseModified = TRUE;
  193. }
  194. Unlock();
  195. return(TRUE);
  196. }
  197. DWORD
  198. LOGGING::LogInformation(
  199. IN const INETLOG_INFORMATION * pInetLogInfo
  200. )
  201. {
  202. DWORD dwErr;
  203. if ( m_fMetabaseModified )
  204. {
  205. ActOnChange();
  206. }
  207. LockShared();
  208. dwErr = ((*m_ComLogLogInformation)( m_Handle, pInetLogInfo ));
  209. Unlock();
  210. return dwErr;
  211. } // LOGGING::LogInformation
  212. DWORD
  213. LOGGING::LogCustomInformation(
  214. IN DWORD cCount,
  215. IN PCUSTOM_LOG_DATA pCustomLogData,
  216. IN LPSTR szHeaderSuffix
  217. )
  218. {
  219. DWORD dwErr;
  220. if ( m_fMetabaseModified )
  221. {
  222. ActOnChange();
  223. }
  224. LockShared();
  225. dwErr = ((*m_ComLogCustomInformation)( m_Handle, cCount, pCustomLogData, szHeaderSuffix));
  226. Unlock();
  227. return dwErr;
  228. }
  229. DWORD
  230. LOGGING::GetConfig(
  231. INETLOG_CONFIGURATIONA *pLogConfig
  232. )
  233. {
  234. DWORD dwErr;
  235. if ( m_fMetabaseModified )
  236. {
  237. ActOnChange();
  238. }
  239. LockShared();
  240. dwErr = ((*m_ComLogGetConfig)( m_Handle, pLogConfig ));
  241. Unlock();
  242. return dwErr;
  243. }
  244. BOOL LOGGING::IsRequiredExtraLoggingFields()
  245. {
  246. if ( m_fMetabaseModified )
  247. {
  248. ActOnChange();
  249. }
  250. return m_fRequiredExtraLoggingFields;
  251. }
  252. CHAR *LOGGING::QueryExtraLoggingFields()
  253. {
  254. if ( m_fMetabaseModified )
  255. {
  256. ActOnChange();
  257. }
  258. return m_szExtraLoggingFields;
  259. }
  260. VOID
  261. LOGGING::ActOnChange()
  262. {
  263. LockExclusive();
  264. if ( m_fMetabaseModified )
  265. {
  266. if (m_ComLogNotifyChange != NULL) {
  267. DWORD cbSize = sizeof(m_szExtraLoggingFields);
  268. (*m_ComLogNotifyChange)( m_Handle );
  269. //
  270. // See if we need extra log fields
  271. //
  272. (*m_ComLogQueryExtraLogFields)(
  273. m_Handle,
  274. m_szExtraLoggingFields,
  275. &cbSize
  276. );
  277. m_fRequiredExtraLoggingFields =
  278. (m_szExtraLoggingFields[0] != '\0');
  279. }
  280. m_fMetabaseModified = FALSE;
  281. }
  282. Unlock();
  283. }
  284. DWORD
  285. LOGGING::SetConfig(
  286. INETLOG_CONFIGURATIONA *pRpcLogConfig
  287. )
  288. {
  289. DWORD cbSize = sizeof(m_szExtraLoggingFields);
  290. LockExclusive();
  291. DWORD dwReturn = (*m_ComLogSetConfig)( m_Handle, pRpcLogConfig );
  292. (*m_ComLogQueryExtraLogFields)(
  293. m_Handle,
  294. m_szExtraLoggingFields,
  295. &cbSize
  296. );
  297. m_fRequiredExtraLoggingFields =
  298. (m_szExtraLoggingFields[0] != '\0');
  299. Unlock();
  300. return(dwReturn);
  301. }
  302. //
  303. // Statics
  304. //
  305. DWORD
  306. LOGGING::Terminate()
  307. /*++
  308. Routine Description:
  309. Terminate the logging object and kill the waiting queue.
  310. Arguments:
  311. Return Value:
  312. always return NO_ERROR
  313. --*/
  314. {
  315. if ( m_hComLogDLL != NULL ) {
  316. DBGPRINTF((DBG_CONTEXT,"Terminate: Freed iscomlog.dll\n"));
  317. //
  318. // call ComLog to terminate itself
  319. //
  320. (*m_ComLogDllCleanUp)();
  321. FreeLibrary( m_hComLogDLL );
  322. m_hComLogDLL = NULL;
  323. }
  324. return(NO_ERROR);
  325. }
  326. DWORD
  327. LOGGING::Initialize()
  328. /*++
  329. Routine Description:
  330. Initialize the logging object by loading the ComLog dll and
  331. set up all the dll entry point
  332. Arguments:
  333. Return Value:
  334. return NO_ERROR if no error
  335. otherwise return ERROR_DLL_NOT_FOUND or ERROR_PROC_NOT_FOUND
  336. --*/
  337. {
  338. DWORD err = NO_ERROR;
  339. DBG_ASSERT(m_hComLogDLL == NULL);
  340. m_hComLogDLL = LoadLibrary( SZ_COMLOG_DLL );
  341. if (m_hComLogDLL!=NULL)
  342. {
  343. if ((( m_ComLogInitializeLog = (P_ComLogInitializeLog)GetProcAddress( m_hComLogDLL, (const char *)"ComLogInitializeLog")) == NULL ) ||
  344. (( m_ComLogTerminateLog = (P_ComLogTerminateLog)GetProcAddress( m_hComLogDLL, (const char *)"ComLogTerminateLog")) == NULL ) ||
  345. (( m_ComLogLogInformation = (P_ComLogLogInformation)GetProcAddress( m_hComLogDLL, (const char *)"ComLogLogInformation"))== NULL ) ||
  346. (( m_ComLogGetConfig = (P_ComLogGetConfig)GetProcAddress( m_hComLogDLL, (const char *)"ComLogGetConfig"))== NULL ) ||
  347. (( m_ComLogSetConfig = (P_ComLogSetConfig)GetProcAddress( m_hComLogDLL, (const char *)"ComLogSetConfig"))== NULL ) ||
  348. (( m_ComLogQueryExtraLogFields = (P_ComLogQueryExtraLogFields)GetProcAddress( m_hComLogDLL, (const char *)"ComLogQueryExtraLogFields"))== NULL ) ||
  349. (( m_ComLogDllStartup = (P_ComLogDllStartup)GetProcAddress(m_hComLogDLL, (const char *)"ComLogDllStartup"))== NULL ) ||
  350. (( m_ComLogNotifyChange = (P_ComLogNotifyChange)GetProcAddress(m_hComLogDLL, (const char *)"ComLogNotifyChange"))== NULL ) ||
  351. (( m_ComLogDllCleanUp = (P_ComLogDllCleanUp)GetProcAddress(m_hComLogDLL, (const char *)"ComLogDllCleanUp"))== NULL ) ||
  352. (( m_ComLogCustomInformation = (P_ComLogCustomInformation)GetProcAddress(m_hComLogDLL, (const char *)"ComLogCustomInformation"))== NULL )
  353. )
  354. {
  355. DBGPRINTF((DBG_CONTEXT,"missing entry point in ComLog dll\n"));
  356. m_ComLogInitializeLog = &(Dummy_ComLogInitializeLog );
  357. m_ComLogTerminateLog = &(Dummy_ComLogTerminateLog );
  358. m_ComLogLogInformation = &(Dummy_ComLogLogInformation );
  359. m_ComLogGetConfig = &(Dummy_ComLogGetConfig );
  360. m_ComLogSetConfig = &(Dummy_ComLogSetConfig );
  361. m_ComLogDllCleanUp = &(Dummy_ComLogDllCleanUp );
  362. m_ComLogNotifyChange = &(Dummy_ComLogNotifyChange );
  363. m_ComLogQueryExtraLogFields = &(Dummy_ComLogQueryExtraLogFields );
  364. m_ComLogCustomInformation = &(Dummy_ComLogCustomInformation );
  365. err = ERROR_PROC_NOT_FOUND;
  366. } else {
  367. //
  368. // Initialize ComLog
  369. //
  370. err = (*m_ComLogDllStartup)();
  371. }
  372. } else {
  373. DBGPRINTF((DBG_CONTEXT,"Failed to load iscomlog.dll\n"));
  374. err = ERROR_DLL_NOT_FOUND;
  375. }
  376. return(err);
  377. }