mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 00:20:05 +00:00 
			
		
		
		
	Consistent usage of ValidateMessage() in level 3 packets
This commit is contained in:
		
							parent
							
								
									7a9582a689
								
							
						
					
					
						commit
						03fdd99585
					
				
					 5 changed files with 146 additions and 102 deletions
				
			
		|  | @ -75,6 +75,8 @@ bool LinkedContourVectorPacket::Parse(std::istream& is) | |||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    std::streampos isBegin = is.tellg(); | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->initialPointIndicator_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->startI_), 2); | ||||
|  | @ -89,28 +91,6 @@ bool LinkedContourVectorPacket::Parse(std::istream& is) | |||
| 
 | ||||
|    int vectorSize = static_cast<int>(p->lengthOfVectors_); | ||||
| 
 | ||||
|    if (is.eof()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    // The number of vectors is equal to the size divided by the number of bytes
 | ||||
|    // in a vector coordinate
 | ||||
|    int vectorCount = vectorSize / 4; | ||||
| 
 | ||||
|    p->endI_.resize(vectorCount); | ||||
|    p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|    for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|    { | ||||
|       is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|       p->endI_[v] = ntohs(p->endI_[v]); | ||||
|       p->endJ_[v] = ntohs(p->endJ_[v]); | ||||
|    } | ||||
| 
 | ||||
|    if (is.eof()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||
|  | @ -133,6 +113,33 @@ bool LinkedContourVectorPacket::Parse(std::istream& is) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       // The number of vectors is equal to the size divided by the number of
 | ||||
|       // bytes in a vector coordinate
 | ||||
|       int vectorCount = vectorSize / 4; | ||||
| 
 | ||||
|       p->endI_.resize(vectorCount); | ||||
|       p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|       for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|       { | ||||
|          is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|          p->endI_[v] = ntohs(p->endI_[v]); | ||||
|          p->endJ_[v] = ntohs(p->endJ_[v]); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    std::streampos isEnd     = is.tellg(); | ||||
|    std::streamoff bytesRead = isEnd - isBegin; | ||||
| 
 | ||||
|    if (!ValidateMessage(is, bytesRead)) | ||||
|    { | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -81,6 +81,8 @@ bool LinkedVectorPacket::Parse(std::istream& is) | |||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    std::streampos isBegin = is.tellg(); | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 2); | ||||
| 
 | ||||
|  | @ -101,34 +103,6 @@ bool LinkedVectorPacket::Parse(std::istream& is) | |||
| 
 | ||||
|       vectorSize -= 2; | ||||
|    } | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->startI_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->startJ_), 2); | ||||
| 
 | ||||
|    p->startI_ = ntohs(p->startI_); | ||||
|    p->startJ_ = ntohs(p->startJ_); | ||||
| 
 | ||||
|    // The number of vectors is equal to the size divided by the number of bytes
 | ||||
|    // in a vector coordinate
 | ||||
|    int vectorCount = vectorSize / 4; | ||||
| 
 | ||||
|    p->endI_.resize(vectorCount); | ||||
|    p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|    for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|    { | ||||
|       is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|       p->endI_[v] = ntohs(p->endI_[v]); | ||||
|       p->endJ_[v] = ntohs(p->endJ_[v]); | ||||
|    } | ||||
| 
 | ||||
|    if (is.eof()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||
|       blockValid = false; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       if (p->packetCode_ != 6 && p->packetCode_ != 9) | ||||
|  | @ -139,6 +113,39 @@ bool LinkedVectorPacket::Parse(std::istream& is) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       is.read(reinterpret_cast<char*>(&p->startI_), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->startJ_), 2); | ||||
| 
 | ||||
|       p->startI_ = ntohs(p->startI_); | ||||
|       p->startJ_ = ntohs(p->startJ_); | ||||
| 
 | ||||
|       // The number of vectors is equal to the size divided by the number of
 | ||||
|       // bytes in a vector coordinate
 | ||||
|       int vectorCount = vectorSize / 4; | ||||
| 
 | ||||
|       p->endI_.resize(vectorCount); | ||||
|       p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|       for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|       { | ||||
|          is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|          p->endI_[v] = ntohs(p->endI_[v]); | ||||
|          p->endJ_[v] = ntohs(p->endJ_[v]); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    std::streampos isEnd     = is.tellg(); | ||||
|    std::streamoff bytesRead = isEnd - isBegin; | ||||
| 
 | ||||
|    if (!ValidateMessage(is, bytesRead)) | ||||
|    { | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -64,6 +64,8 @@ bool SetColorLevelPacket::Parse(std::istream& is) | |||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    std::streampos isBegin = is.tellg(); | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->colorValueIndicator_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->valueOfContour_), 2); | ||||
|  | @ -94,6 +96,14 @@ bool SetColorLevelPacket::Parse(std::istream& is) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    std::streampos isEnd     = is.tellg(); | ||||
|    std::streamoff bytesRead = isEnd - isBegin; | ||||
| 
 | ||||
|    if (!ValidateMessage(is, bytesRead)) | ||||
|    { | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -70,36 +70,14 @@ bool UnlinkedContourVectorPacket::Parse(std::istream& is) | |||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    std::streampos isBegin = is.tellg(); | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfVectors_), 2); | ||||
| 
 | ||||
|    p->packetCode_      = ntohs(p->packetCode_); | ||||
|    p->lengthOfVectors_ = ntohs(p->lengthOfVectors_); | ||||
| 
 | ||||
|    int vectorSize = static_cast<int>(p->lengthOfVectors_); | ||||
| 
 | ||||
