summaryrefslogtreecommitdiff
path: root/cpp/lib
diff options
context:
space:
mode:
authorGordon Sim <gsim@apache.org>2007-02-09 16:46:16 +0000
committerGordon Sim <gsim@apache.org>2007-02-09 16:46:16 +0000
commite754770e56a9ff0df5d5be73b04ed658cdbc5855 (patch)
tree121acfabebc179ce6448b98e4c83b7dbfcb54940 /cpp/lib
parent0b3933e6315389c5d32fb7abea5556c15440f888 (diff)
downloadqpid-python-e754770e56a9ff0df5d5be73b04ed658cdbc5855.tar.gz
Handle invalid channels.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/branches/qpid.0-9@505360 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/lib')
-rw-r--r--cpp/lib/broker/BrokerChannel.cpp20
-rw-r--r--cpp/lib/broker/BrokerChannel.h1
-rw-r--r--cpp/lib/broker/Connection.cpp5
-rw-r--r--cpp/lib/broker/Connection.h1
4 files changed, 17 insertions, 10 deletions
diff --git a/cpp/lib/broker/BrokerChannel.cpp b/cpp/lib/broker/BrokerChannel.cpp
index 0d867d0cf3..07636216a6 100644
--- a/cpp/lib/broker/BrokerChannel.cpp
+++ b/cpp/lib/broker/BrokerChannel.cpp
@@ -60,7 +60,7 @@ Channel::Channel(
tagGenerator("sgen"),
store(_store),
messageBuilder(this, _store, _stagingThreshold),
- opened(true),
+ opened(id == 0),//channel 0 is automatically open, other must be explicitly opened
adapter(new BrokerAdapter(*this, con, con.broker))
{
outstanding.reset();
@@ -320,22 +320,22 @@ void Channel::handleMethodInContext(
)
{
try{
- method->invoke(*adapter, context);
+ if(id != 0 && !method->isA<ChannelOpenBody>() && !isOpen()) {
+ std::stringstream out;
+ out << "Attempt to use unopened channel: " << id;
+ throw ConnectionException(504, out.str());
+ } else {
+ method->invoke(*adapter, context);
+ }
}catch(ChannelException& e){
connection.client->getChannel().close(
context, e.code, e.toString(),
method->amqpClassId(), method->amqpMethodId());
connection.closeChannel(getId());
}catch(ConnectionException& e){
- connection.client->getConnection().close(
- context, e.code, e.toString(),
- method->amqpClassId(), method->amqpMethodId());
- connection.getOutput().close();
+ connection.close(e.code, e.toString(), method->amqpClassId(), method->amqpMethodId());
}catch(std::exception& e){
- connection.client->getConnection().close(
- context, 541/*internal error*/, e.what(),
- method->amqpClassId(), method->amqpMethodId());
- connection.getOutput().close();
+ connection.close(541/*internal error*/, e.what(), method->amqpClassId(), method->amqpMethodId());
}
}
diff --git a/cpp/lib/broker/BrokerChannel.h b/cpp/lib/broker/BrokerChannel.h
index 8ad5d691e6..58c4f0a45b 100644
--- a/cpp/lib/broker/BrokerChannel.h
+++ b/cpp/lib/broker/BrokerChannel.h
@@ -36,6 +36,7 @@
#include <Prefetch.h>
#include <TxBuffer.h>
#include "framing/ChannelAdapter.h"
+#include "ChannelOpenBody.h"
#include "CompletionHandler.h"
namespace qpid {
diff --git a/cpp/lib/broker/Connection.cpp b/cpp/lib/broker/Connection.cpp
index 6694a0ed13..000199a65e 100644
--- a/cpp/lib/broker/Connection.cpp
+++ b/cpp/lib/broker/Connection.cpp
@@ -63,6 +63,11 @@ void Connection::received(qpid::framing::AMQFrame* frame){
getChannel(frame->getChannel()).handleBody(frame->getBody());
}
+void Connection::close(ReplyCode code, const string& text, ClassId classId, MethodId methodId){
+ client->getConnection().close(MethodContext(&getChannel(0)), code, text, classId, methodId);
+ getOutput().close();
+}
+
// TODO aconway 2007-02-02: Should be delegated to the BrokerAdapter
// as it is part of the protocol.
void Connection::initiated(qpid::framing::ProtocolInitiation* header) {
diff --git a/cpp/lib/broker/Connection.h b/cpp/lib/broker/Connection.h
index e3d5156c9b..4f1156dd01 100644
--- a/cpp/lib/broker/Connection.h
+++ b/cpp/lib/broker/Connection.h
@@ -86,6 +86,7 @@ class Connection : public sys::ConnectionInputHandler,
Channel& newChannel(framing::ChannelId channel);
Channel& getChannel(framing::ChannelId channel);
void closeChannel(framing::ChannelId channel);
+ void close(framing::ReplyCode code, const string& text, framing::ClassId classId, framing::MethodId methodId);
private:
typedef boost::ptr_map<framing::ChannelId, Channel> ChannelMap;