]> git.sesse.net Git - cubemap/blobdiff - input.cpp
Support input from pipes (subprocesses).
[cubemap] / input.cpp
index 7f95b2693a96ea0e56f858eb484c68e8f7a84031..81bc2dc4ea4d396ce6d9d7855b211919aff878e4 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -30,6 +30,13 @@ void split_user_host(const string &user_host, string *user, string *host)
 // Extremely rudimentary URL parsing.
 bool parse_url(const string &url, string *protocol, string *user, string *host, string *port, string *path)
 {
+       // pipe:foo (or pipe:"foo").
+       if (url.find("pipe:") == 0) {
+               *protocol = "pipe";
+               *path = string(url.begin() + 5, url.end());
+               return true;
+       }
+
        size_t split = url.find("://");
        if (split == string::npos) {
                return false;
@@ -98,31 +105,31 @@ Input *create_input(const string &url, Input::Encoding encoding)
 {
        string protocol, user, host, port, path;
        if (!parse_url(url, &protocol, &user, &host, &port, &path)) {
-               return NULL;
+               return nullptr;
        }
-       if (protocol == "http") {
+       if (protocol == "http" || protocol == "pipe") {
                return new HTTPInput(url, encoding);
        }
        if (protocol == "udp") {
-               // encoding is ignored; it's never Metacube.
+               assert(encoding == Input::INPUT_ENCODING_RAW);
                return new UDPInput(url);
        }
-       return NULL;
+       return nullptr;
 }
 
 Input *create_input(const InputProto &serialized)
 {
        string protocol, user, host, port, path;
        if (!parse_url(serialized.url(), &protocol, &user, &host, &port, &path)) {
-               return NULL;
+               return nullptr;
        }
-       if (protocol == "http") {
+       if (protocol == "http" || protocol == "pipe") {
                return new HTTPInput(serialized);
        }
        if (protocol == "udp") {
                return new UDPInput(serialized);
        }
-       return NULL;
+       return nullptr;
 }
 
 Input::~Input() {}