1 18 19 package jcifs.smb; 20 21 import java.io.InputStream ; 22 import java.io.IOException ; 23 import jcifs.util.Hexdump; 24 25 abstract class AndXServerMessageBlock extends ServerMessageBlock { 26 27 private static final int ANDX_COMMAND_OFFSET = 1; 28 private static final int ANDX_RESERVED_OFFSET = 2; 29 private static final int ANDX_OFFSET_OFFSET = 3; 30 31 private byte andxCommand = (byte)0xFF; 32 private int andxOffset = 0; 33 34 ServerMessageBlock andx = null; 35 36 AndXServerMessageBlock() { 37 } 38 AndXServerMessageBlock( ServerMessageBlock andx ) { 39 if (andx != null) { 40 this.andx = andx; 41 andxCommand = andx.command; 42 } 43 } 44 45 int getBatchLimit( byte command ) { 46 49 return 0; 50 } 51 52 60 61 int encode( byte[] dst, int dstIndex ) { 62 int start = headerStart = dstIndex; 63 64 dstIndex += writeHeaderWireFormat( dst, dstIndex ); 65 dstIndex += writeAndXWireFormat( dst, dstIndex ); 66 length = dstIndex - start; 67 68 if( digest != null ) { 69 digest.sign( dst, headerStart, length, this, response ); 70 } 71 72 return length; 73 } 74 75 81 82 int decode( byte[] buffer, int bufferIndex ) { 83 int start = headerStart = bufferIndex; 84 85 bufferIndex += readHeaderWireFormat( buffer, bufferIndex ); 86 bufferIndex += readAndXWireFormat( buffer, bufferIndex ); 87 88 length = bufferIndex - start; 89 return length; 90 } 91 int writeAndXWireFormat( byte[] dst, int dstIndex ) { 92 int start = dstIndex; 93 94 wordCount = writeParameterWordsWireFormat( dst, 95 start + ANDX_OFFSET_OFFSET + 2 ); 96 wordCount += 4; dstIndex += wordCount + 1; 98 wordCount /= 2; 99 dst[start] = (byte)( wordCount & 0xFF ); 100 101 byteCount = writeBytesWireFormat( dst, dstIndex + 2 ); 102 dst[dstIndex++] = (byte)( byteCount & 0xFF ); 103 dst[dstIndex++] = (byte)(( byteCount >> 8 ) & 0xFF ); 104 dstIndex += byteCount; 105 106 115 116 if( andx == null || USE_BATCHING == false || 117 batchLevel >= getBatchLimit( andx.command )) { 118 andxCommand = (byte)0xFF; 119 andx = null; 120 121 dst[start + ANDX_COMMAND_OFFSET] = (byte)0xFF; 122 dst[start + ANDX_RESERVED_OFFSET] = (byte)0x00; 123 dst[start + ANDX_OFFSET_OFFSET] = (byte)0x00; 124 dst[start + ANDX_OFFSET_OFFSET + 1] = (byte)0x00; 125 126 return dstIndex - start; 128 } 129 130 136 137 andx.batchLevel = batchLevel + 1; 138 139 140 dst[start + ANDX_COMMAND_OFFSET] = andxCommand; 141 dst[start + ANDX_RESERVED_OFFSET] = (byte)0x00; 142 andxOffset = dstIndex - headerStart; 143 writeInt2( andxOffset, dst, start + ANDX_OFFSET_OFFSET ); 144 145 andx.useUnicode = useUnicode; 146 if( andx instanceof AndXServerMessageBlock ) { 147 148 162 163 andx.uid = uid; 164 dstIndex += ((AndXServerMessageBlock)andx).writeAndXWireFormat( dst, dstIndex ); 165 } else { 166 int andxStart = dstIndex; 169 andx.wordCount = andx.writeParameterWordsWireFormat( dst, dstIndex ); 170 dstIndex += andx.wordCount + 1; 171 andx.wordCount /= 2; 172 dst[andxStart] = (byte)( andx.wordCount & 0xFF ); 173 174 andx.byteCount = andx.writeBytesWireFormat( dst, dstIndex + 2 ); 175 dst[dstIndex++] = (byte)( andx.byteCount & 0xFF ); 176 dst[dstIndex++] = (byte)(( andx.byteCount >> 8 ) & 0xFF ); 177 dstIndex += andx.byteCount; 178 } 179 180 return dstIndex - start; 181 } 182 int readAndXWireFormat( byte[] buffer, int bufferIndex ) { 183 int start = bufferIndex; 184 185 wordCount = buffer[bufferIndex++]; 186 187 if( wordCount != 0 ) { 188 192 193 andxCommand = buffer[bufferIndex]; bufferIndex += 2; 194 andxOffset = readInt2( buffer, bufferIndex ); bufferIndex += 2; 195 196 if( andxOffset == 0 ) { 197 andxCommand = (byte)0xFF; 198 } 199 200 204 205 if( wordCount > 2 ) { 206 bufferIndex += readParameterWordsWireFormat( buffer, bufferIndex ); 207 } 208 } 209 210 byteCount = readInt2( buffer, bufferIndex ); bufferIndex += 2; 211 212 if (byteCount != 0) { 213 int n; 214 n = readBytesWireFormat( buffer, bufferIndex ); 215 bufferIndex += byteCount; 216 } 217 218 224 225 if( errorCode != 0 || andxCommand == (byte)0xFF ) { 226 andxCommand = (byte)0xFF; 227 andx = null; 228 } else if( andx == null ) { 229 andxCommand = (byte)0xFF; 230 throw new RuntimeException ( "no andx command supplied with response" ); 231 } else { 232 233 236 237 bufferIndex = headerStart + andxOffset; 238 239 andx.headerStart = headerStart; 240 andx.command = andxCommand; 241 andx.errorCode = errorCode; 242 andx.flags = flags; 243 andx.flags2 = flags2; 244 andx.tid = tid; 245 andx.pid = pid; 246 andx.uid = uid; 247 andx.mid = mid; 248 andx.useUnicode = useUnicode; 249 250 if( andx instanceof AndXServerMessageBlock ) { 251 bufferIndex += ((AndXServerMessageBlock)andx).readAndXWireFormat( 252 buffer, bufferIndex ); 253 } else { 254 255 258 259 buffer[bufferIndex++] = (byte)( andx.wordCount & 0xFF ); 260 261 if( andx.wordCount != 0 ) { 262 266 267 if( andx.wordCount > 2 ) { 268 bufferIndex += andx.readParameterWordsWireFormat( buffer, bufferIndex ); 269 } 270 } 271 272 andx.byteCount = readInt2( buffer, bufferIndex ); 273 bufferIndex += 2; 274 275 if( andx.byteCount != 0 ) { 276 andx.readBytesWireFormat( buffer, bufferIndex ); 277 bufferIndex += andx.byteCount; 278 } 279 } 280 andx.received = true; 281 } 282 283 return bufferIndex - start; 284 } 285 public String toString() { 286 return new String ( super.toString() + 287 ",andxCommand=0x" + Hexdump.toHexString( andxCommand, 2 ) + 288 ",andxOffset=" + andxOffset ); 289 } 290 } 291 | Popular Tags |