| 266 | // ---------------------------------------------------------------------------------------- |
| 267 | |
| 268 | bool http_client::parse_url( |
| 269 | const std::string& url, |
| 270 | std::string& scheme, |
| 271 | std::string& user, |
| 272 | std::string& pass, |
| 273 | std::string& host, |
| 274 | short& port, |
| 275 | std::string& path |
| 276 | ) const |
| 277 | { |
| 278 | scheme.clear(); |
| 279 | user.clear(); |
| 280 | pass.clear(); |
| 281 | host.clear(); |
| 282 | path.clear(); |
| 283 | port = 0; |
| 284 | |
| 285 | // Find scheme |
| 286 | std::string::size_type pos_scheme = url.find("://"); |
| 287 | if ( pos_scheme == std::string::npos ) |
| 288 | { |
| 289 | pos_scheme = 0; |
| 290 | } |
| 291 | else |
| 292 | { |
| 293 | scheme = strtolower(url.substr(0, pos_scheme)); |
| 294 | pos_scheme += 3; |
| 295 | } |
| 296 | |
| 297 | std::string::size_type pos_path = url.find('/', pos_scheme); |
| 298 | if ( pos_path == std::string::npos ) |
| 299 | { |
| 300 | host = url.substr(pos_scheme); |
| 301 | } |
| 302 | else |
| 303 | { |
| 304 | host = url.substr(pos_scheme, pos_path - pos_scheme); |
| 305 | path = url.substr(pos_path); |
| 306 | } |
| 307 | |
| 308 | std::string::size_type pos_at = host.find('@'); |
| 309 | if ( pos_at != std::string::npos ) |
| 310 | { |
| 311 | std::string::size_type pos_dp = host.find(':'); |
| 312 | if ( pos_dp != std::string::npos && pos_dp < pos_at ) |
| 313 | { |
| 314 | user = host.substr(0, pos_dp); |
| 315 | pass = host.substr(pos_dp+1, pos_at-pos_dp-1); |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | user = host.substr(0, pos_at); |
| 320 | } |
| 321 | host = host.substr(pos_at+1); |
| 322 | } |
| 323 | |
| 324 | std::string::size_type pos_dp = host.find(':'); |
| 325 | if ( pos_dp != std::string::npos ) |