File indexing completed on 2024-05-19 05:49:12
0001 /* 0002 SPDX-FileCopyrightText: 2007 Nicolas Ternisien <nicolas.ternisien@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "apacheAccessAnalyzer.h" 0008 0009 ApacheAccessAnalyzer::ApacheAccessAnalyzer(LogMode *logMode) 0010 : FileAnalyzer(logMode) 0011 { 0012 } 0013 0014 LogViewColumns ApacheAccessAnalyzer::initColumns() 0015 { 0016 LogViewColumns columns; 0017 0018 columns.addColumn(LogViewColumn(i18n("Date"), true, false)); 0019 columns.addColumn(LogViewColumn(i18n("Host Name"), true, true)); 0020 columns.addColumn(LogViewColumn(i18n("Id."), true, true)); //=Identification protocol [From RFC1413 (see Google for more infos)] 0021 columns.addColumn(LogViewColumn(i18n("User"), true, true)); 0022 columns.addColumn(LogViewColumn(i18n("Response"), true, true)); 0023 columns.addColumn(LogViewColumn(i18n("Bytes Sent"), true, false)); 0024 columns.addColumn(LogViewColumn(i18n("Agent Identity"), true, true)); 0025 columns.addColumn(LogViewColumn(i18n("HTTP Request"), true, false)); 0026 columns.addColumn(LogViewColumn(i18n("URL"), true, true)); 0027 0028 return columns; 0029 } 0030 0031 LogFileReader *ApacheAccessAnalyzer::createLogFileReader(const LogFile &logFile) 0032 { 0033 return new LocalLogFileReader(logFile); 0034 } 0035 0036 Analyzer::LogFileSortMode ApacheAccessAnalyzer::logFileSortMode() 0037 { 0038 return Analyzer::AscendingSortedLogFile; 0039 } 0040 0041 LogLine *ApacheAccessAnalyzer::parseMessage(const QString &logLine, const LogFile &originalLogFile) 0042 { 0043 QString line(logLine); 0044 0045 int spacePos = line.indexOf(QLatin1Char(' ')); 0046 0047 QString const hostName = line.left(spacePos); 0048 line.remove(0, spacePos + 1); 0049 0050 spacePos = line.indexOf(QLatin1Char(' ')); 0051 QString const identd = line.left(spacePos); 0052 line.remove(0, spacePos + 1); 0053 0054 spacePos = line.indexOf(QLatin1Char(' ')); 0055 QString const userName = line.left(spacePos); 0056 line.remove(0, spacePos + 1); 0057 0058 int const endDate = line.indexOf(QLatin1Char(']')); 0059 QString const strDateTime = line.left(endDate); 0060 line.remove(0, endDate + 3); 0061 0062 QDateTime const dateTime = ParsingHelper::instance()->parseHttpDateTime(strDateTime.mid(1, strDateTime.length() - 2)); 0063 0064 int endQuote = line.indexOf(QLatin1Char('\"')); 0065 QString const message = line.left(endQuote); 0066 line.remove(0, endQuote + 2); 0067 0068 spacePos = line.indexOf(QLatin1Char(' ')); 0069 QString const httpResponse = ParsingHelper::instance()->parseHttpResponse(line.left(spacePos)); 0070 line.remove(0, spacePos + 1); 0071 0072 spacePos = line.indexOf(QLatin1Char(' ')); 0073 QString const bytesSent = ParsingHelper::instance()->parseSize(line.left(spacePos)); 0074 line.remove(0, spacePos + 2); 0075 0076 QString url; 0077 0078 endQuote = line.indexOf(QLatin1Char('\"')); 0079 if (endQuote != -1) { 0080 url = line.left(endQuote); 0081 line.remove(0, endQuote + 3); 0082 } 0083 0084 QString agent; 0085 0086 // TODO Convert this value to find a more simple name for the Agent 0087 endQuote = line.indexOf(QLatin1Char('\"')); 0088 if (endQuote != -1) { 0089 agent = ParsingHelper::instance()->parseAgent(line.left(endQuote)); 0090 } 0091 0092 QStringList list; 0093 list.append(hostName); 0094 list.append(identd); 0095 list.append(userName); 0096 list.append(httpResponse); 0097 list.append(bytesSent); 0098 list.append(agent); 0099 list.append(message); 0100 list.append(url); 0101 0102 return new LogLine(mLogLineInternalIdGenerator++, dateTime, list, originalLogFile.url().toLocalFile(), Globals::instance().informationLogLevel(), mLogMode); 0103 } 0104 0105 #include "moc_apacheAccessAnalyzer.cpp"