Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

LogRecord Class Reference

#include <logrecord.h>

List of all members.

Public Methods

 LogRecord ()
bool parse_line (const string &line)
 fill in date_, domain_, path_ from line.

const DatePatterndate () const
const Pathpath () const
const Domaindomain () 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_


Constructor & Destructor Documentation

LogRecord::LogRecord ( ) [inline]
 

Definition at line 12 of file logrecord.h.

00012 {}


Member Function Documentation

bool LogRecord::parse_line ( const string & line )
 

fill in date_, domain_, path_ from line.

Definition at line 10 of file logrecord.C.

Referenced by main().

00010                                         {
00011 /* A parse succeeds if all components can be parsed.
00012    This should be modified so that we only parse what is necessary,
00013    according to the configuration. But for now, we are too lazy.
00014 */
00015 return parse_date(line) && parse_path(line) && parse_domain(line);
00016 }

const DatePattern & LogRecord::date ( ) const [inline]
 

Definition at line 17 of file logrecord.h.

Referenced by Stats::add(), and DateExpression::eval().

00017 { return date_; }

const Path & LogRecord::path ( ) const [inline]
 

Definition at line 18 of file logrecord.h.

Referenced by Stats::add(), and PathExpression::eval().

00018 { return path_; }

const Domain & LogRecord::domain ( ) const [inline]
 

Definition at line 19 of file logrecord.h.

Referenced by Stats::add(), and DomainExpression::eval().

00019 { return domain_; }

bool LogRecord::parse_date ( const string & line ) [private]
 

Auxiliary function for parse_line().

Definition at line 20 of file logrecord.C.

Referenced by parse_line().

00020                                         {
00021 /* Select date part: just after first '[' up to first folloing ' '
00022    e.g.
00023 
00024         spider1.tiscalinet.be - - [02/Nov/2000:10:20:36 +0100] ..
00025 
00026    will select
00027 
00028         02/Nov/2000:10:20:36
00029 */
00030 string::size_type date_start(line.find_first_of('['));
00031 if (date_start==string::npos)
00032   return false;
00033 string::size_type date_end(line.find_first_of(' ',date_start));
00034 if (date_end==string::npos)
00035   return false;
00036 string            date_string(line,date_start+1,date_end - date_start-1);
00037 if (date_string.size()==0)
00038   return false;
00039 /* Make date_string acceptable to the Date::Date(const char*) parser.
00040 
00041    1. replace '/' by '-'. In the example, this will yield 
00042 
00043         02-Nov-2000:10:20:36
00044 */
00045 for (string::size_type i=0; i<date_string.size(); ++i)
00046   if (date_string[i]=='/')
00047     date_string[i] = '-';
00048 /*
00049    2. Replace first ':' by space. In the example, this will yield 
00050 
00051         02-Nov-2000 10:20:36
00052 */
00053 date_string.replace(date_string.find_first_of(':'),1," ");
00054 
00055 /* Now parse using Date::Date(const string&). It will throw an exception
00056    if the date cannot be parsed. In that case, we catch the exception
00057    and return false.
00058 */
00059 try {
00060   Date  d(date_string);
00061   date_.set(d.year(),d.month(),d.day(),d.hours());
00062   }
00063 catch (exception& e) {
00064   cerr << "LogRecord::parse_date failed: " << e.what() << endl;
00065   return false;
00066   }
00067 return true;
00068 }

bool LogRecord::parse_path ( const string & line ) [private]
 

Auxiliary function for parse_line().

Definition at line 108 of file logrecord.C.

Referenced by parse_line().

00108                                         {
00109 /* The path part can be found between the first and second occurrences
00110    of `"' (double quote). An example is shown below.
00111 
00112     "GET /ssl/kiesoos.cgi?rolnr=58769\&stjcode=5L10021 HTTP/1.0" 
00113 
00114    This will result in 
00115 
00116      _path = <"","ssl","kiesoos.cgi">
00117 */
00118 string::size_type path_start(line.find_first_of('\"'));
00119 if (path_start==string::npos)
00120   return false;
00121 /* We are not interested in the verb (e.g. GET), so we skip until after the first ' '.
00122    In the example, path_start would then point to.
00123 
00124     /ssl/kiesoos.cgi?rolnr=58769\&stjcode=5L10021 HTTP/1.0" 
00125 */
00126 path_start = line.find_first_of(' ',path_start);
00127 if (path_start==string::npos)
00128   return false;
00129 ++path_start; // After ' '.
00130 /*  We only want the path until the first '?', '#' or ' '. In the example
00131     this should result in.
00132 
00133     path_string = /ssl/kiesoos.cgi
00134 */
00135 
00136 string::size_type path_end = line.find_first_of("#? ",path_start);
00137 if (path_end==string::npos)
00138   return false;
00139 
00140 if (path_end==path_start) // cannot have an empty path
00141   return false;
00142 
00143 string path_string(line,path_start,path_end - path_start);
00144 
00145 // Decode to translate "%7E" back to '~' etc.
00146 www_decode(path_string);
00147 
00148 return path_.parse(path_string);
00149 }

bool LogRecord::parse_domain ( const string & line ) [private]
 

Auxiliary function for parse_line().

Definition at line 153 of file logrecord.C.

Referenced by parse_line().

00153                                           {
00154 /* The domain informatin is easy to find: it's the first part of
00155    a line, followed by a ' ', as illustrated in the following example.
00156 
00157         igwe.vub.ac.be - - [12/Feb/2000:13:18:49 +0100] ...
00158         
00159 */
00160 string::size_type domain_start(0);
00161 string::size_type domain_end(line.find_first_of(' '));
00162 if (domain_end==string::npos)
00163   return false;
00164 string domain_string(line,domain_start,domain_end);
00165 
00166 return domain_.parse(domain_string);
00167 }


Member Data Documentation

DatePattern LogRecord::date_ [private]
 

Definition at line 29 of file logrecord.h.

Path LogRecord::path_ [private]
 

Definition at line 30 of file logrecord.h.

Domain LogRecord::domain_ [private]
 

Definition at line 31 of file logrecord.h.


The documentation for this class was generated from the following files:
httpstats-stage03 [ 7 April, 2001]