KickJava   Java API By Example, From Geeks To Geeks.

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