Use proper namespace for iostream classes
[gnucomo.git] / src / gcm_input / message.h
1
2 /**************************************************************************
3 **  (c) Copyright 2002, Andromeda Technology & Automation
4 ***************************************************************************
5 ** MODULE INFORMATION *
6 ***********************
7 **      FILE NAME      : message.h
8 **      SYSTEM NAME    : 
9 **      VERSION NUMBER : $Revision: 1.2 $
10 **
11 **  DESCRIPTION      :  Classes to for handling client messages
12 **
13 **  EXPORTED OBJECTS : 
14 **  LOCAL    OBJECTS : 
15 **  MODULES  USED    :
16 ***************************************************************************
17 **  ADMINISTRATIVE INFORMATION *
18 ********************************
19 **      ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
20 **      CREATION DATE   : Sep 16, 2002
21 **      LAST UPDATE     : Nov 04, 2002
22 **      MODIFICATIONS   : 
23 **************************************************************************/
24
25 /*****************************
26    $Log: message.h,v $
27    Revision 1.2  2002-11-04 10:13:36  arjen
28    Use proper namespace for iostream classes
29
30    Revision 1.1  2002/10/05 10:25:49  arjen
31    Creation of gcm_input and a first approach to a web interface
32
33 *****************************/
34
35 /* static const char *RCSID = "$Id: message.h,v 1.2 2002-11-04 10:13:36 arjen Exp $"; */
36
37 #include <iostream>
38 #include <list>
39 #include <AXE/String.h>
40 #include <AXE/date.h>
41
42 #include "database.h"
43
44 /*
45 ///////////////////////////////////////////////////////////////////////////
46 //  NAME           : message_buffer
47 //  BASECLASS      : 
48 //  MEMBERS        :
49 //  OPERATORS      :
50 //  METHODS        : rewind()
51 //
52 //  DESCRIPTION    : 
53 //
54 //  RELATIONS      :
55 //  SEE ALSO       :
56 //  LAST MODIFIED  : Nov 04, 2002
57 ///////////////////////////////////////////////////////////////////////////
58 */
59
60 class message_buffer
61 {
62    std::istream       *input;
63    std::list<String>  buffer;
64
65    std::list<String>::iterator   next_line;
66
67 public:
68
69    message_buffer()
70    {
71       input = 0;
72       next_line = buffer.begin();
73    }
74
75    message_buffer(std::istream *in)
76    {
77       input = in;
78       next_line = buffer.begin();
79    }
80
81    void from(std::istream *in)
82    {
83       input = in;
84    }
85
86    friend bool operator >> (message_buffer &, String &);
87
88    void rewind()
89    {
90       next_line = buffer.begin();
91    }
92
93    void operator ++()
94    {
95       if (next_line != buffer.end())
96       {
97          next_line++;
98       }
99    }
100
101    void operator --()
102    {
103       if (next_line != buffer.begin())
104       {
105          next_line--;
106       }
107    }
108 };
109
110 /*
111 ///////////////////////////////////////////////////////////////////////////
112 //  NAME           : client_message
113 //  BASECLASS      : 
114 //  MEMBERS        :
115 //  OPERATORS      :
116 //  METHODS        : classify()
117 //                   enter()
118 //
119 //  DESCRIPTION    : 
120 //
121 //  RELATIONS      :
122 //  SEE ALSO       :
123 //  LAST MODIFIED  : Nov 04, 2002
124 ///////////////////////////////////////////////////////////////////////////
125 */
126
127 class client_message
128 {
129    String     hostname;      //  Where the message came from (FQDN)
130    UTC        arrival;       //  When we got the message.
131    String     service;       //  Service that created the message
132
133    bool       mail_header;   //  Does the message contain a mail header ?
134    bool       gpg_encrypted; //  Is the message encrypted ?
135
136    double     certainty;     //  How certain are we about the message
137    enum
138    {
139       UNKNOWN, SYSLOG, ACCESSLOG, ERRORLOG
140    }  classification;
141
142
143    message_buffer    input;
144    gnucomo_database  database;
145
146 public:
147
148    client_message(std::istream *in, gnucomo_database db);
149
150    double classify(String host, UTC arrival = Now(), String serv = "");
151    int    enter();
152 };
153