This file is indexed.

/usr/include/measurement_kit/net/buffer.hpp is in libmeasurement-kit-dev 0.7.1-2build1.

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
// Part of measurement-kit <https://measurement-kit.github.io/>.
// Measurement-kit is free software. See AUTHORS and LICENSE for more
// information on the copying conditions.
#ifndef MEASUREMENT_KIT_NET_BUFFER_HPP
#define MEASUREMENT_KIT_NET_BUFFER_HPP

#include <measurement_kit/common.hpp>

struct evbuffer;

namespace mk {
namespace net {

class Buffer {
  public:
    Buffer();
    Buffer(evbuffer *b);
    Buffer(std::string);
    Buffer(const void *, size_t);

    ~Buffer() {}

    static Var<Buffer> make();

    /*
     * I expect to read (write) from (into) the input (output)
     * evbuffer of a certain bufferevent. It seems to me natural
     * to use the insertion and extraction operators for that.
     */

    Buffer &operator<<(evbuffer *source);

    Buffer &operator>>(evbuffer *dest);

    Buffer &operator<<(Buffer &source);

    Buffer &operator>>(Buffer &source);

    size_t length();

    /*
     * The following is useful to feed a parser (e.g., the http-parser)
     * with all (or part of) the content of `this`.
     */
    void for_each(std::function<bool(const void *, size_t)> fn);

    /*
     * Discard(), read(), readline() and readn() are the common operations
     * that you need to implement a protocol (AFAICT).
     */

    void discard(size_t count);
    void discard() { discard(length()); }

    std::string readpeek(bool ispeek, size_t upto);

    std::string read(size_t upto) { return readpeek(false, upto); }

    std::string read() { return read(length()); }

    std::string peek(size_t upto) { return readpeek(true, upto); }

    std::string peek() { return peek(length()); }

    /*
     * The semantic of readn() is that we return a string only
     * when we have exactly N bytes available.
     */
    std::string readn(size_t n) {
        if (n > length()) return "";
        return read(n);
    }

    ErrorOr<std::string> readline(size_t maxline);

    /*
     * Wrappers for write, including a handy wrapper for sending
     * random bytes to the output stream.
     */

    void write(std::string in) { write(in.c_str(), in.length()); }

    Buffer &operator<<(std::string in) {
        write(in);
        return *this;
    }

    void write(const char *in) {
        if (in == nullptr) throw std::runtime_error("in is nullptr");
        write(in, strlen(in));
    }

    Buffer &operator<<(const char *in) {
        write(in);
        return *this;
    }

    void write(const void *buf, size_t count);

    ErrorOr<uint8_t> read_uint8();

    void write_uint8(uint8_t);

    ErrorOr<uint16_t> read_uint16();

    void write_uint16(uint16_t);

    ErrorOr<uint32_t> read_uint32();

    void write_uint32(uint32_t);

    void write_rand(size_t count);

    void write(size_t count, std::function<size_t(void *, size_t)> func);

    Var<evbuffer> evbuf;
};

} // namespace net
} // namespace mk
#endif