protected final void adjustLengths(int length) { ddmScalarLen_ -= length; adjustCollectionAndDssLengths(length); /* for (int i = 0; i <= topDdmCollectionStack_; i++) { ddmCollectionLenStack_[i] -= length; } dssLength_ -= length; */ }
final int readUnsignedShort() throws DisconnectException { // should we be checking dss lengths and ddmScalarLengths here // if yes, i am not sure this is the correct place if we should be checking ensureBLayerDataInBuffer(2); adjustLengths(2); return ((buffer_[pos_++] & 0xff) << 8) + ((buffer_[pos_++] & 0xff) << 0); }
protected final void ensureBLayerDataInBuffer(int desiredDataSize) throws DisconnectException { if (dssIsContinued_ && (desiredDataSize > dssLength_)) { int continueDssHeaderCount = (((desiredDataSize - dssLength_) / 32767) + 1); ensureALayerDataInBuffer(desiredDataSize + (continueDssHeaderCount * 2)); compressBLayerData(continueDssHeaderCount); return; } ensureALayerDataInBuffer(desiredDataSize); }
protected int adjustDdmLength(int ddmLength, int length) { ddmLength -= length; if (ddmLength == 0) { adjustLengths(getDdmLength()); } return ddmLength; }
return END_OF_SAME_ID_CHAIN; readDssHeader(); ensureBLayerDataInBuffer(4); ddmScalarLen_ = ((buffer_[pos_++] & 0xff) << 8) + int codePoint = ((buffer_[pos_++] & 0xff) << 8) + ((buffer_[pos_++] & 0xff) << 0); adjustLengths(4); readExtendedLength();
ensureALayerDataInBuffer(copySize); adjustLengths(copySize); baos.write(buffer_, pos_, copySize); pos_ += copySize; readDSSContinuationHeader(); int bytesRead = ensureALayerDataInBuffer(dssLength_); //we need to get back all the data here, and then decrypt if (bytesRead > 0) //we ensuredALayerDAtaInBuffer here and set the flag to true, so we don't need do this again later int totalBytesRead = fill(6); //sometimes the 2nd EXTDTA doesn't come back, need to fetch again to get it if (totalBytesRead > 0) { longBufferForDecryption_ = new byte[totalBytesRead];
protected final void parseLengthAndMatchCodePoint(int expectedCodePoint) throws DisconnectException { int actualCodePoint = 0; if (peekedCodePoint_ == END_OF_COLLECTION) { actualCodePoint = readLengthAndCodePoint(); } else { actualCodePoint = peekedCodePoint_; pos_ += (4 + peekedNumOfExtendedLenBytes_); ddmScalarLen_ = peekedLength_; if (peekedNumOfExtendedLenBytes_ == 0 && ddmScalarLen_ != -1) { adjustLengths(4); } else { adjustCollectionAndDssLengths(4 + peekedNumOfExtendedLenBytes_); } peekedLength_ = 0; peekedCodePoint_ = END_OF_COLLECTION; peekedNumOfExtendedLenBytes_ = 0; } if (actualCodePoint != expectedCodePoint) { agent_.accumulateChainBreakingReadExceptionAndThrow( new DisconnectException(agent_, new ClientMessageId(SQLState.NET_NOT_EXPECTED_CODEPOINT), new Integer(actualCodePoint), new Integer(expectedCodePoint))); } }
private final void readExtendedLength() throws DisconnectException { int numberOfExtendedLenBytes = (ddmScalarLen_ - 0x8000); // fix scroll problem was - 4 int adjustSize = 0; switch (numberOfExtendedLenBytes) { case 4: ensureBLayerDataInBuffer(4); ddmScalarLen_ = ((buffer_[pos_++] & 0xff) << 24) + ((buffer_[pos_++] & 0xff) << 16) + ((buffer_[pos_++] & 0xff) << 8) + ((buffer_[pos_++] & 0xff) << 0); adjustSize = 4; break; case 0: ddmScalarLen_ = -1; adjustSize = 0; break; default: doSyntaxrmSemantics(CodePoint.SYNERRCD_INCORRECT_EXTENDED_LEN); } adjustCollectionAndDssLengths(adjustSize); /* // adjust the lengths here. this is a special case since the // extended length bytes do not include their own length. for (int i = 0; i <= topDdmCollectionStack_; i++) { ddmCollectionLenStack_[i] -= adjustSize; } dssLength_ -= adjustSize; */ }
protected final int peekCodePoint() throws DisconnectException { if (topDdmCollectionStack_ != EMPTY_STACK) { if (ddmCollectionLenStack_[topDdmCollectionStack_] == 0) { return END_OF_COLLECTION; } else if (ddmCollectionLenStack_[topDdmCollectionStack_] < 4) { // error } } // if there is no more data in the current dss, and the dss is not // continued, indicate the end of the same Id chain or read the next dss header. if ((dssLength_ == 0) && (!dssIsContinued_)) { if (!dssIsChainedWithSameID_) { return END_OF_SAME_ID_CHAIN; } readDssHeader(); } if (longBufferForDecryption_ == null) //we don't need to do this if it's data stream encryption { ensureBLayerDataInBuffer(4); } peekedLength_ = ((buffer_[pos_] & 0xff) << 8) + ((buffer_[pos_ + 1] & 0xff) << 0); peekedCodePoint_ = ((buffer_[pos_ + 2] & 0xff) << 8) + ((buffer_[pos_ + 3] & 0xff) << 0); // check for extended length if ((peekedLength_ & 0x8000) == 0x8000) { peekExtendedLength(); } else { peekedNumOfExtendedLenBytes_ = 0; } return peekedCodePoint_; }
ensureALayerDataInBuffer(copySize); adjustLengths(copySize); baos.write(buffer_, pos_, copySize); pos_ += copySize; readDSSContinuationHeader();
protected final void readDssHeader() throws DisconnectException { int correlationID = 0; int nextCorrelationID = 0; ensureALayerDataInBuffer(6); doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_LESS_THAN_6); doSyntaxrmSemantics(CodePoint.SYNERRCD_CBYTE_NOT_D0); && ((gdsFormatter & 0x03) != 0x03) && ((gdsFormatter & 0x04) != 0x04)) { doSyntaxrmSemantics(CodePoint.SYNERRCD_FBYTE_NOT_SUPPORTED); doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_SAME_NEXT_CORRELATOR); doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_ERROR_CONTINUE); doSyntaxrmSemantics(CodePoint.SYNERRCD_INVALID_CORRELATOR); } else { dssCorrelationID_ = nextCorrelationID; decryptData(gdsFormatter, oldDssLength); //we have to decrypt data here because
final String readString(int length, String encoding) throws DisconnectException { if (Typdef.UTF8ENCODING.equals(encoding)) { return readString(length, ClientSharedData.UTF8); } ensureBLayerDataInBuffer(length); adjustLengths(length); String s = null; try { s = new String(buffer_, pos_, length, encoding); } catch (java.io.UnsupportedEncodingException e) { agent_.accumulateChainBreakingReadExceptionAndThrow( new DisconnectException(agent_, new ClientMessageId(SQLState.NET_ENCODING_NOT_SUPPORTED), e)); } pos_ += length; return s; }
protected final void readDSSContinuationHeader() throws DisconnectException { ensureALayerDataInBuffer(2); dssLength_ = ((buffer_[pos_++] & 0xFF) << 8) + ((buffer_[pos_++] & 0xFF) << 0); if ((dssLength_ & 0x8000) == 0x8000) { dssLength_ = DssConstants.MAX_DSS_LEN; dssIsContinued_ = true; } else { dssIsContinued_ = false; } // it is a syntax error if the dss continuation header length // is less than or equal to two if (dssLength_ <= 2) { doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_CONT_LESS_OR_EQUAL_2); } dssLength_ -= 2; // avoid consuming the DSS cont header }
private final void peekExtendedLength() throws DisconnectException { peekedNumOfExtendedLenBytes_ = (peekedLength_ - 0x8004); switch (peekedNumOfExtendedLenBytes_) { case 4: // L L C P Extended Length // -->2-bytes<-- --->4-bytes<--- // We are only peeking the length here, the actual pos_ is still before LLCP. We ensured // 4-bytes in peedCodePoint() for the LLCP, and we need to ensure 4-bytes(of LLCP) + the // extended length bytes here. if (longBufferForDecryption_ == null) //we ddon't need to do this if it's data stream encryption { ensureBLayerDataInBuffer(4 + 4); } // The ddmScalarLen_ we peek here does not include the LLCP and the extended length bytes // themselves. So we will add those back to the ddmScalarLen_ so it can be adjusted // correctly in parseLengthAndMatchCodePoint(). (since the adjustLengths() method will // subtract the length from ddmScalarLen_) peekedLength_ = ((buffer_[pos_ + 4] & 0xff) << 24) + ((buffer_[pos_ + 5] & 0xff) << 16) + ((buffer_[pos_ + 6] & 0xff) << 8) + ((buffer_[pos_ + 7] & 0xff) << 0); break; case 0: peekedLength_ = -1; // this ddm is streamed, so set -1 -> length unknown break; default: doSyntaxrmSemantics(CodePoint.SYNERRCD_INCORRECT_EXTENDED_LEN); } }
adjustLengths(copySize); baos.write(buffer_, pos_, copySize); pos_ += copySize; readDSSContinuationHeader();
protected final int peekLength() throws DisconnectException { ensureBLayerDataInBuffer(2); return (((buffer_[pos_] & 0xff) << 8) + ((buffer_[pos_ + 1] & 0xff) << 0)); }
protected final int ensureALayerDataInBuffer(int desiredDataSize) throws DisconnectException { int totalBytesRead = 0; // calulate the the number of bytes in the buffer. int avail = count_ - pos_; // read more bytes off the network if the data is not in the buffer already. if (avail < desiredDataSize) { totalBytesRead = fill(desiredDataSize - avail); } return totalBytesRead; }
protected int fill(int minimumBytesNeeded) throws DisconnectException { ensureSpaceInBufferForFill(minimumBytesNeeded);
doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_LENGTH_BYTE_NUMBER_MISMATCH); doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_CONT_LESS_OR_EQUAL_2);
return END_OF_SAME_ID_CHAIN; readDssHeader(); ensureBLayerDataInBuffer(4); ddmScalarLen_ = ((buffer_[pos_++] & 0xff) << 8) + int codePoint = ((buffer_[pos_++] & 0xff) << 8) + ((buffer_[pos_++] & 0xff) << 0); adjustLengths(4); readExtendedLength();