KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.UnsupportedEncodingException JavaDoc;
22 import java.util.Date JavaDoc;
23
24 import com.knowgate.debug.*;
25
26 class Trans2FindFirst2Response extends SmbComTransactionResponse {
27
28     // information levels
29

30     static final int SMB_INFO_STANDARD = 1;
31     static final int SMB_INFO_QUERY_EA_SIZE = 2;
32     static final int SMB_INFO_QUERY_EAS_FROM_LIST = 3;
33     static final int SMB_FIND_FILE_DIRECTORY_INFO = 0x101;
34     static final int SMB_FIND_FILE_FULL_DIRECTORY_INFO = 0x102;
35     static final int SMB_FILE_NAMES_INFO = 0x103;
36     static final int SMB_FILE_BOTH_DIRECTORY_INFO = 0x104;
37
38     class SmbFindFileBothDirectoryInfo implements FileEntry {
39         int nextEntryOffset;
40         int fileIndex;
41         long creationTime;
42         long lastAccessTime;
43         long lastWriteTime;
44         long changeTime;
45         long endOfFile;
46         long allocationSize;
47         int extFileAttributes;
48         int fileNameLength;
49         int eaSize;
50         int shortNameLength;
51         String JavaDoc shortName;
52         String JavaDoc filename;
53
54         public String JavaDoc getName() {
55             return filename;
56         }
57         public int getType() {
58             return SmbFile.TYPE_FILESYSTEM;
59         }
60         public int getAttributes() {
61             return extFileAttributes;
62         }
63         public long createTime() {
64             return creationTime;
65         }
66         public long lastModified() {
67             return lastWriteTime;
68         }
69         public long length() {
70             return endOfFile;
71         }
72
73         public String JavaDoc toString() {
74             return new String JavaDoc( "SmbFindFileBothDirectoryInfo[" +
75                 "nextEntryOffset=" + nextEntryOffset +
76                 ",fileIndex=" + fileIndex +
77                 ",creationTime=" + new Date JavaDoc( creationTime ) +
78                 ",lastAccessTime=" + new Date JavaDoc( lastAccessTime ) +
79                 ",lastWriteTime=" + new Date JavaDoc( lastWriteTime ) +
80                 ",changeTime=" + new Date JavaDoc( changeTime ) +
81                 ",endOfFile=" + endOfFile +
82                 ",allocationSize=" + allocationSize +
83                 ",extFileAttributes=" + extFileAttributes +
84                 ",fileNameLength=" + fileNameLength +
85                 ",eaSize=" + eaSize +
86                 ",shortNameLength=" + shortNameLength +
87                 ",shortName=" + shortName +
88                 ",filename=" + filename + "]" );
89         }
90     }
91
92     int sid;
93     boolean isEndOfSearch;
94     int eaErrorOffset;
95     int lastNameOffset, lastNameBufferIndex;
96     String JavaDoc lastName;
97     int resumeKey;
98
99
100     Trans2FindFirst2Response() {
101         command = SMB_COM_TRANSACTION2;
102         subCommand = SmbComTransaction.TRANS2_FIND_FIRST2;
103     }
104
105     String JavaDoc readString( byte[] src, int srcIndex, int len ) {
106         String JavaDoc str = null;
107         try {
108             if( useUnicode ) {
109                 // should Unicode alignment be corrected for here?
110
str = new String JavaDoc( src, srcIndex, len, "UnicodeLittle" );
111             } else {
112
113                 /* On NT without Unicode the fileNameLength
114                  * includes the '\0' whereas on win98 it doesn't. I
115                  * guess most clients only support non-unicode so
116                  * they don't run into this.
117                  */

118
119     /* UPDATE: Maybe not! Could this be a Unicode alignment issue. I hope
120      * so. We cannot just comment out this method and use readString of
121      * ServerMessageBlock.java because the arguments are different, however
122      * one might be able to reduce this.
123      */

124
125                 if( len > 0 && src[srcIndex + len - 1] == '\0' ) {
126                     len--;
127                 }
128                 str = new String JavaDoc( src, srcIndex, len, ServerMessageBlock.OEM_ENCODING );
129             }
130         } catch( UnsupportedEncodingException JavaDoc uee ) {
131             if( DebugFile.trace )
132                 new ErrorHandler(uee);
133         }
134         return str;
135     }
136     int writeSetupWireFormat( byte[] dst, int dstIndex ) {
137         return 0;
138     }
139     int writeParametersWireFormat( byte[] dst, int dstIndex ) {
140         return 0;
141     }
142     int writeDataWireFormat( byte[] dst, int dstIndex ) {
143         return 0;
144     }
145     int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
146         return 0;
147     }
148     int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
149         int start = bufferIndex;
150
151         if( subCommand == SmbComTransaction.TRANS2_FIND_FIRST2 ) {
152             sid = readInt2( buffer, bufferIndex );
153             bufferIndex += 2;
154         }
155         numEntries = readInt2( buffer, bufferIndex );
156         bufferIndex += 2;
157         isEndOfSearch = ( buffer[bufferIndex] & 0x01 ) == 0x01 ? true : false;
158         bufferIndex += 2;
159         eaErrorOffset = readInt2( buffer, bufferIndex );
160         bufferIndex += 2;
161         lastNameOffset = readInt2( buffer, bufferIndex );
162         bufferIndex += 2;
163
164         return bufferIndex - start;
165     }
166     int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
167         int start = bufferIndex;
168         SmbFindFileBothDirectoryInfo e;
169
170         lastNameBufferIndex = bufferIndex + lastNameOffset;
171
172         results = new SmbFindFileBothDirectoryInfo[numEntries];
173         for( int i = 0; i < numEntries; i++ ) {
174             results[i] = e = new SmbFindFileBothDirectoryInfo();
175
176             e.nextEntryOffset = readInt4( buffer, bufferIndex );
177             e.fileIndex = readInt4( buffer, bufferIndex + 4 );
178             e.creationTime = readTime( buffer, bufferIndex + 8 );
179     // e.lastAccessTime = readTime( buffer, bufferIndex + 16 );
180
e.lastWriteTime = readTime( buffer, bufferIndex + 24 );
181     // e.changeTime = readTime( buffer, bufferIndex + 32 );
182
e.endOfFile = readInt8( buffer, bufferIndex + 40 );
183     // e.allocationSize = readInt8( buffer, bufferIndex + 48 );
184
e.extFileAttributes = readInt4( buffer, bufferIndex + 56 );
185             e.fileNameLength = readInt4( buffer, bufferIndex + 60 );
186     // e.eaSize = readInt4( buffer, bufferIndex + 64 );
187
// e.shortNameLength = buffer[bufferIndex + 68] & 0xFF;
188

189             /* With NT, the shortName is in Unicode regardless of what is negotiated.
190              */

191
192     // e.shortName = readString( buffer, bufferIndex + 70, e.shortNameLength );
193
e.filename = readString( buffer, bufferIndex + 94, e.fileNameLength );
194
195             /* lastNameOffset ends up pointing to either to
196              * the exact location of the filename(e.g. Win98)
197              * or to the start of the entry containing the
198              * filename(e.g. NT). Ahhrg! In either case the
199              * lastNameOffset falls between the start of the
200              * entry and the next entry.
201              */

202
203             if( lastNameBufferIndex >= bufferIndex && ( e.nextEntryOffset == 0 ||
204                         lastNameBufferIndex < ( bufferIndex + e.nextEntryOffset ))) {
205                 lastName = e.filename;
206                 resumeKey = e.fileIndex;
207             }
208
209             bufferIndex += e.nextEntryOffset;
210         }
211
212         /* last nextEntryOffset for NT 4(but not 98) is 0 so we must
213          * use dataCount or our accounting will report an error for NT :~(
214          */

215
216         //return bufferIndex - start;
217

218         return dataCount;
219     }
220     public String JavaDoc toString() {
221         String JavaDoc c;
222         if( subCommand == SmbComTransaction.TRANS2_FIND_FIRST2 ) {
223             c = "Trans2FindFirst2Response[";
224         } else {
225             c = "Trans2FindNext2Response[";
226         }
227         return new String JavaDoc( c + super.toString() +
228             ",sid=" + sid +
229             ",searchCount=" + numEntries +
230             ",isEndOfSearch=" + isEndOfSearch +
231             ",eaErrorOffset=" + eaErrorOffset +
232             ",lastNameOffset=" + lastNameOffset +
233             ",lastName=" + lastName + "]" );
234     }
235 }
236
Popular Tags