80
void UriStruct::swap(UriStruct& other)
84
swap(protocol, other.protocol);
85
swap(host, other.host);
86
swap(port, other.port);
88
swap(file, other.file);
89
swap(query, other.query);
90
swap(username, other.username);
91
swap(password, other.password);
92
swap(hasPassword, other.hasPassword);
93
swap(ipv6LiteralAddress, other.ipv6LiteralAddress);
97
void swap(UriStruct& lhs, UriStruct& rhs)
80
102
bool parse(UriStruct& result, const std::string& uri)
82
104
// http://user:password@aria2.sourceforge.net:80/dir/file?query#fragment
263
std::string construct(const UriStruct& us)
268
if(!us.username.empty()) {
269
res += util::percentEncode(us.username);
272
res += util::percentEncode(us.password);
276
if(us.ipv6LiteralAddress) {
283
uint16_t defPort= FeatureConfig::getInstance()->
284
getDefaultPort(us.protocol);
285
if(us.port != 0 && defPort != us.port) {
287
res += util::uitos(us.port);
290
if(us.dir.empty() || us.dir[us.dir.size()-1] != '/') {
298
std::string joinUri(const std::string& baseUri, const std::string& uri)
305
if(!parse(bus, baseUri)) {
308
std::vector<std::string> parts;
309
if(!util::startsWith(uri, "/")) {
310
util::split(bus.dir, std::back_inserter(parts), "/");
312
std::string::const_iterator qend;
313
for(qend = uri.begin(); qend != uri.end(); ++qend) {
318
std::string::const_iterator end;
319
for(end = uri.begin(); end != qend; ++end) {
324
std::string path(uri.begin(), end);
325
util::split(path, std::back_inserter(parts), "/");
329
std::string res = construct(bus);
330
res += util::joinPath(parts.begin(), parts.end());
331
if((path.empty() || util::endsWith(path, "/")) &&
332
!util::endsWith(res, "/")) {
335
res += std::string(end, qend);
241
340
} // namespace uri
243
342
} // namespace aria2