KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > Dialect


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.smb;
18
19 /**
20  * SMB dialect class.
21  * <p>
22  * This class contains the available SMB protocol dialects that may be negotiated when an SMB
23  * session is setup.
24  */

25
26 public final class Dialect
27 {
28
29     // SMB dialect strings, encoded into the SMB session setup packet.
30

31     private static final String JavaDoc[] protList = {
32             "PC NETWORK PROGRAM 1.0",
33             "MICROSOFT NETWORKS 1.03",
34             "MICROSOFT NETWORKS 3.0",
35             "DOS LANMAN1.0",
36             "LANMAN1.0",
37             "DOS LM1.2X002",
38             "LM1.2X002",
39             "DOS LANMAN2.1",
40             "LANMAN2.1",
41             "Samba",
42             "NT LM 0.12",
43             "NT LANMAN 1.0" };
44
45     // SMB dialect type strings
46

47     private static final String JavaDoc[] protType = {
48             "Core",
49             "CorePlus",
50             "DOS LANMAN 1.0",
51             "LANMAN1.0",
52             "DOS LANMAN 2.1",
53             "LM1.2X002",
54             "LANMAN2.1",
55             "NT LM 0.12" };
56
57     // Dialect constants
58

59     public static final int Core = 0;
60     public static final int CorePlus = 1;
61     public static final int DOSLanMan1 = 2;
62     public static final int LanMan1 = 3;
63     public static final int DOSLanMan2 = 4;
64     public static final int LanMan2 = 5;
65     public static final int LanMan2_1 = 6;
66     public static final int NT = 7;
67     public static final int Max = 8;
68
69     public static final int Unknown = -1;
70
71     // SMB dialect type to string conversion array
72

73     private static final int[] protIdx = {
74             Core,
75             CorePlus,
76             DOSLanMan1,
77             DOSLanMan1,
78             LanMan1,
79             DOSLanMan2,
80             LanMan2,
81             LanMan2_1,
82             LanMan2_1,
83             NT,
84             NT,
85             NT };
86
87     // SMB dialect type to string conversion array length
88

89     public static final int SMB_PROT_MAXSTRING = protIdx.length;
90
91     // Table that maps SMB commands to the minimum required SMB dialect
92

93     private static final int[] cmdtable = {
94             Core, // CreateDirectory
95
Core, // DeleteDirectory
96
Core, // OpenFile
97
Core, // CreateFile
98
Core, // CloseFile
99
Core, // FlushFile
100
Core, // DeleteFile
101
Core, // RenameFile
102
Core, // QueryFileInfo
103
Core, // SetFileInfo
104
Core, // Read
105
Core, // Write
106
Core, // LockFile
107
Core, // UnlockFile
108
Core, // CreateTemporary
109
Core, // CreateNew
110
Core, // CheckDirectory
111
Core, // ProcessExit
112
Core, // SeekFile
113
LanMan1, // LockAndRead
114
LanMan1, // WriteAndUnlock
115
0, // Unused
116
0, // ..
117
0, // ..
118
0, // ..
119
0, // ..
120
LanMan1, // ReadRaw
121
LanMan1, // WriteMpxSecondary
122
LanMan1, // WriteRaw
123
LanMan1, // WriteMpx
124
0, // Unused
125
LanMan1, // WriteComplete
126
0, // Unused
127
LanMan1, // SetInformation2
128
LanMan1, // QueryInformation2
129
LanMan1, // LockingAndX
130
LanMan1, // Transaction
131
LanMan1, // TransactionSecondary
132
LanMan1, // Ioctl
133
LanMan1, // Ioctl2
134
LanMan1, // Copy
135
LanMan1, // Move
136
LanMan1, // Echo
137
LanMan1, // WriteAndClose
138
LanMan1, // OpenAndX
139
LanMan1, // ReadAndX
140
LanMan1, // WriteAndX
141
0, // Unused
142
LanMan1, // CloseAndTreeDisconnect
143
LanMan2, // Transaction2
144
LanMan2, // Transaction2Secondary
145
LanMan2, // FindClose2
146
LanMan1, // FindNotifyClose
147
0, // Unused
148
0, // ..
149
0, // ..
150
0, // ..
151
0, // ..
152
0, // ..
153
0, // ..
154
0, // ..
155
0, // ..
156
0, // ..
157
0, // ..
158
0, // ..
159
0, // ..
160
0, // ..
161
0, // ..
162
0, // ..
163
0, // ..
164
0, // ..
165
0, // ..
166
0, // ..
167
0, // ..
168
0, // ..
169
0, // ..
170
0, // ..
171
0, // ..
172
0, // ..
173
0, // ..
174
0, // ..
175
0, // ..
176
0, // ..
177
0, // ..
178
0, // ..
179
0, // ..
180
0, // ..
181
0, // ..
182
0, // ..
183
0, // ..
184
0, // ..
185
0, // ..
186
0, // ..
187
0, // ..
188
0, // ..
189
0, // ..
190
0, // ..
191
0, // ..
192
0, // ..
193
0, // ..
194
0, // ..
195
0, // ..
196
0, // ..
197
0, // ..
198
0, // ..
199
0, // ..
200
0, // ..
201
0, // ..
202
0, // ..
203
0, // ..
204
0, // ..
205
0, // ..
206
Core, // TreeConnect
207
Core, // TreeDisconnect
208
Core, // Negotiate
209
Core, // SessionSetupAndX
210
LanMan1, // LogoffAndX
211
LanMan1, // TreeConnectAndX
212
0, // Unused
213
0, // ..
214
0, // ..
215
0, // ..
216
0, // ..
217
0, // ..
218
0, // ..
219
0, // ..
220
0, // ..
221
0, // ..
222
Core, // DiskInformation
223
Core, // Search
224
LanMan1, // Find
225
LanMan1, // FindUnique
226
0, // Unused
227
0, // ..
228
0, // ..
229
0, // ..
230
0, // ..
231
0, // ..
232
0, // ..
233
0, // ..
234
0, // ..
235
0, // ..
236
0, // ..
237
0, // ..
238
0, // ..
239
0, // ..
240
0, // ..
241
0, // ..
242
0, // ..
243
0, // ..
244
0, // ..
245
0, // ..
246
0, // ..
247
0, // ..
248
0, // ..
249
0, // ..
250
0, // ..
251
0, // ..
252
0, // ..
253
0, // ..
254
NT, // NTTransact
255
NT, // NTTransactSecondary
256
NT, // NTCreateAndX
257
NT, // NTCancel
258
0, // ..
259
0, // ..
260
0, // ..
261
0, // ..
262
0, // ..
263
0, // ..
264
0, // ..
265
0, // ..
266
0, // ..
267
0, // ..
268
0, // ..
269
0, // ..
270
0, // ..
271
0, // ..
272
0, // ..
273
0, // ..
274
0, // ..
275
0, // ..
276
0, // ..
277
0, // ..
278
0, // ..
279
0, // ..
280
0, // ..
281
0, // ..
282
0, // ..
283
0, // ..
284
0, // ..
285
Core, // OpenPrintFile
286
Core, // WritePrintFile
287
Core, // ClosePrintFile
288
Core, // GetPrintQueue
289
0, // ..
290
0, // ..
291
0, // ..
292
0, // ..
293
0, // ..
294
0, // ..
295
0, // ..
296
0, // ..
297
0, // ..
298
0, // ..
299
0, // ..
300
0, // ..
301
-1, // SendMessage
302
-1, // SendBroadcast
303
-1, // SendForward
304
-1, // CancelForward
305
-1, // GetMachineName
306
-1, // SendMultiStart
307
-1, // SendMultiEnd
308
-1 // SendMultiText
309
};
310
311     /**
312      * Return the required SMB dialect string.
313      *
314      * @param i SMB dialect string index.
315      * @return SMB dialect string.
316      */

317
318     public static String JavaDoc DialectString(int i)
319     {
320
321         // Validate the dialect index
322

323         if (i >= protList.length)
324             return null;
325         return protList[i];
326     }
327
328     /**
329      * Determine if the SMB dialect supports the SMB command
330      *
331      * @return boolean
332      * @param dialect int SMB dialect type.
333      * @param cmd int SMB command code.
334      */

335     public final static boolean DialectSupportsCommand(int dialect, int cmd)
336     {
337         // Range check the command
338

339         if (cmd > cmdtable.length)
340             return false;
341
342         // Check if the SMB dialect supports the SMB command.
343

344         if (cmdtable[cmd] <= dialect)
345             return true;
346         return false;
347     }
348
349     /**
350      * Return the SMB dialect type for the specified SMB dialect string index.
351      *
352      * @param i SMB dialect type.
353      * @return SMB dialect string index.
354      */

355
356     public static int DialectType(int i)
357     {
358         return protIdx[i];
359     }
360
361     /**
362      * Return the SMB dialect type for the specified string.
363      *
364      * @return int
365      * @param diastr java.lang.String
366      */

367     public static int DialectType(String JavaDoc diastr)
368     {
369
370         // Search the protocol string list
371

372         int i = 0;
373
374         while (i < protList.length && protList[i].compareTo(diastr) != 0)
375             i++;
376
377         // Return the protocol id
378

379         if (i < protList.length)
380             return DialectType(i);
381         else
382             return Unknown;
383     }
384
385     /**
386      * Return the dialect type as a string.
387      *
388      * @param dia SMB dialect type.
389      * @return SMB dialect type string.
390      */

391
392     public static String JavaDoc DialectTypeString(int dia)
393     {
394         return protType[dia];
395     }
396
397     /**
398      * Return the number of available SMB dialect strings.
399      *
400      * @return Number of available SMB dialect strings.
401      */

402
403     public static int NumberOfDialects()
404     {
405         return protList.length;
406     }
407 }
Popular Tags