KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > smb > Trans2QueryPathInformationResponse


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.Date JavaDoc;
22 import jcifs.util.Hexdump;
23
24 class Trans2QueryPathInformationResponse extends SmbComTransactionResponse {
25
26     // information levels
27
static final int SMB_QUERY_FILE_BASIC_INFO = 0x101;
28     static final int SMB_QUERY_FILE_STANDARD_INFO = 0x102;
29
30     class SmbQueryFileBasicInfo implements Info {
31         long createTime;
32         long lastAccessTime;
33         long lastWriteTime;
34         long changeTime;
35         int attributes;
36
37         public int getAttributes() {
38             return attributes;
39         }
40         public long getCreateTime() {
41             return createTime;
42         }
43         public long getLastWriteTime() {
44             return lastWriteTime;
45         }
46         public long getSize() {
47             return 0L;
48         }
49         public String JavaDoc toString() {
50             return new String JavaDoc( "SmbQueryFileBasicInfo[" +
51                 "createTime=" + new Date JavaDoc( createTime ) +
52                 ",lastAccessTime=" + new Date JavaDoc( lastAccessTime ) +
53                 ",lastWriteTime=" + new Date JavaDoc( lastWriteTime ) +
54                 ",changeTime=" + new Date JavaDoc( changeTime ) +
55                 ",attributes=0x" + Hexdump.toHexString( attributes, 4 ) + "]" );
56         }
57     }
58     class SmbQueryFileStandardInfo implements Info {
59         long allocationSize;
60         long endOfFile;
61         int numberOfLinks;
62         boolean deletePending;
63         boolean directory;
64
65         public int getAttributes() {
66             return 0;
67         }
68         public long getCreateTime() {
69             return 0L;
70         }
71         public long getLastWriteTime() {
72             return 0L;
73         }
74         public long getSize() {
75             return endOfFile;
76         }
77         public String JavaDoc toString() {
78             return new String JavaDoc( "SmbQueryInfoStandard[" +
79                 "allocationSize=" + allocationSize +
80                 ",endOfFile=" + endOfFile +
81                 ",numberOfLinks=" + numberOfLinks +
82                 ",deletePending=" + deletePending +
83                 ",directory=" + directory + "]" );
84         }
85     }
86
87     private int informationLevel;
88
89     Info info;
90
91     Trans2QueryPathInformationResponse( int informationLevel ) {
92         this.informationLevel = informationLevel;
93         subCommand = SmbComTransaction.TRANS2_QUERY_PATH_INFORMATION;
94     }
95
96     int writeSetupWireFormat( byte[] dst, int dstIndex ) {
97         return 0;
98     }
99     int writeParametersWireFormat( byte[] dst, int dstIndex ) {
100         return 0;
101     }
102     int writeDataWireFormat( byte[] dst, int dstIndex ) {
103         return 0;
104     }
105     int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
106         return 0;
107     }
108     int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
109         // observed two zero bytes here with at least win98
110
return 2;
111     }
112     int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
113         switch( informationLevel ) {
114             case SMB_QUERY_FILE_BASIC_INFO:
115                 return readSmbQueryFileBasicInfoWireFormat( buffer, bufferIndex );
116             case SMB_QUERY_FILE_STANDARD_INFO:
117                 return readSmbQueryFileStandardInfoWireFormat( buffer, bufferIndex );
118             default:
119                 return 0;
120         }
121     }
122     int readSmbQueryFileStandardInfoWireFormat( byte[] buffer, int bufferIndex ) {
123         int start = bufferIndex;
124
125         SmbQueryFileStandardInfo info = new SmbQueryFileStandardInfo();
126         info.allocationSize = readInt8( buffer, bufferIndex );
127         bufferIndex += 8;
128         info.endOfFile = readInt8( buffer, bufferIndex );
129         bufferIndex += 8;
130         info.numberOfLinks = readInt4( buffer, bufferIndex );
131         bufferIndex += 4;
132         info.deletePending = ( buffer[bufferIndex++] & 0xFF ) > 0;
133         info.directory = ( buffer[bufferIndex++] & 0xFF ) > 0;
134         this.info = info;
135
136         return bufferIndex - start;
137     }
138     int readSmbQueryFileBasicInfoWireFormat( byte[] buffer, int bufferIndex ) {
139         int start = bufferIndex;
140
141         SmbQueryFileBasicInfo info = new SmbQueryFileBasicInfo();
142         info.createTime = readTime( buffer, bufferIndex );
143         bufferIndex += 8;
144         info.lastAccessTime = readTime( buffer, bufferIndex );
145         bufferIndex += 8;
146         info.lastWriteTime = readTime( buffer, bufferIndex );
147         bufferIndex += 8;
148         info.changeTime = readTime( buffer, bufferIndex );
149         bufferIndex += 8;
150         info.attributes = readInt2( buffer, bufferIndex );
151         bufferIndex += 2;
152         this.info = info;
153
154         return bufferIndex - start;
155     }
156     public String JavaDoc toString() {
157         return new String JavaDoc( "Trans2QueryPathInformationResponse[" +
158             super.toString() + "]" );
159     }
160 }
161
Popular Tags