~ubuntu-branches/debian/sid/wordpress/sid

« back to all changes in this revision

Viewing changes to debian/missing-sources/plupload-1.5.7/csharp/Plupload/PngEncoder/PendingBuffer.cs

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2013-09-04 23:18:58 UTC
  • mfrom: (1.2.28)
  • Revision ID: package-import@ubuntu.com-20130904231858-nljmn1buzswh63jk
Tags: 3.6+dfsg-1
* New upstream release.
* Improve wp-settings to verify that $_SERVER['HTTP_X_FORWARDED_PROTO']
  exists before accessing it (avoids a PHP notice).
  Thanks to Paul Dreik <slask@pauldreik.se> for the report and the patch.
* Document in README.Debian the need to login to /wp-admin/ to complete
  an upgrade.
* Drop useless debian/README.source
* Drop 008CVE2008-2392.patch since upstream now disables unfiltered
  uploads by default. See http://core.trac.wordpress.org/ticket/10692
* Drop 009CVE2008-6767.patch since the backto parameter is validated
  against a whitelist, and externally triggered upgrades are not a
  security problem as long as they work.
* Update debian/missing-sources with latest versions.
* Update upstream l10n.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// PendingBuffer.cs
 
2
//
 
3
// Copyright (C) 2001 Mike Krueger
 
4
// Copyright (C) 2004 John Reilly
 
5
//
 
6
// This file was translated from java, it was part of the GNU Classpath
 
7
// Copyright (C) 2001 Free Software Foundation, Inc.
 
8
//
 
9
// This program is free software; you can redistribute it and/or
 
10
// modify it under the terms of the GNU General Public License
 
11
// as published by the Free Software Foundation; either version 2
 
12
// of the License, or (at your option) any later version.
 
13
//
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
//
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
22
//
 
23
// Linking this library statically or dynamically with other modules is
 
24
// making a combined work based on this library.  Thus, the terms and
 
25
// conditions of the GNU General Public License cover the whole
 
26
// combination.
 
27
// 
 
28
// As a special exception, the copyright holders of this library give you
 
29
// permission to link this library with independent modules to produce an
 
30
// executable, regardless of the license terms of these independent
 
31
// modules, and to copy and distribute the resulting executable under
 
32
// terms of your choice, provided that you also meet, for each linked
 
33
// independent module, the terms and conditions of the license of that
 
34
// module.  An independent module is a module which is not derived from
 
35
// or based on this library.  If you modify this library, you may extend
 
36
// this exception to your version of the library, but you are not
 
37
// obligated to do so.  If you do not wish to do so, delete this
 
38
// exception statement from your version.
 
39
 
 
40
using System;
 
