FireBreath  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Pages
URI::URI ( const std::string &  str_uri)

Initializes a FB::URI object by decoding the input URL.

Definition at line 94 of file URI.cpp.

References parse_query_data(), and url_decode().

94  : port(0) {
95  string w = in_str;
96 
97  size_t l = w.find("://");
98  if (l != std::string::npos) {
99  protocol = w.substr(0, l);
100  std::transform(protocol.begin(), protocol.end(), protocol.begin(), ::tolower);
101  w = w.substr(l + 3);
102  }
103  // validate protocol -- should only contain [a-z0-9]
104  for (l = 0; l < protocol.size(); ++l) {
105  if (!isalnum(protocol[l])) throw std::runtime_error("URI: invalid characters in protocol part");
106  }
107 
108  if (protocol != "file") { // file has neither a domain nor a port
109  l = w.find_first_of("/\\");
110  // chomp at the '/' (if it exists) so parsing the login/domain/port is easier
111  string domain_str;
112  if (l == std::string::npos) {
113  domain_str = w;
114  w = "/";
115  } else {
116  domain_str = w.substr(0, l);
117  w = w.substr(l);
118  }
119 
120  // check for login info
121  l = domain_str.find("@");
122  if (l != std::string::npos) {
123  login = domain_str.substr(0, l);
124  domain_str = domain_str.substr(l + 1);
125  }
126 
127  // split port, if it exists
128  size_t p = domain_str.find(":");
129  if (p != std::string::npos && p < l) {
130  domain = domain_str.substr(0, p);
131  string port_str = domain_str.substr(p + 1);
132  port = boost::lexical_cast<int>(port_str);
133  } else {
134  domain = domain_str;
135  }
136  // domains are case insensitive; transform to lower case for convenience.
137  std::transform(domain.begin(), domain.end(), domain.begin(), ::tolower);
138  }
139 
140  l = w.find('#');
141  if (l != std::string::npos) {
142  fragment = w.substr(l + 1);
143  w = w.substr(0, l);
144  }
145  l = w.find('?');
146  if (l != std::string::npos) {
147  parse_query_data(w.substr(l + 1));
148  w = w.substr(0, l);
149  }
150  path = url_decode(w);
151 }
static std::string url_decode(const std::string &in)
Decodes the given urlencoded URL.
Definition: URI.cpp:53
void parse_query_data(const std::string &in_str)
Parses a urlencoded QueryString and stores the results in the URI.
Definition: URI.cpp:219

Here is the call graph for this function: