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.

394 lines
11 KiB

  1. #include "convlog.h"
  2. #include "inetcom.h"
  3. #include "logtype.h"
  4. //
  5. // Current output file
  6. //
  7. OUTFILESTATUS WebOutFile = {0};
  8. OUTFILESTATUS NoConvertOutFile = {0};
  9. //
  10. // Used for find first
  11. //
  12. WIN32_FIND_DATA FindData = {0};
  13. //
  14. // struct for holding command line args
  15. //
  16. BOOL DoDNSConversion = FALSE;
  17. BOOL SaveFTPEntries = FALSE;
  18. BOOL NoFormatConversion = FALSE;
  19. CHAR FTPSaveFile[MAX_PATH+1] = {0};
  20. CHAR NCSAGMTOffset[MAX_PATH+1] = {0};
  21. DWORD LogFileFormat = LOGFILE_INVALID;
  22. CHAR InputFileName[MAX_PATH+1] = {0};
  23. CHAR OutputDir[MAX_PATH+1] = {0};
  24. CHAR TempDir[MAX_PATH+1] = {0};
  25. DWORD nWebLineCount = 0;
  26. DATEFORMAT dwDateFormat = DateFormatUsa;
  27. BOOL bOnErrorContinue = FALSE;
  28. //
  29. // struct that holds log line items
  30. //
  31. INLOGLINE InLogLine = {0};
  32. int
  33. __cdecl
  34. main(
  35. int argc,
  36. char *argv[]
  37. )
  38. {
  39. FILE *fpInFile; //log File to open
  40. HANDLE hFile; //Handle for FindFirstFile
  41. //
  42. // Buffer to hold log line
  43. //
  44. CHAR szInBuf[MAX_LOG_RECORD_LEN+1];
  45. //
  46. // File mask to search for
  47. //
  48. CHAR szFileMask[MAX_PATH+1];
  49. CHAR szInfileName[MAX_PATH+1];
  50. CHAR szWorkingDir[MAX_PATH+1];
  51. int nTotalWebCount = 0;
  52. BOOL bWebFound = FALSE; //did we find a web line?
  53. BOOL bNoConvertFound = FALSE; //did we find any NoConvert lines?
  54. BOOL bRet; //used for testing returns
  55. DWORD dwErr; //used to hold error codes
  56. int nLineCount = 0; //number of lines read from input file
  57. int nTotalCount = 0;
  58. //int nCount = 0; Bug # 101690
  59. CHAR *pCh;
  60. DWORD dwFieldMask;
  61. BOOL fGetHeader;
  62. DWORD nLinesDumped = 0;
  63. DWORD dwGetLogLineResult;
  64. BOOL bContinue;
  65. DWORD dwCurrentLine;
  66. //
  67. // initialize data structure
  68. //
  69. setlocale(LC_ALL, ".ACP" );
  70. WebOutFile.fpOutFile = NULL;
  71. NoConvertOutFile.fpOutFile = NULL;
  72. ZeroMemory(szInBuf, sizeof(szInBuf));
  73. strcpy(OutputDir, ".\\");
  74. switch ( ParseArgs(argc, argv) ) {
  75. case ILLEGAL_COMMAND_LINE:
  76. Usage(argv[0]);
  77. return 0;
  78. case OUT_DIR_NOT_OK:
  79. printfids(IDS_BAD_DIR, OutputDir);
  80. return 0;
  81. case ERROR_BAD_NONE:
  82. printfids(IDS_BAD_NONE_ERR);
  83. return 0;
  84. case COMMAND_LINE_OK:
  85. break;
  86. }
  87. if ( DoDNSConversion ) {
  88. INT serr;
  89. WSADATA wsaData;
  90. if (serr = WSAStartup(MAKEWORD(2,0), &wsaData) != 0) {
  91. printfids(IDS_WINSOCK_ERR, serr);
  92. DoDNSConversion = FALSE;
  93. }
  94. }
  95. if ( (LogFileFormat == LOGFILE_NCSA) && !DoDNSConversion ) {
  96. printfids(IDS_NO_CONVERSION_NEEDED);
  97. return(0);
  98. }
  99. if ( !InitDateStrings() ) {
  100. printfids(IDS_BAD_DATESTRINGS);
  101. }
  102. if (DoDNSConversion) {
  103. InitHashTable(2000);
  104. AddLocalMachineToCache( );
  105. }
  106. strcpy (szWorkingDir, InputFileName);
  107. // Bug # 101690
  108. //
  109. // for (nCount = strlen(szWorkingDir) -1; nCount >= 0; nCount--) {
  110. //
  111. // if ('\\' == szWorkingDir[nCount]) {
  112. // szWorkingDir[nCount+1] = '\0';
  113. // break;
  114. // }
  115. //
  116. // }
  117. // if (nCount < 0) {
  118. // strcpy (szWorkingDir, ".\\");
  119. // }
  120. //
  121. pCh = _mbsrchr(szWorkingDir, '\\');
  122. if (pCh != NULL) {
  123. *(pCh+1) = '\0';
  124. } else {
  125. strcpy (szWorkingDir, ".\\");
  126. }
  127. strcpy(szFileMask, InputFileName);
  128. hFile = FindFirstFile (szFileMask, &FindData);
  129. if (INVALID_HANDLE_VALUE == hFile) {
  130. printfids(IDS_FILE_NONE, szFileMask);
  131. return(0);
  132. }
  133. do {
  134. if (!(FILE_ATTRIBUTE_DIRECTORY & FindData.dwFileAttributes)) {
  135. strcpy(szInfileName, szWorkingDir);
  136. strcat(szInfileName, FindData.cFileName);
  137. fpInFile = fopen(szInfileName, "r");
  138. printfids(IDS_FILE_OPEN, FindData.cFileName);
  139. nLineCount = 0;
  140. dwCurrentLine = 0;
  141. {
  142. //
  143. // Do file conversion
  144. //
  145. strcpy (WebOutFile.szLastDate, NEW_DATETIME);
  146. strcpy (WebOutFile.szLastTime, NEW_DATETIME);
  147. bWebFound = FALSE;
  148. nWebLineCount = 0;
  149. nLinesDumped = 0;
  150. ExtendedFieldsDefined = FALSE;
  151. szGlobalDate[0] = '\0';
  152. }
  153. fGetHeader = TRUE;
  154. bContinue = TRUE;
  155. while ((bContinue) && (!feof(fpInFile)))
  156. {
  157. dwCurrentLine++;
  158. dwGetLogLineResult = GetLogLine( fpInFile, szInBuf, sizeof(szInBuf), &InLogLine);
  159. if (dwGetLogLineResult == GETLOG_SUCCESS)
  160. {
  161. nLineCount++;
  162. if (DoDNSConversion) {
  163. //
  164. //Getting machine names could take days, so put out status messages
  165. //
  166. switch (nLineCount) {
  167. case 25:
  168. case 50:
  169. case 100:
  170. case 250:
  171. case 500:
  172. printfids(IDS_LINES_PROC, FindData.cFileName, nLineCount);
  173. break;
  174. default:
  175. if ((nLineCount % 1000) == 0)
  176. printfids(IDS_LINES_PROC, FindData.cFileName, nLineCount);
  177. } //end switch
  178. }
  179. //
  180. // if NCSA and just DoDNS, do no convert
  181. //
  182. if ( NoFormatConversion ||
  183. (_strnicmp(
  184. InLogLine.szService,
  185. "W3SVC",
  186. strlen("W3SVC")) != 0) ) {
  187. if ( NoFormatConversion || SaveFTPEntries ) {
  188. ProcessNoConvertLine(
  189. &InLogLine,
  190. FindData.cFileName,
  191. szInBuf,
  192. &NoConvertOutFile,
  193. &bNoConvertFound);
  194. } else {
  195. nLinesDumped++;
  196. }
  197. } else {
  198. bWebFound = TRUE;
  199. if (ProcessWebLine(
  200. &InLogLine,
  201. FindData.cFileName,
  202. &WebOutFile)) {
  203. nWebLineCount++;
  204. }
  205. }
  206. } //end if LogLineProcessed
  207. else
  208. {
  209. if (dwGetLogLineResult != GETLOG_ERROR)
  210. {
  211. nLineCount++;
  212. }
  213. switch (dwGetLogLineResult) {
  214. case GETLOG_ERROR_PARSE_NCSA:
  215. printfids(IDS_FILE_NOT_NCSA,dwCurrentLine);
  216. break;
  217. case GETLOG_ERROR_PARSE_MSINET:
  218. printfids(IDS_FILE_NOT_MSINET,dwCurrentLine);
  219. break;
  220. case GETLOG_ERROR_PARSE_EXTENDED:
  221. printfids(IDS_BAD_EXTENDED_FORMAT,dwCurrentLine);
  222. break;
  223. default:
  224. break;
  225. }
  226. if (!bOnErrorContinue)
  227. {
  228. bContinue = FALSE;
  229. }
  230. }
  231. } //end while !eof
  232. nTotalCount += nLineCount;
  233. if (fpInFile) {
  234. fclose(fpInFile);
  235. }
  236. if (bWebFound) {
  237. if (WebOutFile.fpOutFile != NULL ) {
  238. fclose(WebOutFile.fpOutFile);
  239. WebOutFile.fpOutFile = NULL;
  240. }
  241. bRet = MoveFileEx(
  242. WebOutFile.szTmpFileName,
  243. WebOutFile.szOutFileName,
  244. MOVEFILE_COPY_ALLOWED);
  245. if (!bRet) {
  246. dwErr = GetLastError();
  247. switch (dwErr) {
  248. case ERROR_FILE_EXISTS:
  249. case ERROR_ALREADY_EXISTS:
  250. CombineFiles(WebOutFile.szTmpFileName, WebOutFile.szOutFileName);
  251. break;
  252. case ERROR_PATH_NOT_FOUND:
  253. break;
  254. default:
  255. printfids(IDS_FILE_ERR, dwErr);
  256. return 1;
  257. }
  258. }
  259. }
  260. if (bNoConvertFound) {
  261. bNoConvertFound = FALSE;
  262. if (NoConvertOutFile.fpOutFile != NULL) {
  263. fclose(NoConvertOutFile.fpOutFile);
  264. NoConvertOutFile.fpOutFile = NULL;
  265. }
  266. bRet = MoveFileEx(
  267. NoConvertOutFile.szTmpFileName,
  268. NoConvertOutFile.szOutFileName,
  269. MOVEFILE_COPY_ALLOWED);
  270. if (!bRet) {
  271. dwErr = GetLastError();
  272. switch (dwErr) {
  273. case ERROR_FILE_EXISTS:
  274. case ERROR_ALREADY_EXISTS:
  275. CombineFiles(NoConvertOutFile.szTmpFileName, NoConvertOutFile.szOutFileName);
  276. break;
  277. case ERROR_PATH_NOT_FOUND:
  278. break;
  279. default:
  280. printfids(IDS_FILE_ERR, dwErr);
  281. exit (1);
  282. break;
  283. }
  284. }
  285. }
  286. nTotalWebCount += nWebLineCount;
  287. printfids( IDS_LINES, FindData.cFileName, nLineCount);
  288. printfids (IDS_WEB_LINES, nWebLineCount);
  289. if ( nLinesDumped > 0 ) {
  290. printfids( IDS_DUMP_LINES, nLinesDumped );
  291. nLinesDumped = 0;
  292. }
  293. }
  294. } while (FindNextFile (hFile, &FindData));
  295. FindClose(hFile);
  296. printfids (IDS_TOTALS);
  297. printfids (IDS_TOT_LINES, nTotalCount);
  298. printfids (IDS_TOT_WEB_LINES, nTotalWebCount);
  299. #if DBG
  300. PrintCacheTotals();
  301. #endif
  302. return (0);
  303. }