]> git.sesse.net Git - cubemap/blobdiff - config.cpp
Add a simple HTTP endpoint that returns a very short string.
[cubemap] / config.cpp
index f1b05c1821035819debc55d364c05189a774fed9..9ff0a039d7f641c62404c041df299ed190584bdb 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <net/if.h>
 #include <sys/socket.h>
 #include <map>
 #include <string>
@@ -18,7 +19,7 @@
 
 using namespace std;
 
-#define DEFAULT_BACKLOG_SIZE 1048576
+#define DEFAULT_BACKLOG_SIZE 10485760
 
 struct ConfigLine {
        string keyword;
@@ -187,7 +188,7 @@ bool parse_port(const ConfigLine &line, Config *config)
        }
 
        AcceptorConfig acceptor;
-       acceptor.addr = CreateAnyAddress(port);
+       acceptor.addr = create_any_address(port);
 
        config->acceptors.push_back(acceptor);
        return true;
@@ -234,6 +235,13 @@ bool parse_stream(const ConfigLine &line, Config *config)
                stream.backlog_size = atoi(backlog_it->second.c_str());
        }
 
+       map<string, string>::const_iterator prebuffer_it = line.parameters.find("force_prebuffer");
+       if (prebuffer_it == line.parameters.end()) {
+               stream.prebuffering_bytes = 0;
+       } else {
+               stream.prebuffering_bytes = atoi(prebuffer_it->second.c_str());
+       }
+
        // Parse encoding.
        map<string, string>::const_iterator encoding_parm_it = line.parameters.find("encoding");
        if (encoding_parm_it == line.parameters.end() ||
@@ -290,10 +298,50 @@ bool parse_udpstream(const ConfigLine &line, Config *config)
                udpstream.pacing_rate = atoi(pacing_rate_it->second.c_str()) * 1024 / 8;
        }
 
+       // Parse the TTL. The same value is used for unicast and multicast.
+       map<string, string>::const_iterator ttl_it = line.parameters.find("ttl");
+       if (ttl_it == line.parameters.end()) {
+               udpstream.ttl = -1;
+       } else {
+               udpstream.ttl = atoi(ttl_it->second.c_str());
+       }
+
+       // Parse the multicast interface index.
+       map<string, string>::const_iterator multicast_iface_it = line.parameters.find("multicast_output_interface");
+       if (multicast_iface_it == line.parameters.end()) {
+               udpstream.multicast_iface_index = -1;
+       } else {
+               udpstream.multicast_iface_index = if_nametoindex(multicast_iface_it->second.c_str());
+               if (udpstream.multicast_iface_index == 0) {
+                       log(ERROR, "Interface '%s' does not exist", multicast_iface_it->second.c_str());
+                       return false;
+               }
+       }
+
        config->udpstreams.push_back(udpstream);
        return true;
 }
 
+bool parse_ping(const ConfigLine &line, Config *config)
+{
+       if (line.arguments.size() != 1) {
+               log(ERROR, "'ping' takes exactly one argument");
+               return false;
+       }
+
+       PingConfig ping;
+       ping.url = line.arguments[0];
+
+       // Parse the CORS origin, if it exists.
+       map<string, string>::const_iterator allow_origin_it = line.parameters.find("allow_origin");
+       if (allow_origin_it != line.parameters.end()) {
+               ping.allow_origin = allow_origin_it->second;
+       }
+
+       config->pings.push_back(ping);
+       return true;
+}
+
 bool parse_error_log(const ConfigLine &line, Config *config)
 {
        if (line.arguments.size() != 0) {
@@ -395,6 +443,10 @@ bool parse_config(const string &filename, Config *config)
                        if (!parse_udpstream(line, config)) {
                                return false;
                        }
+               } else if (line.keyword == "ping") {
+                       if (!parse_ping(line, config)) {
+                               return false;
+                       }
                } else if (line.keyword == "error_log") {
                        if (!parse_error_log(line, config)) {
                                return false;