This file is indexed.

/usr/include/ola/ExportMap.h is in libola-dev 0.10.3.nojsmin-2+deb9u1.

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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/*
 * This library 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 2.1 of the License, or (at your option) any later version.
 *
 * This library 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 library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 * ExportMap.h
 * Interface the ExportMap and ExportedVariables
 * Copyright (C) 2005 Simon Newton
 */

/**
 * @file ExportMap.h
 * @brief Export variables on the http server.
 *
 * Exported variables can be used to expose the internal state on the /debug
 * page of the webserver. This allows real time debugging and monitoring of the
 * applications.
 */

#ifndef INCLUDE_OLA_EXPORTMAP_H_
#define INCLUDE_OLA_EXPORTMAP_H_

#include <ola/base/Macro.h>
#include <ola/StringUtils.h>
#include <stdlib.h>

#include <functional>
#include <map>
#include <sstream>
#include <string>
#include <vector>

namespace ola {

/**
 * @class BaseVariable <ola/ExportMap.h>
 * @brief The base variable class.
 *
 * All other exported variables derive from this.
 */
class BaseVariable {
 public:
  /**
   * @brief Create a new BaseVariable.
   * @param name the variable name.
   */
  explicit BaseVariable(const std::string &name): m_name(name) {}

  /**
   * The Destructor.
   */
  virtual ~BaseVariable() {}

  /**
   * @brief Return the name of this variable.
   * @returns the variable name.
   */
  const std::string Name() const { return m_name; }

  /**
   * @brief Return the value of the variable as a string.
   * @returns the value of the variable.
   */
  virtual const std::string Value() const = 0;

 private:
  std::string m_name;
};

struct VariableLessThan: public std::binary_function<BaseVariable*,
                                                     BaseVariable*, bool> {
  bool operator()(BaseVariable *x, BaseVariable *y) {
    return x->Name() < y->Name();
  }
};


/**
 * @class BoolVariable <ola/ExportMap.h>
 * @brief A boolean variable.
 */
class BoolVariable: public BaseVariable {
 public:
  /**
   * @brief Create a new BoolVariable.
   * @param name the variable name.
   */
  explicit BoolVariable(const std::string &name)
      : BaseVariable(name),
        m_value(false) {}
  ~BoolVariable() {}

  /**
   * @brief Set the value of the variable.
   * @param value the new value.
   */
  void Set(bool value) { m_value = value; }

  /**
   * @brief Get the value of this variable.
   * @return the value of the boolean variable.
   */
  bool Get() const { return m_value; }

  /**
   * @brief Get the value of this variable as a string.
   * @return the value of the boolean variable.
   *
   * Booleans are represented by a 1 or 0.
   */
  const std::string Value() const { return m_value ? "1" : "0"; }

 private:
  bool m_value;
};


/*
 * Represents a string variable
 */
class StringVariable: public BaseVariable {
 public:
  explicit StringVariable(const std::string &name)
      : BaseVariable(name),
        m_value("") {}
  ~StringVariable() {}

  void Set(const std::string &value) { m_value = value; }
  const std::string Get() const { return m_value; }
  const std::string Value() const { return m_value; }

 private:
  std::string m_value;
};


/*
 * Represents a integer variable
 */
class IntegerVariable: public BaseVariable {
 public:
  explicit IntegerVariable(const std::string &name)
      : BaseVariable(name),
        m_value(0) {}
  ~IntegerVariable() {}

  void Set(int value) { m_value = value; }
  void operator++(int) { m_value++; }
  void operator--(int) { m_value--; }
  void Reset() { m_value = 0; }
  int Get() const { return m_value; }
  const std::string Value() const {
    std::ostringstream out;
    out << m_value;
    return out.str();
  }

 private:
  int m_value;
};


/*
 * Represents a counter which can only be added to.
 */
class CounterVariable: public BaseVariable {
 public:
  explicit CounterVariable(const std::string &name)
      : BaseVariable(name),
        m_value(0) {}
  ~CounterVariable() {}

  void operator++(int) { m_value++; }
  void operator+=(unsigned int value) { m_value += value; }
  void Reset() { m_value = 0; }
  unsigned int Get() const { return m_value; }
  const std::string Value() const {
    std::ostringstream out;
    out << m_value;
    return out.str();
  }

 private:
  unsigned int m_value;
};


/*
 * A Map variable holds string -> type mappings
 */
template<typename Type>
class MapVariable: public BaseVariable {
 public:
  MapVariable(const std::string &name, const std::string &label)
      : BaseVariable(name),
        m_label(label) {}
  ~MapVariable() {}

  void Remove(const std::string &key);
  void Set(const std::string &key, Type value);
  Type &operator[](const std::string &key);
  const std::string Value() const;
  const std::string Label() const { return m_label; }

 protected:
  std::map<std::string, Type> m_variables;

