diff options
| author | Gordon Sim <gsim@apache.org> | 2012-11-27 15:21:09 +0000 |
|---|---|---|
| committer | Gordon Sim <gsim@apache.org> | 2012-11-27 15:21:09 +0000 |
| commit | db0f022fbdbec9e377c3fd2c0b1eff67908aa8dc (patch) | |
| tree | b3f7a648cf611c1ec95b7fbe557c4fc7fe7801ca /cpp/src/qpid/amqp | |
| parent | b14e4d0b6b637c041e9be784f61b56de1715d379 (diff) | |
| download | qpid-python-db0f022fbdbec9e377c3fd2c0b1eff67908aa8dc.tar.gz | |
QPID-4477: make sasl logic a bit smarter, to handle case where we transition input to tunnelled layer while output still has work for sasl
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1414227 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/src/qpid/amqp')
| -rw-r--r-- | cpp/src/qpid/amqp/Decoder.cpp | 1 | ||||
| -rw-r--r-- | cpp/src/qpid/amqp/Decoder.h | 1 | ||||
| -rw-r--r-- | cpp/src/qpid/amqp/Sasl.cpp | 48 |
3 files changed, 29 insertions, 21 deletions
diff --git a/cpp/src/qpid/amqp/Decoder.cpp b/cpp/src/qpid/amqp/Decoder.cpp index 4c14c8e4d9..9c577e6c92 100644 --- a/cpp/src/qpid/amqp/Decoder.cpp +++ b/cpp/src/qpid/amqp/Decoder.cpp @@ -540,5 +540,6 @@ CharSequence Decoder::readRawUuid() } size_t Decoder::getPosition() const { return position; } +size_t Decoder::getSize() const { return size; } void Decoder::resetSize(size_t s) { size = s; } }} // namespace qpid::amqp diff --git a/cpp/src/qpid/amqp/Decoder.h b/cpp/src/qpid/amqp/Decoder.h index cf3e2d36d1..7ddfe0f17f 100644 --- a/cpp/src/qpid/amqp/Decoder.h +++ b/cpp/src/qpid/amqp/Decoder.h @@ -71,6 +71,7 @@ class Decoder QPID_COMMON_EXTERN void advance(size_t); QPID_COMMON_EXTERN size_t getPosition() const; QPID_COMMON_EXTERN void resetSize(size_t size); + QPID_COMMON_EXTERN size_t getSize() const; private: const char* const start; diff --git a/cpp/src/qpid/amqp/Sasl.cpp b/cpp/src/qpid/amqp/Sasl.cpp index 6d0a7ccb1f..7b0779fe94 100644 --- a/cpp/src/qpid/amqp/Sasl.cpp +++ b/cpp/src/qpid/amqp/Sasl.cpp @@ -58,29 +58,35 @@ void Sasl::endFrame(void* frame) std::size_t Sasl::read(const char* data, size_t available) { - Decoder decoder(data, available); - //read frame-header - uint32_t frameSize = decoder.readUInt(); - QPID_LOG(trace, "Reading SASL frame of size " << frameSize); - decoder.resetSize(frameSize); - uint8_t dataOffset = decoder.readUByte(); - uint8_t frameType = decoder.readUByte(); - if (frameType != 0x01) { - QPID_LOG(error, "Expected SASL frame; got type " << frameType); - } - uint16_t ignored = decoder.readUShort(); - if (ignored) { - QPID_LOG(info, "Got non null bytes at end of SASL frame header"); - } + size_t consumed = 0; + while (available - consumed > 4/*framesize*/) { + Decoder decoder(data+consumed, available-consumed); + //read frame-header + uint32_t frameSize = decoder.readUInt(); + if (frameSize > decoder.getSize()) break;//don't have all the data for this frame yet + + QPID_LOG(trace, "Reading SASL frame of size " << frameSize); + decoder.resetSize(frameSize); + uint8_t dataOffset = decoder.readUByte(); + uint8_t frameType = decoder.readUByte(); + if (frameType != 0x01) { + QPID_LOG(error, "Expected SASL frame; got type " << frameType); + } + uint16_t ignored = decoder.readUShort(); + if (ignored) { + QPID_LOG(info, "Got non null bytes at end of SASL frame header"); + } - //body is at offset 4*dataOffset from the start - size_t skip = dataOffset*4 - 8; - if (skip) { - QPID_LOG(info, "Offset for sasl frame was not as expected"); - decoder.advance(skip); + //body is at offset 4*dataOffset from the start + size_t skip = dataOffset*4 - 8; + if (skip) { + QPID_LOG(info, "Offset for sasl frame was not as expected"); + decoder.advance(skip); + } + decoder.read(*this); + consumed += decoder.getPosition(); } - decoder.read(*this); - return decoder.getPosition(); + return consumed; } std::size_t Sasl::write(char* data, size_t size) |
