Read IRIX system logs.
[gnucomo.git] / src / gcm_input / message.h
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      : message.h
10 **      SYSTEM NAME    : 
11 **      VERSION NUMBER : $Revision: 1.5 $
12 **
13 **  DESCRIPTION      :  Classes to for handling client messages
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   : Sep 16, 2002
23 **      LAST UPDATE     : Feb 28, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: message.h,v $
29    Revision 1.5  2003-03-16 09:42:40  arjen
30    Read IRIX system logs.
31
32    Revision 1.4  2002/12/06 22:26:28  arjen
33    Set the value of log.processed to FALSE when inserting a
34    new log entry into the database
35    When a syslog entry arrives from last year, gcm_input subtracts one from the
36    year of arrival to create the year of the log entry.
37    Read output from "rpm -qa" and enter packages in the parameter table.
38
39    Revision 1.3  2002/11/09 08:04:27  arjen
40    Added a reference to the GPL
41
42    Revision 1.2  2002/11/04 10:13:36  arjen
43    Use proper namespace for iostream classes
44
45    Revision 1.1  2002/10/05 10:25:49  arjen
46    Creation of gcm_input and a first approach to a web interface
47
48 *****************************/
49
50 /* static const char *RCSID = "$Id: message.h,v 1.5 2003-03-16 09:42:40 arjen Exp $"; */
51
52 #include <iostream>
53 #include <list>
54 #include <AXE/String.h>
55 #include <AXE/date.h>
56
57 #include "database.h"
58
59 /*
60 ///////////////////////////////////////////////////////////////////////////
61 //  NAME           : message_buffer
62 //  BASECLASS      : 
63 //  MEMBERS        :
64 //  OPERATORS      :
65 //  METHODS        : rewind()
66 //
67 //  DESCRIPTION    : 
68 //
69 //  RELATIONS      :
70 //  SEE ALSO       :
71 //  LAST MODIFIED  : Nov 04, 2002
72 ///////////////////////////////////////////////////////////////////////////
73 */
74
75 class message_buffer
76 {
77    std::istream       *input;
78    std::list<String>  buffer;
79
80    std::list<String>::iterator   next_line;
81
82 public:
83
84    message_buffer()
85    {
86       input = 0;
87       next_line = buffer.begin();
88    }
89
90    message_buffer(std::istream *in)
91    {
92       input = in;
93       next_line = buffer.begin();
94    }
95
96    void from(std::istream *in)
97    {
98       input = in;
99    }
100
101    friend bool operator >> (message_buffer &, String &);
102
103    void rewind()
104    {
105       next_line = buffer.begin();
106    }
107
108    void operator ++()
109    {
110       if (next_line != buffer.end())
111       {
112          next_line++;
113       }
114    }
115
116    void operator --()
117    {
118       if (next_line != buffer.begin())
119       {
120          next_line--;
121       }
122    }
123 };
124
125 /*
126 ///////////////////////////////////////////////////////////////////////////
127 //  NAME           : client_message
128 //  BASECLASS      : 
129 //  MEMBERS        :
130 //  OPERATORS      :
131 //  METHODS        : classify()
132 //                   enter()
133 //
134 //  DESCRIPTION    : 
135 //
136 //  RELATIONS      :
137 //  SEE ALSO       :
138 //  LAST MODIFIED  : Feb 28, 2003
139 ///////////////////////////////////////////////////////////////////////////
140 */
141
142 class client_message
143 {
144    String     hostname;      //  Where the message came from (FQDN)
145    UTC        arrival;       //  When we got the message.
146    String     service;       //  Service that created the message
147
148    bool       mail_header;   //  Does the message contain a mail header ?
149    bool       gpg_encrypted; //  Is the message encrypted ?
150
151    double     certainty;     //  How certain are we about the message
152    enum
153    {
154       UNKNOWN, SYSLOG, SYSLOG_IRIX, ACCESSLOG, ERRORLOG, RPMLIST
155    }  classification;
156
157
158    message_buffer    input;
159    gnucomo_database  database;
160
161 public:
162
163    client_message(std::istream *in, gnucomo_database db);
164
165    double classify(String host, UTC arrival = Now(), String serv = "");
166    int    enter();
167 };
168