From 4ce389fb6ed57083ee52e8f82d5fb45f7cc6ad74 Mon Sep 17 00:00:00 2001 From: Andrea Bulgarelli Date: Tue, 17 Sep 2013 14:31:02 +0200 Subject: [PATCH] InputPacketStream::getPacketDimension(byte* stream), InputPacketStream::detPacketType(byte* packet), Packet::verifyPacketValue(byte* stream) --- ChangeLog | 8 ++++++++ include/InputPacketStream.h | 13 +++++++++++-- include/Packet.h | 4 ++++ src/InputPacketStream.cpp | 29 +++++++++++++++++++++++++++++ src/Packet.cpp | 19 +++++++++++++++++++ version | 1 - 6 files changed, 71 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 871d31d..598eee7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2013-09-17 Andrea Bulgarelli + +* include/InputPacketStream.h (InputPacketStream): + ** dword getPacketDimension(byte* stream); + ** int detPacketType(byte* packet); +* include/Packet.h (Packet): bool verifyPacketValue(byte* stream); + + 2013-09-13 Andrea Bulgarelli TAG v2.0.7 * src/PartOfPacket.cpp (PartOfPacket::setByteStream): diff --git a/include/InputPacketStream.h b/include/InputPacketStream.h index af89c16..9e1dc32 100644 --- a/include/InputPacketStream.h +++ b/include/InputPacketStream.h @@ -36,17 +36,26 @@ public: ~InputPacketStream(); - /// \return The index of packet type if it's recognized. 0 if packet isn't recogniezed. + /// \return The index of packet type if it's recognized. 0 if packet isn't recognized. /// \param prefix A ByteStream that contains the prefix of packet (if present). /// \param packetHeader A ByteStream that contains the packet header. /// \param packetDataField A ByteStream that contains the packet data field. int detPacketType(ByteStream* prefix, ByteStream* packetHeader, ByteStream* packetDataField); - /// \return The index of packet type if it's recognized. 0 if packet isn't recogniezed. + /// \return The index of packet type if it's recognized. 0 if packet isn't recognized. /// \param prefix A ByteStream that contains the prefix of packet (if present). /// \param packet A ByteStream that contains the packet. int detPacketType(ByteStream* prefix, ByteStream* packet); + ///It returns the index of the packet type contained in the stream. The stream* contains also the prefix (if present) + /// \return The index of packet type if it's recognized. 0 if packet isn't recognized. + /// \param packet A byte* that contains the packet. + int detPacketType(byte* packet); + + ///It returns the total dimension of the packet contained in the stream (without prefix). The stream* contains also the prefix (if present) + ///\param The stream with the prefix (if present) + dword getPacketDimension(byte* stream); + /// This method sets the generic input of the stream /// \param in An input. void setInput(Input* in); diff --git a/include/Packet.h b/include/Packet.h index 53efe14..e2b865c 100644 --- a/include/Packet.h +++ b/include/Packet.h @@ -86,6 +86,10 @@ public: /// \return True if the ByteStream contains a packet bool verifyPacketValue(ByteStream* prefix, ByteStream* packet); + /// Verifies if within the byte* stream passed with arguments it's present a correct packet. The stream* contains also the prefix (if present) + /// \param stream A pointer to the stream of byte, with prefix and packet + bool verifyPacketValue(byte* stream); + /// Verifies if within the ByteStream passed with arguments it's present a correct packet. /// \pre The structure of the stream must be loaded. /// \param prefix This is the prefix of the packet. diff --git a/src/InputPacketStream.cpp b/src/InputPacketStream.cpp index 51b95fe..db886e5 100644 --- a/src/InputPacketStream.cpp +++ b/src/InputPacketStream.cpp @@ -69,6 +69,18 @@ int InputPacketStream::detPacketType(ByteStream* prefix, ByteStream* packet) } +int InputPacketStream::detPacketType(byte* packet) +{ + /// Iterate through list and output each element. + /// The packetType 0 is the packet not recognized + for (dword i = 1; iverifyPacketValue(packet)) + return i; + } + return 0; +} void InputPacketStream::setInput(Input* in) { @@ -145,3 +157,20 @@ Packet* InputPacketStream::readPacket() throw(PacketExceptionIO*) throw e; } } + +dword InputPacketStream::getPacketDimension(byte* stream) { + dword dimPre = 0; + if(prefix) + dimPre += dimPrefix; + //ByteStream* prefix = new ByteStream(stream, dimPre, bigendian); + + dword dim = 0; + dword dimHeader = headerReference->getDimension(); + dim += dimHeader; + ByteStream* tempHeader = new ByteStream(); + tempHeader->setStream(stream+dimPre, dimHeader, bigendian); + headerReference->setByteStream(tempHeader); + dim += headerReference->getPacketLength(); + delete tempHeader; + return dim; +} diff --git a/src/Packet.cpp b/src/Packet.cpp index 1fe9cd3..33542ca 100644 --- a/src/Packet.cpp +++ b/src/Packet.cpp @@ -835,3 +835,22 @@ char* Packet::printPacketOutputStream() char* c = b.printStreamInHexadecimal(); return c; } + +bool Packet::verifyPacketValue(byte* stream) { + + + dword dimPre = 0; + if(thereisprefix) + dimPre += dimPrefix; + ByteStream* prefix = new ByteStream(stream, dimPre, bigendian); + + dword dim = 0; + dword dimHeader = header->getDimension(); + dim += dimHeader; + tempHeader->setStream(stream+dimPre, dimHeader, bigendian); + header->setByteStream(tempHeader); + dim += header->getDimensionOfPacketLenght() + 1; + ByteStream* packet = new ByteStream(stream+dimPre, dim, bigendian); + + return verifyPacketValue(prefix, packet); +} diff --git a/version b/version index 8c3e788..e69de29 100644 --- a/version +++ b/version @@ -1 +0,0 @@ -2.0.1 -- GitLab