~ubuntu-branches/ubuntu/dapper/ksystemlog/dapper

« back to all changes in this revision

Viewing changes to ksystemlog/src/readerFactory.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-07-07 16:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20050707160000-a104d769ph3yfkg4
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2005 by Nicolas Ternisien                               *
 
3
 *   nicolas.ternisien@gmail.com                                           *
 
4
 *                                                                         *
 
5
 *   This program is free software; you can redistribute it and/or modify  *
 
6
 *   it under the terms of the GNU General Public License as published by  *
 
7
 *   the Free Software Foundation; either version 2 of the License, or     *
 
8
 *   (at your option) any later version.                                   *
 
9
 *                                                                         *
 
10
 *   This program is distributed in the hope that it will be useful,       *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
13
 *   GNU General Public License for more details.                          *
 
14
 *                                                                         *
 
15
 *   You should have received a copy of the GNU General Public License     *
 
16
 *   along with this program; if not, write to the                         *
 
17
 *   Free Software Foundation, Inc.,                                       *
 
18
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 
19
 ***************************************************************************/
 
20
 
 
21
#include <klocale.h>
 
22
 
 
23
 
 
24
#include "ksystemlogConfig.h"
 
25
#include "systemReader.h"
 
26
#include "xorgReader.h"
 
27
#include "cronReader.h"
 
28
#include "acpidReader.h"
 
29
 
 
30
#include "cupsReader.h"
 
31
#include "cupsAccessReader.h"
 
32
 
 
33
#include "apacheReader.h"
 
34
#include "apacheAccessReader.h"
 
35
 
 
36
#include "sambaReader.h"
 
37
 
 
38
#include "readerFactory.h"
 
39
 
 
40
KURL ReaderFactory::lastOpenedURL;
 
41
 
 
42
Reader* ReaderFactory::createReader(LogMode* logMode) {
 
43
        
 
44
        /**
 
45
         * Using System Mode in the current view
 
46
         */
 
47
        if (logMode==Globals::systemMode) {
 
48
                Reader* reader=new SystemReader(NULL, "system_reader");
 
49
                return(reader);
 
50
        }
 
51
        
 
52
        /**
 
53
         * Using Boot Mode in the current view
 
54
         */
 
55
        else if (logMode==Globals::bootMode) {
 
56
                Reader* reader=new SystemReader(NULL, "boot_reader");
 
57
                return(reader);
 
58
        }
 
59
        
 
60
        /**
 
61
         * Using Authentication Mode in the current view
 
62
         */
 
63
        else if (logMode==Globals::authenticationMode) {
 
64
                Reader* reader=new SystemReader(NULL, "authentication_reader");
 
65
                return(reader);
 
66
        }
 
67
        
 
68
        /**
 
69
         * Using Kernel Mode in the current view
 
70
         */
 
71
        else if (logMode==Globals::kernelMode) {
 
72
                Reader* reader=new SystemReader(NULL, "kernel_reader");
 
73
                return(reader);
 
74
        }
 
75
        
 
76
        /**
 
77
         * Using Daemon Mode in the current view
 
78
         */
 
79
        else if (logMode==Globals::daemonMode) {
 
80
                Reader* reader=new SystemReader(NULL, "daemon_reader");
 
81
                return(reader);
 
82
        }
 
83
        
 
84
        /**
 
85
         * Using Cron Mode in the current view
 
86
         */
 
87
        else if (logMode==Globals::cronMode) {
 
88
                Reader* reader=new CronReader(NULL, "cron_reader");
 
89
                return(reader);
 
90
        }
 
91
        
 
92
        /**
 
93
         * Using Cron Mode in the current view
 
94
         */
 
95
        else if (logMode==Globals::xorgMode) {
 
96
                Reader* reader=new XorgReader(NULL, "xorg_reader");
 
97
                return(reader);
 
98
        }
 
99
        
 
100
 
 
101
        /**
 
102
         * Using ACPID Mode in the current view
 
103
         */
 
104
        else if (logMode==Globals::acpidMode) {
 
105
                Reader* reader=new AcpidReader(NULL, "acpid_reader");
 
106
                return(reader);
 
107
        }
 
108
        
 
109
        /**
 
110
         * Using Cups Mode in the current view
 
111
         */
 
112
        else if (logMode==Globals::cupsMode) {
 
113
                Reader* reader=new CupsReader(NULL, "cups_reader");
 
114
                return(reader);
 
115
        }
 
116
 
 
117
        /**
 
118
         * Using Cups Access Mode in the current view
 
119
         */
 
120
        else if (logMode==Globals::cupsAccessMode) {
 
121
                Reader* reader=new CupsAccessReader(NULL, "cups_access_reader");
 
122
                return(reader);
 
123
        }
 
124
        
 
125
        /**
 
126
         * Using Apache Mode in the current view
 
127
         */
 
128
        else if (logMode==Globals::apacheMode) {
 
129
                Reader* reader=new ApacheReader(NULL, "apache_reader");
 
130
                return(reader);
 
131
        }
 
132
 
 
133
        /**
 
134
         * Using Apache Access Mode in the current view
 
135
         */
 
136
        else if (logMode==Globals::apacheAccessMode) {
 
137
                Reader* reader=new ApacheAccessReader(NULL, "apache_access_reader");
 
138
                return(reader);
 
139
        }
 
140
        
 
141
        /**
 
142
         * Using Postfix Mode in the current view
 
143
         */
 
144
        else if (logMode==Globals::postfixMode) {
 
145
                Reader* reader=new SystemReader(NULL, "postfix_reader");
 
146
                return(reader);
 
147
        }
 
148
 
 
149
        /**
 
150
         * Using Samba Mode in the current view
 
151
         */
 
152
        else if (logMode==Globals::sambaMode) {
 
153
                Reader* reader=new SambaReader(NULL, "samba_reader");
 
154
                return(reader);
 
155
        }
 
156
        
 
157
        /**
 
158
         * Using Opening Mode in the current view
 
159
         */
 
160
        else if (logMode==Globals::openingMode) {
 
161
                //TODO For the moment, SystemReader is always used to parse file.
 
162
                // Implement a test case for each Reader to know who is the better to read the file
 
163
                Reader* reader=new SystemReader(NULL, "opening_reader");
 
164
                return(reader);
 
165
        }
 
166
        else {
 
167
                kdDebug() << "Error : LogMode not found : returns NULL Reader" << endl;
 
168
                return(NULL);
 
169
        }
 
170
}
 
