X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=input.cpp;h=ec1238181d076273c5d6019fce16e768ed1d6689;hp=1e617807d0058c88b92d6b5f8b13da97c0c837c2;hb=845934ca50eee40884e8cc85ea81eb310efa5ca3;hpb=239a9eab1a2468b401183745a24b2fbd590a6998 diff --git a/input.cpp b/input.cpp index 1e61780..ec12381 100644 --- a/input.cpp +++ b/input.cpp @@ -1,25 +1,28 @@ -#include +#include #include +#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() {}