]> git.sesse.net Git - cubemap/blobdiff - input.cpp
Support UDP packets larger than 4 kB.
[cubemap] / input.cpp
index 1e617807d0058c88b92d6b5f8b13da97c0c837c2..ec1238181d076273c5d6019fce16e768ed1d6689 100644 (file)
--- a/input.cpp
+++ b/input.cpp
@@ -1,25 +1,28 @@
-#include <string.h>
+#include <stddef.h>
 #include <string>
 
+#include "httpinput.h"
 #include "input.h"
+#include "state.pb.h"
+#include "udpinput.h"
 
 using namespace std;
 
 // Extremely rudimentary URL parsing.
 bool parse_url(const string &url, string *protocol, string *host, string *port, string *path)
 {
-       if (url.find("http://") != 0) {
+       size_t split = url.find("://");
+       if (split == string::npos) {
                return false;
        }
+       *protocol = string(url.begin(), url.begin() + split);
 
-       *protocol = "http";
-       
-       string rest = url.substr(strlen("http://"));
-       size_t split = rest.find_first_of(":/");
+       string rest = string(url.begin() + split + 3, url.end());
+       split = rest.find_first_of(":/");
        if (split == string::npos) {
                // http://foo
                *host = rest;
-               *port = "http";
+               *port = *protocol;
                *path = "/";
                return true;
        }
@@ -45,10 +48,40 @@ bool parse_url(const string &url, string *protocol, string *host, string *port,
        }
 
        // http://foo/bar
-       *port = "http";
+       *port = *protocol;
        *path = rest;
        return true;
 }
 
+Input *create_input(const std::string &url)
+{
+       string protocol, host, port, path;
+       if (!parse_url(url, &protocol, &host, &port, &path)) {
+               return NULL;
+       }
+       if (protocol == "http") {
+               return new HTTPInput(url);
+       }
+       if (protocol == "udp") {
+               return new UDPInput(url);
+       }
+       return NULL;
+}
+
+Input *create_input(const InputProto &serialized)
+{
+       string protocol, host, port, path;
+       if (!parse_url(serialized.url(), &protocol, &host, &port, &path)) {
+               return NULL;
+       }
+       if (protocol == "http") {
+               return new HTTPInput(serialized);
+       }
+       if (protocol == "udp") {
+               return new UDPInput(serialized);
+       }
+       return NULL;
+}
+
 Input::~Input() {}