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 com.knowgate.jcifs.smb;
020:
021: import java.util.Date;
022:
023: import com.knowgate.misc.Gadgets;
024:
025: class Trans2QueryPathInformationResponse extends
026: SmbComTransactionResponse {
027:
028: // information levels
029: static final int SMB_QUERY_FILE_BASIC_INFO = 0x101;
030: static final int SMB_QUERY_FILE_STANDARD_INFO = 0x102;
031:
032: class SmbQueryFileBasicInfo implements Info {
033: long createTime;
034: long lastAccessTime;
035: long lastWriteTime;
036: long changeTime;
037: int attributes;
038:
039: public int getAttributes() {
040: return attributes;
041: }
042:
043: public long getCreateTime() {
044: return createTime;
045: }
046:
047: public long getLastWriteTime() {
048: return lastWriteTime;
049: }
050:
051: public long getSize() {
052: return 0L;
053: }
054:
055: public String toString() {
056: return new String("SmbQueryFileBasicInfo[" + "createTime="
057: + new Date(createTime) + ",lastAccessTime="
058: + new Date(lastAccessTime) + ",lastWriteTime="
059: + new Date(lastWriteTime) + ",changeTime="
060: + new Date(changeTime) + ",attributes=0x"
061: + Gadgets.toHexString(attributes, 4) + "]");
062: }
063: }
064:
065: class SmbQueryFileStandardInfo implements Info {
066: long allocationSize;
067: long endOfFile;
068: int numberOfLinks;
069: boolean deletePending;
070: boolean directory;
071:
072: public int getAttributes() {
073: return 0;
074: }
075:
076: public long getCreateTime() {
077: return 0L;
078: }
079:
080: public long getLastWriteTime() {
081: return 0L;
082: }
083:
084: public long getSize() {
085: return endOfFile;
086: }
087:
088: public String toString() {
089: return new String("SmbQueryInfoStandard["
090: + "allocationSize=" + allocationSize
091: + ",endOfFile=" + endOfFile + ",numberOfLinks="
092: + numberOfLinks + ",deletePending=" + deletePending
093: + ",directory=" + directory + "]");
094: }
095: }
096:
097: private int informationLevel;
098:
099: Info info;
100:
101: Trans2QueryPathInformationResponse(int informationLevel) {
102: this .informationLevel = informationLevel;
103: subCommand = SmbComTransaction.TRANS2_QUERY_PATH_INFORMATION;
104: }
105:
106: int writeSetupWireFormat(byte[] dst, int dstIndex) {
107: return 0;
108: }
109:
110: int writeParametersWireFormat(byte[] dst, int dstIndex) {
111: return 0;
112: }
113:
114: int writeDataWireFormat(byte[] dst, int dstIndex) {
115: return 0;
116: }
117:
118: int readSetupWireFormat(byte[] buffer, int bufferIndex, int len) {
119: return 0;
120: }
121:
122: int readParametersWireFormat(byte[] buffer, int bufferIndex, int len) {
123: // observed two zero bytes here with at least win98
124: return 2;
125: }
126:
127: int readDataWireFormat(byte[] buffer, int bufferIndex, int len) {
128: switch (informationLevel) {
129: case SMB_QUERY_FILE_BASIC_INFO:
130: return readSmbQueryFileBasicInfoWireFormat(buffer,
131: bufferIndex);
132: case SMB_QUERY_FILE_STANDARD_INFO:
133: return readSmbQueryFileStandardInfoWireFormat(buffer,
134: bufferIndex);
135: default:
136: return 0;
137: }
138: }
139:
140: int readSmbQueryFileStandardInfoWireFormat(byte[] buffer,
141: int bufferIndex) {
142: int start = bufferIndex;
143:
144: SmbQueryFileStandardInfo info = new SmbQueryFileStandardInfo();
145: info.allocationSize = readInt8(buffer, bufferIndex);
146: bufferIndex += 8;
147: info.endOfFile = readInt8(buffer, bufferIndex);
148: bufferIndex += 8;
149: info.numberOfLinks = readInt4(buffer, bufferIndex);
150: bufferIndex += 4;
151: info.deletePending = (buffer[bufferIndex++] & 0xFF) > 0;
152: info.directory = (buffer[bufferIndex++] & 0xFF) > 0;
153: this .info = info;
154:
155: return bufferIndex - start;
156: }
157:
158: int readSmbQueryFileBasicInfoWireFormat(byte[] buffer,
159: int bufferIndex) {
160: int start = bufferIndex;
161:
162: SmbQueryFileBasicInfo info = new SmbQueryFileBasicInfo();
163: info.createTime = readTime(buffer, bufferIndex);
164: bufferIndex += 8;
165: info.lastAccessTime = readTime(buffer, bufferIndex);
166: bufferIndex += 8;
167: info.lastWriteTime = readTime(buffer, bufferIndex);
168: bufferIndex += 8;
169: info.changeTime = readTime(buffer, bufferIndex);
170: bufferIndex += 8;
171: info.attributes = readInt2(buffer, bufferIndex);
172: bufferIndex += 2;
173: this .info = info;
174:
175: return bufferIndex - start;
176: }
177:
178: public String toString() {
179: return new String("Trans2QueryPathInformationResponse["
180: + super .toString() + "]");
181: }
182: }
|