171
 
 
172
LogFiles* ReaderFactory::createLogFiles(LogMode* logMode) {
 
173
 
 
174
        /**
 
175
         * Using System Mode in the current view
 
176
         */
 
177
        if (logMode==Globals::systemMode) {
 
178
                //Give the log file list to the reader
 
179
                LogFiles* list=ReaderFactory::getSystemLogFiles();
 
180
                return(list);
 
181
        }
 
182
        
 
183
        /**
 
184
         * Using Boot Mode in the current view
 
185
         */
 
186
        else if (logMode==Globals::bootMode) {
 
187
                //Give the log file list to the reader
 
188
                LogFile* file=ReaderFactory::getBootLogFile();
 
189
                LogFiles* list=new LogFiles();
 
190
                list->append(file);
 
191
                return(list);
 
192
        }
 
193
        
 
194
        /**
 
195
         * Using Authentication Mode in the current view
 
196
         */
 
197
        else if (logMode==Globals::authenticationMode) {
 
198
                //Give the log file list to the reader
 
199
                LogFile* file=ReaderFactory::getAuthenticationLogFile();
 
200
                
 
201
                LogFiles* list=new LogFiles();
 
202
                list->append(file);
 
203
                return(list);
 
204
        }
 
205
        
 
206
        /**
 
207
         * Using Kernel Mode in the current view
 
208
         */
 
209
        else if (logMode==Globals::kernelMode) {
 
210
                //Give the log file list to the reader
 
211
                LogFiles* list=ReaderFactory::getKernelLogFiles();
 
212
                return(list);
 
213
        }
 
214
        
 
215
        /**
 
216
         * Using Daemon Mode in the current view
 
217
         */
 
218
        else if (logMode==Globals::daemonMode) {
 
219
                //Give the log file list to the reader
 
220
                LogFiles* list=ReaderFactory::getDaemonLogFiles();
 
221
                return(list);
 
222
        }
 
223
        
 
224
        /**
 
225
         * Using Cron Mode in the current view
 
226
         */
 
227
        else if (logMode==Globals::cronMode) {
 
228
                //Give the log file list to the reader
 
229
                LogFiles* list=ReaderFactory::getCronLogFiles();
 
230
                return(list);
 
231
        }
 
232
        
 
233
        /**
 
234
         * Using Cron Mode in the current view
 
235
         */
 
236
        else if (logMode==Globals::xorgMode) {
 
237
                //Give the log file list to the reader
 
238
                LogFiles* list=ReaderFactory::getXorgLogFiles();
 
239
                return(list);
 
240
        }
 
241
        
 
242
 
 
243
        /**
 
244
         * Using ACPID Mode in the current view
 
245
         */
 
246
        else if (logMode==Globals::acpidMode) {
 
247
                //Give the log file list to the reader
 
248
                LogFiles* list=ReaderFactory::getAcpidLogFiles();
 
249
                return(list);
 
250
 
 
251
        }
 
252
        
 
253
        /**
 
254
         * Using Cups Mode in the current view
 
255
         */
 
256
        else if (logMode==Globals::cupsMode) {
 
257
                //Give the log file list to the reader
 
258
                LogFiles* list=ReaderFactory::getCupsLogFiles();
 
259
                return(list);
 
260
        }
 
261
 
 
262
        /**
 
263
         * Using Cups Access Mode in the current view
 
264
         */
 
265
        else if (logMode==Globals::cupsAccessMode) {
 
266
                //Give the log file list to the reader
 
267
                LogFiles* list=ReaderFactory::getCupsAccessLogFiles();
 
268
                return(list);
 
269
 
 
270
        }
 
271
        
 
272
        /**
 
273
         * Using Apache Mode in the current view
 
274
         */
 
275
        else if (logMode==Globals::apacheMode) {
 
276
                //Give the log file list to the reader
 
277
                LogFiles* list=ReaderFactory::getApacheLogFiles();
 
278
                return(list);
 
279
        }
 
280
 
 
281
        /**
 
282
         * Using Apache Access Mode in the current view
 
283
         */
 
284
        else if (logMode==Globals::apacheAccessMode) {
 
285
                //Give the log file list to the reader
 
286
                LogFiles* list=ReaderFactory::getApacheAccessLogFiles();
 
287
                return(list);
 
288
 
 
289
        }
 
290
        
 
291
        /**
 
292
         * Using Postfix Mode in the current view
 
293
         */
 
294
        else if (logMode==Globals::postfixMode) {
 
295
                //Give the log file list to the reader
 
296
                LogFiles* list=ReaderFactory::getPostfixLogFiles();
 
297
                return(list);
 
298
        }
 
299
        
 
300
        /**
 
301
         * Using Samba Mode in the current view
 
302
         */
 
303
        else if (logMode==Globals::sambaMode) {
 
304
                //Give the log file list to the reader
 
305
                LogFiles* list=ReaderFactory::getSambaLogFiles();
 
306
                return(list);
 
307
        }
 
308
        
 
309
        /**
 
310
         * Using Opening Mode in the current view
 
311
         */
 
312
        else if (logMode==Globals::openingMode) {
 
313
                //Give the file to open to the reader
 
314
                
 
315
                //A little hack... ;-) (what an oriented-object solution !)
 
316
                LogFile* logFile=new LogFile(lastOpenedURL, Globals::informationLogLevel);
 
317
                
 
318
                LogFiles* list=new LogFiles();
 
319
                list->append(logFile);
 
320
                return(list);
 
321
        }
 
322
        else {
 
323
                kdDebug() << "Error : LogFiles not found : returns NULL Reader" << endl;
 
324
                return(NULL);
 
325
        }
 
326
}
 
