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());
41 // Split at the first slash, or the first colon that's not within [].
42 bool within_brackets = false;
43 for (split = 0; split < rest.size(); ++split) {
44 if (rest[split] == '[') {
45 if (within_brackets) {
46 // Can't nest brackets.
49 within_brackets = true;
50 } else if (rest[split] == ']') {
51 if (!within_brackets) {
52 // ] without matching [.
55 within_brackets = false;
56 } else if (rest[split] == '/') {
58 } else if (rest[split] == ':' && !within_brackets) {
63 if (split == rest.size()) {
65 split_user_host(rest, user, host);
66 fprintf(stderr, "ooo user='%s' host='%s'\n", user->c_str(), host->c_str());
72 split_user_host(string(rest.begin(), rest.begin() + split), user, host);
73 char ch = rest[split]; // Colon or slash.
74 rest = string(rest.begin() + split + 1, rest.end());
78 split = rest.find_first_of('/');
79 if (split == string::npos) {
85 // http://foo:1234/bar
86 *port = string(rest.begin(), rest.begin() + split);
87 *path = string(rest.begin() + split, rest.end());
98 Input *create_input(const std::string &url)
100 string protocol, user, host, port, path;
101 if (!parse_url(url, &protocol, &user, &host, &port, &path)) {
104 if (protocol == "http") {
105 return new HTTPInput(url);
107 if (protocol == "udp") {
108 return new UDPInput(url);
113 Input *create_input(const InputProto &serialized)
115 string protocol, user, host, port, path;
116 if (!parse_url(serialized.url(), &protocol, &user, &host, &port, &path)) {
119 if (protocol == "http") {
120 return new HTTPInput(serialized);
122 if (protocol == "udp") {
123 return new UDPInput(serialized);