2 // XmlDictionaryReaderQuotas.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 public sealed class XmlDictionaryReaderQuotas
33 static XmlDictionaryReaderQuotas max
;
35 static XmlDictionaryReaderQuotas ()
37 max
= new XmlDictionaryReaderQuotas (true);
40 readonly bool is_readonly
;
41 int array_len
, bytes
, depth
, nt_chars
, text_len
;
43 public XmlDictionaryReaderQuotas ()
48 private XmlDictionaryReaderQuotas (bool max
)
51 array_len
= max
? int.MaxValue
: 0x4000;
52 bytes
= max
? int.MaxValue
: 0x1000;
53 depth
= max
? int.MaxValue
: 0x20;
54 nt_chars
= max
? int.MaxValue
: 0x4000;
55 text_len
= max
? int.MaxValue
: 0x2000;
58 public static XmlDictionaryReaderQuotas Max
{
62 public int MaxArrayLength
{
63 get { return array_len; }
64 set { array_len = Check (value); }
67 public int MaxBytesPerRead
{
69 set { bytes = Check (value); }
74 set { depth = Check (value); }
77 public int MaxNameTableCharCount
{
78 get { return nt_chars; }
79 set { nt_chars = Check (value); }
82 public int MaxStringContentLength
{
83 get { return text_len; }
84 set { text_len = Check (value); }
87 private int Check (int value)
90 throw new InvalidOperationException ("This quota is read-only.");
92 throw new ArgumentException ("Value must be positive integer.");
96 public void CopyTo (XmlDictionaryReaderQuotas quota
)
98 quota
.array_len
= array_len
;
101 quota
.nt_chars
= nt_chars
;
102 quota
.text_len
= text_len
;