| 153 | namespace proton { |
| 154 | |
| 155 | struct url::impl { |
| 156 | static const char* const default_host; |
| 157 | const char* scheme; |
| 158 | const char* username; |
| 159 | const char* password; |
| 160 | const char* host; |
| 161 | const char* port; |
| 162 | const char* path; |
| 163 | std::vector<char> cstr; |
| 164 | mutable std::string str; |
| 165 | |
| 166 | impl(const std::string& s) : |
| 167 | scheme(0), username(0), password(0), host(0), port(0), path(0), |
| 168 | cstr(s.size()+1, '\0') |
| 169 | { |
| 170 | std::copy(s.begin(), s.end(), cstr.begin()); |
| 171 | parse_url(&cstr[0], &scheme, &username, &password, &host, &port, &path); |
| 172 | } |
| 173 | |
| 174 | void defaults() { |
| 175 | if (!scheme || *scheme=='\0' ) scheme = proton::url::AMQP.c_str(); |
| 176 | if (!host || *host=='\0' ) host = default_host; |
| 177 | if (!port || *port=='\0' ) port = scheme; |
| 178 | } |
| 179 | |
| 180 | operator std::string() const { |
| 181 | if ( str.empty() ) { |
| 182 | if (scheme) { |
| 183 | str += scheme; |
| 184 | str += "://"; |
| 185 | } |
| 186 | if (username) { |
| 187 | str += pni_urlencode(username); |
| 188 | } |
| 189 | if (password) { |
| 190 | str += ":"; |
| 191 | str += pni_urlencode(password); |
| 192 | } |
| 193 | if (username || password) { |
| 194 | str += "@"; |
| 195 | } |
| 196 | if (host) { |
| 197 | if (std::strchr(host, ':')) { |
| 198 | str += '['; |
| 199 | str += host; |
| 200 | str += ']'; |
| 201 | } else { |
| 202 | str += host; |
| 203 | } |
| 204 | } |
| 205 | if (port) { |
| 206 | str += ':'; |
| 207 | str += port; |
| 208 | } |
| 209 | if (path) { |
| 210 | str += '/'; |
| 211 | str += path; |
| 212 | } |
nothing calls this directly
no test coverage detected