]> git.sesse.net Git - cubemap/blobdiff - server.cpp
Try to fix some overflow issues on 32-bit platforms, where size_t is 32-bit. Untested.
[cubemap] / server.cpp
index a7f579c170928eabae1ca0d025c5ec1204741dd5..ceb7f3d80b7c96db81fe4dda0d3bf0d16d15ce48 100644 (file)
@@ -1,5 +1,6 @@
 #include <assert.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <pthread.h>
@@ -301,7 +302,7 @@ void Server::add_client_from_serialized(const ClientProto &client, const vector<
 
 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;
        }
@@ -910,12 +911,12 @@ int Server::parse_request(Client *client)
 
        // 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;
        }
@@ -985,25 +986,25 @@ int Server::parse_request(Client *client)
                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 {
@@ -1069,7 +1070,7 @@ void Server::construct_stream_header(Client *client)
                response.append(buf);
        } else if (client->stream_pos_end != Client::STREAM_POS_NO_END) {
                char buf[64];
-               snprintf(buf, sizeof(buf), "Content-length: %zu\r\n", client->stream_pos_end - client->stream_pos);
+               snprintf(buf, sizeof(buf), "Content-length: %" PRIu64 "\r\n", client->stream_pos_end - client->stream_pos);
                response.append(buf);
        }
        if (client->http_11) {
@@ -1166,7 +1167,7 @@ void Server::construct_hls_playlist(Client *client)
 
 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;