]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_url.cc
import 15.2.4
[ceph.git] / 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
3
4 #include <string>
5 #include <regex>
6
7 namespace rgw {
8
9 namespace {
10 const auto USER_GROUP_IDX = 3;
11 const auto PASSWORD_GROUP_IDX = 4;
12 const auto HOST_GROUP_IDX = 5;
13
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:]]+)?";
18 }
19
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;
24
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];
29 return true;
30 }
31
32 return false;
33 }
34
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;
39
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];
43 return true;
44 }
45
46 return false;
47 }
48 }
49