41
 
 
42
namespace Plupload.PngEncoder {
 
43
 
 
44
        /// <summary>
 
45
        /// This class is general purpose class for writing data to a buffer.
 
46
        /// 
 
47
        /// It allows you to write bits as well as bytes
 
48
        /// Based on DeflaterPending.java
 
49
        /// 
 
50
        /// author of the original java version : Jochen Hoenicke
 
51
        /// </summary>
 
52
        public class PendingBuffer {
 
53
                #region Instance Fields
 
54
                /// <summary>
 
55
                /// Internal work buffer
 
56
                /// </summary>
 
57
                byte[] buffer_;
 
58
 
 
59
                int start;
 
60
                int end;
 
61
 
 
62
                uint bits;
 
63
                int bitCount;
 
64
                #endregion
 
65
 
 
66
                #region Constructors
 
67
                /// <summary>
 
68
                /// construct instance using default buffer size of 4096
 
69
                /// </summary>
 
70
                public PendingBuffer()
 
71
                        : this(4096) {
 
72
                }
 
73
 
 
74
                /// <summary>
 
75
                /// construct instance using specified buffer size
 
76
                /// </summary>
 
77
                /// <param name="bufferSize">
 
78
                /// size to use for internal buffer
 
79
                /// </param>
 
80
                public PendingBuffer(int bufferSize) {
 
81
                        buffer_ = new byte[bufferSize];
 
82
                }
 
83
 
 
84
                #endregion
 
85
 
 
86
                /// <summary>
 
87
                /// Clear internal state/buffers
 
88
                /// </summary>
 
89
                public void Reset() {
 
90
                        start = end = bitCount = 0;
 
91
                }
 
92
 
 
93
                /// <summary>
 
94
                /// Write a byte to buffer
 
95
                /// </summary>
 
96
                /// <param name="value">
 
97
                /// The value to write
 
98
                /// </param>
 
99
                public void WriteByte(int value) {
 
100
#if DebugDeflation
 
101
                        if (DeflaterConstants.DEBUGGING && (start != 0) )
 
102
                        {
 
103
                                throw new SharpZipBaseException("Debug check: start != 0");
 
104
                        }
 
105
#endif
 
106
                        buffer_[end++] = unchecked((byte) value);
 
107
                }
 
108
 
 
109
                /// <summary>
 
110
                /// Write a short value to buffer LSB first
 
111
                /// </summary>
 
112
                /// <param name="value">
 
113
                /// The value to write.
 
114
                /// </param>
 
115
                public void WriteShort(int value) {
 
116
#if DebugDeflation
 
117
                        if (DeflaterConstants.DEBUGGING && (start != 0) )
 
118
                        {
 
119
                                throw new SharpZipBaseException("Debug check: start != 0");
 
120
                        }
 
121
#endif
 
122
                        buffer_[end++] = unchecked((byte) value);
 
123
                        buffer_[end++] = unchecked((byte) (value >> 8));
 
124
                }
 
125
 
 
126
                /// <summary>
 
127
                /// write an integer LSB first
 
128
                /// </summary>
 
129
                /// <param name="value">The value to write.</param>
 
130
                public void WriteInt(int value) {
 
131
#if DebugDeflation
 
132
                        if (DeflaterConstants.DEBUGGING && (start != 0) )
 
133
                        {
 
134
                                throw new SharpZipBaseException("Debug check: start != 0");
 
135
                        }
 
136
#endif
 
137
                        buffer_[end++] = unchecked((byte) value);
 
138
                        buffer_[end++] = unchecked((byte) (value >> 8));
 
139
                        buffer_[end++] = unchecked((byte) (value >> 16));
 
140
                        buffer_[end++] = unchecked((byte) (value >> 24));
 
141
                }
 
142
 
 
143
                /// <summary>
 
144
                /// Write a block of data to buffer
 
145
                /// </summary>
 
146
                /// <param name="block">data to write</param>
 
147
                /// <param name="offset">offset of first byte to write</param>
 
148
                /// <param name="length">number of bytes to write</param>
 
149
                public void WriteBlock(byte[] block, int offset, int length) {
 
150
#if DebugDeflation
 
151
                        if (DeflaterConstants.DEBUGGING && (start != 0) ) 
 
152
                        {
 
153
                                throw new SharpZipBaseException("Debug check: start != 0");
 
154
                        }
 
155
#endif
 
156
                        System.Array.Copy(block, offset, buffer_, end, length);
 
157
                        end += length;
 
158
                }
 
159
 
 
160
                /// <summary>
 
161
                /// The number of bits written to the buffer
 
162
                /// </summary>
 
163
                public int BitCount {
 
164
                        get {
 
165
                                return bitCount;
 
166
                        }
 
167
                }
 
168
 
 
169
                /// <summary>
 
170
                /// Align internal buffer on a byte boundary
 
171
                /// </summary>
 
172
                public void AlignToByte() {
 
173
#if DebugDeflation
 
174
                        if (DeflaterConstants.DEBUGGING && (start != 0) ) 
 
175
                        {
 
176
                                throw new SharpZipBaseException("Debug check: start != 0");
 
177
                        }
 
178
#endif
 
179
                        if (bitCount > 0) {
 
180
                                buffer_[end++] = unchecked((byte) bits);
 
181
                                if (bitCount > 8) {
 
182
                                        buffer_[end++] = unchecked((byte) (bits >> 8));
 
183
                                }
 
184
                        }
 
185
                        bits = 0;
 
186
                        bitCount = 0;
 
187
                }
 
188
 
 
189
                /// <summary>
 
190
                /// Write bits to internal buffer
 
191
                /// </summary>
 
192
                /// <param name="b">source of bits</param>
 
193
                /// <param name="count">number of bits to write</param>
 
194
                public void WriteBits(int b, int count) {
 
195
#if DebugDeflation
 
196
                        if (DeflaterConstants.DEBUGGING && (start != 0) ) 
 
197
                        {
 
198
                                throw new SharpZipBaseException("Debug check: start != 0");
 
199
                        }
 
200
 
 
201
                        //                      if (DeflaterConstants.DEBUGGING) {
 
202
                        //                              //Console.WriteLine("writeBits("+b+","+count+")");
 
203
                        //                      }
 
204
#endif
 
205
                        bits |= (uint) (b << bitCount);
 
206
                        bitCount += count;
 
207
                        if (bitCount >= 16) {
 
208
                                buffer_[end++] = unchecked((byte) bits);
 
209
                                buffer_[end++] = unchecked((byte) (bits >> 8));
 
210
                                bits >>= 16;
 
211
                                bitCount -= 16;
 
212
                        }
 
213
                }
 
214
 
 
215
                /// <summary>
 
216
                /// Write a short value to internal buffer most significant byte first
 
217
                /// </summary>
 
218
                /// <param name="s">value to write</param>
 
219
                public void WriteShortMSB(int s) {
 
220
#if DebugDeflation
 
221
                        if (DeflaterConstants.DEBUGGING && (start != 0) ) 
 
222
                        {
 
223
                                throw new SharpZipBaseException("Debug check: start != 0");
 
224
                        }
 
225
#endif
 
226
                        buffer_[end++] = unchecked((byte) (s >> 8));
 
227
                        buffer_[end++] = unchecked((byte) s);
 
228
                }
 
229
 
 
230
                /// <summary>
 
231
                /// Indicates if buffer has been flushed
 
232
                /// </summary>
 
233
                public bool IsFlushed {
 
234
                        get {
 
235
                                return end == 0;
 
236
                        }
 
237
                }
 
238
 
 
239
                /// <summary>
 
240
                /// Flushes the pending buffer into the given output array.  If the
 
241
                /// output array is to small, only a partial flush is done.
 
242
                /// </summary>
 
243
                /// <param name="output">The output array.</param>
 
244
                /// <param name="offset">The offset into output array.</param>
 
245
                /// <param name="length">The maximum number of bytes to store.</param>
 
246
                /// <returns>The number of bytes flushed.</returns>
 
247
                public int Flush(byte[] output, int offset, int length) {
 
248
                        if (bitCount >= 8) {
 
249
                                buffer_[end++] = unchecked((byte) bits);
 
250
                                bits >>= 8;
 
251
                                bitCount -= 8;
 
252
                        }
 
253
 
 
254
                        if (length > end - start) {
 
255
                                length = end - start;
 
256
                                System.Array.Copy(buffer_, start, output, offset, length);
 
257
                                start = 0;
 
258
                                end = 0;
 
259
                        } else {
 
260
                                System.Array.Copy(buffer_, start, output, offset, length);
 
261
                                start += length;
 
262
                        }
 
263
                        return length;
 
264
                }
 
265
 
 
266
                /// <summary>
 
267
                /// Convert internal buffer to byte array.
 
268
                /// Buffer is empty on completion
 
269
                /// </summary>
 
270
                /// <returns>
 
271
                /// The internal buffer contents converted to a byte array.
 
272
                /// </returns>
 
273
                public byte[] ToByteArray() {
 
274
                        byte[] result = new byte[end - start];
 
275
                        System.Array.Copy(buffer_, start, result, 0, result.Length);
 
276
                        start = 0;
 
277
                        end = 0;
 
278
                        return result;
 
279
                }
 
280
        }
 
281
}