Qpid Proton C++  0.17.0
url.hpp
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 "./internal/pn_unique_ptr.hpp"
26 #include "./error.hpp"
27 
28 #include <proton/type_compat.h>
29 
30 #include <iosfwd>
31 #include <string>
32 
33 namespace proton {
34 
36 struct
37 PN_CPP_CLASS_EXTERN url_error : public error {
40  PN_CPP_EXTERN explicit url_error(const std::string&);
42 };
43 
56 class url {
57  public:
58  static const std::string AMQP;
59  static const std::string AMQPS;
60 
61  // XXX No constructor for an empty URL?
62  // XXX What is the default 'defaults' behavior?
63 
68  PN_CPP_EXTERN url(const std::string& url_str);
69 
79  PN_CPP_EXTERN url(const std::string& url_str, bool defaults);
81 
83  PN_CPP_EXTERN url(const url&);
84 
85  PN_CPP_EXTERN ~url();
86 
88  PN_CPP_EXTERN url& operator=(const url&);
89 
91  PN_CPP_EXTERN bool empty() const;
92 
94  PN_CPP_EXTERN operator std::string() const;
95 
99 
101  PN_CPP_EXTERN std::string scheme() const;
103  PN_CPP_EXTERN std::string user() const;
104  // XXX Passwords in URLs are dumb.
106  PN_CPP_EXTERN std::string password() const;
108  PN_CPP_EXTERN std::string host() const;
110  PN_CPP_EXTERN std::string port() const;
112  PN_CPP_EXTERN uint16_t port_int() const;
114  PN_CPP_EXTERN std::string host_port() const;
115 
116  // XXX is this not confusing (or incorrect)? The path starts with
117  // the first / after //.
119  PN_CPP_EXTERN std::string path() const;
120 
122 
124  friend PN_CPP_EXTERN std::string to_string(const url&);
125 
126  private:
127  struct impl;
128  internal::pn_unique_ptr<impl> impl_;
129 
131 
132  friend PN_CPP_EXTERN std::ostream& operator<<(std::ostream&, const url&);
133 
134  // XXX Why is it important to have this?
140  friend PN_CPP_EXTERN std::istream& operator>>(std::istream&, url&);
141 
143 };
144 
145 } // proton
146 
147 #endif // PROTON_URL_HPP
std::string path() const
path is everything after the final "/".
std::ostream & operator<<(std::ostream &, const binary &)
Print a binary value.
static const std::string AMQP
"amqp" prefix
Definition: url.hpp:58
std::string host_port() const
host_port returns just the host:port part of the URL
std::string port() const
port can be a number or a symbolic name such as "amqp".
url & operator=(const url &)
Copy a URL.
An error encountered during URL parsing.
Definition: url.hpp:36
std::string scheme() const
amqp or amqps.
url(const std::string &url_str)
Parse url_str as an AMQP URL.
bool empty() const
True if the URL is empty.
std::string password() const
The password.
A URL parser.
Definition: url.hpp:56
std::string user() const
The user name for authentication.
friend std::string to_string(const url &)
Return URL as a string.
std::string host() const
The host name or IP address.
The base Proton error.
Definition: error.hpp:37
uint16_t port_int() const
port_int is the numeric value of the port.
The main Proton namespace.
Definition: annotation_key.hpp:30
static const std::string AMQPS
"amqps" prefix
Definition: url.hpp:59