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