diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/qpid/Url.h | 2 | ||||
-rw-r--r-- | cpp/src/qpid/Url.cpp | 38 |
2 files changed, 31 insertions, 9 deletions
diff --git a/cpp/include/qpid/Url.h b/cpp/include/qpid/Url.h index 80931618ed..353e9d5599 100644 --- a/cpp/include/qpid/Url.h +++ b/cpp/include/qpid/Url.h @@ -82,8 +82,6 @@ struct Url : public std::vector<Address> { QPID_COMMON_EXTERN std::string getPass() const; private: - static std::vector<std::string> protocols; - mutable std::string cache; // cache string form for efficiency. std::string user, pass; diff --git a/cpp/src/qpid/Url.cpp b/cpp/src/qpid/Url.cpp index 0b9fdbf6eb..ab796f4642 100644 --- a/cpp/src/qpid/Url.cpp +++ b/cpp/src/qpid/Url.cpp @@ -22,10 +22,12 @@ #include "qpid/sys/SystemInfo.h" #include "qpid/sys/StrError.h" #include "qpid/client/Connector.h" - +#include "qpid/sys/Mutex.h" #include <boost/lexical_cast.hpp> #include <algorithm> +#include <vector> +#include <string> #include <string.h> @@ -34,6 +36,32 @@ using boost::lexical_cast; namespace qpid { +class ProtocolTags { + public: + bool find(const string& tag) { + sys::Mutex::ScopedLock l(lock); + return std::find(tags.begin(), tags.end(), tag) != tags.end(); + } + + void add(const string& tag) { + sys::Mutex::ScopedLock l(lock); + if (std::find(tags.begin(), tags.end(), tag) == tags.end()) + tags.push_back(tag); + } + + static ProtocolTags& instance() { + /** First call must be made while program is still single threaded. + * This will be the case since tags are registered in static initializers. + */ + static ProtocolTags tags; + return tags; + } + + private: + sys::Mutex lock; + vector<string> tags; +}; + Url::Invalid::Invalid(const string& s) : Exception(s) {} Url Url::getHostNameUrl(uint16_t port) { @@ -119,9 +147,7 @@ class UrlParser { const char* j = std::find(i,end,':'); if (j != end) { string tag(i,j); - if (std::find(Url::protocols.begin(), Url::protocols.end(), tag) != - Url::protocols.end()) - { + if (ProtocolTags::instance().find(tag)) { i = j+1; result = tag; return true; @@ -234,8 +260,6 @@ std::istream& operator>>(std::istream& is, Url& url) { return is; } -std::vector<std::string> Url::protocols; - -void Url::addProtocol(const std::string& tag) { protocols.push_back(tag); } +void Url::addProtocol(const std::string& tag) { ProtocolTags::instance().add(tag); } } // namespace qpid |