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