Code improvements
This commit is contained in:
parent
b58bd89a97
commit
224c224e29
|
@ -113,10 +113,10 @@ const std::vector<std::string> DateTimeOps::processDateTime( const std::string&
|
|||
// convert to seconds
|
||||
if ( aux == "us" ) {
|
||||
// from microseconds
|
||||
datetime = datetime.substr( 0, datetime.size()-6 );
|
||||
datetime.resize( datetime.size()-6 );
|
||||
} else if ( aux == "ms" ) {
|
||||
// from milliseconds
|
||||
datetime = datetime.substr( 0, datetime.size()-3 );
|
||||
datetime.resize( datetime.size()-3 );
|
||||
} else if ( aux == "s.ms" ) {
|
||||
// from seconds.milliseconds
|
||||
datetime = std::to_string( std::stoi( datetime ) );
|
||||
|
@ -140,11 +140,13 @@ const std::vector<std::string> DateTimeOps::processDateTime( const std::string&
|
|||
day = datetime.substr( 8, 2 );
|
||||
|
||||
} else if ( format == "MMDDYY" ) {
|
||||
int y = std::stoi( datetime.substr( 6, 2 ) );
|
||||
month = datetime.substr( 0, 2 );
|
||||
day = datetime.substr( 3, 2 );
|
||||
year = "20" + datetime.substr( 6, 2 );
|
||||
year = (y<70) ? "20" : "19";
|
||||
year += std::to_string( y );
|
||||
|
||||
} else if ( format == "MDYY" ) {
|
||||
} else if ( format == "MDYYYY" ) {
|
||||
int aux_;
|
||||
if ( datetime.at(2) == '/' ) {
|
||||
month = datetime.substr( 0, 2 );
|
||||
|
@ -158,21 +160,23 @@ const std::vector<std::string> DateTimeOps::processDateTime( const std::string&
|
|||
aux_ += 3;
|
||||
} else {
|
||||
day = "0" + datetime.substr( aux_, 1 );
|
||||
aux_ = +2;
|
||||
aux_ += 2;
|
||||
}
|
||||
year = "20" + datetime.substr( aux_ );
|
||||
year = datetime.substr( aux_ );
|
||||
|
||||
} else if ( StringOps::startsWith( format, "year" ) ) {
|
||||
year = datetime;
|
||||
if ( format == "year_short" ) {
|
||||
year = "20" + year;
|
||||
int y = std::stoi( year );
|
||||
year = (y<70) ? "20" : "19";
|
||||
year += year;
|
||||
}
|
||||
|
||||
} else if ( StringOps::startsWith( format, "month" ) ) {
|
||||
if ( format.size() <= 5 ) {
|
||||
month = datetime;
|
||||
} else {
|
||||
datetime = datetime.substr( 0, 3 ); // may be the full name
|
||||
datetime.resize( 3 ); // may be the full name
|
||||
month = DateTimeOps::convertMonth( datetime );
|
||||
}
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ FormatOps::FormatOps()
|
|||
|
||||
|
||||
// count the new lines
|
||||
const int FormatOps::countNewLines( const std::string& initial, const std::string& final, const std::vector<std::string>& separators ) const
|
||||
const unsigned FormatOps::countNewLines( const std::string& initial, const std::string& final, const std::vector<std::string>& separators ) const
|
||||
{
|
||||
int nl = 0;
|
||||
unsigned nl = 0;
|
||||
nl += StringOps::count( initial, "\n" );
|
||||
nl += StringOps::count( final, "\n" );
|
||||
for ( const std::string& sep : separators ) {
|
||||
|
@ -616,7 +616,7 @@ const FormatOps::LogsFormat FormatOps::processIisFormatString( const std::string
|
|||
// IIS logging module
|
||||
final = ",";
|
||||
separators = {", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",", ",", "};
|
||||
fields = {"client","NONE","date_time_MDYY","date_time_utc_t","NONE","NONE","NONE","time_taken_ms","bytes_received","bytes_sent","response_code","NONE","request_method","request_uri","request_query"};
|
||||
fields = {"client","NONE","date_time_MDYYYY","date_time_utc_t","NONE","NONE","NONE","time_taken_ms","bytes_received","bytes_sent","response_code","NONE","request_method","request_uri","request_query"};
|
||||
break;
|
||||
case 1:
|
||||
// NCSA logging module
|
||||
|
|
|
@ -24,7 +24,7 @@ public:
|
|||
std::string final; //!< The final separator
|
||||
std::vector<std::string> separators; //!< The separators in the middle
|
||||
std::vector<std::string> fields; //!< The fields
|
||||
int new_lines; //!< The number of new lines
|
||||
unsigned new_lines; //!< The number of new lines
|
||||
};
|
||||
|
||||
|
||||
|
@ -117,7 +117,7 @@ private:
|
|||
\return The number of new lines in a single log line
|
||||
\see LogsFormat, processApacheFormatString(), processNginxFormatString()
|
||||
*/
|
||||
const int countNewLines( const std::string& initial, const std::string& final, const std::vector<std::string>& separators ) const;
|
||||
const unsigned countNewLines( const std::string& initial, const std::string& final, const std::vector<std::string>& separators ) const;
|
||||
|
||||
//! Finds the end of a Nginx log field
|
||||
/*!
|
||||
|
@ -437,7 +437,7 @@ private:
|
|||
/////////////
|
||||
//// IIS ////
|
||||
|
||||
//!< Access logs fields formats
|
||||
//!< Access logs fields formats (W3C)
|
||||
const std::unordered_map<std::string, std::string> IIS_ALF = {
|
||||
{"date", "date_time_utc_d"},
|
||||
{"time", "date_time_utc_t"},
|
||||
|
@ -468,7 +468,7 @@ private:
|
|||
const std::unordered_map<std::string, QString> IIS_ALF_SAMPLES = {
|
||||
{"NONE", "<span style=\"color:#7f7f7f\">DISCARDED</span>"},
|
||||
{"date_time_ncsa", "<b><span style=\"color:#00cc6f\">01/Jan/2000:23:59:59 +0000</span></b>"},
|
||||
{"date_time_MDYY", "<b><span style=\"color:#00cc6f\">1/1/00</span></b>"},
|
||||
{"date_time_MDYYYY", "<b><span style=\"color:#00cc6f\">1/1/2000</span></b>"},
|
||||
{"date_time_utc_d", "<b><span style=\"color:#00cc6f\">2000-01-01</span></b>"},
|
||||
{"date_time_utc_t", "<b><span style=\"color:#00cc6f\">23:59:59</span></b>"},
|
||||
{"request_full", "<b><span style=\"color:#00cc6f\">GET /index.php?query=x HTTP/1.1</span></b>"},
|
||||
|
|
|
@ -28,7 +28,6 @@ public:
|
|||
/*!
|
||||
\param db_path The path of the log files' Hashes database
|
||||
\return Whether the operation has been successful or not
|
||||
\see hashes
|
||||
*/
|
||||
const bool loadUsedHashesLists( const std::string& db_path );
|
||||
|
||||
|
@ -46,7 +45,6 @@ public:
|
|||
\param file_hash The sha256 hash to compare
|
||||
\param web_server_id The ID of the Web Server which generated the file
|
||||
\return Whether the hash is already in the list or not
|
||||
\see hashes
|
||||
*/
|
||||
const bool hasBeenUsed( const std::string& file_hash, const int& web_server_id ) const;
|
||||
|
||||
|
@ -56,7 +54,6 @@ public:
|
|||
\param hashes The list of hashes to insert
|
||||
\param web_server_id The ID of the Web Server which generated the file
|
||||
\return Whether the operation has been successful or not
|
||||
\see insertUsedHash()
|
||||
*/
|
||||
const bool insertUsedHashes( const std::string& db_path, const std::vector<std::string>& hashes, const int& web_server_id );
|
||||
|
||||
|
|
|
@ -79,9 +79,9 @@ void TextBrowser::makePreview( QString& content ) const
|
|||
this->color_scheme.at("text") );
|
||||
}
|
||||
content += ">";
|
||||
if ( this->wide_lines ) {
|
||||
/*if ( this->wide_lines ) {
|
||||
content += "<br/>";
|
||||
}
|
||||
}*/
|
||||
for ( int i=0; i<32; i++ ) {
|
||||
content += "<p>";
|
||||
|
||||
|
@ -166,7 +166,7 @@ void TextBrowser::makePreview( QString& content ) const
|
|||
content += "</b>";
|
||||
|
||||
content += "</p>";
|
||||
if ( this->wide_lines ) {
|
||||
if ( this->wide_lines && i < 31 ) {
|
||||
content += "<br/>";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,22 +24,24 @@ void RichText::enrichLogs( QString &rich_content, const std::string& content, co
|
|||
.arg( colors.at("background"), colors.at("text") );
|
||||
}
|
||||
rich_content += ">";
|
||||
if ( wide_lines == true ) {
|
||||
/*if ( wide_lines == true ) {
|
||||
rich_content += "<br/>";
|
||||
}
|
||||
}*/
|
||||
QString rich_line="", class_name="";
|
||||
std::string sep, fld, fld_str, aux_sep2;
|
||||
bool missing=false;
|
||||
bool missing = false;
|
||||
size_t start, stop, i, aux_start, aux_stop,
|
||||
line_size, sep_size;
|
||||
const size_t n_sep = logs_format.separators.size()-1;
|
||||
std::vector<std::string> lines;
|
||||
StringOps::splitrip( lines, content );
|
||||
size_t lines_left = lines.size();
|
||||
for ( const std::string& line : lines ) {
|
||||
lines_left --;
|
||||
// check if the line is commented, usually from IIS logs
|
||||
if ( StringOps::startsWith( line, "#" ) && !StringOps::startsWith( logs_format.initial, "#" ) ) {
|
||||
rich_line = QString("<p>%1</p>").arg( QString::fromStdString( line ) );
|
||||
if ( wide_lines == true ) {
|
||||
if ( wide_lines ) {
|
||||
rich_line += "<br/>";
|
||||
}
|
||||
rich_content.append( rich_line );
|
||||
|
@ -135,7 +137,7 @@ void RichText::enrichLogs( QString &rich_content, const std::string& content, co
|
|||
}
|
||||
|
||||
// finally update if needed
|
||||
if ( ok == true && aux_stop >= stop ) {
|
||||
if ( ok && aux_stop >= stop ) {
|
||||
stop = aux_stop;
|
||||
fld_str = StringOps::strip( line.substr(start, stop-start), " " );
|
||||
}
|
||||
|
@ -148,7 +150,7 @@ void RichText::enrichLogs( QString &rich_content, const std::string& content, co
|
|||
fld_str = fld_str.substr( 1, fld_str.size()-1 );
|
||||
rich_line += "[";
|
||||
if ( StringOps::endsWith( fld_str, "]" ) ) {
|
||||
fld_str = fld_str.substr( 0, fld_str.size()-1 );
|
||||
fld_str.resize( fld_str.size()-1 );
|
||||
sep = "]" + sep;
|
||||
}
|
||||
}
|
||||
|
@ -182,7 +184,7 @@ void RichText::enrichLogs( QString &rich_content, const std::string& content, co
|
|||
}
|
||||
rich_line += "</b>";
|
||||
// update the stop for the next start
|
||||
if ( missing == true ) {
|
||||
if ( missing ) {
|
||||
stop = aux_stop;
|
||||
} else {
|
||||
stop += sep_size;
|
||||
|
@ -193,7 +195,7 @@ void RichText::enrichLogs( QString &rich_content, const std::string& content, co
|
|||
rich_line += QString::fromStdString( logs_format.final );
|
||||
break;
|
||||
}
|
||||
if ( missing == true ) {
|
||||
if ( missing ) {
|
||||
missing = false;
|
||||
rich_line += QString::fromStdString( aux_sep2 );
|
||||
} else {
|
||||
|
@ -201,10 +203,10 @@ void RichText::enrichLogs( QString &rich_content, const std::string& content, co
|
|||
}
|
||||
}
|
||||
rich_line += "</p>";
|
||||
if ( wide_lines == true ) {
|
||||
if ( wide_lines && lines_left > 0 ) {
|
||||
rich_line += "<br/>";
|
||||
}
|
||||
rich_content+= rich_line;
|
||||
rich_content += rich_line;
|
||||
}
|
||||
lines.clear();
|
||||
rich_content += "</body></html>";
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
#include "strings.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
StringOps::StringOps()
|
||||
{
|
||||
|
@ -373,17 +375,17 @@ const std::string StringOps::replace( const std::string& str, const std::string&
|
|||
const std::string StringOps::toUpper( const std::string& str )
|
||||
{
|
||||
std::string up = "";
|
||||
for ( const unsigned char& ch : str ) {
|
||||
up.push_back( (char)std::toupper( ch ) );
|
||||
}
|
||||
std::transform( str.cbegin(), str.cend(),
|
||||
std::back_inserter( up ),
|
||||
[](char c){ return std::toupper( c ); } );
|
||||
return up;
|
||||
}
|
||||
|
||||
const std::string StringOps::toLower( const std::string& str )
|
||||
{
|
||||
std::string low = "";
|
||||
for ( const unsigned char& ch : str ) {
|
||||
low.push_back( (char)std::tolower( ch ) );
|
||||
}
|
||||
std::transform( str.cbegin(), str.cend(),
|
||||
std::back_inserter( low ),
|
||||
[](char c){ return std::toupper( c ); } );
|
||||
return low;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue