11 // Extremely rudimentary URL parsing.
12 bool parse_url(const string &url, string *protocol, string *host, string *port, string *path)
14 size_t split = url.find("://");
15 if (split == string::npos) {
18 *protocol = string(url.begin(), url.begin() + split);
20 string rest = string(url.begin() + split + 3, url.end());
21 split = rest.find_first_of(":/");
22 if (split == string::npos) {
30 *host = string(rest.begin(), rest.begin() + split);
31 char ch = rest[split]; // Colon or slash.
32 rest = string(rest.begin() + split + 1, rest.end());
36 split = rest.find_first_of('/');
37 if (split == string::npos) {
43 // http://foo:1234/bar
44 *port = string(rest.begin(), rest.begin() + split);
45 *path = string(rest.begin() + split, rest.end());
56 Input *create_input(const std::string &stream_id, const std::string &url)
58 string protocol, host, port, path;
59 if (!parse_url(url, &protocol, &host, &port, &path)) {
62 if (protocol == "http") {
63 return new HTTPInput(stream_id, url);
65 if (protocol == "udp") {
66 return new UDPInput(stream_id, url);
71 Input *create_input(const InputProto &serialized)
73 string protocol, host, port, path;
74 if (!parse_url(serialized.url(), &protocol, &host, &port, &path)) {
77 if (protocol == "http") {
78 return new HTTPInput(serialized);
80 if (protocol == "udp") {
81 return new UDPInput(serialized);