KickJava   Java API By Example, From Geeks To Geeks.

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

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