File indexing completed on 2024-05-12 05:17:25

0001 /*
0002     Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0003     Author: Kevin Ottens <kevin@kdab.com>
0004 
0005     This library is free software; you can redistribute it and/or modify it
0006     under the terms of the GNU Library General Public License as published by
0007     the Free Software Foundation; either version 2 of the License, or (at your
0008     option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful, but WITHOUT
0011     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0012     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
0013     License for more details.
0014 
0015     You should have received a copy of the GNU Library General Public License
0016     along with this library; see the file COPYING.LIB.  If not, write to the
0017     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0018     02110-1301, USA.
0019 */
0020 
0021 #include "sessionlogger_p.h"
0022 
0023 #include "kimap_debug.h"
0024 
0025 #ifdef WIN32
0026 #include <process.h>
0027 #else
0028 #include <unistd.h> //for getpid()
0029 #endif
0030 
0031 using namespace KIMAP2;
0032 
0033 SessionLogger::SessionLogger()
0034     : m_id(0)
0035 {
0036     static qint64 nextId = 0;
0037     m_id = ++nextId;
0038 
0039     m_file.setFileName(QLatin1String(qgetenv("KIMAP2_LOGFILE"))
0040                        + QLatin1Char('.')
0041 #ifdef WIN32
0042                        + QString::number(_getpid())
0043 #else
0044                        + QString::number(getpid())
0045 #endif
0046                        + QLatin1Char('.') + QString::number(m_id));
0047     if (!m_file.open(QFile::WriteOnly)) {
0048         qCDebug(KIMAP2_LOG) << " m_file can be open in write only";
0049     }
0050 }
0051 
0052 SessionLogger::~SessionLogger()
0053 {
0054     m_file.close();
0055 }
0056 
0057 void SessionLogger::dataSent(const QByteArray &data)
0058 {
0059     m_file.write("C: " + data.trimmed() + '\n');
0060     m_file.flush();
0061 }
0062 
0063 void SessionLogger::dataReceived(const QByteArray &data)
0064 {
0065     m_file.write("S: " + data.trimmed() + '\n');
0066     m_file.flush();
0067 }
0068 
0069 void SessionLogger::disconnectionOccured()
0070 {
0071     m_file.write("X\n");
0072 }