comparison src/ch/ethz/ssh2/SFTPv6FileAttributes.java @ 308:42b15aaa7ac7 ganymed

merge
author Carl Byington <carl@five-ten-sg.com>
date Wed, 30 Jul 2014 14:21:50 -0700
parents 071eccdff8ea
children
comparison
equal deleted inserted replaced
306:90e47d99ea54 308:42b15aaa7ac7
171 */ 171 */
172 public SFTPv6FileAttributes(final TypesReader tr) throws IOException { 172 public SFTPv6FileAttributes(final TypesReader tr) throws IOException {
173 int flags = tr.readUINT32(); 173 int flags = tr.readUINT32();
174 // The type field is always present 174 // The type field is always present
175 this.type = tr.readByte(); 175 this.type = tr.readByte();
176 if((flags & AttribFlags.SSH_FILEXFER_ATTR_SIZE) != 0) { 176
177 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_SIZE) != 0) {
177 this.size = tr.readUINT64(); 178 this.size = tr.readUINT64();
178 } 179 }
179 if((flags & AttribFlags.SSH_FILEXFER_ATTR_ALLOCATION_SIZE) != 0) { 180
181 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_ALLOCATION_SIZE) != 0) {
180 // Ignore 182 // Ignore
181 tr.readUINT64(); 183 tr.readUINT64();
182 } 184 }
183 if((flags & AttribFlags.SSH_FILEXFER_ATTR_OWNERGROUP) != 0) { 185
186 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_OWNERGROUP) != 0) {
184 this.owner = tr.readString(); 187 this.owner = tr.readString();
185 this.group = tr.readString(); 188 this.group = tr.readString();
186 } 189 }
187 if((flags & AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS) != 0) { 190
191 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS) != 0) {
188 this.permissions = tr.readUINT32(); 192 this.permissions = tr.readUINT32();
189 } 193 }
190 if((flags & AttribFlags.SSH_FILEXFER_ATTR_ACCESSTIME) != 0) { 194
195 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_ACCESSTIME) != 0) {
191 this.atime = tr.readUINT64(); 196 this.atime = tr.readUINT64();
192 } 197 }
193 if((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) { 198
194 // Ignore 199 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) {
195 tr.readUINT32(); 200 // Ignore
196 } 201 tr.readUINT32();
197 if((flags & AttribFlags.SSH_FILEXFER_ATTR_CREATETIME) != 0) { 202 }
203
204 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_CREATETIME) != 0) {
198 this.createtime = tr.readUINT64(); 205 this.createtime = tr.readUINT64();
199 } 206 }
200 if((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) { 207
201 // Ignore 208 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) {
202 tr.readUINT32(); 209 // Ignore
203 } 210 tr.readUINT32();
204 if((flags & AttribFlags.SSH_FILEXFER_ATTR_MODIFYTIME) != 0) { 211 }
212
213 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_MODIFYTIME) != 0) {
205 this.mtime = tr.readUINT64(); 214 this.mtime = tr.readUINT64();
206 } 215 }
207 if((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) { 216
208 // Ignore 217 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) {
209 tr.readUINT32(); 218 // Ignore
210 } 219 tr.readUINT32();
211 if((flags & AttribFlags.SSH_FILEXFER_ATTR_CTIME) != 0) { 220 }
221
222 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_CTIME) != 0) {
212 this.ctime = tr.readUINT64(); 223 this.ctime = tr.readUINT64();
213 } 224 }
214 if((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) { 225
215 // Ignore 226 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_SUBSECOND_TIMES) != 0) {
216 tr.readUINT32(); 227 // Ignore
217 } 228 tr.readUINT32();
218 if((flags & AttribFlags.SSH_FILEXFER_ATTR_ACL) != 0) { 229 }
230
231 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_ACL) != 0) {
219 // Ignore 232 // Ignore
220 tr.readString(); 233 tr.readString();
221 } 234 }
222 if((flags & AttribFlags.SSH_FILEXFER_ATTR_BITS) != 0) { 235
236 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_BITS) != 0) {
223 // Ignore attrib-bits 237 // Ignore attrib-bits
224 tr.readUINT32(); 238 tr.readUINT32();
225 // Ignore attrib-bits-valid 239 // Ignore attrib-bits-valid
226 tr.readUINT32(); 240 tr.readUINT32();
227 } 241 }
228 if((flags & AttribFlags.SSH_FILEXFER_ATTR_TEXT_HINT) != 0) { 242
243 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_TEXT_HINT) != 0) {
229 // Ignore 244 // Ignore
230 tr.readByte(); 245 tr.readByte();
231 } 246 }
232 if((flags & AttribFlags.SSH_FILEXFER_ATTR_MIME_TYPE) != 0) { 247
248 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_MIME_TYPE) != 0) {
233 // Ignore 249 // Ignore
234 tr.readString(); 250 tr.readString();
235 } 251 }
236 if((flags & AttribFlags.SSH_FILEXFER_ATTR_LINK_COUNT) != 0) { 252
237 // Ignore 253 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_LINK_COUNT) != 0) {
238 tr.readUINT32(); 254 // Ignore
239 } 255 tr.readUINT32();
240 if((flags & AttribFlags.SSH_FILEXFER_ATTR_UNTRANSLATED_NAME) != 0) { 256 }
257
258 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_UNTRANSLATED_NAME) != 0) {
241 // Ignore 259 // Ignore
242 tr.readString(); 260 tr.readString();
243 } 261 }
244 if((flags & AttribFlags.SSH_FILEXFER_ATTR_EXTENDED) != 0) { 262
263 if ((flags & AttribFlags.SSH_FILEXFER_ATTR_EXTENDED) != 0) {
245 int count = tr.readUINT32(); 264 int count = tr.readUINT32();
265
246 // Read it anyway to detect corrupt packets 266 // Read it anyway to detect corrupt packets
247 while(count > 0) { 267 while (count > 0) {
248 // extension-name 268 // extension-name
249 tr.readByteString(); 269 tr.readByteString();
250 // extension-data 270 // extension-data
251 tr.readByteString(); 271 tr.readByteString();
252 count--; 272 count--;
264 public byte[] toBytes() { 284 public byte[] toBytes() {
265 TypesWriter tw = new TypesWriter(); 285 TypesWriter tw = new TypesWriter();
266 // The 'valid-attribute-flags' specifies which of the fields are present. Those fields 286 // The 'valid-attribute-flags' specifies which of the fields are present. Those fields
267 // for which the corresponding flag is not set are not present 287 // for which the corresponding flag is not set are not present
268 int attrFlags = 0; 288 int attrFlags = 0;
269 if(this.size != null) { 289
290 if (this.size != null) {
270 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_SIZE; 291 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_SIZE;
271 } 292 }
272 if((this.owner != null) && (this.group != null)) { 293
294 if ((this.owner != null) && (this.group != null)) {
273 // If either the owner or group field is zero length, the field should 295 // If either the owner or group field is zero length, the field should
274 // be considered absent, and no change should be made to that specific 296 // be considered absent, and no change should be made to that specific
275 // field during a modification operation. 297 // field during a modification operation.
276 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_OWNERGROUP; 298 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_OWNERGROUP;
277 } 299 }
278 if(this.permissions != null) { 300
301 if (this.permissions != null) {
279 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS; 302 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_PERMISSIONS;
280 } 303 }
281 if(this.atime != null) { 304
305 if (this.atime != null) {
282 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_ACCESSTIME; 306 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_ACCESSTIME;
283 } 307 }
284 if(this.createtime != null) { 308
309 if (this.createtime != null) {
285 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_CREATETIME; 310 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_CREATETIME;
286 } 311 }
287 if(this.mtime != null) { 312
313 if (this.mtime != null) {
288 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_MODIFYTIME; 314 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_MODIFYTIME;
289 } 315 }
290 if(this.ctime != null) { 316
317 if (this.ctime != null) {
291 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_CTIME; 318 attrFlags = attrFlags | AttribFlags.SSH_FILEXFER_ATTR_CTIME;
292 } 319 }
320
293 tw.writeUINT32(attrFlags); 321 tw.writeUINT32(attrFlags);
322
294 // The type field is always present. 323 // The type field is always present.
295 if(this.size != null) { 324 if (this.size != null) {
296 tw.writeUINT64(this.size); 325 tw.writeUINT64(this.size);
297 } 326 }
298 if((this.owner != null) && (this.group != null)) { 327
328 if ((this.owner != null) && (this.group != null)) {
299 tw.writeString(owner); 329 tw.writeString(owner);
300 tw.writeString(group); 330 tw.writeString(group);
301 } 331 }
302 if(this.permissions != null) { 332
333 if (this.permissions != null) {
303 tw.writeUINT32(this.permissions); 334 tw.writeUINT32(this.permissions);
304 } 335 }
305 if(this.atime != null) { 336
337 if (this.atime != null) {
306 tw.writeUINT64(this.atime); 338 tw.writeUINT64(this.atime);
307 } 339 }
308 if(this.createtime != null) { 340
341 if (this.createtime != null) {
309 tw.writeUINT64(this.createtime); 342 tw.writeUINT64(this.createtime);
310 } 343 }
311 if(this.mtime != null) { 344
345 if (this.mtime != null) {
312 tw.writeUINT64(this.mtime); 346 tw.writeUINT64(this.mtime);
313 } 347 }
314 if(this.ctime != null) { 348
349 if (this.ctime != null) {
315 tw.writeUINT64(this.ctime); 350 tw.writeUINT64(this.ctime);
316 } 351 }
352
317 return tw.getBytes(); 353 return tw.getBytes();
318 } 354 }
319 355
320 @Override 356 @Override
321 public String toString() { 357 public String toString() {