1 17 package org.alfresco.filesys.smb; 18 19 import org.alfresco.filesys.util.DataBuffer; 20 21 26 public class TransactBuffer 27 { 28 29 31 protected static final int DefaultSetupSize = 32; 32 protected static final int DefaultDataSize = 8192; 33 protected static final int DefaultParameterSize = 64; 34 35 37 protected static final int DefaultMaxSetupReturn = 16; 38 protected static final int DefaultMaxParameterReturn = 256; 39 protected static final int DefaultMaxDataReturn = 65000; 40 41 43 protected int m_treeId = -1; 44 45 47 protected int m_type; 48 protected int m_func; 49 50 52 protected String m_name; 53 54 56 protected DataBuffer m_setupBuf; 57 58 60 protected DataBuffer m_paramBuf; 61 62 64 protected DataBuffer m_dataBuf; 65 66 68 protected boolean m_multi; 69 70 72 protected boolean m_unicode; 73 74 76 protected int m_maxSetup = DefaultMaxSetupReturn; 77 protected int m_maxParam = DefaultMaxParameterReturn; 78 protected int m_maxData = DefaultMaxDataReturn; 79 80 83 public TransactBuffer() 84 { 85 m_setupBuf = new DataBuffer(DefaultSetupSize); 86 m_paramBuf = new DataBuffer(DefaultParameterSize); 87 m_dataBuf = new DataBuffer(DefaultDataSize); 88 } 89 90 97 public TransactBuffer(int scnt, int pcnt, int dcnt) 98 { 99 100 102 if (scnt > 0) 103 m_setupBuf = new DataBuffer(scnt); 104 105 107 if (pcnt > 0) 108 m_paramBuf = new DataBuffer(pcnt); 109 110 112 if (dcnt > 0) 113 m_dataBuf = new DataBuffer(dcnt); 114 115 117 m_multi = true; 118 } 119 120 128 public TransactBuffer(int cmd, int scnt, int pcnt, int dcnt) 129 { 130 131 133 setType(cmd); 134 135 137 if (scnt > 0) 138 m_setupBuf = new DataBuffer(scnt); 139 140 142 if (pcnt > 0) 143 m_paramBuf = new DataBuffer(pcnt); 144 145 147 if (dcnt > 0) 148 m_dataBuf = new DataBuffer(dcnt); 149 150 152 m_multi = true; 153 } 154 155 164 public TransactBuffer(int func, String name, int scnt, int pcnt, int dcnt) 165 { 166 167 169 setName(name); 170 171 173 if (scnt > 0) 174 m_setupBuf = new DataBuffer(scnt); 175 176 178 if (pcnt > 0) 179 m_paramBuf = new DataBuffer(pcnt); 180 181 183 if (dcnt > 0) 184 m_dataBuf = new DataBuffer(dcnt); 185 186 188 setFunction(func); 189 190 192 m_multi = true; 193 } 194 195 205 public TransactBuffer(int func, int scnt, int pcnt, byte[] dbuf, int doff, int dlen) 206 { 207 208 210 if (scnt > 0) 211 m_setupBuf = new DataBuffer(scnt); 212 213 215 if (pcnt > 0) 216 m_paramBuf = new DataBuffer(pcnt); 217 218 220 if (dbuf != null) 221 m_dataBuf = new DataBuffer(dbuf, doff, dlen); 222 223 225 setFunction(func); 226 227 229 m_multi = true; 230 } 231 232 237 public final boolean hasTreeId() 238 { 239 return m_treeId != -1 ? true : false; 240 } 241 242 247 public final int getTreeId() 248 { 249 return m_treeId; 250 } 251 252 258 public final int isType() 259 { 260 return m_type; 261 } 262 263 268 public final int getFunction() 269 { 270 return m_func; 271 } 272 273 278 public final boolean hasName() 279 { 280 return m_name != null ? true : false; 281 } 282 283 288 public final String getName() 289 { 290 return m_name; 291 } 292 293 298 public final boolean isMultiPacket() 299 { 300 return m_multi; 301 } 302 303 308 public final boolean isUnicode() 309 { 310 return m_unicode; 311 } 312 313 318 public final boolean hasSetupBuffer() 319 { 320 return m_setupBuf != null ? true : false; 321 } 322 323 328 public final DataBuffer getSetupBuffer() 329 { 330 return m_setupBuf; 331 } 332 333 338 public final boolean hasParameterBuffer() 339 { 340 return m_paramBuf != null ? true : false; 341 } 342 343 348 public final DataBuffer getParameterBuffer() 349 { 350 return m_paramBuf; 351 } 352 353 358 public final boolean hasDataBuffer() 359 { 360 return m_dataBuf != null ? true : false; 361 } 362 363 368 public final DataBuffer getDataBuffer() 369 { 370 return m_dataBuf; 371 } 372 373 378 public final int getReturnSetupLimit() 379 { 380 return m_maxSetup; 381 } 382 383 388 public final int getReturnParameterLimit() 389 { 390 return m_maxParam; 391 } 392 393 398 public final int getReturnDataLimit() 399 { 400 return m_maxData; 401 } 402 403 408 public final void setTreeId(int tid) 409 { 410 m_treeId = tid; 411 } 412 413 418 public final void setType(int typ) 419 { 420 m_type = typ; 421 } 422 423 428 public final void setFunction(int func) 429 { 430 m_func = func; 431 } 432 433 438 public final void setName(String name) 439 { 440 m_name = name; 441 } 442 443 448 public final void setUnicode(boolean uni) 449 { 450 m_unicode = uni; 451 } 452 453 458 public final void setReturnSetupLimit(int limit) 459 { 460 m_maxSetup = limit; 461 } 462 463 468 public final void setReturnParameterLimit(int limit) 469 { 470 m_maxParam = limit; 471 } 472 473 478 public final void setReturnDataLimit(int limit) 479 { 480 m_maxData = limit; 481 } 482 483 490 public final void setReturnLimits(int slimit, int plimit, int dlimit) 491 { 492 setReturnSetupLimit(slimit); 493 setReturnParameterLimit(plimit); 494 setReturnDataLimit(dlimit); 495 } 496 497 501 public final void setEndOfBuffer() 502 { 503 504 506 if (m_setupBuf != null) 507 m_setupBuf.setEndOfBuffer(); 508 509 511 if (m_paramBuf != null) 512 m_paramBuf.setEndOfBuffer(); 513 514 516 if (m_dataBuf != null) 517 m_dataBuf.setEndOfBuffer(); 518 } 519 520 527 public final void appendSetup(byte[] buf, int off, int len) 528 { 529 m_setupBuf.appendData(buf, off, len); 530 } 531 532 539 public final void appendParameter(byte[] buf, int off, int len) 540 { 541 m_paramBuf.appendData(buf, off, len); 542 } 543 544 551 public final void appendData(byte[] buf, int off, int len) 552 { 553 m_dataBuf.appendData(buf, off, len); 554 } 555 556 561 public String toString() 562 { 563 StringBuffer str = new StringBuffer (); 564 565 str.append("["); 566 567 switch (isType()) 568 { 569 case PacketType.Transaction: 570 str.append("Trans"); 571 break; 572 case PacketType.Transaction2: 573 str.append("Trans2("); 574 str.append(getName()); 575 str.append(")"); 576 break; 577 case PacketType.NTTransact: 578 str.append("NTTrans"); 579 break; 580 default: 581 str.append("Unknown"); 582 break; 583 } 584 str.append("-0x"); 585 str.append(Integer.toHexString(getFunction())); 586 587 str.append(": setup="); 588 if (m_setupBuf != null) 589 str.append(m_setupBuf); 590 else 591 str.append("none"); 592 593 str.append(",param="); 594 if (m_paramBuf != null) 595 str.append(m_paramBuf); 596 else 597 str.append("none"); 598 599 str.append(",data="); 600 if (m_dataBuf != null) 601 str.append(m_dataBuf); 602 else 603 str.append("none"); 604 str.append("]"); 605 606 str.append(",max="); 607 str.append(getReturnSetupLimit()); 608 609 str.append("/"); 610 str.append(getReturnParameterLimit()); 611 612 str.append("/"); 613 str.append(getReturnDataLimit()); 614 615 return str.toString(); 616 } 617 } 618 | Popular Tags |