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