12 // Extremely rudimentary URL parsing.
13 bool parse_url(const string &url, string *protocol, string *host, string *port, string *path)
15 size_t split = url.find("://");
16 if (split == string::npos) {
19 *protocol = string(url.begin(), url.begin() + split);
21 string rest = string(url.begin() + split + 3, url.end());
22 split = rest.find_first_of(":/");
23 if (split == string::npos) {
31 *host = string(rest.begin(), rest.begin() + split);
32 char ch = rest[split]; // Colon or slash.
33 rest = string(rest.begin() + split + 1, rest.end());
37 split = rest.find_first_of('/');
38 if (split == string::npos) {
44 // http://foo:1234/bar
45 *port = string(rest.begin(), rest.begin() + split);
46 *path = string(rest.begin() + split, rest.end());
57 Input *create_input(const std::string &stream_id, const std::string &url)
59 string protocol, host, port, path;
60 if (!parse_url(url, &protocol, &host, &port, &path)) {
63 if (protocol == "http") {
64 return new HTTPInput(stream_id, url);
66 if (protocol == "udp") {
67 return new UDPInput(stream_id, url);
72 Input *create_input(const InputProto &serialized)
74 string protocol, host, port, path;
75 if (!parse_url(serialized.url(), &protocol, &host, &port, &path)) {
78 if (protocol == "http") {
79 return new HTTPInput(serialized);
81 if (protocol == "udp") {
82 return new UDPInput(serialized);