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.

435 lines
9.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name :
  4. logobj.cxx
  5. Abstract:
  6. Log COM Object
  7. Author:
  8. Johnson Apacible (JohnsonA) 02-April-1997
  9. --*/
  10. #include "precomp.hxx"
  11. #include "comlog.hxx"
  12. CInetLogInformation::CInetLogInformation(
  13. VOID
  14. ):
  15. m_refCount ( 0),
  16. m_szClientAddress ( NULL),
  17. m_szServerAddress ( NULL),
  18. m_szUserName ( NULL),
  19. m_szOperation ( NULL),
  20. m_szTarget ( NULL),
  21. m_szParameters ( NULL),
  22. m_szHTTPHeaders ( NULL),
  23. m_szVersion ( NULL),
  24. m_cbSiteName ( 0),
  25. m_cbComputerName ( 0),
  26. m_cbServerAddress ( 0),
  27. m_cbClientAddress ( 0),
  28. m_cbUserName ( 0),
  29. m_cbOperation ( 0),
  30. m_cbTarget ( 0),
  31. m_cbParameters ( 0),
  32. m_cbHTTPHeaders ( 0),
  33. m_cbVersion ( 0),
  34. m_dwPort ( 0),
  35. m_msProcessingTime ( 0),
  36. m_dwWin32Status ( 0),
  37. m_dwProtocolStatus ( 0),
  38. m_bytesSent ( 0),
  39. m_bytesRecv ( 0)
  40. {
  41. m_szSiteName[0] = '\0';
  42. m_szComputerName[0] = '\0';
  43. } // CInetLogInformation::CInetLogInformation
  44. CInetLogInformation::~CInetLogInformation(
  45. VOID
  46. )
  47. {
  48. } // CInetLogInformation::~CInetLogInformation
  49. ULONG
  50. CInetLogInformation::AddRef(
  51. VOID
  52. )
  53. {
  54. InterlockedIncrement( &m_refCount );
  55. return(m_refCount);
  56. } // CInetLogInformation::AddRef
  57. ULONG
  58. CInetLogInformation::Release(
  59. VOID
  60. )
  61. {
  62. InterlockedDecrement( &m_refCount );
  63. return(m_refCount);
  64. } // CInetLogInformation::Release
  65. HRESULT
  66. CInetLogInformation::QueryInterface(
  67. REFIID riid,
  68. VOID **ppObj
  69. )
  70. {
  71. if ( riid == IID_IUnknown ||
  72. riid == IID_IINETLOG_INFORMATION ) {
  73. *ppObj = (CInetLogInformation *)this;
  74. AddRef();
  75. return(NO_ERROR);
  76. } else {
  77. return(E_NOINTERFACE);
  78. }
  79. } // CInetLogInformation::QueryInterface
  80. #define RETURN_STRING_INFO( _pBuf, _pcbBuf, _pInfo, _cbInfo ) { \
  81. if ( (_pBuf) != NULL ) { \
  82. \
  83. if ( *(_pcbBuf) >= (_cbInfo) ) { \
  84. CopyMemory( _pBuf, _pInfo, _cbInfo ); \
  85. } else { \
  86. *(_pcbBuf) = (_cbInfo); \
  87. return(NULL); \
  88. } \
  89. } \
  90. *(_pcbBuf) = (_cbInfo); \
  91. return(_pInfo); \
  92. }
  93. LPSTR STDMETHODCALLTYPE
  94. CInetLogInformation::GetSiteName(
  95. IN PCHAR pszSiteName,
  96. IN PDWORD pcbSize
  97. )
  98. {
  99. RETURN_STRING_INFO(
  100. pszSiteName,
  101. pcbSize,
  102. m_szSiteName,
  103. m_cbSiteName);
  104. } // GetSiteName
  105. LPSTR STDMETHODCALLTYPE
  106. CInetLogInformation::GetComputerName(
  107. IN PCHAR pszComputerName,
  108. IN PDWORD pcbSize
  109. )
  110. {
  111. RETURN_STRING_INFO(
  112. pszComputerName,
  113. pcbSize,
  114. m_szComputerName,
  115. m_cbComputerName);
  116. } // GetComputerName
  117. LPSTR STDMETHODCALLTYPE
  118. CInetLogInformation::GetClientHostName(
  119. IN PCHAR pszClientHostName,
  120. IN PDWORD pcbSize
  121. )
  122. {
  123. RETURN_STRING_INFO(
  124. pszClientHostName,
  125. pcbSize,
  126. m_szClientAddress,
  127. m_cbClientAddress);
  128. } // GetClientHostName
  129. LPSTR STDMETHODCALLTYPE
  130. CInetLogInformation::GetClientUserName(
  131. IN PCHAR pszClientUserName,
  132. IN PDWORD pcbSize
  133. )
  134. {
  135. RETURN_STRING_INFO(
  136. pszClientUserName,
  137. pcbSize,
  138. m_szUserName,
  139. m_cbUserName);
  140. } // GetClientUserName
  141. LPSTR STDMETHODCALLTYPE
  142. CInetLogInformation::GetServerAddress(
  143. IN PCHAR pszServerAddress,
  144. IN PDWORD pcbSize
  145. )
  146. {
  147. RETURN_STRING_INFO(
  148. pszServerAddress,
  149. pcbSize,
  150. m_szServerAddress,
  151. m_cbServerAddress);
  152. } // GetServerIPAddress
  153. LPSTR STDMETHODCALLTYPE
  154. CInetLogInformation::GetOperation(
  155. IN PCHAR pszOperation,
  156. IN PDWORD pcbSize
  157. )
  158. {
  159. RETURN_STRING_INFO(
  160. pszOperation,
  161. pcbSize,
  162. m_szOperation,
  163. m_cbOperation);
  164. } // GetOperation
  165. LPSTR STDMETHODCALLTYPE
  166. CInetLogInformation::GetTarget(
  167. IN PCHAR pszTarget,
  168. IN PDWORD pcbSize
  169. )
  170. {
  171. RETURN_STRING_INFO(
  172. pszTarget,
  173. pcbSize,
  174. m_szTarget,
  175. m_cbTarget);
  176. } // GetTarget
  177. LPSTR STDMETHODCALLTYPE
  178. CInetLogInformation::GetParameters(
  179. IN PCHAR pszParameters,
  180. IN PDWORD pcbSize
  181. )
  182. {
  183. RETURN_STRING_INFO(
  184. pszParameters,
  185. pcbSize,
  186. m_szParameters,
  187. m_cbParameters);
  188. } // GetParameters
  189. LPSTR STDMETHODCALLTYPE
  190. CInetLogInformation::GetExtraHTTPHeaders(
  191. IN PCHAR pszHTTPHeaders,
  192. IN PDWORD pcbSize
  193. )
  194. {
  195. RETURN_STRING_INFO(
  196. pszHTTPHeaders,
  197. pcbSize,
  198. m_szHTTPHeaders,
  199. m_cbHTTPHeaders);
  200. } // GetExtraHTTPHeaders
  201. DWORD STDMETHODCALLTYPE
  202. CInetLogInformation::GetTimeForProcessing(
  203. VOID
  204. )
  205. {
  206. return(m_msProcessingTime);
  207. } // GetTimeForProcessing
  208. DWORD STDMETHODCALLTYPE
  209. CInetLogInformation::GetPortNumber(
  210. VOID
  211. )
  212. {
  213. return(m_dwPort);
  214. } // GetPortNumber
  215. DWORD STDMETHODCALLTYPE
  216. CInetLogInformation::GetBytesSent(
  217. VOID
  218. )
  219. {
  220. return(m_bytesSent);
  221. } // GetBytesSent
  222. DWORD STDMETHODCALLTYPE
  223. CInetLogInformation::GetBytesRecvd(
  224. VOID
  225. )
  226. {
  227. return(m_bytesRecv);
  228. } // GetBytesRecvd
  229. DWORD STDMETHODCALLTYPE
  230. CInetLogInformation::GetWin32Status(
  231. VOID
  232. )
  233. {
  234. return(m_dwWin32Status);
  235. } // GetWin32Status
  236. DWORD STDMETHODCALLTYPE
  237. CInetLogInformation::GetProtocolStatus(
  238. VOID
  239. )
  240. {
  241. return(m_dwProtocolStatus);
  242. } // GetProtocolStatus
  243. LPSTR STDMETHODCALLTYPE
  244. CInetLogInformation::GetVersionString(
  245. IN PCHAR pszVersionString,
  246. IN PDWORD pcbSize
  247. )
  248. {
  249. RETURN_STRING_INFO(
  250. pszVersionString,
  251. pcbSize,
  252. m_szVersion,
  253. m_cbVersion);
  254. } //GetVersionString
  255. CHAR szNULL[] = "";
  256. CHAR szDotDot[] = "...";
  257. VOID
  258. CInetLogInformation::CanonicalizeLogRecord(
  259. IN INETLOG_INFORMATION * pInetLogRecord,
  260. IN LPCSTR pszSiteName,
  261. IN LPCSTR pszComputerName,
  262. IN BOOL fDefault
  263. )
  264. {
  265. m_szClientAddress = pInetLogRecord->pszClientHostName;
  266. if ( m_szClientAddress == NULL ) {
  267. m_szClientAddress = szNULL;
  268. m_cbClientAddress = 0;
  269. } else {
  270. m_cbClientAddress = pInetLogRecord->cbClientHostName;
  271. }
  272. m_szOperation = pInetLogRecord->pszOperation;
  273. if ( m_szOperation == NULL ) {
  274. m_szOperation = szNULL;
  275. m_cbOperation = 0;
  276. } else {
  277. m_cbOperation = pInetLogRecord->cbOperation;
  278. if ( m_cbOperation > MAX_LOG_OPERATION_FIELD_LEN ) {
  279. m_cbOperation = MAX_LOG_OPERATION_FIELD_LEN;
  280. }
  281. }
  282. m_szTarget = pInetLogRecord->pszTarget;
  283. if ( m_szTarget == NULL ) {
  284. m_szTarget = szNULL;
  285. m_cbTarget = 0;
  286. } else {
  287. m_cbTarget = pInetLogRecord->cbTarget;
  288. if ( m_cbTarget > MAX_LOG_TARGET_FIELD_LEN ) {
  289. m_cbTarget = MAX_LOG_TARGET_FIELD_LEN;
  290. }
  291. }
  292. m_dwProtocolStatus = pInetLogRecord->dwProtocolStatus;
  293. m_bytesSent = pInetLogRecord->dwBytesSent;
  294. m_bytesRecv = pInetLogRecord->dwBytesRecvd;
  295. if ( fDefault ) {
  296. return;
  297. }
  298. strcpy( m_szSiteName, pszSiteName );
  299. strcpy( m_szComputerName, pszComputerName );
  300. m_cbSiteName = (DWORD)strlen(m_szSiteName);
  301. m_cbComputerName = (DWORD)strlen(m_szComputerName);
  302. m_szUserName = pInetLogRecord->pszClientUserName;
  303. if ( m_szUserName == NULL ) {
  304. m_szUserName = szNULL;
  305. m_cbUserName = 0;
  306. } else {
  307. m_cbUserName = (DWORD)strlen(m_szUserName);
  308. if ( m_cbUserName > MAX_LOG_USER_FIELD_LEN ) {
  309. m_cbUserName = MAX_LOG_USER_FIELD_LEN;
  310. }
  311. }
  312. //
  313. // If server IP is empty, then set it the first time
  314. //
  315. m_szServerAddress = pInetLogRecord->pszServerAddress;
  316. if ( m_szServerAddress == NULL ) {
  317. m_szServerAddress = szNULL;
  318. m_cbServerAddress = 0;
  319. } else {
  320. m_cbServerAddress = (DWORD)strlen(m_szServerAddress);
  321. }
  322. if ( pInetLogRecord->pszParameters == NULL ) {
  323. m_szParameters = szNULL;
  324. m_cbParameters = 0;
  325. } else {
  326. m_szParameters = pInetLogRecord->pszParameters;
  327. m_cbParameters = (DWORD)strlen(m_szParameters);
  328. if ( m_cbParameters > MAX_LOG_PARAMETER_FIELD_LEN ) {
  329. m_szParameters = szDotDot;
  330. m_cbParameters = 3;
  331. }
  332. }
  333. if ( pInetLogRecord->pszHTTPHeader == NULL ) {
  334. m_szHTTPHeaders = szNULL;
  335. m_cbHTTPHeaders = 0;
  336. } else {
  337. m_szHTTPHeaders = pInetLogRecord->pszHTTPHeader;
  338. m_cbHTTPHeaders = pInetLogRecord->cbHTTPHeaderSize;
  339. }
  340. if ( pInetLogRecord->pszVersion == NULL ) {
  341. m_szVersion = szNULL;
  342. m_cbVersion = 0;
  343. } else {
  344. m_szVersion = pInetLogRecord->pszVersion;
  345. m_cbVersion = (DWORD)strlen(m_szVersion);
  346. }
  347. m_msProcessingTime = pInetLogRecord->msTimeForProcessing;
  348. m_dwWin32Status = pInetLogRecord->dwWin32Status;
  349. m_dwPort = pInetLogRecord->dwPort;
  350. return;
  351. } // CanonicalizeLogRecord