001: /* jcifs smb client library in Java
002: * Copyright (C) 2003 "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:
023: class Trans2GetDfsReferralResponse extends SmbComTransactionResponse {
024:
025: class Referral {
026: private int version;
027: private int size;
028: private int serverType;
029: private int flags;
030: private int proximity;
031: private int ttl;
032: private int pathOffset;
033: private int altPathOffset;
034: private int nodeOffset;
035: private String path = null;
036: private String altPath;
037:
038: String node;
039:
040: int readWireFormat(byte[] buffer, int bufferIndex, int len) {
041: int start = bufferIndex;
042:
043: version = readInt2(buffer, bufferIndex);
044: if (version != 3 && version != 1) {
045: throw new RuntimeException(
046: "Version "
047: + version
048: + " referral not supported. Please report this to jcifs at samba dot org.");
049: }
050: bufferIndex += 2;
051: size = readInt2(buffer, bufferIndex);
052: bufferIndex += 2;
053: serverType = readInt2(buffer, bufferIndex);
054: bufferIndex += 2;
055: flags = readInt2(buffer, bufferIndex);
056: bufferIndex += 2;
057: if (version == 3) {
058: proximity = readInt2(buffer, bufferIndex);
059: bufferIndex += 2;
060: ttl = readInt2(buffer, bufferIndex);
061: bufferIndex += 2;
062: pathOffset = readInt2(buffer, bufferIndex);
063: bufferIndex += 2;
064: altPathOffset = readInt2(buffer, bufferIndex);
065: bufferIndex += 2;
066: nodeOffset = readInt2(buffer, bufferIndex);
067: bufferIndex += 2;
068:
069: path = readString(buffer, start + pathOffset, len,
070: (flags2 & FLAGS2_UNICODE) != 0);
071: node = readString(buffer, start + nodeOffset, len,
072: (flags2 & FLAGS2_UNICODE) != 0);
073: } else if (version == 1) {
074: node = readString(buffer, bufferIndex, len,
075: (flags2 & FLAGS2_UNICODE) != 0);
076: }
077:
078: return size;
079: }
080:
081: public String toString() {
082: return new String("Referral[" + "version=" + version
083: + ",size=" + size + ",serverType=" + serverType
084: + ",flags=" + flags + ",proximity=" + proximity
085: + ",ttl=" + ttl + ",pathOffset=" + pathOffset
086: + ",altPathOffset=" + altPathOffset
087: + ",nodeOffset=" + nodeOffset + ",path=" + path
088: + ",altPath=" + altPath + ",node=" + node + "]");
089: }
090: }
091:
092: int pathConsumed;
093: int numReferrals;
094: int flags;
095: Referral referral;
096:
097: Trans2GetDfsReferralResponse() {
098: subCommand = SmbComTransaction.TRANS2_GET_DFS_REFERRAL;
099: }
100:
101: int writeSetupWireFormat(byte[] dst, int dstIndex) {
102: return 0;
103: }
104:
105: int writeParametersWireFormat(byte[] dst, int dstIndex) {
106: return 0;
107: }
108:
109: int writeDataWireFormat(byte[] dst, int dstIndex) {
110: return 0;
111: }
112:
113: int readSetupWireFormat(byte[] buffer, int bufferIndex, int len) {
114: return 0;
115: }
116:
117: int readParametersWireFormat(byte[] buffer, int bufferIndex, int len) {
118: return 0;
119: }
120:
121: int readDataWireFormat(byte[] buffer, int bufferIndex, int len) {
122: int start = bufferIndex;
123:
124: pathConsumed = readInt2(buffer, bufferIndex);
125: bufferIndex += 2;
126: /* Samba 2.2.8a will reply with Unicode paths even though
127: * ASCII is negotiated so we must use flags2 (probably
128: * should anyway).
129: */
130: if ((flags2 & FLAGS2_UNICODE) != 0) {
131: pathConsumed /= 2;
132: }
133: numReferrals = readInt2(buffer, bufferIndex);
134: bufferIndex += 2;
135: flags = readInt2(buffer, bufferIndex);
136: bufferIndex += 4;
137:
138: referral = new Referral();
139: while (numReferrals-- > 0) {
140: bufferIndex += referral.readWireFormat(buffer, bufferIndex,
141: len);
142: }
143: if (referral.path != null
144: && referral.path.charAt(pathConsumed - 1) == '\\') {
145: pathConsumed--;
146: }
147:
148: return bufferIndex - start;
149: }
150:
151: public String toString() {
152: return new String("Trans2GetDfsReferralResponse["
153: + super .toString() + ",pathConsumed=" + pathConsumed
154: + ",numReferrals=" + numReferrals + ",flags=" + flags
155: + "," + referral + "]");
156: }
157: }
|