KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jcifs > smb > SmbComWriteAndX


1 /* jcifs smb client library in Java
2  * Copyright (C) 2000 "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 jcifs.Config;
22
23 class SmbComWriteAndX extends AndXServerMessageBlock {
24
25     private static final int READ_ANDX_BATCH_LIMIT =
26                             Config.getInt( "jcifs.smb.client.WriteAndX.ReadAndX", 1 );
27     private static final int CLOSE_BATCH_LIMIT =
28                             Config.getInt( "jcifs.smb.client.WriteAndX.Close", 1 );
29
30     private int fid,
31         writeMode,
32         remaining,
33         dataLength,
34         dataOffset,
35         off;
36     private byte[] b;
37     private long offset;
38
39     SmbComWriteAndX() {
40         super( null );
41         command = SMB_COM_WRITE_ANDX;
42     }
43     SmbComWriteAndX( int fid, long offset, int remaining,
44                     byte[] b, int off, int len, ServerMessageBlock andx ) {
45         super( andx );
46         this.fid = fid;
47         this.offset = offset;
48         this.remaining = remaining;
49         this.b = b;
50         this.off = off;
51         dataLength = len;
52         command = SMB_COM_WRITE_ANDX;
53     }
54
55     void setParam( int fid, long offset, int remaining,
56                     byte[] b, int off, int len ) {
57         this.fid = fid;
58         this.offset = offset;
59         this.remaining = remaining;
60         this.b = b;
61         this.off = off;
62         dataLength = len;
63         digest = null; /* otherwise recycled commands
64                         * like writeandx will choke if session
65                         * closes in between */

66     }
67     int getBatchLimit( byte command ) {
68         if( command == SMB_COM_READ_ANDX ) {
69             return READ_ANDX_BATCH_LIMIT;
70         }
71         if( command == SMB_COM_CLOSE ) {
72             return CLOSE_BATCH_LIMIT;
73         }
74         return 0;
75     }
76     int writeParameterWordsWireFormat( byte[] dst, int dstIndex ) {
77         int start = dstIndex;
78
79         dataOffset = (dstIndex - headerStart) + 26; // 26 = off from here to pad
80
/*
81  * pad = ( dataOffset - headerStart ) % 4;
82  * pad = pad == 0 ? 0 : 4 - pad;
83  * dataOffset += pad;
84  */

85
86         writeInt2( fid, dst, dstIndex );
87         dstIndex += 2;
88         writeInt4( offset, dst, dstIndex );
89         dstIndex += 4;
90         for( int i = 0; i < 4; i++ ) {
91             dst[dstIndex++] = (byte)0x00;
92         }
93         writeInt2( writeMode, dst, dstIndex );
94         dstIndex += 2;
95         writeInt2( remaining, dst, dstIndex );
96         dstIndex += 2;
97         dst[dstIndex++] = (byte)0x00;
98         dst[dstIndex++] = (byte)0x00;
99         writeInt2( dataLength, dst, dstIndex );
100         dstIndex += 2;
101         writeInt2( dataOffset, dst, dstIndex );
102         dstIndex += 2;
103         writeInt4( offset >> 32, dst, dstIndex );
104         dstIndex += 4;
105
106         return dstIndex - start;
107     }
108     int writeBytesWireFormat( byte[] dst, int dstIndex ) {
109         int start = dstIndex;
110
111 /* Netware doesn't like this
112  * while( pad-- > 0 ) {
113  * dst[dstIndex++] = (byte)0x00;
114  * }
115  */

116         System.arraycopy( b, off, dst, dstIndex, dataLength );
117         dstIndex += dataLength;
118
119         return dstIndex - start;
120     }
121     int readParameterWordsWireFormat( byte[] buffer, int bufferIndex ) {
122         return 0;
123     }
124     int readBytesWireFormat( byte[] buffer, int bufferIndex ) {
125         return 0;
126     }
127     public String JavaDoc toString() {
128         return new String JavaDoc( "SmbComWriteAndX[" +
129             super.toString() +
130             ",fid=" + fid +
131             ",offset=" + offset +
132             ",writeMode=" + writeMode +
133             ",remaining=" + remaining +
134             ",dataLength=" + dataLength +
135             ",dataOffset=" + dataOffset + "]" );
136     }
137 }
138
Popular Tags