This file is indexed.

/usr/include/opendht/log_enable.h is in libopendht-dev 1.2.1~dfsg1-8.

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
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
170
171
172
173
174
175
/*
 *  Copyright (C) 2016 Savoir-faire Linux Inc.
 *  Author : Adrien BĂ©raud <adrien.beraud@savoirfairelinux.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 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "infohash.h"

#ifndef OPENDHT_LOG
#define OPENDHT_LOG true
#endif

namespace dht {

// Logging related utility functions

/**
 * Dummy function used to disable logging
 */
inline void NOLOG(char const*, va_list) {}

/**
 * Wrapper for logging methods
 */
struct LogMethod {
    LogMethod() = default;

    template<typename T>
    LogMethod(T&& t) : func(std::forward<T>(t)) {}

    void operator()(char const* format, ...) const {
        va_list args;
        va_start(args, format);
        func(format, args);
        va_end(args);
    }
    void log(char const* format, va_list args) const {
        func(format, args);
    }
    explicit operator bool() const {
        return (bool)func;
    }

    void logPrintable(const uint8_t *buf, size_t buflen) const {
        std::string buf_clean(buflen, '\0');
        for (size_t i=0; i<buflen; i++)
            buf_clean[i] = isprint(buf[i]) ? buf[i] : '.';
        (*this)("%s", buf_clean.c_str());
    }
private:
    std::function<void(char const*, va_list)> func;
};

struct Logger {
    LogMethod DEBUG = NOLOG;
    LogMethod WARN = NOLOG;
    LogMethod ERR = NOLOG;
    void setFilter(const InfoHash& f) {
        filter_ = f;
        filterEnable_ = filter_ != InfoHash{};
    }
    inline void log0(const LogMethod& logger, char const* format, va_list args) const {
#if OPENDHT_LOG
        if (logger and not filterEnable_)
            logger.log(format, args);
#endif
    }
    inline void log1(const LogMethod& logger, const InfoHash& f, char const* format, va_list args) const {
#if OPENDHT_LOG
        if (logger and (not filterEnable_ or f == filter_))
            logger.log(format, args);
#endif
    }
    inline void log2(const LogMethod& logger, const InfoHash& f1, const InfoHash& f2, char const* format, va_list args) const {
#if OPENDHT_LOG
        if (logger and (not filterEnable_ or f1 == filter_ or f2 == filter_))
            logger.log(format, args);
#endif
    }
    inline void d(char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log0(DEBUG, format, args);
        va_end(args);
#endif
    }
    inline void d(const InfoHash& f, char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log1(DEBUG, f, format, args);
        va_end(args);
#endif
    }
    inline void d(const InfoHash& f1, const InfoHash& f2, char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log2(DEBUG, f1, f2, format, args);
        va_end(args);
#endif
    }
    inline void w(char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log0(WARN, format, args);
        va_end(args);
#endif
    }
    inline void w(const InfoHash& f, char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log1(WARN, f, format, args);
        va_end(args);
#endif
    }
    inline void w(const InfoHash& f1, const InfoHash& f2, char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log2(WARN, f1, f2, format, args);
        va_end(args);
#endif
    }
    inline void e(char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log0(ERR, format, args);
        va_end(args);
#endif
    }
    inline void e(const InfoHash& f, char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log1(ERR, f, format, args);
        va_end(args);
#endif
    }
    inline void e(const InfoHash& f1, const InfoHash& f2, char const* format, ...) const {
#if OPENDHT_LOG
        va_list args;
        va_start(args, format);
        log2(ERR, f1, f2, format, args);
        va_end(args);
#endif
    }
private:
    bool filterEnable_ {false};
    InfoHash filter_ {};
};

}