| 1 |
#ifndef PROTON_URL_HPP |
| 2 |
#define PROTON_URL_HPP |
| 3 |
|
| 4 |
/* |
| 5 |
* |
| 6 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 7 |
* or more contributor license agreements. See the NOTICE file |
| 8 |
* distributed with this work for additional information |
| 9 |
* regarding copyright ownership. The ASF licenses this file |
| 10 |
* to you under the Apache License, Version 2.0 (the |
| 11 |
* "License"); you may not use this file except in compliance |
| 12 |
* with the License. You may obtain a copy of the License at |
| 13 |
* |
| 14 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 15 |
* |
| 16 |
* Unless required by applicable law or agreed to in writing, |
| 17 |
* software distributed under the License is distributed on an |
| 18 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 |
* KIND, either express or implied. See the License for the |
| 20 |
* specific language governing permissions and limitations |
| 21 |
* under the License. |
| 22 |
* |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "./error.hpp" |
| 26 |
|
| 27 |
#include <proton/type_compat.h> |
| 28 |
|
| 29 |
#include <iosfwd> |
| 30 |
#include <memory> |
| 31 |
#include <string> |
| 32 |
|
| 33 |
/// @file |
| 34 |
/// **Deprecated** - Use a third-party URL library. |
| 35 |
|
| 36 |
namespace proton { |
| 37 |
|
| 38 |
/// **Deprecated** - Use a third-party URL library. |
| 39 |
/// |
| 40 |
/// An error encountered during URL parsing. |
| 41 |
|
| 42 |
struct |
| 43 |
PN_CPP_DEPRECATED("Use a third-party URL library") |
| 44 |
PN_CPP_CLASS_EXTERN url_error : public error { |
| 45 |
/// @cond INTERNAL |
| 46 |
/// Construct a URL error with a message. |
| 47 |
PN_CPP_EXTERN explicit url_error(const std::string&); |
| 48 |
PN_CPP_EXTERN ~url_error() throw(); |
| 49 |
/// @endcond |
| 50 |
}; |
| 51 |
|
| 52 |
/// **Deprecated** - Use a third-party URL library. |
| 53 |
/// |
| 54 |
/// A URL parser. |
| 55 |
/// |
| 56 |
/// Proton URLs take the form |
| 57 |
/// `<scheme>://<username>:<password>@<host>:<port>/<path>`. |
| 58 |
/// |
| 59 |
/// - Scheme can be `amqp` or `amqps`. Host is a DNS name or IP |
| 60 |
/// address (v4 or v6). |
| 61 |
/// |
| 62 |
/// - Port can be a number or a symbolic service name such as `amqp`. |
| 63 |
/// |
| 64 |
/// - Path is normally used as a link source or target address. On a |
| 65 |
/// broker it typically corresponds to a queue or topic name. |
| 66 |
class PN_CPP_DEPRECATED("Use a third-party URL library") url { |
| 67 |
public: |
| 68 |
static const std::string AMQP; ///< "amqp" prefix |
| 69 |
static const std::string AMQPS; ///< "amqps" prefix |
| 70 |
|
| 71 |
// XXX No constructor for an empty URL? |
| 72 |
// XXX What is the default 'defaults' behavior? |
| 73 |
|
| 74 |
/// Parse `url_str` as an AMQP URL. |
| 75 |
/// |
| 76 |
/// @note Converts automatically from string. |
| 77 |
/// @throw url_error if URL is invalid. |
| 78 |
PN_CPP_EXTERN url(const std::string& url_str); |
| 79 |
|
| 80 |
/// @cond INTERNAL |
| 81 |
/// XXX I want to understand why this is important to keep. |
| 82 |
/// |
| 83 |
/// **Unsettled API** - Parse `url_str` as an AMQP URL. If |
| 84 |
/// `defaults` is true, fill in defaults for missing values. |
| 85 |
/// Otherwise, return an empty string for missing values. |
| 86 |
/// |
| 87 |
/// @note Converts automatically from string. |
| 88 |
/// @throw url_error if URL is invalid. |
| 89 |
PN_CPP_EXTERN url(const std::string& url_str, bool defaults); |
| 90 |
/// @endcond |
| 91 |
|
| 92 |
/// Copy a URL. |
| 93 |
PN_CPP_EXTERN url(const url&); |
| 94 |
|
| 95 |
PN_CPP_EXTERN ~url(); |
| 96 |
|
| 97 |
/// Copy a URL. |
| 98 |
PN_CPP_EXTERN url& operator=(const url&); |
| 99 |
|
| 100 |
/// True if the URL is empty. |
| 101 |
PN_CPP_EXTERN bool empty() const; |
| 102 |
|
| 103 |
/// Returns the URL as a string |
| 104 |
PN_CPP_EXTERN operator std::string() const; |
| 105 |
|
| 106 |
/// @name URL fields |
| 107 |
/// |
| 108 |
/// @{ |
| 109 |
|
| 110 |
/// `amqp` or `amqps`. |
| 111 |
PN_CPP_EXTERN std::string scheme() const; |
| 112 |
/// The user name for authentication. |
| 113 |
PN_CPP_EXTERN std::string user() const; |
| 114 |
// XXX Passwords in URLs are dumb. |
| 115 |
/// The password. |
| 116 |
PN_CPP_EXTERN std::string password() const; |
| 117 |
/// The host name or IP address. |
| 118 |
PN_CPP_EXTERN std::string host() const; |
| 119 |
/// `port` can be a number or a symbolic name such as "amqp". |
| 120 |
PN_CPP_EXTERN std::string port() const; |
| 121 |
/// `port_int` is the numeric value of the port. |
| 122 |
PN_CPP_EXTERN uint16_t port_int() const; |
| 123 |
/// host_port returns just the `host:port` part of the URL |
| 124 |
PN_CPP_EXTERN std::string host_port() const; |
| 125 |
|
| 126 |
// XXX is this not confusing (or incorrect)? The path starts with |
| 127 |
// the first / after //. |
| 128 |
/// `path` is everything after the final "/". |
| 129 |
PN_CPP_EXTERN std::string path() const; |
| 130 |
|
| 131 |
/// @} |
| 132 |
|
| 133 |
/// Return URL as a string. |
| 134 |
friend PN_CPP_EXTERN std::string to_string(const url&); |
| 135 |
|
| 136 |
private: |
| 137 |
struct impl; |
| 138 |
std::unique_ptr<impl> impl_; |
| 139 |
|
| 140 |
/// @cond INTERNAL |
| 141 |
|
| 142 |
friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const url&); |
| 143 |
|
| 144 |
// XXX Why is it important to have this? |
| 145 |
/// Parse `url` from istream. This automatically fills in |
| 146 |
/// defaults for missing values. |
| 147 |
/// |
| 148 |
/// @note An invalid url is indicated by setting |
| 149 |
/// std::stream::fail(), NOT by throwing url_error. |
| 150 |
friend PN_CPP_EXTERN std::istream& operator>>(std::istream&, url&); |
| 151 |
|
| 152 |
/// @endcond |
| 153 |
}; |
| 154 |
|
| 155 |
} // proton |
| 156 |
|
| 157 |
#endif // PROTON_URL_HPP |