Accept a wider range of input patterns
[gnucomo.git] / src / gcm_input / access_cooker.cpp
1
2 /**************************************************************************
3 **  (c) Copyright 2002, Andromeda Technology & Automation
4 ** This is free software; you can redistribute it and/or modify it under the
5 ** terms of the GNU General Public License, see the file COPYING.
6 ***************************************************************************
7 ** MODULE INFORMATION *
8 ***********************
9 **      FILE NAME      : access_cooker.cpp
10 **      SYSTEM NAME    : 
11 **      VERSION NUMBER : $Revision: 1.3 $
12 **
13 **  DESCRIPTION      :  Cooks Apache http daemon access log lines
14 **
15 **  EXPORTED OBJECTS : 
16 **  LOCAL    OBJECTS : 
17 **  MODULES  USED    :
18 ***************************************************************************
19 **  ADMINISTRATIVE INFORMATION *
20 ********************************
21 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
22 **      CREATION DATE   : Aug 11, 2003
23 **      LAST UPDATE     : Aug 11, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: access_cooker.cpp,v $
29    Revision 1.3  2003-12-22 10:22:21  arjen
30    Accept a wider range of input patterns
31
32    Revision 1.2  2003/12/04 10:38:09  arjen
33    Major redesign. All input is handled through XML. Raw input data is first
34    transformed into an XML document for further processing.
35    A collection of polymorphic classes handle the transformation of various
36    input formats into XML.
37    Classifying input data is done with a finite improbability calculation.
38
39    Revision 1.1  2003/08/11 16:56:15  arjen
40    Different kinds of log files are parsed by a collection of objects
41    of different classes, derived from the base class line_cooker
42    Depending on the message content or the message_type element in
43    XML, one of these objects is selected.
44
45    Logrunner is integrated with gcm_input. Although its functionality
46    is still limited, a connection between logrunner and gcm_input
47    is beginning to form.
48
49 *****************************/
50
51 /* static const char *RCSID = "$Id: access_cooker.cpp,v 1.3 2003-12-22 10:22:21 arjen Exp $"; */
52
53 #include <ctype.h>
54
55 #include "access_cooker.h"
56
57 static const regex re_accesslog("(GET|POST|HEAD|OPTIONS|CONNECT) .+ HTTP");
58
59 bool access_cooker::check_pattern(String logline)
60 {
61    return logline == re_accesslog;
62 }
63
64 bool access_cooker::cook_this(String logline, UTC arrival)
65 {
66    if (check_pattern(logline))
67    {
68       String datestring = logline(regex("\\[.+\\]"));
69
70       datestring <<= 1;
71       datestring >>= 1;
72       datestring[datestring.index(':')] = ' ';
73
74       date   log_date = datestring;
75       hour   log_time = datestring;
76
77       log_date = datestring;
78       log_time = datestring;
79
80       ts = UTC(log_date, log_time);
81
82       hn  = "";
83       srv = "httpd";
84
85       return true;
86    }
87    else
88    {
89       return false;
90    }
91 }
92
93