|    // The number of vectors is equal to the size divided by the number of bytes
 | ||||
|    // in a vector
 | ||||
|    int vectorCount = vectorSize / 8; | ||||
| 
 | ||||
|    p->beginI_.resize(vectorCount); | ||||
|    p->beginJ_.resize(vectorCount); | ||||
|    p->endI_.resize(vectorCount); | ||||
|    p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|    for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|    { | ||||
|       is.read(reinterpret_cast<char*>(&p->beginI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->beginJ_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|       p->beginI_[v] = ntohs(p->beginI_[v]); | ||||
|       p->beginJ_[v] = ntohs(p->beginJ_[v]); | ||||
|       p->endI_[v]   = ntohs(p->endI_[v]); | ||||
|       p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||
|    } | ||||
| 
 | ||||
|    if (is.eof()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||
|  | @ -115,6 +93,41 @@ bool UnlinkedContourVectorPacket::Parse(std::istream& is) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       int vectorSize = static_cast<int>(p->lengthOfVectors_); | ||||
| 
 | ||||
|       // The number of vectors is equal to the size divided by the number of
 | ||||
|       // bytes in a vector
 | ||||
|       int vectorCount = vectorSize / 8; | ||||
| 
 | ||||
|       p->beginI_.resize(vectorCount); | ||||
|       p->beginJ_.resize(vectorCount); | ||||
|       p->endI_.resize(vectorCount); | ||||
|       p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|       for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|       { | ||||
|          is.read(reinterpret_cast<char*>(&p->beginI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->beginJ_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|          p->beginI_[v] = ntohs(p->beginI_[v]); | ||||
|          p->beginJ_[v] = ntohs(p->beginJ_[v]); | ||||
|          p->endI_[v]   = ntohs(p->endI_[v]); | ||||
|          p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    std::streampos isEnd     = is.tellg(); | ||||
|    std::streamoff bytesRead = isEnd - isBegin; | ||||
| 
 | ||||
|    if (!ValidateMessage(is, bytesRead)) | ||||
|    { | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -82,6 +82,8 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | |||
| { | ||||
|    bool blockValid = true; | ||||
| 
 | ||||
|    std::streampos isBegin = is.tellg(); | ||||
| 
 | ||||
|    is.read(reinterpret_cast<char*>(&p->packetCode_), 2); | ||||
|    is.read(reinterpret_cast<char*>(&p->lengthOfBlock_), 2); | ||||
| 
 | ||||
|  | @ -102,34 +104,6 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | |||
| 
 | ||||
|       vectorSize -= 2; | ||||
|    } | ||||
| 
 | ||||
|    // The number of vectors is equal to the size divided by the number of bytes
 | ||||
|    // in a vector
 | ||||
|    int vectorCount = vectorSize / 8; | ||||
| 
 | ||||
|    p->beginI_.resize(vectorCount); | ||||
|    p->beginJ_.resize(vectorCount); | ||||
|    p->endI_.resize(vectorCount); | ||||
|    p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|    for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|    { | ||||
|       is.read(reinterpret_cast<char*>(&p->beginI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->beginJ_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|       is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|       p->beginI_[v] = ntohs(p->beginI_[v]); | ||||
|       p->beginJ_[v] = ntohs(p->beginJ_[v]); | ||||
|       p->endI_[v]   = ntohs(p->endI_[v]); | ||||
|       p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||
|    } | ||||
| 
 | ||||
|    if (is.eof()) | ||||
|    { | ||||
|       BOOST_LOG_TRIVIAL(debug) << logPrefix_ << "Reached end of file"; | ||||
|       blockValid = false; | ||||
|    } | ||||
|    else | ||||
|    { | ||||
|       if (p->packetCode_ != 7 && p->packetCode_ != 10) | ||||
|  | @ -140,6 +114,39 @@ bool UnlinkedVectorPacket::Parse(std::istream& is) | |||
|       } | ||||
|    } | ||||
| 
 | ||||
|    if (blockValid) | ||||
|    { | ||||
|       // The number of vectors is equal to the size divided by the number of
 | ||||
|       // bytes in a vector
 | ||||
|       int vectorCount = vectorSize / 8; | ||||
| 
 | ||||
|       p->beginI_.resize(vectorCount); | ||||
|       p->beginJ_.resize(vectorCount); | ||||
|       p->endI_.resize(vectorCount); | ||||
|       p->endJ_.resize(vectorCount); | ||||
| 
 | ||||
|       for (int v = 0; v < vectorCount && !is.eof(); v++) | ||||
|       { | ||||
|          is.read(reinterpret_cast<char*>(&p->beginI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->beginJ_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endI_[v]), 2); | ||||
|          is.read(reinterpret_cast<char*>(&p->endJ_[v]), 2); | ||||
| 
 | ||||
|          p->beginI_[v] = ntohs(p->beginI_[v]); | ||||
|          p->beginJ_[v] = ntohs(p->beginJ_[v]); | ||||
|          p->endI_[v]   = ntohs(p->endI_[v]); | ||||
|          p->endJ_[v]   = ntohs(p->endJ_[v]); | ||||
|       } | ||||
|    } | ||||
| 
 | ||||
|    std::streampos isEnd     = is.tellg(); | ||||
|    std::streamoff bytesRead = isEnd - isBegin; | ||||
| 
 | ||||
|    if (!ValidateMessage(is, bytesRead)) | ||||
|    { | ||||
|       blockValid = false; | ||||
|    } | ||||
| 
 | ||||
|    return blockValid; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat