13 // Does not support passwords, only user:host, since this is really only used
14 // to parse VLC's udp://source@multicastgroup:1234/ syntax (we do not support
16 void split_user_host(const string &user_host, string *user, string *host)
18 size_t split = user_host.find("@");
19 if (split == string::npos) {
23 *user = string(user_host.begin(), user_host.begin() + split);
24 *host = string(user_host.begin() + split + 1, user_host.end());
30 // Extremely rudimentary URL parsing.
31 bool parse_url(const string &url, string *protocol, string *user, string *host, string *port, string *path)
33 size_t split = url.find("://");
34 if (split == string::npos) {
37 *protocol = string(url.begin(), url.begin() + split);
39 string rest = string(url.begin() + split + 3, url.end());
40 split = rest.find_first_of(":/");
41 if (split == string::npos) {
43 split_user_host(rest, user, host);
49 split_user_host(string(rest.begin(), rest.begin() + split), user, host);
50 char ch = rest[split]; // Colon or slash.
51 rest = string(rest.begin() + split + 1, rest.end());
55 split = rest.find_first_of('/');
56 if (split == string::npos) {
62 // http://foo:1234/bar
63 *port = string(rest.begin(), rest.begin() + split);
64 *path = string(rest.begin() + split, rest.end());
75 Input *create_input(const std::string &url)
77 string protocol, user, host, port, path;
78 if (!parse_url(url, &protocol, &user, &host, &port, &path)) {
81 if (protocol == "http") {
82 return new HTTPInput(url);
84 if (protocol == "udp") {
85 return new UDPInput(url);
90 Input *create_input(const InputProto &serialized)
92 string protocol, user, host, port, path;
93 if (!parse_url(serialized.url(), &protocol, &user, &host, &port, &path)) {
96 if (protocol == "http") {
97 return new HTTPInput(serialized);
99 if (protocol == "udp") {
100 return new UDPInput(serialized);