OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 /** | 7 /** |
8 * Parser for MIME multipart types of data as described in RFC 2046 | 8 * Parser for MIME multipart types of data as described in RFC 2046 |
9 * section 5.1.1. The data to parse is supplied through the [:update:] | 9 * section 5.1.1. The data to parse is supplied through the [:update:] |
10 * method. As the data is parsed the following callbacks are called: | 10 * method. As the data is parsed the following callbacks are called: |
(...skipping 23 matching lines...) Expand all Loading... |
34 const int _LAST_BOUNDARY_DASH2 = 11; | 34 const int _LAST_BOUNDARY_DASH2 = 11; |
35 const int _LAST_BOUNDARY_ENDING = 12; | 35 const int _LAST_BOUNDARY_ENDING = 12; |
36 const int _LAST_BOUNDARY_END = 13; | 36 const int _LAST_BOUNDARY_END = 13; |
37 const int _DONE = 14; | 37 const int _DONE = 14; |
38 const int _FAILURE = 15; | 38 const int _FAILURE = 15; |
39 | 39 |
40 // Construct a new MIME multipart parser with the boundary | 40 // Construct a new MIME multipart parser with the boundary |
41 // [boundary]. The boundary should be as specified in the content | 41 // [boundary]. The boundary should be as specified in the content |
42 // type parameter, that is without the -- prefix. | 42 // type parameter, that is without the -- prefix. |
43 _MimeMultipartParser(String boundary) { | 43 _MimeMultipartParser(String boundary) { |
44 List<int> charCodes = boundary.charCodes; | 44 List<int> charCodes = boundary.codeUnits; |
45 _boundary = new List<int>.fixedLength(4 + charCodes.length); | 45 _boundary = new List<int>.fixedLength(4 + charCodes.length); |
46 // Set-up the matching boundary preceding it with CRLF and two | 46 // Set-up the matching boundary preceding it with CRLF and two |
47 // dashes. | 47 // dashes. |
48 _boundary[0] = _CharCode.CR; | 48 _boundary[0] = _CharCode.CR; |
49 _boundary[1] = _CharCode.LF; | 49 _boundary[1] = _CharCode.LF; |
50 _boundary[2] = _CharCode.DASH; | 50 _boundary[2] = _CharCode.DASH; |
51 _boundary[3] = _CharCode.DASH; | 51 _boundary[3] = _CharCode.DASH; |
52 _boundary.setRange(4, charCodes.length, charCodes); | 52 _boundary.setRange(4, charCodes.length, charCodes); |
53 _state = _START; | 53 _state = _START; |
54 _headerField = new StringBuffer(); | 54 _headerField = new StringBuffer(); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 reportData(); | 286 reportData(); |
287 } | 287 } |
288 return index - offset; | 288 return index - offset; |
289 } | 289 } |
290 | 290 |
291 bool _isTokenChar(int byte) { | 291 bool _isTokenChar(int byte) { |
292 return byte > 31 && byte < 128 && _Const.SEPARATORS.indexOf(byte) == -1; | 292 return byte > 31 && byte < 128 && _Const.SEPARATORS.indexOf(byte) == -1; |
293 } | 293 } |
294 | 294 |
295 int _toLowerCase(int byte) { | 295 int _toLowerCase(int byte) { |
296 final int aCode = "A".charCodeAt(0); | 296 final int aCode = "A".codeUnitAt(0); |
297 final int zCode = "Z".charCodeAt(0); | 297 final int zCode = "Z".codeUnitAt(0); |
298 final int delta = "a".charCodeAt(0) - aCode; | 298 final int delta = "a".codeUnitAt(0) - aCode; |
299 return (aCode <= byte && byte <= zCode) ? byte + delta : byte; | 299 return (aCode <= byte && byte <= zCode) ? byte + delta : byte; |
300 } | 300 } |
301 | 301 |
302 void _expect(int val1, int val2) { | 302 void _expect(int val1, int val2) { |
303 if (val1 != val2) { | 303 if (val1 != val2) { |
304 throw new MimeParserException("Failed to parse multipart mime 1"); | 304 throw new MimeParserException("Failed to parse multipart mime 1"); |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 void _expectWS(int byte) { | 308 void _expectWS(int byte) { |
(...skipping 15 matching lines...) Expand all Loading... |
324 Function partDataReceived; | 324 Function partDataReceived; |
325 Function partEnd; | 325 Function partEnd; |
326 } | 326 } |
327 | 327 |
328 | 328 |
329 class MimeParserException implements Exception { | 329 class MimeParserException implements Exception { |
330 const MimeParserException([String this.message = ""]); | 330 const MimeParserException([String this.message = ""]); |
331 String toString() => "MimeParserException: $message"; | 331 String toString() => "MimeParserException: $message"; |
332 final String message; | 332 final String message; |
333 } | 333 } |
OLD | NEW |