You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gs...@apache.org on 2010/01/28 09:37:38 UTC
svn commit: r904000 - in /qpid/trunk/qpid/cpp: examples/messaging/
include/qpid/messaging/ src/ src/qpid/client/amqp0_10/ src/qpid/messaging/
src/tests/
Author: gsim
Date: Thu Jan 28 08:37:37 2010
New Revision: 904000
URL: http://svn.apache.org/viewvc?rev=904000&view=rev
Log:
QPID-664: change format of connection options string to match address options; make open() a non-static method.
Added:
qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.h
Modified:
qpid/trunk/qpid/cpp/examples/messaging/client.cpp
qpid/trunk/qpid/cpp/examples/messaging/drain.cpp
qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp
qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp
qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp
qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp
qpid/trunk/qpid/cpp/examples/messaging/server.cpp
qpid/trunk/qpid/cpp/examples/messaging/spout.cpp
qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp
qpid/trunk/qpid/cpp/examples/messaging/topic_sender.cpp
qpid/trunk/qpid/cpp/include/qpid/messaging/Connection.h
qpid/trunk/qpid/cpp/src/CMakeLists.txt
qpid/trunk/qpid/cpp/src/Makefile.am
qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h
qpid/trunk/qpid/cpp/src/qpid/messaging/Address.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/Connection.cpp
qpid/trunk/qpid/cpp/src/qpid/messaging/ConnectionImpl.h
qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp
qpid/trunk/qpid/cpp/src/tests/qpid_recv.cpp
qpid/trunk/qpid/cpp/src/tests/qpid_send.cpp
qpid/trunk/qpid/cpp/src/tests/qpid_stream.cpp
Modified: qpid/trunk/qpid/cpp/examples/messaging/client.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/client.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/client.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/client.cpp Thu Jan 28 08:37:37 2010
@@ -40,7 +40,8 @@
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
try {
- Connection connection = Connection::open(url);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Sender sender = session.createSender("service_queue");
Modified: qpid/trunk/qpid/cpp/examples/messaging/drain.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/drain.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/drain.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/drain.cpp Thu Jan 28 08:37:37 2010
@@ -42,6 +42,7 @@
bool help;
std::string url;
std::string address;
+ std::string connectionOptions;
int64_t timeout;
bool forever;
qpid::log::Options log;
@@ -59,6 +60,7 @@
("address,a", qpid::optValue(address, "ADDRESS"), "address to drain from")
("timeout,t", qpid::optValue(timeout, "TIMEOUT"), "timeout in seconds to wait before exiting")
("forever,f", qpid::optValue(forever), "ignore timeout and wait forever")
+ ("connection-options", qpid::optValue(connectionOptions,"OPTIONS"), "connection options string in the form {name1=value1, name2=value2}")
("help", qpid::optValue(help), "print this usage statement");
add(log);
}
@@ -96,7 +98,8 @@
Options options(argv[0]);
if (options.parse(argc, argv)) {
try {
- Connection connection = Connection::open(options.url);
+ Connection connection(options.connectionOptions);
+ connection.open(options.url);
Session session = connection.newSession();
Receiver receiver = session.createReceiver(options.address);
Duration timeout = options.getTimeout();
Modified: qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/map_receiver.cpp Thu Jan 28 08:37:37 2010
@@ -39,7 +39,8 @@
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
try {
- Connection connection = Connection::open(url);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Receiver receiver = session.createReceiver("message_queue");
Message message = receiver.fetch();
Modified: qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/map_sender.cpp Thu Jan 28 08:37:37 2010
@@ -39,7 +39,8 @@
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
try {
- Connection connection = Connection::open(url);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Sender sender = session.createSender("message_queue");
Modified: qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/queue_receiver.cpp Thu Jan 28 08:37:37 2010
@@ -32,9 +32,8 @@
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
try {
- Variant::Map options;
- if (argc>2) parseOptionString(argv[2], options);
- Connection connection = Connection::open(url, options);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Receiver receiver = session.createReceiver("message_queue");
while (true) {
Modified: qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/queue_sender.cpp Thu Jan 28 08:37:37 2010
@@ -35,7 +35,8 @@
int count = argc>2 ? atoi(argv[2]) : 10;
try {
- Connection connection = Connection::open(url);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Sender sender = session.createSender("message_queue");
Modified: qpid/trunk/qpid/cpp/examples/messaging/server.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/server.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/server.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/server.cpp Thu Jan 28 08:37:37 2010
@@ -42,7 +42,8 @@
const char* url = argc>1 ? argv[1] : "amqp:tcp:127.0.0.1:5672";
try {
- Connection connection = Connection::open(url);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Receiver receiver = session.createReceiver("service_queue; {create: always}");
Modified: qpid/trunk/qpid/cpp/examples/messaging/spout.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/spout.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/spout.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/spout.cpp Thu Jan 28 08:37:37 2010
@@ -56,6 +56,7 @@
string_vector properties;
string_vector entries;
std::string content;
+ std::string connectionOptions;
qpid::log::Options log;
Options(const std::string& argv0=std::string())
@@ -76,6 +77,7 @@
("property,P", qpid::optValue(properties, "NAME=VALUE"), "specify message property")
("map,M", qpid::optValue(entries, "NAME=VALUE"), "specify entry for map content")
("content", qpid::optValue(content, "CONTENT"), "specify textual content")
+ ("connection-options", qpid::optValue(connectionOptions,"OPTIONS"), "connection options string in the form {name1=value1, name2=value2}")
("help", qpid::optValue(help), "print this usage statement");
add(log);
}
@@ -155,7 +157,8 @@
Options options(argv[0]);
if (options.parse(argc, argv)) {
try {
- Connection connection = Connection::open(options.url);
+ Connection connection(options.connectionOptions);
+ connection.open(options.url);
Session session = connection.newSession();
Sender sender = session.createSender(options.address);
Modified: qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/topic_receiver.cpp Thu Jan 28 08:37:37 2010
@@ -35,7 +35,8 @@
const std::string pattern = argc>2 ? argv[2] : "#.#";
try {
- Connection connection = Connection::open(url);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Receiver receiver = session.createReceiver("news_service; {filter:[control, " + pattern + "]}");
while (true) {
Modified: qpid/trunk/qpid/cpp/examples/messaging/topic_sender.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/examples/messaging/topic_sender.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/examples/messaging/topic_sender.cpp (original)
+++ qpid/trunk/qpid/cpp/examples/messaging/topic_sender.cpp Thu Jan 28 08:37:37 2010
@@ -52,7 +52,8 @@
int count = argc>2 ? atoi(argv[2]) : 10;
try {
- Connection connection = Connection::open(url);
+ Connection connection;
+ connection.open(url);
Session session = connection.newSession();
Sender sender = session.createSender("news_service");
Modified: qpid/trunk/qpid/cpp/include/qpid/messaging/Connection.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/include/qpid/messaging/Connection.h?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/include/qpid/messaging/Connection.h (original)
+++ qpid/trunk/qpid/cpp/include/qpid/messaging/Connection.h Thu Jan 28 08:37:37 2010
@@ -38,9 +38,16 @@
class ConnectionImpl;
class Session;
+struct InvalidOptionString : public qpid::Exception
+{
+ InvalidOptionString(const std::string& msg);
+};
+
class Connection : public qpid::client::Handle<ConnectionImpl>
{
public:
+ QPID_CLIENT_EXTERN Connection(ConnectionImpl* impl);
+ QPID_CLIENT_EXTERN Connection(const Connection&);
/**
* Current implementation supports the following options:
*
@@ -70,12 +77,11 @@
*
*
*/
- static QPID_CLIENT_EXTERN Connection open(const std::string& url, const Variant::Map& options = Variant::Map());
-
- QPID_CLIENT_EXTERN Connection(ConnectionImpl* impl = 0);
- QPID_CLIENT_EXTERN Connection(const Connection&);
+ QPID_CLIENT_EXTERN Connection(const Variant::Map& options = Variant::Map());
+ QPID_CLIENT_EXTERN Connection(const std::string& options);
QPID_CLIENT_EXTERN ~Connection();
QPID_CLIENT_EXTERN Connection& operator=(const Connection&);
+ QPID_CLIENT_EXTERN void open(const std::string& url);
QPID_CLIENT_EXTERN void close();
QPID_CLIENT_EXTERN Session newSession(bool transactional, const std::string& name = std::string());
QPID_CLIENT_EXTERN Session newSession(const std::string& name = std::string());
@@ -87,19 +93,6 @@
};
-struct InvalidOptionString : public qpid::Exception
-{
- InvalidOptionString(const std::string& msg);
-};
-
-/**
- * TODO: need to change format of connection option string (currently
- * name1=value1&name2=value2 etc, should probably use map syntax as
- * per address options.
- */
-QPID_CLIENT_EXTERN void parseOptionString(const std::string&, Variant::Map&);
-QPID_CLIENT_EXTERN Variant::Map parseOptionString(const std::string&);
-
}} // namespace qpid::messaging
#endif /*!QPID_MESSAGING_CONNECTION_H*/
Modified: qpid/trunk/qpid/cpp/src/CMakeLists.txt
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/CMakeLists.txt?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/CMakeLists.txt (original)
+++ qpid/trunk/qpid/cpp/src/CMakeLists.txt Thu Jan 28 08:37:37 2010
@@ -639,6 +639,8 @@
qpid/client/SubscriptionManagerImpl.cpp
qpid/client/TCPConnector.cpp
qpid/messaging/Address.cpp
+ qpid/messaging/AddressParser.h
+ qpid/messaging/AddressParser.cpp
qpid/messaging/Connection.cpp
qpid/messaging/ConnectionImpl.h
qpid/messaging/ListContent.cpp
Modified: qpid/trunk/qpid/cpp/src/Makefile.am
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/Makefile.am?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/Makefile.am (original)
+++ qpid/trunk/qpid/cpp/src/Makefile.am Thu Jan 28 08:37:37 2010
@@ -702,6 +702,8 @@
qpid/client/TCPConnector.cpp \
qpid/client/TCPConnector.h \
qpid/messaging/Address.cpp \
+ qpid/messaging/AddressParser.h \
+ qpid/messaging/AddressParser.cpp \
qpid/messaging/Connection.cpp \
qpid/messaging/ListContent.cpp \
qpid/messaging/ListView.cpp \
Modified: qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.cpp Thu Jan 28 08:37:37 2010
@@ -61,8 +61,8 @@
setIfFound(from, "bounds", to.bounds);
}
-ConnectionImpl::ConnectionImpl(const std::string& u, const Variant::Map& options) :
- url(u), reconnectionEnabled(true), timeout(-1),
+ConnectionImpl::ConnectionImpl(const Variant::Map& options) :
+ reconnectionEnabled(true), timeout(-1),
minRetryInterval(1), maxRetryInterval(30)
{
QPID_LOG(debug, "Opening connection to " << url << " with " << options);
@@ -71,6 +71,11 @@
setIfFound(options, "reconnection-timeout", timeout);
setIfFound(options, "min-retry-interval", minRetryInterval);
setIfFound(options, "max-retry-interval", maxRetryInterval);
+}
+
+void ConnectionImpl::open(const std::string& u)
+{
+ url = u;
connection.open(url, settings);
}
Modified: qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/client/amqp0_10/ConnectionImpl.h Thu Jan 28 08:37:37 2010
@@ -40,7 +40,8 @@
class ConnectionImpl : public qpid::messaging::ConnectionImpl
{
public:
- ConnectionImpl(const std::string& url, const qpid::messaging::Variant::Map& options);
+ ConnectionImpl(const qpid::messaging::Variant::Map& options);
+ void open(const std::string& url);
void close();
qpid::messaging::Session newSession(bool transactional, const std::string& name);
qpid::messaging::Session getSession(const std::string& name) const;
Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/Address.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/Address.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/Address.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/Address.cpp Thu Jan 28 08:37:37 2010
@@ -156,207 +156,4 @@
MalformedAddress::MalformedAddress(const std::string& msg) : Exception(msg) {}
-AddressParser::AddressParser(const std::string& s) : input(s), current(0) {}
-
-bool AddressParser::error(const std::string& message)
-{
- throw MalformedAddress((boost::format("%1%, character %2% of %3%") % message % current % input).str());
-}
-
-bool AddressParser::parse(Address& address)
-{
- std::string name;
- if (readName(name)) {
- if (name.find('#') == 0) name = qpid::framing::Uuid(true).str() + name;
- address.setName(name);
- if (readChar('/')) {
- std::string subject;
- if (readSubject(subject)) {
- address.setSubject(subject);
- } else {
- return error("Expected subject after /");
- }
- }
- if (readChar(';')) {
- Variant options = Variant::Map();
- if (readMap(options)) {
- address.setOptions(options.asMap());
- }
- }
- //skip trailing whitespace
- while (!eos() && iswhitespace()) ++current;
- return eos() || error("Unexpected chars in address: " + input.substr(current));
- } else {
- return input.empty() || error("Expected name");
- }
-}
-
-bool AddressParser::readList(Variant& value)
-{
- if (readChar('[')) {
- value = Variant::List();
- Variant item;
- while (readValue(item)) {
- value.asList().push_back(item);
- if (!readChar(',')) break;
- }
- return readChar(']') || error("Unmatched '['!");
- } else {
- return false;
- }
-}
-
-bool AddressParser::readMap(Variant& value)
-{
- if (readChar('{')) {
- value = Variant::Map();
- while (readKeyValuePair(value.asMap()) && readChar(',')) {}
- return readChar('}') || error("Unmatched '{'!");
- } else {
- return false;
- }
-}
-
-bool AddressParser::readKeyValuePair(Variant::Map& map)
-{
- std::string key;
- Variant value;
- if (readKey(key)) {
- if (readChar(':') && readValue(value)) {
- map[key] = value;
- return true;
- } else {
- return error("Bad key-value pair, expected ':'");
- }
- } else {
- return false;
- }
-}
-
-bool AddressParser::readKey(std::string& key)
-{
- return readWord(key);
-}
-
-bool AddressParser::readValue(Variant& value)
-{
- return readSimpleValue(value) || readQuotedValue(value) ||
- readMap(value) || readList(value) || error("Expected value");
-}
-
-bool AddressParser::readString(std::string& value, char delimiter)
-{
- if (readChar(delimiter)) {
- std::string::size_type start = current++;
- while (!eos()) {
- if (input.at(current) == delimiter) {
- if (current > start) {
- value = input.substr(start, current - start);
- } else {
- value = "";
- }
- ++current;
- return true;
- } else {
- ++current;
- }
- }
- return error("Unmatched delimiter");
- } else {
- return false;
- }
-}
-
-bool AddressParser::readName(std::string& name)
-{
- return readQuotedString(name) || readWord(name, "/;");
-}
-
-bool AddressParser::readSubject(std::string& subject)
-{
- return readQuotedString(subject) || readWord(subject, ";");
-}
-
-bool AddressParser::readQuotedString(std::string& s)
-{
- return readString(s, '"') || readString(s, '\'');
-}
-
-bool AddressParser::readQuotedValue(Variant& value)
-{
- std::string s;
- if (readQuotedString(s)) {
- value = s;
- return true;
- } else {
- return false;
- }
-}
-
-bool AddressParser::readSimpleValue(Variant& value)
-{
- std::string s;
- if (readWord(s)) {
- value = s;
- try { value = value.asInt64(); return true; } catch (const InvalidConversion&) {}
- try { value = value.asDouble(); return true; } catch (const InvalidConversion&) {}
- return true;
- } else {
- return false;
- }
-}
-
-bool AddressParser::readWord(std::string& value, const std::string& delims)
-{
- //skip leading whitespace
- while (!eos() && iswhitespace()) ++current;
-
- //read any number of non-whitespace, non-reserved chars into value
- std::string::size_type start = current;
- while (!eos() && !iswhitespace() && !in(delims)) ++current;
-
- if (current > start) {
- value = input.substr(start, current - start);
- return true;
- } else {
- return false;
- }
-}
-
-bool AddressParser::readChar(char c)
-{
- while (!eos()) {
- if (iswhitespace()) {
- ++current;
- } else if (input.at(current) == c) {
- ++current;
- return true;
- } else {
- return false;
- }
- }
- return false;
-}
-
-bool AddressParser::iswhitespace()
-{
- return ::isspace(input.at(current));
-}
-
-bool AddressParser::isreserved()
-{
- return in(RESERVED);
-}
-
-bool AddressParser::in(const std::string& chars)
-{
- return chars.find(input.at(current)) != std::string::npos;
-}
-
-bool AddressParser::eos()
-{
- return current >= input.size();
-}
-
-const std::string AddressParser::RESERVED = "\'\"{}[],:/";
}} // namespace qpid::messaging
Added: qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.cpp?rev=904000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.cpp (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.cpp Thu Jan 28 08:37:37 2010
@@ -0,0 +1,263 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "AddressParser.h"
+#include "qpid/framing/Uuid.h"
+#include <boost/format.hpp>
+
+namespace qpid {
+namespace messaging {
+
+AddressParser::AddressParser(const std::string& s) : input(s), current(0) {}
+
+bool AddressParser::error(const std::string& message)
+{
+ throw MalformedAddress((boost::format("%1%, character %2% of %3%") % message % current % input).str());
+}
+
+bool AddressParser::parse(Address& address)
+{
+ std::string name;
+ if (readName(name)) {
+ if (name.find('#') == 0) name = qpid::framing::Uuid(true).str() + name;
+ address.setName(name);
+ if (readChar('/')) {
+ std::string subject;
+ if (readSubject(subject)) {
+ address.setSubject(subject);
+ } else {
+ return error("Expected subject after /");
+ }
+ }
+ if (readChar(';')) {
+ Variant options = Variant::Map();
+ if (readMap(options)) {
+ address.setOptions(options.asMap());
+ }
+ }
+ //skip trailing whitespace
+ while (!eos() && iswhitespace()) ++current;
+ return eos() || error("Unexpected chars in address: " + input.substr(current));
+ } else {
+ return input.empty() || error("Expected name");
+ }
+}
+
+bool AddressParser::parseMap(Variant::Map& map)
+{
+ if (readChar('{')) {
+ readMapEntries(map);
+ return readChar('}') || error("Unmatched '{'!");
+ } else {
+ return false;
+ }
+}
+
+bool AddressParser::parseList(Variant::List& list)
+{
+ if (readChar('[')) {
+ readListItems(list);
+ return readChar(']') || error("Unmatched '['!");
+ } else {
+ return false;
+ }
+}
+
+
+bool AddressParser::readList(Variant& value)
+{
+ if (readChar('[')) {
+ value = Variant::List();
+ readListItems(value.asList());
+ return readChar(']') || error("Unmatched '['!");
+ } else {
+ return false;
+ }
+}
+
+void AddressParser::readListItems(Variant::List& list)
+{
+ Variant item;
+ while (readValue(item)) {
+ list.push_back(item);
+ if (!readChar(',')) break;
+ }
+}
+
+bool AddressParser::readMap(Variant& value)
+{
+ if (readChar('{')) {
+ value = Variant::Map();
+ readMapEntries(value.asMap());
+ return readChar('}') || error("Unmatched '{'!");
+ } else {
+ return false;
+ }
+}
+
+void AddressParser::readMapEntries(Variant::Map& map)
+{
+ while (readKeyValuePair(map) && readChar(',')) {}
+}
+
+bool AddressParser::readKeyValuePair(Variant::Map& map)
+{
+ std::string key;
+ Variant value;
+ if (readKey(key)) {
+ if (readChar(':') && readValue(value)) {
+ map[key] = value;
+ return true;
+ } else {
+ return error("Bad key-value pair, expected ':'");
+ }
+ } else {
+ return false;
+ }
+}
+
+bool AddressParser::readKey(std::string& key)
+{
+ return readWord(key);
+}
+
+bool AddressParser::readValue(Variant& value)
+{
+ return readSimpleValue(value) || readQuotedValue(value) ||
+ readMap(value) || readList(value) || error("Expected value");
+}
+
+bool AddressParser::readString(std::string& value, char delimiter)
+{
+ if (readChar(delimiter)) {
+ std::string::size_type start = current++;
+ while (!eos()) {
+ if (input.at(current) == delimiter) {
+ if (current > start) {
+ value = input.substr(start, current - start);
+ } else {
+ value = "";
+ }
+ ++current;
+ return true;
+ } else {
+ ++current;
+ }
+ }
+ return error("Unmatched delimiter");
+ } else {
+ return false;
+ }
+}
+
+bool AddressParser::readName(std::string& name)
+{
+ return readQuotedString(name) || readWord(name, "/;");
+}
+
+bool AddressParser::readSubject(std::string& subject)
+{
+ return readQuotedString(subject) || readWord(subject, ";");
+}
+
+bool AddressParser::readQuotedString(std::string& s)
+{
+ return readString(s, '"') || readString(s, '\'');
+}
+
+bool AddressParser::readQuotedValue(Variant& value)
+{
+ std::string s;
+ if (readQuotedString(s)) {
+ value = s;
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool AddressParser::readSimpleValue(Variant& value)
+{
+ std::string s;
+ if (readWord(s)) {
+ value = s;
+ try { value = value.asInt64(); return true; } catch (const InvalidConversion&) {}
+ try { value = value.asDouble(); return true; } catch (const InvalidConversion&) {}
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool AddressParser::readWord(std::string& value, const std::string& delims)
+{
+ //skip leading whitespace
+ while (!eos() && iswhitespace()) ++current;
+
+ //read any number of non-whitespace, non-reserved chars into value
+ std::string::size_type start = current;
+ while (!eos() && !iswhitespace() && !in(delims)) ++current;
+
+ if (current > start) {
+ value = input.substr(start, current - start);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool AddressParser::readChar(char c)
+{
+ while (!eos()) {
+ if (iswhitespace()) {
+ ++current;
+ } else if (input.at(current) == c) {
+ ++current;
+ return true;
+ } else {
+ return false;
+ }
+ }
+ return false;
+}
+
+bool AddressParser::iswhitespace()
+{
+ return ::isspace(input.at(current));
+}
+
+bool AddressParser::isreserved()
+{
+ return in(RESERVED);
+}
+
+bool AddressParser::in(const std::string& chars)
+{
+ return chars.find(input.at(current)) != std::string::npos;
+}
+
+bool AddressParser::eos()
+{
+ return current >= input.size();
+}
+
+const std::string AddressParser::RESERVED = "\'\"{}[],:/";
+
+}} // namespace qpid::messaging
Added: qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.h?rev=904000&view=auto
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.h (added)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/AddressParser.h Thu Jan 28 08:37:37 2010
@@ -0,0 +1,65 @@
+#ifndef QPID_MESSAGING_ADDRESSPARSER_H
+#define QPID_MESSAGING_ADDRESSPARSER_H
+
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+#include "qpid/messaging/Address.h"
+
+namespace qpid {
+namespace messaging {
+
+class AddressParser
+{
+ public:
+ AddressParser(const std::string&);
+ bool parse(Address& address);
+ bool parseMap(Variant::Map& map);
+ bool parseList(Variant::List& list);
+ private:
+ const std::string& input;
+ std::string::size_type current;
+ static const std::string RESERVED;
+
+ bool readChar(char c);
+ bool readQuotedString(std::string& s);
+ bool readQuotedValue(Variant& value);
+ bool readString(std::string& value, char delimiter);
+ bool readWord(std::string& word, const std::string& delims = RESERVED);
+ bool readSimpleValue(Variant& word);
+ bool readKey(std::string& key);
+ bool readValue(Variant& value);
+ bool readKeyValuePair(Variant::Map& map);
+ bool readMap(Variant& value);
+ bool readList(Variant& value);
+ bool readName(std::string& name);
+ bool readSubject(std::string& subject);
+ bool error(const std::string& message);
+ bool eos();
+ bool iswhitespace();
+ bool in(const std::string& delims);
+ bool isreserved();
+ void readListItems(Variant::List& list);
+ void readMapEntries(Variant::Map& map);
+};
+
+}} // namespace qpid::messaging
+
+#endif /*!QPID_MESSAGING_ADDRESSPARSER_H*/
Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/Connection.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/Connection.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/Connection.cpp (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/Connection.cpp Thu Jan 28 08:37:37 2010
@@ -19,6 +19,7 @@
*
*/
#include "qpid/messaging/Connection.h"
+#include "qpid/messaging/AddressParser.h"
#include "qpid/messaging/ConnectionImpl.h"
#include "qpid/messaging/Session.h"
#include "qpid/messaging/SessionImpl.h"
@@ -37,18 +38,27 @@
using qpid::client::PI;
-Connection Connection::open(const std::string& url, const Variant::Map& options)
-{
- //only support amqp 0-10 at present
- Connection connection(new qpid::client::amqp0_10::ConnectionImpl(url, options));
- return connection;
-}
-
Connection::Connection(ConnectionImpl* impl) { PI::ctor(*this, impl); }
Connection::Connection(const Connection& c) : qpid::client::Handle<ConnectionImpl>() { PI::copy(*this, c); }
Connection& Connection::operator=(const Connection& c) { return PI::assign(*this, c); }
Connection::~Connection() { PI::dtor(*this); }
+Connection::Connection(const std::string& o)
+{
+ Variant::Map options;
+ AddressParser parser(o);
+ if (parser.parseMap(options)) {
+ PI::ctor(*this, new qpid::client::amqp0_10::ConnectionImpl(options));
+ } else {
+ throw InvalidOptionString(o);
+ }
+}
+Connection::Connection(const Variant::Map& options)
+{
+ PI::ctor(*this, new qpid::client::amqp0_10::ConnectionImpl(options));
+}
+
+void Connection::open(const std::string& url) { impl->open(url); }
void Connection::close() { impl->close(); }
Session Connection::newSession(const char* name) { return impl->newSession(false, name); }
Session Connection::newSession(const std::string& name) { return impl->newSession(false, name); }
Modified: qpid/trunk/qpid/cpp/src/qpid/messaging/ConnectionImpl.h
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/qpid/messaging/ConnectionImpl.h?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/qpid/messaging/ConnectionImpl.h (original)
+++ qpid/trunk/qpid/cpp/src/qpid/messaging/ConnectionImpl.h Thu Jan 28 08:37:37 2010
@@ -36,6 +36,7 @@
{
public:
virtual ~ConnectionImpl() {}
+ virtual void open(const std::string& url) = 0;
virtual void close() = 0;
virtual Session newSession(bool transactional, const std::string& name) = 0;
virtual Session getSession(const std::string& name) const = 0;
Modified: qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/MessagingSessionTests.cpp Thu Jan 28 08:37:37 2010
@@ -110,9 +110,18 @@
MessagingFixture(Broker::Options opts = Broker::Options()) :
BrokerFixture(opts),
- connection(Connection::open((boost::format("amqp:tcp:localhost:%1%") % (broker->getPort(Broker::TCP_TRANSPORT))).str())),
+ connection(open(broker->getPort(Broker::TCP_TRANSPORT))),
session(connection.newSession()),
- admin(broker->getPort(Broker::TCP_TRANSPORT)) {}
+ admin(broker->getPort(Broker::TCP_TRANSPORT))
+ {
+ }
+
+ static Connection open(uint16_t port)
+ {
+ Connection connection;
+ connection.open((boost::format("amqp:tcp:localhost:%1%") % (port)).str());
+ return connection;
+ }
void ping(const qpid::messaging::Address& address)
{
Modified: qpid/trunk/qpid/cpp/src/tests/qpid_recv.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/qpid_recv.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/qpid_recv.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/qpid_recv.cpp Thu Jan 28 08:37:37 2010
@@ -148,11 +148,8 @@
Options opts;
if (opts.parse(argc, argv)) {
try {
- Variant::Map connectionOptions;
- if (opts.connectionOptions.size()) {
- parseOptionString(opts.connectionOptions, connectionOptions);
- }
- Connection connection = Connection::open(opts.url, connectionOptions);
+ Connection connection(opts.connectionOptions);
+ connection.open(opts.url);
Session session = connection.newSession(opts.tx > 0);
Receiver receiver = session.createReceiver(opts.address);
receiver.setCapacity(opts.capacity);
Modified: qpid/trunk/qpid/cpp/src/tests/qpid_send.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/qpid_send.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/qpid_send.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/qpid_send.cpp Thu Jan 28 08:37:37 2010
@@ -180,11 +180,8 @@
Options opts;
if (opts.parse(argc, argv)) {
try {
- Variant::Map connectionOptions;
- if (opts.connectionOptions.size()) {
- parseOptionString(opts.connectionOptions, connectionOptions);
- }
- Connection connection = Connection::open(opts.url, connectionOptions);
+ Connection connection(opts.connectionOptions);
+ connection.open(opts.url);
Session session = connection.newSession(opts.tx > 0);
Sender sender = session.createSender(opts.address);
Message msg;
Modified: qpid/trunk/qpid/cpp/src/tests/qpid_stream.cpp
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/cpp/src/tests/qpid_stream.cpp?rev=904000&r1=903999&r2=904000&view=diff
==============================================================================
--- qpid/trunk/qpid/cpp/src/tests/qpid_stream.cpp (original)
+++ qpid/trunk/qpid/cpp/src/tests/qpid_stream.cpp Thu Jan 28 08:37:37 2010
@@ -72,7 +72,8 @@
void run()
{
try {
- Connection connection = Connection::open(opts.url);
+ Connection connection;
+ connection.open(opts.url);
Session session = connection.newSession();
doWork(session);
session.close();
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org