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.

371 lines
9.3 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. ullog.h (Http.sys Ansi Logging)
  5. Abstract:
  6. This module implements the logging facilities
  7. for Http.sys including the NCSA,IIS and W3C types
  8. of logging.
  9. Author:
  10. Ali E. Turkoglu (aliTu) 10-May-2000
  11. Revision History:
  12. --*/
  13. #ifndef _ULLOG_H_
  14. #define _ULLOG_H_
  15. //
  16. // Forwarders.
  17. //
  18. typedef struct _UL_FULL_TRACKER *PUL_FULL_TRACKER;
  19. typedef struct _UL_INTERNAL_REQUEST *PUL_INTERNAL_REQUEST;
  20. typedef struct _UL_CONFIG_GROUP_OBJECT *PUL_CONFIG_GROUP_OBJECT;
  21. //
  22. // Brief information about how logging locks works; Whole link list is controlled
  23. // by a global EResource g_pUlNonpagedData->LogListResource. Functions that require
  24. // read access to this list are Hit(),CacheHit() & BufferFlush() and the ReCycle().
  25. // Whereas functions that requires write access are Create(),Remove() and ReConfig().
  26. // Also the log entry eresource (EntryResource) controls the per entry buffer.
  27. // This eresource is acquired shared for the log hits.
  28. //
  29. //
  30. // Structure to hold info for a log file
  31. //
  32. typedef struct _UL_LOG_FILE_ENTRY
  33. {
  34. //
  35. // Signature is UL_LOG_FILE_ENTRY_POOL_TAG.
  36. //
  37. ULONG Signature;
  38. //
  39. // This lock protects the whole entry. The ZwWrite operation
  40. // that's called after the lock acquired cannot run at APC_LEVEL
  41. // therefore we have to use push lock to prevent a bugcheck
  42. //
  43. UL_PUSH_LOCK EntryPushLock;
  44. //
  45. // The name of the file. Full path including the directory.
  46. //
  47. UNICODE_STRING FileName;
  48. PWSTR pShortName;
  49. //
  50. // Following will be NULL until a request comes in to the
  51. // site that this entry represents.
  52. //
  53. PUL_LOG_FILE_HANDLE pLogFile;
  54. //
  55. // links all log file entries
  56. //
  57. LIST_ENTRY LogFileListEntry;
  58. //
  59. // Private config info
  60. //
  61. HTTP_LOGGING_TYPE Format;
  62. HTTP_LOGGING_PERIOD Period;
  63. ULONG TruncateSize;
  64. ULONG LogExtFileFlags;
  65. ULONG SiteId;
  66. //
  67. // Time to expire field in terms of Hours.
  68. // This could be at most 24 * 31, that's for monthly
  69. // log cycling. Basically we keep a single periodic hourly
  70. // timer and every time it expires we traverse the
  71. // log list to figure out which log files are expired
  72. // at that time by looking at this fields. And then we
  73. // recylcle the log if necessary.
  74. //
  75. ULONG TimeToExpire;
  76. //
  77. // File for the entry is automatically closed every 15
  78. // minutes. This is to track the idle time.
  79. //
  80. ULONG TimeToClose;
  81. //
  82. // If this entry has MAX_SIZE or UNLIMITED
  83. // log period
  84. //
  85. ULONG SequenceNumber;
  86. ULARGE_INTEGER TotalWritten;
  87. union
  88. {
  89. //
  90. // Flags to show the field states mostly. Used by
  91. // recycling.
  92. //
  93. ULONG Value;
  94. struct
  95. {
  96. ULONG StaleSequenceNumber:1;
  97. ULONG StaleTimeToExpire:1;
  98. ULONG RecyclePending:1;
  99. ULONG LogTitleWritten:1;
  100. ULONG TitleFlushPending:1;
  101. ULONG Active:1;
  102. ULONG LocaltimeRollover:1;
  103. ULONG CreateFileFailureLogged:1;
  104. ULONG WriteFailureLogged:1;
  105. };
  106. } Flags;
  107. //
  108. // Each log file entry keeps a fixed amount of log buffer.
  109. // The buffer size is g_AllocationGranularity comes from
  110. // the system's allocation granularity.
  111. //
  112. PUL_LOG_FILE_BUFFER LogBuffer;
  113. } UL_LOG_FILE_ENTRY, *PUL_LOG_FILE_ENTRY;
  114. #define IS_VALID_LOG_FILE_ENTRY( pEntry ) \
  115. HAS_VALID_SIGNATURE(pEntry, UL_LOG_FILE_ENTRY_POOL_TAG)
  116. //
  117. // CGroup decides on whether logging is enabled for itself or not looking
  118. // at this macro.
  119. //
  120. #define IS_LOGGING_ENABLED(pCgobj) \
  121. ((pCgobj) != NULL && \
  122. (pCgobj)->LoggingConfig.Flags.Present == 1 && \
  123. (pCgobj)->LoggingConfig.LoggingEnabled == TRUE && \
  124. (pCgobj)->pLogFileEntry != NULL)
  125. //
  126. // Followings are all parts of our internal buffer to hold
  127. // the Logging information. We copy over this info from WP
  128. // buffer upon SendResponse request. Yet few of this fields
  129. // are calculated directly by us and filled. The order of
  130. // this fields SHOULD match with the definition of the
  131. // UlFieldTitleLookupTable.
  132. //
  133. typedef enum _UL_LOG_FIELD_TYPE
  134. {
  135. UlLogFieldDate = 0, // 0
  136. UlLogFieldTime,
  137. UlLogFieldSiteName,
  138. UlLogFieldServerName,
  139. UlLogFieldServerIp,
  140. UlLogFieldMethod, // 5
  141. UlLogFieldUriStem,
  142. UlLogFieldUriQuery,
  143. UlLogFieldServerPort,
  144. UlLogFieldUserName,
  145. UlLogFieldClientIp, // 10
  146. UlLogFieldProtocolVersion,
  147. UlLogFieldUserAgent,
  148. UlLogFieldCookie,
  149. UlLogFieldReferrer,
  150. UlLogFieldHost, // 15
  151. UlLogFieldProtocolStatus,
  152. UlLogFieldSubStatus,
  153. UlLogFieldWin32Status,
  154. UlLogFieldBytesSent,
  155. UlLogFieldBytesReceived, // 20
  156. UlLogFieldTimeTaken,
  157. UlLogFieldMaximum
  158. } UL_LOG_FIELD_TYPE, *PUL_LOG_FIELD_TYPE;
  159. //
  160. // Size of the pre-allocated log line buffer inside the request structure.
  161. //
  162. #define UL_MAX_LOG_LINE_BUFFER_SIZE (10*1024)
  163. #define UL_MAX_TITLE_BUFFER_SIZE (512)
  164. //
  165. // To avoid the infinite loop situation we have to set the minimum
  166. // allowable log file size to something bigger than maximum allowable
  167. // log record line.
  168. //
  169. C_ASSERT(HTTP_MIN_ALLOWED_TRUNCATE_SIZE_FOR_LOG_FILE >
  170. (UL_MAX_TITLE_BUFFER_SIZE + UL_MAX_LOG_LINE_BUFFER_SIZE));
  171. //
  172. // If somebody overwrites the default log buffering size which
  173. // is system granularity size of 64K. We have to make sure the
  174. // buffer size is not smaller then miminum allowed. Which is
  175. // MaximumAlowed Logrecord size of 10K. Also it should be 4k
  176. // aligned therefore makes it 12k at least.
  177. //
  178. #define MINIMUM_ALLOWED_LOG_BUFFER_SIZE (12*1024)
  179. C_ASSERT(MINIMUM_ALLOWED_LOG_BUFFER_SIZE >
  180. (UL_MAX_TITLE_BUFFER_SIZE + UL_MAX_LOG_LINE_BUFFER_SIZE));
  181. #define MAXIMUM_ALLOWED_LOG_BUFFER_SIZE (64*1024)
  182. //
  183. // Fix size date and time fields per format.
  184. //
  185. #define W3C_DATE_FIELD_LEN (10)
  186. #define W3C_TIME_FIELD_LEN (8)
  187. #define NCSA_FIX_DATE_AND_TIME_FIELD_SIZE (29)
  188. C_ASSERT(STRLEN_LIT("[07/Jan/2000:00:02:23 -0800] ")
  189. == NCSA_FIX_DATE_AND_TIME_FIELD_SIZE);
  190. #define IIS_MAX_DATE_AND_TIME_FIELD_SIZE (22)
  191. C_ASSERT(STRLEN_LIT("12/31/2002, 17:05:40, ")
  192. == IIS_MAX_DATE_AND_TIME_FIELD_SIZE);
  193. //
  194. // IIS Log line is fragmented at the capture time the offsets
  195. // are as follows and never get changed even if the buffer get
  196. // reallocated. This are default values and only the third
  197. // fragment can get bigger.
  198. //
  199. #define IIS_LOG_LINE_FIRST_FRAGMENT_OFFSET (0)
  200. #define IIS_LOG_LINE_DEFAULT_FIRST_FRAGMENT_ALLOCATION_SIZE (512)
  201. #define IIS_LOG_LINE_SECOND_FRAGMENT_OFFSET (512)
  202. #define IIS_LOG_LINE_DEFAULT_SECOND_FRAGMENT_ALLOCATION_SIZE (512)
  203. #define IIS_LOG_LINE_THIRD_FRAGMENT_OFFSET (1024)
  204. #define IIS_LOG_LINE_DEFAULT_THIRD_FRAGMENT_ALLOCATION_SIZE (3072)
  205. //
  206. // The HTTP Hit Logging functions which we expose in this module.
  207. //
  208. NTSTATUS
  209. UlInitializeLogs(
  210. VOID
  211. );
  212. VOID
  213. UlTerminateLogs(
  214. VOID
  215. );
  216. NTSTATUS
  217. UlSetUTF8Logging (
  218. IN BOOLEAN UTF8Logging
  219. );
  220. NTSTATUS
  221. UlCreateLogEntry(
  222. IN OUT PUL_CONFIG_GROUP_OBJECT pConfigGroup,
  223. IN PHTTP_CONFIG_GROUP_LOGGING pUserConfig
  224. );
  225. VOID
  226. UlRemoveLogEntry(
  227. IN PUL_CONFIG_GROUP_OBJECT pConfigGroup
  228. );
  229. VOID
  230. UlLogTimerHandler(
  231. IN PUL_WORK_ITEM pWorkItem
  232. );
  233. VOID
  234. UlLogTimerDpcRoutine(
  235. PKDPC Dpc,
  236. PVOID DeferredContext,
  237. PVOID SystemArgument1,
  238. PVOID SystemArgument2
  239. );
  240. VOID
  241. UlBufferTimerHandler(
  242. IN PUL_WORK_ITEM pWorkItem
  243. );
  244. VOID
  245. UlBufferTimerDpcRoutine(
  246. PKDPC Dpc,
  247. PVOID DeferredContext,
  248. PVOID SystemArgument1,
  249. PVOID SystemArgument2
  250. );
  251. NTSTATUS
  252. UlReConfigureLogEntry(
  253. IN PUL_CONFIG_GROUP_OBJECT pConfigGroup,
  254. IN PHTTP_CONFIG_GROUP_LOGGING pCfgOld,
  255. IN PHTTP_CONFIG_GROUP_LOGGING pCfgNew
  256. );
  257. NTSTATUS
  258. UlCaptureLogFieldsW3C(
  259. IN PHTTP_LOG_FIELDS_DATA pLogData,
  260. IN PUL_INTERNAL_REQUEST pRequest,
  261. OUT PUL_LOG_DATA_BUFFER *ppLogBuffer
  262. );
  263. NTSTATUS
  264. UlCaptureLogFieldsNCSA(
  265. IN PHTTP_LOG_FIELDS_DATA pLogData,
  266. IN PUL_INTERNAL_REQUEST pRequest,
  267. OUT PUL_LOG_DATA_BUFFER *ppLogBuffer
  268. );
  269. NTSTATUS
  270. UlCaptureLogFieldsIIS(
  271. IN PHTTP_LOG_FIELDS_DATA pLogData,
  272. IN PUL_INTERNAL_REQUEST pRequest,
  273. OUT PUL_LOG_DATA_BUFFER *ppLogBuffer
  274. );
  275. NTSTATUS
  276. UlLogHttpHit(
  277. IN PUL_LOG_DATA_BUFFER pLogBuffer
  278. );
  279. NTSTATUS
  280. UlLogHttpCacheHit(
  281. IN PUL_FULL_TRACKER pTracker
  282. );
  283. NTSTATUS
  284. UlDisableLogEntry(
  285. IN OUT PUL_LOG_FILE_ENTRY pEntry
  286. );
  287. #endif // _ULLOG_H_