KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > dcerpc > info > ShareInfo


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.dcerpc.info;
18
19 import org.alfresco.filesys.smb.dcerpc.DCEBuffer;
20 import org.alfresco.filesys.smb.dcerpc.DCEBufferException;
21 import org.alfresco.filesys.smb.dcerpc.DCEReadable;
22 import org.alfresco.filesys.smb.dcerpc.DCEWriteable;
23
24 /**
25  * Share Information Class
26  * <p>
27  * Holds the details of a share from a DCE/RPC request/response.
28  */

29 public class ShareInfo implements DCEWriteable, DCEReadable
30 {
31
32     // Information levels supported
33

34     public static final int InfoLevel0 = 0;
35     public static final int InfoLevel1 = 1;
36     public static final int InfoLevel2 = 2;
37     public static final int InfoLevel502 = 502;
38     public static final int InfoLevel1005 = 1005;
39
40     // Share types
41

42     public static final int Disk = 0x00000000;
43     public static final int PrintQueue = 0x00000001;
44     public static final int Device = 0x00000002;
45     public static final int IPC = 0x00000003;
46     public static final int Hidden = 0x80000000;
47
48     // Share permission flags
49

50     public static final int Read = 0x01;
51     public static final int Write = 0x02;
52     public static final int Create = 0x04;
53     public static final int Execute = 0x08;
54     public static final int Delete = 0x10;
55     public static final int Attrib = 0x20;
56     public static final int Perm = 0x40;
57     public static final int All = 0x7F;
58
59     // Information level
60

61     private int m_infoLevel;
62
63     // Share details
64

65     private String JavaDoc m_name;
66     private int m_type;
67     private String JavaDoc m_comment;
68
69     private int m_permissions;
70     private int m_maxUsers;
71     private int m_curUsers;
72     private String JavaDoc m_path;
73     private String JavaDoc m_password;
74
75     private int m_flags;
76
77     /**
78      * Class constructor
79      */

80     public ShareInfo()
81     {
82     }
83
84     /**
85      * Class constructor
86      *
87      * @param lev int
88      */

89     public ShareInfo(int lev)
90     {
91         m_infoLevel = lev;
92     }
93
94     /**
95      * Class constructor
96      *
97      * @param lev int
98      * @param name String
99      * @param typ int
100      * @param comment String
101      */

102     public ShareInfo(int lev, String JavaDoc name, int typ, String JavaDoc comment)
103     {
104         m_infoLevel = lev;
105         m_name = name;
106         m_type = typ;
107         m_comment = comment;
108     }
109
110     /**
111      * Return the information level
112      *
113      * @return int
114      */

115     public final int getInformationLevel()
116     {
117         return m_infoLevel;
118     }
119
120     /**
121      * Return the share name
122      *
123      * @return String
124      */

125     public final String JavaDoc getName()
126     {
127         return m_name;
128     }
129
130     /**
131      * Return the share type
132      *
133      * @return int
134      */

135     public final int getType()
136     {
137         return m_type;
138     }
139
140     /**
141      * Get the share flags
142      *
143      * @return int
144      */

145     public final int getFlags()
146     {
147         return m_flags;
148     }
149
150     /**
151      * Check if this share is a hidden/admin share
152      *
153      * @return boolean
154      */

155     public final boolean isHidden()
156     {
157         return (m_type & Hidden) != 0 ? true : false;
158     }
159
160     /**
161      * Check if this is a disk share
162      *
163      * @return boolean
164      */

165     public final boolean isDisk()
166     {
167         return (m_type & 0x0000FFFF) == Disk ? true : false;
168     }
169
170     /**
171      * Check if this is a printer share
172      *
173      * @return boolean
174      */

175     public final boolean isPrinter()
176     {
177         return (m_type & 0x0000FFFF) == PrintQueue ? true : false;
178     }
179
180     /**
181      * Check if this is a device share
182      *
183      * @return boolean
184      */

185     public final boolean isDevice()
186     {
187         return (m_type & 0x0000FFFF) == Device ? true : false;
188     }
189
190     /**
191      * Check if this is a named pipe share
192      *
193      * @return boolean
194      */

195     public final boolean isNamedPipe()
196     {
197         return (m_type & 0x0000FFFF) == IPC ? true : false;
198     }
199
200     /**
201      * Return the share permissions
202      *
203      * @return int
204      */

205     public final int getPermissions()
206     {
207         return m_permissions;
208     }
209
210     /**
211      * Return the maximum number of users allowed
212      *
213      * @return int
214      */

215     public final int getMaximumUsers()
216     {
217         return m_maxUsers;
218     }
219
220     /**
221      * Return the current number of users
222      *
223      * @return int
224      */

225     public final int getCurrentUsers()
226     {
227         return m_curUsers;
228     }
229
230     /**
231      * Return the share local path
232      *
233      * @return String
234      */

235     public final String JavaDoc getPath()
236     {
237         return m_path;
238     }
239
240     /**
241      * Return the share password
242      *
243      * @return String
244      */

245     public final String JavaDoc getPassword()
246     {
247         return m_password;
248     }
249
250     /**
251      * Return the share type as a string
252      *
253      * @return String
254      */

255     public final String JavaDoc getTypeAsString()
256     {
257
258         String JavaDoc typ = "";
259         switch (getType() & 0xFF)
260         {
261         case Disk:
262             typ = "Disk";
263             break;
264         case PrintQueue:
265             typ = "Printer";
266             break;
267         case Device:
268             typ = "Device";
269             break;
270         case IPC:
271             typ = "IPC";
272             break;
273         }
274
275         return typ;
276     }
277
278     /**
279      * Return the comment
280      *
281      * @return String
282      */

283     public final String JavaDoc getComment()
284     {
285         return m_comment;
286     }
287
288     /**
289      * Set the information level
290      *
291      * @param lev int
292      */

293     public final void setInformationLevel(int lev)
294     {
295         m_infoLevel = lev;
296     }
297
298     /**
299      * Set the share type
300      *
301      * @param int typ
302      */

303     public final void setType(int typ)
304     {
305         m_type = typ;
306     }
307
308     /**
309      * Set the share flags
310      *
311      * @param flags int
312      */

313     public final void setFlags(int flags)
314     {
315         m_flags = flags;
316     }
317
318     /**
319      * Set the share name
320      *
321      * @param name String
322      */

323     public final void setName(String JavaDoc name)
324     {
325         m_name = name;
326     }
327
328     /**
329      * Set the share comment
330      *
331      * @param str String
332      */

333     public final void setComment(String JavaDoc str)
334     {
335         m_comment = str;
336     }
337
338     /**
339      * Set the share permissions
340      *
341      * @param perm int
342      */

343     public final void setPermissions(int perm)
344     {
345         m_permissions = perm;
346     }
347
348     /**
349      * Set the maximum number of users
350      *
351      * @param maxUsers int
352      */

353     public final void setMaximumUsers(int maxUsers)
354     {
355         m_maxUsers = maxUsers;
356     }
357
358     /**
359      * Set the current number of users
360      *
361      * @param curUsers int
362      */

363     public final void setCurrentUsers(int curUsers)
364     {
365         m_curUsers = curUsers;
366     }
367
368     /**
369      * Set the local path
370      *
371      * @param path String
372      */

373     public final void setPath(String JavaDoc path)
374     {
375         m_path = path;
376     }
377
378     /**
379      * Clear all string values
380      */

381     protected final void clearStrings()
382     {
383
384         // Clear the string values
385

386         m_name = null;
387         m_comment = null;
388         m_path = null;
389         m_password = null;
390     }
391
392     /**
393      * Read the share information from the DCE/RPC buffer
394      *
395      * @param buf DCEBuffer
396      * @exception DCEBufferException
397      */

398     public void readObject(DCEBuffer buf) throws DCEBufferException
399     {
400
401         // Clear all existing strings
402

403         clearStrings();
404
405         // Unpack the share information
406

407         switch (getInformationLevel())
408         {
409
410         // Information level 0
411

412         case InfoLevel0:
413             m_name = buf.getPointer() != 0 ? "" : null;
414             break;
415
416         // Information level 1
417

418         case InfoLevel1:
419             m_name = buf.getPointer() != 0 ? "" : null;
420             m_type = buf.getInt();
421             m_comment = buf.getPointer() != 0 ? "" : null;
422             break;
423
424         // Information level 2
425

426         case InfoLevel2:
427             m_name = buf.getPointer() != 0 ? "" : null;
428             m_type = buf.getInt();
429             m_comment = buf.getPointer() != 0 ? "" : null;
430             m_permissions = buf.getInt();
431             m_maxUsers = buf.getInt();
432             m_curUsers = buf.getInt();
433             m_path = buf.getPointer() != 0 ? "" : null;
434             m_password = buf.getPointer() != 0 ? "" : null;
435             break;
436
437         // Information level 502
438

439         case InfoLevel502:
440             m_name = buf.getPointer() != 0 ? "" : null;
441             m_type = buf.getInt();
442             m_comment = buf.getPointer() != 0 ? "" : null;
443             m_permissions = buf.getInt();
444             m_maxUsers = buf.getInt();
445             m_curUsers = buf.getInt();
446             m_path = buf.getPointer() != 0 ? "" : null;
447             m_password = buf.getPointer() != 0 ? "" : null;
448
449             buf.skipBytes(4); // Reserved value
450

451             // Security descriptor
452
break;
453         }
454     }
455
456     /**
457      * Read the strings for this share from the DCE/RPC buffer
458      *
459      * @param buf DCEBuffer
460      * @exception DCEBufferException
461      */

462     public void readStrings(DCEBuffer buf) throws DCEBufferException
463     {
464
465         // Read the strings for this share information
466

467         switch (getInformationLevel())
468         {
469
470         // Information level 0
471

472         case InfoLevel0:
473             if (getName() != null)
474                 m_name = buf.getString(DCEBuffer.ALIGN_INT);
475             break;
476
477         // Information level 1
478

479         case InfoLevel1:
480             if (getName() != null)
481                 m_name = buf.getString(DCEBuffer.ALIGN_INT);
482             if (getComment() != null)
483                 m_comment = buf.getString(DCEBuffer.ALIGN_INT);
484             break;
485
486         // Information level 2 and 502
487

488         case InfoLevel2:
489         case InfoLevel502:
490             if (getName() != null)
491                 m_name = buf.getString(DCEBuffer.ALIGN_INT);
492             if (getComment() != null)
493                 m_comment = buf.getString(DCEBuffer.ALIGN_INT);
494             if (getPath() != null)
495                 m_path = buf.getString(DCEBuffer.ALIGN_INT);
496             if (getPassword() != null)
497                 m_password = buf.getString(DCEBuffer.ALIGN_INT);
498             break;
499         }
500     }
501
502     /**
503      * Write the share information to the DCE buffer
504      *
505      * @param buf DCEBuffer
506      * @param strBuf DCEBuffer
507      */

508     public void writeObject(DCEBuffer buf, DCEBuffer strBuf)
509     {
510
511         // Pack the share information
512

513         switch (getInformationLevel())
514         {
515
516         // Information level 0
517

518         case InfoLevel0:
519             buf.putPointer(true);
520             strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
521             break;
522
523         // Information level 1
524

525         case InfoLevel1:
526             buf.putPointer(true);
527             buf.putInt(getType());
528             buf.putPointer(true);
529
530             strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
531             strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true);
532             break;
533
534         // Information level 2
535

536         case InfoLevel2:
537             buf.putPointer(true);
538             buf.putInt(getType());
539             buf.putPointer(true);
540             buf.putInt(getPermissions());
541             buf.putInt(getMaximumUsers());
542             buf.putInt(getCurrentUsers());
543             buf.putPointer(getPath() != null);
544             buf.putPointer(getPassword() != null);
545
546             strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
547             strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true);
548             if (getPath() != null)
549                 strBuf.putString(getPath(), DCEBuffer.ALIGN_INT, true);
550             if (getPassword() != null)
551                 strBuf.putString(getPassword(), DCEBuffer.ALIGN_INT, true);
552             break;
553
554         // Information level 502
555

556         case InfoLevel502:
557             buf.putPointer(true);
558             buf.putInt(getType());
559             buf.putPointer(true);
560             buf.putInt(getPermissions());
561             buf.putInt(getMaximumUsers());
562             buf.putInt(getCurrentUsers());
563             buf.putPointer(getPath() != null);
564             buf.putPointer(getPassword() != null);
565             buf.putInt(0); // Reserved, must be zero
566
buf.putPointer(false); // Security descriptor
567

568             strBuf.putString(getName(), DCEBuffer.ALIGN_INT, true);
569             strBuf.putString(getComment() != null ? getComment() : "", DCEBuffer.ALIGN_INT, true);
570             if (getPath() != null)
571                 strBuf.putString(getPath(), DCEBuffer.ALIGN_INT, true);
572             if (getPassword() != null)
573                 strBuf.putString(getPassword(), DCEBuffer.ALIGN_INT, true);
574             break;
575
576         // Information level 1005
577

578         case InfoLevel1005:
579             buf.putInt(getFlags());
580             break;
581         }
582     }
583
584     /**
585      * Return the share information as a string
586      *
587      * @return String
588      */

589     public String JavaDoc toString()
590     {
591         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
592
593         str.append("[");
594         str.append(getName());
595         str.append(":");
596         str.append(getInformationLevel());
597         str.append(":");
598
599         if (getInformationLevel() == 1)
600         {
601             str.append("0x");
602             str.append(Integer.toHexString(getType()));
603             str.append(",");
604             str.append(getComment());
605         }
606
607         str.append("]");
608         return str.toString();
609     }
610 }
611
Popular Tags