/usr/include/ola/slp/URLEntry.h is in libola-dev 0.9.1-1.1.
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 | /*
* 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 2 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 Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* URLEntry.h
* The object which holds a url and lifetime.
* Copyright (C) 2012 Simon Newton
*/
#ifndef INCLUDE_OLA_SLP_URLENTRY_H_
#define INCLUDE_OLA_SLP_URLENTRY_H_
#include <ola/io/BigEndianStream.h>
#include <ostream>
#include <string>
#include <vector>
namespace ola {
namespace slp {
/**
* Represents a URL with the an associated lifetime. The URL cannot be changed
* once the object is created. This object is cheap to copy so it can be used
* in STL containers. It doesn't have an ordering defined though.
*/
class URLEntry {
public:
URLEntry() {}
/**
* Create a new URLEntry
* @param url the url string
* @param lifetime the lifetime in seconds.
*/
URLEntry(const std::string &url, uint16_t lifetime)
: m_url(url),
m_lifetime(lifetime) {
}
~URLEntry() {}
std::string url() const { return m_url; }
uint16_t lifetime() const { return m_lifetime; }
void set_lifetime(uint16_t lifetime) { m_lifetime = lifetime; }
/*
* Age this URL by the given number of seconds
* @returns true if this url has now expired, false otherwise.
*/
bool AgeLifetime(uint16_t seconds) {
if (m_lifetime <= seconds) {
m_lifetime = 0;
return true;
}
m_lifetime-= seconds;
return false;
}
// Return the total size of this URL entry as it appears on the wire
unsigned int PackedSize() const { return 6 + m_url.size(); }
// Write this ServiceEntry to an IOQueue
void Write(ola::io::BigEndianOutputStreamInterface *output) const;
// equality is based on the url only
bool operator==(const URLEntry &other) const {
return m_url == other.m_url;
}
bool operator!=(const URLEntry &other) const {
return m_url != other.m_url;
}
URLEntry& operator=(const URLEntry &other) {
if (this != &other) {
m_url = other.m_url;
m_lifetime = other.m_lifetime;
}
return *this;
}
void ToStream(std::ostream *out) const {
*out << m_url << "(" << m_lifetime << ")";
}
std::string ToString() const {
std::ostringstream str;
ToStream(&str);
return str.str();
}
friend std::ostream& operator<<(std::ostream &out, const URLEntry &entry) {
entry.ToStream(&out);
return out;
}
protected:
std::string m_url;
uint16_t m_lifetime;
// TODO(simon): add auth blocks here
};
// typedef for convenience
typedef std::vector<URLEntry> URLEntries;
} // namespace slp
} // namespace ola
#endif // INCLUDE_OLA_SLP_URLENTRY_H_
|