eb32449d321445755782476dff3a05e3bb806b81
[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.7 $
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     : Aug 06, 2003
24 **      MODIFICATIONS   : 
25 **************************************************************************/
26
27 /*****************************
28    $Log: message.h,v $
29    Revision 1.7  2003-08-11 16:56:16  arjen
30    Different kinds of log files are parsed by a collection of objects
31    of different classes, derived from the base class line_cooker
32    Depending on the message content or the message_type element in
33    XML, one of these objects is selected.
34
35    Logrunner is integrated with gcm_input. Although its functionality
36    is still limited, a connection between logrunner and gcm_input
37    is beginning to form.
38
39    Revision 1.6  2003/04/29 09:16:44  arjen
40    Read XML input,
41    Only cooked log entries for now.
42
43    Revision 1.5  2003/03/16 09:42:40  arjen
44    Read IRIX system logs.
45
46    Revision 1.4  2002/12/06 22:26:28  arjen
47    Set the value of log.processed to FALSE when inserting a
48    new log entry into the database
49    When a syslog entry arrives from last year, gcm_input subtracts one from the
50    year of arrival to create the year of the log entry.
51    Read output from "rpm -qa" and enter packages in the parameter table.
52
53    Revision 1.3  2002/11/09 08:04:27  arjen
54    Added a reference to the GPL
55
56    Revision 1.2  2002/11/04 10:13:36  arjen
57    Use proper namespace for iostream classes
58
59    Revision 1.1  2002/10/05 10:25:49  arjen
60    Creation of gcm_input and a first approach to a web interface
61
62 *****************************/
63
64 /* static const char *RCSID = "$Id: message.h,v 1.7 2003-08-11 16:56:16 arjen Exp $"; */
65
66 #include <iostream>
67 #include <list>
68 #include <AXE/String.h>
69 #include <AXE/date.h>
70
71 #include <libxml/parser.h>
72
73 #include "line_cooker.h"
74 #include "database.h"
75
76 /*
77 ///////////////////////////////////////////////////////////////////////////
78 //  NAME           : message_buffer
79 //  BASECLASS      : 
80 //  MEMBERS        :
81 //  OPERATORS      :
82 //  METHODS        : rewind()
83 //
84 //  DESCRIPTION    : 
85 //
86 //  RELATIONS      :
87 //  SEE ALSO       :
88 //  LAST MODIFIED  : Nov 04, 2002
89 ///////////////////////////////////////////////////////////////////////////
90 */
91
92 class message_buffer
93 {
94    std::istream       *input;
95    std::list<String>  buffer;
96
97    std::list<String>::iterator   next_line;
98
99 public:
100
101    message_buffer()
102    {
103       input = 0;
104       next_line = buffer.begin();
105    }
106
107    message_buffer(std::istream *in)
108    {
109       input = in;
110       next_line = buffer.begin();
111    }
112
113    void from(std::istream *in)
114    {
115       input = in;
116    }
117
118    friend bool operator >> (message_buffer &, String &);
119
120    void rewind()
121    {
122       next_line = buffer.begin();
123    }
124
125    void operator ++()
126    {
127       if (next_line != buffer.end())
128       {
129          next_line++;
130       }
131    }
132
133    void operator --()
134    {
135       if (next_line != buffer.begin())
136       {
137          next_line--;
138       }
139    }
140 };
141
142 /*
143 ///////////////////////////////////////////////////////////////////////////
144 //  NAME           : client_message
145 //  BASECLASS      : 
146 //  MEMBERS        :
147 //  OPERATORS      :
148 //  METHODS        : classify()
149 //                   enter()
150 //
151 //  DESCRIPTION    : 
152 //
153 //  RELATIONS      :
154 //  SEE ALSO       :
155 //  LAST MODIFIED  : Aug 06, 2003
156 ///////////////////////////////////////////////////////////////////////////
157 */
158
159 class client_message
160 {
161    String     hostname;      //  Where the message came from (FQDN)
162    UTC        arrival;       //  When we got the message.
163    String     service;       //  Service that created the message
164
165    std::list<line_cooker *>  kitchen;   //  The collection of line cookers
166    line_cooker           *   pan;       //  The one we cook this log with
167
168    bool       mail_header;   //  Does the message contain a mail header ?
169    bool       gpg_encrypted; //  Is the message encrypted ?
170
171    xmlDocPtr  xmlDom;
172
173    double     certainty;     //  How certain are we about the message
174    enum
175    {
176       UNKNOWN,  RPMLIST, XML, COOKER_OBJECT
177    }  classification;
178
179
180    message_buffer    input;
181    gnucomo_database  database;
182
183    int     readXMLinput(String first_line);
184    void    enterXML();
185
186 public:
187
188    client_message(std::istream *in, gnucomo_database db);
189
190    void   add_cooker(line_cooker *lc)
191    {
192       kitchen.push_back(lc);
193    }
194
195    double classify(String host, UTC arrival = Now(), String serv = "");
196    int    enter();
197 };
198