]>
git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_url.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
10 const auto USER_GROUP_IDX
= 3;
11 const auto PASSWORD_GROUP_IDX
= 4;
12 const auto HOST_GROUP_IDX
= 5;
14 const std::string schema_re
= "([[:alpha:]]+:\\/\\/)";
15 const std::string user_pass_re
= "(([^:\\s]+):([^@\\s]+)@)?";
16 const std::string host_port_re
= "([[:alnum:].:-]+)";
17 const std::string path_re
= "(/[[:print:]]*)?";
20 bool parse_url_authority(const std::string
& url
, std::string
& host
, std::string
& user
, std::string
& password
) {
21 const std::string re
= schema_re
+ user_pass_re
+ host_port_re
+ path_re
;
22 const std::regex
url_regex(re
, std::regex::icase
);
23 std::smatch url_match_result
;
25 if (std::regex_match(url
, url_match_result
, url_regex
)) {
26 host
= url_match_result
[HOST_GROUP_IDX
];
27 user
= url_match_result
[USER_GROUP_IDX
];
28 password
= url_match_result
[PASSWORD_GROUP_IDX
];
35 bool parse_url_userinfo(const std::string
& url
, std::string
& user
, std::string
& password
) {
36 const std::string re
= schema_re
+ user_pass_re
+ host_port_re
+ path_re
;
37 const std::regex
url_regex(re
);
38 std::smatch url_match_result
;
40 if (std::regex_match(url
, url_match_result
, url_regex
)) {
41 user
= url_match_result
[USER_GROUP_IDX
];
42 password
= url_match_result
[PASSWORD_GROUP_IDX
];