diff options
author | Alan Conway <aconway@apache.org> | 2008-04-04 14:42:36 +0000 |
---|---|---|
committer | Alan Conway <aconway@apache.org> | 2008-04-04 14:42:36 +0000 |
commit | 37b17edcaeb1fd79eae8801a8b395a63f33a5cf7 (patch) | |
tree | 3f153f504822fb27b71f38c67cc3d88a047ecf21 /cpp | |
parent | 892d5f2f1cca71f7f42bace628ee1ca1296cc6bf (diff) | |
download | qpid-python-37b17edcaeb1fd79eae8801a8b395a63f33a5cf7.tar.gz |
src/qpid/amqp_0_10/Assembly.cpp,.h:
- remove unused class.
src/qpid/Serializer.h, src/qpid/amqp_0_10/Map.h:
- Enforce map Size limits using serializer.
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@644727 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/src/Makefile.am | 2 | ||||
-rw-r--r-- | cpp/src/qpid/Serializer.h | 7 | ||||
-rw-r--r-- | cpp/src/qpid/amqp_0_10/Assembly.cpp | 82 | ||||
-rw-r--r-- | cpp/src/qpid/amqp_0_10/Assembly.h | 71 | ||||
-rw-r--r-- | cpp/src/qpid/amqp_0_10/Map.h | 11 |
5 files changed, 12 insertions, 161 deletions
diff --git a/cpp/src/Makefile.am b/cpp/src/Makefile.am index bb3f87f96b..6dd945fc07 100644 --- a/cpp/src/Makefile.am +++ b/cpp/src/Makefile.am @@ -115,8 +115,6 @@ libqpidcommon_la_SOURCES = \ qpid/amqp_0_10/Segment.h \ qpid/amqp_0_10/Segment.cpp \ qpid/amqp_0_10/SerializableString.h \ - qpid/amqp_0_10/Assembly.h \ - qpid/amqp_0_10/Assembly.cpp \ qpid/amqp_0_10/Map.h \ qpid/amqp_0_10/Map.cpp \ qpid/amqp_0_10/UnknownType.h \ diff --git a/cpp/src/qpid/Serializer.h b/cpp/src/qpid/Serializer.h index d3e5264864..6b67a4ccf8 100644 --- a/cpp/src/qpid/Serializer.h +++ b/cpp/src/qpid/Serializer.h @@ -22,6 +22,7 @@ * */ +#include <limits> #include <algorithm> #include "qpid/Exception.h" // FIXME aconway 2008-04-03: proper exception class. @@ -101,6 +102,12 @@ template <class Derived> class Serializer { return l; } + /** Get the max number of bytes that can be processed under the + * current limit. + */ + size_t getLimit() const { + return limit - bytes; + } /** Set absolute limit. */ void setAbsLimit(size_t n) { limit = n; diff --git a/cpp/src/qpid/amqp_0_10/Assembly.cpp b/cpp/src/qpid/amqp_0_10/Assembly.cpp deleted file mode 100644 index ad753e2d08..0000000000 --- a/cpp/src/qpid/amqp_0_10/Assembly.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * 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 "Assembly.h" -#include "qpid/Exception.h" -#include "Codec.h" -#include "qpid/framing/Blob.h" - -namespace qpid { -namespace amqp_0_10 { - -using framing::in_place; - -Assembly::Assembly(const Command& c) : command(in_place<Command::Holder>(c)) {} -Assembly::Assembly(const Control& c) : control(in_place<Control::Holder>(c)) {} - -void Assembly::add(const Frame& f) { - switch (f.getType()) { - case COMMAND: { - Segment& s = segments[ACTION_SEG]; - s.add(f); - if (s.isComplete()) { - command = in_place<Command::Holder>(); - Codec::decode(s.begin())(*command); - if (f.testFlags(Frame::LAST_SEGMENT)) { - segments[HEADER_SEG].setMissing(); - segments[BODY_SEG].setMissing(); - } - } - break; - } - case CONTROL: { - Segment& s = segments[ACTION_SEG]; - s.add(f); - if (s.isComplete()) { - control = in_place<Control::Holder>(); - Codec::decode(s.begin())(*control); - if (f.testFlags(Frame::LAST_SEGMENT)) { - segments[HEADER_SEG].setMissing(); - segments[BODY_SEG].setMissing(); - } - } - break; - } - case HEADER: { - Segment& s = segments[HEADER_SEG]; - s.add(f); - if (s.isComplete()) { - header = in_place<Header>(); - Codec::decode(*header); - if (f.testFlags(Frame::LAST_SEGMENT)) { - segments[BODY_SEG].setMissing(); - } - } - break; - } - case BODY: { - Segment& s = segments[BODY_SEG]; - s.add(f); - break; - } - } -} - -}} // namespace qpid::amqp_0_10 diff --git a/cpp/src/qpid/amqp_0_10/Assembly.h b/cpp/src/qpid/amqp_0_10/Assembly.h deleted file mode 100644 index 6205032ef9..0000000000 --- a/cpp/src/qpid/amqp_0_10/Assembly.h +++ /dev/null @@ -1,71 +0,0 @@ -#ifndef QPID_AMQP_0_10_ASSEMBLY_H -#define QPID_AMQP_0_10_ASSEMBLY_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/amqp_0_10/CommandHolder.h" -#include "qpid/amqp_0_10/ControlHolder.h" -#include "Segment.h" -#include <boost/optional.hpp> - -namespace qpid { -namespace amqp_0_10 { - -// FIXME aconway 2008-03-06: TODO -struct Header { - template <class S> void serialize(S&) {} -}; - -class Assembly -{ - public: - enum SegmentIndex { ACTION_SEG, HEADER_SEG, BODY_SEG }; - - Assembly() {} - Assembly(const Command& c); - Assembly(const Control& c); - - Segment& getSegment(int i) { return segments[i]; } - const Segment& getSegment(int i) const { return segments[i]; } - - const Command* getCommand() const { return command ? command->get() : 0; } - const Control* getControl() const { return control ? control->get() : 0; } - const Header* getHeader() const { return header.get_ptr(); } - - void setCommand(const Command& c) { *command = c; } - void setControl(const Control& c) { *control = c; } - void setHeader(const Header& h) { header = h; } - - void add(const Frame& f); - - bool isComplete() const { return segments[BODY_SEG].isComplete(); } - - private: - Segment segments[3]; - boost::optional<Command::Holder> command; - boost::optional<Control::Holder> control; - boost::optional<Header> header; -}; - -}} // namespace qpid::amqp_0_10 - -#endif /*!QPID_AMQP_0_10_ASSEMBLY_H*/ diff --git a/cpp/src/qpid/amqp_0_10/Map.h b/cpp/src/qpid/amqp_0_10/Map.h index c23b4e37db..2798e27867 100644 --- a/cpp/src/qpid/amqp_0_10/Map.h +++ b/cpp/src/qpid/amqp_0_10/Map.h @@ -164,18 +164,17 @@ template <class S> void Map::encode(S& s) const { } template <class S> void Map::decode(S& s) { - uint32_t cSize /*, count*/; + uint32_t decodedSize /*, count*/; // FIXME aconway 2008-04-03: replace preview mapping with 0-10 mapping: // s(contentSize())(uint32_t(size())); // size, count - // s(cSize)(count); - s(cSize); - typename S::Iterator start = s.pos(); + // s(decodedSize)(count); + s(decodedSize); + typename S::ScopedLimit l(s, decodedSize); // Make sure we don't overrun. // FIXME aconway 2008-04-03: replace preview with 0-10: // for ( ; count > 0; --count) { - while (uint32_t(std::distance(start, s.pos())) < cSize) { + while (s.getLimit() > 0) { key_type k; MapValue v; s(k)(v); - if (uint32_t(std::distance(start, s.pos())) > cSize) throwInvalidArg(); insert(value_type(k,v)); } } |