1 18 19 package jcifs.smb; 20 21 import java.util.Enumeration ; 22 23 abstract class SmbComTransactionResponse extends ServerMessageBlock implements Enumeration { 24 25 private static final int SETUP_OFFSET = 61; 27 28 private static final int DISCONNECT_TID = 0x01; 29 private static final int ONE_WAY_TRANSACTION = 0x02; 30 31 private int totalParameterCount; 32 private int totalDataCount; 33 private int parameterCount; 34 private int parameterOffset; 35 private int parameterDisplacement; 36 private int dataOffset; 37 private int dataDisplacement; 38 private int setupCount; 39 private int pad; 40 private int pad1; 41 private boolean parametersDone, dataDone; 42 43 private int bufParameterStart; 44 private int bufDataStart; 45 46 int dataCount; 47 byte subCommand; 48 boolean hasMore = true; 49 boolean isPrimary = true; 50 byte[] txn_buf; 51 52 53 int status; 54 int numEntries; 55 FileEntry[] results; 56 57 SmbComTransactionResponse() { 58 txn_buf = null; 59 } 60 61 void reset() { 62 super.reset(); 63 bufDataStart = 0; 64 isPrimary = hasMore = true; 65 parametersDone = dataDone = false; 66 } 67 public boolean hasMoreElements() { 68 return errorCode == 0 && hasMore; 69 } 70 public Object nextElement() { 71 if( isPrimary ) { 72 isPrimary = false; 73 } 74 return this; 75 } 76 int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) { 77 return 0; 78 } 79 int writeBytesWireFormat( byte[] dst, int dstIndex ) { 80 return 0; 81 } 82 int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) { 83 int start = bufferIndex; 84 85 totalParameterCount = readInt2( buffer, bufferIndex ); 86 if( bufDataStart == 0 ) { 87 bufDataStart = totalParameterCount; 88 } 89 bufferIndex += 2; 90 totalDataCount = readInt2( buffer, bufferIndex ); 91 bufferIndex += 4; parameterCount = readInt2( buffer, bufferIndex ); 93 bufferIndex += 2; 94 parameterOffset = readInt2( buffer, bufferIndex ); 95 bufferIndex += 2; 96 parameterDisplacement = readInt2( buffer, bufferIndex ); 97 bufferIndex += 2; 98 dataCount = readInt2( buffer, bufferIndex ); 99 bufferIndex += 2; 100 dataOffset = readInt2( buffer, bufferIndex ); 101 bufferIndex += 2; 102 dataDisplacement = readInt2( buffer, bufferIndex ); 103 bufferIndex += 2; 104 setupCount = buffer[bufferIndex] & 0xFF; 105 bufferIndex += 2; 106 if( setupCount != 0 ) { 107 if( log.level > 2 ) 108 log.println( "setupCount is not zero: " + setupCount ); 109 } 110 111 return bufferIndex - start; 112 } 113 int readBytesWireFormat( byte[] buffer, int bufferIndex ) { 114 pad = pad1 = 0; 115 int n; 116 117 if( parameterCount > 0 ) { 118 bufferIndex += pad = parameterOffset - ( bufferIndex - headerStart ); 119 System.arraycopy( buffer, bufferIndex, txn_buf, 120 bufParameterStart + parameterDisplacement, parameterCount ); 121 bufferIndex += parameterCount; 122 } 123 if( dataCount > 0 ) { 124 bufferIndex += pad1 = dataOffset - ( bufferIndex - headerStart ); 125 System.arraycopy( buffer, bufferIndex, txn_buf, 126 bufDataStart + dataDisplacement, dataCount ); 127 bufferIndex += dataCount; 128 } 129 130 133 134 if( !parametersDone && 135 ( parameterDisplacement + parameterCount ) == totalParameterCount) { 136 parametersDone = true; 137 } 138 139 if( !dataDone && ( dataDisplacement + dataCount ) == totalDataCount) { 140 dataDone = true; 141 } 142 143 if( parametersDone && dataDone ) { 144 hasMore = false; 145 readParametersWireFormat( txn_buf, bufParameterStart, totalParameterCount ); 146 readDataWireFormat( txn_buf, bufDataStart, totalDataCount ); 147 } 148 149 return pad + parameterCount + pad1 + dataCount; 150 } 151 152 abstract int writeSetupWireFormat( byte[] dst, int dstIndex ); 153 abstract int writeParametersWireFormat( byte[] dst, int dstIndex ); 154 abstract int writeDataWireFormat( byte[] dst, int dstIndex ); 155 abstract int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ); 156 abstract int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ); 157 abstract int readDataWireFormat( byte[] buffer, int bufferIndex, int len ); 158 159 public String toString() { 160 return new String ( super.toString() + 161 ",totalParameterCount=" + totalParameterCount + 162 ",totalDataCount=" + totalDataCount + 163 ",parameterCount=" + parameterCount + 164 ",parameterOffset=" + parameterOffset + 165 ",parameterDisplacement=" + parameterDisplacement + 166 ",dataCount=" + dataCount + 167 ",dataOffset=" + dataOffset + 168 ",dataDisplacement=" + dataDisplacement + 169 ",setupCount=" + setupCount + 170 ",pad=" + pad + 171 ",pad1=" + pad1 ); 172 } 173 } 174 | Popular Tags |