327
 
 
328
 
 
329
 
 
330
 
 
331
 
 
332
LogFile* ReaderFactory::getGenericLogFile(QString& file) {
 
333
 
 
334
        LogLevel* level=Globals::informationLogLevel;
 
335
        
 
336
        KURL url(file);
 
337
        if (!url.isValid()) {
 
338
                kdDebug() << i18n("URL '%1' is not valid, skipping this URL.").arg(url.path()) << endl;
 
339
                return(NULL);
 
340
        }
 
341
        
 
342
        LogFile* logFile=new LogFile(url, level);
 
343
        return(logFile);
 
344
}
 
345
 
 
346
LogFiles* ReaderFactory::getGenericLogFiles(QStringList& stringList, QValueList<int>& valueList) {
 
347
 
 
348
        LogFiles* logFiles=new LogFiles();
 
349
        
 
350
        if (stringList.size() != valueList.size()) {
 
351
                kdDebug() << i18n("The two arrays size are different, skipping the reading of log files.") << endl;
 
352
                return(logFiles);
 
353
        }
 
354
 
 
355
        LogFile* logFile;
 
356
        
 
357
        LogLevel* level;
 
358
        
 
359
        QStringList::Iterator itString=stringList.begin();
 
360
        QValueList<int>::Iterator itInt=valueList.begin();
 
361
        
 
362
        while(itString!=stringList.end()) {
 
363
                if (*itInt>=0 && *itInt<(int) Globals::logLevels.count())
 
364
                        level=Globals::logLevels.at(*itInt);
 
365
                else
 
366
                        level=Globals::informationLogLevel;
 
367
                
 
368
                KURL url(*itString);
 
369
                if (!url.isValid()) {
 
370
                        kdDebug() << i18n("URL '%1' is not valid, skipping this URL.").arg(url.path()) << endl;
 
371
                        continue;
 
372
                        itString++;
 
373
                        itInt++;
 
374
                }
 
375
                
 
376
                logFile=new LogFile(url, level);
 
377
                logFiles->push_back(logFile);
 
378
                        
 
379
        
 
380
                itString++;
 
381
                itInt++;
 
382
        }
 
383
        
 
384
        return(logFiles);
 
385
}
 
