summaryrefslogtreecommitdiff
path: root/cpp/common/framing/src
diff options
context:
space:
mode:
authorAlan Conway <aconway@apache.org>2006-10-11 15:50:15 +0000
committerAlan Conway <aconway@apache.org>2006-10-11 15:50:15 +0000
commit2bcadbb42a6fb2f096c1fc0a4b957d64a5024ef6 (patch)
tree886eb0659c6f28c2f1d26de7d5fd29fff0072dc5 /cpp/common/framing/src
parent9fc2b6c5f0848d65f1bf20e62279c055d12a1d40 (diff)
downloadqpid-python-2bcadbb42a6fb2f096c1fc0a4b957d64a5024ef6.tar.gz
Turned up gcc warnings, fixed warnings in code, enabled -Werror.
Note: #include "qpid_test_plugin.h" instead of <cppunit/TestPlugin.h> Works around warning from a cppunit macro. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@462834 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/common/framing/src')
-rw-r--r--cpp/common/framing/src/AMQContentBody.cpp4
-rw-r--r--cpp/common/framing/src/AMQFrame.cpp32
-rw-r--r--cpp/common/framing/src/AMQHeaderBody.cpp4
-rw-r--r--cpp/common/framing/src/AMQMethodBody.cpp4
-rw-r--r--cpp/common/framing/src/BasicHeaderProperties.cpp36
-rw-r--r--cpp/common/framing/src/BodyHandler.cpp2
-rw-r--r--cpp/common/framing/src/Buffer.cpp48
-rw-r--r--cpp/common/framing/src/FieldTable.cpp17
-rw-r--r--cpp/common/framing/src/InitiationHandler.cpp21
-rw-r--r--cpp/common/framing/src/InputHandler.cpp21
-rw-r--r--cpp/common/framing/src/OutputHandler.cpp21
11 files changed, 126 insertions, 84 deletions
diff --git a/cpp/common/framing/src/AMQContentBody.cpp b/cpp/common/framing/src/AMQContentBody.cpp
index 6bc588c3ab..1be8867d53 100644
--- a/cpp/common/framing/src/AMQContentBody.cpp
+++ b/cpp/common/framing/src/AMQContentBody.cpp
@@ -30,8 +30,8 @@ u_int32_t qpid::framing::AMQContentBody::size() const{
void qpid::framing::AMQContentBody::encode(Buffer& buffer) const{
buffer.putRawData(data);
}
-void qpid::framing::AMQContentBody::decode(Buffer& buffer, u_int32_t size){
- buffer.getRawData(data, size);
+void qpid::framing::AMQContentBody::decode(Buffer& buffer, u_int32_t _size){
+ buffer.getRawData(data, _size);
}
void qpid::framing::AMQContentBody::print(std::ostream& out) const
diff --git a/cpp/common/framing/src/AMQFrame.cpp b/cpp/common/framing/src/AMQFrame.cpp
index 5686c9ac81..487ab1a443 100644
--- a/cpp/common/framing/src/AMQFrame.cpp
+++ b/cpp/common/framing/src/AMQFrame.cpp
@@ -63,33 +63,13 @@ bool AMQFrame::decode(Buffer& buffer)
{
if(buffer.available() < 7) return false;
buffer.record();
- u_int8_t type = buffer.getOctet();
- channel = buffer.getShort();
- u_int32_t size = buffer.getLong();
- if(buffer.available() < size + 1){
+ u_int32_t bufSize = decodeHead(buffer);
+
+ if(buffer.available() < bufSize + 1){
buffer.restore();
return false;
}
- switch(type)
- {
- case METHOD_BODY:
- body = createMethodBody(buffer);
- break;
- case HEADER_BODY:
- body = AMQBody::shared_ptr(new AMQHeaderBody());
- break;
- case CONTENT_BODY:
- body = AMQBody::shared_ptr(new AMQContentBody());
- break;
- case HEARTBEAT_BODY:
- body = AMQBody::shared_ptr(new AMQHeartbeatBody());
- break;
- default:
- string msg("Unknown body type: ");
- msg += type;
- THROW_QPID_ERROR(FRAMING_ERROR, msg);
- }
- body->decode(buffer, size);
+ decodeBody(buffer, bufSize);
u_int8_t end = buffer.getOctet();
if(end != 0xCE) THROW_QPID_ERROR(FRAMING_ERROR, "Frame end not found");
return true;
@@ -101,7 +81,7 @@ u_int32_t AMQFrame::decodeHead(Buffer& buffer){
return buffer.getLong();
}
-void AMQFrame::decodeBody(Buffer& buffer, uint32_t size)
+void AMQFrame::decodeBody(Buffer& buffer, uint32_t bufSize)
{
switch(type)
{
@@ -122,7 +102,7 @@ void AMQFrame::decodeBody(Buffer& buffer, uint32_t size)
msg += type;
THROW_QPID_ERROR(FRAMING_ERROR, msg);
}
- body->decode(buffer, size);
+ body->decode(buffer, bufSize);
}
std::ostream& qpid::framing::operator<<(std::ostream& out, const AMQFrame& t){
diff --git a/cpp/common/framing/src/AMQHeaderBody.cpp b/cpp/common/framing/src/AMQHeaderBody.cpp
index 1fd387c5d5..dce5f1fd54 100644
--- a/cpp/common/framing/src/AMQHeaderBody.cpp
+++ b/cpp/common/framing/src/AMQHeaderBody.cpp
@@ -41,12 +41,12 @@ void qpid::framing::AMQHeaderBody::encode(Buffer& buffer) const {
properties->encode(buffer);
}
-void qpid::framing::AMQHeaderBody::decode(Buffer& buffer, u_int32_t size){
+void qpid::framing::AMQHeaderBody::decode(Buffer& buffer, u_int32_t bufSize){
u_int16_t classId = buffer.getShort();
weight = buffer.getShort();
contentSize = buffer.getLongLong();
createProperties(classId);
- properties->decode(buffer, size - 12);
+ properties->decode(buffer, bufSize - 12);
}
void qpid::framing::AMQHeaderBody::createProperties(int classId){
diff --git a/cpp/common/framing/src/AMQMethodBody.cpp b/cpp/common/framing/src/AMQMethodBody.cpp
index 73862bb2bf..7455050377 100644
--- a/cpp/common/framing/src/AMQMethodBody.cpp
+++ b/cpp/common/framing/src/AMQMethodBody.cpp
@@ -24,7 +24,7 @@ void qpid::framing::AMQMethodBody::encode(Buffer& buffer) const{
encodeContent(buffer);
}
-void qpid::framing::AMQMethodBody::decode(Buffer& buffer, u_int32_t size){
+void qpid::framing::AMQMethodBody::decode(Buffer& buffer, u_int32_t /*size*/){
decodeContent(buffer);
}
@@ -32,7 +32,7 @@ bool qpid::framing::AMQMethodBody::match(AMQMethodBody* other) const{
return other != 0 && other->amqpClassId() == amqpClassId() && other->amqpMethodId() == amqpMethodId();
}
-void qpid::framing::AMQMethodBody::invoke(AMQP_ServerOperations& target, u_int16_t channel){
+void qpid::framing::AMQMethodBody::invoke(AMQP_ServerOperations& /*target*/, u_int16_t /*channel*/){
THROW_QPID_ERROR(PROTOCOL_ERROR, "Method not supported by AMQP Server.");
}
diff --git a/cpp/common/framing/src/BasicHeaderProperties.cpp b/cpp/common/framing/src/BasicHeaderProperties.cpp
index 4219d33a8f..c9153665d5 100644
--- a/cpp/common/framing/src/BasicHeaderProperties.cpp
+++ b/cpp/common/framing/src/BasicHeaderProperties.cpp
@@ -23,23 +23,23 @@ qpid::framing::BasicHeaderProperties::BasicHeaderProperties() : deliveryMode(0),
qpid::framing::BasicHeaderProperties::~BasicHeaderProperties(){}
u_int32_t qpid::framing::BasicHeaderProperties::size() const{
- u_int32_t size = 2;//flags
- if(contentType.length() > 0) size += contentType.length() + 1;
- if(contentEncoding.length() > 0) size += contentEncoding.length() + 1;
- if(headers.count() > 0) size += headers.size();
- if(deliveryMode != 0) size += 1;
- if(priority != 0) size += 1;
- if(correlationId.length() > 0) size += correlationId.length() + 1;
- if(replyTo.length() > 0) size += replyTo.length() + 1;
- if(expiration.length() > 0) size += expiration.length() + 1;
- if(messageId.length() > 0) size += messageId.length() + 1;
- if(timestamp != 0) size += 8;
- if(type.length() > 0) size += type.length() + 1;
- if(userId.length() > 0) size += userId.length() + 1;
- if(appId.length() > 0) size += appId.length() + 1;
- if(clusterId.length() > 0) size += clusterId.length() + 1;
+ u_int32_t bytes = 2;//flags
+ if(contentType.length() > 0) bytes += contentType.length() + 1;
+ if(contentEncoding.length() > 0) bytes += contentEncoding.length() + 1;
+ if(headers.count() > 0) bytes += headers.size();
+ if(deliveryMode != 0) bytes += 1;
+ if(priority != 0) bytes += 1;
+ if(correlationId.length() > 0) bytes += correlationId.length() + 1;
+ if(replyTo.length() > 0) bytes += replyTo.length() + 1;
+ if(expiration.length() > 0) bytes += expiration.length() + 1;
+ if(messageId.length() > 0) bytes += messageId.length() + 1;
+ if(timestamp != 0) bytes += 8;
+ if(type.length() > 0) bytes += type.length() + 1;
+ if(userId.length() > 0) bytes += userId.length() + 1;
+ if(appId.length() > 0) bytes += appId.length() + 1;
+ if(clusterId.length() > 0) bytes += clusterId.length() + 1;
- return size;
+ return bytes;
}
void qpid::framing::BasicHeaderProperties::encode(qpid::framing::Buffer& buffer) const{
@@ -62,9 +62,8 @@ void qpid::framing::BasicHeaderProperties::encode(qpid::framing::Buffer& buffer)
if(clusterId.length() > 0) buffer.putShortString(clusterId);
}
-void qpid::framing::BasicHeaderProperties::decode(qpid::framing::Buffer& buffer, u_int32_t size){
+void qpid::framing::BasicHeaderProperties::decode(qpid::framing::Buffer& buffer, u_int32_t /*size*/){
u_int16_t flags = buffer.getShort();
- int shift = 15;
if(flags & (1 << 15)) buffer.getShortString(contentType);
if(flags & (1 << 14)) buffer.getShortString(contentEncoding);
if(flags & (1 << 13)) buffer.getFieldTable(headers);
@@ -83,7 +82,6 @@ void qpid::framing::BasicHeaderProperties::decode(qpid::framing::Buffer& buffer,
u_int16_t qpid::framing::BasicHeaderProperties::getFlags() const{
u_int16_t flags(0);
- int shift = 15;
if(contentType.length() > 0) flags |= (1 << 15);
if(contentEncoding.length() > 0) flags |= (1 << 14);
if(headers.count() > 0) flags |= (1 << 13);
diff --git a/cpp/common/framing/src/BodyHandler.cpp b/cpp/common/framing/src/BodyHandler.cpp
index 4e4e2e02f7..b428c62637 100644
--- a/cpp/common/framing/src/BodyHandler.cpp
+++ b/cpp/common/framing/src/BodyHandler.cpp
@@ -21,6 +21,8 @@
using namespace qpid::framing;
using namespace std::tr1;
+BodyHandler::~BodyHandler() {}
+
void BodyHandler::handleBody(AMQBody::shared_ptr& body){
switch(body->type())
diff --git a/cpp/common/framing/src/Buffer.cpp b/cpp/common/framing/src/Buffer.cpp
index 15a4485abd..87aa1df7e9 100644
--- a/cpp/common/framing/src/Buffer.cpp
+++ b/cpp/common/framing/src/Buffer.cpp
@@ -18,7 +18,7 @@
#include "Buffer.h"
#include "FieldTable.h"
-qpid::framing::Buffer::Buffer(int _size) : size(_size), position(0), limit(_size){
+qpid::framing::Buffer::Buffer(u_int32_t _size) : size(_size), position(0), limit(_size){
data = new char[size];
}
@@ -37,7 +37,7 @@ void qpid::framing::Buffer::clear(){
}
void qpid::framing::Buffer::compact(){
- int p = limit - position;
+ u_int32_t p = limit - position;
//copy p chars from position to 0
memmove(data, data + position, p);
limit = size;
@@ -54,7 +54,7 @@ void qpid::framing::Buffer::restore(){
limit = r_limit;
}
-int qpid::framing::Buffer::available(){
+u_int32_t qpid::framing::Buffer::available(){
return limit - position;
}
@@ -62,7 +62,7 @@ char* qpid::framing::Buffer::start(){
return data + position;
}
-void qpid::framing::Buffer::move(int bytes){
+void qpid::framing::Buffer::move(u_int32_t bytes){
position += bytes;
}
@@ -123,29 +123,29 @@ u_int64_t qpid::framing::Buffer::getLongLong(){
void qpid::framing::Buffer::putShortString(const string& s){
- u_int8_t size = s.length();
- putOctet(size);
- s.copy(data + position, size);
- position += size;
+ u_int8_t len = s.length();
+ putOctet(len);
+ s.copy(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::putLongString(const string& s){
- u_int32_t size = s.length();
- putLong(size);
- s.copy(data + position, size);
- position += size;
+ u_int32_t len = s.length();
+ putLong(len);
+ s.copy(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::getShortString(string& s){
- u_int8_t size = getOctet();
- s.assign(data + position, size);
- position += size;
+ u_int8_t len = getOctet();
+ s.assign(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::getLongString(string& s){
- u_int32_t size = getLong();
- s.assign(data + position, size);
- position += size;
+ u_int32_t len = getLong();
+ s.assign(data + position, len);
+ position += len;
}
void qpid::framing::Buffer::putFieldTable(const FieldTable& t){
@@ -157,12 +157,12 @@ void qpid::framing::Buffer::getFieldTable(FieldTable& t){
}
void qpid::framing::Buffer::putRawData(const string& s){
- u_int32_t size = s.length();
- s.copy(data + position, size);
- position += size;
+ u_int32_t len = s.length();
+ s.copy(data + position, len);
+ position += len;
}
-void qpid::framing::Buffer::getRawData(string& s, u_int32_t size){
- s.assign(data + position, size);
- position += size;
+void qpid::framing::Buffer::getRawData(string& s, u_int32_t len){
+ s.assign(data + position, len);
+ position += len;
}
diff --git a/cpp/common/framing/src/FieldTable.cpp b/cpp/common/framing/src/FieldTable.cpp
index b12b2783df..088c8fb500 100644
--- a/cpp/common/framing/src/FieldTable.cpp
+++ b/cpp/common/framing/src/FieldTable.cpp
@@ -27,12 +27,12 @@ namespace framing {
FieldTable::~FieldTable() {}
u_int32_t FieldTable::size() const {
- u_int32_t size(4);
+ u_int32_t len(4);
for(ValueMap::const_iterator i = values.begin(); i != values.end(); ++i) {
// 2 = shortstr_len_byyte + type_char_byte
- size += 2 + (i->first).size() + (i->second)->size();
+ len += 2 + (i->first).size() + (i->second)->size();
}
- return size;
+ return len;
}
int FieldTable::count() const {
@@ -74,9 +74,6 @@ void FieldTable::setTable(const std::string& name, const FieldTable& value){
}
namespace {
-// TODO aconway 2006-09-26: This is messy. Revisit the field table
-// and Value classes with a traits-based approach.
-//
template <class T> T default_value() { return T(); }
template <> int default_value<int>() { return 0; }
template <> u_int64_t default_value<u_int64_t>() { return 0; }
@@ -117,9 +114,11 @@ void FieldTable::encode(Buffer& buffer) const{
}
void FieldTable::decode(Buffer& buffer){
- u_int32_t size = buffer.getLong();
- int leftover = buffer.available() - size;
-
+ u_int32_t len = buffer.getLong();
+ u_int32_t available = buffer.available();
+ if (available < len)
+ THROW_QPID_ERROR(FRAMING_ERROR, "Not enough data for field table.");
+ u_int32_t leftover = available - len;
while(buffer.available() > leftover){
std::string name;
buffer.getShortString(name);
diff --git a/cpp/common/framing/src/InitiationHandler.cpp b/cpp/common/framing/src/InitiationHandler.cpp
new file mode 100644
index 0000000000..9c18facf44
--- /dev/null
+++ b/cpp/common/framing/src/InitiationHandler.cpp
@@ -0,0 +1,21 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "InitiationHandler.h"
+
+qpid::framing::InitiationHandler::~InitiationHandler() {}
diff --git a/cpp/common/framing/src/InputHandler.cpp b/cpp/common/framing/src/InputHandler.cpp
new file mode 100644
index 0000000000..7116caa24a
--- /dev/null
+++ b/cpp/common/framing/src/InputHandler.cpp
@@ -0,0 +1,21 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "InputHandler.h"
+
+qpid::framing::InputHandler::~InputHandler() {}
diff --git a/cpp/common/framing/src/OutputHandler.cpp b/cpp/common/framing/src/OutputHandler.cpp
new file mode 100644
index 0000000000..8d99b4ef92
--- /dev/null
+++ b/cpp/common/framing/src/OutputHandler.cpp
@@ -0,0 +1,21 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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 "OutputHandler.h"
+
+qpid::framing::OutputHandler::~OutputHandler() {}