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