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.

427 lines
10 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. rawlogp.h (Centralized Binary (Raw) Logging v1.0)
  5. Abstract:
  6. Private header file for the Binary (Raw) Logging.
  7. Author:
  8. Ali E. Turkoglu (aliTu) 04-Oct-2001
  9. Revision History:
  10. ---
  11. --*/
  12. #ifndef _RAWLOGP_H_
  13. #define _RAWLOGP_H_
  14. ///////////////////////////////////////////////////////////////////////////////
  15. //
  16. // Private definitions for the HTTP Binary Logging Module
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. //
  20. // Only one binary log file allowed.
  21. //
  22. #define IS_BINARY_LOGGING_STARTED() (g_BinaryLogEntryCount != 0)
  23. #define INCREMENT_BINARY_LOGGING_STATE(Started) \
  24. (InterlockedIncrement(&g_BinaryLogEntryCount))
  25. //
  26. // Binary file name related. IBL stands for internet binary log.
  27. //
  28. #define BINARY_LOG_FILE_NAME_PREFIX L"\\raw"
  29. #define BINARY_LOG_FILE_NAME_EXTENSION L"ibl"
  30. #define BINARY_LOG_FILE_NAME_EXTENSION_PLUS_DOT L".ibl"
  31. //
  32. // Buffering related....
  33. //
  34. #define DEFAULT_BINARY_LOG_FILE_BUFFER_SIZE (0x00010000)
  35. //
  36. // Buffer flush out period in minutes.
  37. //
  38. #define DEFAULT_BINARY_LOG_BUFFER_TIMER_PERIOD_IN_MIN (1)
  39. //
  40. // To be able to limit the binary log index record size, we have
  41. // to enforce a certain limit to the length of the strings.
  42. //
  43. #define MAX_BINARY_LOG_INDEX_STRING_LEN (4096)
  44. //
  45. // UserName field has its own field limitation.
  46. //
  47. #define MAX_BINARY_LOG_URL_STRING_LEN (4096)
  48. #define MAX_BINARY_LOG_USERNAME_STRING_LEN (256)
  49. //
  50. // Two macros for getting abs path (and its size) from uri cache entry.
  51. //
  52. #define URI_SIZE_FROM_CACHE(UriKey) \
  53. ((UriKey).Length - ((UriKey).pPath ? \
  54. (DIFF((UriKey).pPath - (UriKey).pUri) * sizeof(WCHAR)) : 0))
  55. #define URI_FROM_CACHE(UriKey) \
  56. ((UriKey).pPath ? (UriKey).pPath : (UriKey).pUri)
  57. ///////////////////////////////////////////////////////////////////////////////
  58. //
  59. // Private function calls
  60. //
  61. ///////////////////////////////////////////////////////////////////////////////
  62. NTSTATUS
  63. UlpDisableBinaryEntry(
  64. IN OUT PUL_BINARY_LOG_FILE_ENTRY pEntry
  65. );
  66. NTSTATUS
  67. UlpRecycleBinaryLogFile(
  68. IN OUT PUL_BINARY_LOG_FILE_ENTRY pEntry
  69. );
  70. NTSTATUS
  71. UlpHandleBinaryLogFileRecycle(
  72. IN OUT PVOID pContext
  73. );
  74. NTSTATUS
  75. UlpCreateBinaryLogFile(
  76. IN OUT PUL_BINARY_LOG_FILE_ENTRY pEntry,
  77. IN PUNICODE_STRING pDirectory
  78. );
  79. __inline
  80. UCHAR
  81. UlpHttpVersionToBinaryLogVersion(
  82. IN HTTP_VERSION version
  83. )
  84. {
  85. if (HTTP_EQUAL_VERSION(version, 0, 9))
  86. {
  87. return BINARY_LOG_PROTOCOL_VERSION_HTTP09;
  88. }
  89. else if (HTTP_EQUAL_VERSION(version, 1, 0))
  90. {
  91. return BINARY_LOG_PROTOCOL_VERSION_HTTP10;
  92. }
  93. else if (HTTP_EQUAL_VERSION(version, 1, 1))
  94. {
  95. return BINARY_LOG_PROTOCOL_VERSION_HTTP11;
  96. }
  97. return BINARY_LOG_PROTOCOL_VERSION_UNKNWN;
  98. }
  99. ULONG
  100. UlpRawCopyLogHeader(
  101. IN PUCHAR pBuffer
  102. );
  103. ULONG
  104. UlpRawCopyLogFooter(
  105. IN PUCHAR pBuffer
  106. );
  107. VOID
  108. UlpRawCopyCacheNotification(
  109. IN PVOID pContext,
  110. IN PUCHAR pBuffer,
  111. IN ULONG BytesRequired
  112. );
  113. VOID
  114. UlpRawCopyForLogCacheMiss(
  115. IN PVOID pContext,
  116. IN PUCHAR pBuffer,
  117. IN ULONG BytesRequired
  118. );
  119. VOID
  120. UlpRawCopyForLogCacheHit(
  121. IN PVOID pContext,
  122. IN PUCHAR pBuffer,
  123. IN ULONG BytesRequired
  124. );
  125. typedef
  126. VOID
  127. (*PUL_RAW_LOG_COPIER)(
  128. IN PVOID pContext,
  129. IN PUCHAR pBuffer,
  130. IN ULONG BytesRequired
  131. );
  132. VOID
  133. UlpEventLogRawWriteFailure(
  134. IN PUL_BINARY_LOG_FILE_ENTRY pEntry,
  135. IN NTSTATUS Status
  136. );
  137. NTSTATUS
  138. UlpFlushRawLogFile(
  139. IN PUL_BINARY_LOG_FILE_ENTRY pEntry
  140. );
  141. __inline
  142. NTSTATUS
  143. UlpCheckRawFile(
  144. IN OUT PUL_BINARY_LOG_FILE_ENTRY pEntry,
  145. IN PUL_CONTROL_CHANNEL pControlChannel
  146. )
  147. {
  148. NTSTATUS Status = STATUS_SUCCESS;
  149. PUNICODE_STRING pDirectory = NULL;
  150. ASSERT(IS_VALID_CONTROL_CHANNEL(pControlChannel));
  151. ASSERT(IS_VALID_BINARY_LOG_FILE_ENTRY(pEntry));
  152. //
  153. // We can grap the file buffer and do our copy in place while holding the
  154. // entry lock shared. This will prevent the buffer flush and the extra copy.
  155. // But first let's see if we have to create/open the file.
  156. //
  157. if (!pEntry->Flags.Active)
  158. {
  159. UlAcquirePushLockExclusive(&pEntry->PushLock);
  160. //
  161. // Ping again to see if we have been blocked on the lock, and
  162. // somebody else already took care of the creation.
  163. //
  164. if (!pEntry->Flags.Active)
  165. {
  166. //
  167. // It's possible that LogFileDir.Buffer could be NULL,
  168. // if the allocation failed during the Set cgroup ioctl.
  169. //
  170. pDirectory = &pControlChannel->BinaryLoggingConfig.LogFileDir;
  171. if (pDirectory->Buffer)
  172. {
  173. Status = UlpCreateBinaryLogFile(pEntry, pDirectory);
  174. }
  175. else
  176. {
  177. Status = STATUS_INVALID_PARAMETER;
  178. }
  179. }
  180. UlReleasePushLockExclusive(&pEntry->PushLock);
  181. if (!NT_SUCCESS(Status))
  182. {
  183. return Status;
  184. }
  185. }
  186. return Status;
  187. }
  188. /***************************************************************************++
  189. Routine Description:
  190. When the log file is on size based recycling and if we write this new
  191. record to the file, we have to recycle. This function returns TRUE.
  192. Otherwise it returns FALSE.
  193. Arguments:
  194. pEntry: The log file entry.
  195. NewRecordSize: The size of the new record going to the buffer. (Bytes)
  196. --***************************************************************************/
  197. __inline
  198. BOOLEAN
  199. UlpIsRawLogFileOverFlow(
  200. IN PUL_BINARY_LOG_FILE_ENTRY pEntry,
  201. IN ULONG NewRecordSize
  202. )
  203. {
  204. if (pEntry->Period != HttpLoggingPeriodMaxSize ||
  205. pEntry->TruncateSize == HTTP_LIMIT_INFINITE)
  206. {
  207. return FALSE;
  208. }
  209. else
  210. {
  211. //
  212. // BufferUsed: Amount of log buffer we are >currently< using.
  213. //
  214. ULONG BufferUsed = 0;
  215. if (pEntry->LogBuffer)
  216. {
  217. BufferUsed = pEntry->LogBuffer->BufferUsed;
  218. }
  219. //
  220. // TotalWritten get updated >only< with buffer flush. Therefore
  221. // we have to pay attention to the buffer used.
  222. //
  223. if ((pEntry->TotalWritten.QuadPart
  224. + (ULONGLONG) BufferUsed
  225. + (ULONGLONG) NewRecordSize
  226. ) >= (ULONGLONG) pEntry->TruncateSize)
  227. {
  228. UlTrace(BINARY_LOGGING,
  229. ("Http!UlpIsRawLogFileOverFlow: pEntry %p FileBuffer %p "
  230. "TW:%I64d B:%d R:%d T:%d\n",
  231. pEntry,
  232. pEntry->LogBuffer,
  233. pEntry->TotalWritten.QuadPart,
  234. BufferUsed,
  235. NewRecordSize,
  236. pEntry->TruncateSize
  237. ));
  238. return TRUE;
  239. }
  240. else
  241. {
  242. return FALSE;
  243. }
  244. }
  245. }
  246. /***************************************************************************++
  247. Routine Description:
  248. This will calculate the index record size for a given cache entry.
  249. Arguments:
  250. pUriEntry: The uri cache entry.
  251. Returns
  252. The index record size.
  253. --***************************************************************************/
  254. __inline
  255. ULONG
  256. UlpGetIndexRecordSize(
  257. IN PUL_URI_CACHE_ENTRY pUriEntry
  258. )
  259. {
  260. ULONG IndexBytes;
  261. ULONG UriSize;
  262. ASSERT(IS_VALID_URI_CACHE_ENTRY(pUriEntry));
  263. UriSize = URI_SIZE_FROM_CACHE(pUriEntry->UriKey) ;
  264. ASSERT(UriSize != 0); // We cannot write an index for nothing
  265. IndexBytes = sizeof(HTTP_RAW_INDEX_FIELD_DATA);
  266. //
  267. // Carefull with the inlined part, the 4 bytes of
  268. // the uri will be inlined inside the index struct.
  269. //
  270. if (UriSize > URI_BYTES_INLINED)
  271. {
  272. IndexBytes += ALIGN_UP((UriSize - URI_BYTES_INLINED),PVOID);
  273. }
  274. ASSERT(IndexBytes == ALIGN_UP(IndexBytes, PVOID));
  275. return IndexBytes;
  276. }
  277. NTSTATUS
  278. UlpWriteToRawLogFileDebug(
  279. IN PUL_BINARY_LOG_FILE_ENTRY pEntry,
  280. IN ULONG BytesRequired,
  281. IN PUL_RAW_LOG_COPIER pBufferWritter,
  282. IN PVOID pContext,
  283. OUT PLONG pBinaryIndexWritten
  284. );
  285. NTSTATUS
  286. UlpWriteToRawLogFileShared(
  287. IN PUL_BINARY_LOG_FILE_ENTRY pEntry,
  288. IN ULONG BytesRequired,
  289. IN PUL_RAW_LOG_COPIER pBufferWritter,
  290. IN PVOID pContext,
  291. OUT PLONG pBinaryIndexWritten
  292. );
  293. NTSTATUS
  294. UlpWriteToRawLogFileExclusive(
  295. IN PUL_BINARY_LOG_FILE_ENTRY pEntry,
  296. IN ULONG BytesRequired,
  297. IN PUL_RAW_LOG_COPIER pBufferWritter,
  298. IN PVOID pContext,
  299. OUT PLONG pBinaryIndexWritten
  300. );
  301. NTSTATUS
  302. UlpWriteToRawLogFile(
  303. IN PUL_BINARY_LOG_FILE_ENTRY pEntry,
  304. IN PUL_URI_CACHE_ENTRY pUriEntry,
  305. IN ULONG RecordSize,
  306. IN PUL_RAW_LOG_COPIER pBufferWritter,
  307. IN PVOID pContext
  308. );
  309. VOID
  310. UlpBinaryBufferTimerDpcRoutine(
  311. PKDPC Dpc,
  312. PVOID DeferredContext,
  313. PVOID SystemArgument1,
  314. PVOID SystemArgument2
  315. );
  316. VOID
  317. UlpBinaryBufferTimerHandler(
  318. IN PUL_WORK_ITEM pWorkItem
  319. );
  320. VOID
  321. UlpBinaryLogTimerDpcRoutine(
  322. PKDPC Dpc,
  323. PVOID DeferredContext,
  324. PVOID SystemArgument1,
  325. PVOID SystemArgument2
  326. );
  327. VOID
  328. UlpBinaryLogTimerHandler(
  329. IN PUL_WORK_ITEM pWorkItem
  330. );
  331. #endif // _RAWLOGP_H_