KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > SrvTransactBuffer


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.server;
18
19 import org.alfresco.filesys.smb.PacketType;
20 import org.alfresco.filesys.smb.TransactBuffer;
21 import org.alfresco.filesys.util.DataBuffer;
22 import org.alfresco.filesys.util.DataPacker;
23
24 /**
25  * Transact Buffer Class
26  * <p>
27  * Contains the parameters and data for a transaction, transaction2 or NT transaction request.
28  */

29 class SrvTransactBuffer extends TransactBuffer
30 {
31
32     /**
33      * Class constructor
34      *
35      * @param slen int
36      * @param plen int
37      * @param dlen int
38      */

39     public SrvTransactBuffer(int slen, int plen, int dlen)
40     {
41         super(slen, plen, dlen);
42     }
43
44     /**
45      * Class constructor
46      * <p>
47      * Construct a TransactBuffer using the maximum size settings from the specified transaction
48      * buffer
49      *
50      * @param tbuf SrvTransactBuffer
51      */

52     public SrvTransactBuffer(SrvTransactBuffer tbuf)
53     {
54         super(tbuf.getReturnSetupLimit(), tbuf.getReturnParameterLimit(), tbuf.getReturnDataLimit());
55
56         // Save the return limits for this transaction buffer
57

58         setReturnLimits(tbuf.getReturnSetupLimit(), tbuf.getReturnParameterLimit(), tbuf.getReturnDataLimit());
59
60         // Set the transaction reply type
61

62         setType(tbuf.isType());
63
64         // Copy the tree id
65

66         setTreeId(tbuf.getTreeId());
67     }
68
69     /**
70      * Class constructor
71      *
72      * @param ntpkt NTTransPacket
73      */

74     public SrvTransactBuffer(NTTransPacket ntpkt)
75     {
76
77         // Call the base constructor so that it does not allocate any buffers
78

79         super(0, 0, 0);
80
81         // Set the tree id
82

83         setTreeId(ntpkt.getTreeId());
84
85         // Set the setup block and size
86

87         int slen = ntpkt.getSetupCount() * 2;
88         if (slen > 0)
89             m_setupBuf = new DataBuffer(ntpkt.getBuffer(), ntpkt.getSetupOffset(), slen);
90
91         // Set the parameter block and size
92

93         int plen = ntpkt.getTotalParameterCount();
94         if (plen > 0)
95             m_paramBuf = new DataBuffer(ntpkt.getBuffer(), ntpkt.getParameterBlockOffset(), plen);
96
97         // Set the data block and size
98

99         int dlen = ntpkt.getDataBlockCount();
100         if (dlen > 0)
101             m_dataBuf = new DataBuffer(ntpkt.getBuffer(), ntpkt.getDataBlockOffset(), dlen);
102
103         // Set the transaction type and sub-function
104

105         setType(ntpkt.getCommand());
106         setFunction(ntpkt.getNTFunction());
107
108         // Set the maximum parameter and data block lengths to be returned
109

110         setReturnParameterLimit(ntpkt.getMaximumParameterReturn());
111         setReturnDataLimit(ntpkt.getMaximumDataReturn());
112
113         // Set the Unicode flag
114

115         setUnicode(ntpkt.isUnicode());
116
117         // Indicate that this is a not a multi-packet transaction
118

119         m_multi = false;
120     }
121
122     /**
123      * Class constructor
124      *
125      * @param tpkt SMBSrvTransPacket
126      */

127     public SrvTransactBuffer(SMBSrvTransPacket tpkt)
128     {
129
130         // Call the base constructor so that it does not allocate any buffers
131

132         super(0, 0, 0);
133
134         // Set the tree id
135

136         setTreeId(tpkt.getTreeId());
137
138         // Set the setup block and size
139

140         int slen = tpkt.getSetupCount() * 2;
141         if (slen > 0)
142             m_setupBuf = new DataBuffer(tpkt.getBuffer(), tpkt.getSetupOffset(), slen);
143
144         // Set the parameter block and size
145

146         int plen = tpkt.getTotalParameterCount();
147         if (plen > 0)
148             m_paramBuf = new DataBuffer(tpkt.getBuffer(), tpkt.getRxParameterBlock(), plen);
149
150         // Set the data block and size
151

152         int dlen = tpkt.getRxDataBlockLength();
153         if (dlen > 0)
154             m_dataBuf = new DataBuffer(tpkt.getBuffer(), tpkt.getRxDataBlock(), dlen);
155
156         // Set the transaction type and sub-function
157

158         setType(tpkt.getCommand());
159
160         if (tpkt.getSetupCount() > 0)
161             setFunction(tpkt.getSetupParameter(0));
162
163         // Set the Unicode flag
164

165         setUnicode(tpkt.isUnicode());
166
167         // Get the transaction name, if used
168

169         if (isType() == PacketType.Transaction)
170         {
171
172             // Unpack the transaction name string
173

174             int pos = tpkt.getByteOffset();
175             byte[] buf = tpkt.getBuffer();
176
177             if (isUnicode())
178                 pos = DataPacker.wordAlign(pos);
179
180             setName(DataPacker.getString(buf, pos, 64, isUnicode()));
181         }
182         else
183             setName("");
184
185         // Indicate that this is a not a multi-packet transaction
186

187         m_multi = false;
188     }
189 }
190
Popular Tags