KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > smb > Trans2GetDfsReferralResponse


1 /* jcifs smb client library in Java
2  * Copyright (C) 2003 "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
23 class Trans2GetDfsReferralResponse extends SmbComTransactionResponse {
24
25     class Referral {
26         private int version;
27         private int size;
28         private int serverType;
29         private int flags;
30         private int proximity;
31         private int ttl;
32         private int pathOffset;
33         private int altPathOffset;
34         private int nodeOffset;
35         private String JavaDoc path = null;
36         private String JavaDoc altPath;
37
38         String JavaDoc node;
39
40         int readWireFormat( byte[] buffer, int bufferIndex, int len ) {
41             int start = bufferIndex;
42
43             version = readInt2( buffer, bufferIndex );
44 if( version != 3 && version != 1 ) {
45     throw new RuntimeException JavaDoc( "Version " + version + " referral not supported. Please report this to jcifs at samba dot org." );
46 }
47             bufferIndex += 2;
48             size = readInt2( buffer, bufferIndex );
49             bufferIndex += 2;
50             serverType = readInt2( buffer, bufferIndex );
51             bufferIndex += 2;
52             flags = readInt2( buffer, bufferIndex );
53             bufferIndex += 2;
54             if( version == 3 ) {
55                 proximity = readInt2( buffer, bufferIndex );
56                 bufferIndex += 2;
57                 ttl = readInt2( buffer, bufferIndex );
58                 bufferIndex += 2;
59                 pathOffset = readInt2( buffer, bufferIndex );
60                 bufferIndex += 2;
61                 altPathOffset = readInt2( buffer, bufferIndex );
62                 bufferIndex += 2;
63                 nodeOffset = readInt2( buffer, bufferIndex );
64                 bufferIndex += 2;
65
66                 path = readString( buffer, start + pathOffset, len, (flags2 & FLAGS2_UNICODE) != 0);
67                 node = readString( buffer, start + nodeOffset, len, (flags2 & FLAGS2_UNICODE) != 0);
68             } else if( version == 1 ) {
69                 node = readString( buffer, bufferIndex, len, (flags2 & FLAGS2_UNICODE) != 0);
70             }
71
72             return size;
73         }
74
75         public String JavaDoc toString() {
76             return new String JavaDoc( "Referral[" +
77                 "version=" + version + ",size=" + size +
78                 ",serverType=" + serverType + ",flags=" + flags +
79                 ",proximity=" + proximity + ",ttl=" + ttl +
80                 ",pathOffset=" + pathOffset + ",altPathOffset=" + altPathOffset +
81                 ",nodeOffset=" + nodeOffset + ",path=" + path + ",altPath=" + altPath +
82                 ",node=" + node + "]" );
83         }
84     }
85
86     int pathConsumed;
87     int numReferrals;
88     int flags;
89     Referral referral;
90
91     Trans2GetDfsReferralResponse() {
92         subCommand = SmbComTransaction.TRANS2_GET_DFS_REFERRAL;
93     }
94
95     int writeSetupWireFormat( byte[] dst, int dstIndex ) {
96         return 0;
97     }
98     int writeParametersWireFormat( byte[] dst, int dstIndex ) {
99         return 0;
100     }
101     int writeDataWireFormat( byte[] dst, int dstIndex ) {
102         return 0;
103     }
104     int readSetupWireFormat( byte[] buffer, int bufferIndex, int len ) {
105         return 0;
106     }
107     int readParametersWireFormat( byte[] buffer, int bufferIndex, int len ) {
108         return 0;
109     }
110     int readDataWireFormat( byte[] buffer, int bufferIndex, int len ) {
111         int start = bufferIndex;
112
113         pathConsumed = readInt2( buffer, bufferIndex );
114         bufferIndex += 2;
115             /* Samba 2.2.8a will reply with Unicode paths even though
116              * ASCII is negotiated so we must use flags2 (probably
117              * should anyway).
118              */

119         if((flags2 & FLAGS2_UNICODE) != 0) {
120             pathConsumed /= 2;
121         }
122         numReferrals = readInt2( buffer, bufferIndex );
123         bufferIndex += 2;
124         flags = readInt2( buffer, bufferIndex );
125         bufferIndex += 4;
126
127         referral = new Referral();
128         while( numReferrals-- > 0 ) {
129             bufferIndex += referral.readWireFormat( buffer, bufferIndex, len );
130         }
131         if (referral.path != null && referral.path.charAt( pathConsumed - 1 ) == '\\' ) {
132             pathConsumed--;
133         }
134
135         return bufferIndex - start;
136     }
137     public String JavaDoc toString() {
138         return new String JavaDoc( "Trans2GetDfsReferralResponse[" +
139             super.toString() + ",pathConsumed=" + pathConsumed +
140             ",numReferrals=" + numReferrals + ",flags=" + flags +
141             "," + referral + "]" );
142     }
143 }
144
Popular Tags