Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 32313 invoked from network); 2 May 2005 06:27:22 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 2 May 2005 06:27:22 -0000 Received: (qmail 83559 invoked by uid 500); 2 May 2005 06:28:38 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 83469 invoked by uid 500); 2 May 2005 06:28:36 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 83364 invoked by uid 500); 2 May 2005 06:28:34 -0000 Delivered-To: apmail-incubator-derby-cvs@incubator.apache.org Received: (qmail 83213 invoked by uid 99); 2 May 2005 06:28:32 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 01 May 2005 23:28:27 -0700 Received: (qmail 31705 invoked by uid 65534); 2 May 2005 06:26:47 -0000 Message-ID: <20050502062647.31703.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r165585 [38/42] - in /incubator/derby/code/trunk/java/client/org/apache/derby: client/ client/am/ client/net/ client/resources/ jdbc/ Date: Mon, 02 May 2005 06:26:03 -0000 To: derby-cvs@incubator.apache.org From: jboynes@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Modified: incubator/derby/code/trunk/java/client/org/apache/derby/client/ne= t/Reply.java URL: http://svn.apache.org/viewcvs/incubator/derby/code/trunk/java/client/o= rg/apache/derby/client/net/Reply.java?rev=3D165585&r1=3D165584&r2=3D165585&= view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- incubator/derby/code/trunk/java/client/org/apache/derby/client/net/Repl= y=2Ejava (original) +++ incubator/derby/code/trunk/java/client/org/apache/derby/client/net/Repl= y=2Ejava Sun May 1 23:25:59 2005 @@ -21,1479 +21,1398 @@ package org.apache.derby.client.net; =20 =20 -import org.apache.derby.client.am.SqlState; -import org.apache.derby.client.am.SqlException; -import org.apache.derby.client.am.SignedBinary; import java.io.ByteArrayOutputStream; =20 -public class Reply -{ - protected org.apache.derby.client.am.Agent agent_; - protected NetAgent netAgent_; //cheat-link to (NetAgent) agent_ - - private CcsidManager ccsidManager_; - protected final static int DEFAULT_BUFFER_SIZE =3D 32767; - protected byte[] buffer_; - protected int pos_; - protected int count_; - - private int topDdmCollectionStack_; - private final static int MAX_MARKS_NESTING =3D 10; - private int[] ddmCollectionLenStack_; - private int ddmScalarLen_; // a value of -1 -> streamed ddm -> length un= known - private final static int EMPTY_STACK =3D -1; - - protected boolean ensuredLengthForDecryption_ =3D false; // A layer leng= ths have already been ensured in decrypt method. - protected byte[] longBufferForDecryption_ =3D null; - protected int longPosForDecryption_ =3D 0; - protected byte[] longValueForDecryption_ =3D null; - protected int longCountForDecryption_ =3D 0; - - protected int dssLength_; - protected boolean dssIsContinued_; - private boolean dssIsChainedWithSameID_; - private boolean dssIsChainedWithDiffID_; - protected int dssCorrelationID_; - - protected int peekedLength_ =3D 0; - protected int peekedCodePoint_ =3D END_OF_COLLECTION; // saves the pe= eked codept - private int peekedNumOfExtendedLenBytes_ =3D 0; - private int currentPos_ =3D 0; - - public final static int END_OF_COLLECTION =3D -1; - public final static int END_OF_SAME_ID_CHAIN =3D -2; - Reply (NetAgent netAgent, int bufferSize) - { - buffer_ =3D new byte[bufferSize]; - agent_ =3D netAgent_ =3D netAgent; - ccsidManager_ =3D netAgent.targetCcsidManager_; - ddmCollectionLenStack_ =3D new int[Reply.MAX_MARKS_NESTING]; - initialize (); - } - - final void initialize () - { - pos_ =3D 0; - count_ =3D 0; - topDdmCollectionStack_ =3D Reply.EMPTY_STACK; - for (int i =3D 0; i < Reply.MAX_MARKS_NESTING; i++) { - ddmCollectionLenStack_[i] =3D 0; - } - ddmScalarLen_ =3D 0; - dssLength_ =3D 0; - dssIsContinued_ =3D false; - dssIsChainedWithSameID_ =3D false; - dssIsChainedWithDiffID_ =3D false; - dssCorrelationID_ =3D 1; - } - - final int getDdmLength() - { - return ddmScalarLen_; - } - - // This is a helper method which shifts the buffered bytes from - // wherever they are in the current buffer to the beginning of - // different buffer (note these buffers could be the same). - // State information is updated as needed after the shift. - private final void shiftBuffer (byte[] destinationBuffer) - { - // calculate the size of the data in the current buffer. - int sz =3D count_ - pos_; - - // copy this data to the new buffer starting at position 0. - System.arraycopy (buffer_, pos_, destinationBuffer, 0, sz); - - // update the state information for data in the new buffer. - pos_ =3D 0; - count_ =3D sz; - - // replace the old buffer with the new buffer. - buffer_ =3D destinationBuffer; - } - - // This method makes sure there is enough room in the buffer - // for a certain number of bytes. This method will allocate - // a new buffer if needed and shift the bytes in the current buffer - // to make ensure space is available for a fill. Right now - // this method will shift bytes as needed to make sure there is - // as much room as possible in the buffer before trying to - // do the read. The idea is to try to have space to get as much data as= possible - // if we need to do a read on the socket's stream. - protected final void ensureSpaceInBufferForFill (int desiredSpace) - { - // calculate the total unused space in the buffer. - // this includes any space at the end of the buffer and any free - // space at the beginning resulting from bytes already read. - int currentAvailableSpace =3D (buffer_.length - count_) + pos_; - - // check to see if there is enough free space. - if (currentAvailableSpace < desiredSpace) { - - // there is not enough free space so we need more storage. - // we are going to double the buffer unless that happens to still be= too small. - // if more than double the buffer is needed, use the smallest amount= over this as possible. - int doubleBufferSize =3D (2 * buffer_.length); - - int minumNewBufferSize =3D (desiredSpace - currentAvailableSpace) + = buffer_.length; - int newsz =3D minumNewBufferSize <=3D doubleBufferSize ? doubleBuffe= rSize : minumNewBufferSize; - - byte[] newBuffer =3D new byte[newsz]; - - // shift everything from the old buffer to the new buffer - shiftBuffer (newBuffer); - } - else { - - // there is enough free space in the buffer but let's make sure it i= s all at the end. - // this is also important because if we are going to do a read, it w= ould be nice - // to get as much data as possible and making room at the end if the= buffer helps to - // ensure this. - if (pos_ !=3D 0) { - shiftBuffer (buffer_); - } - } - } - - // This method will attempt to read a minimum number of bytes - // from the underlying stream. This method will keep trying to - // read bytes until it has obtained at least the minimum number. - // Now returns the total bytes read for decryption, use to return void. - protected int fill (int minimumBytesNeeded) throws org.apache.derby.clie= nt.am.DisconnectException - { - // make sure that there is enough space in the buffer to hold - // the minimum number of bytes needed. - ensureSpaceInBufferForFill (minimumBytesNeeded); - - // read until the minimum number of bytes needed is now in the buffer. - // hopefully the read method will return as many bytes as it can. - int totalBytesRead =3D 0; - int actualBytesRead =3D 0; - do { - try { - // oops, we shouldn't expose the agent's input stream here, collaps= e this into a read method on the agent - actualBytesRead =3D netAgent_.getInputStream().read (buffer_, coun= t_, buffer_.length - count_); - } - catch (java.io.IOException ioe) { - netAgent_.throwCommunicationsFailure ("Reply.fill()", - "InputStream.read()", - ioe.getMessage(), - "*"); - } - finally { - if (agent_.loggingEnabled()) - ((NetLogWriter) netAgent_.logWriter_).traceProtocolFlow (buffer_, - count_, - actualBytesRead, - NetLogWriter.TYPE_TRACE_RECEIVE, - "Reply", - "fill", - 2); // tracepoint - } - count_ +=3D actualBytesRead; - totalBytesRead +=3D actualBytesRead; - - } - while ((totalBytesRead < minimumBytesNeeded) && (actualBytesRead !=3D = -1)); - - if (actualBytesRead =3D=3D -1) { - if (totalBytesRead < minimumBytesNeeded) { - netAgent_.throwCommunicationsFailure ("Reply.fill()", - "InputStream.read()", - "insufficient data", - "*"); - } - } - return totalBytesRead; - } - - // Make sure a certain amount of Layer A data is in the buffer. - // The data will be in the buffer after this method is called. - // Now returns the total bytes read for decryption, use to return void. - protected final int ensureALayerDataInBuffer (int desiredDataSize) throw= s org.apache.derby.client.am.DisconnectException - { - int totalBytesRead =3D 0; - // calulate the the number of bytes in the buffer. - int avail =3D count_ - pos_; - - // read more bytes off the network if the data is not in the buffer al= ready. - if (avail < desiredDataSize) { - totalBytesRead =3D fill (desiredDataSize - avail); - } - return totalBytesRead; - } - - protected final void ensureBLayerDataInBuffer (int desiredDataSize) thro= ws org.apache.derby.client.am.DisconnectException - { - if (dssIsContinued_ && (desiredDataSize > dssLength_)) { - int continueDssHeaderCount =3D - (((desiredDataSize - dssLength_) / 32767) + 1); - ensureALayerDataInBuffer (desiredDataSize + (continueDssHeaderCount = * 2)); - compressBLayerData (continueDssHeaderCount); - return; - } - ensureALayerDataInBuffer (desiredDataSize); - } - - // this will probably never be called. - // it is included here in the highly unlikely event that a reply object - // exceeds 32K. for opimization purposes, we should consider - // removing this. removing this should be ok since we handle most - // big stuff returned from the server (qrydta's for example) by - // copying out the data into some other storage. any extended dss header - // info will be removed in the copying process. - private final void compressBLayerData (int continueDssHeaderCount) throw= s org.apache.derby.client.am.DisconnectException - { - int tempPos =3D 0; - - // jump to the last continuation header. - for (int i =3D 0; i < continueDssHeaderCount; i++) { - // the first may be less than the size of a full dss - if (i =3D=3D 0) { - // only jump by the number of bytes remaining in the current dss - tempPos =3D pos_ + dssLength_; - } - else { - // all other jumps are for a full continued dss - tempPos +=3D 32767; - } - } - - // for each of the dss headers to remove, - // read out the continuation header and increment the dss length by the - // size of the conitnation bytes, then shift the continuation data as= needed. - int shiftSize =3D 0; - int bytesToShift =3D 0; - int continueHeaderLength =3D 0; - int newDssLength =3D 0; - for (int i =3D 0; i < continueDssHeaderCount; i++) { - - continueHeaderLength =3D ((buffer_[tempPos]&0xFF) << 8) + - ((buffer_[tempPos + 1]&0xFF) << 0); - - if (i =3D=3D 0) { - // if this is the last one (farthest down stream and first to stri= p out) - - if ((continueHeaderLength & 0x8000) =3D=3D 0x8000) { - // the last dss header is again continued - continueHeaderLength =3D 32767; - dssIsContinued_ =3D true; - } - else { - // the last dss header was not contiued so update continue state= flag - dssIsContinued_ =3D false; - } - // the very first shift size is 2 - shiftSize =3D 2; - } - else { - // already removed the last header so make sure the chaining flag = is on - if ((continueHeaderLength & 0x8000) =3D=3D 0x8000) { - continueHeaderLength =3D 32767; - } - else { - // this is a syntax error but not really certain which one. - // for now pick 0x02 which is Dss header Length does not match t= he number - // of bytes of data found. - doSyntaxrmSemantics (CodePoint.SYNERRCD_DSS_LENGTH_BYTE_NUMBER_M= ISMATCH); - } - // increase the shift size by 2 - shiftSize +=3D 2; - } - - // it is a syntax error if the dss continuation is less than or equa= l to two - if (continueHeaderLength <=3D 2) { - doSyntaxrmSemantics (CodePoint.SYNERRCD_DSS_CONT_LESS_OR_EQUAL_2); - } - - newDssLength +=3D (continueHeaderLength - 2); - - // calculate the number of bytes to shift - if (i !=3D (continueDssHeaderCount - 1)) - bytesToShift =3D 32767; - else - bytesToShift =3D dssLength_; - - tempPos -=3D (shiftSize - 1); - // perform the compress - for (int j =3D 0; j < bytesToShift; j++) { - buffer_[tempPos + shiftSize] =3D buffer_[tempPos]; - tempPos--; - } - tempPos +=3D (shiftSize + 1); - } - // reposition the start of the data after the final dss shift. - pos_ =3D tempPos; - dssLength_ =3D dssLength_ + newDssLength; - } - - protected final void readDssHeader () throws org.apache.derby.client.am.= DisconnectException - { - int correlationID =3D 0; - int nextCorrelationID =3D 0; - ensureALayerDataInBuffer (6); - - // read out the dss length - dssLength_ =3D - ((buffer_[pos_++]&0xFF) << 8) + - ((buffer_[pos_++]&0xFF) << 0); - - // Remember the old dss length for decryption only. - int oldDssLength =3D dssLength_; - - // check for the continuation bit and update length as needed. - if ((dssLength_ & 0x8000) =3D=3D 0x8000) { - dssLength_ =3D 32767; - dssIsContinued_ =3D true; - } - else { - dssIsContinued_ =3D false; - } - - if (dssLength_ < 6) - doSyntaxrmSemantics (CodePoint.SYNERRCD_DSS_LESS_THAN_6); - - // If the GDS id is not valid, or - // if the reply is not an RPYDSS nor - // a OBJDSS, then throw an exception. - if ((buffer_[pos_++]&0xFF) !=3D 0xd0) - doSyntaxrmSemantics (CodePoint.SYNERRCD_CBYTE_NOT_D0); - - int gdsFormatter =3D buffer_[pos_++]&0xFF; - if (((gdsFormatter & 0x02) !=3D 0x02) - &&((gdsFormatter & 0x03) !=3D 0x03) - &&((gdsFormatter & 0x04) !=3D 0x04)) { - doSyntaxrmSemantics (CodePoint.SYNERRCD_FBYTE_NOT_SUPPORTED); - } - - // Determine if the current DSS is chained with the - // next DSS, with the same or different request ID. - if ((gdsFormatter & 0x40) =3D=3D 0x40) { // on indicates structure = chained to next structure - if ((gdsFormatter & 0x10) =3D=3D 0x10) { - dssIsChainedWithSameID_ =3D true; - dssIsChainedWithDiffID_ =3D false; - nextCorrelationID =3D dssCorrelationID_; - } - else { +import org.apache.derby.client.am.SignedBinary; +import org.apache.derby.client.am.SqlException; +import org.apache.derby.client.am.SqlState; + +public class Reply { + protected org.apache.derby.client.am.Agent agent_; + protected NetAgent netAgent_; //cheat-link to (NetAgent) agent_ + + private CcsidManager ccsidManager_; + protected final static int DEFAULT_BUFFER_SIZE =3D 32767; + protected byte[] buffer_; + protected int pos_; + protected int count_; + + private int topDdmCollectionStack_; + private final static int MAX_MARKS_NESTING =3D 10; + private int[] ddmCollectionLenStack_; + private int ddmScalarLen_; // a value of -1 -> streamed ddm -> length = unknown + private final static int EMPTY_STACK =3D -1; + + protected boolean ensuredLengthForDecryption_ =3D false; // A layer le= ngths have already been ensured in decrypt method. + protected byte[] longBufferForDecryption_ =3D null; + protected int longPosForDecryption_ =3D 0; + protected byte[] longValueForDecryption_ =3D null; + protected int longCountForDecryption_ =3D 0; + + protected int dssLength_; + protected boolean dssIsContinued_; + private boolean dssIsChainedWithSameID_; + private boolean dssIsChainedWithDiffID_; + protected int dssCorrelationID_; + + protected int peekedLength_ =3D 0; + protected int peekedCodePoint_ =3D END_OF_COLLECTION; // saves the = peeked codept + private int peekedNumOfExtendedLenBytes_ =3D 0; + private int currentPos_ =3D 0; + + public final static int END_OF_COLLECTION =3D -1; + public final static int END_OF_SAME_ID_CHAIN =3D -2; + + Reply(NetAgent netAgent, int bufferSize) { + buffer_ =3D new byte[bufferSize]; + agent_ =3D netAgent_ =3D netAgent; + ccsidManager_ =3D netAgent.targetCcsidManager_; + ddmCollectionLenStack_ =3D new int[Reply.MAX_MARKS_NESTING]; + initialize(); + } + + final void initialize() { + pos_ =3D 0; + count_ =3D 0; + topDdmCollectionStack_ =3D Reply.EMPTY_STACK; + for (int i =3D 0; i < Reply.MAX_MARKS_NESTING; i++) { + ddmCollectionLenStack_[i] =3D 0; + } + ddmScalarLen_ =3D 0; + dssLength_ =3D 0; + dssIsContinued_ =3D false; dssIsChainedWithSameID_ =3D false; - dssIsChainedWithDiffID_ =3D true; - nextCorrelationID =3D dssCorrelationID_ + 1; - } - } - else { - // chaining bit not b'1', make sure DSSFMT bit3 not b'1' - if ((gdsFormatter & 0x10) =3D=3D 0x10) { // Next DSS can not have = same correlator - doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_SAME_NEXT_CORRELA= TOR); - } - - // chaining bit not b'1', make sure no error continuation - if ((gdsFormatter & 0x20) =3D=3D 0x20) { // must be 'do not continue= on error' - doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_ERROR_CONTINUE); - } - - dssIsChainedWithSameID_ =3D false; - dssIsChainedWithDiffID_ =3D false; - nextCorrelationID =3D 1; - } - - correlationID =3D - ((buffer_[pos_++]&0xFF) << 8) + - ((buffer_[pos_++]&0xFF) << 0); - - // corrid must be the one expected or a -1 which gets returned in some= error cases. - if ((correlationID !=3D dssCorrelationID_) && (correlationID !=3D 0xFF= FF)){ - doSyntaxrmSemantics (CodePoint.SYNERRCD_INVALID_CORRELATOR); - } - else { - dssCorrelationID_ =3D nextCorrelationID; - } - dssLength_ -=3D 6; - if ((gdsFormatter & 0x04) =3D=3D 0x04 ) - decryptData (gdsFormatter, oldDssLength); //we have to decrypt dat= a here because - //we need the decrypted = codepoint. If - //Data is very long > 32= 767, we have to - //get all the data first= because decrypt - //piece by piece doesn't= work. - } + dssIsChainedWithDiffID_ =3D false; + dssCorrelationID_ =3D 1; + } + + final int getDdmLength() { + return ddmScalarLen_; + } + + // This is a helper method which shifts the buffered bytes from + // wherever they are in the current buffer to the beginning of + // different buffer (note these buffers could be the same). + // State information is updated as needed after the shift. + private final void shiftBuffer(byte[] destinationBuffer) { + // calculate the size of the data in the current buffer. + int sz =3D count_ - pos_; + + // copy this data to the new buffer starting at position 0. + System.arraycopy(buffer_, pos_, destinationBuffer, 0, sz); + + // update the state information for data in the new buffer. + pos_ =3D 0; + count_ =3D sz; + + // replace the old buffer with the new buffer. + buffer_ =3D destinationBuffer; + } + + // This method makes sure there is enough room in the buffer + // for a certain number of bytes. This method will allocate + // a new buffer if needed and shift the bytes in the current buffer + // to make ensure space is available for a fill. Right now + // this method will shift bytes as needed to make sure there is + // as much room as possible in the buffer before trying to + // do the read. The idea is to try to have space to get as much data = as possible + // if we need to do a read on the socket's stream. + protected final void ensureSpaceInBufferForFill(int desiredSpace) { + // calculate the total unused space in the buffer. + // this includes any space at the end of the buffer and any free + // space at the beginning resulting from bytes already read. + int currentAvailableSpace =3D (buffer_.length - count_) + pos_; + + // check to see if there is enough free space. + if (currentAvailableSpace < desiredSpace) { + + // there is not enough free space so we need more storage. + // we are going to double the buffer unless that happens to st= ill be too small. + // if more than double the buffer is needed, use the smallest = amount over this as possible. + int doubleBufferSize =3D (2 * buffer_.length); + + int minumNewBufferSize =3D (desiredSpace - currentAvailableSpa= ce) + buffer_.length; + int newsz =3D minumNewBufferSize <=3D doubleBufferSize ? doubl= eBufferSize : minumNewBufferSize; + + byte[] newBuffer =3D new byte[newsz]; + + // shift everything from the old buffer to the new buffer + shiftBuffer(newBuffer); + } else { + + // there is enough free space in the buffer but let's make sur= e it is all at the end. + // this is also important because if we are going to do a read= , it would be nice + // to get as much data as possible and making room at the end = if the buffer helps to + // ensure this. + if (pos_ !=3D 0) { + shiftBuffer(buffer_); + } + } + } + + // This method will attempt to read a minimum number of bytes + // from the underlying stream. This method will keep trying to + // read bytes until it has obtained at least the minimum number. + // Now returns the total bytes read for decryption, use to return void. + protected int fill(int minimumBytesNeeded) throws org.apache.derby.cli= ent.am.DisconnectException { + // make sure that there is enough space in the buffer to hold + // the minimum number of bytes needed. + ensureSpaceInBufferForFill(minimumBytesNeeded); + + // read until the minimum number of bytes needed is now in the buf= fer. + // hopefully the read method will return as many bytes as it can. + int totalBytesRead =3D 0; + int actualBytesRead =3D 0; + do { + try { + // oops, we shouldn't expose the agent's input stream here= , collapse this into a read method on the agent + actualBytesRead =3D netAgent_.getInputStream().read(buffer= _, count_, buffer_.length - count_); + } catch (java.io.IOException ioe) { + netAgent_.throwCommunicationsFailure("Reply.fill()", + "InputStream.read()", + ioe.getMessage(), + "*"); + } finally { + if (agent_.loggingEnabled()) { + ((NetLogWriter) netAgent_.logWriter_).traceProtocolFlo= w(buffer_, + count_, + actualBytesRead, + NetLogWriter.TYPE_TRACE_RECEIVE, + "Reply", + "fill", + 2); // tracepoint + } + } + count_ +=3D actualBytesRead; + totalBytesRead +=3D actualBytesRead; + + } while ((totalBytesRead < minimumBytesNeeded) && (actualBytesRead= !=3D -1)); + + if (actualBytesRead =3D=3D -1) { + if (totalBytesRead < minimumBytesNeeded) { + netAgent_.throwCommunicationsFailure("Reply.fill()", + "InputStream.read()", + "insufficient data", + "*"); + } + } + return totalBytesRead; + } + + // Make sure a certain amount of Layer A data is in the buffer. + // The data will be in the buffer after this method is called. + // Now returns the total bytes read for decryption, use to return void. + protected final int ensureALayerDataInBuffer(int desiredDataSize) thro= ws org.apache.derby.client.am.DisconnectException { + int totalBytesRead =3D 0; + // calulate the the number of bytes in the buffer. + int avail =3D count_ - pos_; + + // read more bytes off the network if the data is not in the buffe= r already. + if (avail < desiredDataSize) { + totalBytesRead =3D fill(desiredDataSize - avail); + } + return totalBytesRead; + } + + protected final void ensureBLayerDataInBuffer(int desiredDataSize) thr= ows org.apache.derby.client.am.DisconnectException { + if (dssIsContinued_ && (desiredDataSize > dssLength_)) { + int continueDssHeaderCount =3D + (((desiredDataSize - dssLength_) / 32767) + 1); + ensureALayerDataInBuffer(desiredDataSize + (continueDssHeaderC= ount * 2)); + compressBLayerData(continueDssHeaderCount); + return; + } + ensureALayerDataInBuffer(desiredDataSize); + } + + // this will probably never be called. + // it is included here in the highly unlikely event that a reply object + // exceeds 32K. for opimization purposes, we should consider + // removing this. removing this should be ok since we handle most + // big stuff returned from the server (qrydta's for example) by + // copying out the data into some other storage. any extended dss hea= der + // info will be removed in the copying process. + private final void compressBLayerData(int continueDssHeaderCount) thro= ws org.apache.derby.client.am.DisconnectException { + int tempPos =3D 0; + + // jump to the last continuation header. + for (int i =3D 0; i < continueDssHeaderCount; i++) { + // the first may be less than the size of a full dss + if (i =3D=3D 0) { + // only jump by the number of bytes remaining in the curre= nt dss + tempPos =3D pos_ + dssLength_; + } else { + // all other jumps are for a full continued dss + tempPos +=3D 32767; + } + } + + // for each of the dss headers to remove, + // read out the continuation header and increment the dss length b= y the + // size of the conitnation bytes, then shift the continuation dat= a as needed. + int shiftSize =3D 0; + int bytesToShift =3D 0; + int continueHeaderLength =3D 0; + int newDssLength =3D 0; + for (int i =3D 0; i < continueDssHeaderCount; i++) { + + continueHeaderLength =3D ((buffer_[tempPos] & 0xFF) << 8) + + ((buffer_[tempPos + 1] & 0xFF) << 0); + + if (i =3D=3D 0) { + // if this is the last one (farthest down stream and first= to strip out) + + if ((continueHeaderLength & 0x8000) =3D=3D 0x8000) { + // the last dss header is again continued + continueHeaderLength =3D 32767; + dssIsContinued_ =3D true; + } else { + // the last dss header was not contiued so update cont= inue state flag + dssIsContinued_ =3D false; + } + // the very first shift size is 2 + shiftSize =3D 2; + } else { + // already removed the last header so make sure the chaini= ng flag is on + if ((continueHeaderLength & 0x8000) =3D=3D 0x8000) { + continueHeaderLength =3D 32767; + } else { + // this is a syntax error but not really certain which= one. + // for now pick 0x02 which is Dss header Length does n= ot match the number + // of bytes of data found. + doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_LENGTH_BYTE= _NUMBER_MISMATCH); + } + // increase the shift size by 2 + shiftSize +=3D 2; + } + + // it is a syntax error if the dss continuation is less than o= r equal to two + if (continueHeaderLength <=3D 2) { + doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_CONT_LESS_OR_EQ= UAL_2); + } + + newDssLength +=3D (continueHeaderLength - 2); + + // calculate the number of bytes to shift + if (i !=3D (continueDssHeaderCount - 1)) { + bytesToShift =3D 32767; + } else { + bytesToShift =3D dssLength_; + } + + tempPos -=3D (shiftSize - 1); + // perform the compress + for (int j =3D 0; j < bytesToShift; j++) { + buffer_[tempPos + shiftSize] =3D buffer_[tempPos]; + tempPos--; + } + tempPos +=3D (shiftSize + 1); + } + // reposition the start of the data after the final dss shift. + pos_ =3D tempPos; + dssLength_ =3D dssLength_ + newDssLength; + } + + protected final void readDssHeader() throws org.apache.derby.client.am= .DisconnectException { + int correlationID =3D 0; + int nextCorrelationID =3D 0; + ensureALayerDataInBuffer(6); + + // read out the dss length + dssLength_ =3D + ((buffer_[pos_++] & 0xFF) << 8) + + ((buffer_[pos_++] & 0xFF) << 0); + + // Remember the old dss length for decryption only. + int oldDssLength =3D dssLength_; + + // check for the continuation bit and update length as needed. + if ((dssLength_ & 0x8000) =3D=3D 0x8000) { + dssLength_ =3D 32767; + dssIsContinued_ =3D true; + } else { + dssIsContinued_ =3D false; + } + + if (dssLength_ < 6) { + doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_LESS_THAN_6); + } + + // If the GDS id is not valid, or + // if the reply is not an RPYDSS nor + // a OBJDSS, then throw an exception. + if ((buffer_[pos_++] & 0xFF) !=3D 0xd0) { + doSyntaxrmSemantics(CodePoint.SYNERRCD_CBYTE_NOT_D0); + } + + int gdsFormatter =3D buffer_[pos_++] & 0xFF; + if (((gdsFormatter & 0x02) !=3D 0x02) + && ((gdsFormatter & 0x03) !=3D 0x03) + && ((gdsFormatter & 0x04) !=3D 0x04)) { + doSyntaxrmSemantics(CodePoint.SYNERRCD_FBYTE_NOT_SUPPORTED); + } + + // Determine if the current DSS is chained with the + // next DSS, with the same or different request ID. + if ((gdsFormatter & 0x40) =3D=3D 0x40) { // on indicates struct= ure chained to next structure + if ((gdsFormatter & 0x10) =3D=3D 0x10) { + dssIsChainedWithSameID_ =3D true; + dssIsChainedWithDiffID_ =3D false; + nextCorrelationID =3D dssCorrelationID_; + } else { + dssIsChainedWithSameID_ =3D false; + dssIsChainedWithDiffID_ =3D true; + nextCorrelationID =3D dssCorrelationID_ + 1; + } + } else { + // chaining bit not b'1', make sure DSSFMT bit3 not b'1' + if ((gdsFormatter & 0x10) =3D=3D 0x10) { // Next DSS can not = have same correlator + doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_SAME_NEXT= _CORRELATOR); + } + + // chaining bit not b'1', make sure no error continuation + if ((gdsFormatter & 0x20) =3D=3D 0x20) { // must be 'do not co= ntinue on error' + doSyntaxrmSemantics(CodePoint.SYNERRCD_CHAIN_OFF_ERROR_CON= TINUE); + } =20 + dssIsChainedWithSameID_ =3D false; + dssIsChainedWithDiffID_ =3D false; + nextCorrelationID =3D 1; + } =20 + correlationID =3D + ((buffer_[pos_++] & 0xFF) << 8) + + ((buffer_[pos_++] & 0xFF) << 0); + + // corrid must be the one expected or a -1 which gets returned in = some error cases. + if ((correlationID !=3D dssCorrelationID_) && (correlationID !=3D = 0xFFFF)) { + doSyntaxrmSemantics(CodePoint.SYNERRCD_INVALID_CORRELATOR); + } else { + dssCorrelationID_ =3D nextCorrelationID; + } + dssLength_ -=3D 6; + if ((gdsFormatter & 0x04) =3D=3D 0x04) { + decryptData(gdsFormatter, oldDssLength); //we have to decrypt= data here because + } + //we need the decrypted codepoint. If + //Data is very long > 32767, we have to + //get all the data first because decrypt + //piece by piece doesn't work. + } =20 - private final void decryptData(int gdsFormatter, int oldDssLength) throw= s org.apache.derby.client.am.DisconnectException - { + + private final void decryptData(int gdsFormatter, int oldDssLength) thr= ows org.apache.derby.client.am.DisconnectException { boolean readHeader; =20 - if(dssLength_ =3D=3D 32761) { - ByteArrayOutputStream baos; - int copySize =3D 0; + if (dssLength_ =3D=3D 32761) { + ByteArrayOutputStream baos; + int copySize =3D 0; + + baos =3D new ByteArrayOutputStream(); + + // set the amount to read for the first segment + copySize =3D dssLength_; // note: has already been adjusted fo= r headers + + do { + // determine if a continuation header needs to be read aft= er the data + if (dssIsContinued_) { + readHeader =3D true; + } else { + readHeader =3D false; + } + + // read the segment + ensureALayerDataInBuffer(copySize); + adjustLengths(copySize); + baos.write(buffer_, pos_, copySize); + pos_ +=3D copySize; + + // read the continuation header, if necessary + if (readHeader) { + readDSSContinuationHeader(); + } + + copySize =3D dssLength_; + } while (readHeader =3D=3D true); + byte[] cipherBytes =3D baos.toByteArray(); + byte[] clearedByte =3D null; + try { + clearedByte =3D netAgent_.netConnection_.getEncryptionMana= ger().decryptData(cipherBytes, + NetConfiguration.SECMEC_EUSRIDPWD, + netAgent_.netConnection_.getTargetPublicKey(), + netAgent_.netConnection_.getTargetPublicKey()); + } catch (SqlException e) { + //throw new SqlException (agent_.logWriter_, "error in dec= rypting data"); + } + + //The decrypted data is for one codepoint only. We need to sav= e the data follows this codepoint + longBufferForDecryption_ =3D new byte[buffer_.length - pos_]; + longPosForDecryption_ =3D 0; + count_ =3D count_ - pos_; + longCountForDecryption_ =3D count_; + System.arraycopy(buffer_, pos_, longBufferForDecryption_, 0, b= uffer_.length - pos_); + + //copy the clear data to buffer_ + if (clearedByte.length >=3D 32767) { + System.arraycopy(clearedByte, 0, buffer_, 0, 32767); + } else { + System.arraycopy(clearedByte, 0, buffer_, 0, clearedByte.l= ength); + } + + pos_ =3D 0; + dssLength_ =3D buffer_.length; =20 - baos =3D new ByteArrayOutputStream (); + int lobLength =3D 0; + if (clearedByte.length > 32767) { //for extended length, leng= th is the 4 bytes that follow codepoint + lobLength =3D ((clearedByte[4] & 0xFF) << 24) + + ((clearedByte[5] & 0xFF) << 16) + + ((clearedByte[6] & 0xFF) << 8) + + ((clearedByte[7] & 0xFF) << 0); + longValueForDecryption_ =3D new byte[lobLength]; + System.arraycopy(clearedByte, 8, longValueForDecryption_, = 0, clearedByte.length - 8); + } else { + lobLength =3D ((clearedByte[0] & 0xFF) << 8) + + ((clearedByte[1] & 0xFF) << 0); + longValueForDecryption_ =3D new byte[lobLength - 4]; + System.arraycopy(clearedByte, 4, longValueForDecryption_, = 0, clearedByte.length - 4); + } + } else { + int bytesRead =3D 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 + { + ensuredLengthForDecryption_ =3D true; + } + byte[] encryptedByte =3D new byte[dssLength_]; + System.arraycopy(buffer_, pos_, encryptedByte, 0, dssLength_); + byte[] array1 =3D new byte[pos_]; + System.arraycopy(buffer_, 0, array1, 0, pos_); //save the dat= a before encrypted data in array1 + byte[] array3 =3D new byte[buffer_.length - dssLength_ - pos_]; + System.arraycopy(buffer_, pos_ + dssLength_, array3, 0, buffer= _=2Elength - dssLength_ - pos_); //save the data follows encrypted data in = array3 + byte[] clearedByte =3D null; + try { + clearedByte =3D netAgent_.netConnection_.getEncryptionMana= ger().decryptData(encryptedByte, + NetConfiguration.SECMEC_EUSRIDPWD, + netAgent_.netConnection_.getTargetPublicKey(), + netAgent_.netConnection_.getTargetPublicKey()); + } catch (SqlException e) { + //throw new SqlException (agent_.logWriter_, "error in dec= rypting data"); + } + dssLength_ -=3D (encryptedByte.length - clearedByte.length); + byte[] buffer =3D new byte[array1.length + clearedByte.length = + array3.length]; + System.arraycopy(array1, 0, buffer, 0, array1.length); + System.arraycopy(clearedByte, 0, buffer, array1.length, cleare= dByte.length); + System.arraycopy(array3, 0, buffer, array1.length + clearedByt= e=2Elength, array3.length); + buffer_ =3D buffer; + int oldCount =3D count_; + count_ =3D count_ - (encryptedByte.length - clearedByte.length= ); + if (((clearedByte[2] & 0xff) << 8) + ((clearedByte[3] & 0xff) = << 0) =3D=3D 0x146c) { + int firstLobLength =3D ((clearedByte[0] & 0xFF) << 8) + + ((clearedByte[1] & 0xFF) << 0); + + boolean flag =3D false; + if (gdsFormatter =3D=3D 0x54) { + flag =3D true; + } + if (flag) { + if (oldCount - oldDssLength < 6) { + int totalBytesRead =3D fill(6); //sometimes the 2n= d EXTDTA doesn't come back, need to fetch again to get it + if (totalBytesRead > 0) { + longBufferForDecryption_ =3D new byte[totalByt= esRead]; + longPosForDecryption_ =3D 0; + System.arraycopy(buffer_, pos_ + firstLobLengt= h, longBufferForDecryption_, 0, + totalBytesRead); + } + + } else { + longBufferForDecryption_ =3D new byte[count_ - pos= _ - firstLobLength]; + longPosForDecryption_ =3D 0; + System.arraycopy(buffer_, pos_ + firstLobLength, l= ongBufferForDecryption_, 0, + longBufferForDecryption_.length); + + } + } //end if(flag) + int lobLength =3D ((clearedByte[0] & 0xFF) << 8) + + ((clearedByte[1] & 0xFF) << 0) - 4; + + longValueForDecryption_ =3D new byte[lobLength]; + + System.arraycopy(clearedByte, 4, longValueForDecryption_, = 0, clearedByte.length - 4); //copy the decrypted lob value (excluded lengt= h an dcodepoint) to longValue_ + } else if (((clearedByte[2] & 0xff) << 8) + ((clearedByte[3] &= 0xff) << 0) =3D=3D 0x241B) { + int length =3D ((clearedByte[0] & 0xFF) << 8) + + ((clearedByte[1] & 0xFF) << 0); + boolean noData =3D false; + if (clearedByte[4] =3D=3D -1 && clearedByte[5] =3D=3D -1) { + noData =3D true; //there is no data, no need to do the= copy + } + if (!noData) { + if (length =3D=3D 32776) { + length =3D ((clearedByte[4] & 0xFF) << 24) + + ((clearedByte[5] & 0xFF) << 16) + + ((clearedByte[6] & 0xFF) << 8) + + ((clearedByte[7] & 0xFF) << 0); + longValueForDecryption_ =3D new byte[length]; + System.arraycopy(clearedByte, 8, longValueForDecry= ption_, 0, + clearedByte.length - 8); + longCountForDecryption_ =3D count_ - (pos_ + lengt= h + 8); + longBufferForDecryption_ =3D new byte[buffer_.leng= th - pos_ - length - 8]; + System.arraycopy(buffer_, pos_ + length + 8, longB= ufferForDecryption_, 0, + longBufferForDecryption_.length); + + } else { + longPosForDecryption_ =3D 0; + longCountForDecryption_ =3D count_ - (pos_ + lengt= h); + longBufferForDecryption_ =3D new byte[buffer_.leng= th - pos_ - length]; + System.arraycopy(buffer_, pos_ + length, longBuffe= rForDecryption_, 0, + longBufferForDecryption_.length); =20 - // set the amount to read for the first segment - copySize =3D dssLength_; // note: has already been adjusted for = headers + longValueForDecryption_ =3D new byte[length - 4]; =20 - do { + System.arraycopy(clearedByte, 4, longValueForDecry= ption_, 0, + clearedByte.length - 4); + } + } + } + } + } + + + final int readUnsignedShort() throws org.apache.derby.client.am.Discon= nectException { + // 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); + } + + final short readShort() throws org.apache.derby.client.am.DisconnectEx= ception { + // should we be checking dss lengths and ddmScalarLengths here + ensureBLayerDataInBuffer(2); + adjustLengths(2); + short s =3D SignedBinary.getShort(buffer_, pos_); + + pos_ +=3D 2; + + return s; + } + + final int readInt() throws org.apache.derby.client.am.DisconnectExcept= ion { + // should we be checking dss lengths and ddmScalarLengths here + ensureBLayerDataInBuffer(4); + adjustLengths(4); + int i =3D SignedBinary.getInt(buffer_, pos_); + pos_ +=3D 4; + + return i; + } + + final void readIntArray(int[] array) throws org.apache.derby.client.am= .DisconnectException { + ensureBLayerDataInBuffer(array.length * 4); + adjustLengths(array.length * 4); + + for (int i =3D 0; i < array.length; i++) { + array[i] =3D SignedBinary.getInt(buffer_, pos_); + pos_ +=3D 4; + } + } + + + final long readLong() throws org.apache.derby.client.am.DisconnectExce= ption { + // should we be checking dss lengths and ddmScalarLengths here + ensureBLayerDataInBuffer(8); + adjustLengths(8); + long l =3D SignedBinary.getLong(buffer_, pos_); + + pos_ +=3D 8; + + return l; + } + + + final int[] readUnsignedShortList() throws org.apache.derby.client.am.= DisconnectException { + int len =3D ddmScalarLen_; + ensureBLayerDataInBuffer(len); + adjustLengths(len); + + int count =3D len / 2; + int[] list =3D new int[count]; + + for (int i =3D 0; i < count; i++) { + list[i] =3D ((buffer_[pos_++] & 0xff) << 8) + + ((buffer_[pos_++] & 0xff) << 0); + } + + return list; + } + + final int readUnsignedByte() throws org.apache.derby.client.am.Disconn= ectException { + ensureBLayerDataInBuffer(1); + adjustLengths(1); + return (buffer_[pos_++] & 0xff); + } + + final byte readByte() throws org.apache.derby.client.am.DisconnectExce= ption { + ensureBLayerDataInBuffer(1); + adjustLengths(1); + return (byte) (buffer_[pos_++] & 0xff); + } + + final boolean readBoolean() throws org.apache.derby.client.am.Disconne= ctException { + ensureBLayerDataInBuffer(1); + adjustLengths(1); + return buffer_[pos_++] !=3D 0; + } + + final String readString(int length) throws org.apache.derby.client.am.= DisconnectException { + ensureBLayerDataInBuffer(length); + adjustLengths(length); + + String result =3D ccsidManager_.convertToUCS2(buffer_, pos_, lengt= h); + pos_ +=3D length; + return result; + } + + final String readString(int length, String encoding) throws org.apache= .derby.client.am.DisconnectException { + ensureBLayerDataInBuffer(length); + adjustLengths(length); + String s =3D null; + + try { + s =3D new String(buffer_, pos_, length, encoding); + } catch (java.io.UnsupportedEncodingException e) { + agent_.accumulateChainBreakingReadExceptionAndThrow(new org.ap= ache.derby.client.am.DisconnectException(e, + agent_, + "encoding not supported!!")); + } + + pos_ +=3D length; + return s; + } + + final String readString() throws org.apache.derby.client.am.Disconnect= Exception { + int len =3D ddmScalarLen_; + ensureBLayerDataInBuffer(len); + adjustLengths(len); + String result =3D ccsidManager_.convertToUCS2(buffer_, pos_, len); + pos_ +=3D len; + return result; + } + + final byte[] readBytes(int length) throws org.apache.derby.client.am.D= isconnectException { + ensureBLayerDataInBuffer(length); + adjustLengths(length); + + byte[] b =3D new byte[length]; + System.arraycopy(buffer_, pos_, b, 0, length); + pos_ +=3D length; + return b; + } + + final byte[] readBytes() throws org.apache.derby.client.am.DisconnectE= xception { + int len =3D ddmScalarLen_; + ensureBLayerDataInBuffer(len); + adjustLengths(len); + + byte[] b =3D new byte[len]; + System.arraycopy(buffer_, pos_, b, 0, len); + pos_ +=3D len; + return b; + } + + final byte[] readLDBytes() throws org.apache.derby.client.am.Disconnec= tException { + ensureBLayerDataInBuffer(2); + int len =3D ((buffer_[pos_++] & 0xff) << 8) + ((buffer_[pos_++] & = 0xff) << 0); + + if (len =3D=3D 0) { + adjustLengths(2); + return null; + } + + ensureBLayerDataInBuffer(len); + adjustLengths(len + 2); + + byte[] b =3D new byte[len]; + System.arraycopy(buffer_, pos_, b, 0, len); + pos_ +=3D len; + return b; + } + + final void skipBytes(int length) throws org.apache.derby.client.am.Dis= connectException { + ensureBLayerDataInBuffer(length); + adjustLengths(length); + pos_ +=3D length; + } + + final void skipBytes() throws org.apache.derby.client.am.DisconnectExc= eption { + int len =3D ddmScalarLen_; + ensureBLayerDataInBuffer(len); + adjustLengths(len); + pos_ +=3D len; + } + + // This will be the new and improved getData that handles all QRYDTA/E= XTDTA + // Returns the stream so that the caller can cache it + final ByteArrayOutputStream getData(ByteArrayOutputStream existingBuff= er) throws org.apache.derby.client.am.DisconnectException { + boolean readHeader; + int copySize; + ByteArrayOutputStream baos; + + // note: an empty baos can yield an allocated and empty byte[] + if (existingBuffer !=3D null) { + baos =3D existingBuffer; + } else { + if (ddmScalarLen_ !=3D -1) { + // allocate a stream based on a known amount of data + baos =3D new ByteArrayOutputStream(ddmScalarLen_); + } else { + // allocate a stream to hold an unknown amount of data + baos =3D new ByteArrayOutputStream(); + //isLengthAndNullabilityUnknown =3D true; + } + } + + // set the amount to read for the first segment + copySize =3D dssLength_; // note: has already been adjusted for he= aders + + do { // determine if a continuation header needs to be read after t= he data - if (dssIsContinued_) - readHeader =3D true; - else - readHeader =3D false; + if (dssIsContinued_) { + readHeader =3D true; + } else { + readHeader =3D false; + } =20 // read the segment - ensureALayerDataInBuffer (copySize); - adjustLengths (copySize); - baos.write (buffer_, pos_, copySize); + ensureALayerDataInBuffer(copySize); + adjustLengths(copySize); + baos.write(buffer_, pos_, copySize); pos_ +=3D copySize; =20 // read the continuation header, if necessary - if (readHeader) - readDSSContinuationHeader (); + if (readHeader) { + readDSSContinuationHeader(); + } =20 copySize =3D dssLength_; - } - while (readHeader =3D=3D true); - byte[] cipherBytes =3D baos.toByteArray(); - byte[] clearedByte =3D null; - try{ - clearedByte =3D netAgent_.netConnection_.getEncryptionManager(= )=2EdecryptData( - cipherBytes, - NetConfiguration.SECMEC_EUSRIDPWD, - netAgent_.netConnection_.getTargetPublicKey(), - netAgent_.netConnection_.getTargetPublicKey()); - } - catch (SqlException e) - { - //throw new SqlException (agent_.logWriter_, "error in decrypt= ing data"); - } - - //The decrypted data is for one codepoint only. We need to save = the data follows this codepoint - longBufferForDecryption_ =3D new byte[buffer_.length - pos_]; - longPosForDecryption_ =3D 0; - count_ =3D count_ - pos_; - longCountForDecryption_ =3D count_; - System.arraycopy(buffer_,pos_,longBufferForDecryption_,0,buffer_= .length - pos_); - - //copy the clear data to buffer_ - if (clearedByte.length >=3D32767) - System.arraycopy(clearedByte,0,buffer_,0,32767); - else - System.arraycopy(clearedByte,0,buffer_,0,clearedByte.length); - - pos_ =3D 0; - dssLength_ =3D buffer_.length; - - int lobLength =3D 0; - if(clearedByte.length > 32767) { //for extended length, length = is the 4 bytes that follow codepoint - lobLength =3D ( (clearedByte[4] & 0xFF) << 24) + - ( (clearedByte[5] & 0xFF) << 16) + - ( (clearedByte[6] & 0xFF) << 8) + - ( (clearedByte[7] & 0xFF) << 0); - longValueForDecryption_ =3D new byte[lobLength]; - System.arraycopy (clearedByte, 8, longValueForDecryption_, 0, = clearedByte.length-8); - } - else { - lobLength =3D ( (clearedByte[0] & 0xFF) << 8) + - ( (clearedByte[1] & 0xFF) << 0); - longValueForDecryption_ =3D new byte[lobLength-4]; - System.arraycopy (clearedByte, 4, longValueForDecryption_, 0, = clearedByte.length-4); - } - } - - else{ - int bytesRead =3D ensureALayerDataInBuffer (dssLength_); //we nee= d 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 - ensuredLengthForDecryption_ =3D true; - byte[] encryptedByte =3D new byte[dssLength_]; - System.arraycopy(buffer_,pos_,encryptedByte,0,dssLength_); - byte[] array1 =3D new byte[pos_]; - System.arraycopy(buffer_,0,array1,0,pos_); //save the data before= encrypted data in array1 - byte[] array3 =3D new byte[buffer_.length - dssLength_ - pos_]; - System.arraycopy(buffer_,pos_+dssLength_,array3,0,buffer_.length -= dssLength_ - pos_); //save the data follows encrypted data in array3 - byte[] clearedByte =3D null; - try{ - clearedByte =3D netAgent_.netConnection_.getEncryptionManager().= decryptData( - encryptedByte, - NetConfiguration.SECMEC_EUSRIDPWD, - netAgent_.netConnection_.getTargetPublicKey(), - netAgent_.netConnection_.getTargetPublicKey()); + } while (readHeader =3D=3D true); + + return baos; + } + + // reads a DSS continuation header + // prereq: pos_ is positioned on the first byte of the two-byte header + // post: dssIsContinued_ is set to true if the continuation bit is o= n, false otherwise + // dssLength_ is set to DssConstants.MAX_DSS_LEN - 2 (don't co= unt the header for the next read) + // helper method for getEXTDTAData + protected final void readDSSContinuationHeader() throws org.apache.der= by.client.am.DisconnectException { + ensureALayerDataInBuffer(2); + + dssLength_ =3D + ((buffer_[pos_++] & 0xFF) << 8) + + ((buffer_[pos_++] & 0xFF) << 0); + + if ((dssLength_ & 0x8000) =3D=3D 0x8000) { + dssLength_ =3D DssConstants.MAX_DSS_LEN; + dssIsContinued_ =3D true; + } else { + dssIsContinued_ =3D false; } - catch (SqlException e) - { - //throw new SqlException (agent_.logWriter_, "error in decryptin= g data"); + // it is a syntax error if the dss continuation header length + // is less than or equal to two + if (dssLength_ <=3D 2) { + doSyntaxrmSemantics(CodePoint.SYNERRCD_DSS_CONT_LESS_OR_EQUAL_= 2); } - dssLength_ -=3D (encryptedByte.length - clearedByte.length); - byte[] buffer =3D new byte[array1.length + clearedByte.length + ar= ray3.length]; - System.arraycopy(array1,0,buffer,0,array1.length); - System.arraycopy(clearedByte,0,buffer,array1.length,clearedByte.le= ngth); - System.arraycopy(array3,0,buffer,array1.length+clearedByte.length,= array3.length); - buffer_ =3D buffer; - int oldCount =3D count_; - count_ =3D count_ - (encryptedByte.length - clearedByte.length); - if (((clearedByte[2]& 0xff) << 8) + ((clearedByte[3] & 0xff) << 0)= =3D=3D 0x146c) { - int firstLobLength =3D ( (clearedByte[0] & 0xFF) << 8) + - ( (clearedByte[1] & 0xFF) << 0); - - boolean flag =3D false; - if (gdsFormatter =3D=3D 0x54) - flag =3D true; - if(flag){ - if (oldCount - oldDssLength < 6) { - int totalBytesRead =3D fill(6); //sometimes the 2nd EXTDTA = doesn't come back, need to fetch again to get it - if (totalBytesRead > 0) { - longBufferForDecryption_ =3D new byte[totalBytesRead]; - longPosForDecryption_ =3D 0; - System.arraycopy(buffer_, pos_ + firstLobLength, longBuff= erForDecryption_, 0, - totalBytesRead); - } - - } - else { - longBufferForDecryption_ =3D new byte[count_ - pos_ - first= LobLength]; - longPosForDecryption_ =3D 0; - System.arraycopy(buffer_, pos_ + firstLobLength, longBuffer= ForDecryption_, 0, - longBufferForDecryption_.length); =20 - } - } //end if(flag) - int lobLength =3D ( (clearedByte[0] & 0xFF) << 8) + - ( (clearedByte[1] & 0xFF) << 0) - 4; - - longValueForDecryption_ =3D new byte[lobLength]; - - System.arraycopy (clearedByte, 4, longValueForDecryption_, 0, cle= aredByte.length - 4); //copy the decrypted lob value (excluded length an d= codepoint) to longValue_ - } - else if (((clearedByte[2]& 0xff) << 8) + ((clearedByte[3] & 0xff) = << 0) =3D=3D 0x241B){ - int length =3D ( (clearedByte[0] & 0xFF) << 8) + - ( (clearedByte[1] & 0xFF) << 0); - boolean noData =3D false; - if (clearedByte[4] =3D=3D -1 && clearedByte[5] =3D=3D -1) - noData =3D true; //there is no data, no need to do the copy - if (!noData) { - if (length =3D=3D 32776) { - length =3D ( (clearedByte[4] & 0xFF) << 24) + - ( (clearedByte[5] & 0xFF) << 16) + - ( (clearedByte[6] & 0xFF) << 8) + - ( (clearedByte[7] & 0xFF) << 0); - longValueForDecryption_ =3D new byte[length]; - System.arraycopy (clearedByte, 8, longValueForDecryption_,= 0, - clearedByte.length - 8); - longCountForDecryption_ =3D count_ - (pos_ + length + 8); - longBufferForDecryption_ =3D new byte[buffer_.length - pos= _ - length - 8]; - System.arraycopy(buffer_, pos_ + length + 8, longBufferFor= Decryption_, 0, - longBufferForDecryption_.length); - - } - else { - longPosForDecryption_ =3D 0; - longCountForDecryption_ =3D count_ - (pos_ + length); - longBufferForDecryption_ =3D new byte[buffer_.length - pos= _ - length]; - System.arraycopy (buffer_, pos_ + length, longBufferForDec= ryption_, 0, - longBufferForDecryption_.length); - - longValueForDecryption_ =3D new byte[length - 4]; - - System.arraycopy (clearedByte, 4, longValueForDecryption_,= 0, - clearedByte.length - 4); - } - } - } - } - } - - - final int readUnsignedShort () throws org.apache.derby.client.am.Disconn= ectException - { - // should we be checking dss lengths and ddmScalarLengths here=20 - // if yes, i am not sure this is the correct place if we should be che= cking=20 - ensureBLayerDataInBuffer (2); - adjustLengths (2); - return ((buffer_[pos_++] & 0xff) << 8) + - ((buffer_[pos_++] & 0xff) << 0); - } - - final short readShort () throws org.apache.derby.client.am.DisconnectExc= eption - { - // should we be checking dss lengths and ddmScalarLengths here=20 - ensureBLayerDataInBuffer (2); - adjustLengths (2); - short s =3D SignedBinary.getShort (buffer_, pos_); - - pos_ +=3D 2; - - return s; - } - - final int readInt () throws org.apache.derby.client.am.DisconnectExcepti= on - { - // should we be checking dss lengths and ddmScalarLengths here=20 - ensureBLayerDataInBuffer (4); - adjustLengths (4); - int i =3D SignedBinary.getInt (buffer_, pos_); - pos_ +=3D 4; - - return i; - } - - final void readIntArray (int[] array) throws org.apache.derby.client.am.= DisconnectException - { - ensureBLayerDataInBuffer (array.length * 4); - adjustLengths (array.length * 4); - - for (int i =3D 0; i < array.length; i++) { - array[i] =3D SignedBinary.getInt (buffer_, pos_); - pos_ +=3D 4; - } - } - - - final long readLong () throws org.apache.derby.client.am.DisconnectExcep= tion - { - // should we be checking dss lengths and ddmScalarLengths here - ensureBLayerDataInBuffer (8); - adjustLengths (8); - long l =3D SignedBinary.getLong (buffer_, pos_); - - pos_ +=3D 8; - - return l; - } - - - final int [] readUnsignedShortList() throws org.apache.derby.client.am.= DisconnectException - { - int len =3D ddmScalarLen_; - ensureBLayerDataInBuffer (len); - adjustLengths (len); - - int count =3D len/2; - int[] list =3D new int[count]; - - for (int i=3D0; i < count; i++) { - list[i] =3D ((buffer_[pos_++] & 0xff) << 8) + - ((buffer_[pos_++] & 0xff) << 0); - } - - return list; - } - - final int readUnsignedByte () throws org.apache.derby.client.am.Disconne= ctException - { - ensureBLayerDataInBuffer (1); - adjustLengths (1); - return (buffer_[pos_++] & 0xff); - } - - final byte readByte () throws org.apache.derby.client.am.DisconnectExcep= tion - { - ensureBLayerDataInBuffer (1); - adjustLengths (1); - return (byte) (buffer_[pos_++] & 0xff); - } - - final boolean readBoolean () throws org.apache.derby.client.am.Disconnec= tException - { - ensureBLayerDataInBuffer (1); - adjustLengths (1); - return buffer_[pos_++] !=3D 0; - } - - final String readString (int length) throws org.apache.derby.client.am.D= isconnectException - { - ensureBLayerDataInBuffer (length); - adjustLengths (length); - - String result =3D ccsidManager_.convertToUCS2 (buffer_, pos_, length); - pos_ +=3D length; - return result; - } - - final String readString (int length, String encoding) throws org.apache.= derby.client.am.DisconnectException - { - ensureBLayerDataInBuffer (length); - adjustLengths (length); - String s =3D null; - - try { - s =3D new String (buffer_, pos_, length, encoding); - } - catch (java.io.UnsupportedEncodingException e) { - agent_.accumulateChainBreakingReadExceptionAndThrow ( - new org.apache.derby.client.am.DisconnectException ( - e, - agent_, - "encoding not supported!!")); - } - - pos_ +=3D length; - return s; - } - - final String readString () throws org.apache.derby.client.am.DisconnectE= xception - { - int len =3D ddmScalarLen_; - ensureBLayerDataInBuffer (len); - adjustLengths (len); - String result =3D ccsidManager_.convertToUCS2 (buffer_, pos_, len); - pos_ +=3D len; - return result; - } - - final byte[] readBytes (int length) throws org.apache.derby.client.am.Di= sconnectException - { - ensureBLayerDataInBuffer (length); - adjustLengths (length); - - byte[] b =3D new byte[length]; - System.arraycopy (buffer_, pos_, b, 0, length); - pos_ +=3D length; - return b; - } - - final byte[] readBytes () throws org.apache.derby.client.am.DisconnectEx= ception - { - int len =3D ddmScalarLen_; - ensureBLayerDataInBuffer (len); - adjustLengths (len); - - byte[] b =3D new byte[len]; - System.arraycopy (buffer_, pos_, b, 0, len); - pos_ +=3D len; - return b; - } - - final byte[] readLDBytes () throws org.apache.derby.client.am.Disconnect= Exception - { - ensureBLayerDataInBuffer (2); - int len =3D ((buffer_[pos_++] & 0xff) << 8) + ((buffer_[pos_++] & 0xff= ) << 0); - - if (len =3D=3D 0) { - adjustLengths (2); - return null; - } - - ensureBLayerDataInBuffer (len); - adjustLengths (len + 2); - - byte [] b =3D new byte[len]; - System.arraycopy (buffer_, pos_, b, 0, len); - pos_ +=3D len; - return b; - } - - final void skipBytes (int length) throws org.apache.derby.client.am.Disc= onnectException - { - ensureBLayerDataInBuffer (length); - adjustLengths (length); - pos_ +=3D length; - } - - final void skipBytes () throws org.apache.derby.client.am.DisconnectExce= ption - { - int len =3D ddmScalarLen_; - ensureBLayerDataInBuffer (len); - adjustLengths (len); - pos_ +=3D len; - } - - // This will be the new and improved getData that handles all QRYDTA/EXT= DTA - // Returns the stream so that the caller can cache it - final ByteArrayOutputStream getData (ByteArrayOutputStream existingBuffe= r) throws org.apache.derby.client.am.DisconnectException - { - boolean readHeader; - int copySize; - ByteArrayOutputStream baos; - - // note: an empty baos can yield an allocated and empty byte[] - if (existingBuffer !=3D null) - baos =3D existingBuffer; - else { - if (ddmScalarLen_ !=3D -1) { - // allocate a stream based on a known amount of data - baos =3D new ByteArrayOutputStream (ddmScalarLen_); - } - else { - // allocate a stream to hold an unknown amount of data - baos =3D new ByteArrayOutputStream (); - //isLengthAndNullabilityUnknown =3D true; - } - } - - // set the amount to read for the first segment - copySize =3D dssLength_; // note: has already been adjusted for headers - - do { - // determine if a continuation header needs to be read after the data - if (dssIsContinued_) - readHeader =3D true; - else - readHeader =3D false; - - // read the segment - ensureALayerDataInBuffer (copySize); - adjustLengths (copySize); - baos.write (buffer_, pos_, copySize); - pos_ +=3D copySize; - - // read the continuation header, if necessary - if (readHeader) - readDSSContinuationHeader (); - - copySize =3D dssLength_; - } - while (readHeader =3D=3D true); - - return baos; - } - - // reads a DSS continuation header - // prereq: pos_ is positioned on the first byte of the two-byte header - // post: dssIsContinued_ is set to true if the continuation bit is on,= false otherwise - // dssLength_ is set to DssConstants.MAX_DSS_LEN - 2 (don't coun= t the header for the next read) - // helper method for getEXTDTAData - protected final void readDSSContinuationHeader () throws org.apache.derb= y=2Eclient.am.DisconnectException - { - ensureALayerDataInBuffer(2); - - dssLength_ =3D - ((buffer_[pos_++]&0xFF) << 8) + - ((buffer_[pos_++]&0xFF) << 0); - - if ((dssLength_ & 0x8000) =3D=3D 0x8000) { - dssLength_ =3D DssConstants.MAX_DSS_LEN; - dssIsContinued_ =3D true; - } - else { - dssIsContinued_ =3D false; - } - // it is a syntax error if the dss continuation header length - // is less than or equal to two - if (dssLength_ <=3D 2) { - doSyntaxrmSemantics (CodePoint.SYNERRCD_DSS_CONT_LESS_OR_EQUAL_2); - } - - dssLength_ -=3D 2; // avoid consuming the DSS cont header - } - - - // As part of parsing the reply, the client can detect that the - // data sent from the target agent does not structurally - // conform to the requirements of the DDM architecture. These are - // the same checks performed by the target server on the messages - // it receives from the protocolj code. Server side detected errors - // result in a SYNTAXRM being returned from the AS. According to the - // DDM manual, parsing of the DSS is terminated when the error is - // detected. The Syntax Error Code, SYNERRCD, describes the various err= ors. - // - // Note: Not all of these may be valid at the client. See descriptions = for - // which ones make sense for client side errors/checks. - // Syntax Error Code Description of Error - // ----------------- -------------------- - // 0x01 Dss header Length is less than 6. - // 0x02 Dss header Length does not match t= he - // number of bytes of data found. - // 0x03 Dss header C-byte not D0. - // 0x04 Dss header f-bytes either not - // recognized or not supported. - // 0x05 DSS continuation specified but not= found. - // For example, DSS continuation is s= pecified - // on the last DSS, and the SNA LU 6.= 2 communication - // facility returned the SEND indicat= or. - // 0x06 DSS chaining specified but no DSS = found. - // For example, DSS chaining is speci= fied - // on the last DSS, and the SNA LU 6.= 2 communication - // facility returned the SEND indicat= or. - // 0x07 Object length less than four. For= example, - // a command parameter's length is sp= ecified - // as two, or a command's length is s= pecified as three. - // 0x08 Object length does not match the n= umber of bytes of data - // found. For example, a RQSDSS with= a length of 150 - // contains a command whose length is= 125 or a SRVDGN parameter - // specifies a length of 200 but ther= e are only 50 - // bytes left in the DSS. - // 0x09 Object length greater than maximum= allowed. - // For example, a RECCNT parameter sp= ecifies a - // length of ten, but the parameter i= s defined - // to have a maximum length of eight. - // 0x0A Object length less than the minimu= m required. - // For example, a SVRCOD parameter sp= ecifies a - // length of five, but the parameter = is defined - // to have a fixed length of six. - // 0x0B Object length not allowed. For ex= ample, - // a FILEXDPT parameter is specified = with a length of - // 11, but this would indicate that o= nly half of the hours - // field is present instead of the co= mplete hours field. - // 0x0C Incorrect large object extended le= ngth field (see - // description of DSS). For example,= an extended - // length field is present, but it is= only three bytes - // long when it is defined to be a mu= ltiple of two bytes. - // 0x0D Object code point index not suppor= ted. - // For example, a code point of 8032 = is encountered - // but x'8' is a reserved code point = index. - // 0x0E Required object not found. For ex= ample, a CLEAR - // command does not have a filnam par= ameter present, - // or a MODREC command is not followe= d by a RECORD - // command data object. - // 0x0F Too many command data objects sent= . For example, - // a MODREC command is followed by tw= o RECORD command - // command data objects, or a DECREC = command is followed - // by RECORD object. - // 0x10 Mutually exclusive objects present. - // For example, a CRTDIRF command spe= cifies both - // a DCLNAM and FILNAM parameters. - // 0x11 Too few command data objects sent. - // For example, an INSRECEF command t= hat - // specified RECCNT95) is followed by= only - // 4 RECORD command data objects. - // 0x12 Duplicate object present. - // For example, a LSTFAT command has = tow FILNAM - // parameters specified. - // 0x13 Invalid request correlator specifi= ed. - // Use PRCCNVRM with PRCCNVDC of 04 o= r 05 instead - // of this error code. This error co= de is being retained - // for compatibility with Level 1 of = the architecture. - // 0x14 Required value not found. - // 0x15 Reserved value not allowed. For e= xample, - // a INSRECEF command specified a REC= CNT(0) parameter. - // 0x16 DSS continuation less than or equa= l to two. - // For example, the length bytes of t= he DSS continuation - // have the value of one. - // 0x17 Objects not in required order. Fo= r example, a RECAL - // object contains a RECORD object fo= llowed by a RECNBR - // object with is not in the defined = order. - // 0x18 DSS chaining byt not b'1', but DSS= FMT bit3 set to b'1'. - // 0x19 Previous DSS indicated current DSS= has the same - // request correlator, but the reques= t correlators are - // not the same. - // 0x1A DSS cahining bit not b'1', but err= or continuation requested. - // 0x1B Mutually exclusive parameter value= s not specified. - // For example, an OPEN command speci= fied PRPSHD(TRUE) - // and FILSHR(READER). - // 0x1D Code point not valid command. For= example, the first - // code point in RQSDSS either is not= in the dictionary - // or is not a code point for a comma= nd. - // - // When the client detects these errors, it will be handled as if a SYNT= AXRM is returned - // from the server. In this SYNTAXRM case, PROTOCOL architects an SQLST= ATE of 58008 or 58009. - // - // Messages - // SQLSTATE : 58009 - // Execution failed due to a distribution protocol error that caused= deallocation of the conversation. - // SQLCODE : -30020 - // Execution failed because of a Distributed Protocol - // Error that will affect the successful execution of subsequent - // commands and SQL statements: Reason Code . - // Some possible reason codes include: - // 121C Indicates that the user is not authorized to perform the re= quested command. - // 1232 The command could not be completed because of a permanent e= rror. - // In most cases, the server will be in the process of an abend. - // 220A The target server has received an invalid data description. - // If a user SQLDA is specified, ensure that the fields are - // initialized correctly. Also, ensure that the length does not - // exceed the maximum allowed length for the data type being us= ed. - // - // The command or statement cannot be processed. The current - // transaction is rolled back and the application is disconnect= ed - // from the remote database. - final void doSyntaxrmSemantics (int syntaxErrorCode) throws org.apache.d= erby.client.am.DisconnectException - { - agent_.accumulateChainBreakingReadExceptionAndThrow ( - new org.apache.derby.client.am.DisconnectException ( - agent_, - "Execution failed due to a distribution protocol error " + - "that caused deallocation of the conversation. " + - "A PROTOCOL Data Stream Syntax Error was detected. Reason: " + - "0x" + Integer.toHexString (syntaxErrorCode), - SqlState._58009)); - } + dssLength_ -=3D 2; // avoid consuming the DSS cont header + } + + + // As part of parsing the reply, the client can detect that the + // data sent from the target agent does not structurally + // conform to the requirements of the DDM architecture. These are + // the same checks performed by the target server on the messages + // it receives from the protocolj code. Server side detected errors + // result in a SYNTAXRM being returned from the AS. According to the + // DDM manual, parsing of the DSS is terminated when the error is + // detected. The Syntax Error Code, SYNERRCD, describes the various e= rrors. + // + // Note: Not all of these may be valid at the client. See description= s for + // which ones make sense for client side errors/checks. + // Syntax Error Code Description of Error + // ----------------- -------------------- + // 0x01 Dss header Length is less than 6. + // 0x02 Dss header Length does not match= the + // number of bytes of data found. + // 0x03 Dss header C-byte not D0. + // 0x04 Dss header f-bytes either not + // recognized or not supported. + // 0x05 DSS continuation specified but n= ot found. + // For example, DSS continuation is= specified + // on the last DSS, and the SNA LU = 6=2E2 communication + // facility returned the SEND indic= ator. + // 0x06 DSS chaining specified but no DS= S found. + // For example, DSS chaining is spe= cified + // on the last DSS, and the SNA LU = 6=2E2 communication + // facility returned the SEND indic= ator. + // 0x07 Object length less than four. F= or example, + // a command parameter's length is = specified + // as two, or a command's length is= specified as three. + // 0x08 Object length does not match the= number of bytes of data + // found. For example, a RQSDSS wi= th a length of 150 + // contains a command whose length = is 125 or a SRVDGN parameter + // specifies a length of 200 but th= ere are only 50 + // bytes left in the DSS. + // 0x09 Object length greater than maxim= um allowed. + // For example, a RECCNT parameter = specifies a + // length of ten, but the parameter= is defined + // to have a maximum length of eigh= t=2E + // 0x0A Object length less than the mini= mum required. + // For example, a SVRCOD parameter = specifies a + // length of five, but the paramete= r is defined + // to have a fixed length of six. + // 0x0B Object length not allowed. For = example, + // a FILEXDPT parameter is specifie= d with a length of + // 11, but this would indicate that= only half of the hours + // field is present instead of the = complete hours field. + // 0x0C Incorrect large object extended = length field (see + // description of DSS). For exampl= e, an extended + // length field is present, but it = is only three bytes + // long when it is defined to be a = multiple of two bytes. + // 0x0D Object code point index not supp= orted. + // For example, a code point of 803= 2 is encountered + // but x'8' is a reserved code poin= t index. + // 0x0E Required object not found. For = example, a CLEAR + // command does not have a filnam p= arameter present, + // or a MODREC command is not follo= wed by a RECORD + // command data object. + // 0x0F Too many command data objects se= nt. For example, + // a MODREC command is followed by = two RECORD command + // command data objects, or a DECRE= C command is followed + // by RECORD object. + // 0x10 Mutually exclusive objects prese= nt. + // For example, a CRTDIRF command s= pecifies both + // a DCLNAM and FILNAM parameters. + // 0x11 Too few command data objects sen= t=2E + // For example, an INSRECEF command= that + // specified RECCNT95) is followed = by only + // 4 RECORD command data objects. + // 0x12 Duplicate object present. + // For example, a LSTFAT command ha= s tow FILNAM + // parameters specified. + // 0x13 Invalid request correlator speci= fied. + // Use PRCCNVRM with PRCCNVDC of 04= or 05 instead + // of this error code. This error = code is being retained + // for compatibility with Level 1 o= f the architecture. + // 0x14 Required value not found. + // 0x15 Reserved value not allowed. For= example, + // a INSRECEF command specified a R= ECCNT(0) parameter. + // 0x16 DSS continuation less than or eq= ual to two. + // For example, the length bytes of= the DSS continuation + // have the value of one. + // 0x17 Objects not in required order. = For example, a RECAL + // object contains a RECORD object = followed by a RECNBR + // object with is not in the define= d order. + // 0x18 DSS chaining byt not b'1', but D= SSFMT bit3 set to b'1'. + // 0x19 Previous DSS indicated current D= SS has the same + // request correlator, but the requ= est correlators are + // not the same. + // 0x1A DSS cahining bit not b'1', but e= rror continuation requested. + // 0x1B Mutually exclusive parameter val= ues not specified. + // For example, an OPEN command spe= cified PRPSHD(TRUE) + // and FILSHR(READER). + // 0x1D Code point not valid command. F= or example, the first + // code point in RQSDSS either is n= ot in the dictionary + // or is not a code point for a com= mand. + // + // When the client detects these errors, it will be handled as if a SY= NTAXRM is returned + // from the server. In this SYNTAXRM case, PROTOCOL architects an SQL= STATE of 58008 or 58009. + // + // Messages + // SQLSTATE : 58009 + // Execution failed due to a distribution protocol error that caus= ed deallocation of the conversation. + // SQLCODE : -30020 + // Execution failed because of a Distributed Protocol + // Error that will affect the successful execution of subseque= nt + // commands and SQL statements: Reason Code . + // Some possible reason codes include: + // 121C Indicates that the user is not authorized to perform the = requested command. + // 1232 The command could not be completed because of a permanent= error. + // In most cases, the server will be in the process of an abe= nd. + // 220A The target server has received an invalid data descriptio= n=2E + // If a user SQLDA is specified, ensure that the fields are + // initialized correctly. Also, ensure that the length does n= ot + // exceed the maximum allowed length for the data type being = used. + // + // The command or statement cannot be processed. The current + // transaction is rolled back and the application is disconne= cted + // from the remote database. + final void doSyntaxrmSemantics(int syntaxErrorCode) throws org.apache.= derby.client.am.DisconnectException { + agent_.accumulateChainBreakingReadExceptionAndThrow(new org.apache= .derby.client.am.DisconnectException(agent_, + "Execution failed due to a distribution protocol error " + + "that caused deallocation of the conversation. " + + "A PROTOCOL Data Stream Syntax Error was detected. Reason= : " + + "0x" + Integer.toHexString(syntaxErrorCode), + SqlState._58009)); + } =20 =20 // the names of these methods start with a letter z. // the z will be removed when they are finalized... =20 - protected final void pushLengthOnCollectionStack() - { - ddmCollectionLenStack_[++topDdmCollectionStack_] =3D ddmScalarLen_; - ddmScalarLen_ =3D 0; - } - - protected final void adjustLengths(int length) - { - ddmScalarLen_ -=3D length; - adjustCollectionAndDssLengths (length); - /* - for (int i =3D 0; i <=3D topDdmCollectionStack_; i++) { - ddmCollectionLenStack_[i] -=3D length; - } - dssLength_ -=3D length; - */ - } - - protected int adjustDdmLength (int ddmLength, int length) - { - ddmLength -=3D length; - if (ddmLength =3D=3D 0) - adjustLengths (getDdmLength()); - return ddmLength; - } - - // Pop the collection Length stack. - // pre: The collection length stack must not be empty and the top value - // on the stack must be 0. - // post: The top 0 value on the stack will be popped. - protected final void popCollectionStack() - { - topDdmCollectionStack_--; - } - - protected final int peekCodePoint() throws org.apache.derby.client.am.Di= sconnectException - { - if (topDdmCollectionStack_ !=3D EMPTY_STACK) { - if (ddmCollectionLenStack_[topDdmCollectionStack_] =3D=3D 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 d= ss header. - if ((dssLength_ =3D=3D 0) && (!dssIsContinued_)) { - if (!dssIsChainedWithSameID_) { - return END_OF_SAME_ID_CHAIN; - } - readDssHeader(); - } - - if (longBufferForDecryption_ =3D=3D null) //we don't need to do this = if it's data stream encryption - ensureBLayerDataInBuffer (4); - peekedLength_ =3D ((buffer_[pos_] & 0xff) << 8) + ((buffer_[pos_+1] & = 0xff) << 0); - peekedCodePoint_ =3D ((buffer_[pos_+2] & 0xff) << 8) + ((buffer_[pos_+= 3] & 0xff) << 0); - - // check for extended length - if ((peekedLength_ & 0x8000) =3D=3D 0x8000) - peekExtendedLength(); - else - peekedNumOfExtendedLenBytes_ =3D 0; - return peekedCodePoint_; - } - - // Read out the 2-byte length without moving the pos_ pointer. - protected final int peekLength() throws org.apache.derby.client.am.Disco= nnectException - { - ensureBLayerDataInBuffer (2); - return (((buffer_[pos_] & 0xff) << 8) + - ((buffer_[pos_ + 1] & 0xff) << 0)); - } - - // Read "length" number of bytes from the buffer into the byte array b s= tarting from offset - // "offset". The current offset in the buffer does not change. - protected final int peekFastBytes (byte[] b, int offset, int length) thr= ows org.apache.derby.client.am.DisconnectException - { - for (int i =3D 0; i < length; i++) { - b[offset+i] =3D buffer_[pos_+i]; - } - return offset+length; - } - - protected final void parseLengthAndMatchCodePoint (int expectedCodePoint= ) throws org.apache.derby.client.am.DisconnectException - { - int actualCodePoint =3D 0; - if (peekedCodePoint_ =3D=3D END_OF_COLLECTION) - actualCodePoint =3D readLengthAndCodePoint(); - else { - actualCodePoint =3D peekedCodePoint_; - pos_ +=3D (4 + peekedNumOfExtendedLenBytes_); - ddmScalarLen_ =3D peekedLength_; - if (peekedNumOfExtendedLenBytes_ =3D=3D 0 && ddmScalarLen_ !=3D -1) { - adjustLengths (4); - } - else { - adjustCollectionAndDssLengths (4+peekedNumOfExtendedLenBytes_); - } - peekedLength_ =3D 0; - peekedCodePoint_ =3D END_OF_COLLECTION; - peekedNumOfExtendedLenBytes_ =3D 0; - } - - if (actualCodePoint !=3D expectedCodePoint) { - zThrowSyntaxError ("actual code point, " + actualCodePoint + - " does not match expected code point, " + expecte= dCodePoint); - } - } - protected final int readLengthAndCodePoint () throws org.apache.derby.cl= ient.am.DisconnectException - { - if (topDdmCollectionStack_ !=3D EMPTY_STACK) { - if (ddmCollectionLenStack_[topDdmCollectionStack_] =3D=3D 0) - return END_OF_COLLECTION; - else if (ddmCollectionLenStack_[topDdmCollectionStack_] < 4) { - zThrowSyntaxError ("ddm collection contains less than 4 bytes of d= ata"); - } - } - [=2E.. 822 lines stripped ...]