#include <logrecord.h>
Public Methods | |
LogRecord () | |
bool | parse_line (const string &line, const Configuration &conf) |
fill in date_, domain_, path_ from line. | |
const DatePattern& | date () const |
const Path& | path () const |
const Domain& | domain () const |
Private Methods | |
bool | parse_date (const string &line) |
Auxiliary function for parse_line(). | |
bool | parse_path (const string &line) |
Auxiliary function for parse_line(). | |
bool | parse_domain (const string &line) |
Auxiliary function for parse_line(). | |
Private Attributes | |
DatePattern | date_ |
Path | path_ |
Domain | domain_ |
|
Definition at line 14 of file logrecord.h. 00014 {} |
|
fill in date_, domain_, path_ from line.
Definition at line 11 of file logrecord.C. Referenced by main().
00011 { 00012 /* A parse succeeds if all components can be parsed. 00013 We only parse the parts that are needed according to 00014 conf.criteria(); 00015 */ 00016 const set<Configuration::CRITERIUM>& criteria(conf.criteria()); 00017 00018 if (criteria.count(Configuration::DATE)) 00019 if (!parse_date(line)) 00020 return false; 00021 00022 if (criteria.count(Configuration::PATH)) 00023 if (!parse_path(line)) 00024 return false; 00025 00026 if (criteria.count(Configuration::DOMAIN)) 00027 if (!parse_domain(line)) 00028 return false; 00029 00030 return true; 00031 } |
|
Definition at line 19 of file logrecord.h. Referenced by Stats::add(), and DateExpression::eval().
00019 { return date_; } |
|
Definition at line 20 of file logrecord.h. Referenced by Stats::add(), and PathExpression::eval().
00020 { return path_; } |
|
Definition at line 21 of file logrecord.h. Referenced by Stats::add(), and DomainExpression::eval().
00021 { return domain_; } |
|
Auxiliary function for parse_line().
Definition at line 35 of file logrecord.C. Referenced by parse_line().
00035 { 00036 /* Select date part: just after first '[' up to first folloing ' ' 00037 e.g. 00038 00039 spider1.tiscalinet.be - - [02/Nov/2000:10:20:36 +0100] .. 00040 00041 will select 00042 00043 02/Nov/2000:10:20:36 00044 */ 00045 string::size_type date_start(line.find_first_of('[')); 00046 if (date_start==string::npos) 00047 return false; 00048 string::size_type date_end(line.find_first_of(' ',date_start)); 00049 if (date_end==string::npos) 00050 return false; 00051 string date_string(line,date_start+1,date_end - date_start-1); 00052 if (date_string.size()==0) 00053 return false; 00054 /* Make date_string acceptable to the Date::Date(const char*) parser. 00055 00056 1. replace '/' by '-'. In the example, this will yield 00057 00058 02-Nov-2000:10:20:36 00059 */ 00060 for (string::size_type i=0; i<date_string.size(); ++i) 00061 if (date_string[i]=='/') 00062 date_string[i] = '-'; 00063 /* 00064 2. Replace first ':' by space. In the example, this will yield 00065 00066 02-Nov-2000 10:20:36 00067 */ 00068 date_string.replace(date_string.find_first_of(':'),1," "); 00069 00070 /* Now parse using Date::Date(const string&). It will throw an exception 00071 if the date cannot be parsed. In that case, we catch the exception 00072 and return false. 00073 */ 00074 try { 00075 Date d(date_string); 00076 date_.set(d.year(),d.month(),d.day(),d.hours()); 00077 } 00078 catch (exception& e) { 00079 cerr << "LogRecord::parse_date failed: " << e.what() << endl; 00080 return false; 00081 } 00082 return true; 00083 } |
|
Auxiliary function for parse_line().
Definition at line 123 of file logrecord.C. Referenced by parse_line().
00123 { 00124 /* The path part can be found between the first and second occurrences 00125 of `"' (double quote). An example is shown below. 00126 00127 "GET /ssl/kiesoos.cgi?rolnr=58769\&stjcode=5L10021 HTTP/1.0" 00128 00129 This will result in 00130 00131 _path = <"","ssl","kiesoos.cgi"> 00132 */ 00133 string::size_type path_start(line.find_first_of('\"')); 00134 if (path_start==string::npos) 00135 return false; 00136 /* We are not interested in the verb (e.g. GET), so we skip until after the first ' '. 00137 In the example, path_start would then point to. 00138 00139 /ssl/kiesoos.cgi?rolnr=58769\&stjcode=5L10021 HTTP/1.0" 00140 */ 00141 path_start = line.find_first_of(' ',path_start); 00142 if (path_start==string::npos) 00143 return false; 00144 ++path_start; // After ' '. 00145 /* We only want the path until the first '?', '#' or ' '. In the example 00146 this should result in. 00147 00148 path_string = /ssl/kiesoos.cgi 00149 */ 00150 00151 string::size_type path_end = line.find_first_of("#? ",path_start); 00152 if (path_end==string::npos) 00153 return false; 00154 00155 if (path_end==path_start) // cannot have an empty path 00156 return false; 00157 00158 string path_string(line,path_start,path_end - path_start); 00159 00160 // Decode to translate "%7E" back to '~' etc. 00161 www_decode(path_string); 00162 00163 return path_.parse(path_string); 00164 } |
|
Auxiliary function for parse_line().
Definition at line 168 of file logrecord.C. Referenced by parse_line().
00168 { 00169 /* The domain informatin is easy to find: it's the first part of 00170 a line, followed by a ' ', as illustrated in the following example. 00171 00172 igwe.vub.ac.be - - [12/Feb/2000:13:18:49 +0100] ... 00173 00174 */ 00175 string::size_type domain_start(0); 00176 string::size_type domain_end(line.find_first_of(' ')); 00177 if (domain_end==string::npos) 00178 return false; 00179 string domain_string(line,domain_start,domain_end); 00180 00181 return domain_.parse(domain_string); 00182 } |
|
Definition at line 31 of file logrecord.h. |
|
Definition at line 32 of file logrecord.h. |
|
Definition at line 33 of file logrecord.h. |