KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > jcifs > smb > SmbComTransactionResponse


1 /* jcifs smb client library in Java
2  * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package com.knowgate.jcifs.smb;
20
21 import java.util.Enumeration JavaDoc;
22
23 import com.knowgate.debug.*;
24
25 abstract class SmbComTransactionResponse extends ServerMessageBlock implements Enumeration JavaDoc {
26
27     // relative to headerStart
28
private static final int SETUP_OFFSET = 61;
29
30     private static final int DISCONNECT_TID = 0x01;
31     private static final int ONE_WAY_TRANSACTION = 0x02;
32
33     private int totalParameterCount;
34     private int totalDataCount;
35     private int parameterCount;
36     private int parameterOffset;
37     private int parameterDisplacement;
38     private int dataOffset;
39     private int dataDisplacement;
40     private int setupCount;
41     private int pad;
42     private int pad1;
43     private boolean parametersDone, dataDone;
44
45     private int bufParameterStart;
46     private int bufDataStart;
47
48     int dataCount;
49     byte subCommand;
50     boolean hasMore = true;
51     boolean isPrimary = true;
52     byte[] txn_buf;
53
54     /* for doNetEnum and doFindFirstNext */
55     int status;
56     int numEntries;
57     FileEntry[] results;
58
59     SmbComTransactionResponse() {
60         txn_buf = null;
61     }
62
63     public void reset() {
64         bufDataStart = 0;
65         isPrimary = hasMore = true;
66         parametersDone = dataDone = false;
67     }
68     public boolean hasMoreElements() {
69         return hasMore;
70     }
71     public Object JavaDoc nextElement() {
72         if( isPrimary ) {
73             isPrimary = false;
74         }
75         return this;
76     }
77     int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
78         return 0;
79     }
80     int writeBytesWireFormat( byte[] dst, int dstIndex ) {
81         return 0;
82     }
83     int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
84         int start = bufferIndex;
85
86         totalParameterCount = readInt2( buffer, bufferIndex );
87         if( bufDataStart == 0 ) {
88             bufDataStart = totalParameterCount;
89         }
90         bufferIndex += 2;
91         totalDataCount = readInt2( buffer, bufferIndex );
92         bufferIndex += 4; // Reserved
93
parameterCount = readInt2( buffer, bufferIndex );
94         bufferIndex += 2;
95         parameterOffset = readInt2( buffer, bufferIndex );
96         bufferIndex += 2;
97         parameterDisplacement = readInt2( buffer, bufferIndex );
98         bufferIndex += 2;
99         dataCount = readInt2( buffer, bufferIndex );
100         bufferIndex += 2;
101         dataOffset = readInt2( buffer, bufferIndex );
102         bufferIndex += 2;
103         dataDisplacement = readInt2( buffer, bufferIndex );
104         bufferIndex += 2;
105         setupCount = buffer[bufferIndex] & 0xFF;
106         bufferIndex += 2;
107         if( setupCount != 0 ) {
108             if( DebugFile.trace )
109                 DebugFile.writeln( "setupCount is not zero: " + setupCount );
110         }
111
112         return bufferIndex - start;
113     }
114     int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
115         pad = pad1 = 0;
116         int n;
117
118         if( parameterCount > 0 ) {
119             bufferIndex += pad = parameterOffset - ( bufferIndex - headerStart );
120             System.arraycopy( buffer, bufferIndex, txn_buf,
121                             bufParameterStart + parameterDisplacement, parameterCount );
122             bufferIndex += parameterCount;
123         }
124         if( dataCount > 0 ) {
125             bufferIndex += pad1 = dataOffset - ( bufferIndex - headerStart );
126             System.arraycopy( buffer, bufferIndex, txn_buf,
127                             bufDataStart + dataDisplacement, dataCount );
128             bufferIndex += dataCount;
129         }
130
131         /* Check to see if the entire transaction has been
132          * read. If so call the read methods.
133          */

134
135         if( !parametersDone &&
136                 ( parameterDisplacement + parameterCount ) == totalParameterCount) {
137             parametersDone = true;
138         }
139
140         if( !dataDone &&
141                 ( dataDisplacement + dataCount ) == totalDataCount) {
142             dataDone = true;
143         }
144
145         if( parametersDone && dataDone ) {
146             hasMore = false;
147             readParametersWireFormat( txn_buf, bufParameterStart, totalParameterCount );
148             readDataWireFormat( txn_buf, bufDataStart, totalDataCount );
149         }
150
151         return pad + parameterCount + pad1 + dataCount;
152     }
153
154     abstract int writeSetupWireFormat( byte[] dst, int dstIndex );
155     abstract int writeParametersWireFormat( byte[] dst, int dstIndex );
156     abstract int writeDataWireFormat( byte[] dst, int dstIndex );
157     abstract int readSetupWireFormat( byte[] buffer, int bufferIndex, int len );
158     abstract int readParametersWireFormat( byte[] buffer, int bufferIndex, int len );
159     abstract int readDataWireFormat( byte[] buffer, int bufferIndex, int len );
160
161     public String JavaDoc toString() {
162         return new String JavaDoc( super.toString() +
163             ",totalParameterCount=" + totalParameterCount +
164             ",totalDataCount=" + totalDataCount +
165             ",parameterCount=" + parameterCount +
166             ",parameterOffset=" + parameterOffset +
167             ",parameterDisplacement=" + parameterDisplacement +
168             ",dataCount=" + dataCount +
169             ",dataOffset=" + dataOffset +
170             ",dataDisplacement=" + dataDisplacement +
171             ",setupCount=" + setupCount +
172             ",pad=" + pad +
173             ",pad1=" + pad1 );
174     }
175 }
176
Popular Tags