summaryrefslogtreecommitdiffstats
path: root/ksystemlog/src/samba/sambaReader.cpp
blob: f1fcb673fd12ad3fe662df13eac9b327de73a515 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/***************************************************************************
 *   Copyright (C) 2005 by Nicolas Ternisien                               *
 *   nicolas.ternisien@gmail.com                                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

#include <klocale.h>
#include <kmessagebox.h>

#include "parsingHelper.h"
#include "sambaReader.h"

SambaReader::SambaReader(TQObject *parent, const char *name) : 
	DefaultReader(parent, name)
	{
	
}


SambaReader::~SambaReader() {

}


void SambaReader::initColumns(LogViewColumns* columns) {
	columns->append(new LogViewColumn(i18n("Date"), true, false));
	columns->append(new LogViewColumn(i18n("Source File"), true, true));
	columns->append(new LogViewColumn(i18n("Function"), true, true));
	columns->append(new LogViewColumn(i18n("Line"), true, true));
	columns->append(new LogViewColumn(i18n("Message"), true, false));

}

LogLine* SambaReader::parseMessage(TQString& logLine, LogFile* logFile) {

	/*
	 * Log line examples :
	 * [2005/06/27 21:06:01, 0] nmbd/nmbd.c:main(668)
	 * Netbios nameserver version 3.0.14a started.
	 * Copyright Andrew Tridgell and the Samba Team 1994-2004
	 * [2005/06/27 21:11:46, 0] nmbd/nmbd_become_lmb.c:become_local_master_stage2(396)
	 *  *****
	 *  Samba name server STEAKHACHE is now a local master browser for workgroup MAISON on subnet 192.168.1.33
	 * 
	 *  *****
	 * [2005/06/28 06:41:03, 0] nmbd/nmbd.c:terminate(56)
	 * Got SIGTERM: going down...
	 * [2005/06/28 18:08:11, 0] nmbd/nmbd.c:main(668)
	 * Netbios nameserver version 3.0.14a started.
	 * Copyright Andrew Tridgell and the Samba Team 1994-2004
	 */
	
	//The Date
	int dateBegin=logLine.find("[");
	int dateEnd=logLine.find("]");
	
	TQString strDate=logLine.mid(dateBegin+1, dateEnd-dateBegin-1);
	
	TQString year=strDate.mid(0, 4);
	TQString month=strDate.mid(5, 2);
	TQString day=strDate.mid(8, 2);
	
	TQString hour=strDate.mid(11, 2);
	TQString min=strDate.mid(14, 2);
	TQString sec=strDate.mid(17, 2);

	TQDate date=TQDate(year.toInt(), month.toInt(), day.toInt());
	TQTime time=TQTime(hour.toInt(), min.toInt(), sec.toInt());

	logLine=logLine.remove(0, dateEnd+2);
	

	//The source file
	int doubleDot;
	doubleDot=logLine.find(":");
	TQString file=logLine.left(doubleDot);
	logLine=logLine.remove(0, doubleDot+1);
	
	//The function
	int bracket=logLine.find("(");
	TQString function=logLine.left(bracket);
	logLine=logLine.remove(0, bracket+1);
	
	//The line number
	bracket=logLine.find(")");
	TQString lineNumber=logLine.left(bracket);
	
	//Remove the first return character and the two useless space of the first message line
	logLine=logLine.remove(0, bracket+4);

	//Message
	//Remove the last \n
	logLine=logLine.left(logLine.length()-1);
	//Remove return characters and 2 first spaces at each lines
	TQString message=logLine.replace("\n  ", " / ");

	//TQString message=logLine.replace("\n", " / ");
	
	TQStringList list;
	list.push_back(file);
	list.push_back(function);
	list.push_back(lineNumber);
	list.push_back(message);
	
	TQString filePath=logFile->url.path();

	LogLine* line=new LogLine(date, time, list, filePath, Globals::informationLogLevel, Globals::sambaMode->id);
	
	return(line);
}

TQStringList* SambaReader::getRawBuffer(TQFile* file) {
	kdDebug() << "Retrieving the raw buffer..." << endl;

	TQString line;
	
	TQString buffer;
	TQString tmpBuffer;
	TQStringList* rawBuffer=new TQStringList();
	
	int res;

	//Insert the content of the file in a string list
	while(!file->atEnd()) {
	
		//Read the first MaxCharactersRead characters
		res=file->readLine(buffer, tmpMaxCharacters);
		
		//Ignore the rest of the line
		while(res==tmpMaxCharacters)
			file->readLine(tmpBuffer, tmpMaxCharacters);
		
		if (buffer[0]=='[') {
			
			//If it is not the first time we add a line
			if (!line.isNull()) {
				//Push the new buffer to the list
				rawBuffer->push_back(line);
			}
			
			line=buffer;
		}
		else {
			//line+='\n';
			line+=buffer;
		}
	}

	kdDebug() << "Raw buffer retrieved." << endl;
	
	return(rawBuffer);
}


#include "sambaReader.moc"