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 com.knowgate.jcifs.smb;
020:
021: import java.util.Enumeration;
022:
023: import com.knowgate.debug.*;
024:
025: abstract class SmbComTransactionResponse extends ServerMessageBlock
026: implements Enumeration {
027:
028: // relative to headerStart
029: private static final int SETUP_OFFSET = 61;
030:
031: private static final int DISCONNECT_TID = 0x01;
032: private static final int ONE_WAY_TRANSACTION = 0x02;
033:
034: private int totalParameterCount;
035: private int totalDataCount;
036: private int parameterCount;
037: private int parameterOffset;
038: private int parameterDisplacement;
039: private int dataOffset;
040: private int dataDisplacement;
041: private int setupCount;
042: private int pad;
043: private int pad1;
044: private boolean parametersDone, dataDone;
045:
046: private int bufParameterStart;
047: private int bufDataStart;
048:
049: int dataCount;
050: byte subCommand;
051: boolean hasMore = true;
052: boolean isPrimary = true;
053: byte[] txn_buf;
054:
055: /* for doNetEnum and doFindFirstNext */
056: int status;
057: int numEntries;
058: FileEntry[] results;
059:
060: SmbComTransactionResponse() {
061: txn_buf = null;
062: }
063:
064: public void reset() {
065: bufDataStart = 0;
066: isPrimary = hasMore = true;
067: parametersDone = dataDone = false;
068: }
069:
070: public boolean hasMoreElements() {
071: return hasMore;
072: }
073:
074: public Object nextElement() {
075: if (isPrimary) {
076: isPrimary = false;
077: }
078: return this ;
079: }
080:
081: int writeParameterWordsWireFormat(byte[] dst, int dstIndex) {
082: return 0;
083: }
084:
085: int writeBytesWireFormat(byte[] dst, int dstIndex) {
086: return 0;
087: }
088:
089: int readParameterWordsWireFormat(byte[] buffer, int bufferIndex) {
090: int start = bufferIndex;
091:
092: totalParameterCount = readInt2(buffer, bufferIndex);
093: if (bufDataStart == 0) {
094: bufDataStart = totalParameterCount;
095: }
096: bufferIndex += 2;
097: totalDataCount = readInt2(buffer, bufferIndex);
098: bufferIndex += 4; // Reserved
099: parameterCount = readInt2(buffer, bufferIndex);
100: bufferIndex += 2;
101: parameterOffset = readInt2(buffer, bufferIndex);
102: bufferIndex += 2;
103: parameterDisplacement = readInt2(buffer, bufferIndex);
104: bufferIndex += 2;
105: dataCount = readInt2(buffer, bufferIndex);
106: bufferIndex += 2;
107: dataOffset = readInt2(buffer, bufferIndex);
108: bufferIndex += 2;
109: dataDisplacement = readInt2(buffer, bufferIndex);
110: bufferIndex += 2;
111: setupCount = buffer[bufferIndex] & 0xFF;
112: bufferIndex += 2;
113: if (setupCount != 0) {
114: if (DebugFile.trace)
115: DebugFile.writeln("setupCount is not zero: "
116: + setupCount);
117: }
118:
119: return bufferIndex - start;
120: }
121:
122: int readBytesWireFormat(byte[] buffer, int bufferIndex) {
123: pad = pad1 = 0;
124: int n;
125:
126: if (parameterCount > 0) {
127: bufferIndex += pad = parameterOffset
128: - (bufferIndex - headerStart);
129: System.arraycopy(buffer, bufferIndex, txn_buf,
130: bufParameterStart + parameterDisplacement,
131: parameterCount);
132: bufferIndex += parameterCount;
133: }
134: if (dataCount > 0) {
135: bufferIndex += pad1 = dataOffset
136: - (bufferIndex - headerStart);
137: System.arraycopy(buffer, bufferIndex, txn_buf, bufDataStart
138: + dataDisplacement, dataCount);
139: bufferIndex += dataCount;
140: }
141:
142: /* Check to see if the entire transaction has been
143: * read. If so call the read methods.
144: */
145:
146: if (!parametersDone
147: && (parameterDisplacement + parameterCount) == totalParameterCount) {
148: parametersDone = true;
149: }
150:
151: if (!dataDone
152: && (dataDisplacement + dataCount) == totalDataCount) {
153: dataDone = true;
154: }
155:
156: if (parametersDone && dataDone) {
157: hasMore = false;
158: readParametersWireFormat(txn_buf, bufParameterStart,
159: totalParameterCount);
160: readDataWireFormat(txn_buf, bufDataStart, totalDataCount);
161: }
162:
163: return pad + parameterCount + pad1 + dataCount;
164: }
165:
166: abstract int writeSetupWireFormat(byte[] dst, int dstIndex);
167:
168: abstract int writeParametersWireFormat(byte[] dst, int dstIndex);
169:
170: abstract int writeDataWireFormat(byte[] dst, int dstIndex);
171:
172: abstract int readSetupWireFormat(byte[] buffer, int bufferIndex,
173: int len);
174:
175: abstract int readParametersWireFormat(byte[] buffer,
176: int bufferIndex, int len);
177:
178: abstract int readDataWireFormat(byte[] buffer, int bufferIndex,
179: int len);
180:
181: public String toString() {
182: return new String(super .toString() + ",totalParameterCount="
183: + totalParameterCount + ",totalDataCount="
184: + totalDataCount + ",parameterCount=" + parameterCount
185: + ",parameterOffset=" + parameterOffset
186: + ",parameterDisplacement=" + parameterDisplacement
187: + ",dataCount=" + dataCount + ",dataOffset="
188: + dataOffset + ",dataDisplacement=" + dataDisplacement
189: + ",setupCount=" + setupCount + ",pad=" + pad
190: + ",pad1=" + pad1);
191: }
192: }
|