001: /* jcifs smb client library in Java
002: * Copyright (C) 2000 "Michael B. Allen" <jcifs at samba dot org>
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package jcifs.smb;
020:
021: import java.util.Date;
022: import jcifs.util.Hexdump;
023:
024: class Trans2QueryPathInformationResponse extends
025: SmbComTransactionResponse {
026:
027: // information levels
028: static final int SMB_QUERY_FILE_BASIC_INFO = 0x101;
029: static final int SMB_QUERY_FILE_STANDARD_INFO = 0x102;
030:
031: class SmbQueryFileBasicInfo implements Info {
032: long createTime;
033: long lastAccessTime;
034: long lastWriteTime;
035: long changeTime;
036: int attributes;
037:
038: public int getAttributes() {
039: return attributes;
040: }
041:
042: public long getCreateTime() {
043: return createTime;
044: }
045:
046: public long getLastWriteTime() {
047: return lastWriteTime;
048: }
049:
050: public long getSize() {
051: return 0L;
052: }
053:
054: public String toString() {
055: return new String("SmbQueryFileBasicInfo[" + "createTime="
056: + new Date(createTime) + ",lastAccessTime="
057: + new Date(lastAccessTime) + ",lastWriteTime="
058: + new Date(lastWriteTime) + ",changeTime="
059: + new Date(changeTime) + ",attributes=0x"
060: + Hexdump.toHexString(attributes, 4) + "]");
061: }
062: }
063:
064: class SmbQueryFileStandardInfo implements Info {
065: long allocationSize;
066: long endOfFile;
067: int numberOfLinks;
068: boolean deletePending;
069: boolean directory;
070:
071: public int getAttributes() {
072: return 0;
073: }
074:
075: public long getCreateTime() {
076: return 0L;
077: }
078:
079: public long getLastWriteTime() {
080: return 0L;
081: }
082:
083: public long getSize() {
084: return endOfFile;
085: }
086:
087: public String toString() {
088: return new String("SmbQueryInfoStandard["
089: + "allocationSize=" + allocationSize
090: + ",endOfFile=" + endOfFile + ",numberOfLinks="
091: + numberOfLinks + ",deletePending=" + deletePending
092: + ",directory=" + directory + "]");
093: }
094: }
095:
096: private int informationLevel;
097:
098: Info info;
099:
100: Trans2QueryPathInformationResponse(int informationLevel) {
101: this .informationLevel = informationLevel;
102: subCommand = SmbComTransaction.TRANS2_QUERY_PATH_INFORMATION;
103: }
104:
105: int writeSetupWireFormat(byte[] dst, int dstIndex) {
106: return 0;
107: }
108:
109: int writeParametersWireFormat(byte[] dst, int dstIndex) {
110: return 0;
111: }
112:
113: int writeDataWireFormat(byte[] dst, int dstIndex) {
114: return 0;
115: }
116:
117: int readSetupWireFormat(byte[] buffer, int bufferIndex, int len) {
118: return 0;
119: }
120:
121: int readParametersWireFormat(byte[] buffer, int bufferIndex, int len) {
122: // observed two zero bytes here with at least win98
123: return 2;
124: }
125:
126: int readDataWireFormat(byte[] buffer, int bufferIndex, int len) {
127: switch (informationLevel) {
128: case SMB_QUERY_FILE_BASIC_INFO:
129: return readSmbQueryFileBasicInfoWireFormat(buffer,
130: bufferIndex);
131: case SMB_QUERY_FILE_STANDARD_INFO:
132: return readSmbQueryFileStandardInfoWireFormat(buffer,
133: bufferIndex);
134: default:
135: return 0;
136: }
137: }
138:
139: int readSmbQueryFileStandardInfoWireFormat(byte[] buffer,
140: int bufferIndex) {
141: int start = bufferIndex;
142:
143: SmbQueryFileStandardInfo info = new SmbQueryFileStandardInfo();
144: info.allocationSize = readInt8(buffer, bufferIndex);
145: bufferIndex += 8;
146: info.endOfFile = readInt8(buffer, bufferIndex);
147: bufferIndex += 8;
148: info.numberOfLinks = readInt4(buffer, bufferIndex);
149: bufferIndex += 4;
150: info.deletePending = (buffer[bufferIndex++] & 0xFF) > 0;
151: info.directory = (buffer[bufferIndex++] & 0xFF) > 0;
152: this .info = info;
153:
154: return bufferIndex - start;
155: }
156:
157: int readSmbQueryFileBasicInfoWireFormat(byte[] buffer,
158: int bufferIndex) {
159: int start = bufferIndex;
160:
161: SmbQueryFileBasicInfo info = new SmbQueryFileBasicInfo();
162: info.createTime = readTime(buffer, bufferIndex);
163: bufferIndex += 8;
164: info.lastAccessTime = readTime(buffer, bufferIndex);
165: bufferIndex += 8;
166: info.lastWriteTime = readTime(buffer, bufferIndex);
167: bufferIndex += 8;
168: info.changeTime = readTime(buffer, bufferIndex);
169: bufferIndex += 8;
170: info.attributes = readInt2(buffer, bufferIndex);
171: bufferIndex += 2;
172: this .info = info;
173:
174: return bufferIndex - start;
175: }
176:
177: public String toString() {
178: return new String("Trans2QueryPathInformationResponse["
179: + super .toString() + "]");
180: }
181: }
|