1 17 package org.alfresco.filesys.smb.server; 18 19 import org.alfresco.filesys.netbios.RFCNetBIOSProtocol; 20 import org.alfresco.filesys.smb.PacketType; 21 import org.alfresco.filesys.util.DataPacker; 22 23 26 27 public class SMBTransPacket extends SMBSrvPacket 28 { 29 30 32 protected static final int STD_PARAMS = 14; 33 34 37 public static final int IsContinued = 234; 38 39 41 protected String m_transName; 42 43 45 protected int m_paramCnt; 46 47 49 private static int m_nextMID = 1; 50 51 56 public SMBTransPacket(byte[] buf) 57 { 58 super(buf); 59 } 60 61 66 public SMBTransPacket(int siz) 67 { 68 super(siz); 69 70 72 setMultiplexId(getNextMultiplexId()); 73 } 74 75 80 public final static int getNextMultiplexId() 81 { 82 return m_nextMID++; 83 } 84 85 90 public final int getTotalParameterCount() 91 { 92 return getParameter(0); 93 } 94 95 100 public final int getTotalDataCount() 101 { 102 return getParameter(1); 103 } 104 105 110 public final int getParameterBlockCount() 111 { 112 return getParameter(9); 113 } 114 115 120 public final int getParameterBlockOffset() 121 { 122 return getParameter(10) + RFCNetBIOSProtocol.HEADER_LEN; 123 } 124 125 130 public final int getDataBlockCount() 131 { 132 return getParameter(11); 133 } 134 135 140 public final int getDataBlockOffset() 141 { 142 return getParameter(12) + RFCNetBIOSProtocol.HEADER_LEN; 143 } 144 145 150 public final int getSecondaryParameterBlockCount() 151 { 152 return getParameter(2); 153 } 154 155 160 public final int getSecondaryParameterBlockOffset() 161 { 162 return getParameter(3) + RFCNetBIOSProtocol.HEADER_LEN; 163 } 164 165 170 public final int getParameterBlockDisplacement() 171 { 172 return getParameter(4); 173 } 174 175 180 public final int getSecondaryDataBlockCount() 181 { 182 return getParameter(5); 183 } 184 185 190 public final int getSecondaryDataBlockOffset() 191 { 192 return getParameter(6) + RFCNetBIOSProtocol.HEADER_LEN; 193 } 194 195 200 public final int getDataBlockDisplacement() 201 { 202 return getParameter(7); 203 } 204 205 210 public final int getSubFunction() 211 { 212 return getParameter(14); 213 } 214 215 220 public final void getParameterBlock(short[] prmblk) throws java.lang.ArrayIndexOutOfBoundsException 221 { 222 223 226 int prmcnt = getParameter(3) / 2; if (prmblk.length < prmcnt) 228 throw new java.lang.ArrayIndexOutOfBoundsException (); 229 230 233 int pos = getParameter(4) + RFCNetBIOSProtocol.HEADER_LEN; 234 235 237 byte[] buf = getBuffer(); 238 239 for (int idx = 0; idx < prmcnt; idx++) 240 { 241 242 244 prmblk[idx] = (short) DataPacker.getIntelShort(buf, pos); 245 pos += 2; 246 } 247 } 248 249 258 public final void InitializeTransact(int pcnt, byte[] paramblk, int plen, byte[] datablk, int dlen) 259 { 260 261 263 if (m_transName == null) 264 setCommand(PacketType.Transaction2); 265 else 266 setCommand(PacketType.Transaction); 267 268 270 setParameterCount(pcnt); 271 272 274 m_paramCnt = pcnt; 275 276 278 setParameter(0, plen); setParameter(1, dlen); 281 for (int i = 2; i < 9; setParameter(i++, 0)) 282 ; 283 284 setParameter(9, plen); setParameter(11, dlen); 287 setParameter(13, pcnt - STD_PARAMS); 289 291 int pos = getByteOffset(); 292 int startPos = pos; 293 294 296 int idx; 297 byte[] buf = getBuffer(); 298 299 if (m_transName != null) 300 { 301 302 304 byte[] nam = m_transName.getBytes(); 305 306 for (idx = 0; idx < nam.length; idx++) 307 buf[pos++] = nam[idx]; 308 } 309 310 312 if ((pos % 2) > 0) 313 pos++; 314 315 317 if (paramblk != null) 318 { 319 320 322 setParameter(10, pos - RFCNetBIOSProtocol.HEADER_LEN); 323 324 326 for (idx = 0; idx < plen; idx++) 327 buf[pos++] = paramblk[idx]; 328 } 329 else 330 { 331 332 334 setParameter(10, 0); 335 } 336 337 339 if ((pos % 2) > 0) 340 pos++; 341 342 344 if (datablk != null) 345 { 346 347 349 setParameter(12, pos - RFCNetBIOSProtocol.HEADER_LEN); 350 351 353 for (idx = 0; idx < dlen; idx++) 354 buf[pos++] = datablk[idx]; 355 } 356 else 357 { 358 359 361 setParameter(12, 0); 362 } 363 364 366 setByteCount(pos - startPos); 367 } 368 369 375 376 public final void setSetupParameter(int idx, int val) 377 { 378 setParameter(STD_PARAMS + idx, val); 379 } 380 381 386 387 public final void setTransactionName(String tname) 388 { 389 m_transName = tname; 390 } 391 } | Popular Tags |