This file is indexed.

/usr/include/kolab/errorhandler.h is in libkolab-dev 1.0.2-10ubuntu6.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
/*
 * Copyright (C) 2012  Christian Mollekopf <mollekopf@kolabsys.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


#ifndef ERRORHANDLER_H
#define ERRORHANDLER_H

#include "kolab_export.h"

#include <QString>
#include <QList>
#include <QDebug>

namespace Kolab {

class DebugStream;
/**
 * Kolab Error Handler
 * 
 * Errors are reported during an operation, but the operation might still succeed.
 * The error handler therefore contains all errors which occured during a single operation,
 * and must be cleared at the start of a new operation.
 * 
 * A user of the kolabobject classes should check ErrorHandler::error() after every operation.
 * 
 * all non-const functions are not for the user of this class and only exist for internal usage.
 * 
 * TODO: Hide everything which is not meant for the user from the interface.
 * FIXME: Use Threadlocal storage to make this threadsafe.
 */
class KOLAB_EXPORT ErrorHandler
{
public:
    enum Severity {
        Debug,
        Warning, //Warning, error could be corrected, object can be used without dataloss. This warning is also used if dataloss is acceptable because a feature is explicitly not supported.
        Error, //Potentially corrupt object, writing the object back could result in dataloss. (Object could still be used to display the data readonly).
        Critical //Critical error, produced object cannot be used and should be thrown away (writing back will result in dataloss).
    };
    
    struct Err {
        Err(Severity s, const QString &m, const QString &l): severity(s), message(m), location(l){};
        Severity severity;
        QString message;
        QString location;
    };
    
    static ErrorHandler &instance()
    {
        static ErrorHandler inst;
        return inst;
    }
    
    void addError(Severity s, const QString &message, const QString &location);
    const QList <Err> &getErrors() const;
    Severity error() const;
    QString errorMessage() const;
    void clear();
    
    /**
     * Check for errors during the libkolabxml reading/writing process and copy them into this error handler.
     */
    static void handleLibkolabxmlErrors();
    
    static void clearErrors()
    {
        ErrorHandler::instance().clear();
    }
    
    static bool errorOccured()
    {
        if (ErrorHandler::instance().error() >= Error) {
            return true;
        }
        return false;
    }
    
    /**
     * Returns a debug stream to which logs errors
     */
    static QDebug debugStream(Severity, int line, const char* file);

private:
    ErrorHandler();
    ErrorHandler(const ErrorHandler &);
    ErrorHandler & operator= (const ErrorHandler &);
    
    Severity m_worstError;
    QString m_worstErrorMessage;
    QList <Err> m_errorQueue;
    QScopedPointer<DebugStream> m_debugStream;
};

void logMessage(const QString &,const QString &, int, ErrorHandler::Severity s);

#define LOG(message) logMessage(message,__FILE__, __LINE__, ErrorHandler::Debug);
#define WARNING(message) logMessage(message,__FILE__, __LINE__, ErrorHandler::Warning);
#define ERROR(message) logMessage(message,__FILE__, __LINE__, ErrorHandler::Error);
#define CRITICAL(message) logMessage(message,__FILE__, __LINE__, ErrorHandler::Critical);


class DebugStream: public QIODevice
{
public:
    QString m_location;
    ErrorHandler::Severity m_severity;
    DebugStream();
    virtual ~DebugStream();
    bool isSequential() const { return true; }
    qint64 readData(char *, qint64) { return 0; /* eof */ }
    qint64 readLineData(char *, qint64) { return 0; /* eof */ }
    qint64 writeData(const char *data, qint64 len);
private:
    Q_DISABLE_COPY(DebugStream)
};

#define Debug() Kolab::ErrorHandler::debugStream(Kolab::ErrorHandler::Debug, __LINE__, __FILE__)
#define Warning() Kolab::ErrorHandler::debugStream(Kolab::ErrorHandler::Warning, __LINE__, __FILE__)
#define Error() Kolab::ErrorHandler::debugStream(Kolab::ErrorHandler::Error, __LINE__, __FILE__)
#define Critical() Kolab::ErrorHandler::debugStream(Kolab::ErrorHandler::Critical, __LINE__, __FILE__)

}

QDebug operator<<(QDebug dbg, const std::string &s);

#endif // ERRORHANDLER_H