386
 
 
387
LogFiles* ReaderFactory::getNoModeLogFiles(QStringList& stringList) {
 
388
 
 
389
        LogFiles* logFiles=new LogFiles();
 
390
        
 
391
        LogFile* logFile;
 
392
        
 
393
        //Default level used for No Mode logs
 
394
        LogLevel* level=Globals::noneLogLevel;
 
395
        
 
396
        QStringList::Iterator it;
 
397
        for(it=stringList.begin(); it!=stringList.end(); it++) {
 
398
                
 
399
                KURL url(*it);
 
400
                if (!url.isValid()) {
 
401
                        kdDebug() << i18n("URL '%1' is not valid, skipping this URL.").arg(url.path()) << endl;
 
402
                        continue;
 
403
                }
 
404
                
 
405
                logFile=new LogFile(url, level);
 
406
                logFiles->push_back(logFile);
 
407
 
 
408
        }
 
409
        
 
410
        return(logFiles);
 
411
}
 
412
 
 
413
LogFile* ReaderFactory::getBootLogFile() {
 
414
        QString file=KSystemLogConfig::bootPath();
 
415
        return(getGenericLogFile(file));
 
416
}
 
417
 
 
418
LogFile* ReaderFactory::getAuthenticationLogFile() {
 
419
        QString file=KSystemLogConfig::authenticationPath();
 
420
        return(getGenericLogFile(file));
 
421
}
 
422
 
 
423
LogFiles* ReaderFactory::getSystemLogFiles() {
 
424
        QStringList files=KSystemLogConfig::systemPaths();
 
425
        QValueList<int> levels=KSystemLogConfig::systemLevels();
 
426
        return(ReaderFactory::getGenericLogFiles(files, levels));
 
427
}
 
428
 
 
429
LogFiles* ReaderFactory::getAcpidLogFiles() {
 
430
        QStringList files=KSystemLogConfig::acpidPaths();
 
431
        
 
432
        return(getNoModeLogFiles(files));
 
433
}
 
434
 
 
435
LogFiles* ReaderFactory::getKernelLogFiles() {
 
436
        QStringList files=KSystemLogConfig::kernelPaths();
 
437
        QValueList<int> levels=KSystemLogConfig::kernelLevels();
 
438
        return(ReaderFactory::getGenericLogFiles(files, levels));
 
439
}
 
440
                
 
441
LogFiles* ReaderFactory::getDaemonLogFiles() {
 
442
        QStringList files=KSystemLogConfig::daemonPaths();
 
443
        QValueList<int> levels=KSystemLogConfig::daemonLevels();
 
444
        return(ReaderFactory::getGenericLogFiles(files, levels));
 
445
}
 
446
 
 
447
LogFiles* ReaderFactory::getCronLogFiles() {
 
448
        QStringList files=KSystemLogConfig::cronPaths();
 
449
        QValueList<int> levels=KSystemLogConfig::cronLevels();
 
450
        return(ReaderFactory::getGenericLogFiles(files, levels));
 
451
}
 
452
 
 
453
 
 
454
LogFiles* ReaderFactory::getXorgLogFiles() {
 
455
        QStringList stringList=KSystemLogConfig::xorgPaths();
 
456
        return(getNoModeLogFiles(stringList));
 
457
}
 
458
 
 
459
LogFiles* ReaderFactory::getCupsLogFiles() {
 
460
        QStringList stringList=KSystemLogConfig::cupsPaths();
 
461
        return(getNoModeLogFiles(stringList));
 
462
}
 
463
 
 
464
LogFiles* ReaderFactory::getCupsAccessLogFiles() {
 
465
        QStringList stringList=KSystemLogConfig::cupsAccessPaths();
 
466
        return(getNoModeLogFiles(stringList));
 
467
}
 
468
 
 
469
LogFiles* ReaderFactory::getApacheLogFiles() {
 
470
        QStringList stringList=KSystemLogConfig::apachePaths();
 
471
        return(getNoModeLogFiles(stringList));
 
472
}
 
473
 
 
474
LogFiles* ReaderFactory::getApacheAccessLogFiles() {
 
475
        QStringList stringList=KSystemLogConfig::apacheAccessPaths();
 
476
        return(getNoModeLogFiles(stringList));
 
477
}
 
478
 
 
479
LogFiles* ReaderFactory::getPostfixLogFiles() {
 
480
        QStringList files=KSystemLogConfig::postfixPaths();
 
481
        QValueList<int> levels=KSystemLogConfig::postfixLevels();
 
482
        return(ReaderFactory::getGenericLogFiles(files, levels));
 
483
}
 
484
 
 
485
LogFiles* ReaderFactory::getSambaLogFiles() {
 
486
        QStringList stringList=KSystemLogConfig::sambaPaths();
 
487
        return(getNoModeLogFiles(stringList));
 
488
}
 
489