001: /* jcifs smb client library in Java
002: * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package jcifs.smb;
020:
021: import jcifs.Config;
022: import java.io.IOException;
023: import java.io.InputStream;
024:
025: class SmbComWriteAndX extends AndXServerMessageBlock {
026:
027: private static final int READ_ANDX_BATCH_LIMIT = Config.getInt(
028: "jcifs.smb.client.WriteAndX.ReadAndX", 1);
029: private static final int CLOSE_BATCH_LIMIT = Config.getInt(
030: "jcifs.smb.client.WriteAndX.Close", 1);
031:
032: private int fid, writeMode, remaining, dataLength, dataOffset, off;
033: private byte[] b;
034: private long offset;
035:
036: SmbComWriteAndX() {
037: super (null);
038: command = SMB_COM_WRITE_ANDX;
039: }
040:
041: SmbComWriteAndX(int fid, long offset, int remaining, byte[] b,
042: int off, int len, ServerMessageBlock andx) {
043: super (andx);
044: this .fid = fid;
045: this .offset = offset;
046: this .remaining = remaining;
047: this .b = b;
048: this .off = off;
049: dataLength = len;
050: command = SMB_COM_WRITE_ANDX;
051: }
052:
053: void setParam(int fid, long offset, int remaining, byte[] b,
054: int off, int len) {
055: this .fid = fid;
056: this .offset = offset;
057: this .remaining = remaining;
058: this .b = b;
059: this .off = off;
060: dataLength = len;
061: }
062:
063: int getBatchLimit(byte command) {
064: if (command == SMB_COM_READ_ANDX) {
065: return READ_ANDX_BATCH_LIMIT;
066: }
067: if (command == SMB_COM_CLOSE) {
068: return CLOSE_BATCH_LIMIT;
069: }
070: return 0;
071: }
072:
073: int writeParameterWordsWireFormat(byte[] dst, int dstIndex) {
074: int start = dstIndex;
075:
076: dataOffset = (dstIndex - headerStart) + 26; // 26 = off from here to pad
077: /*
078: * pad = ( dataOffset - headerStart ) % 4;
079: * pad = pad == 0 ? 0 : 4 - pad;
080: * dataOffset += pad;
081: */
082:
083: writeInt2(fid, dst, dstIndex);
084: dstIndex += 2;
085: writeInt4(offset, dst, dstIndex);
086: dstIndex += 4;
087: for (int i = 0; i < 4; i++) {
088: dst[dstIndex++] = (byte) 0x00;
089: }
090: writeInt2(writeMode, dst, dstIndex);
091: dstIndex += 2;
092: writeInt2(remaining, dst, dstIndex);
093: dstIndex += 2;
094: dst[dstIndex++] = (byte) 0x00;
095: dst[dstIndex++] = (byte) 0x00;
096: writeInt2(dataLength, dst, dstIndex);
097: dstIndex += 2;
098: writeInt2(dataOffset, dst, dstIndex);
099: dstIndex += 2;
100: writeInt4(offset >> 32, dst, dstIndex);
101: dstIndex += 4;
102:
103: return dstIndex - start;
104: }
105:
106: int writeBytesWireFormat(byte[] dst, int dstIndex) {
107: int start = dstIndex;
108:
109: /* Netware doesn't like this
110: * while( pad-- > 0 ) {
111: * dst[dstIndex++] = (byte)0x00;
112: * }
113: */
114: System.arraycopy(b, off, dst, dstIndex, dataLength);
115: dstIndex += dataLength;
116:
117: return dstIndex - start;
118: }
119:
120: int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) {
121: return 0;
122: }
123:
124: int readBytesWireFormat(byte[] buffer, int bufferIndex) {
125: return 0;
126: }
127:
128: int readBytesDirectWireFormat(InputStream in, int byteCount,
129: byte[] buffer, int bufferIndex) throws IOException {
130: return 0;
131: }
132:
133: public String toString() {
134: return new String("SmbComWriteAndX[" + super .toString()
135: + ",fid=" + fid + ",offset=" + offset + ",writeMode="
136: + writeMode + ",remaining=" + remaining
137: + ",dataLength=" + dataLength + ",dataOffset="
138: + dataOffset + "]");
139: }
140: }
|