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