#include <string.h>
#include <net/if.h>
#include <sys/socket.h>
-#include <map>
#include <string>
#include <utility>
+#include <unordered_map>
#include <vector>
#include "tlse.h"
struct ConfigLine {
string keyword;
vector<string> arguments;
- map<string, string> parameters;
+ unordered_map<string, string> parameters;
};
namespace {
return true;
}
-bool parse_tls_parameters(const map<string, string> ¶meters, AcceptorConfig *acceptor)
+bool parse_tls_parameters(const unordered_map<string, string> ¶meters, AcceptorConfig *acceptor)
{
bool has_cert = false, has_key = false;
return false;
}
- multimap<string, string> parameters = extract_headers(lines, url);
+ unordered_multimap<string, string> parameters = extract_headers(lines, url);
// Remove “Content-encoding: metacube”.
// TODO: Make case-insensitive.
#include <map>
#include <set>
#include <string>
+#include <unordered_map>
#include <utility>
#include <vector>
serialize_start.tv_nsec = loaded_state.serialize_start_usec() * 1000ull;
// Deserialize the streams.
- map<string, string> stream_headers_for_url; // See below.
+ unordered_map<string, string> stream_headers_for_url; // See below.
for (const StreamProto &stream : loaded_state.streams()) {
if (all_urls.count(stream.url()) == 0) {
// Delete the stream backlogs.
return ret;
}
-multimap<string, string> extract_headers(const vector<string> &lines, const string &log_context)
+unordered_multimap<string, string> extract_headers(const vector<string> &lines, const string &log_context)
{
- multimap<string, string> parameters;
+ unordered_multimap<string, string> parameters;
for (size_t i = 1; i < lines.size(); ++i) {
size_t split = lines[i].find(":");
if (split == string::npos) {
// Various routines that deal with parsing; both HTTP requests and more generic text.
#include <stddef.h>
-#include <map>
#include <string>
+#include <unordered_map>
#include <vector>
// Split a line on whitespace, e.g. "foo bar baz" -> {"foo", "bar", "baz"}.
// Extract HTTP headers from a request or response. Ignores the first line,
// where the verb or the return code is.
-std::multimap<std::string, std::string> extract_headers(
+std::unordered_multimap<std::string, std::string> extract_headers(
const std::vector<std::string> &lines, const std::string &log_context);
// Add the new data to an existing string, looking for \r\n\r\n
int Server::lookup_stream_by_url(const string &url) const
{
- map<string, int>::const_iterator stream_url_it = stream_url_map.find(url);
+ const auto stream_url_it = stream_url_map.find(url);
if (stream_url_it == stream_url_map.end()) {
return -1;
}
// Parse the headers, for logging purposes.
// TODO: Case-insensitivity.
- multimap<string, string> headers = extract_headers(lines, client->remote_addr);
- multimap<string, string>::const_iterator referer_it = headers.find("Referer");
+ unordered_multimap<string, string> headers = extract_headers(lines, client->remote_addr);
+ const auto referer_it = headers.find("Referer");
if (referer_it != headers.end()) {
client->referer = referer_it->second;
}
- multimap<string, string>::const_iterator user_agent_it = headers.find("User-Agent");
+ const auto user_agent_it = headers.find("User-Agent");
if (user_agent_it != headers.end()) {
client->user_agent = user_agent_it->second;
}
client->close_after_response = true;
client->http_11 = false;
} else {
- multimap<string, string>::const_iterator connection_it = headers.find("Connection");
+ const auto connection_it = headers.find("Connection");
if (connection_it != headers.end() && connection_it->second == "close") {
client->close_after_response = true;
}
}
- map<string, int>::const_iterator stream_url_map_it = stream_url_map.find(url);
+ const auto stream_url_map_it = stream_url_map.find(url);
if (stream_url_map_it != stream_url_map.end()) {
// Serve a regular stream..
client->stream = streams[stream_url_map_it->second].get();
client->serving_hls_playlist = false;
} else {
- map<string, int>::const_iterator stream_hls_url_map_it = stream_hls_url_map.find(url);
+ const auto stream_hls_url_map_it = stream_hls_url_map.find(url);
if (stream_hls_url_map_it != stream_hls_url_map.end()) {
// Serve HLS playlist.
client->stream = streams[stream_hls_url_map_it->second].get();
client->serving_hls_playlist = true;
} else {
- map<string, string>::const_iterator ping_url_map_it = ping_url_map.find(url);
+ const auto ping_url_map_it = ping_url_map.find(url);
if (ping_url_map_it == ping_url_map.end()) {
return 404; // Not found.
} else {
void Server::construct_204(Client *client)
{
- map<string, string>::const_iterator ping_url_map_it = ping_url_map.find(client->url);
+ const auto ping_url_map_it = ping_url_map.find(client->url);
assert(ping_url_map_it != ping_url_map.end());
string response;
#include <sys/epoll.h>
#include <sys/types.h>
#include <time.h>
-#include <map>
#include <memory>
#include <mutex>
#include <queue>
#include <string>
+#include <unordered_map>
#include <vector>
#include "tlse.h"
std::vector<std::unique_ptr<Stream>> streams;
// Map from URL to index into <streams>.
- std::map<std::string, int> stream_url_map, stream_hls_url_map;
+ std::unordered_map<std::string, int> stream_url_map, stream_hls_url_map;
// Map from URL to CORS Allow-Origin header (or empty string).
- std::map<std::string, std::string> ping_url_map;
+ std::unordered_map<std::string, std::string> ping_url_map;
// Map from file descriptor to client.
- std::map<int, Client> clients;
+ std::unordered_map<int, Client> clients;
// A list of all clients, ordered by the time they connected (first element),
// and their file descriptor (second element). It is ordered by connection time
epoll_event events[EPOLL_MAX_EVENTS];
// For each TLS-enabled acceptor, our private server context for its key pair.
- std::map<const Acceptor *, TLSContext *> tls_server_contexts;
+ std::unordered_map<const Acceptor *, TLSContext *> tls_server_contexts;
// The actual worker thread.
virtual void do_work();