3#ifndef STREAMBASE_URI_H
4#define STREAMBASE_URI_H
6#include "StreamBase.hpp"
8#include "Exceptions.hpp"
13SB_INTERNAL_FWD(Errors);
14SB_INTERNAL_FWD(StreamBaseURIUtil);
40 static const unsigned int DEFAULT_PORT = 10000;
70 static const unsigned int DEFAULT_NODE_MANAGER_PORT = 10002;
71 static const char *
const ENVIRONMENT_VARIABLE;
73 static const char *
const URI_ENVIRONMENT_VARIABLE;
75 static const char *
const URI_PROPERTY_NAME;
79 typedef std::map<std::string, std::string> ParamMap;
83 std::string _container;
95 StreamBaseURI(
const std::string &host,
unsigned int port,
const std::string &user =
"",
const std::string &password =
"");
98 StreamBaseURI(
const std::string &host,
const std::string &container,
unsigned int port,
const std::string &user =
"",
const std::string &password =
"");
101 StreamBaseURI(
const std::string &host,
unsigned int port,
const ParamMap ¶mMap)
102 : _host(host), _port(port), _container(NO_CONTAINER)
104 copy(paramMap.begin(), paramMap.end(), inserter(_params, _params.begin()));
109 StreamBaseURI(
const std::string &host,
const std::string &container,
unsigned int port,
const ParamMap ¶mMap)
110 : _host(host), _port(port), _container(container)
112 copy(paramMap.begin(), paramMap.end(), inserter(_params, _params.begin()));
122 static std::string
as_string(
const std::vector<StreamBaseURI> &uris);
135 unsigned int getPort()
const {
return _port; }
138 std::string
getUser()
const {
return getParameter(USER_PARAM); }
141 std::string
getPassword()
const {
return getParameter(PASSWORD_PARAM); }
144 std::string
getParameter(
const std::string &key)
const {
return NMSTL::lookup(_params, key); }
147 std::string
getParam(
const std::string &key)
const {
return NMSTL::lookup(_params, key); }
155 void addParameter(
const std::string &key,
const std::string &value) { _params[key] = value; }
164 operator const void *()
const {
return _host.empty() ? 0 :
this; }
176 void init(NMSTL::Address address,
const std::string &container);
178 void processParams(
const std::string &uri, std::string::size_type paramsPos);
183 int auth(
const std::string& user,
const std::string& password);
185 friend class sb_internal::StreamBaseURIUtil;
190inline std::ostream& operator << (std::ostream& os,
const sb::StreamBaseURI& uri) {
A URI for a StreamBase client connection.
Definition: StreamBaseURI.hpp:36
static const char *const USER_PARAM
URI parameter used for username.
Definition: StreamBaseURI.hpp:46
static std::string const DEFAULT_HOST
The default container name.
Definition: StreamBaseURI.hpp:43
StreamBaseURI(const std::string &uri)
Parse URI from a string.
StreamBaseURI()
Default-constructed object; no operations are allowed.
Definition: StreamBaseURI.hpp:89
StreamBaseURI(const std::string &host, const std::string &container, unsigned int port, const std::string &user="", const std::string &password="")
Create explicitly from host/port with container.
StreamBaseURI(const std::string &host, const std::string &container, unsigned int port, const ParamMap ¶mMap)
Create explicitly from host/port with container, including a map of parameters.
Definition: StreamBaseURI.hpp:109
std::string getUser() const
Return the user name component of the URI.
Definition: StreamBaseURI.hpp:138
static std::string const NO_CONTAINER
No container specification.
Definition: StreamBaseURI.hpp:61
void addParameter(const std::string &key, const std::string &value)
Add a parameter.
Definition: StreamBaseURI.hpp:155
StreamBaseURI(const std::string &host, unsigned int port, const ParamMap ¶mMap)
Create explicitly from host/port, including a map of parameters.
Definition: StreamBaseURI.hpp:101
void removeParameter(std::string key)
Add a parameter.
Definition: StreamBaseURI.hpp:158
static std::vector< StreamBaseURI > vectorFromEnvironment()
Create from the environment variable and return a vector of StreamBaseURIs.
std::string getParameter(const std::string &key) const
Return a parameter, or empty string if undefined.
Definition: StreamBaseURI.hpp:144
static std::string const SYSTEM_CONTAINER
The system container name.
Definition: StreamBaseURI.hpp:58
std::string getParam(const std::string &key) const
Return a parameter, or empty string if undefined.
Definition: StreamBaseURI.hpp:147
size_t getNumParameters()
return the number of parameters
Definition: StreamBaseURI.hpp:161
std::string getPassword() const
Return the password component of the URI.
Definition: StreamBaseURI.hpp:141
static StreamBaseURI const DEFAULT_URI
The default URI.
Definition: StreamBaseURI.hpp:67
std::string getHost() const
Return the host component of the URI.
Definition: StreamBaseURI.hpp:128
const StreamBaseURI getBaseURI() const
return a StreamBaseURI without Parameters
Definition: StreamBaseURI.hpp:173
static std::string const DEFAULT_CONTAINER
The default container name.
Definition: StreamBaseURI.hpp:55
static std::vector< StreamBaseURI > vectorFromString(const std::string &uris)
Return a StreamBaseURI vector from a string of comma sepearted URIs.
bool getParameter(const std::string &key, std::string &value) const
Return a parameter into value (returning true if one was found).
std::string getContainer() const
Returns the container name component of the URI.
Definition: StreamBaseURI.hpp:132
static const char *const PASSWORD_PARAM
URI parameter used for password.
Definition: StreamBaseURI.hpp:52
static const char *const USERNAME_PARAM
URI parameter used for username.
Definition: StreamBaseURI.hpp:49
static StreamBaseURI fromEnvironment()
Create from the environment variable.
static std::string as_string(const std::vector< StreamBaseURI > &uris)
Return a string representation of a list of uris.
unsigned int getPort() const
Return the port component of the URI.
Definition: StreamBaseURI.hpp:135
StreamBaseURI(const std::string &host, unsigned int port, const std::string &user="", const std::string &password="")
Create explicitly from host/port.
static const StreamBaseURI DEFAULT
The default URI (pointing to localhost, port 10000, default container).
Definition: StreamBaseURI.hpp:64
std::string as_string() const
Return the URI as a string.