 private:
  std::string m_label;
};

typedef MapVariable<std::string> StringMap;


/**
 * An map of integer values. This provides an increment operation.
 */
class IntMap: public MapVariable<int> {
 public:
  IntMap(const std::string &name, const std::string &label)
      : MapVariable<int>(name, label) {}

  void Increment(const std::string &key) {
    m_variables[key]++;
  }
};


/**
 * An IntMap. This provides an increment operation.
 */
class UIntMap: public MapVariable<unsigned int> {
 public:
  UIntMap(const std::string &name, const std::string &label)
      : MapVariable<unsigned int>(name, label) {}

  void Increment(const std::string &key) {
    m_variables[key]++;
  }
};


/*
 * Return a value from the Map Variable, this will create an entry in the map
 * if the variable doesn't exist.
 */
template<typename Type>
Type &MapVariable<Type>::operator[](const std::string &key) {
  return m_variables[key];
}


/*
 * Set a value in the Map variable.
 */
template<typename Type>
void MapVariable<Type>::Set(const std::string &key, Type value) {
  m_variables[key] = value;
}


/**
 * Remove a value from the map
 * @param key the key to remove
 */
template<typename Type>
void MapVariable<Type>::Remove(const std::string &key) {
  typename std::map<std::string, Type>::iterator iter = m_variables.find(key);

  if (iter != m_variables.end())
    m_variables.erase(iter);
}

/*
 * Return the string representation of this map variable.
 * The form is:
 *   var_name  map:label_name key1:value1 key2:value2
 * @return the string representation of the variable.
 */
template<typename Type>
inline const std::string MapVariable<Type>::Value() const {
  std::ostringstream value;
  value << "map:" << m_label;
  typename std::map<std::string, Type>::const_iterator iter;
  for (iter = m_variables.begin(); iter != m_variables.end(); ++iter)
    value << " " << iter->first << ":" << iter->second;
  return value.str();
}


/*
 * Strings need to be quoted
 */
template<>
inline const std::string MapVariable<std::string>::Value() const {
  std::ostringstream value;
  value << "map:" << m_label;
  std::map<std::string, std::string>::const_iterator iter;
  for (iter = m_variables.begin(); iter != m_variables.end(); ++iter) {
    std::string var = iter->second;
    Escape(&var);
    value << " " << iter->first << ":\"" << var << "\"";
  }
  return value.str();
}




/**
 * @brief A container for the exported variables.
 *
 */
class ExportMap {
 public:
  ExportMap() {}
  ~ExportMap();

  /**
   * @brief Lookup or create a BoolVariable.
   * @param name the name of this variable.
   * @return a pointer to the BoolVariable.
   *
   * The variable is created if it doesn't already exist. The pointer is
   * valid for the lifetime of the ExportMap.
   */
  BoolVariable *GetBoolVar(const std::string &name);

  /**
   * @brief Lookup or create an IntegerVariable.
   * @param name the name of this variable.
   * @return an IntegerVariable.
   *
   * The variable is created if it doesn't already exist. The pointer is
   * valid for the lifetime of the ExportMap.
   */
  IntegerVariable *GetIntegerVar(const std::string &name);

  /**
   * @brief Lookup or create a CounterVariable.
   * @param name the name of this variable.
   * @return a CounterVariable.
   *
   * The variable is created if it doesn't already exist. The pointer is
   * valid for the lifetime of the ExportMap.
   */
  CounterVariable *GetCounterVar(const std::string &name);

  /**
   * @brief Lookup or create a StringVariable.
   * @param name the name of this variable.
   * @return a StringVariable.
   *
   * The variable is created if it doesn't already exist. The pointer is
   * valid for the lifetime of the ExportMap.
   */
  StringVariable *GetStringVar(const std::string &name);

  StringMap *GetStringMapVar(const std::string &name,
                             const std::string &label = "");
  IntMap *GetIntMapVar(const std::string &name, const std::string &label = "");
  UIntMap *GetUIntMapVar(const std::string &name,
                         const std::string &label = "");

  /**
   * @brief Fetch a list of all known variables.
   * @returns a vector of all variables.
   */
  std::vector<BaseVariable*> AllVariables() const;

 private :
  template<typename Type>
  Type *GetVar(std::map<std::string, Type*> *var_map,
               const std::string &name);

  template<typename Type>
  Type *GetMapVar(std::map<std::string, Type*> *var_map,
                  const std::string &name,
                  const std::string &label);

  std::map<std::string, BoolVariable*> m_bool_variables;
  std::map<std::string, CounterVariable*> m_counter_variables;
  std::map<std::string, IntegerVariable*> m_int_variables;
  std::map<std::string, StringVariable*> m_string_variables;

  std::map<std::string, StringMap*> m_str_map_variables;
  std::map<std::string, IntMap*> m_int_map_variables;
  std::map<std::string, UIntMap*> m_uint_map_variables;

  DISALLOW_COPY_AND_ASSIGN(ExportMap);
};
}  // namespace ola
#endif  // INCLUDE_OLA_EXPORTMAP_H_